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;
149#ifdef WITH_METAL_BACKEND
150 if (mtl_max_threads_per_threadgroup_ == 0) {
151 mtl_max_threads_per_threadgroup_ = info.mtl_max_threads_per_threadgroup_;
172 std::cout <<
name_ <<
": Validation failed while merging " << info.
name_ <<
" : ";
173 std::cout <<
error << std::endl;
179 assert_no_overlap(
false,
"additional info already merged via another info");
183 assert_no_overlap(
compute_layout_.local_size_x == -1,
"Compute layout already defined");
188 assert_no_overlap(
vertex_source_.is_empty(),
"Vertex source already existing");
192 assert_no_overlap(
geometry_source_.is_empty(),
"Geometry source already existing");
197 assert_no_overlap(
fragment_source_.is_empty(),
"Fragment source already existing");
201 assert_no_overlap(
compute_source_.is_empty(),
"Compute source already existing");
208 <<
": Validation failed. BuiltinBits::LAYER shouldn't be used with geometry shaders."
214 int images = 0, samplers = 0, ubos = 0, ssbos = 0;
216 auto set_resource_slot = [&](
Resource &res) {
217 switch (res.bind_type) {
225 res.slot = samplers++;
234 set_resource_slot(res);
237 set_resource_slot(res);
240 set_resource_slot(res);
252 error +=
"Missing vertex shader in " + this->
name_ +
".\n";
255 error +=
"Missing fragment shader in " + this->
name_ +
".\n";
260 error +=
"Compute shader has vertex_source_ shader attached in " + this->
name_ +
".\n";
263 error +=
"Compute shader has geometry_source_ shader attached in " + this->
name_ +
".\n";
266 error +=
"Compute shader has fragment_source_ shader attached in " + this->
name_ +
".\n";
273 " has geometry stage and uses barycentric coordinates. This is not allowed as "
274 "fallback injects a geometry stage.\n";
278 " has geometry stage and uses multi-viewport. This is not allowed as "
279 "fallback injects a geometry stage.\n";
283 " has geometry stage and uses layer output. This is not allowed as "
284 "fallback injects a geometry stage.\n";
296 if (
interface->instance_name.is_empty()) {
298 " that doesn't contain an instance name, but is required for the fallback "
299 "geometry shader.\n";
305 error += this->
name_ +
306 " contains a stage interface using an instance name and mixed interpolation modes. "
307 "This is not compatible with Vulkan and need to be adjusted.\n";
314 error += this->
name_ +
" contains two specialization constants with the name: " +
324 error += this->
name_ +
" contains two compilation constants with the name: " +
337 Set<int> images, samplers, ubos, ssbos;
339 auto register_resource = [&](
const Resource &res) ->
bool {
340 switch (res.bind_type) {
342 return images.
add(res.slot);
344 return samplers.
add(res.slot);
346 return ubos.
add(res.slot);
348 return ssbos.
add(res.slot);
355 auto print_resource_name = [&](
const Resource &res) {
370 std::cout <<
"Unknown Type";
375 for (
const Resource &_res : resources) {
376 if (&res != &_res && res.
bind_type == _res.bind_type && res.
slot == _res.slot) {
377 std::cout <<
name_ <<
": Validation failed : Overlapping ";
378 print_resource_name(res);
379 std::cout <<
" and ";
380 print_resource_name(_res);
381 std::cout <<
" at (" << res.
slot <<
") while merging " << other_info.
name_ << std::endl;
387 if (register_resource(res) ==
false) {
393 if (register_resource(res) ==
false) {
399 if (register_resource(res) ==
false) {
408 uint32_t attr_bits = 0;
410 if (attr.index >= 16 || attr.index < 0) {
411 std::cout <<
name_ <<
": \"" << attr.name
412 <<
"\" : Type::float3x3_t unsupported as vertex attribute." << std::endl;
415 if (attr.index >= 16 || attr.index < 0) {
416 std::cout <<
name_ <<
": Invalid index for attribute \"" << attr.name <<
"\"" << std::endl;
419 uint32_t attr_new = 0;
421 for (
int i = 0;
i < 4;
i++) {
422 attr_new |= 1 << (attr.index +
i);
426 attr_new |= 1 << attr.index;
429 if ((attr_bits & attr_new) != 0) {
430 std::cout <<
name_ <<
": Attribute \"" << attr.name
431 <<
"\" overlap one or more index from another attribute."
432 " Note that mat4 takes up 4 indices.";
434 std::cout <<
" While merging " << other_info->
name_ << std::endl;
436 std::cout << std::endl;
439 attr_bits |= attr_new;
454# pragma optimize("", off)
461#define GPU_SHADER_NAMED_INTERFACE_INFO(_interface, _inst_name) \
462 StageInterfaceInfo *ptr_##_interface = new StageInterfaceInfo(#_interface, #_inst_name); \
463 StageInterfaceInfo &_interface = *ptr_##_interface; \
464 g_interfaces->add_new(#_interface, ptr_##_interface); \
467#define GPU_SHADER_INTERFACE_INFO(_interface) \
468 StageInterfaceInfo *ptr_##_interface = new StageInterfaceInfo(#_interface); \
469 StageInterfaceInfo &_interface = *ptr_##_interface; \
470 g_interfaces->add_new(#_interface, ptr_##_interface); \
473#define GPU_SHADER_CREATE_INFO(_info) \
474 ShaderCreateInfo *ptr_##_info = new ShaderCreateInfo(#_info); \
475 ShaderCreateInfo &_info = *ptr_##_info; \
476 g_create_infos->add_new(#_info, ptr_##_info); \
479#define GPU_SHADER_NAMED_INTERFACE_END(_inst_name) ;
480#define GPU_SHADER_INTERFACE_END() ;
481#define GPU_SHADER_CREATE_END() ;
488 draw_resource_id = draw_resource_id_fallback;
489 draw_resource_with_custom_id = draw_resource_with_custom_id_fallback;
494 eevee_deferred_tile_classify.storage_buf(
504#if GPU_SHADER_PRINTF_ENABLE
505 const bool is_material_shader = info->name_.startswith(
"eevee_surf_");
509 info->additional_info(
"gpu_print");
515 if ((info->builtins_ & BuiltinBits::USE_DEBUG_DRAW) == BuiltinBits::USE_DEBUG_DRAW) {
516 info->additional_info(
"draw_debug_draw");
522 info->finalize(
true);
529# pragma optimize("", on)
550 int skipped_filter = 0;
558 if (info->do_static_compilation_) {
559 if (name_starts_with_filter &&
573 infos.
append(
reinterpret_cast<const GPUShaderCreateInfo *
>(info));
580 for (
int i :
result.index_range()) {
583 std::cerr <<
"Compilation " << info->
name_.
c_str() <<
" Failed\n";
598 switch (res.bind_type) {
601 name = res.uniformbuf.name;
605 name = res.storagebuf.name;
609 name = res.sampler.name;
613 name = res.image.name;
617 if (
input ==
nullptr) {
618 std::cerr <<
"Error: " << info->
name_;
619 std::cerr <<
": Resource « " << name <<
" » not found in the shader interface\n";
621 else if (
input->location == -1) {
622 std::cerr <<
"Warning: " << info->
name_;
623 std::cerr <<
": Resource « " << name <<
" » is optimized out\n";
631 printf(
"Shader Test compilation result: %d / %d passed", success, total);
632 if (skipped_filter > 0) {
633 printf(
" (skipped %d when filtering)", skipped_filter);
636 printf(
" (skipped %d for compatibility reasons)", skipped);
639 return success == total;
645 printf(
"Error: Cannot find shader create info named \"%s\"\n", info_name);
649 return reinterpret_cast<const GPUShaderCreateInfo *
>(info);
bool GPU_geometry_shader_support()
bool GPU_stencil_clasify_buffer_workaround()
bool GPU_shader_draw_parameters_support()
eGPUBackendType GPU_backend_get_type()
blender::Vector< GPUShader * > GPU_shader_batch_finalize(BatchHandle &handle)
void GPU_shader_free(GPUShader *shader)
BatchHandle GPU_shader_batch_create_from_infos(blender::Span< const GPUShaderCreateInfo * > infos, CompilationPriority priority=CompilationPriority::High)
void append(const T &value)
ValueIterator values() const &
constexpr bool is_empty() const
constexpr const char * c_str() const
struct @064345207361167251075330302113175271221317160336::@113254110077376341056327177062323111323010325277 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)
Map< StringRef, ShaderCreateInfo * > CreateInfoDictionnary
Map< StringRef, StageInterfaceInfo * > InterfaceDictionnary
BuiltinBits gpu_shader_dependency_get_builtins(const StringRefNull shader_source_name)
static InterfaceDictionnary * g_interfaces
bool gpu_shader_dependency_force_gpu_print_injection()
static bool is_vulkan_compatible_interface(const StageInterfaceInfo &iface)
static CreateInfoDictionnary * g_create_infos
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)
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
size_t interface_names_size_
Vector< StringRefNull > additional_infos_
StringRefNull geometry_source_
Vector< StageInterfaceInfo * > geometry_out_interfaces_
Vector< Resource > pass_resources_
Vector< Resource > resources_get_all_() const
GeometryStageLayout geometry_layout_
StringRefNull fragment_source_
ComputeStageLayout compute_layout_
void validate_merge(const ShaderCreateInfo &other_info)
Vector< SpecializationConstant > specialization_constants_
Vector< StringRefNull > typedef_sources_
Vector< PushConst > push_constants_
Vector< FragOut > fragment_outputs_
StringRefNull instance_name