Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
-- v6: vkd3d-shader/hlsl: Add tex2Dlod() function.
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 46 ++++++++++++++++++++++++++--- tests/hlsl/sample-level.shader_test | 24 +++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 0e72a539e..77f6eaedb 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3547,7 +3547,7 @@ static bool intrinsic_tan(struct hlsl_ctx *ctx, static bool intrinsic_tex(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc, const char *name, enum hlsl_sampler_dim dim) { - struct hlsl_resource_load_params load_params = {.type = HLSL_RESOURCE_SAMPLE}; + struct hlsl_resource_load_params load_params = { 0 }; const struct hlsl_type *sampler_type; struct hlsl_ir_node *coords, *load;
@@ -3576,10 +3576,41 @@ static bool intrinsic_tex(struct hlsl_ctx *ctx, const struct parse_initializer * hlsl_release_string_buffer(ctx, string); }
- if (!(coords = add_implicit_conversion(ctx, params->instrs, params->args[1], - hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, hlsl_sampler_dim_count(dim)), loc))) + if (!strcmp(name, "tex2Dlod")) { - return false; + struct hlsl_ir_node *lod, *c; + + load_params.type = HLSL_RESOURCE_SAMPLE_LOD; + + if (!(c = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, Y, Z, W), hlsl_sampler_dim_count(dim), params->args[1], loc))) + return false; + hlsl_block_add_instr(params->instrs, c); + + if (!(coords = add_implicit_conversion(ctx, params->instrs, c, hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, + hlsl_sampler_dim_count(dim)), loc))) + { + return false; + } + + if (!(lod = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(W, W, W, W), 1, params->args[1], loc))) + return false; + hlsl_block_add_instr(params->instrs, lod); + + if (!(load_params.lod = add_implicit_conversion(ctx, params->instrs, lod, + hlsl_get_scalar_type(ctx, HLSL_TYPE_FLOAT), loc))) + { + return false; + } + } + else + { + load_params.type = HLSL_RESOURCE_SAMPLE; + + if (!(coords = add_implicit_conversion(ctx, params->instrs, params->args[1], + hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, hlsl_sampler_dim_count(dim)), loc))) + { + return false; + } }
/* tex1D() functions never produce 1D resource declarations. For newer profiles half offset @@ -3638,6 +3669,12 @@ static bool intrinsic_tex2D(struct hlsl_ctx *ctx, return intrinsic_tex(ctx, params, loc, "tex2D", HLSL_SAMPLER_DIM_2D); }
+static bool intrinsic_tex2Dlod(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + return intrinsic_tex(ctx, params, loc, "tex2Dlod", HLSL_SAMPLER_DIM_2D); +} + static bool intrinsic_tex3D(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -3822,6 +3859,7 @@ intrinsic_functions[] = {"tan", 1, true, intrinsic_tan}, {"tex1D", -1, false, intrinsic_tex1D}, {"tex2D", -1, false, intrinsic_tex2D}, + {"tex2Dlod", 2, false, intrinsic_tex2Dlod}, {"tex3D", -1, false, intrinsic_tex3D}, {"texCUBE", -1, false, intrinsic_texCUBE}, {"transpose", 1, true, intrinsic_transpose}, diff --git a/tests/hlsl/sample-level.shader_test b/tests/hlsl/sample-level.shader_test index c91c65493..8b2890ff7 100644 --- a/tests/hlsl/sample-level.shader_test +++ b/tests/hlsl/sample-level.shader_test @@ -34,3 +34,27 @@ probe all rgba (0.5, 0.0, 1.0, 0.0) uniform 0 float4 1.0 0.0 0.0 0.0 todo(sm>=6) draw quad probe all rgba (0.0, 0.0, 1.0, 0.0) + +[require] +shader model >= 3.0 +options: backcompat + +[pixel shader fail(sm>=6)] +sampler s; +float level; + +float4 main() : sv_target +{ + return tex2Dlod(s, float4(0.5, 0.5, 0, level)); +} + +[test] +uniform 0 float4 0.0 0.0 0.0 0.0 +draw quad +probe all rgba (1.0, 0.0, 1.0, 0.0) +uniform 0 float4 0.5 0.0 0.0 0.0 +draw quad +probe all rgba (0.5, 0.0, 1.0, 0.0) +uniform 0 float4 1.0 0.0 0.0 0.0 +draw quad +probe all rgba (0.0, 0.0, 1.0, 0.0)
This merge request was approved by Zebediah Figura.
This is going to conflict with 219. In the future it probably makes the most sense not to submit multiple patches at a time that touch the exact same area. That only creates more work for everyone.
This is going to conflict with 219.
Fortunately (well, maybe not quite) 219 doesn't currently apply cleanly to begin with, so no conflict in that sense.
This merge request was approved by Henri Verbeet.