From e61046fb232c2396c28a61937d67613d2fad4733 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Fri, 6 Sep 2024 22:03:05 +0200 Subject: [PATCH] vkd3d-shader/hlsl: Implement the "earlydepthstencil" attribute. --- libs/vkd3d-shader/hlsl.h | 2 ++ libs/vkd3d-shader/hlsl_codegen.c | 4 +++- libs/vkd3d-shader/tpf.c | 14 ++++++++++++++ tests/hlsl/depth-bounds.shader_test | 4 ++-- tests/hlsl/early-depth-stencil.shader_test | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index d40181a6..66c43826 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -603,6 +603,8 @@ struct hlsl_ir_function_decl unsigned int attr_count; const struct hlsl_attribute *const *attrs; + bool early_depth_test; + /* Synthetic boolean variable marking whether a return statement has been * executed. Needed to deal with return statements in non-uniform control * flow, since some backends can't handle them. */ diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 397eb2d7..93f19360 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -6027,7 +6027,7 @@ static void parse_patchconstantfunc_attribute(struct hlsl_ctx *ctx, const struct "Patch constant function \"%s\" is not defined.", name); } -static void parse_entry_function_attributes(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl *entry_func) +static void parse_entry_function_attributes(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func) { const struct hlsl_profile_info *profile = ctx->profile; unsigned int i; @@ -6049,6 +6049,8 @@ static void parse_entry_function_attributes(struct hlsl_ctx *ctx, const struct h parse_partitioning_attribute(ctx, attr); else if (!strcmp(attr->name, "patchconstantfunc") && profile->type == VKD3D_SHADER_TYPE_HULL) parse_patchconstantfunc_attribute(ctx, attr); + else if (!strcmp(attr->name, "earlydepthstencil") && profile->type == VKD3D_SHADER_TYPE_PIXEL) + entry_func->early_depth_test = true; else hlsl_warning(ctx, &entry_func->attrs[i]->loc, VKD3D_SHADER_WARNING_HLSL_UNKNOWN_ATTRIBUTE, "Ignoring unknown attribute \"%s\".", entry_func->attrs[i]->name); diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 34d32272..78b94c3f 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4630,6 +4630,17 @@ static void write_sm4_dcl_thread_group(const struct tpf_writer *tpf, const uint3 write_sm4_instruction(tpf, &instr); } +static void write_sm4_dcl_global_flags(const struct tpf_writer *tpf, uint32_t flags) +{ + struct sm4_instruction instr = + { + .opcode = VKD3D_SM4_OP_DCL_GLOBAL_FLAGS, + .extra_bits = flags << VKD3D_SM4_GLOBAL_FLAGS_SHIFT, + }; + + write_sm4_instruction(tpf, &instr); +} + static void write_sm4_ret(const struct tpf_writer *tpf) { struct sm4_instruction instr = @@ -6119,6 +6130,9 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx, const struct hlsl_ir_function_d write_sm4_dcl_textures(&tpf, resource, true); } + if (entry_func->early_depth_test && profile->major_version >= 5) + write_sm4_dcl_global_flags(&tpf, VKD3DSGF_FORCE_EARLY_DEPTH_STENCIL); + LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry) { if ((var->is_input_semantic && var->last_read) || (var->is_output_semantic && var->first_write)) diff --git a/tests/hlsl/depth-bounds.shader_test b/tests/hlsl/depth-bounds.shader_test index e808b117..9ab1c332 100644 --- a/tests/hlsl/depth-bounds.shader_test +++ b/tests/hlsl/depth-bounds.shader_test @@ -38,7 +38,7 @@ clear rtv 0 0.0 0.0 0.0 0.0 clear dsv 0.0 todo(glsl) draw quad probe (0, 0) rgba(0, 0, 0, 0) -todo(sm<6) probe uav 1 (0) r(0.0) +probe uav 1 (0) r(0.0) clear rtv 0 0.0 0.0 0.0 0.0 clear dsv 0.3 @@ -62,4 +62,4 @@ clear rtv 0 0.0 0.0 0.0 0.0 clear dsv 1.0 todo(glsl) draw quad probe (0, 0) rgba(0, 0, 0, 0) -todo(sm<6) probe uav 1 (0) r(0.0) +probe uav 1 (0) r(0.0) diff --git a/tests/hlsl/early-depth-stencil.shader_test b/tests/hlsl/early-depth-stencil.shader_test index 07d56a39..810bd4a7 100644 --- a/tests/hlsl/early-depth-stencil.shader_test +++ b/tests/hlsl/early-depth-stencil.shader_test @@ -28,4 +28,4 @@ clear rtv 0 0.0 0.0 0.0 0.0 clear dsv 0.5 todo(glsl) draw quad probe (0, 0) rgba(0, 0, 0, 0) -todo(sm<6) probe uav 1 (0) r(0.0) +probe uav 1 (0) r(0.0)