26#undef GPU_SHADER_NAMED_INTERFACE_INFO
27#undef GPU_SHADER_INTERFACE_INFO
28#undef GPU_SHADER_CREATE_INFO
29#undef GPU_SHADER_NAMED_INTERFACE_END
30#undef GPU_SHADER_INTERFACE_END
31#undef GPU_SHADER_CREATE_END
54 bool use_flat =
false;
55 bool use_smooth =
false;
56 bool use_noperspective =
false;
66 use_noperspective =
true;
70 int num_used_interpolation_types = (use_flat ? 1 : 0) + (use_smooth ? 1 : 0) +
71 (use_noperspective ? 1 : 0);
74 if (num_used_interpolation_types > 1) {
75 std::cout <<
"'" << iface.
name <<
"' uses multiple interpolation types\n";
79 return num_used_interpolation_types <= 1;
103 bool last_char_is_underscore =
false;
105 for (
char &c :
name_) {
106 if (!std::isalnum(c)) {
109 if (c ==
'_' && last_char_is_underscore) {
113 last_char_is_underscore = c ==
'_';
120 defines +=
"#define CREATE_INFO_" +
name_ +
"\n";
136 defines +=
"#define IFACE_INFO_" + interface->name +
"\n";
148 auto deps_merged = std::make_unique<Set<StringRefNull>>();
202#ifdef WITH_METAL_BACKEND
203 if (mtl_max_threads_per_threadgroup_ == 0) {
204 mtl_max_threads_per_threadgroup_ = info.mtl_max_threads_per_threadgroup_;
226 if (!deps_merged->add(info.
name_)) {
227 assert_no_overlap(info,
false,
"additional info already merged via another info");
274 <<
": Validation failed. BuiltinBits::LAYER shouldn't be used with geometry shaders."
284 res_copy.
conditions.extend(additional_conditions);
286 resource_vector.append(res_copy);
293 res_copy.
conditions.extend(additional_conditions);
295 resource_vector.append(res_copy);
303 std::cout <<
name_ <<
": Validation failed while merging " << info.
name_ <<
" : ";
304 std::cout << error << std::endl;
314 int &acceleration_structures)
const
324 res.
slot = samplers++;
330 res.
slot = acceleration_structures++;
342 error +=
"Missing vertex shader in " + this->
name_ +
".\n";
345 error +=
"Missing fragment shader in " + this->
name_ +
".\n";
350 error +=
"Compute shader has vertex_source_ shader attached in " + this->
name_ +
".\n";
353 error +=
"Compute shader has geometry_source_ shader attached in " + this->
name_ +
".\n";
356 error +=
"Compute shader has fragment_source_ shader attached in " + this->
name_ +
".\n";
362 error +=
"Shader " + this->
name_ +
363 " has geometry stage and uses barycentric coordinates. This is not allowed as "
364 "fallback injects a geometry stage.\n";
367 error +=
"Shader " + this->
name_ +
368 " has geometry stage and uses multi-viewport. This is not allowed as "
369 "fallback injects a geometry stage.\n";
372 error +=
"Shader " + this->
name_ +
373 " has geometry stage and uses layer output. This is not allowed as "
374 "fallback injects a geometry stage.\n";
388 if (interface->instance_name.is_empty()) {
389 error +=
"Shader " + this->
name_ +
" uses interface " + interface->name +
390 " that doesn't contain an instance name, but is required for the fallback "
391 "geometry shader.\n";
399 if (
inout.name.is_array()) {
400 error +=
"Shader " + this->
name_ +
" : \"" + interface->name +
"." +
inout.name +
"\":";
401 error +=
" Array types are not allowed in shader stage interfaces.\n";
404 error +=
"Shader " + this->
name_ +
" : \"" + interface->name +
"." +
inout.name +
"\":";
405 error +=
" Matrix types are not allowed in shader stage interfaces.\n";
411 error += this->
name_ +
412 " contains a stage interface using an instance name and mixed interpolation modes. "
413 "This is not compatible with Vulkan and need to be adjusted.\n";
420 error += this->
name_ +
" contains two specialization constants with the name: " +
430 error += this->
name_ +
" contains two compilation constants with the name: " +
440 error += this->
name_ +
" contains two specialization constants with the name: " +
447 Set<int> images, samplers, ubos, ssbos, acceleration_structures;
449 auto register_resource = [&](
const Resource &res) ->
bool {
450 switch (res.bind_type) {
452 return ubos.
add(res.slot);
454 return ssbos.
add(res.slot);
456 return samplers.
add(res.slot);
458 return images.
add(res.slot);
460 return acceleration_structures.
add(res.slot);
467 auto print_resource_name = [&](
const Resource &res) {
470 error +=
"Uniform Buffer " + res.uniformbuf.name;
473 error +=
"Storage Buffer " + res.storagebuf.name;
476 error +=
"Sampler " + res.sampler.name;
479 error +=
"Image " + res.image.name;
482 error +=
"Acceleration Structure " + res.acceleration_structure.name;
485 error +=
"Unknown Type";
490 for (
const Resource &_res : resources) {
491 if (&res != &_res && res.
bind_type == _res.bind_type && res.
slot == _res.slot) {
492 error +=
name_ +
": Validation failed : Overlapping ";
493 print_resource_name(res);
495 print_resource_name(_res);
496 error +=
" at binding location " + std::to_string(res.
slot) +
"\n";
502 if (register_resource(res) ==
false) {
508 if (register_resource(res) ==
false) {
514 if (register_resource(res) ==
false) {
525 Set<int> images, samplers, ubos, ssbos, acceleration_structures;
527 auto register_resource = [&](
const Resource &res) ->
bool {
528 switch (res.bind_type) {
530 return images.
add(res.slot);
532 return samplers.
add(res.slot);
534 return ubos.
add(res.slot);
536 return ssbos.
add(res.slot);
538 return acceleration_structures.
add(res.slot);
545 auto print_resource_name = [&](
const Resource &res) {
548 std::cout <<
"Uniform Buffer " << res.uniformbuf.name;
551 std::cout <<
"Storage Buffer " << res.storagebuf.name;
554 std::cout <<
"Sampler " << res.sampler.name;
557 std::cout <<
"Image " << res.image.name;
560 std::cout <<
"Acceleration Structure " << res.acceleration_structure.name;
563 std::cout <<
"Unknown Type";
568 for (
const Resource &_res : resources) {
569 if (&res != &_res && res.
bind_type == _res.bind_type && res.
slot == _res.slot) {
570 std::cout <<
name_ <<
": Validation failed : Overlapping ";
571 print_resource_name(res);
572 std::cout <<
" and ";
573 print_resource_name(_res);
574 std::cout <<
" at (" << res.
slot <<
") while merging " << other_info.
name_ << std::endl;
580 if (register_resource(res) ==
false) {
586 if (register_resource(res) ==
false) {
592 if (register_resource(res) ==
false) {
603 std::cout <<
name_ <<
": \"" << attr.name <<
"\" : float3x3 unsupported as vertex attribute."
608 std::cout <<
name_ <<
": \"" << attr.name <<
"\" : float4x4 unsupported as vertex attribute."
612 if (attr.name.is_array()) {
613 std::cout <<
name_ <<
": \"" << attr.name
614 <<
"\" : arrays are unsupported as vertex attribute." << std::endl;
617 if (attr.index >= 16 || attr.index < 0) {
618 std::cout <<
name_ <<
": Invalid index for attribute \"" << attr.name <<
"\"" << std::endl;
623 for (
int i = 0; i < 4; i++) {
624 attr_new |= 1 << (attr.index + i);
628 attr_new |= 1 << attr.index;
631 if ((attr_bits & attr_new) != 0) {
632 std::cout <<
name_ <<
": Attribute \"" << attr.name
633 <<
"\" overlap one or more index from another attribute."
634 " Note that mat4 takes up 4 indices.";
636 std::cout <<
" While merging " << other_info->
name_ << std::endl;
638 std::cout << std::endl;
641 attr_bits |= attr_new;
649#define GPU_SHADER_NAMED_INTERFACE_INFO(_interface, _inst_name) \
650 StageInterfaceInfo *ptr_##_interface = new StageInterfaceInfo(#_interface, #_inst_name); \
651 StageInterfaceInfo &_interface = *ptr_##_interface; \
652 g_interfaces->add_new(#_interface, ptr_##_interface); \
655#define GPU_SHADER_INTERFACE_INFO(_interface) \
656 StageInterfaceInfo *ptr_##_interface = new StageInterfaceInfo(#_interface); \
657 StageInterfaceInfo &_interface = *ptr_##_interface; \
658 g_interfaces->add_new(#_interface, ptr_##_interface); \
661#define GPU_SHADER_CREATE_INFO(_info) \
662 ShaderCreateInfo *ptr_##_info = new ShaderCreateInfo(#_info); \
663 ShaderCreateInfo &_info = *ptr_##_info; \
664 g_create_infos->add_new(#_info, ptr_##_info); \
667#define GPU_SHADER_NAMED_INTERFACE_END(_inst_name) ;
668#define GPU_SHADER_INTERFACE_END() ;
669#define GPU_SHADER_CREATE_END() ;
707# pragma optimize("", off)
714#include "glsl_compositor_infos_list.hh"
720#include "glsl_draw_infos_list.hh"
726#include "glsl_eevee_infos_list.hh"
738#include "glsl_select_id_infos_list.hh"
740#include "glsl_overlay_infos_list.hh"
746#include "glsl_image_infos_list.hh"
752#include "glsl_gpencil_infos_list.hh"
758#include "glsl_workbench_infos_list.hh"
764#include "glsl_gpu_infos_list.hh"
770#include "glsl_ocio_infos_list.hh"
776#ifdef WITH_OPENSUBDIV
777# include "glsl_osd_infos_list.hh"
798 info->is_generated_ =
false;
806 info->builtins(builtins);
808 if (!info->compute_source_.is_empty()) {
809 info->shared_variables_.extend(
813#if GPU_SHADER_PRINTF_ENABLE
814 const bool is_material_shader =
StringRefNull(info->name_).startswith(
"eevee_surf_");
818 info->additional_info(
"gpu_print");
825 info->additional_info(
"DebugDraw");
831 info->finalize(
true);
838# pragma optimize("", on)
858 int skipped_filter = 0;
866 if (info->do_static_compilation_) {
867 if (name_starts_with_filter &&
908 switch (res.bind_type) {
910 input = interface->ubo_get(res.slot);
911 name = res.uniformbuf.name;
914 input = interface->ssbo_get(res.slot);
915 name = res.storagebuf.name;
918 input = interface->texture_get(res.slot);
919 name = res.sampler.name;
922 input = interface->texture_get(res.slot);
923 name = res.image.name;
926 input = interface->acceleration_structure_get(res.slot);
927 name = res.acceleration_structure.name;
931 if (input ==
nullptr) {
932 std::cerr <<
"Error: " << info->name_;
933 std::cerr <<
": Resource « " << name <<
" » not found in the shader interface\n";
936 std::cerr <<
"Warning: " << info->name_;
937 std::cerr <<
": Resource « " << name <<
" » is optimized out\n";
945 printf(
"Shader Test compilation result: %d / %d passed", success, total);
946 if (skipped_filter > 0) {
947 printf(
" (skipped %d when filtering)", skipped_filter);
950 printf(
" (skipped %d for compatibility reasons)", skipped);
953 return success == total;
959 printf(
"Error: Cannot find shader create info named \"%s\"\n", info_name);
963 return reinterpret_cast<const GPUShaderCreateInfo *
>(info);
ValueIterator values() const &
const Value & lookup(const Key &key) const
bool contains(const Key &key) const
constexpr StringRefNull()
void append(const T &value)
constexpr bool is_empty() const
PipelineGraphic eevee_deferred_tile_classify(eevee::deferred::tiles::fullscreen_vert, eevee::deferred::tiles::classify_tiles, eevee::deferred::tiles::TileClassification{ .use_stencil_ref_out=true, })
Span< ShaderCreateInfo::SharedVariable > gpu_shader_dependency_get_shared_variables(const StringRefNull shader_source_name)
static CreateInfoDictionary * g_create_infos
Map< StringRef, ShaderCreateInfo * > CreateInfoDictionary
BuiltinBits gpu_shader_dependency_get_builtins(const StringRefNull shader_source_name)
Map< StringRef, StageInterfaceInfo * > InterfaceDictionary
static InterfaceDictionary * g_interfaces
bool gpu_shader_dependency_force_gpu_print_injection()
static bool is_vulkan_compatible_interface(const StageInterfaceInfo &iface)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void GPU_shader_compiler_wait_for_all()
bool GPU_geometry_shader_support()
bool gpu_shader_create_info_compile_all(const char *name_starts_with_filter)
static void init_compositor_infos()
static void init_ocio_infos()
GPUBackendType GPU_backend_get_type()
void gpu_shader_create_info_init()
static void init_workbench_infos()
bool GPU_ray_query_support()
static void init_gpencil_infos()
static void init_overlay_infos()
void gpu_shader_create_info_exit()
static void init_eevee_infos()
static void init_gpu_infos()
static void init_draw_infos()
int64_t AsyncCompilationHandle
static void init_image_infos()
const GPUShaderCreateInfo * gpu_shader_create_info_get(const char *info_name)
static void init_osd_infos()
gpu::Shader * GPU_shader_async_compilation_finalize(AsyncCompilationHandle &handle)
void GPU_shader_free(gpu::Shader *shader)
bool GPU_stencil_classify_buffer_workaround()
AsyncCompilationHandle GPU_shader_async_compilation(const GPUShaderCreateInfo *info, CompilationPriority priority=CompilationPriority::High)
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
StringRefNull vertex_source_
void validate_vertex_attributes(const ShaderCreateInfo *other_info=nullptr)
StringRefNull compute_source_
Vector< Resource, 0 > geometry_resources_
StringRefNull compute_entry_fn_
Vector< StringRefNull, 0 > typedef_sources_
Vector< BuiltinBit, 0 > builtins_
Vector< SpecializationConstant, 0 > specialization_constants_
void extend_predicate(Vector< Resource, 0 > &resource_vector, ShaderCreateInfo::Resource res_copy, Span< ConditionFn > additional_conditions) const
void assert_no_overlap(const ShaderCreateInfo &info, const bool test, const StringRefNull error) const
Vector< CompilationConstant, 0 > compilation_constants_
Vector< AdditionalInfo, 0 > additional_infos_
bool early_fragment_test_
Vector< VertIn, 0 > vertex_inputs_
void finalize(const bool recursive=false)
std::string resource_guard_defines(Span< CompilationConstant > constants) const
Vector< StageInterfaceInfoHandle, 0 > geometry_out_interfaces_
StringRefNull geometry_entry_fn_
void validate_merge(const ShaderCreateInfo &other_info)
size_t interface_names_size_
Vector< StageInterfaceInfoHandle, 0 > vertex_out_interfaces_
Self & additional_info(StringRefNull info_name)
std::string check_error() const
Vector< Resource, 0 > pass_resources_
Vector< PushConst, 0 > push_constants_
StringRefNull geometry_source_
StringRefNull vertex_entry_fn_
std::string iface_guard_defines() const
Vector< Resource > resources_get_all_() const
void set_resource_slot(Resource &res, int &images, int &samplers, int &ubos, int &ssbos, int &acceleration_structures) const
GeometryStageLayout geometry_layout_
StringRefNull fragment_source_
Vector< SubpassIn, 0 > subpass_inputs_
Vector< Resource, 0 > batch_resources_
Vector< SharedVariable, 0 > shared_variables_
ComputeStageLayout compute_layout_
bool is_vulkan_compatible() const
Vector< FragOut, 0 > fragment_outputs_
StringRefNull fragment_entry_fn_
BuiltinBits builtins_combined() const
Vector< std::array< StringRefNull, 2 >, 0 > defines_
ShaderCreateInfo(const char *name)
StringRefNull instance_name