Skip to content

Commit 4cd65e0

Browse files
committed
Ensure that all spec constants are given a value in the mobile post process shader so that re-spirv can pick up on them and optimize them out of the final shader
This is needed to workaround a bug on Adreno devices when using input attachments and spec constants in the same shader
1 parent 25203e2 commit 4cd65e0

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

servers/rendering/renderer_rd/effects/tone_mapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ void ToneMapper::tonemapper_subpass(RD::DrawListID p_subpass_draw_list, RID p_so
324324
tonemap_mobile.push_constant.white = p_settings.white;
325325
tonemap_mobile.push_constant.luminance_multiplier = p_settings.luminance_multiplier;
326326

327-
uint32_t spec_constant = 0;
327+
uint32_t spec_constant = TONEMAP_MOBILE_ADRENO_BUG;
328328
spec_constant |= p_settings.use_bcs ? TONEMAP_MOBILE_FLAG_USE_BCS : 0;
329329
//spec_constant |= p_settings.use_glow ? TONEMAP_MOBILE_FLAG_USE_GLOW : 0;
330330
//spec_constant |= p_settings.glow_map_strength > 0.01 ? TONEMAP_MOBILE_FLAG_USE_GLOW_MAP : 0;

servers/rendering/renderer_rd/effects/tone_mapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class ToneMapper {
100100
TONEMAP_MOBILE_FLAG_GLOW_MODE_SOFTLIGHT = (1 << 15),
101101
TONEMAP_MOBILE_FLAG_GLOW_MODE_REPLACE = (1 << 16),
102102
TONEMAP_MOBILE_FLAG_GLOW_MODE_MIX = (1 << 17),
103+
TONEMAP_MOBILE_ADRENO_BUG = (1 << 18), // Needs to be last so we force the pipeline cache to specify specializations for all variants.
103104
};
104105

105106
struct TonemapPushConstant {

servers/rendering/renderer_rd/pipeline_cache_rd.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ RID PipelineCacheRD::_generate_version(RD::VertexFormatID p_vertex_format_id, RD
4646
uint32_t bool_index = 0;
4747
uint32_t bool_specializations = p_bool_specializations;
4848
while (bool_specializations) {
49-
if (bool_specializations & (1 << bool_index)) {
50-
RD::PipelineSpecializationConstant sc;
51-
sc.bool_value = true;
52-
sc.constant_id = bool_index;
53-
sc.type = RD::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL;
54-
specialization_constants.push_back(sc);
55-
bool_specializations &= ~(1 << bool_index);
56-
}
49+
RD::PipelineSpecializationConstant sc;
50+
sc.bool_value = bool(bool_specializations & (1 << bool_index));
51+
sc.constant_id = bool_index;
52+
sc.type = RD::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL;
53+
specialization_constants.push_back(sc);
54+
bool_specializations &= ~(1 << bool_index);
5755
bool_index++;
5856
}
5957

0 commit comments

Comments
 (0)