|
@@ -3246,10 +3246,7 @@ Vector<uint8_t> RenderingDeviceDriverD3D12::shader_compile_binary_from_spirv(Vec
|
|
compressed_stages.push_back(zstd);
|
|
compressed_stages.push_back(zstd);
|
|
|
|
|
|
uint32_t s = compressed_stages[i].size();
|
|
uint32_t s = compressed_stages[i].size();
|
|
- if (s % 4 != 0) {
|
|
|
|
- s += 4 - (s % 4);
|
|
|
|
- }
|
|
|
|
- stages_binary_size += s;
|
|
|
|
|
|
+ stages_binary_size += STEPIFY(s, 4);
|
|
}
|
|
}
|
|
|
|
|
|
CharString shader_name_utf = p_shader_name.utf8();
|
|
CharString shader_name_utf = p_shader_name.utf8();
|
|
@@ -3259,10 +3256,7 @@ Vector<uint8_t> RenderingDeviceDriverD3D12::shader_compile_binary_from_spirv(Vec
|
|
uint32_t total_size = sizeof(uint32_t) * 3; // Header + version + main datasize;.
|
|
uint32_t total_size = sizeof(uint32_t) * 3; // Header + version + main datasize;.
|
|
total_size += sizeof(ShaderBinary::Data);
|
|
total_size += sizeof(ShaderBinary::Data);
|
|
|
|
|
|
- total_size += binary_data.shader_name_len;
|
|
|
|
- if ((binary_data.shader_name_len % 4) != 0) { // Alignment rules are really strange.
|
|
|
|
- total_size += 4 - (binary_data.shader_name_len % 4);
|
|
|
|
- }
|
|
|
|
|
|
+ total_size += STEPIFY(binary_data.shader_name_len, 4);
|
|
|
|
|
|
for (int i = 0; i < sets_bindings.size(); i++) {
|
|
for (int i = 0; i < sets_bindings.size(); i++) {
|
|
total_size += sizeof(uint32_t);
|
|
total_size += sizeof(uint32_t);
|
|
@@ -3294,13 +3288,17 @@ Vector<uint8_t> RenderingDeviceDriverD3D12::shader_compile_binary_from_spirv(Vec
|
|
memcpy(binptr + offset, &binary_data, sizeof(ShaderBinary::Data));
|
|
memcpy(binptr + offset, &binary_data, sizeof(ShaderBinary::Data));
|
|
offset += sizeof(ShaderBinary::Data);
|
|
offset += sizeof(ShaderBinary::Data);
|
|
|
|
|
|
|
|
+#define ADVANCE_OFFSET_WITH_ALIGNMENT(m_bytes) \
|
|
|
|
+ { \
|
|
|
|
+ offset += m_bytes; \
|
|
|
|
+ uint32_t padding = STEPIFY(m_bytes, 4) - m_bytes; \
|
|
|
|
+ memset(binptr + offset, 0, padding); /* Avoid garbage data. */ \
|
|
|
|
+ offset += padding; \
|
|
|
|
+ }
|
|
|
|
+
|
|
if (binary_data.shader_name_len > 0) {
|
|
if (binary_data.shader_name_len > 0) {
|
|
memcpy(binptr + offset, shader_name_utf.ptr(), binary_data.shader_name_len);
|
|
memcpy(binptr + offset, shader_name_utf.ptr(), binary_data.shader_name_len);
|
|
- offset += binary_data.shader_name_len;
|
|
|
|
-
|
|
|
|
- if ((binary_data.shader_name_len % 4) != 0) { // Alignment rules are really strange.
|
|
|
|
- offset += 4 - (binary_data.shader_name_len % 4);
|
|
|
|
- }
|
|
|
|
|
|
+ ADVANCE_OFFSET_WITH_ALIGNMENT(binary_data.shader_name_len);
|
|
}
|
|
}
|
|
|
|
|
|
for (int i = 0; i < sets_bindings.size(); i++) {
|
|
for (int i = 0; i < sets_bindings.size(); i++) {
|
|
@@ -3326,14 +3324,7 @@ Vector<uint8_t> RenderingDeviceDriverD3D12::shader_compile_binary_from_spirv(Vec
|
|
encode_uint32(zstd_size[i], binptr + offset);
|
|
encode_uint32(zstd_size[i], binptr + offset);
|
|
offset += sizeof(uint32_t);
|
|
offset += sizeof(uint32_t);
|
|
memcpy(binptr + offset, compressed_stages[i].ptr(), compressed_stages[i].size());
|
|
memcpy(binptr + offset, compressed_stages[i].ptr(), compressed_stages[i].size());
|
|
-
|
|
|
|
- uint32_t s = compressed_stages[i].size();
|
|
|
|
-
|
|
|
|
- if (s % 4 != 0) {
|
|
|
|
- s += 4 - (s % 4);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- offset += s;
|
|
|
|
|
|
+ ADVANCE_OFFSET_WITH_ALIGNMENT(compressed_stages[i].size());
|
|
}
|
|
}
|
|
|
|
|
|
memcpy(binptr + offset, root_sig_blob->GetBufferPointer(), root_sig_blob->GetBufferSize());
|
|
memcpy(binptr + offset, root_sig_blob->GetBufferPointer(), root_sig_blob->GetBufferSize());
|
|
@@ -3382,10 +3373,7 @@ RDD::ShaderID RenderingDeviceDriverD3D12::shader_create_from_bytecode(const Vect
|
|
|
|
|
|
if (binary_data.shader_name_len) {
|
|
if (binary_data.shader_name_len) {
|
|
r_name.parse_utf8((const char *)(binptr + read_offset), binary_data.shader_name_len);
|
|
r_name.parse_utf8((const char *)(binptr + read_offset), binary_data.shader_name_len);
|
|
- read_offset += binary_data.shader_name_len;
|
|
|
|
- if ((binary_data.shader_name_len % 4) != 0) { // Alignment rules are really strange.
|
|
|
|
- read_offset += 4 - (binary_data.shader_name_len % 4);
|
|
|
|
- }
|
|
|
|
|
|
+ read_offset += STEPIFY(binary_data.shader_name_len, 4);
|
|
}
|
|
}
|
|
|
|
|
|
r_shader_desc.uniform_sets.resize(binary_data.set_count);
|
|
r_shader_desc.uniform_sets.resize(binary_data.set_count);
|
|
@@ -3458,6 +3446,7 @@ RDD::ShaderID RenderingDeviceDriverD3D12::shader_create_from_bytecode(const Vect
|
|
|
|
|
|
for (uint32_t i = 0; i < binary_data.stage_count; i++) {
|
|
for (uint32_t i = 0; i < binary_data.stage_count; i++) {
|
|
ERR_FAIL_COND_V(read_offset + sizeof(uint32_t) * 3 >= binsize, ShaderID());
|
|
ERR_FAIL_COND_V(read_offset + sizeof(uint32_t) * 3 >= binsize, ShaderID());
|
|
|
|
+
|
|
uint32_t stage = decode_uint32(binptr + read_offset);
|
|
uint32_t stage = decode_uint32(binptr + read_offset);
|
|
read_offset += sizeof(uint32_t);
|
|
read_offset += sizeof(uint32_t);
|
|
uint32_t dxil_size = decode_uint32(binptr + read_offset);
|
|
uint32_t dxil_size = decode_uint32(binptr + read_offset);
|
|
@@ -3472,13 +3461,9 @@ RDD::ShaderID RenderingDeviceDriverD3D12::shader_create_from_bytecode(const Vect
|
|
ERR_FAIL_COND_V(dec_dxil_size != (int32_t)dxil_size, ShaderID());
|
|
ERR_FAIL_COND_V(dec_dxil_size != (int32_t)dxil_size, ShaderID());
|
|
shader_info_in.stages_bytecode[ShaderStage(stage)] = dxil;
|
|
shader_info_in.stages_bytecode[ShaderStage(stage)] = dxil;
|
|
|
|
|
|
- if (zstd_size % 4 != 0) {
|
|
|
|
- zstd_size += 4 - (zstd_size % 4);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- ERR_FAIL_COND_V(read_offset + zstd_size > binsize, ShaderID());
|
|
|
|
-
|
|
|
|
|
|
+ zstd_size = STEPIFY(zstd_size, 4);
|
|
read_offset += zstd_size;
|
|
read_offset += zstd_size;
|
|
|
|
+ ERR_FAIL_COND_V(read_offset > binsize, ShaderID());
|
|
}
|
|
}
|
|
|
|
|
|
const uint8_t *root_sig_data_ptr = binptr + read_offset;
|
|
const uint8_t *root_sig_data_ptr = binptr + read_offset;
|