28#undef GPU_SHADER_INTERFACE_INFO
29#undef GPU_SHADER_CREATE_INFO
52 bool use_flat =
false;
53 bool use_smooth =
false;
54 bool use_noperspective =
false;
56 switch (attr.interp) {
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;
148#ifdef WITH_METAL_BACKEND
149 if (mtl_max_threads_per_threadgroup_ == 0) {
150 mtl_max_threads_per_threadgroup_ = info.mtl_max_threads_per_threadgroup_;
170 std::cout <<
name_ <<
": Validation failed while merging " << info.
name_ <<
" : ";
171 std::cout <<
error << std::endl;
177 assert_no_overlap(
false,
"additional info already merged via another info");
206 <<
": Validation failed. BuiltinBits::LAYER shouldn't be used with geometry shaders."
212 int images = 0, samplers = 0, ubos = 0, ssbos = 0;
214 auto set_resource_slot = [&](
Resource &res) {
215 switch (res.bind_type) {
223 res.slot = samplers++;
232 set_resource_slot(res);
235 set_resource_slot(res);
238 set_resource_slot(res);
250 error +=
"Missing vertex shader in " + this->
name_ +
".\n";
253 error +=
"Missing fragment shader in " + this->
name_ +
".\n";
258 error +=
"Compute shader has vertex_source_ shader attached in " + this->
name_ +
".\n";
261 error +=
"Compute shader has geometry_source_ shader attached in " + this->
name_ +
".\n";
264 error +=
"Compute shader has fragment_source_ shader attached in " + this->
name_ +
".\n";
270 error +=
"Shader " + this->
name_ +
271 " has geometry stage and uses barycentric coordinates. This is not allowed as "
272 "fallback injects a geometry stage.\n";
275 error +=
"Shader " + this->
name_ +
276 " has geometry stage and uses multi-viewport. This is not allowed as "
277 "fallback injects a geometry stage.\n";
280 error +=
"Shader " + this->
name_ +
281 " has geometry stage and uses layer output. This is not allowed as "
282 "fallback injects a geometry stage.\n";
300 if (interface->instance_name.is_empty()) {
301 error +=
"Shader " + this->
name_ +
" uses interface " + interface->name +
302 " that doesn't contain an instance name, but is required for the fallback "
303 "geometry shader.\n";
310 error += this->
name_ +
311 " contains a stage interface using an instance name and mixed interpolation modes. "
312 "This is not compatible with Vulkan and need to be adjusted.\n";
319 error += this->
name_ +
" contains two specialization constants with the name: " +
332 Set<int> images, samplers, ubos, ssbos;
334 auto register_resource = [&](
const Resource &res) ->
bool {
335 switch (res.bind_type) {
337 return images.
add(res.slot);
339 return samplers.
add(res.slot);
341 return ubos.
add(res.slot);
343 return ssbos.
add(res.slot);
350 auto print_resource_name = [&](
const Resource &res) {
365 std::cout <<
"Unknown Type";
370 for (
const Resource &_res : resources) {
371 if (&res != &_res && res.
bind_type == _res.bind_type && res.
slot == _res.slot) {
372 std::cout <<
name_ <<
": Validation failed : Overlapping ";
373 print_resource_name(res);
374 std::cout <<
" and ";
375 print_resource_name(_res);
376 std::cout <<
" at (" << res.
slot <<
") while merging " << other_info.
name_ << std::endl;
382 if (register_resource(res) ==
false) {
388 if (register_resource(res) ==
false) {
394 if (register_resource(res) ==
false) {
405 if (attr.index >= 16 || attr.index < 0) {
406 std::cout <<
name_ <<
": \"" << attr.name
407 <<
"\" : Type::MAT3 unsupported as vertex attribute." << std::endl;
410 if (attr.index >= 16 || attr.index < 0) {
411 std::cout <<
name_ <<
": Invalid index for attribute \"" << attr.name <<
"\"" << std::endl;
416 for (
int i = 0; i < 4; i++) {
417 attr_new |= 1 << (attr.index + i);
421 attr_new |= 1 << attr.index;
424 if ((attr_bits & attr_new) != 0) {
425 std::cout <<
name_ <<
": Attribute \"" << attr.name
426 <<
"\" overlap one or more index from another attribute."
427 " Note that mat4 takes up 4 indices.";
429 std::cout <<
" While merging " << other_info->
name_ << std::endl;
431 std::cout << std::endl;
434 attr_bits |= attr_new;
449# pragma optimize("", off)
457#define GPU_SHADER_INTERFACE_INFO(_interface, _inst_name) \
458 StageInterfaceInfo *ptr_##_interface = new StageInterfaceInfo(#_interface, _inst_name); \
459 StageInterfaceInfo &_interface = *ptr_##_interface; \
460 g_interfaces->add_new(#_interface, ptr_##_interface); \
463#define GPU_SHADER_CREATE_INFO(_info) \
464 ShaderCreateInfo *ptr_##_info = new ShaderCreateInfo(#_info); \
465 ShaderCreateInfo &_info = *ptr_##_info; \
466 g_create_infos->add_new(#_info, ptr_##_info); \
470#include "compositor_shader_create_info_list.hh"
471#include "gpu_shader_create_info_list.hh"
477# include "gpu_shader_baked.hh"
494 draw_resource_with_custom_id_new = draw_resource_with_custom_id_fallback;
499 eevee_deferred_tile_classify.storage_buf(
500 12, Qualifier::READ_WRITE,
"uint",
"dummy_workaround_buf[]");
503#ifdef WITH_METAL_BACKEND
507 gpu_shader_3D_polyline_uniform_color = gpu_shader_3D_polyline_uniform_color_no_geom;
508 gpu_shader_3D_polyline_flat_color = gpu_shader_3D_polyline_flat_color_no_geom;
509 gpu_shader_3D_polyline_smooth_color = gpu_shader_3D_polyline_smooth_color_no_geom;
510 gpu_shader_3D_polyline_uniform_color_clipped =
511 gpu_shader_3D_polyline_uniform_color_clipped_no_geom;
514 overlay_edit_mesh_edge = overlay_edit_mesh_edge_no_geom;
515 overlay_edit_mesh_edge_flat = overlay_edit_mesh_edge_flat_no_geom;
516 overlay_edit_mesh_edge_clipped = overlay_edit_mesh_edge_clipped_no_geom;
517 overlay_edit_mesh_edge_flat_clipped = overlay_edit_mesh_edge_flat_clipped_no_geom;
519 overlay_edit_curve_handle = overlay_edit_curve_handle_no_geom;
520 overlay_edit_curve_handle_clipped = overlay_edit_curve_handle_clipped_no_geom;
522 overlay_edit_curves_handle = overlay_edit_curves_handle_no_geom;
523 overlay_edit_curves_handle_clipped = overlay_edit_curves_handle_clipped_no_geom;
526 overlay_armature_shape_outline = overlay_armature_shape_outline_no_geom;
527 overlay_armature_shape_outline_clipped = overlay_armature_shape_outline_clipped_no_geom;
528 overlay_armature_shape_wire = overlay_armature_shape_wire_no_geom;
531 overlay_motion_path_line = overlay_motion_path_line_no_geom;
532 overlay_motion_path_line_clipped = overlay_motion_path_line_clipped_no_geom;
535 basic_depth_mesh_conservative = basic_depth_mesh_conservative_no_geom;
536 basic_depth_mesh_conservative_clipped = basic_depth_mesh_conservative_no_geom_clipped;
537 basic_depth_pointcloud_conservative = basic_depth_pointcloud_conservative_no_geom;
538 basic_depth_pointcloud_conservative_clipped =
539 basic_depth_pointcloud_conservative_no_geom_clipped;
542 overlay_outline_prepass_wire = overlay_outline_prepass_wire_no_geom;
545 overlay_edit_uv_edges = overlay_edit_uv_edges_no_geom;
548 gpu_shader_gpencil_stroke = gpu_shader_gpencil_stroke_no_geom;
557 if (is_tile_based_arch) {
570#if GPU_SHADER_PRINTF_ENABLE
571 if ((info->builtins_ & BuiltinBits::USE_PRINTF) == BuiltinBits::USE_PRINTF ||
574 info->additional_info(
"gpu_print");
580 if ((info->builtins_ & BuiltinBits::USE_DEBUG_DRAW) == BuiltinBits::USE_DEBUG_DRAW) {
581 info->additional_info(
"draw_debug_draw");
583 if ((info->builtins_ & BuiltinBits::USE_DEBUG_PRINT) == BuiltinBits::USE_DEBUG_PRINT) {
584 info->additional_info(
"draw_debug_print");
594 info->finalize(
true);
601# pragma optimize("", on)
623 int skipped_filter = 0;
628 if (info->do_static_compilation_) {
629 if (name_starts_with_filter &&
644 reinterpret_cast<const GPUShaderCreateInfo *
>(info));
645 if (shader ==
nullptr) {
646 std::cerr <<
"Compilation " << info->name_.c_str() <<
" Failed\n";
662 switch (res.bind_type) {
663 case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER:
664 input = interface->ubo_get(res.slot);
665 name = res.uniformbuf.
name;
667 case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER:
668 input = interface->ssbo_get(res.slot);
669 name = res.storagebuf.name;
671 case ShaderCreateInfo::Resource::BindType::SAMPLER:
672 input = interface->texture_get(res.slot);
673 name = res.sampler.name;
675 case ShaderCreateInfo::Resource::BindType::IMAGE:
676 input = interface->texture_get(res.slot);
677 name = res.image.name;
681 if (input ==
nullptr) {
682 std::cerr <<
"Error: " << info->name_;
683 std::cerr <<
": Resource « " << name <<
" » not found in the shader interface\n";
685 else if (input->location == -1) {
686 std::cerr <<
"Warning: " << info->name_;
687 std::cerr <<
": Resource « " << name <<
" » is optimized out\n";
695 printf(
"Shader Test compilation result: %d / %d passed", success, total);
696 if (skipped_filter > 0) {
697 printf(
" (skipped %d when filtering)", skipped_filter);
700 printf(
" (skipped %d for compatibility reasons)", skipped);
703 return success == total;
709 printf(
"Error: Cannot find shader create info named \"%s\"\n", info_name);
713 return reinterpret_cast<const GPUShaderCreateInfo *
>(info);
717 GPUShaderCreateInfo &r_info)
720 std::string msg = std::string(
"Error: Cannot find shader create info named \"") + info_name +
#define BLI_assert_msg(a, msg)
bool GPU_transform_feedback_support()
bool GPU_crappy_amd_driver()
bool GPU_geometry_shader_support()
bool GPU_stencil_clasify_buffer_workaround()
bool GPU_shader_draw_parameters_support()
eGPUBackendType GPU_backend_get_type()
GPUShader * GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
void GPU_shader_free(GPUShader *shader)
struct GPUShader GPUShader
const Value & lookup(const Key &key) const
ValueIterator values() const
void add_new(const Key &key, const Value &value)
ItemIterator items() const
bool contains(const Key &key) const
constexpr bool is_empty() const
gbuf_header_tx eevee_shadow_data
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()
void gpu_shader_create_info_get_unfinalized_copy(const char *info_name, GPUShaderCreateInfo &r_info)
static void error(const char *str)
Map< StringRef, ShaderCreateInfo * > CreateInfoDictionnary
static CreateInfoValueDictionnary * g_create_infos_unfinalized
Map< StringRef, StageInterfaceInfo * > InterfaceDictionnary
BuiltinBits gpu_shader_dependency_get_builtins(const StringRefNull 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
Map< StringRef, ShaderCreateInfo > CreateInfoValueDictionnary
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_
Vector< Resource > geometry_resources_
Vector< std::array< StringRefNull, 2 > > defines_
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_
eGPUShaderTFBType tf_type_
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