Merge pull request #55311 from Chaosus/fix_uniform_array
Fix uniform array alignment to fix a bug
This commit is contained in:
commit
4813abc6e7
@ -2652,7 +2652,17 @@ void RendererStorageRD::MaterialData::update_uniform_buffer(const Map<StringName
|
|||||||
//regular uniform
|
//regular uniform
|
||||||
uint32_t offset = p_uniform_offsets[E.value.order];
|
uint32_t offset = p_uniform_offsets[E.value.order];
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
uint32_t size = ShaderLanguage::get_type_size(E.value.type);
|
uint32_t size = 0U;
|
||||||
|
// The following code enforces a 16-byte alignment of uniform arrays.
|
||||||
|
if (E.value.array_size > 0) {
|
||||||
|
size = ShaderLanguage::get_type_size(E.value.type) * E.value.array_size;
|
||||||
|
int m = (16 * E.value.array_size);
|
||||||
|
if ((size % m) != 0U) {
|
||||||
|
size += m - (size % m);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
size = ShaderLanguage::get_type_size(E.value.type);
|
||||||
|
}
|
||||||
ERR_CONTINUE(offset + size > p_buffer_size);
|
ERR_CONTINUE(offset + size > p_buffer_size);
|
||||||
#endif
|
#endif
|
||||||
uint8_t *data = &p_buffer[offset];
|
uint8_t *data = &p_buffer[offset];
|
||||||
|
@ -661,6 +661,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
|
|||||||
uniform_sizes.write[uniform.order] = _get_datatype_size(ShaderLanguage::TYPE_UINT);
|
uniform_sizes.write[uniform.order] = _get_datatype_size(ShaderLanguage::TYPE_UINT);
|
||||||
uniform_alignments.write[uniform.order] = _get_datatype_alignment(ShaderLanguage::TYPE_UINT);
|
uniform_alignments.write[uniform.order] = _get_datatype_alignment(ShaderLanguage::TYPE_UINT);
|
||||||
} else {
|
} else {
|
||||||
|
// The following code enforces a 16-byte alignment of uniform arrays.
|
||||||
if (uniform.array_size > 0) {
|
if (uniform.array_size > 0) {
|
||||||
int size = _get_datatype_size(uniform.type) * uniform.array_size;
|
int size = _get_datatype_size(uniform.type) * uniform.array_size;
|
||||||
int m = (16 * uniform.array_size);
|
int m = (16 * uniform.array_size);
|
||||||
@ -668,10 +669,11 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
|
|||||||
size += m - (size % m);
|
size += m - (size % m);
|
||||||
}
|
}
|
||||||
uniform_sizes.write[uniform.order] = size;
|
uniform_sizes.write[uniform.order] = size;
|
||||||
|
uniform_alignments.write[uniform.order] = 16;
|
||||||
} else {
|
} else {
|
||||||
uniform_sizes.write[uniform.order] = _get_datatype_size(uniform.type);
|
uniform_sizes.write[uniform.order] = _get_datatype_size(uniform.type);
|
||||||
|
uniform_alignments.write[uniform.order] = _get_datatype_alignment(uniform.type);
|
||||||
}
|
}
|
||||||
uniform_alignments.write[uniform.order] = _get_datatype_alignment(uniform.type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user