Blender V5.3
gpu_shader_compat_cxx.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
26
27#pragma once
28
29#include <cstdio> // IWYU pragma: export printf
30
31#include "gpu_shader_cxx_builtin.hh" // IWYU pragma: export
32#include "gpu_shader_cxx_global.hh" // IWYU pragma: export
33#include "gpu_shader_cxx_image.hh" // IWYU pragma: export
34#include "gpu_shader_cxx_matrix.hh" // IWYU pragma: export
35#include "gpu_shader_cxx_sampler.hh" // IWYU pragma: export
36#include "gpu_shader_cxx_string.hh" // IWYU pragma: export
37#include "gpu_shader_cxx_vector.hh" // IWYU pragma: export
38
39#define assert(assertion)
40
41#include "gpu_shader_cxx_attribute.hh" // IWYU pragma: export
42
43/* -------------------------------------------------------------------- */
46
47/* Decorate a variable in global scope that is common to all threads in a thread-group. */
48#define shared
49
51
52/* GLSL main function must return void. C++ need to return int.
53 * Inject real main (C++) inside the GLSL main definition. */
54#define main() \
55 /* Fake main prototype. */ \
56 /* void */ _fake_main(); \
57 /* Real main. */ \
58 int main() \
59 { \
60 _fake_main(); \
61 return 0; \
62 } \
63 /* Fake main definition. */ \
64 void _fake_main()
65
66#define GLSL_CPP_STUBS
67#ifndef GPU_SHADER
68# define GPU_SHADER
69#endif
70
71/* Reserved keywords in GLSL that are allowed in preprocessor directives for compiling in C++. */
72#define sizeof static_assert(false, "sizeof is a reserved keyword")
73
74#ifdef GPU_SHADER_LIBRARY
75# define GPU_VERTEX_SHADER
76# define GPU_FRAGMENT_SHADER
77# define GPU_COMPUTE_SHADER
78#endif
79
80/* Resource accessor. */
81#define specialization_constant_get(create_info, _res) create_info::_res
82#define shared_variable_get(create_info, _res) create_info::_res
83#define push_constant_get(create_info, _res) create_info::_res
84#define interface_get(create_info, _res) create_info::_res
85#define attribute_get(create_info, _res) create_info::_res
86#define buffer_get(create_info, _res) create_info::_res
87#define sampler_get(create_info, _res) create_info::_res
88#define image_get(create_info, _res) create_info::_res
89#define srt_access(create_info, _res) create_info::_res
94#define resource_table_get(table_type) (*(table_type *)(new char[1024 * 16]))
95
97
98struct NoConstants {};
99
100template<typename VertFn,
101 typename FragFn,
102 typename ConstT1 = NoConstants,
103 typename ConstT2 = NoConstants,
104 typename ConstT3 = NoConstants,
105 typename ConstT4 = NoConstants>
107 VertFn vert;
108 FragFn frag;
109 /* Constant values. */
110 ConstT1 c1;
111 ConstT2 c2;
112 ConstT3 c3;
113 ConstT4 c4;
114
115 PipelineGraphic(VertFn vert, FragFn frag) : vert(vert), frag(frag), c1({}), c2({}), c3({}) {}
116 PipelineGraphic(VertFn vert, FragFn frag, ConstT1 c1)
117 : vert(vert), frag(frag), c1(c1), c2({}), c3({})
118 {
119 }
120 PipelineGraphic(VertFn vert, FragFn frag, ConstT1 c1, ConstT2 c2)
121 : vert(vert), frag(frag), c1(c1), c2(c2), c3({})
122 {
123 }
124 PipelineGraphic(VertFn vert, FragFn frag, ConstT1 c1, ConstT2 c2, ConstT3 c3)
125 : vert(vert), frag(frag), c1(c1), c2(c2), c3(c3)
126 {
127 }
128 PipelineGraphic(VertFn vert, FragFn frag, ConstT1 c1, ConstT2 c2, ConstT3 c3, ConstT4 c4)
129 : vert(vert), frag(frag), c1(c1), c2(c2), c3(c3), c4(c4)
130 {
131 }
132};
133
134/* For assert support. */
135#if defined(GPU_VERTEX_SHADER)
136# define GPU_THREAD uint3(0)
137#elif defined(GPU_FRAGMENT_SHADER)
138# define GPU_THREAD uint3(0)
139#elif defined(GPU_COMPUTE_SHADER)
140# define GPU_THREAD uint3(0)
141#else
142# define GPU_THREAD error_not_in_a_shader_question_mark
143#endif
144
145template<typename CompFn,
146 typename ConstT1 = NoConstants,
147 typename ConstT2 = NoConstants,
148 typename ConstT3 = NoConstants>
150 CompFn comp;
151 /* Constant values. */
152 ConstT1 c1;
153 ConstT2 c2;
154 ConstT3 c3;
155
156 PipelineCompute(CompFn comp) : comp(comp), c1({}), c2({}), c3({}) {}
157 PipelineCompute(CompFn comp, ConstT1 c1) : comp(comp), c1(c1), c2({}), c3({}) {}
158 PipelineCompute(CompFn comp, ConstT1 c1, ConstT2 c2) : comp(comp), c1(c1), c2(c2), c3({}) {}
159 PipelineCompute(CompFn comp, ConstT1 c1, ConstT2 c2, ConstT3 c3)
160 : comp(comp), c1(c1), c2(c2), c3(c3)
161 {
162 }
163};
164
165#ifndef FLT_MAX
166# define FLT_MAX uintBitsToFloat(0x7F7FFFFFu)
167# define FLT_MIN uintBitsToFloat(0x00800000u)
168# define FLT_EPSILON 1.192092896e-07F
169#endif
170#ifndef SHRT_MAX
171# define SHRT_MAX 0x00007FFF
172# define INT_MAX 0x7FFFFFFF
173# define USHRT_MAX 0x0000FFFFu
174# define UINT_MAX 0xFFFFFFFFu
175#endif
176#ifndef NAN_FLT
177# define NAN_FLT uintBitsToFloat(0x7FC00000u)
178#endif
179
181
182/* -------------------------------------------------------------------- */
190
251
@ SFLOAT_16_16_16_16
@ SNORM_16_16_16_16
@ SFLOAT_32_32_32_32
@ UNORM_16_16_16_16
PipelineCompute(CompFn comp, ConstT1 c1, ConstT2 c2)
PipelineCompute(CompFn comp, ConstT1 c1)
PipelineCompute(CompFn comp, ConstT1 c1, ConstT2 c2, ConstT3 c3)
PipelineGraphic(VertFn vert, FragFn frag, ConstT1 c1)
PipelineGraphic(VertFn vert, FragFn frag)
PipelineGraphic(VertFn vert, FragFn frag, ConstT1 c1, ConstT2 c2)
PipelineGraphic(VertFn vert, FragFn frag, ConstT1 c1, ConstT2 c2, ConstT3 c3, ConstT4 c4)
PipelineGraphic(VertFn vert, FragFn frag, ConstT1 c1, ConstT2 c2, ConstT3 c3)