1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © Microsoft Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include "dxil_enums.h" 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "nir.h" 27bf215546Sopenharmony_ci#include "nir_types.h" 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "util/u_debug.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_cienum dxil_prog_sig_comp_type dxil_get_prog_sig_comp_type(const struct glsl_type *type) 32bf215546Sopenharmony_ci{ 33bf215546Sopenharmony_ci type = glsl_without_array(type); 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci switch (glsl_get_base_type(type)) { 36bf215546Sopenharmony_ci case GLSL_TYPE_UINT: return DXIL_PROG_SIG_COMP_TYPE_UINT32; 37bf215546Sopenharmony_ci case GLSL_TYPE_INT: return DXIL_PROG_SIG_COMP_TYPE_SINT32; 38bf215546Sopenharmony_ci case GLSL_TYPE_FLOAT: return DXIL_PROG_SIG_COMP_TYPE_FLOAT32; 39bf215546Sopenharmony_ci case GLSL_TYPE_FLOAT16: return DXIL_PROG_SIG_COMP_TYPE_FLOAT16; 40bf215546Sopenharmony_ci case GLSL_TYPE_DOUBLE: return DXIL_PROG_SIG_COMP_TYPE_FLOAT64; 41bf215546Sopenharmony_ci case GLSL_TYPE_UINT16: return DXIL_PROG_SIG_COMP_TYPE_UINT16; 42bf215546Sopenharmony_ci case GLSL_TYPE_INT16: return DXIL_PROG_SIG_COMP_TYPE_SINT16; 43bf215546Sopenharmony_ci case GLSL_TYPE_UINT64: return DXIL_PROG_SIG_COMP_TYPE_UINT64; 44bf215546Sopenharmony_ci case GLSL_TYPE_INT64: return DXIL_PROG_SIG_COMP_TYPE_SINT64; 45bf215546Sopenharmony_ci case GLSL_TYPE_BOOL: return DXIL_PROG_SIG_COMP_TYPE_UINT32; 46bf215546Sopenharmony_ci case GLSL_TYPE_STRUCT: return DXIL_PROG_SIG_COMP_TYPE_UNKNOWN; 47bf215546Sopenharmony_ci default: 48bf215546Sopenharmony_ci debug_printf("unexpected type: %s\n", glsl_get_type_name(type)); 49bf215546Sopenharmony_ci return DXIL_PROG_SIG_COMP_TYPE_UNKNOWN; 50bf215546Sopenharmony_ci } 51bf215546Sopenharmony_ci} 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_cienum dxil_component_type dxil_get_comp_type(const struct glsl_type *type) 54bf215546Sopenharmony_ci{ 55bf215546Sopenharmony_ci type = glsl_without_array(type); 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci enum glsl_base_type base_type = glsl_get_base_type(type); 58bf215546Sopenharmony_ci if (glsl_type_is_texture(type) || glsl_type_is_image(type)) 59bf215546Sopenharmony_ci base_type = glsl_get_sampler_result_type(type); 60bf215546Sopenharmony_ci switch (base_type) { 61bf215546Sopenharmony_ci case GLSL_TYPE_UINT: return DXIL_COMP_TYPE_U32; 62bf215546Sopenharmony_ci case GLSL_TYPE_INT: return DXIL_COMP_TYPE_I32; 63bf215546Sopenharmony_ci case GLSL_TYPE_FLOAT: return DXIL_COMP_TYPE_F32; 64bf215546Sopenharmony_ci case GLSL_TYPE_FLOAT16: return DXIL_COMP_TYPE_F16; 65bf215546Sopenharmony_ci case GLSL_TYPE_DOUBLE: return DXIL_COMP_TYPE_F64; 66bf215546Sopenharmony_ci case GLSL_TYPE_UINT16: return DXIL_COMP_TYPE_U16; 67bf215546Sopenharmony_ci case GLSL_TYPE_INT16: return DXIL_COMP_TYPE_I16; 68bf215546Sopenharmony_ci case GLSL_TYPE_UINT64: return DXIL_COMP_TYPE_U64; 69bf215546Sopenharmony_ci case GLSL_TYPE_INT64: return DXIL_COMP_TYPE_I64; 70bf215546Sopenharmony_ci case GLSL_TYPE_BOOL: return DXIL_COMP_TYPE_I1; 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci default: 73bf215546Sopenharmony_ci debug_printf("type: %s\n", glsl_get_type_name(type)); 74bf215546Sopenharmony_ci unreachable("unexpected glsl type"); 75bf215546Sopenharmony_ci } 76bf215546Sopenharmony_ci} 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_cienum dxil_resource_kind dxil_get_resource_kind(const struct glsl_type *type) 79bf215546Sopenharmony_ci{ 80bf215546Sopenharmony_ci type = glsl_without_array(type); 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci /* This looks weird, we strip the arrays but then we still test whether it's 83bf215546Sopenharmony_ci * an array, key is the first refers to sampler[] and the second to samplerArray */ 84bf215546Sopenharmony_ci bool is_array = glsl_sampler_type_is_array(type); 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_ci if (glsl_type_is_texture(type) || glsl_type_is_image(type)) { 87bf215546Sopenharmony_ci switch (glsl_get_sampler_dim(type)) { 88bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_1D: 89bf215546Sopenharmony_ci return is_array ? DXIL_RESOURCE_KIND_TEXTURE1D_ARRAY 90bf215546Sopenharmony_ci : DXIL_RESOURCE_KIND_TEXTURE1D; 91bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_2D: 92bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_EXTERNAL: 93bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_SUBPASS: 94bf215546Sopenharmony_ci return is_array ? DXIL_RESOURCE_KIND_TEXTURE2D_ARRAY 95bf215546Sopenharmony_ci : DXIL_RESOURCE_KIND_TEXTURE2D; 96bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_3D: 97bf215546Sopenharmony_ci return DXIL_RESOURCE_KIND_TEXTURE3D; 98bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_CUBE: 99bf215546Sopenharmony_ci return is_array ? DXIL_RESOURCE_KIND_TEXTURECUBE_ARRAY 100bf215546Sopenharmony_ci : DXIL_RESOURCE_KIND_TEXTURECUBE; 101bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_RECT: 102bf215546Sopenharmony_ci return DXIL_RESOURCE_KIND_TEXTURE2D; 103bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_BUF: 104bf215546Sopenharmony_ci return DXIL_RESOURCE_KIND_TYPED_BUFFER; 105bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_MS: 106bf215546Sopenharmony_ci case GLSL_SAMPLER_DIM_SUBPASS_MS: 107bf215546Sopenharmony_ci return is_array ? DXIL_RESOURCE_KIND_TEXTURE2DMS_ARRAY 108bf215546Sopenharmony_ci : DXIL_RESOURCE_KIND_TEXTURE2DMS; 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci default: 111bf215546Sopenharmony_ci debug_printf("type: %s\n", glsl_get_type_name(type)); 112bf215546Sopenharmony_ci unreachable("unexpected sampler type"); 113bf215546Sopenharmony_ci } 114bf215546Sopenharmony_ci } 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci debug_printf("type: %s\n", glsl_get_type_name(type)); 117bf215546Sopenharmony_ci unreachable("unexpected glsl type"); 118bf215546Sopenharmony_ci} 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_cienum dxil_input_primitive dxil_get_input_primitive(enum shader_prim primitive) 121bf215546Sopenharmony_ci{ 122bf215546Sopenharmony_ci switch (primitive) { 123bf215546Sopenharmony_ci case SHADER_PRIM_POINTS: 124bf215546Sopenharmony_ci return DXIL_INPUT_PRIMITIVE_POINT; 125bf215546Sopenharmony_ci case SHADER_PRIM_LINES: 126bf215546Sopenharmony_ci return DXIL_INPUT_PRIMITIVE_LINE; 127bf215546Sopenharmony_ci case SHADER_PRIM_LINES_ADJACENCY: 128bf215546Sopenharmony_ci return DXIL_INPUT_PRIMITIVE_LINES_ADJENCY; 129bf215546Sopenharmony_ci case SHADER_PRIM_TRIANGLES: 130bf215546Sopenharmony_ci return DXIL_INPUT_PRIMITIVE_TRIANGLE; 131bf215546Sopenharmony_ci case SHADER_PRIM_TRIANGLES_ADJACENCY: 132bf215546Sopenharmony_ci return DXIL_INPUT_PRIMITIVE_TRIANGLES_ADJENCY; 133bf215546Sopenharmony_ci default: 134bf215546Sopenharmony_ci unreachable("unhandled primitive topology"); 135bf215546Sopenharmony_ci } 136bf215546Sopenharmony_ci} 137bf215546Sopenharmony_ci 138bf215546Sopenharmony_cienum dxil_primitive_topology dxil_get_primitive_topology(enum shader_prim topology) 139bf215546Sopenharmony_ci{ 140bf215546Sopenharmony_ci switch (topology) { 141bf215546Sopenharmony_ci case SHADER_PRIM_POINTS: 142bf215546Sopenharmony_ci return DXIL_PRIMITIVE_TOPOLOGY_POINT_LIST; 143bf215546Sopenharmony_ci case SHADER_PRIM_LINES: 144bf215546Sopenharmony_ci return DXIL_PRIMITIVE_TOPOLOGY_LINE_LIST; 145bf215546Sopenharmony_ci case SHADER_PRIM_LINE_STRIP: 146bf215546Sopenharmony_ci return DXIL_PRIMITIVE_TOPOLOGY_LINE_STRIP; 147bf215546Sopenharmony_ci case SHADER_PRIM_TRIANGLE_STRIP: 148bf215546Sopenharmony_ci return DXIL_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; 149bf215546Sopenharmony_ci default: 150bf215546Sopenharmony_ci unreachable("unhandled primitive topology"); 151bf215546Sopenharmony_ci } 152bf215546Sopenharmony_ci} 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_cistatic const char *overload_str[DXIL_NUM_OVERLOADS] = { 155bf215546Sopenharmony_ci [DXIL_NONE] = "", 156bf215546Sopenharmony_ci [DXIL_I16] = "i16", 157bf215546Sopenharmony_ci [DXIL_I32] = "i32", 158bf215546Sopenharmony_ci [DXIL_I64] = "i64", 159bf215546Sopenharmony_ci [DXIL_F16] = "f16", 160bf215546Sopenharmony_ci [DXIL_F32] = "f32", 161bf215546Sopenharmony_ci [DXIL_F64] = "f64", 162bf215546Sopenharmony_ci}; 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ciconst char *dxil_overload_suffix( enum overload_type overload) 165bf215546Sopenharmony_ci{ 166bf215546Sopenharmony_ci assert(overload < DXIL_NUM_OVERLOADS); 167bf215546Sopenharmony_ci return overload_str[overload]; 168bf215546Sopenharmony_ci} 169