From abc2412ccc430565af05f257cd3e51f967994b19 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Mon, 27 Feb 2023 10:29:58 -0800 Subject: [PATCH] microsoft/compiler: Refactor type -> resource kind helper Part-of: --- src/microsoft/compiler/dxil_enums.c | 65 +++++++++++++++++++------------------ src/microsoft/compiler/dxil_enums.h | 4 +++ 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/microsoft/compiler/dxil_enums.c b/src/microsoft/compiler/dxil_enums.c index 9607457..66a2884 100644 --- a/src/microsoft/compiler/dxil_enums.c +++ b/src/microsoft/compiler/dxil_enums.c @@ -75,6 +75,38 @@ enum dxil_component_type dxil_get_comp_type(const struct glsl_type *type) } } +enum dxil_resource_kind dxil_sampler_dim_to_resource_kind(enum glsl_sampler_dim dim, bool is_array) +{ + switch (dim) { + case GLSL_SAMPLER_DIM_1D: + return is_array ? DXIL_RESOURCE_KIND_TEXTURE1D_ARRAY + : DXIL_RESOURCE_KIND_TEXTURE1D; + case GLSL_SAMPLER_DIM_2D: + case GLSL_SAMPLER_DIM_EXTERNAL: + return is_array ? DXIL_RESOURCE_KIND_TEXTURE2D_ARRAY + : DXIL_RESOURCE_KIND_TEXTURE2D; + case GLSL_SAMPLER_DIM_SUBPASS: + return DXIL_RESOURCE_KIND_TEXTURE2D_ARRAY; + case GLSL_SAMPLER_DIM_3D: + return DXIL_RESOURCE_KIND_TEXTURE3D; + case GLSL_SAMPLER_DIM_CUBE: + return is_array ? DXIL_RESOURCE_KIND_TEXTURECUBE_ARRAY + : DXIL_RESOURCE_KIND_TEXTURECUBE; + case GLSL_SAMPLER_DIM_RECT: + return DXIL_RESOURCE_KIND_TEXTURE2D; + case GLSL_SAMPLER_DIM_BUF: + return DXIL_RESOURCE_KIND_TYPED_BUFFER; + case GLSL_SAMPLER_DIM_MS: + return is_array ? DXIL_RESOURCE_KIND_TEXTURE2DMS_ARRAY + : DXIL_RESOURCE_KIND_TEXTURE2DMS; + case GLSL_SAMPLER_DIM_SUBPASS_MS: + return DXIL_RESOURCE_KIND_TEXTURE2DMS_ARRAY; + + default: + unreachable("unexpected sampler type"); + } +} + enum dxil_resource_kind dxil_get_resource_kind(const struct glsl_type *type) { type = glsl_without_array(type); @@ -83,37 +115,8 @@ enum dxil_resource_kind dxil_get_resource_kind(const struct glsl_type *type) * an array, key is the first refers to sampler[] and the second to samplerArray */ bool is_array = glsl_sampler_type_is_array(type); - if (glsl_type_is_texture(type) || glsl_type_is_image(type)) { - switch (glsl_get_sampler_dim(type)) { - case GLSL_SAMPLER_DIM_1D: - return is_array ? DXIL_RESOURCE_KIND_TEXTURE1D_ARRAY - : DXIL_RESOURCE_KIND_TEXTURE1D; - case GLSL_SAMPLER_DIM_2D: - case GLSL_SAMPLER_DIM_EXTERNAL: - return is_array ? DXIL_RESOURCE_KIND_TEXTURE2D_ARRAY - : DXIL_RESOURCE_KIND_TEXTURE2D; - case GLSL_SAMPLER_DIM_SUBPASS: - return DXIL_RESOURCE_KIND_TEXTURE2D_ARRAY; - case GLSL_SAMPLER_DIM_3D: - return DXIL_RESOURCE_KIND_TEXTURE3D; - case GLSL_SAMPLER_DIM_CUBE: - return is_array ? DXIL_RESOURCE_KIND_TEXTURECUBE_ARRAY - : DXIL_RESOURCE_KIND_TEXTURECUBE; - case GLSL_SAMPLER_DIM_RECT: - return DXIL_RESOURCE_KIND_TEXTURE2D; - case GLSL_SAMPLER_DIM_BUF: - return DXIL_RESOURCE_KIND_TYPED_BUFFER; - case GLSL_SAMPLER_DIM_MS: - return is_array ? DXIL_RESOURCE_KIND_TEXTURE2DMS_ARRAY - : DXIL_RESOURCE_KIND_TEXTURE2DMS; - case GLSL_SAMPLER_DIM_SUBPASS_MS: - return DXIL_RESOURCE_KIND_TEXTURE2DMS_ARRAY; - - default: - debug_printf("type: %s\n", glsl_get_type_name(type)); - unreachable("unexpected sampler type"); - } - } + if (glsl_type_is_texture(type) || glsl_type_is_image(type)) + return dxil_sampler_dim_to_resource_kind(glsl_get_sampler_dim(type), is_array); debug_printf("type: %s\n", glsl_get_type_name(type)); unreachable("unexpected glsl type"); diff --git a/src/microsoft/compiler/dxil_enums.h b/src/microsoft/compiler/dxil_enums.h index 50c0afb..8c88d34 100644 --- a/src/microsoft/compiler/dxil_enums.h +++ b/src/microsoft/compiler/dxil_enums.h @@ -24,6 +24,8 @@ #ifndef DIXL_ENUMS_H #define DIXL_ENUMS_H +#include + enum dxil_signature_kind { DXIL_SIG_INVALID = 0, DXIL_SIG_INPUT, @@ -372,11 +374,13 @@ extern "C" { #endif struct glsl_type; +enum glsl_sampler_dim; enum dxil_component_type dxil_get_comp_type(const struct glsl_type *type); enum dxil_prog_sig_comp_type dxil_get_prog_sig_comp_type(const struct glsl_type *type); +enum dxil_resource_kind dxil_sampler_dim_to_resource_kind(enum glsl_sampler_dim dim, bool is_array); enum dxil_resource_kind dxil_get_resource_kind(const struct glsl_type *type); enum dxil_primitive_topology dxil_get_primitive_topology(unsigned topology); -- 2.7.4