From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 13 ++++++++- libs/vkd3d-shader/hlsl_codegen.c | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 5c1c44ca..a100259d 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3463,7 +3463,11 @@ static bool intrinsic_tex(struct hlsl_ctx *ctx, const struct parse_initializer * hlsl_release_string_buffer(ctx, string); }
- if (!strcmp(name, "tex2Dproj")) + if (ctx->profile->major_version < 4 && dim == HLSL_SAMPLER_DIM_1D) + dim = HLSL_SAMPLER_DIM_2D; + + if (!strcmp(name, "tex1Dproj") + || !strcmp(name, "tex2Dproj")) { load_params.type = HLSL_RESOURCE_SAMPLE_PROJ; coords_dim = 4; @@ -3489,6 +3493,12 @@ static bool intrinsic_tex(struct hlsl_ctx *ctx, const struct parse_initializer * return true; }
+static bool intrinsic_tex1Dproj(struct hlsl_ctx *ctx, + const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + return intrinsic_tex(ctx, params, loc, "tex1Dproj", HLSL_SAMPLER_DIM_1D); +} + static bool intrinsic_tex2D(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { @@ -3675,6 +3685,7 @@ intrinsic_functions[] = {"smoothstep", 3, true, intrinsic_smoothstep}, {"sqrt", 1, true, intrinsic_sqrt}, {"step", 2, true, intrinsic_step}, + {"tex1Dproj", 2, false, intrinsic_tex1Dproj}, {"tex2D", -1, false, intrinsic_tex2D}, {"tex2Dproj", 2, false, intrinsic_tex2Dproj}, {"tex3D", -1, false, intrinsic_tex3D}, diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index bd1e041e..763fd159 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -2787,6 +2787,55 @@ static bool lower_tex_proj(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi return true; }
+static bool lower_tex_1d(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) +{ + struct hlsl_ir_node *store, *half, *x; + struct hlsl_ir_resource_load *load; + struct hlsl_deref coords_deref; + struct hlsl_ir_load *var_load; + struct hlsl_ir_var *coords; + + if (instr->type != HLSL_IR_RESOURCE_LOAD) + return false; + load = hlsl_ir_resource_load(instr); + if (load->sampler.var) + return false; + if (load->sampling_dim != HLSL_SAMPLER_DIM_1D) + return false; + + if (!(half = hlsl_new_float_constant(ctx, 0.5f, &instr->loc))) + return false; + list_add_before(&instr->entry, &half->entry); + + if (!(coords = hlsl_new_synthetic_var(ctx, "coords", + hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, 2), &instr->loc))) + return false; + + if (!(x = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, X, X, X), 1, load->coords.node, &instr->loc))) + return false; + list_add_before(&instr->entry, &x->entry); + + hlsl_init_simple_deref_from_var(&coords_deref, coords); + if (!(store = hlsl_new_store_index(ctx, &coords_deref, NULL, x, 0, &instr->loc))) + return false; + list_add_before(&instr->entry, &store->entry); + + if (!(store = hlsl_new_store_index(ctx, &coords_deref, NULL, half, 1 << 1, &instr->loc))) + return false; + list_add_before(&instr->entry, &store->entry); + + if (!(var_load = hlsl_new_var_load(ctx, coords, &instr->loc))) + return false; + list_add_before(&instr->entry, &var_load->node.entry); + + load->sampling_dim = HLSL_SAMPLER_DIM_2D; + + hlsl_src_remove(&load->coords); + hlsl_src_from_node(&load->coords, &var_load->node); + + return true; +} + static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { switch (instr->type) @@ -4345,6 +4394,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry if (profile->major_version >= 4) { hlsl_transform_ir(ctx, lower_tex_proj, body, NULL); + hlsl_transform_ir(ctx, lower_tex_1d, body, NULL); }
hlsl_transform_ir(ctx, validate_static_object_references, body, NULL);