Blender V5.3
gpu_shader_create_info.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
13
14#pragma once
15
16#if !defined(GPU_SHADER)
17# include "BLI_enum_flags.hh"
18# include "BLI_hash.hh"
19# include "BLI_string_ref.hh"
21# include "BLI_vector.hh"
22# include "GPU_common_types.hh"
23# include "GPU_material.hh"
24# include "GPU_texture.hh"
26
27# include <iostream>
28#endif
29
30#if !defined(GPU_SHADER)
31namespace blender {
32#endif
33
34/* Force enable `printf` support in release build. */
35#define GPU_FORCE_ENABLE_SHADER_PRINTF 0
36
37#if !defined(NDEBUG) || GPU_FORCE_ENABLE_SHADER_PRINTF
38# define GPU_SHADER_PRINTF_ENABLE 1
39#else
40# define GPU_SHADER_PRINTF_ENABLE 0
41#endif
42#define GPU_SHADER_PRINTF_SLOT 13
43#define GPU_SHADER_PRINTF_MAX_CAPACITY (1024 * 4)
44
45/* Used for primitive expansion. */
46#define GPU_SSBO_INDEX_BUF_SLOT 7
47/* Used for polylines. */
48#define GPU_SSBO_POLYLINE_POS_BUF_SLOT 0
49#define GPU_SSBO_POLYLINE_COL_BUF_SLOT 1
50
51#if defined(GLSL_CPP_STUBS)
52# define GPU_SHADER_NAMED_INTERFACE_INFO(_interface, _inst_name) \
53 namespace iface_ns::_interface { \
54 struct {
55# define GPU_SHADER_NAMED_INTERFACE_END(_inst_name) \
56 } \
57 _inst_name; \
58 }
59
60# define GPU_SHADER_INTERFACE_INFO(_interface) namespace iface_ns::_interface {
61# define GPU_SHADER_INTERFACE_END() }
62
63# define GPU_SHADER_CREATE_INFO(_info) \
64 namespace _info { \
65 namespace gl_VertexShader { \
66 } \
67 namespace gl_FragmentShader { \
68 } \
69 namespace gl_ComputeShader { \
70 }
71# define GPU_SHADER_CREATE_END() }
72
73# define SHADER_LIBRARY_CREATE_INFO(_info) using namespace _info;
74# define VERTEX_SHADER_CREATE_INFO(_info) \
75 using namespace ::gl_VertexShader; \
76 using namespace _info::gl_VertexShader; \
77 using namespace _info;
78# define FRAGMENT_SHADER_CREATE_INFO(_info) \
79 using namespace ::gl_FragmentShader; \
80 using namespace _info::gl_FragmentShader; \
81 using namespace _info;
82# define COMPUTE_SHADER_CREATE_INFO(_info) \
83 using namespace ::gl_ComputeShader; \
84 using namespace _info::gl_ComputeShader; \
85 using namespace _info;
86
87#elif !defined(GPU_SHADER_CREATE_INFO)
88/* Helps intellisense / auto-completion inside info files. */
89# define GPU_SHADER_NAMED_INTERFACE_INFO(_interface, _inst_name) \
90 static inline void autocomplete_helper_interface_##_interface() \
91 { \
92 StageInterfaceInfo _interface(#_interface, _inst_name); \
93 _interface
94# define GPU_SHADER_INTERFACE_INFO(_interface) \
95 static inline void autocomplete_helper_interface_##_interface() \
96 { \
97 StageInterfaceInfo _interface(#_interface); \
98 _interface
99# define GPU_SHADER_CREATE_INFO(_info) \
100 static inline void autocomplete_helper_info_##_info() \
101 { \
102 ShaderCreateInfo _info(#_info); \
103 _info
104
105# define GPU_SHADER_NAMED_INTERFACE_END(_inst_name) \
106 ; \
107 }
108# define GPU_SHADER_INTERFACE_END() \
109 ; \
110 }
111# define GPU_SHADER_CREATE_END() \
112 ; \
113 }
114
115#endif
116
117#ifndef GLSL_CPP_STUBS
118# define SMOOTH(type, name) .smooth(Type::type##_t, #name)
119# define FLAT(type, name) .flat(Type::type##_t, #name)
120# define NO_PERSPECTIVE(type, name) .no_perspective(Type::type##_t, #name)
121
122/* LOCAL_GROUP_SIZE(int size_x, int size_y = 1, int size_z = 1) */
123# define LOCAL_GROUP_SIZE(...) .local_group_size(__VA_ARGS__)
124
125# define VERTEX_IN(slot, type, name) .vertex_in(slot, Type::type##_t, #name)
126# define VERTEX_OUT(stage_interface) .vertex_out(stage_interface)
127/* TO REMOVE. */
128# define GEOMETRY_LAYOUT(...) .geometry_layout(__VA_ARGS__)
129# define GEOMETRY_OUT(stage_interface) .geometry_out(stage_interface)
130
131# define VERTEX_IN_SRT(srt) .additional_info(srt)
132# define VERTEX_OUT_SRT(srt) .vertex_out(srt##_t)
133# define FRAGMENT_OUT_SRT(srt) .additional_info(srt)
134# define RESOURCE_SRT(srd) .additional_info(srt)
135
136# define SUBPASS_IN(slot, type, img_type, name, rog) \
137 .subpass_in(slot, Type::type##_t, ImageType::img_type, #name, rog)
138
139# define FRAGMENT_OUT(slot, type, name) .fragment_out(slot, Type::type##_t, #name)
140# define FRAGMENT_OUT_DUAL(slot, type, name, blend) \
141 .fragment_out(slot, Type::type##_t, #name, DualBlend::blend)
142# define FRAGMENT_OUT_ROG(slot, type, name, rog) \
143 .fragment_out(slot, Type::type##_t, #name, DualBlend::NONE, rog)
144
145# define EARLY_FRAGMENT_TEST(enable) .early_fragment_test(enable)
146# define DEPTH_WRITE(value) .depth_write(value)
147
148# define SPECIALIZATION_CONSTANT(type, name, default_value) \
149 .specialization_constant(Type::type##_t, #name, default_value)
150
151# define COMPILATION_CONSTANT(type, name, value) \
152 .compilation_constant(Type::type##_t, #name, value)
153# define COMPILATION_CONSTANT_SRT(type, name, value) \
154 .compilation_constant(Type::type##_t, #name, value)
155
156# define PUSH_CONSTANT(type, name) .push_constant(Type::type##_t, #name)
157# define PUSH_CONSTANT_ARRAY(type, name, array_size) \
158 .push_constant(Type::type##_t, #name, array_size)
159
160# define UNIFORM_BUF(slot, type_name, name) .uniform_buf(slot, #type_name, #name)
161# define UNIFORM_BUF_FREQ(slot, type_name, name, freq) \
162 .uniform_buf(slot, #type_name, #name, Frequency::freq)
163
164# define STORAGE_BUF(slot, qualifiers, type_name, name) \
165 .storage_buf(slot, Qualifier::qualifiers, STRINGIFY(type_name), #name)
166# define STORAGE_BUF_FREQ(slot, qualifiers, type_name, name, freq) \
167 .storage_buf(slot, Qualifier::qualifiers, STRINGIFY(type_name), #name, Frequency::freq)
168
169# define ACCELERATION_STRUCTURE(slot, name) .acceleration_structure(slot, #name)
170# define ACCELERATION_STRUCTURE_FREQ(slot, name, freq) \
171 .acceleration_structure(slot, #name, Frequency::freq)
172
173# define SAMPLER(slot, type, name) .sampler(slot, ImageType::type, #name)
174# define SAMPLER_FREQ(slot, type, name, freq) \
175 .sampler(slot, ImageType::type, #name, Frequency::freq)
176
177# define IMAGE(slot, format, qualifiers, type, name) \
178 .image( \
179 slot, gpu::TextureFormat::format, Qualifier::qualifiers, ImageReadWriteType::type, #name)
180# define IMAGE_FREQ(slot, format, qualifiers, type, name, freq) \
181 .image(slot, \
182 gpu::TextureFormat::format, \
183 Qualifier::qualifiers, \
184 ImageReadWriteType::type, \
185 #name, \
186 Frequency::freq)
187
188# define GROUP_SHARED(type, name) .shared_variable(Type::type##_t, #name)
189
190# define BUILTINS(builtin) .builtins(builtin)
191
192# define VERTEX_SOURCE(filename) .vertex_source(filename)
193# define FRAGMENT_SOURCE(filename) .fragment_source(filename)
194# define COMPUTE_SOURCE(filename) .compute_source(filename)
195# define GRAPHIC_SOURCE(filename) .vertex_source(filename).fragment_source(filename)
196
197# define VERTEX_FUNCTION(function) .vertex_function(function)
198# define FRAGMENT_FUNCTION(function) .fragment_function(function)
199# define COMPUTE_FUNCTION(function) .compute_function(function)
200
201# define DEFINE(name) .define(name)
202# define DEFINE_VALUE(name, value) .define(name, value)
203
204# define DO_STATIC_COMPILATION() .do_static_compilation(true)
205
206/* TO REMOVE. */
207# define METAL_BACKEND_ONLY() .metal_backend_only(true)
208
209# define ADDITIONAL_INFO(info_name) .additional_info(#info_name)
210# define TYPEDEF_SOURCE(filename) .typedef_source(filename)
211
212# define SRT_DATA(srt_name) .additional_info(#srt_name)
213
214# define MTL_MAX_TOTAL_THREADS_PER_THREADGROUP(value) \
215 .mtl_max_total_threads_per_threadgroup(value)
216
217#else
218
219# define _read const
220# define _write
221# define _read_write
222
223# define SMOOTH(type, name) type name = {};
224# define FLAT(type, name) type name = {};
225# define NO_PERSPECTIVE(type, name) type name = {};
226
227/* LOCAL_GROUP_SIZE(int size_x, int size_y = -1, int size_z = -1) */
228# define LOCAL_GROUP_SIZE(...)
229
230# define VERTEX_IN(slot, type, name) \
231 namespace gl_VertexShader { \
232 const type name = {}; \
233 }
234# define VERTEX_OUT(stage_interface) using namespace iface_ns::stage_interface;
235
236/* TO REMOVE. */
237# define GEOMETRY_LAYOUT(...)
238# define GEOMETRY_OUT(stage_interface) using namespace iface_ns::stage_interface;
239
240# define SUBPASS_IN(slot, type, img_type, name, rog) const type name = {};
241
242# define FRAGMENT_OUT(slot, type, name) \
243 namespace gl_FragmentShader { \
244 type name; \
245 }
246# define FRAGMENT_OUT_DUAL(slot, type, name, blend) \
247 namespace gl_FragmentShader { \
248 type name; \
249 }
250# define FRAGMENT_OUT_ROG(slot, type, name, rog) \
251 namespace gl_FragmentShader { \
252 type name; \
253 }
254
255# define VERTEX_IN_SRT(srt)
256# define VERTEX_OUT_SRT(srt)
257# define FRAGMENT_OUT_SRT(srt)
258# define RESOURCE_SRT(srd)
259
260# define EARLY_FRAGMENT_TEST(enable)
261# define DEPTH_WRITE(value)
262
263# define SPECIALIZATION_CONSTANT(type, name, default_value) \
264 constexpr type name = type(default_value);
265
266# define COMPILATION_CONSTANT(type, name, value) constexpr type name = type(value);
267# define COMPILATION_CONSTANT_SRT(type, name, value)
268
269# define PUSH_CONSTANT(type, name) extern const type name;
270# define PUSH_CONSTANT_ARRAY(type, name, array_size) extern const type name[array_size];
271
272# define UNIFORM_BUF(slot, type_name, name) extern const type_name name;
273# define UNIFORM_BUF_FREQ(slot, type_name, name, freq) extern const type_name name;
274
275# define STORAGE_BUF(slot, qualifiers, type_name, name) extern _##qualifiers type_name name;
276# define STORAGE_BUF_FREQ(slot, qualifiers, type_name, name, freq) \
277 extern _##qualifiers type_name name;
278
279# define ACCELERATION_STRUCTURE(slot, name) accelerationStructure name;
280# define ACCELERATION_STRUCTURE_FREQ(slot, name, freq) accelerationStructure name;
281
282# define SAMPLER(slot, type, name) type name;
283# define SAMPLER_FREQ(slot, type, name, freq) type name;
284
285# define IMAGE(slot, format, qualifiers, type, name) _##qualifiers type name;
286# define IMAGE_FREQ(slot, format, qualifiers, type, name, freq) _##qualifiers type name;
287
288# define GROUP_SHARED(type, name) type name;
289
290# define BUILTINS(builtin)
291
292# define VERTEX_SOURCE(filename)
293# define FRAGMENT_SOURCE(filename)
294# define COMPUTE_SOURCE(filename)
295# define GRAPHIC_SOURCE(filename)
296
297# define VERTEX_FUNCTION(filename)
298# define FRAGMENT_FUNCTION(filename)
299# define COMPUTE_FUNCTION(filename)
300
301# define DEFINE(name)
302# define DEFINE_VALUE(name, value)
303
304# define DO_STATIC_COMPILATION()
305
306/* TO REMOVE. */
307# define METAL_BACKEND_ONLY()
308
309# define ADDITIONAL_INFO(info_name) \
310 using namespace info_name; \
311 using namespace info_name::gl_FragmentShader; \
312 using namespace info_name::gl_VertexShader;
313
314# define SRT_DATA(srt_name)
315
316# define TYPEDEF_SOURCE(filename)
317
318# define MTL_MAX_TOTAL_THREADS_PER_THREADGROUP(value)
319#endif
320
321#define _INFO_EXPAND2(a, b) ADDITIONAL_INFO(a) ADDITIONAL_INFO(b)
322#define _INFO_EXPAND3(a, b, c) _INFO_EXPAND2(a, b) ADDITIONAL_INFO(c)
323#define _INFO_EXPAND4(a, b, c, d) _INFO_EXPAND3(a, b, c) ADDITIONAL_INFO(d)
324#define _INFO_EXPAND5(a, b, c, d, e) _INFO_EXPAND4(a, b, c, d) ADDITIONAL_INFO(e)
325#define _INFO_EXPAND6(a, b, c, d, e, f) _INFO_EXPAND5(a, b, c, d, e) ADDITIONAL_INFO(f)
326
327#define ADDITIONAL_INFO_EXPAND(...) VA_NARGS_CALL_OVERLOAD(_INFO_EXPAND, __VA_ARGS__)
328
329#define CREATE_INFO_VARIANT(name, ...) \
330 GPU_SHADER_CREATE_INFO(name) \
331 DO_STATIC_COMPILATION() \
332 ADDITIONAL_INFO_EXPAND(__VA_ARGS__) \
333 GPU_SHADER_CREATE_END()
334
335#if !defined(GLSL_CPP_STUBS)
336
337namespace gpu {
338struct GPUSource;
339}
340
341namespace gpu::shader {
342
343/* All of these functions is a bit out of place */
344static inline Type to_type(const GPUType type)
345{
346 switch (type) {
347 case GPU_FLOAT:
348 return Type::float_t;
349 case GPU_VEC2:
350 return Type::float2_t;
351 case GPU_VEC3:
352 return Type::float3_t;
353 case GPU_VEC4:
354 return Type::float4_t;
355 case GPU_MAT3:
356 return Type::float3x3_t;
357 case GPU_MAT4:
358 return Type::float4x4_t;
359 case GPU_INT:
360 return Type::int_t;
361 case GPU_INT2:
362 return Type::int2_t;
363 case GPU_INT3:
364 return Type::int3_t;
365 case GPU_INT4:
366 return Type::int4_t;
367 case GPU_BOOL:
368 return Type::bool_t;
369 case GPU_NONE:
370 case GPU_TEX1D_ARRAY:
371 case GPU_TEX2D:
372 case GPU_TEX2D_ARRAY:
373 case GPU_TEX3D:
374 case GPU_CLOSURE:
375 case GPU_ATTR:
377 case GPU_SHADING_DATA:
378 break;
379 }
380
381 BLI_assert_msg(0, "Error: Cannot convert GPUType to shader::Type.");
382 return Type::float_t;
383}
384
385static inline std::ostream &operator<<(std::ostream &stream, const Type type)
386{
387 switch (type) {
388 case Type::float_t:
389 return stream << "float";
390 case Type::float2_t:
391 return stream << "float2";
392 case Type::float3_t:
393 return stream << "float3";
394 case Type::float4_t:
395 return stream << "float4";
396 case Type::float3x3_t:
397 return stream << "float3x3";
398 case Type::float4x4_t:
399 return stream << "float4x4";
401 return stream << "vec3_1010102_Inorm";
402 case Type::uchar_t:
403 return stream << "uchar";
404 case Type::uchar2_t:
405 return stream << "uchar2";
406 case Type::uchar3_t:
407 return stream << "uchar3";
408 case Type::uchar4_t:
409 return stream << "uchar4";
410 case Type::char_t:
411 return stream << "char";
412 case Type::char2_t:
413 return stream << "char2";
414 case Type::char3_t:
415 return stream << "char3";
416 case Type::char4_t:
417 return stream << "char4";
418 case Type::int_t:
419 return stream << "int";
420 case Type::int2_t:
421 return stream << "int2";
422 case Type::int3_t:
423 return stream << "int3";
424 case Type::int4_t:
425 return stream << "int4";
426 case Type::uint_t:
427 return stream << "uint";
428 case Type::uint2_t:
429 return stream << "uint2";
430 case Type::uint3_t:
431 return stream << "uint3";
432 case Type::uint4_t:
433 return stream << "uint4";
434 case Type::ushort_t:
435 return stream << "ushort";
436 case Type::ushort2_t:
437 return stream << "ushort2";
438 case Type::ushort3_t:
439 return stream << "ushort3";
440 case Type::ushort4_t:
441 return stream << "ushort4";
442 case Type::short_t:
443 return stream << "short";
444 case Type::short2_t:
445 return stream << "short2";
446 case Type::short3_t:
447 return stream << "short3";
448 case Type::short4_t:
449 return stream << "short4";
450 case Type::bool_t:
451 return stream << "bool";
452 default:
453 BLI_assert(0);
454 return stream;
455 }
456}
457
458static inline std::ostream &operator<<(std::ostream &stream, const GPUType type)
459{
460 switch (type) {
461 case GPU_CLOSURE:
462 return stream << "Closure";
463 default:
464 return stream << to_type(type);
465 }
466}
467
468enum class BuiltinBits {
469 NONE = 0,
475 STENCIL_REF = (1 << 1),
476 FRAG_COORD = (1 << 2),
477 CLIP_DISTANCES = (1 << 3),
478 FRONT_FACING = (1 << 4),
479 GLOBAL_INVOCATION_ID = (1 << 5),
480 INSTANCE_ID = (1 << 6),
481 INSTANCE_INDEX = INSTANCE_ID, /* Map to the same value. */
486 LAYER = (1 << 7),
488 LOCAL_INVOCATION_INDEX = (1 << 9),
489 NUM_WORK_GROUP = (1 << 10),
490 POINT_COORD = (1 << 11),
491 POINT_SIZE = (1 << 12),
492 PRIMITIVE_ID = (1 << 13),
493 VERTEX_ID = (1 << 14),
494 WORK_GROUP_ID = (1 << 15),
495 WORK_GROUP_SIZE = (1 << 16),
500 VIEWPORT_INDEX = (1 << 17),
501
502 /* Texture atomics requires usage options to alter compilation flag. */
503 TEXTURE_ATOMIC = (1 << 18),
504
505 /* Enable shader patching on GL to remap clip range to 0..1.
506 * Will do nothing if ClipControl is unsupported. */
507 CLIP_CONTROL = (1 << 19),
508
509 /* On metal, tag the shader to use argument buffer to overcome the 16 sampler limit. */
511
512 /* Selective enablement of ray queries. */
513 RAY_QUERY = (1 << 21),
514
515 /* Disable our own GPU shader preprocessor optimizer in case we can't ensure the
516 * input is within spec. */
517 NO_PREPROCESSOR = (1 << 23),
523 NO_BUFFER_TYPE_LINTING = (1 << 24),
524 /* Not a builtin but a flag we use to tag shaders that use the debug features. */
525 USE_PRINTF = (1 << 25),
526 USE_DEBUG_DRAW = (1 << 26),
527
528 /* Shader source needs to be implemented at runtime. */
529 RUNTIME_GENERATED = (1 << 27),
530};
532
537enum class DepthWrite {
538 /* UNCHANGED specified as default to indicate gl_FragDepth is not used. */
543};
544
545/* Samplers & images. */
546enum class ImageType {
548# define TYPES_EXPAND(s) \
549 Float##s, Uint##s, Int##s, sampler##s = Float##s, usampler##s = Uint##s, isampler##s = Int##s
550
552 TYPES_EXPAND(1DArray),
554 TYPES_EXPAND(2DArray),
557 TYPES_EXPAND(CubeArray),
559# undef TYPES_EXPAND
560
561# define TYPES_EXPAND(s) \
562 Shadow##s, Depth##s, sampler##s##Shadow = Shadow##s, sampler##s##Depth = Depth##s
565 TYPES_EXPAND(2DArray),
567 TYPES_EXPAND(CubeArray),
568# undef TYPES_EXPAND
569
570# define TYPES_EXPAND(s) \
571 AtomicUint##s, AtomicInt##s, usampler##s##Atomic = AtomicUint##s, \
572 isampler##s##Atomic = AtomicInt##s
584 TYPES_EXPAND(2DArray),
586# undef TYPES_EXPAND
587};
588
589/* Samplers & images. */
592# define TYPES_EXPAND(s) \
593 Float##s = int(ImageType::Float##s), Uint##s = int(ImageType::Uint##s), \
594 Int##s = int(ImageType::Int##s), image##s = Float##s, uimage##s = Uint##s, iimage##s = Int##s
597 TYPES_EXPAND(1DArray),
599 TYPES_EXPAND(2DArray),
601# undef TYPES_EXPAND
602
603# define TYPES_EXPAND(s) \
604 AtomicUint##s = int(ImageType::AtomicUint##s), AtomicInt##s = int(ImageType::AtomicInt##s), \
605 uimage##s##Atomic = AtomicUint##s, iimage##s##Atomic = AtomicInt##s
617 TYPES_EXPAND(2DArray),
619# undef TYPES_EXPAND
620};
621
622static inline bool is_atomic_type(ImageType type)
623{
624 switch (type) {
625 case ImageType::AtomicUint2D:
626 case ImageType::AtomicInt2D:
627 case ImageType::AtomicUint2DArray:
628 case ImageType::AtomicInt2DArray:
629 case ImageType::AtomicUint3D:
630 case ImageType::AtomicInt3D:
631 return true;
632 default:
633 break;
634 }
635 return false;
636}
637
638/* Storage qualifiers. */
639enum class Qualifier {
641 no_restrict = (1 << 0),
642 read = (1 << 1),
643 write = (1 << 2),
645 read_write = read | write,
646 read_no_restrict = read | no_restrict,
647 QUALIFIER_MAX = (write << 1) - 1,
648};
650
652enum class Frequency {
653 BATCH = 0,
656 GEOMETRY,
657};
658
660enum class DualBlend {
661 NONE = 0,
664};
665
672
681
690
691/* Same as StringRefNull but with a few extra member functions. */
693 constexpr ResourceString() : StringRefNull() {}
694 constexpr ResourceString(const char *str, int64_t size) : StringRefNull(str, size) {}
695 ResourceString(std::nullptr_t) = delete;
696 constexpr ResourceString(const char *str) : StringRefNull(str) {}
697 ResourceString(const std::string &str) : StringRefNull(str) {}
699
701 {
702 return this->find_first_of("[");
703 }
704
705 bool is_array() const
706 {
707 return array_offset() != -1;
708 }
709
711 {
712 int64_t offset = this->array_offset();
713 if (offset == -1) {
714 return *this;
715 }
716 return StringRef(this->c_str(), offset);
717 }
718
720 {
721 int64_t offset = this->array_offset();
722 if (offset == -1) {
723 return "";
724 }
725 return this->substr(this->array_offset());
726 }
727};
728
735
744
745 StageInterfaceInfo(const char *name_, const char *instance_name_ = "")
746 : name(name_), instance_name(instance_name_) {};
748
750
752 {
753 inouts.append({Interpolation::SMOOTH, type, _name});
754 return *static_cast<Self *>(this);
755 }
756
758 {
759 inouts.append({Interpolation::FLAT, type, _name});
760 return *static_cast<Self *>(this);
761 }
762
764 {
765 inouts.append({Interpolation::NO_PERSPECTIVE, type, _name});
766 return *static_cast<Self *>(this);
767 }
768};
769
772 /* Associated filename this source replaces. */
775 std::string content;
776};
777
779
780# define TEST_EQUAL(a, b, _member) \
781 if (!((a)._member == (b)._member)) { \
782 return false; \
783 }
784
785# define TEST_VECTOR_EQUAL(a, b, _vector) \
786 TEST_EQUAL(a, b, _vector.size()); \
787 for (auto i : _vector.index_range()) { \
788 TEST_EQUAL(a, b, _vector[i]); \
789 }
790
800 using ConditionFn = std::function<bool(Span<CompilationConstant>)>;
801 struct Conditions : Vector<ConditionFn, 0> {
802
803 Conditions() = default;
805 {
806 this->append(fn);
807 };
808
810 {
811 if (is_empty()) {
812 return true;
813 }
814 for (const auto &cond : *this) {
815 if (cond(constants)) {
816 return true;
817 }
818 }
819 return false;
820 }
821 };
822
824 std::string name_;
828 bool is_generated_ = true;
830 bool finalized_ = false;
846 struct BuiltinBit {
849
850 bool operator==(const BuiltinBit &b) const
851 {
852 TEST_EQUAL(*this, b, bit);
853 return true;
854 }
855 };
857
859 {
861 for (const BuiltinBit &value : builtins_) {
862 bits = BuiltinBits(bits | value.bit);
863 }
864 return bits;
865 }
866
875
877
878 struct VertIn {
879 int index;
883
884 bool operator==(const VertIn &b) const
885 {
886 TEST_EQUAL(*this, b, index);
887 TEST_EQUAL(*this, b, type);
888 TEST_EQUAL(*this, b, name);
889 return true;
890 }
891 };
893
899 int max_vertices = -1;
900
902 {
903 TEST_EQUAL(*this, b, primitive_in);
904 TEST_EQUAL(*this, b, invocations);
905 TEST_EQUAL(*this, b, primitive_out);
906 TEST_EQUAL(*this, b, max_vertices);
907 return true;
908 }
909 };
911
913 int local_size_x = -1;
914 int local_size_y = -1;
915 int local_size_z = -1;
916
917 bool operator==(const ComputeStageLayout &b) const
918 {
919 TEST_EQUAL(*this, b, local_size_x);
920 TEST_EQUAL(*this, b, local_size_y);
921 TEST_EQUAL(*this, b, local_size_z);
922 return true;
923 }
924 };
926
927 struct FragOut {
928 int index;
932 /* NOTE: Currently only supported by Metal. */
935
936 bool operator==(const FragOut &b) const
937 {
938 TEST_EQUAL(*this, b, index);
939 TEST_EQUAL(*this, b, type);
940 TEST_EQUAL(*this, b, blend);
941 TEST_EQUAL(*this, b, name);
943 return true;
944 }
945 };
947
948 struct SubpassIn {
949 int index;
953 /* NOTE: Currently only supported by Metal. */
956
957 bool operator==(const SubpassIn &b) const
958 {
959 TEST_EQUAL(*this, b, index);
960 TEST_EQUAL(*this, b, type);
961 TEST_EQUAL(*this, b, img_type);
962 TEST_EQUAL(*this, b, name);
964 return true;
965 }
966 };
968
971
973 {
974 for (const CompilationConstant &constant : constants) {
975 if (constant.name == name) {
976 /* Note: We don't support float for now, so cast everything to int. */
977 return constant.value.i;
978 }
979 }
980 return 0;
981 }
982
988
990
995
1002
1007
1013
1017
1018 struct Resource {
1026
1027 /* Name of the create info that declared this resource. */
1030 int slot;
1039
1040 Resource(const ShaderCreateInfo &info, BindType type, int _slot, ConditionFn cond)
1041 : info_name(info.name_),
1042 bind_type(type),
1043 slot(_slot),
1044 conditions(cond ? Conditions(cond) : Conditions()) {};
1045
1046 bool operator==(const Resource &b) const
1047 {
1048 TEST_EQUAL(*this, b, bind_type);
1049 TEST_EQUAL(*this, b, slot);
1050 switch (bind_type) {
1051 case UNIFORM_BUFFER:
1052 TEST_EQUAL(*this, b, uniformbuf.type_name);
1053 TEST_EQUAL(*this, b, uniformbuf.name);
1054 break;
1055 case STORAGE_BUFFER:
1056 TEST_EQUAL(*this, b, storagebuf.qualifiers);
1057 TEST_EQUAL(*this, b, storagebuf.type_name);
1058 TEST_EQUAL(*this, b, storagebuf.name);
1059 break;
1060 case SAMPLER:
1061 TEST_EQUAL(*this, b, sampler.type);
1062 TEST_EQUAL(*this, b, sampler.name);
1063 break;
1064 case IMAGE:
1065 TEST_EQUAL(*this, b, image.format);
1066 TEST_EQUAL(*this, b, image.type);
1067 TEST_EQUAL(*this, b, image.qualifiers);
1068 TEST_EQUAL(*this, b, image.name);
1069 break;
1071 TEST_EQUAL(*this, b, acceleration_structure.name);
1072 break;
1073 }
1074 return true;
1075 }
1076 };
1077
1085
1087 {
1088 switch (freq) {
1089 case Frequency::PASS:
1090 return pass_resources_;
1091 case Frequency::BATCH:
1092 return batch_resources_;
1094 return geometry_resources_;
1095 }
1097 return pass_resources_;
1098 }
1099
1100 /* Return all resources regardless of their frequency. */
1102 {
1103 Vector<Resource> all_resources;
1104 all_resources.extend(pass_resources_);
1105 all_resources.extend(batch_resources_);
1106 all_resources.extend(geometry_resources_);
1107 return all_resources;
1108 }
1109
1113
1114 operator StageInterfaceInfo *() const
1115 {
1116 return iface;
1117 }
1118
1120 {
1121 TEST_EQUAL(*this, b, iface);
1122 return true;
1123 }
1124 };
1125
1128
1129 struct PushConst {
1134
1136 {
1137 return (array_size > 0) ? array_size : 1;
1138 }
1139
1140 std::string array_str() const
1141 {
1142 return array_size > 0 ? "[" + std::to_string(array_size) + "]" : "";
1143 }
1144
1145 bool operator==(const PushConst &b) const
1146 {
1147 TEST_EQUAL(*this, b, type);
1148 TEST_EQUAL(*this, b, name);
1149 TEST_EQUAL(*this, b, array_size);
1150 return true;
1151 }
1152 };
1153
1155
1156 /* Sources for resources type definitions. */
1158
1162
1164
1172
1173 bool operator==(const AdditionalInfo &b) const
1174 {
1175 TEST_EQUAL(*this, b, name);
1176 return true;
1177 }
1178 };
1180
1182
1183 /* API-specific parameters. */
1184# ifdef WITH_METAL_BACKEND
1185 ushort mtl_max_threads_per_threadgroup_ = 0;
1186# endif
1187
1188 public:
1189 ShaderCreateInfo(const char *name);
1190
1192
1194
1195 /* WORKAROUND: Avoid unused expression warning. */
1197 {
1198 return *this;
1199 }
1200
1201 /* -------------------------------------------------------------------- */
1204
1205 Self &vertex_in(int slot, Type type, StringRefNull name, ConditionFn cond = nullptr)
1206 {
1207 vertex_inputs_.append({slot, type, name, cond ? Conditions(cond) : Conditions()});
1208 interface_names_size_ += name.size() + 1;
1209 return *static_cast<Self *>(this);
1210 }
1211
1212 Self &vertex_out(StageInterfaceInfo &interface, ConditionFn cond = nullptr)
1213 {
1215 StageInterfaceInfoHandle{&interface, cond ? Conditions(cond) : Conditions()});
1216 return *static_cast<Self *>(this);
1217 }
1218
1220 PrimitiveOut prim_out,
1221 int max_vertices,
1222 int invocations = -1)
1223 {
1226 geometry_layout_.max_vertices = max_vertices;
1227 geometry_layout_.invocations = invocations;
1228 return *static_cast<Self *>(this);
1229 }
1230
1231 Self &local_group_size(int local_size_x, int local_size_y = 1, int local_size_z = 1)
1232 {
1233 compute_layout_.local_size_x = local_size_x;
1234 compute_layout_.local_size_y = local_size_y;
1235 compute_layout_.local_size_z = local_size_z;
1236 return *static_cast<Self *>(this);
1237 }
1238
1244 {
1245 early_fragment_test_ = enable;
1246 return *static_cast<Self *>(this);
1247 }
1248
1256 {
1257 geometry_out_interfaces_.append_as(&interface, cond ? Conditions(cond) : Conditions());
1258 return *static_cast<Self *>(this);
1259 }
1260
1262 Type type,
1263 StringRefNull name,
1264 DualBlend blend = DualBlend::NONE,
1265 int raster_order_group = -1,
1266 ConditionFn cond = nullptr)
1267 {
1268 fragment_outputs_.append(
1269 {slot, type, blend, name, raster_order_group, cond ? Conditions(cond) : Conditions()});
1270 return *static_cast<Self *>(this);
1271 }
1272
1288 int slot, Type type, ImageType img_type, StringRefNull name, int raster_order_group = -1)
1289 {
1290 subpass_inputs_.append({slot, type, img_type, name, raster_order_group});
1291 return *static_cast<Self *>(this);
1292 }
1293
1295 {
1296 fn(*this);
1297 return *static_cast<Self *>(this);
1298 }
1299
1301
1302 /* -------------------------------------------------------------------- */
1309
1310 Self &compilation_constant(Type type, StringRefNull name, double default_value)
1311 {
1312 CompilationConstant constant;
1313 constant.type = type;
1314 constant.name = name;
1315 switch (type) {
1316 case Type::int_t:
1317 constant.value.i = int(default_value);
1318 break;
1319 case Type::bool_t:
1320 case Type::uint_t:
1321 constant.value.u = uint(default_value);
1322 break;
1323 default:
1324 BLI_assert_msg(0, "Only scalar integer and bool types can be used as constants");
1325 break;
1326 }
1327 compilation_constants_.append(constant);
1328 interface_names_size_ += name.size() + 1;
1329 return *static_cast<Self *>(this);
1330 }
1331
1333
1334 /* -------------------------------------------------------------------- */
1337
1338 /* Adds a specialization constant which is a dynamically modifiable value, which will be
1339 * statically compiled into a PSO configuration to provide optimal runtime performance,
1340 * with a reduced re-compilation cost vs Macro's with easier generation of unique permutations
1341 * based on run-time values.
1342 *
1343 * Tip: To evaluate use-cases of where specialization constants can provide a performance
1344 * gain, benchmark a given shader in its default case. Attempt to statically disable branches or
1345 * conditions which rely on uniform look-ups and measure if there is a marked improvement in
1346 * performance and/or reduction in memory bandwidth/register pressure.
1347 *
1348 * NOTE: Specialization constants will incur new compilation of PSOs and thus can incur an
1349 * unexpected cost. Specialization constants should be reserved for infrequently changing
1350 * parameters (e.g. user setting parameters such as toggling of features or quality level
1351 * presets), or those with a low set of possible runtime permutations.
1352 *
1353 * Specialization constants are assigned at runtime using:
1354 * - `GPU_shader_constant_*(shader, name, value)`
1355 * or
1356 * - `DrawPass::specialize_constant(shader, name, value)`
1357 *
1358 * All constants **MUST** be specified before binding a shader.
1359 */
1360 Self &specialization_constant(Type type, StringRefNull name, double default_value)
1361 {
1362 SpecializationConstant constant;
1363 constant.type = type;
1364 constant.name = name;
1365 switch (type) {
1366 case Type::int_t:
1367 constant.value.i = int(default_value);
1368 break;
1369 case Type::bool_t:
1370 case Type::uint_t:
1371 constant.value.u = uint(default_value);
1372 break;
1373 case Type::float_t:
1374 constant.value.f = float(default_value);
1375 break;
1376 default:
1377 BLI_assert_msg(0, "Only scalar types can be used as constants");
1378 break;
1379 }
1380 specialization_constants_.append(constant);
1381 interface_names_size_ += name.size() + 1;
1382 return *static_cast<Self *>(this);
1383 }
1384
1385 /* TODO: Add API to specify unique specialization config permutations in CreateInfo, allowing
1386 * specialized compilation to be primed and handled in the background at start-up, rather than
1387 * waiting for a given permutation to occur dynamically. */
1388
1390
1391 /* -------------------------------------------------------------------- */
1394
1396 {
1397 shared_variables_.append({type, name, this->name_});
1398 return *static_cast<Self *>(this);
1399 }
1400
1402
1403 /* -------------------------------------------------------------------- */
1406
1408 StringRefNull type_name,
1409 StringRefNull name,
1411 ConditionFn cond = nullptr)
1412 {
1413 Resource res(*this, Resource::BindType::UNIFORM_BUFFER, slot, cond);
1414 res.uniformbuf.name = name;
1415 res.uniformbuf.type_name = type_name;
1416 resources_get_(freq).append(res);
1417 interface_names_size_ += name.size() + 1;
1418 return *static_cast<Self *>(this);
1419 }
1420
1422 Qualifier qualifiers,
1423 StringRefNull type_name,
1424 StringRefNull name,
1426 ConditionFn cond = nullptr)
1427 {
1428 Resource res(*this, Resource::BindType::STORAGE_BUFFER, slot, cond);
1429 res.storagebuf.qualifiers = qualifiers;
1430 res.storagebuf.type_name = type_name;
1431 res.storagebuf.name = name;
1432 resources_get_(freq).append(res);
1433 interface_names_size_ += name.size() + 1;
1434 return *static_cast<Self *>(this);
1435 }
1436
1438 StringRefNull name,
1440 ConditionFn cond = nullptr)
1441 {
1443 res.acceleration_structure.name = name;
1444 resources_get_(freq).append(res);
1445 interface_names_size_ += name.size() + 1;
1447 return *(Self *)this;
1448 }
1449
1450 Self &image(int slot,
1451 TextureFormat format,
1452 Qualifier qualifiers,
1453 ImageReadWriteType type,
1454 StringRefNull name,
1456 ConditionFn cond = nullptr)
1457 {
1458 Resource res(*this, Resource::BindType::IMAGE, slot, cond);
1459 res.image.format = format;
1460 res.image.qualifiers = qualifiers;
1461 res.image.type = ImageType(type);
1462 res.image.name = name;
1463 resources_get_(freq).append(res);
1464 interface_names_size_ += name.size() + 1;
1465 return *static_cast<Self *>(this);
1466 }
1467
1468 Self &sampler(int slot,
1469 ImageType type,
1470 StringRefNull name,
1472 ConditionFn cond = nullptr)
1473 {
1474 Resource res(*this, Resource::BindType::SAMPLER, slot, cond);
1475 res.sampler.type = type;
1476 res.sampler.name = name;
1477 resources_get_(freq).append(res);
1478 interface_names_size_ += name.size() + 1;
1479 return *static_cast<Self *>(this);
1480 }
1481
1483
1484 /* -------------------------------------------------------------------- */
1487
1489 {
1491 return *static_cast<Self *>(this);
1492 }
1493
1495 {
1497 return *static_cast<Self *>(this);
1498 }
1499
1501 {
1503 return *static_cast<Self *>(this);
1504 }
1505
1507 {
1508 vertex_entry_fn_ = function_name;
1509 return *static_cast<Self *>(this);
1510 }
1511
1513 {
1514 fragment_entry_fn_ = function_name;
1515 return *static_cast<Self *>(this);
1516 }
1517
1519 {
1520 compute_entry_fn_ = function_name;
1521 return *static_cast<Self *>(this);
1522 }
1523
1525
1526 /* -------------------------------------------------------------------- */
1532
1534 StringRefNull name,
1535 int array_size = 0,
1536 ConditionFn cond = nullptr)
1537 {
1538 /* We don't have support for UINT push constants yet, use INT instead. */
1539 BLI_assert(type != Type::uint_t);
1540 BLI_assert_msg(name.find("[") == -1,
1541 "Array syntax is forbidden for push constants."
1542 "Use the array_size parameter instead.");
1543 push_constants_.append_as(type, name, array_size, cond ? Conditions(cond) : Conditions());
1544 interface_names_size_ += name.size() + 1;
1545 return *static_cast<Self *>(this);
1546 }
1547
1549
1550 /* -------------------------------------------------------------------- */
1553
1555 {
1556 defines_.append({name, value});
1557 return *static_cast<Self *>(this);
1558 }
1559
1561
1562 /* -------------------------------------------------------------------- */
1565
1567 {
1568 do_static_compilation_ = value;
1569 return *static_cast<Self *>(this);
1570 }
1571
1573 {
1574 builtins_.append_as(builtin, cond ? Conditions(cond) : Conditions());
1575 return *static_cast<Self *>(this);
1576 }
1577
1578 /* Defines how the fragment shader will write to gl_FragDepth. */
1580 {
1581 depth_write_ = value;
1582 return *static_cast<Self *>(this);
1583 }
1584
1586 {
1587 metal_backend_only_ = flag;
1588 return *static_cast<Self *>(this);
1589 }
1590
1592
1593 /* -------------------------------------------------------------------- */
1598
1600 {
1601 additional_infos_.append({info_name});
1602 return *static_cast<Self *>(this);
1603 }
1604
1605 template<typename... Args> Self &additional_info(StringRefNull info_name, Args... args)
1606 {
1607 additional_info(info_name);
1608 additional_info(args...);
1609 return *static_cast<Self *>(this);
1610 }
1611
1613 {
1614 additional_infos_.append_as(info_name, cond ? Conditions(cond) : Conditions());
1615 return *static_cast<Self *>(this);
1616 }
1617
1619
1620 /* -------------------------------------------------------------------- */
1627
1629 {
1630 typedef_sources_.append(filename);
1631 return *static_cast<Self *>(this);
1632 }
1633
1635
1636 /* -------------------------------------------------------------------- */
1643
1649 Self &mtl_max_total_threads_per_threadgroup(ushort max_total_threads_per_threadgroup)
1650 {
1651# ifdef WITH_METAL_BACKEND
1652 mtl_max_threads_per_threadgroup_ = max_total_threads_per_threadgroup;
1653# else
1654 UNUSED_VARS(max_total_threads_per_threadgroup);
1655# endif
1656 return *static_cast<Self *>(this);
1657 }
1658
1660
1661 /* -------------------------------------------------------------------- */
1667
1668 /* WARNING: Recursive evaluation is not thread safe.
1669 * Non-recursive evaluation expects their dependencies to be already finalized.
1670 * (All statically declared CreateInfos are automatically finalized at startup) */
1671 void finalize(const bool recursive = false);
1672
1673 std::string resource_guard_defines(Span<CompilationConstant> constants) const;
1674 std::string iface_guard_defines() const;
1675
1676 void extend_predicate(Vector<Resource, 0> &resource_vector,
1678 Span<ConditionFn> additional_conditions) const;
1679 void extend_predicate(Vector<PushConst, 0> &resource_vector,
1681 Span<ConditionFn> additional_conditions) const;
1682 void assert_no_overlap(const ShaderCreateInfo &info,
1683 const bool test,
1684 const StringRefNull error) const;
1685 void set_resource_slot(Resource &res,
1686 int &images,
1687 int &samplers,
1688 int &ubos,
1689 int &ssbos,
1690 int &acceleration_structures) const;
1691 std::string check_error() const;
1692 bool is_vulkan_compatible() const;
1693
1695 void validate_merge(const ShaderCreateInfo &other_info);
1696 void validate_vertex_attributes(const ShaderCreateInfo *other_info = nullptr);
1697
1699
1700 /* -------------------------------------------------------------------- */
1704
1705 /* Comparison operator for GPUPass cache. We only compare if it will create the same shader
1706 * code. So we do not compare name and some other internal stuff. */
1734
1736 friend std::ostream &operator<<(std::ostream &stream, const ShaderCreateInfo &info)
1737 {
1738 /* TODO(@fclem): Complete print. */
1739
1740 auto print_resource = [&](const Resource &res) {
1741 switch (res.bind_type) {
1743 stream << "UNIFORM_BUFFER(" << res.slot << ", " << res.uniformbuf.name << ")"
1744 << std::endl;
1745 break;
1747 stream << "STORAGE_BUFFER(" << res.slot << ", " << res.storagebuf.name << ")"
1748 << std::endl;
1749 break;
1751 stream << "SAMPLER(" << res.slot << ", " << res.sampler.name << ")" << std::endl;
1752 break;
1754 stream << "IMAGE(" << res.slot << ", " << res.image.name << ")" << std::endl;
1755 break;
1757 stream << "ACCELERATION_STRUCTURE(" << res.slot << ", "
1758 << res.acceleration_structure.name << ")" << std::endl;
1759 break;
1760 }
1761 };
1762
1763 /* TODO(@fclem): Order the resources. */
1764 for (const auto &res : info.batch_resources_) {
1765 print_resource(res);
1766 }
1767 for (const auto &res : info.pass_resources_) {
1768 print_resource(res);
1769 }
1770 for (const auto &res : info.geometry_resources_) {
1771 print_resource(res);
1772 }
1773 return stream;
1774 }
1775
1777 {
1778 for (const auto &res : batch_resources_) {
1779 if (res.bind_type == bind_type) {
1780 return true;
1781 }
1782 }
1783 for (const auto &res : pass_resources_) {
1784 if (res.bind_type == bind_type) {
1785 return true;
1786 }
1787 }
1788 for (const auto &res : geometry_resources_) {
1789 if (res.bind_type == bind_type) {
1790 return true;
1791 }
1792 }
1793 return false;
1794 }
1795
1797 {
1799 }
1800
1801 int sampler_count() const
1802 {
1803 int count = 0;
1804 for (const ShaderCreateInfo::Resource &res : this->pass_resources_) {
1805 count += int(res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER);
1806 }
1807 for (const ShaderCreateInfo::Resource &res : this->batch_resources_) {
1808 count += int(res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER);
1809 }
1810 for (const ShaderCreateInfo::Resource &res : this->geometry_resources_) {
1811 count += int(res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER);
1812 }
1813 return count;
1814 }
1815
1817 {
1818 int slot = 0;
1819 for (const ShaderCreateInfo::Resource &res : this->pass_resources_) {
1820 if (res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER) {
1821 slot = std::max(slot, res.slot);
1822 }
1823 }
1824 for (const ShaderCreateInfo::Resource &res : this->batch_resources_) {
1825 if (res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER) {
1826 slot = std::max(slot, res.slot);
1827 }
1828 }
1829 for (const ShaderCreateInfo::Resource &res : this->geometry_resources_) {
1830 if (res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER) {
1831 slot = std::max(slot, res.slot);
1832 }
1833 }
1834 return slot;
1835 }
1836
1838
1839 /* -------------------------------------------------------------------- */
1842
1853 {
1854 pipelines_.append({});
1855 return pipelines_.last();
1856 }
1857
1859
1860# undef TEST_EQUAL
1861# undef TEST_VECTOR_EQUAL
1862};
1863
1864/* Storage for strings referenced but the patched create info. */
1866
1867} // namespace gpu::shader
1868
1871 {
1872 uint64_t hash = 0;
1873 for (const gpu::shader::SpecializationConstant::Value &value : key) {
1874 hash = hash * 33 ^ uint64_t(value.u);
1875 }
1876 return hash;
1877 }
1878};
1879
1880#endif
1881
1882#if !defined(GPU_SHADER)
1883} // namespace blender
1884#endif
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define BLI_assert_msg(a, msg)
constexpr StringRef()
constexpr int64_t find_first_of(StringRef chars, int64_t pos=0) const
constexpr int64_t size() const
constexpr int64_t find(char c, int64_t pos=0) const
constexpr StringRef substr(int64_t start, int64_t size) const
constexpr const char * c_str() const
#define str(s)
#define SMOOTH(type, name)
#define TYPES_EXPAND(s)
#define TEST_VECTOR_EQUAL(a, b, _vector)
#define FLAT(type, name)
#define NO_PERSPECTIVE(type, name)
#define TEST_EQUAL(a, b, _member)
#define raster_order_group(i)
std::string filename(const std::string_view &str, size_t pos)
Vector< shader::GeneratedSource, 0 > GeneratedSourceList
static bool is_atomic_type(ImageType type)
static Type to_type(const GPUType type)
static std::ostream & operator<<(std::ostream &stream, const Type type)
Vector< std::unique_ptr< std::string >, 0 > ShaderCreateInfoStringCache
ENUM_OPERATORS(BuiltinBits)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
__int64 int64_t
Definition BKE_text.h:90
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)
Definition voxel.cc:16
unsigned int uint
Definition BKE_text.h:55
unsigned short ushort
Definition BKE_text.h:56
@ GPU_KERNEL_GLOBALS
#define hash
Definition noise_c.cc:156
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
uint64_t operator()(const Vector< gpu::shader::SpecializationConstant::Value > &key) const
Description of a graphical pipeline to pre-compile during shader creation.
constexpr ResourceString(const char *str, int64_t size)
ResourceString(std::nullptr_t)=delete
bool evaluate(Span< CompilationConstant > constants) const
Resource(const ShaderCreateInfo &info, BindType type, int _slot, ConditionFn cond)
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
Self & uniform_buf(int slot, StringRefNull type_name, StringRefNull name, Frequency freq=Frequency::PASS, ConditionFn cond=nullptr)
void validate_vertex_attributes(const ShaderCreateInfo *other_info=nullptr)
Self & mtl_max_total_threads_per_threadgroup(ushort max_total_threads_per_threadgroup)
Self & image(int slot, TextureFormat format, Qualifier qualifiers, ImageReadWriteType type, StringRefNull name, Frequency freq=Frequency::PASS, ConditionFn cond=nullptr)
Self & compute_source(StringRefNull filename)
Self & compilation_constant(Type type, StringRefNull name, double default_value)
Self & additional_info_with_condition(StringRefNull info_name, ConditionFn cond=nullptr)
Self & geometry_layout(PrimitiveIn prim_in, PrimitiveOut prim_out, int max_vertices, int invocations=-1)
Self & fragment_source(StringRefNull filename)
Vector< SpecializationConstant, 0 > specialization_constants_
void extend_predicate(Vector< Resource, 0 > &resource_vector, ShaderCreateInfo::Resource res_copy, Span< ConditionFn > additional_conditions) const
Self & vertex_in(int slot, Type type, StringRefNull name, ConditionFn cond=nullptr)
void assert_no_overlap(const ShaderCreateInfo &info, const bool test, const StringRefNull error) const
Vector< CompilationConstant, 0 > compilation_constants_
void finalize(const bool recursive=false)
std::string resource_guard_defines(Span< CompilationConstant > constants) const
Self & fragment_out(int slot, Type type, StringRefNull name, DualBlend blend=DualBlend::NONE, int raster_order_group=-1, ConditionFn cond=nullptr)
Vector< StageInterfaceInfoHandle, 0 > geometry_out_interfaces_
Vector< Resource, 0 > & resources_get_(Frequency freq)
void validate_merge(const ShaderCreateInfo &other_info)
Vector< StageInterfaceInfoHandle, 0 > vertex_out_interfaces_
Self & shared_variable(Type type, StringRefNull name)
bool operator==(const ShaderCreateInfo &b) const
Self & vertex_function(StringRefNull function_name)
Self & additional_info(StringRefNull info_name)
Self & typedef_source(StringRefNull filename)
Self & storage_buf(int slot, Qualifier qualifiers, StringRefNull type_name, StringRefNull name, Frequency freq=Frequency::PASS, ConditionFn cond=nullptr)
bool has_resource_type(Resource::BindType bind_type) const
Self & shared_resource_descriptor(void(*fn)(ShaderCreateInfo &))
void set_resource_slot(Resource &res, int &images, int &samplers, int &ubos, int &ssbos, int &acceleration_structures) const
Self & builtins(BuiltinBits builtin, ConditionFn cond=nullptr)
Self & acceleration_structure(int slot, StringRefNull name, Frequency freq=Frequency::PASS, ConditionFn cond=nullptr)
Self & compute_function(StringRefNull function_name)
Self & additional_info(StringRefNull info_name, Args... args)
Self & subpass_in(int slot, Type type, ImageType img_type, StringRefNull name, int raster_order_group=-1)
Self & specialization_constant(Type type, StringRefNull name, double default_value)
Self & fragment_function(StringRefNull function_name)
friend std::ostream & operator<<(std::ostream &stream, const ShaderCreateInfo &info)
Self & local_group_size(int local_size_x, int local_size_y=1, int local_size_z=1)
Self & vertex_out(StageInterfaceInfo &interface, ConditionFn cond=nullptr)
PipelineState & pipeline_state()
Create a new pipeline state.
static int find_constant(Span< CompilationConstant > constants, StringRefNull name)
Self & sampler(int slot, ImageType type, StringRefNull name, Frequency freq=Frequency::PASS, ConditionFn cond=nullptr)
Self & define(StringRefNull name, StringRefNull value="")
Self & geometry_out(StageInterfaceInfo &interface, ConditionFn cond=nullptr)
Self & push_constant(Type type, StringRefNull name, int array_size=0, ConditionFn cond=nullptr)
std::function< bool(Span< CompilationConstant >)> ConditionFn
Vector< std::array< StringRefNull, 2 >, 0 > defines_
Self & smooth(Type type, StringRefNull _name)
StageInterfaceInfo(const char *name_, const char *instance_name_="")
Self & no_perspective(Type type, StringRefNull _name)
Self & flat(Type type, StringRefNull _name)