vkd3d-shader/hlsl: Emit vsir structured loads.

This commit is contained in:
Victor Chiletto
2025-02-27 17:44:37 -03:00
committed by Henri Verbeet
parent ae450e5957
commit 8698874628
Notes: Henri Verbeet 2025-09-04 14:11:02 +02:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1699
3 changed files with 70 additions and 64 deletions

View File

@@ -11735,6 +11735,7 @@ static bool sm4_generate_vsir_instr_ld(struct hlsl_ctx *ctx,
const struct vkd3d_shader_version *version = &program->shader_version; const struct vkd3d_shader_version *version = &program->shader_version;
const struct hlsl_ir_node *sample_index = load->sample_index.node; const struct hlsl_ir_node *sample_index = load->sample_index.node;
const struct hlsl_ir_node *texel_offset = load->texel_offset.node; const struct hlsl_ir_node *texel_offset = load->texel_offset.node;
const struct hlsl_ir_node *byte_offset = load->byte_offset.node;
const struct hlsl_ir_node *coords = load->coords.node; const struct hlsl_ir_node *coords = load->coords.node;
unsigned int coords_writemask = VKD3DSP_WRITEMASK_ALL; unsigned int coords_writemask = VKD3DSP_WRITEMASK_ALL;
const struct hlsl_deref *resource = &load->resource; const struct hlsl_deref *resource = &load->resource;
@@ -11742,20 +11743,15 @@ static bool sm4_generate_vsir_instr_ld(struct hlsl_ctx *ctx,
enum hlsl_sampler_dim dim = load->sampling_dim; enum hlsl_sampler_dim dim = load->sampling_dim;
bool tgsm = load->resource.var->is_tgsm; bool tgsm = load->resource.var->is_tgsm;
struct vkd3d_shader_instruction *ins; struct vkd3d_shader_instruction *ins;
bool multisampled, raw, structured;
enum vkd3d_shader_opcode opcode; enum vkd3d_shader_opcode opcode;
bool multisampled, raw;
VKD3D_ASSERT(load->load_type == HLSL_RESOURCE_LOAD); VKD3D_ASSERT(load->load_type == HLSL_RESOURCE_LOAD);
if (resource_type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER)
{
hlsl_fixme(ctx, &load->node.loc, "Structured buffer loads.");
return false;
}
multisampled = resource_type->class == HLSL_CLASS_TEXTURE multisampled = resource_type->class == HLSL_CLASS_TEXTURE
&& (resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS && (resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS
|| resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY); || resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY);
structured = resource_type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER;
if (!tgsm) if (!tgsm)
{ {
@@ -11766,15 +11762,19 @@ static bool sm4_generate_vsir_instr_ld(struct hlsl_ctx *ctx,
hlsl_fixme(ctx, &load->node.loc, "Load from structured TGSM."); hlsl_fixme(ctx, &load->node.loc, "Load from structured TGSM.");
return false; return false;
} }
VKD3D_ASSERT(!(structured && multisampled));
if (uav) if (structured)
opcode = VSIR_OP_LD_STRUCTURED;
else if (uav)
opcode = VSIR_OP_LD_UAV_TYPED; opcode = VSIR_OP_LD_UAV_TYPED;
else if (raw) else if (raw)
opcode = VSIR_OP_LD_RAW; opcode = VSIR_OP_LD_RAW;
else else
opcode = multisampled ? VSIR_OP_LD2DMS : VSIR_OP_LD; opcode = multisampled ? VSIR_OP_LD2DMS : VSIR_OP_LD;
if (!(ins = generate_vsir_add_program_instruction(ctx, program, &instr->loc, opcode, 1, 2 + multisampled))) if (!(ins = generate_vsir_add_program_instruction(ctx, program,
&instr->loc, opcode, 1, 2 + multisampled + structured)))
return false; return false;
if (texel_offset && !sm4_generate_vsir_validate_texel_offset_aoffimmi(texel_offset)) if (texel_offset && !sm4_generate_vsir_validate_texel_offset_aoffimmi(texel_offset))
@@ -11802,10 +11802,15 @@ static bool sm4_generate_vsir_instr_ld(struct hlsl_ctx *ctx,
vsir_src_from_hlsl_node(&ins->src[0], ctx, coords, coords_writemask); vsir_src_from_hlsl_node(&ins->src[0], ctx, coords, coords_writemask);
if (!sm4_generate_vsir_init_src_param_from_deref(ctx, program, if (!sm4_generate_vsir_init_src_param_from_deref(ctx, program,
&ins->src[1], resource, ins->dst[0].write_mask, &instr->loc)) &ins->src[structured ? 2 : 1], resource, ins->dst[0].write_mask, &instr->loc))
return false; return false;
if (multisampled) if (structured)
{
VKD3D_ASSERT(byte_offset);
vsir_src_from_hlsl_node(&ins->src[1], ctx, byte_offset, VKD3DSP_WRITEMASK_ALL);
}
else if (multisampled)
{ {
if (sample_index->type == HLSL_IR_CONSTANT) if (sample_index->type == HLSL_IR_CONSTANT)
vsir_src_from_hlsl_constant_value(&ins->src[2], ctx, vsir_src_from_hlsl_constant_value(&ins->src[2], ctx,

View File

@@ -4309,6 +4309,7 @@ static void tpf_handle_instruction(struct tpf_compiler *tpf, const struct vkd3d_
case VSIR_OP_LD: case VSIR_OP_LD:
case VSIR_OP_LD2DMS: case VSIR_OP_LD2DMS:
case VSIR_OP_LD_RAW: case VSIR_OP_LD_RAW:
case VSIR_OP_LD_STRUCTURED:
case VSIR_OP_LD_UAV_TYPED: case VSIR_OP_LD_UAV_TYPED:
case VSIR_OP_LOG: case VSIR_OP_LOG:
case VSIR_OP_LOOP: case VSIR_OP_LOOP:

View File

@@ -9,7 +9,7 @@ size (buffer, 4)
8.0 9.0 10.0 11.0 8.0 9.0 10.0 11.0
12.0 13.0 14.0 15.0 12.0 13.0 14.0 15.0
[pixel shader todo] [pixel shader]
StructuredBuffer<float4> buffer; StructuredBuffer<float4> buffer;
float4 main() : sv_target float4 main() : sv_target
@@ -18,10 +18,10 @@ float4 main() : sv_target
} }
[test] [test]
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0) probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0)
[pixel shader todo] [pixel shader]
struct banana struct banana
{ {
float2 x; float2 x;
@@ -38,10 +38,10 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0) probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0)
uniform 0 uint 1 uniform 0 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(4.0, 5.0, 6.0, 7.0) probe (0, 0) rgba(4.0, 5.0, 6.0, 7.0)
[srv 0] [srv 0]
@@ -54,7 +54,7 @@ size (buffer, 5)
12.0 13.0 14.0 12.0 13.0 14.0
% Structured buffers are tightly packed. % Structured buffers are tightly packed.
[pixel shader todo] [pixel shader]
uniform uint idx; uniform uint idx;
StructuredBuffer<float3> buffer; StructuredBuffer<float3> buffer;
@@ -65,15 +65,15 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(0.0, 1.0, 2.0, 1.0) probe (0, 0) rgba(0.0, 1.0, 2.0, 1.0)
uniform 0 uint 1 uniform 0 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(3.0, 4.0, 5.0, 1.0) probe (0, 0) rgba(3.0, 4.0, 5.0, 1.0)
% Also true for structs. % Also true for structs.
[pixel shader todo] [pixel shader]
struct banana struct banana
{ {
float2 x; float2 x;
@@ -90,13 +90,13 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 2 uniform 0 uint 2
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(6.0, 7.0, 8.0, 2.0) probe (0, 0) rgba(6.0, 7.0, 8.0, 2.0)
uniform 0 uint 3 uniform 0 uint 3
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(9.0, 10.0, 11.0, 3.0) probe (0, 0) rgba(9.0, 10.0, 11.0, 3.0)
uniform 0 uint 4 uniform 0 uint 4
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(12.0, 13.0, 14.0, 4.0) probe (0, 0) rgba(12.0, 13.0, 14.0, 4.0)
% Matrices % Matrices
@@ -114,7 +114,7 @@ size (buffer, 2)
24.0 25.0 26.0 27.0 24.0 25.0 26.0 27.0
28.0 29.0 30.0 31.0 28.0 29.0 30.0 31.0
[pixel shader todo] [pixel shader]
StructuredBuffer<float4x4> buf; StructuredBuffer<float4x4> buf;
uniform uint buf_idx; uniform uint buf_idx;
@@ -128,20 +128,20 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
uniform 1 uint 0 uniform 1 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(0.0, 4.0, 8.0, 12.0) probe (0, 0) rgba(0.0, 4.0, 8.0, 12.0)
uniform 0 uint 0 uniform 0 uint 0
uniform 1 uint 1 uniform 1 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(1.0, 5.0, 9.0, 13.0) probe (0, 0) rgba(1.0, 5.0, 9.0, 13.0)
uniform 0 uint 1 uniform 0 uint 1
uniform 1 uint 0 uniform 1 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(16.0, 20.0, 24.0, 28.0) probe (0, 0) rgba(16.0, 20.0, 24.0, 28.0)
[pixel shader todo] [pixel shader]
struct container struct container
{ {
row_major float4x4 m; row_major float4x4 m;
@@ -160,20 +160,20 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
uniform 1 uint 0 uniform 1 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0) probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0)
uniform 0 uint 0 uniform 0 uint 0
uniform 1 uint 1 uniform 1 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(4.0, 5.0, 6.0, 7.0) probe (0, 0) rgba(4.0, 5.0, 6.0, 7.0)
uniform 0 uint 1 uniform 0 uint 1
uniform 1 uint 0 uniform 1 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(16.0, 17.0, 18.0, 19.0) probe (0, 0) rgba(16.0, 17.0, 18.0, 19.0)
[pixel shader todo] [pixel shader]
StructuredBuffer<float4x4> buf; StructuredBuffer<float4x4> buf;
uniform uint buf_idx; uniform uint buf_idx;
@@ -185,14 +185,14 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(1.0, 2.0, 0.0, 4.0) probe (0, 0) rgba(1.0, 2.0, 0.0, 4.0)
uniform 0 uint 1 uniform 0 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(17.0, 18.0, 16.0, 20.0) probe (0, 0) rgba(17.0, 18.0, 16.0, 20.0)
[pixel shader todo] [pixel shader]
typedef row_major float4x4 rm_float4x4; typedef row_major float4x4 rm_float4x4;
StructuredBuffer<rm_float4x4> buf; StructuredBuffer<rm_float4x4> buf;
@@ -205,12 +205,12 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
if(sm<6) probe (0, 0) rgba(4.0, 8.0, 0.0, 1.0) if(sm<6) probe (0, 0) rgba(4.0, 8.0, 0.0, 1.0)
if(sm>=6) probe (0, 0) rgba(1.0, 2.0, 0.0, 4.0) if(sm>=6) probe (0, 0) rgba(1.0, 2.0, 0.0, 4.0)
uniform 0 uint 1 uniform 0 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
if(sm<6) probe (0, 0) rgba(20.0, 24.0, 16.0, 17.0) if(sm<6) probe (0, 0) rgba(20.0, 24.0, 16.0, 17.0)
if(sm>=6) probe (0, 0) rgba(17.0, 18.0, 16.0, 20.0) if(sm>=6) probe (0, 0) rgba(17.0, 18.0, 16.0, 20.0)
@@ -225,7 +225,7 @@ size (buffer, 2)
9.0 10.0 9.0 10.0
11.0 12.0 11.0 12.0
[pixel shader todo] [pixel shader]
StructuredBuffer<float2x3> buf; StructuredBuffer<float2x3> buf;
uniform uint buf_idx; uniform uint buf_idx;
@@ -239,20 +239,20 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
uniform 1 uint 0 uniform 1 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(1.0, 3.0, 5.0, 1.0) probe (0, 0) rgba(1.0, 3.0, 5.0, 1.0)
uniform 0 uint 0 uniform 0 uint 0
uniform 1 uint 1 uniform 1 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(2.0, 4.0, 6.0, 1.0) probe (0, 0) rgba(2.0, 4.0, 6.0, 1.0)
uniform 0 uint 1 uniform 0 uint 1
uniform 1 uint 0 uniform 1 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe(0, 0) rgba(7.0, 9.0, 11.0, 1.0) probe(0, 0) rgba(7.0, 9.0, 11.0, 1.0)
[pixel shader todo] [pixel shader]
typedef row_major float2x3 rm_float2x3; typedef row_major float2x3 rm_float2x3;
StructuredBuffer<rm_float2x3> buf; StructuredBuffer<rm_float2x3> buf;
@@ -267,23 +267,23 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
uniform 1 uint 0 uniform 1 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
if(sm<6) probe (0, 0) rgba(1.0, 2.0, 3.0, 1.0) if(sm<6) probe (0, 0) rgba(1.0, 2.0, 3.0, 1.0)
if(sm>=6) probe (0, 0) rgba(1.0, 3.0, 5.0, 1.0) if(sm>=6) probe (0, 0) rgba(1.0, 3.0, 5.0, 1.0)
uniform 0 uint 0 uniform 0 uint 0
uniform 1 uint 1 uniform 1 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
if(sm<6) probe (0, 0) rgba(4.0, 5.0, 6.0, 1.0) if(sm<6) probe (0, 0) rgba(4.0, 5.0, 6.0, 1.0)
if(sm>=6) probe (0, 0) rgba(2.0, 4.0, 6.0, 1.0) if(sm>=6) probe (0, 0) rgba(2.0, 4.0, 6.0, 1.0)
uniform 0 uint 1 uniform 0 uint 1
uniform 1 uint 0 uniform 1 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
if(sm<6) probe(0, 0) rgba(7.0, 8.0, 9.0, 1.0) if(sm<6) probe(0, 0) rgba(7.0, 8.0, 9.0, 1.0)
if(sm>=6) probe(0, 0) rgba(7.0, 9.0, 11.0, 1.0) if(sm>=6) probe(0, 0) rgba(7.0, 9.0, 11.0, 1.0)
[pixel shader todo] [pixel shader]
StructuredBuffer<float2x3> buf; StructuredBuffer<float2x3> buf;
uniform uint buf_idx; uniform uint buf_idx;
@@ -295,14 +295,14 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) f32(4.0, 6.0, 5.0, 1.0) probe (0, 0) f32(4.0, 6.0, 5.0, 1.0)
uniform 0 uint 1 uniform 0 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) f32(10.0, 12.0, 11.0, 1) probe (0, 0) f32(10.0, 12.0, 11.0, 1)
[pixel shader todo] [pixel shader]
typedef row_major float2x3 rm_float2x3; typedef row_major float2x3 rm_float2x3;
StructuredBuffer<rm_float2x3> buf; StructuredBuffer<rm_float2x3> buf;
@@ -315,12 +315,12 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
if(sm<6) probe (0, 0) f32(5.0, 6.0, 3.0, 1.0) if(sm<6) probe (0, 0) f32(5.0, 6.0, 3.0, 1.0)
if(sm>=6) probe (0, 0) f32(4.0, 6.0, 5.0, 1.0) if(sm>=6) probe (0, 0) f32(4.0, 6.0, 5.0, 1.0)
uniform 0 uint 1 uniform 0 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
if(sm<6) probe (0, 0) f32(11.0, 12.0, 9.0, 1.0) if(sm<6) probe (0, 0) f32(11.0, 12.0, 9.0, 1.0)
if(sm>=6) probe (0, 0) f32(10.0, 12.0, 11.0, 1.0) if(sm>=6) probe (0, 0) f32(10.0, 12.0, 11.0, 1.0)
@@ -331,7 +331,7 @@ size (buffer, 3)
5.0 6.0 7.0 8.0 9.0 5.0 6.0 7.0 8.0 9.0
10.0 11.0 12.0 13.0 14.0 10.0 11.0 12.0 13.0 14.0
[pixel shader todo] [pixel shader]
struct banana struct banana
{ {
float x[4]; float x[4];
@@ -350,17 +350,17 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
uniform 1 uint 0 uniform 1 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(0.0, 4.0, 0.0, 0.0) probe (0, 0) rgba(0.0, 4.0, 0.0, 0.0)
uniform 0 uint 0 uniform 0 uint 0
uniform 1 uint 1 uniform 1 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(1.0, 4.0, 0.0, 1.0) probe (0, 0) rgba(1.0, 4.0, 0.0, 1.0)
uniform 0 uint 1 uniform 0 uint 1
uniform 1 uint 0 uniform 1 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(5.0, 9.0, 1.0, 0.0) probe (0, 0) rgba(5.0, 9.0, 1.0, 0.0)
% Same values as above, but mixed float and int. % Same values as above, but mixed float and int.
@@ -371,7 +371,7 @@ size (buffer, 3)
5.0 6.0 7 8 9 5.0 6.0 7 8 9
10.0 11.0 12 13 14 10.0 11.0 12 13 14
[pixel shader todo] [pixel shader]
struct banana struct banana
{ {
float2 x; float2 x;
@@ -388,14 +388,14 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0) probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0)
uniform 0 uint 1 uniform 0 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(5.0, 6.0, 7.0, 8.0) probe (0, 0) rgba(5.0, 6.0, 7.0, 8.0)
% Nested structs. % Nested structs.
[pixel shader todo] [pixel shader]
struct floats struct floats
{ {
float x; float x;
@@ -425,13 +425,13 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0) probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0)
uniform 0 uint 1 uniform 0 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(5.0, 6.0, 7.0, 8.0) probe (0, 0) rgba(5.0, 6.0, 7.0, 8.0)
[pixel shader todo] [pixel shader]
struct apple struct apple
{ {
float x; float x;
@@ -466,10 +466,10 @@ float4 main() : sv_target
[test] [test]
uniform 0 uint 0 uniform 0 uint 0
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0) probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0)
uniform 0 uint 1 uniform 0 uint 1
todo(sm<6 | msl) draw quad todo(msl | glsl) draw quad
probe (0, 0) rgba(5.0, 6.0, 7.0, 8.0) probe (0, 0) rgba(5.0, 6.0, 7.0, 8.0)
% Check that an index load of a non-structured resource load % Check that an index load of a non-structured resource load