diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index d662d6b66..0990e2792 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -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 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 *byte_offset = load->byte_offset.node; const struct hlsl_ir_node *coords = load->coords.node; unsigned int coords_writemask = VKD3DSP_WRITEMASK_ALL; 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; bool tgsm = load->resource.var->is_tgsm; struct vkd3d_shader_instruction *ins; + bool multisampled, raw, structured; enum vkd3d_shader_opcode opcode; - bool multisampled, raw; 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 && (resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMS || resource_type->sampler_dim == HLSL_SAMPLER_DIM_2DMSARRAY); + structured = resource_type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER; 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."); return false; } + VKD3D_ASSERT(!(structured && multisampled)); - if (uav) + if (structured) + opcode = VSIR_OP_LD_STRUCTURED; + else if (uav) opcode = VSIR_OP_LD_UAV_TYPED; else if (raw) opcode = VSIR_OP_LD_RAW; else 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; 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); 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; - 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) vsir_src_from_hlsl_constant_value(&ins->src[2], ctx, diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 0ec6f626c..24a28886b 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4309,6 +4309,7 @@ static void tpf_handle_instruction(struct tpf_compiler *tpf, const struct vkd3d_ case VSIR_OP_LD: case VSIR_OP_LD2DMS: case VSIR_OP_LD_RAW: + case VSIR_OP_LD_STRUCTURED: case VSIR_OP_LD_UAV_TYPED: case VSIR_OP_LOG: case VSIR_OP_LOOP: diff --git a/tests/hlsl/srv-structuredbuffer.shader_test b/tests/hlsl/srv-structuredbuffer.shader_test index 6841335de..22ca01694 100644 --- a/tests/hlsl/srv-structuredbuffer.shader_test +++ b/tests/hlsl/srv-structuredbuffer.shader_test @@ -9,7 +9,7 @@ size (buffer, 4) 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 -[pixel shader todo] +[pixel shader] StructuredBuffer buffer; float4 main() : sv_target @@ -18,10 +18,10 @@ float4 main() : sv_target } [test] -todo(sm<6 | msl) draw quad +todo(msl | glsl) draw quad probe (0, 0) rgba(0.0, 1.0, 2.0, 3.0) -[pixel shader todo] +[pixel shader] struct banana { float2 x; @@ -38,10 +38,10 @@ float4 main() : sv_target [test] 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) 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) [srv 0] @@ -54,7 +54,7 @@ size (buffer, 5) 12.0 13.0 14.0 % Structured buffers are tightly packed. -[pixel shader todo] +[pixel shader] uniform uint idx; StructuredBuffer buffer; @@ -65,15 +65,15 @@ float4 main() : sv_target [test] 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) 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) % Also true for structs. -[pixel shader todo] +[pixel shader] struct banana { float2 x; @@ -90,13 +90,13 @@ float4 main() : sv_target [test] 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) 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) 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) % Matrices @@ -114,7 +114,7 @@ size (buffer, 2) 24.0 25.0 26.0 27.0 28.0 29.0 30.0 31.0 -[pixel shader todo] +[pixel shader] StructuredBuffer buf; uniform uint buf_idx; @@ -128,20 +128,20 @@ float4 main() : sv_target [test] uniform 0 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) uniform 0 uint 0 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) uniform 0 uint 1 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) -[pixel shader todo] +[pixel shader] struct container { row_major float4x4 m; @@ -160,20 +160,20 @@ float4 main() : sv_target [test] uniform 0 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) uniform 0 uint 0 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) uniform 0 uint 1 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) -[pixel shader todo] +[pixel shader] StructuredBuffer buf; uniform uint buf_idx; @@ -185,14 +185,14 @@ float4 main() : sv_target [test] 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) 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) -[pixel shader todo] +[pixel shader] typedef row_major float4x4 rm_float4x4; StructuredBuffer buf; @@ -205,12 +205,12 @@ float4 main() : sv_target [test] 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(1.0, 2.0, 0.0, 4.0) 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(17.0, 18.0, 16.0, 20.0) @@ -225,7 +225,7 @@ size (buffer, 2) 9.0 10.0 11.0 12.0 -[pixel shader todo] +[pixel shader] StructuredBuffer buf; uniform uint buf_idx; @@ -239,20 +239,20 @@ float4 main() : sv_target [test] uniform 0 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) uniform 0 uint 0 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) uniform 0 uint 1 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) -[pixel shader todo] +[pixel shader] typedef row_major float2x3 rm_float2x3; StructuredBuffer buf; @@ -267,23 +267,23 @@ float4 main() : sv_target [test] uniform 0 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, 3.0, 5.0, 1.0) uniform 0 uint 0 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(2.0, 4.0, 6.0, 1.0) uniform 0 uint 1 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, 9.0, 11.0, 1.0) -[pixel shader todo] +[pixel shader] StructuredBuffer buf; uniform uint buf_idx; @@ -295,14 +295,14 @@ float4 main() : sv_target [test] 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) 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) -[pixel shader todo] +[pixel shader] typedef row_major float2x3 rm_float2x3; StructuredBuffer buf; @@ -315,12 +315,12 @@ float4 main() : sv_target [test] 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(4.0, 6.0, 5.0, 1.0) 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(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 10.0 11.0 12.0 13.0 14.0 -[pixel shader todo] +[pixel shader] struct banana { float x[4]; @@ -350,17 +350,17 @@ float4 main() : sv_target [test] uniform 0 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) uniform 0 uint 0 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) uniform 0 uint 1 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) % Same values as above, but mixed float and int. @@ -371,7 +371,7 @@ size (buffer, 3) 5.0 6.0 7 8 9 10.0 11.0 12 13 14 -[pixel shader todo] +[pixel shader] struct banana { float2 x; @@ -388,14 +388,14 @@ float4 main() : sv_target [test] 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) 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) % Nested structs. -[pixel shader todo] +[pixel shader] struct floats { float x; @@ -425,13 +425,13 @@ float4 main() : sv_target [test] 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) 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) -[pixel shader todo] +[pixel shader] struct apple { float x; @@ -466,10 +466,10 @@ float4 main() : sv_target [test] 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) 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) % Check that an index load of a non-structured resource load