@@ -3441,7 +3441,7 @@ Vector<uint8_t> RenderingDeviceDriverVulkan::shader_compile_binary_from_spirv(Ve
3441
3441
3442
3442
binary_data.shader_name_len = shader_name_utf.length ();
3443
3443
3444
- uint32_t total_size = sizeof (uint32_t ) * 3 ; // Header + version + main datasize;.
3444
+ uint32_t total_size = sizeof (uint32_t ) * 4 ; // Header + version + pad + main datasize;.
3445
3445
total_size += sizeof (ShaderBinary::Data);
3446
3446
3447
3447
total_size += STEPIFY (binary_data.shader_name_len , 4 );
@@ -3470,6 +3470,8 @@ Vector<uint8_t> RenderingDeviceDriverVulkan::shader_compile_binary_from_spirv(Ve
3470
3470
offset += sizeof (uint32_t );
3471
3471
encode_uint32 (sizeof (ShaderBinary::Data), binptr + offset);
3472
3472
offset += sizeof (uint32_t );
3473
+ encode_uint32 (0 , binptr + offset); // Pad to align ShaderBinary::Data to 8 bytes.
3474
+ offset += sizeof (uint32_t );
3473
3475
memcpy (binptr + offset, &binary_data, sizeof (ShaderBinary::Data));
3474
3476
offset += sizeof (ShaderBinary::Data);
3475
3477
@@ -3528,15 +3530,16 @@ RDD::ShaderID RenderingDeviceDriverVulkan::shader_create_from_bytecode(const Vec
3528
3530
uint32_t read_offset = 0 ;
3529
3531
3530
3532
// Consistency check.
3531
- ERR_FAIL_COND_V (binsize < sizeof (uint32_t ) * 3 + sizeof (ShaderBinary::Data), ShaderID ());
3533
+ ERR_FAIL_COND_V (binsize < sizeof (uint32_t ) * 4 + sizeof (ShaderBinary::Data), ShaderID ());
3532
3534
ERR_FAIL_COND_V (binptr[0 ] != ' G' || binptr[1 ] != ' S' || binptr[2 ] != ' B' || binptr[3 ] != ' D' , ShaderID ());
3533
3535
3534
3536
uint32_t bin_version = decode_uint32 (binptr + 4 );
3535
3537
ERR_FAIL_COND_V (bin_version != ShaderBinary::VERSION, ShaderID ());
3536
3538
3537
3539
uint32_t bin_data_size = decode_uint32 (binptr + 8 );
3538
3540
3539
- const ShaderBinary::Data &binary_data = *(reinterpret_cast <const ShaderBinary::Data *>(binptr + 12 ));
3541
+ // 16, not 12, to skip alignment padding.
3542
+ const ShaderBinary::Data &binary_data = *(reinterpret_cast <const ShaderBinary::Data *>(binptr + 16 ));
3540
3543
3541
3544
r_shader_desc.push_constant_size = binary_data.push_constant_size ;
3542
3545
shader_info.vk_push_constant_stages = binary_data.vk_push_constant_stages_mask ;
@@ -3549,7 +3552,7 @@ RDD::ShaderID RenderingDeviceDriverVulkan::shader_create_from_bytecode(const Vec
3549
3552
r_shader_desc.compute_local_size [1 ] = binary_data.compute_local_size [1 ];
3550
3553
r_shader_desc.compute_local_size [2 ] = binary_data.compute_local_size [2 ];
3551
3554
3552
- read_offset += sizeof (uint32_t ) * 3 + bin_data_size;
3555
+ read_offset += sizeof (uint32_t ) * 4 + bin_data_size;
3553
3556
3554
3557
if (binary_data.shader_name_len ) {
3555
3558
r_name.parse_utf8 ((const char *)(binptr + read_offset), binary_data.shader_name_len );
0 commit comments