Skip to content

Commit 6bf6402

Browse files
committed
Merge pull request godotengine#94785 from Chaosus/shader_fix_samplers_order
Fix texture samplers to not being last in the property list
2 parents af919a8 + e41048e commit 6bf6402

File tree

6 files changed

+18
-21
lines changed

6 files changed

+18
-21
lines changed

drivers/gles3/storage/material_storage.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,7 @@ void ShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const
586586
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL) {
587587
continue;
588588
}
589-
if (E.value.texture_order >= 0) {
590-
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.texture_order + 100000));
591-
} else {
592-
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.order));
593-
}
589+
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.prop_order));
594590
}
595591
int uniform_count = filtered_uniforms.size();
596592
sorter.sort(filtered_uniforms.ptr(), uniform_count);
@@ -640,7 +636,7 @@ bool ShaderData::is_parameter_texture(const StringName &p_param) const {
640636
return false;
641637
}
642638

643-
return uniforms[p_param].texture_order >= 0;
639+
return uniforms[p_param].is_texture();
644640
}
645641

646642
///////////////////////////////////////////////////////////////////////////
@@ -719,7 +715,7 @@ void MaterialData::update_uniform_buffer(const HashMap<StringName, ShaderLanguag
719715
bool uses_global_buffer = false;
720716

721717
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : p_uniforms) {
722-
if (E.value.order < 0) {
718+
if (E.value.is_texture()) {
723719
continue; // texture, does not go here
724720
}
725721

servers/rendering/dummy/storage/material_storage.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,7 @@ void MaterialStorage::get_shader_parameter_list(RID p_shader, List<PropertyInfo>
102102
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL) {
103103
continue;
104104
}
105-
if (E.value.texture_order >= 0) {
106-
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.texture_order + 100000));
107-
} else {
108-
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.order));
109-
}
105+
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.prop_order));
110106
}
111107
int uniform_count = filtered_uniforms.size();
112108
sorter.sort(filtered_uniforms.ptr(), uniform_count);

servers/rendering/renderer_rd/storage_rd/material_storage.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,7 @@ void MaterialStorage::ShaderData::get_shader_uniform_list(List<PropertyInfo> *p_
580580
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL) {
581581
continue;
582582
}
583-
if (E.value.texture_order >= 0) {
584-
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.texture_order + 100000));
585-
} else {
586-
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.order));
587-
}
583+
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.prop_order));
588584
}
589585
int uniform_count = filtered_uniforms.size();
590586
sorter.sort(filtered_uniforms.ptr(), uniform_count);
@@ -634,7 +630,7 @@ bool MaterialStorage::ShaderData::is_parameter_texture(const StringName &p_param
634630
return false;
635631
}
636632

637-
return uniforms[p_param].texture_order >= 0;
633+
return uniforms[p_param].is_texture();
638634
}
639635

640636
///////////////////////////////////////////////////////////////////////////
@@ -645,7 +641,7 @@ void MaterialStorage::MaterialData::update_uniform_buffer(const HashMap<StringNa
645641
bool uses_global_buffer = false;
646642

647643
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : p_uniforms) {
648-
if (E.value.order < 0) {
644+
if (E.value.is_texture()) {
649645
continue; // texture, does not go here
650646
}
651647

servers/rendering/shader_compiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
922922
if (shader->uniforms.has(vnode->name)) {
923923
//its a uniform!
924924
const ShaderLanguage::ShaderNode::Uniform &u = shader->uniforms[vnode->name];
925-
if (u.texture_order >= 0) {
925+
if (u.is_texture()) {
926926
StringName name;
927927
if (u.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SCREEN_TEXTURE) {
928928
name = "color_buffer";
@@ -1039,7 +1039,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
10391039
if (shader->uniforms.has(anode->name)) {
10401040
//its a uniform!
10411041
const ShaderLanguage::ShaderNode::Uniform &u = shader->uniforms[anode->name];
1042-
if (u.texture_order >= 0) {
1042+
if (u.is_texture()) {
10431043
code = _mkid(anode->name); //texture, use as is
10441044
} else {
10451045
//a scalar or vector

servers/rendering/shader_language.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8228,6 +8228,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
82288228
int texture_binding = 0;
82298229
int uniforms = 0;
82308230
int instance_index = 0;
8231+
int prop_index = 0;
82318232
#ifdef DEBUG_ENABLED
82328233
uint64_t uniform_buffer_size = 0;
82338234
uint64_t max_uniform_buffer_size = 0;
@@ -8782,6 +8783,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
87828783
++texture_binding;
87838784
}
87848785
uniform.order = -1;
8786+
uniform.prop_order = prop_index++;
87858787
} else {
87868788
if (uniform_scope == ShaderNode::Uniform::SCOPE_INSTANCE && (type == TYPE_MAT2 || type == TYPE_MAT3 || type == TYPE_MAT4)) {
87878789
_set_error(vformat(RTR("The '%s' qualifier is not supported for matrix types."), "SCOPE_INSTANCE"));
@@ -8790,6 +8792,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
87908792
uniform.texture_order = -1;
87918793
if (uniform_scope != ShaderNode::Uniform::SCOPE_INSTANCE) {
87928794
uniform.order = uniforms++;
8795+
uniform.prop_order = prop_index++;
87938796
#ifdef DEBUG_ENABLED
87948797
if (check_device_limit_warnings) {
87958798
if (uniform.array_size > 0) {

servers/rendering/shader_language.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ class ShaderLanguage {
648648
};
649649

650650
int order = 0;
651+
int prop_order = 0;
651652
int texture_order = 0;
652653
int texture_binding = 0;
653654
DataType type = TYPE_VOID;
@@ -664,6 +665,11 @@ class ShaderLanguage {
664665
String group;
665666
String subgroup;
666667

668+
_FORCE_INLINE_ bool is_texture() const {
669+
// Order is assigned to -1 for texture uniforms.
670+
return order < 0;
671+
}
672+
667673
Uniform() {
668674
hint_range[0] = 0.0f;
669675
hint_range[1] = 1.0f;

0 commit comments

Comments
 (0)