vkd3d-shader/spirv: Clamp push constant CBV sizes to those of the push constant ranges backing them.

Otherwise invalid SPIR-V may be generated, because the CBV field in
"push_cb_struct" may end up overlapping with a subsequent one.
This commit is contained in:
Giovanni Mascellani
2025-11-12 13:43:59 +01:00
committed by Henri Verbeet
parent 2903831f79
commit 7f377879fc
Notes: Henri Verbeet 2025-11-12 15:31:45 +01:00
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1826
3 changed files with 11 additions and 5 deletions

View File

@@ -6668,13 +6668,18 @@ static void spirv_compiler_emit_cbv_declaration(struct spirv_compiler *compiler,
/* Push constant buffers are handled in /* Push constant buffers are handled in
* spirv_compiler_emit_push_constant_buffers(). * spirv_compiler_emit_push_constant_buffers().
*/ */
push_cb->reg = reg;
push_cb->size = size;
if (size_in_bytes > push_cb->pc.size) if (size_in_bytes > push_cb->pc.size)
{ {
WARN("Constant buffer size %u exceeds push constant size %u.\n", spirv_compiler_warning(compiler, VKD3D_SHADER_WARNING_SPV_INVALID_SIZE,
size_in_bytes, push_cb->pc.size); "Constant buffer cb%u, space %u, has size %u which exceeds the push constant size %u.",
push_cb->pc.register_index, push_cb->pc.register_space, size_in_bytes, push_cb->pc.size);
size_in_bytes = push_cb->pc.size;
size = align(size_in_bytes, VKD3D_VEC4_SIZE * sizeof(uint32_t));
size /= VKD3D_VEC4_SIZE * sizeof(uint32_t);
} }
push_cb->reg = reg;
push_cb->size = size;
return; return;
} }

View File

@@ -110,6 +110,7 @@ enum vkd3d_shader_error
VKD3D_SHADER_WARNING_SPV_INVALID_SWIZZLE = 2300, VKD3D_SHADER_WARNING_SPV_INVALID_SWIZZLE = 2300,
VKD3D_SHADER_WARNING_SPV_INVALID_UAV_FLAGS = 2301, VKD3D_SHADER_WARNING_SPV_INVALID_UAV_FLAGS = 2301,
VKD3D_SHADER_WARNING_SPV_IGNORING_FLAG = 2302, VKD3D_SHADER_WARNING_SPV_IGNORING_FLAG = 2302,
VKD3D_SHADER_WARNING_SPV_INVALID_SIZE = 2303,
VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY = 3000, VKD3D_SHADER_ERROR_RS_OUT_OF_MEMORY = 3000,
VKD3D_SHADER_ERROR_RS_INVALID_VERSION = 3001, VKD3D_SHADER_ERROR_RS_INVALID_VERSION = 3001,

View File

@@ -22,7 +22,7 @@ float4 main() : SV_Target
[test] [test]
uniform 0 float4 1.0 2.0 3.0 4.0 uniform 0 float4 1.0 2.0 3.0 4.0
todo(d3d12 & !windows & !mvk) draw quad draw quad
probe (0, 0) f32(2.0, 3.0, 4.0, 5.0) probe (0, 0) f32(2.0, 3.0, 4.0, 5.0)
[require] [require]