Merge pull request #94368 from CrazyRoka/optimize-render-pass-uniform-set
Optimize `RenderForwardClustered::_setup_render_pass_uniform_set` by reducing Vector allocations
This commit is contained in:
commit
14ce5ba8a1
14 changed files with 53 additions and 36 deletions
|
|
@ -394,7 +394,9 @@ static FfxErrorCode execute_gpu_job_compute_rd(FSR2Context::Scratch &p_scratch,
|
|||
FSR2Effect::Pipeline &backend_pipeline = *reinterpret_cast<FSR2Effect::Pipeline *>(p_job.pipeline.pipeline);
|
||||
ERR_FAIL_COND_V(backend_pipeline.pipeline_rid.is_null(), FFX_ERROR_INVALID_ARGUMENT);
|
||||
|
||||
Vector<RD::Uniform> compute_uniforms;
|
||||
thread_local LocalVector<RD::Uniform> compute_uniforms;
|
||||
compute_uniforms.clear();
|
||||
|
||||
for (uint32_t i = 0; i < p_job.pipeline.srvCount; i++) {
|
||||
RID texture_rid = p_scratch.resources.rids[p_job.srvs[i].internalIndex];
|
||||
RD::Uniform texture_uniform(RD::UNIFORM_TYPE_TEXTURE, p_job.pipeline.srvResourceBindings[i].slotIndex, texture_rid);
|
||||
|
|
|
|||
|
|
@ -464,7 +464,8 @@ void SSEffects::downsample_depth(Ref<RenderSceneBuffersRD> p_render_buffers, uin
|
|||
if (use_mips) {
|
||||
// Grab our downsample uniform set from cache, these are automatically cleaned up if the depth textures are cleared.
|
||||
// This also ensures we can switch between left eye and right eye uniform sets without recreating the uniform twice a frame.
|
||||
Vector<RD::Uniform> u_depths;
|
||||
thread_local LocalVector<RD::Uniform> u_depths;
|
||||
u_depths.clear();
|
||||
|
||||
// Note, use_full_mips is true if either SSAO or SSIL uses half size, but the other full size and we're using mips.
|
||||
// That means we're filling all 5 levels.
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ ALBEDO = vec3(1.0);
|
|||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
uniforms.append_array(material_storage->samplers_rd_get_default().get_uniforms(SAMPLERS_BINDING_FIRST_INDEX));
|
||||
material_storage->samplers_rd_get_default().append_uniforms(uniforms, SAMPLERS_BINDING_FIRST_INDEX);
|
||||
|
||||
volumetric_fog.base_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, volumetric_fog.default_shader_rd, VolumetricFogShader::FogSet::FOG_SET_BASE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -552,7 +552,9 @@ void SkyRD::Sky::free() {
|
|||
RID SkyRD::Sky::get_textures(SkyTextureSetVersion p_version, RID p_default_shader_rd, Ref<RenderSceneBuffersRD> p_render_buffers) {
|
||||
RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton();
|
||||
|
||||
Vector<RD::Uniform> uniforms;
|
||||
thread_local LocalVector<RD::Uniform> uniforms;
|
||||
uniforms.clear();
|
||||
|
||||
{
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
|
||||
|
|
@ -873,7 +875,7 @@ void sky() {
|
|||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
uniforms.append_array(material_storage->samplers_rd_get_default().get_uniforms(SAMPLERS_BINDING_FIRST_INDEX));
|
||||
material_storage->samplers_rd_get_default().append_uniforms(uniforms, SAMPLERS_BINDING_FIRST_INDEX);
|
||||
|
||||
sky_scene_state.uniform_set = RD::get_singleton()->uniform_set_create(uniforms, sky_shader.default_shader_rd, SKY_SET_UNIFORMS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3139,7 +3139,8 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
|
||||
//default render buffer and scene state uniform set
|
||||
|
||||
Vector<RD::Uniform> uniforms;
|
||||
thread_local LocalVector<RD::Uniform> uniforms;
|
||||
uniforms.clear();
|
||||
|
||||
{
|
||||
RD::Uniform u;
|
||||
|
|
@ -3324,7 +3325,7 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
uniforms.append_array(p_samplers.get_uniforms(12));
|
||||
p_samplers.append_uniforms(uniforms, 12);
|
||||
|
||||
{
|
||||
RD::Uniform u;
|
||||
|
|
@ -3459,7 +3460,8 @@ RID RenderForwardClustered::_setup_render_pass_uniform_set(RenderListType p_rend
|
|||
|
||||
RID RenderForwardClustered::_setup_sdfgi_render_pass_uniform_set(RID p_albedo_texture, RID p_emission_texture, RID p_emission_aniso_texture, RID p_geom_facing_texture, const RendererRD::MaterialStorage::Samplers &p_samplers) {
|
||||
RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton();
|
||||
Vector<RD::Uniform> uniforms;
|
||||
thread_local LocalVector<RD::Uniform> uniforms;
|
||||
uniforms.clear();
|
||||
|
||||
{
|
||||
RD::Uniform u;
|
||||
|
|
@ -3623,7 +3625,7 @@ RID RenderForwardClustered::_setup_sdfgi_render_pass_uniform_set(RID p_albedo_te
|
|||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
uniforms.append_array(p_samplers.get_uniforms(12));
|
||||
p_samplers.append_uniforms(uniforms, 12);
|
||||
|
||||
// actual sdfgi stuff
|
||||
|
||||
|
|
|
|||
|
|
@ -605,7 +605,7 @@ RID RenderForwardMobile::_setup_render_pass_uniform_set(RenderListType p_render_
|
|||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
uniforms.append_array(p_samplers.get_uniforms(13));
|
||||
p_samplers.append_uniforms(uniforms, 13);
|
||||
|
||||
if (p_index >= (int)render_pass_uniform_sets.size()) {
|
||||
render_pass_uniform_sets.resize(p_index + 1);
|
||||
|
|
|
|||
|
|
@ -455,7 +455,7 @@ RID RendererCanvasRenderRD::_create_base_uniform_set(RID p_to_render_target, boo
|
|||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
uniforms.append_array(material_storage->samplers_rd_get_default().get_uniforms(SAMPLERS_BINDING_FIRST_INDEX));
|
||||
material_storage->samplers_rd_get_default().append_uniforms(uniforms, SAMPLERS_BINDING_FIRST_INDEX);
|
||||
|
||||
RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, shader.default_version_rd_shader, BASE_UNIFORM_SET);
|
||||
if (p_backbuffer) {
|
||||
|
|
|
|||
|
|
@ -1177,24 +1177,25 @@ void MaterialStorage::MaterialData::set_as_used() {
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// MaterialStorage::Samplers
|
||||
|
||||
Vector<RD::Uniform> MaterialStorage::Samplers::get_uniforms(int p_first_index) const {
|
||||
Vector<RD::Uniform> uniforms;
|
||||
template void MaterialStorage::Samplers::append_uniforms(LocalVector<RD::Uniform> &p_uniforms, int p_first_index) const;
|
||||
|
||||
template void MaterialStorage::Samplers::append_uniforms(Vector<RD::Uniform> &p_uniforms, int p_first_index) const;
|
||||
|
||||
template <typename Collection>
|
||||
void MaterialStorage::Samplers::append_uniforms(Collection &p_uniforms, int p_first_index) const {
|
||||
// Binding ids are aligned with samplers_inc.glsl.
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 0, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 1, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 2, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 3, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 4, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 5, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 6, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 7, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 8, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 9, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 10, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 11, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
|
||||
return uniforms;
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 0, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 1, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 2, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 3, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 4, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 5, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 6, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 7, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 8, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 9, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 10, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
p_uniforms.push_back(RD::Uniform(RD::UNIFORM_TYPE_SAMPLER, p_first_index + 11, rids[RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC][RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED]));
|
||||
}
|
||||
|
||||
bool MaterialStorage::Samplers::is_valid() const {
|
||||
|
|
|
|||
|
|
@ -128,7 +128,8 @@ public:
|
|||
return rids[p_filter][p_repeat];
|
||||
}
|
||||
|
||||
Vector<RD::Uniform> get_uniforms(int p_first_index) const;
|
||||
template <typename Collection>
|
||||
void append_uniforms(Collection &p_uniforms, int p_first_index) const;
|
||||
bool is_valid() const;
|
||||
bool is_null() const;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ void process() {
|
|||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
uniforms.append_array(material_storage->samplers_rd_get_default().get_uniforms(SAMPLERS_BINDING_FIRST_INDEX));
|
||||
material_storage->samplers_rd_get_default().append_uniforms(uniforms, SAMPLERS_BINDING_FIRST_INDEX);
|
||||
|
||||
particles_shader.base_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, particles_shader.default_shader_rd, BASE_UNIFORM_SET);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ void UniformSetCacheRD::_bind_methods() {
|
|||
}
|
||||
|
||||
RID UniformSetCacheRD::get_cache_array(RID p_shader, uint32_t p_set, const TypedArray<RDUniform> &p_uniforms) {
|
||||
Vector<RD::Uniform> uniforms;
|
||||
thread_local LocalVector<RD::Uniform> uniforms;
|
||||
uniforms.clear();
|
||||
|
||||
for (int i = 0; i < p_uniforms.size(); i++) {
|
||||
Ref<RDUniform> uniform = p_uniforms[i];
|
||||
|
|
|
|||
|
|
@ -125,7 +125,8 @@ class UniformSetCacheRD : public Object {
|
|||
void _invalidate(Cache *p_cache);
|
||||
static void _uniform_set_invalidation_callback(void *p_userdata);
|
||||
|
||||
RID _allocate_from_uniforms(RID p_shader, uint32_t p_set, uint32_t p_hash, uint32_t p_table_idx, const Vector<RD::Uniform> &p_uniforms) {
|
||||
template <typename Collection>
|
||||
RID _allocate_from_uniforms(RID p_shader, uint32_t p_set, uint32_t p_hash, uint32_t p_table_idx, const Collection &p_uniforms) {
|
||||
RID rid = RD::get_singleton()->uniform_set_create(p_uniforms, p_shader, p_set);
|
||||
ERR_FAIL_COND_V(rid.is_null(), rid);
|
||||
|
||||
|
|
@ -183,10 +184,10 @@ public:
|
|||
}
|
||||
|
||||
template <typename... Args>
|
||||
RID get_cache_vec(RID p_shader, uint32_t p_set, const Vector<RD::Uniform> &p_uniforms) {
|
||||
RID get_cache_vec(RID p_shader, uint32_t p_set, const LocalVector<RD::Uniform> &p_uniforms) {
|
||||
uint32_t h = hash_murmur3_one_64(p_shader.get_id());
|
||||
h = hash_murmur3_one_32(p_set, h);
|
||||
for (int i = 0; i < p_uniforms.size(); i++) {
|
||||
for (uint32_t i = 0; i < p_uniforms.size(); i++) {
|
||||
h = _hash_uniform(p_uniforms[i], h);
|
||||
}
|
||||
|
||||
|
|
@ -199,7 +200,7 @@ public:
|
|||
while (c) {
|
||||
if (c->hash == h && c->set == p_set && c->shader == p_shader && (uint32_t)p_uniforms.size() == c->uniforms.size()) {
|
||||
bool all_ok = true;
|
||||
for (int i = 0; i < p_uniforms.size(); i++) {
|
||||
for (uint32_t i = 0; i < p_uniforms.size(); i++) {
|
||||
if (!_compare_uniform(p_uniforms[i], c->uniforms[i])) {
|
||||
all_ok = false;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -3081,7 +3081,12 @@ void RenderingDevice::_uniform_set_update_shared(UniformSet *p_uniform_set) {
|
|||
}
|
||||
}
|
||||
|
||||
RID RenderingDevice::uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set) {
|
||||
template RID RenderingDevice::uniform_set_create(const LocalVector<RD::Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set);
|
||||
|
||||
template RID RenderingDevice::uniform_set_create(const Vector<RD::Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set);
|
||||
|
||||
template <typename Collection>
|
||||
RID RenderingDevice::uniform_set_create(const Collection &p_uniforms, RID p_shader, uint32_t p_shader_set) {
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
ERR_FAIL_COND_V(p_uniforms.is_empty(), RID());
|
||||
|
|
|
|||
|
|
@ -963,7 +963,8 @@ private:
|
|||
void _uniform_set_update_shared(UniformSet *p_uniform_set);
|
||||
|
||||
public:
|
||||
RID uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set);
|
||||
template <typename Collection>
|
||||
RID uniform_set_create(const Collection &p_uniforms, RID p_shader, uint32_t p_shader_set);
|
||||
bool uniform_set_is_valid(RID p_uniform_set);
|
||||
void uniform_set_set_invalidation_callback(RID p_uniform_set, InvalidationCallback p_callback, void *p_userdata);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue