From 2330ffdedae8c1f675151ba6118092034f30b31d Mon Sep 17 00:00:00 2001 From: Conor McCarthy Date: Wed, 21 Feb 2024 14:10:47 +1000 Subject: [PATCH] vkd3d-shader/dxil: Implement DX intrinsics SampleBias and SampleLevel. --- libs/vkd3d-shader/dxil.c | 17 +++++++++++++++-- tests/hlsl/sample-bias.shader_test | 6 +++--- tests/hlsl/sample-level.shader_test | 6 +++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c index 93ed3e06..bcd83f51 100644 --- a/libs/vkd3d-shader/dxil.c +++ b/libs/vkd3d-shader/dxil.c @@ -379,6 +379,8 @@ enum dx_intrinsic_opcode DX_CREATE_HANDLE = 57, DX_CBUFFER_LOAD_LEGACY = 59, DX_SAMPLE = 60, + DX_SAMPLE_B = 61, + DX_SAMPLE_LOD = 62, DX_SAMPLE_GRAD = 63, DX_TEXTURE_LOAD = 66, DX_TEXTURE_STORE = 67, @@ -4338,7 +4340,7 @@ static void sm6_parser_emit_dx_sample(struct sm6_parser *sm6, enum dx_intrinsic_ const struct sm6_value *resource, *sampler; struct vkd3d_shader_src_param *src_params; struct vkd3d_shader_instruction *ins; - unsigned int clamp_idx; + unsigned int clamp_idx = 0; resource = operands[0]; sampler = operands[1]; @@ -4367,6 +4369,15 @@ static void sm6_parser_emit_dx_sample(struct sm6_parser *sm6, enum dx_intrinsic_ src_params = instruction_src_params_alloc(ins, 3, sm6); clamp_idx = 9; break; + case DX_SAMPLE_B: + clamp_idx = 10; + /* fall through */ + case DX_SAMPLE_LOD: + instruction_init_with_resource(ins, (op == DX_SAMPLE_B) ? VKD3DSIH_SAMPLE_B : VKD3DSIH_SAMPLE_LOD, + resource, sm6); + src_params = instruction_src_params_alloc(ins, 4, sm6); + src_param_init_from_value(&src_params[3], operands[9]); + break; case DX_SAMPLE_GRAD: instruction_init_with_resource(ins, VKD3DSIH_SAMPLE_GRAD, resource, sm6); src_params = instruction_src_params_alloc(ins, 5, sm6); @@ -4381,7 +4392,7 @@ static void sm6_parser_emit_dx_sample(struct sm6_parser *sm6, enum dx_intrinsic_ if (!src_params) return; - if (!sm6_value_is_undef(operands[clamp_idx])) + if (clamp_idx && !sm6_value_is_undef(operands[clamp_idx])) { FIXME("Ignoring LOD clamp value.\n"); vkd3d_shader_parser_warning(&sm6->p, VKD3D_SHADER_WARNING_DXIL_IGNORING_OPERANDS, @@ -4654,7 +4665,9 @@ static const struct sm6_dx_opcode_info sm6_dx_op_table[] = [DX_ROUND_Z ] = {"g", "R", sm6_parser_emit_dx_unary}, [DX_RSQRT ] = {"g", "R", sm6_parser_emit_dx_unary}, [DX_SAMPLE ] = {"o", "HHffffiiif", sm6_parser_emit_dx_sample}, + [DX_SAMPLE_B ] = {"o", "HHffffiiiff", sm6_parser_emit_dx_sample}, [DX_SAMPLE_GRAD ] = {"o", "HHffffiiifffffff", sm6_parser_emit_dx_sample}, + [DX_SAMPLE_LOD ] = {"o", "HHffffiiif", sm6_parser_emit_dx_sample}, [DX_SIN ] = {"g", "R", sm6_parser_emit_dx_sincos}, [DX_SPLIT_DOUBLE ] = {"S", "d", sm6_parser_emit_dx_split_double}, [DX_SQRT ] = {"g", "R", sm6_parser_emit_dx_unary}, diff --git a/tests/hlsl/sample-bias.shader_test b/tests/hlsl/sample-bias.shader_test index 0d446af9..b63be727 100644 --- a/tests/hlsl/sample-bias.shader_test +++ b/tests/hlsl/sample-bias.shader_test @@ -32,13 +32,13 @@ float4 main(float2 coord : texcoord) : sv_target [test] uniform 0 float4 6.5 0.0 0.0 0.0 -todo(sm<4 | sm>=6) draw quad +todo(sm<4) draw quad probe all rgba (10.0, 0.0, 10.0, 0.0) uniform 0 float4 7.5 0.0 0.0 0.0 -todo(sm<4 | sm>=6) draw quad +todo(sm<4) draw quad probe all rgba (4.0, 0.0, 10.0, 0.0) uniform 0 float4 8.5 0.0 0.0 0.0 -todo(sm<4 | sm>=6) draw quad +todo(sm<4) draw quad probe all rgba (0.0, 0.0, 10.0, 0.0) diff --git a/tests/hlsl/sample-level.shader_test b/tests/hlsl/sample-level.shader_test index 71ffc07f..66a51986 100644 --- a/tests/hlsl/sample-level.shader_test +++ b/tests/hlsl/sample-level.shader_test @@ -26,13 +26,13 @@ float4 main() : sv_target [test] uniform 0 float4 0.0 0.0 0.0 0.0 -todo(sm<4 | sm>=6) draw quad +todo(sm<4) draw quad probe all rgba (1.0, 0.0, 1.0, 0.0) uniform 0 float4 0.5 0.0 0.0 0.0 -todo(sm<4 | sm>=6) draw quad +todo(sm<4) draw quad probe all rgba (0.5, 0.0, 1.0, 0.0) uniform 0 float4 1.0 0.0 0.0 0.0 -todo(sm<4 | sm>=6) draw quad +todo(sm<4) draw quad probe all rgba (0.0, 0.0, 1.0, 0.0) [require]