Files
mesa/src/compiler/libcl/assert.h
Konstantin Seurer cb31b5a958 clc,libcl: Clean up CL includes
This patch does a couple of things to make CL integration with drivers
as seamless as possible:
- We pull in opencl-c.h and opencl-c-base.h to stop relying on system
  headers.
- Parts of libcl.h are moved to new headers that are incomplete CL-safe
  variants of libc headers.
- A couple of util headers are changed to remove now unnecessary
  __OPENCL_VERSION__ guards and make more headers CL safe.
- Drivers now include src/compiler/libcl and use headers like
  macros.h,u_math.h instead of libcl.h.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33576>
2025-04-11 21:27:37 +00:00

40 lines
1.1 KiB
C

/*
* Copyright 2024 Valve Corporation
* Copyright 2023 Alyssa Rosenzweig
* SPDX-License-Identifier: MIT
*/
#pragma once
#ifndef __OPENCL_VERSION__
#error "should only be included from OpenCL"
#endif
#include <stdlib.h>
/* OpenCL C lacks static_assert, a part of C11. This makes static_assert
* available on both host and device. It is defined as variadic to handle also
* no-message static_asserts (standardized in C23).
*/
#define _S(x) #x
#define _PASTE_(x, y) x##y
#define _PASTE(x, y) _PASTE_(x, y)
#define static_assert(_COND, ...) \
typedef char _PASTE(static_assertion, __LINE__)[(_COND) ? 1 : -1]
/* OpenCL C lacks a standard assert. We implement one on top of abort. We are
* careful to use a single printf so the lines don't get split up if multiple
* threads assert in parallel.
*/
#ifndef NDEBUG
#define _ASSERT_STRING(x) _ASSERT_STRING_INNER(x)
#define _ASSERT_STRING_INNER(x) #x
#define assert(x) if (!(x)) { \
printf("Shader assertion fail at " __FILE__ ":" \
_ASSERT_STRING(__LINE__) "\nExpected " #x "\n\n"); \
nir_printf_abort(); \
}
#else
#define assert(x)
#endif