From 37a61bf41a7f96e4ddb8ead2f1d6c1875d6a16ad Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Mon, 11 Nov 2024 21:46:43 -0300 Subject: [PATCH] vkd3d-shader/hlsl: Store the global flags in the vsir program. --- libs/vkd3d-shader/hlsl_codegen.c | 31 +++++++++++++++++++++++++++++++ libs/vkd3d-shader/tpf.c | 23 ++--------------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 7d0a9aa5..2a625bc0 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -9490,6 +9490,36 @@ static void generate_vsir_scan_required_features(struct hlsl_ctx *ctx, struct vs * STENCIL_REF, and TYPED_UAV_LOAD_ADDITIONAL_FORMATS. */ } +static void generate_vsir_scan_global_flags(struct hlsl_ctx *ctx, + struct vsir_program *program, const struct hlsl_ir_function_decl *entry_func) +{ + const struct vkd3d_shader_version *version = &program->shader_version; + struct extern_resource *extern_resources; + unsigned int extern_resources_count, i; + + extern_resources = sm4_get_extern_resources(ctx, &extern_resources_count); + + if (version->major == 4) + { + for (i = 0; i < extern_resources_count; ++i) + { + const struct extern_resource *resource = &extern_resources[i]; + const struct hlsl_type *type = resource->component_type; + + if (type && type->class == HLSL_CLASS_TEXTURE && type->sampler_dim == HLSL_SAMPLER_DIM_RAW_BUFFER) + { + program->global_flags |= VKD3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS; + break; + } + } + } + + sm4_free_extern_resources(extern_resources, extern_resources_count); + + if (entry_func->early_depth_test && vkd3d_shader_ver_ge(version, 5, 0)) + program->global_flags |= VKD3DSGF_FORCE_EARLY_DEPTH_STENCIL; +} + /* OBJECTIVE: Translate all the information from ctx and entry_func to the * vsir_program, so it can be used as input to tpf_compile() without relying * on ctx and entry_func. */ @@ -9531,6 +9561,7 @@ static void sm4_generate_vsir(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl } generate_vsir_scan_required_features(ctx, program); + generate_vsir_scan_global_flags(ctx, program, func); } static struct hlsl_ir_jump *loop_unrolling_find_jump(struct hlsl_block *block, struct hlsl_ir_node *stop_point, diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index c9de4e47..d8763052 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4870,7 +4870,6 @@ static void tpf_write_shdr(struct tpf_compiler *tpf, struct hlsl_ir_function_dec const struct hlsl_buffer *cbuffer; struct hlsl_ctx *ctx = tpf->ctx; size_t token_count_position; - uint32_t global_flags = 0; static const uint16_t shader_types[VKD3D_SHADER_TYPE_COUNT] = { @@ -4892,26 +4891,8 @@ static void tpf_write_shdr(struct tpf_compiler *tpf, struct hlsl_ir_function_dec put_u32(&buffer, vkd3d_make_u32((version->major << 4) | version->minor, shader_types[version->type])); token_count_position = put_u32(&buffer, 0); - if (version->major == 4) - { - for (i = 0; i < extern_resources_count; ++i) - { - const struct extern_resource *resource = &extern_resources[i]; - const struct hlsl_type *type = resource->component_type; - - if (type && type->class == HLSL_CLASS_TEXTURE && type->sampler_dim == HLSL_SAMPLER_DIM_RAW_BUFFER) - { - global_flags |= VKD3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS; - break; - } - } - } - - if (entry_func->early_depth_test && vkd3d_shader_ver_ge(version, 5, 0)) - global_flags |= VKD3DSGF_FORCE_EARLY_DEPTH_STENCIL; - - if (global_flags) - write_sm4_dcl_global_flags(tpf, global_flags); + if (tpf->program->global_flags) + write_sm4_dcl_global_flags(tpf, tpf->program->global_flags); if (version->type == VKD3D_SHADER_TYPE_HULL) {