mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-03 20:48:08 +02:00
In the C23 standard unreachable() is now a predefined function-like macro in <stddef.h> See https://android.googlesource.com/platform/bionic/+/HEAD/docs/c23.md#is-now-a-predefined-function_like-macro-in And this causes build errors when building for C23: ----------------------------------------------------------------------- In file included from ../src/util/log.h:30, from ../src/util/log.c:30: ../src/util/macros.h:123:9: warning: "unreachable" redefined 123 | #define unreachable(str) \ | ^~~~~~~~~~~ In file included from ../src/util/macros.h:31: /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:456:9: note: this is the location of the previous definition 456 | #define unreachable() (__builtin_unreachable ()) | ^~~~~~~~~~~ ----------------------------------------------------------------------- So don't redefine it with the same name, but use the name UNREACHABLE() to also signify it's a macro. Using a different name also makes sense because the behavior of the macro was extending the one of __builtin_unreachable() anyway, and it also had a different signature, accepting one argument, compared to the standard unreachable() with no arguments. This change improves the chances of building mesa with the C23 standard, which for instance is the default in recent AOSP versions. All the instances of the macro, including the definition, were updated with the following command line: git grep -l '[^_]unreachable(' -- "src/**" | sort | uniq | \ while read file; \ do \ sed -e 's/\([^_]\)unreachable(/\1UNREACHABLE(/g' -i "$file"; \ done && \ sed -e 's/#undef unreachable/#undef UNREACHABLE/g' -i src/intel/isl/isl_aux_info.c Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36437>
193 lines
7.2 KiB
C
193 lines
7.2 KiB
C
/*
|
||
* Copyright © Microsoft Corporation
|
||
*
|
||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||
* copy of this software and associated documentation files (the "Software"),
|
||
* to deal in the Software without restriction, including without limitation
|
||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
* and/or sell copies of the Software, and to permit persons to whom the
|
||
* Software is furnished to do so, subject to the following conditions:
|
||
*
|
||
* The above copyright notice and this permission notice (including the next
|
||
* paragraph) shall be included in all copies or substantial portions of the
|
||
* Software.
|
||
*
|
||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||
* IN THE SOFTWARE.
|
||
*/
|
||
|
||
#include "dxil_enums.h"
|
||
|
||
#include "glsl_types.h"
|
||
#include "nir.h"
|
||
|
||
#include "util/u_debug.h"
|
||
|
||
enum dxil_prog_sig_comp_type dxil_get_prog_sig_comp_type(const struct glsl_type *type)
|
||
{
|
||
type = glsl_without_array(type);
|
||
|
||
switch (glsl_get_base_type(type)) {
|
||
case GLSL_TYPE_UINT: return DXIL_PROG_SIG_COMP_TYPE_UINT32;
|
||
case GLSL_TYPE_INT: return DXIL_PROG_SIG_COMP_TYPE_SINT32;
|
||
case GLSL_TYPE_FLOAT: return DXIL_PROG_SIG_COMP_TYPE_FLOAT32;
|
||
case GLSL_TYPE_FLOAT16: return DXIL_PROG_SIG_COMP_TYPE_FLOAT16;
|
||
case GLSL_TYPE_DOUBLE: return DXIL_PROG_SIG_COMP_TYPE_UINT32;
|
||
case GLSL_TYPE_UINT16: return DXIL_PROG_SIG_COMP_TYPE_UINT16;
|
||
case GLSL_TYPE_INT16: return DXIL_PROG_SIG_COMP_TYPE_SINT16;
|
||
case GLSL_TYPE_UINT64: return DXIL_PROG_SIG_COMP_TYPE_UINT32;
|
||
case GLSL_TYPE_INT64: return DXIL_PROG_SIG_COMP_TYPE_SINT32;
|
||
case GLSL_TYPE_BOOL: return DXIL_PROG_SIG_COMP_TYPE_UINT32;
|
||
/* For structs, just emit them as float registers. This way, they can be
|
||
* interpolated or not, and it doesn't matter, and it avoids linking issues
|
||
* that we'd see if the type here tried to depend on (e.g.) interp mode. */
|
||
case GLSL_TYPE_STRUCT: return DXIL_PROG_SIG_COMP_TYPE_FLOAT32;
|
||
default:
|
||
debug_printf("unexpected type: %s\n", glsl_get_type_name(type));
|
||
return DXIL_PROG_SIG_COMP_TYPE_UNKNOWN;
|
||
}
|
||
}
|
||
|
||
enum dxil_component_type dxil_get_comp_type_from_prog_sig_type(enum dxil_prog_sig_comp_type type)
|
||
{
|
||
switch (type) {
|
||
case DXIL_PROG_SIG_COMP_TYPE_UINT32: return DXIL_COMP_TYPE_U32;
|
||
case DXIL_PROG_SIG_COMP_TYPE_SINT32: return DXIL_COMP_TYPE_I32;
|
||
case DXIL_PROG_SIG_COMP_TYPE_FLOAT32: return DXIL_COMP_TYPE_F32;
|
||
case DXIL_PROG_SIG_COMP_TYPE_UINT16: return DXIL_COMP_TYPE_U16;
|
||
case DXIL_PROG_SIG_COMP_TYPE_SINT16: return DXIL_COMP_TYPE_I16;
|
||
case DXIL_PROG_SIG_COMP_TYPE_FLOAT16: return DXIL_COMP_TYPE_F16;
|
||
default:
|
||
debug_printf("unexpected signature type\n");
|
||
UNREACHABLE("unexpected signature type");
|
||
}
|
||
}
|
||
|
||
enum dxil_component_type dxil_get_comp_type(const struct glsl_type *type)
|
||
{
|
||
type = glsl_without_array(type);
|
||
|
||
enum glsl_base_type base_type = glsl_get_base_type(type);
|
||
if (glsl_type_is_texture(type) || glsl_type_is_image(type))
|
||
base_type = glsl_get_sampler_result_type(type);
|
||
|
||
switch (base_type) {
|
||
case GLSL_TYPE_UINT: return DXIL_COMP_TYPE_U32;
|
||
case GLSL_TYPE_INT: return DXIL_COMP_TYPE_I32;
|
||
case GLSL_TYPE_FLOAT: return DXIL_COMP_TYPE_F32;
|
||
case GLSL_TYPE_FLOAT16: return DXIL_COMP_TYPE_F16;
|
||
case GLSL_TYPE_DOUBLE: return DXIL_COMP_TYPE_F64;
|
||
case GLSL_TYPE_UINT16: return DXIL_COMP_TYPE_U16;
|
||
case GLSL_TYPE_INT16: return DXIL_COMP_TYPE_I16;
|
||
case GLSL_TYPE_UINT64: return DXIL_COMP_TYPE_U64;
|
||
case GLSL_TYPE_INT64: return DXIL_COMP_TYPE_I64;
|
||
case GLSL_TYPE_BOOL: return DXIL_COMP_TYPE_I1;
|
||
|
||
default:
|
||
debug_printf("type: %s\n", glsl_get_type_name(type));
|
||
UNREACHABLE("unexpected glsl 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);
|
||
|
||
/* This looks weird, we strip the arrays but then we still test whether it's
|
||
* 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))
|
||
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");
|
||
}
|
||
|
||
enum dxil_input_primitive dxil_get_input_primitive(enum mesa_prim primitive)
|
||
{
|
||
switch (primitive) {
|
||
case MESA_PRIM_POINTS:
|
||
return DXIL_INPUT_PRIMITIVE_POINT;
|
||
case MESA_PRIM_LINES:
|
||
return DXIL_INPUT_PRIMITIVE_LINE;
|
||
case MESA_PRIM_LINES_ADJACENCY:
|
||
return DXIL_INPUT_PRIMITIVE_LINES_ADJENCY;
|
||
case MESA_PRIM_TRIANGLES:
|
||
return DXIL_INPUT_PRIMITIVE_TRIANGLE;
|
||
case MESA_PRIM_TRIANGLES_ADJACENCY:
|
||
return DXIL_INPUT_PRIMITIVE_TRIANGLES_ADJENCY;
|
||
default:
|
||
UNREACHABLE("unhandled primitive topology");
|
||
}
|
||
}
|
||
|
||
enum dxil_primitive_topology dxil_get_primitive_topology(enum mesa_prim topology)
|
||
{
|
||
switch (topology) {
|
||
case MESA_PRIM_POINTS:
|
||
return DXIL_PRIMITIVE_TOPOLOGY_POINT_LIST;
|
||
case MESA_PRIM_LINES:
|
||
return DXIL_PRIMITIVE_TOPOLOGY_LINE_LIST;
|
||
case MESA_PRIM_LINE_STRIP:
|
||
return DXIL_PRIMITIVE_TOPOLOGY_LINE_STRIP;
|
||
case MESA_PRIM_TRIANGLE_STRIP:
|
||
return DXIL_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
|
||
default:
|
||
UNREACHABLE("unhandled primitive topology");
|
||
}
|
||
}
|
||
|
||
static const char *overload_str[DXIL_NUM_OVERLOADS] = {
|
||
[DXIL_NONE] = "",
|
||
[DXIL_I1] = "i1",
|
||
[DXIL_I16] = "i16",
|
||
[DXIL_I32] = "i32",
|
||
[DXIL_I64] = "i64",
|
||
[DXIL_F16] = "f16",
|
||
[DXIL_F32] = "f32",
|
||
[DXIL_F64] = "f64",
|
||
};
|
||
|
||
const char *dxil_overload_suffix( enum overload_type overload)
|
||
{
|
||
assert(overload < DXIL_NUM_OVERLOADS);
|
||
return overload_str[overload];
|
||
}
|