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
52 bool use_flat =
false;
53 bool use_smooth =
false;
54 bool use_noperspective =
false;
64 use_noperspective =
true;
68 int num_used_interpolation_types = (use_flat ? 1 : 0) + (use_smooth ? 1 : 0) +
69 (use_noperspective ? 1 : 0);
72 if (num_used_interpolation_types > 1) {
73 std::cout <<
"'" << iface.
name <<
"' uses multiple interpolation types\n";
77 return num_used_interpolation_types <= 1;
101 if (
name_.startswith(
"MA") ||
name_.startswith(
"WO")) {
102 defines +=
"#define CREATE_INFO_Material\n";
105 defines +=
"#define CREATE_INFO_" +
name_ +
"\n";
167#ifdef WITH_METAL_BACKEND
168 if (mtl_max_threads_per_threadgroup_ == 0) {
169 mtl_max_threads_per_threadgroup_ = info.mtl_max_threads_per_threadgroup_;
190 std::cout <<
name_ <<
": Validation failed while merging " << info.
name_ <<
" : ";
191 std::cout <<
error << std::endl;
197 assert_no_overlap(
false,
"additional info already merged via another info");
201 assert_no_overlap(
compute_layout_.local_size_x == -1,
"Compute layout already defined");
206 assert_no_overlap(
vertex_source_.is_empty(),
"Vertex source already existing");
210 assert_no_overlap(
geometry_source_.is_empty(),
"Geometry source already existing");
215 assert_no_overlap(
fragment_source_.is_empty(),
"Fragment source already existing");
219 assert_no_overlap(
compute_source_.is_empty(),
"Compute source already existing");
224 assert_no_overlap(
vertex_entry_fn_ ==
"main",
"Vertex function already existing");
228 assert_no_overlap(
geometry_entry_fn_ ==
"main",
"Geometry function already existing");
232 assert_no_overlap(
fragment_entry_fn_ ==
"main",
"Fragment function already existing");
236 assert_no_overlap(
compute_entry_fn_ ==
"main",
"Compute function already existing");
243 <<
": Validation failed. BuiltinBits::LAYER shouldn't be used with geometry shaders."
249 int images = 0, samplers = 0, ubos = 0, ssbos = 0;
251 auto set_resource_slot = [&](
Resource &res) {
252 switch (res.bind_type) {
260 res.slot = samplers++;
269 set_resource_slot(res);
272 set_resource_slot(res);
275 set_resource_slot(res);
287 error +=
"Missing vertex shader in " + this->
name_ +
".\n";
290 error +=
"Missing fragment shader in " + this->
name_ +
".\n";
295 error +=
"Compute shader has vertex_source_ shader attached in " + this->
name_ +
".\n";
298 error +=
"Compute shader has geometry_source_ shader attached in " + this->
name_ +
".\n";
301 error +=
"Compute shader has fragment_source_ shader attached in " + this->
name_ +
".\n";
308 " has geometry stage and uses barycentric coordinates. This is not allowed as "
309 "fallback injects a geometry stage.\n";
313 " has geometry stage and uses multi-viewport. This is not allowed as "
314 "fallback injects a geometry stage.\n";
318 " has geometry stage and uses layer output. This is not allowed as "
319 "fallback injects a geometry stage.\n";
331 if (
interface->instance_name.is_empty()) {
333 " that doesn't contain an instance name, but is required for the fallback "
334 "geometry shader.\n";
340 error += this->
name_ +
341 " contains a stage interface using an instance name and mixed interpolation modes. "
342 "This is not compatible with Vulkan and need to be adjusted.\n";
349 error += this->
name_ +
" contains two specialization constants with the name: " +
359 error += this->
name_ +
" contains two compilation constants with the name: " +
369 error += this->
name_ +
" contains two specialization constants with the name: " +
382 Set<int> images, samplers, ubos, ssbos;
384 auto register_resource = [&](
const Resource &res) ->
bool {
385 switch (res.bind_type) {
387 return images.
add(res.slot);
389 return samplers.
add(res.slot);
391 return ubos.
add(res.slot);
393 return ssbos.
add(res.slot);
400 auto print_resource_name = [&](
const Resource &res) {
415 std::cout <<
"Unknown Type";
420 for (
const Resource &_res : resources) {
421 if (&res != &_res && res.
bind_type == _res.bind_type && res.
slot == _res.slot) {
422 std::cout <<
name_ <<
": Validation failed : Overlapping ";
423 print_resource_name(res);
424 std::cout <<
" and ";
425 print_resource_name(_res);
426 std::cout <<
" at (" << res.
slot <<
") while merging " << other_info.
name_ << std::endl;
432 if (register_resource(res) ==
false) {
438 if (register_resource(res) ==
false) {
444 if (register_resource(res) ==
false) {
453 uint32_t attr_bits = 0;
455 if (attr.index >= 16 || attr.index < 0) {
456 std::cout <<
name_ <<
": \"" << attr.name
457 <<
"\" : Type::float3x3_t unsupported as vertex attribute." << std::endl;
460 if (attr.index >= 16 || attr.index < 0) {
461 std::cout <<
name_ <<
": Invalid index for attribute \"" << attr.name <<
"\"" << std::endl;
464 uint32_t attr_new = 0;
466 for (
int i = 0;
i < 4;
i++) {
467 attr_new |= 1 << (attr.index +
i);
471 attr_new |= 1 << attr.index;
474 if ((attr_bits & attr_new) != 0) {
475 std::cout <<
name_ <<
": Attribute \"" << attr.name
476 <<
"\" overlap one or more index from another attribute."
477 " Note that mat4 takes up 4 indices.";
479 std::cout <<
" While merging " << other_info->
name_ << std::endl;
481 std::cout << std::endl;
484 attr_bits |= attr_new;
499# pragma optimize("", off)
506#define GPU_SHADER_NAMED_INTERFACE_INFO(_interface, _inst_name) \
507 StageInterfaceInfo *ptr_##_interface = new StageInterfaceInfo(#_interface, #_inst_name); \
508 StageInterfaceInfo &_interface = *ptr_##_interface; \
509 g_interfaces->add_new(#_interface, ptr_##_interface); \
512#define GPU_SHADER_INTERFACE_INFO(_interface) \
513 StageInterfaceInfo *ptr_##_interface = new StageInterfaceInfo(#_interface); \
514 StageInterfaceInfo &_interface = *ptr_##_interface; \
515 g_interfaces->add_new(#_interface, ptr_##_interface); \
518#define GPU_SHADER_CREATE_INFO(_info) \
519 ShaderCreateInfo *ptr_##_info = new ShaderCreateInfo(#_info); \
520 ShaderCreateInfo &_info = *ptr_##_info; \
521 g_create_infos->add_new(#_info, ptr_##_info); \
524#define GPU_SHADER_NAMED_INTERFACE_END(_inst_name) ;
525#define GPU_SHADER_INTERFACE_END() ;
526#define GPU_SHADER_CREATE_END() ;
529#include "glsl_compositor_infos_list.hh"
530#include "glsl_draw_infos_list.hh"
531#include "glsl_gpu_infos_list.hh"
532#include "glsl_ocio_infos_list.hh"
533#ifdef WITH_OPENSUBDIV
534# include "glsl_osd_infos_list.hh"
539 eevee_deferred_tile_classify.storage_buf(
544 info->is_generated_ =
false;
551#if GPU_SHADER_PRINTF_ENABLE
552 const bool is_material_shader = info->name_.startswith(
"eevee_surf_");
556 info->additional_info(
"gpu_print");
563 info->additional_info(
"draw_debug_draw");
569 info->finalize(
true);
576# pragma optimize("", on)
597 int skipped_filter = 0;
605 if (info->do_static_compilation_) {
606 if (name_starts_with_filter &&
620 infos.
append(
reinterpret_cast<const GPUShaderCreateInfo *
>(info));
627 for (
int i :
result.index_range()) {
630 std::cerr <<
"Compilation " << info->
name_.
c_str() <<
" Failed\n";
645 switch (res.bind_type) {
648 name = res.uniformbuf.name;
652 name = res.storagebuf.name;
656 name = res.sampler.name;
660 name = res.image.name;
664 if (
input ==
nullptr) {
665 std::cerr <<
"Error: " << info->
name_;
666 std::cerr <<
": Resource « " <<
name <<
" » not found in the shader interface\n";
668 else if (
input->location == -1) {
669 std::cerr <<
"Warning: " << info->
name_;
670 std::cerr <<
": Resource « " <<
name <<
" » is optimized out\n";
678 printf(
"Shader Test compilation result: %d / %d passed", success, total);
679 if (skipped_filter > 0) {
680 printf(
" (skipped %d when filtering)", skipped_filter);
683 printf(
" (skipped %d for compatibility reasons)", skipped);
686 return success == total;
692 printf(
"Error: Cannot find shader create info named \"%s\"\n", info_name);
696 return reinterpret_cast<const GPUShaderCreateInfo *
>(info);
bool GPU_geometry_shader_support()
bool GPU_stencil_clasify_buffer_workaround()
GPUBackendType GPU_backend_get_type()
void GPU_shader_free(blender::gpu::Shader *shader)
blender::Vector< blender::gpu::Shader * > GPU_shader_batch_finalize(BatchHandle &handle)
BatchHandle GPU_shader_batch_create_from_infos(blender::Span< const GPUShaderCreateInfo * > infos, CompilationPriority priority=CompilationPriority::High)
void append(const T &value)
constexpr bool is_empty() const
constexpr const char * c_str() const
struct @021025263243242147216143265077100330027142264337::@225245033123204053237120173316075113304004012000 batch
const GPUShaderCreateInfo * gpu_shader_create_info_get(const char *info_name)
void gpu_shader_create_info_exit()
bool gpu_shader_create_info_compile(const char *name_starts_with_filter)
void gpu_shader_create_info_init()
static void error(const char *str)
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)
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
StringRefNull vertex_source_
Vector< StageInterfaceInfo * > vertex_out_interfaces_
StringRefNull compute_source_
Vector< SubpassIn > subpass_inputs_
ShaderCreateInfo(const char *name)
StringRefNull compute_entry_fn_
Vector< Resource > geometry_resources_
Vector< std::array< StringRefNull, 2 > > defines_
Vector< CompilationConstant, 0 > compilation_constants_
void validate_vertex_attributes(const ShaderCreateInfo *other_info=nullptr)
std::string check_error() const
Vector< VertIn > vertex_inputs_
bool early_fragment_test_
bool auto_resource_location_
void finalize(const bool recursive=false)
Vector< Resource > batch_resources_
bool is_vulkan_compatible() const
StringRefNull geometry_entry_fn_
size_t interface_names_size_
Vector< StringRefNull > additional_infos_
StringRefNull geometry_source_
Vector< StageInterfaceInfo * > geometry_out_interfaces_
Vector< Resource > pass_resources_
StringRefNull vertex_entry_fn_
Vector< Resource > resources_get_all_() const
GeometryStageLayout geometry_layout_
StringRefNull fragment_source_
Vector< SharedVariable, 0 > shared_variables_
ComputeStageLayout compute_layout_
StringRefNull fragment_entry_fn_
void validate_merge(const ShaderCreateInfo &other_info)
void resource_guard_defines(std::string &defines) const
Vector< SpecializationConstant > specialization_constants_
Vector< StringRefNull > typedef_sources_
Vector< PushConst > push_constants_
Vector< FragOut > fragment_outputs_
StringRefNull instance_name