Blender V4.3
blender::gpu::shader::ShaderCreateInfo Struct Reference

Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correctly provided, this is all that is needed to create and compile a GPUShader. More...

#include <gpu_shader_create_info.hh>

Inherited by GPUCodegenCreateInfo.

Classes

struct  ComputeStageLayout
 
struct  FragOut
 
struct  GeometryStageLayout
 
struct  Image
 
struct  PushConst
 
struct  Resource
 
struct  Sampler
 
struct  StorageBuf
 
struct  UniformBuf
 
struct  VertIn
 

Public Types

using SubpassIn = FragOut
 
using Self = ShaderCreateInfo
 

Public Member Functions

Vector< Resource > & resources_get_ (Frequency freq)
 
Vector< Resourceresources_get_all_ () const
 
 ShaderCreateInfo (const char *name)
 
 ~ShaderCreateInfo ()
 
Shaders in/outs (fixed function pipeline config)
Selfvertex_in (int slot, Type type, StringRefNull name)
 
Selfvertex_out (StageInterfaceInfo &interface)
 
Selfgeometry_layout (PrimitiveIn prim_in, PrimitiveOut prim_out, int max_vertices, int invocations=-1)
 
Selflocal_group_size (int local_size_x=-1, int local_size_y=-1, int local_size_z=-1)
 
Selfearly_fragment_test (bool enable)
 
Selfgeometry_out (StageInterfaceInfo &interface)
 
Selffragment_out (int slot, Type type, StringRefNull name, DualBlend blend=DualBlend::NONE, int raster_order_group=-1)
 
Selfsubpass_in (int slot, Type type, StringRefNull name, int raster_order_group=-1)
 
Shader specialization constants
Selfspecialization_constant (Type type, StringRefNull name, double default_value)
 
Resources bindings points
Selfuniform_buf (int slot, StringRefNull type_name, StringRefNull name, Frequency freq=Frequency::PASS)
 
Selfstorage_buf (int slot, Qualifier qualifiers, StringRefNull type_name, StringRefNull name, Frequency freq=Frequency::PASS)
 
Selfimage (int slot, eGPUTextureFormat format, Qualifier qualifiers, ImageType type, StringRefNull name, Frequency freq=Frequency::PASS)
 
Selfsampler (int slot, ImageType type, StringRefNull name, Frequency freq=Frequency::PASS, GPUSamplerState sampler=GPUSamplerState::internal_sampler())
 
Shader Source
Selfvertex_source (StringRefNull filename)
 
Selfgeometry_source (StringRefNull filename)
 
Selffragment_source (StringRefNull filename)
 
Selfcompute_source (StringRefNull filename)
 
Push constants

Data managed by GPUShader. Can be set through uniform functions. Must be less than 128bytes.

Selfpush_constant (Type type, StringRefNull name, int array_size=0)
 
Defines
Selfdefine (StringRefNull name, StringRefNull value="")
 
Selfdo_static_compilation (bool value)
 
Selfbuiltins (BuiltinBits builtin)
 
Selfdepth_write (DepthWrite value)
 
Selfauto_resource_location (bool value)
 
Selflegacy_resource_location (bool value)
 
Selfmetal_backend_only (bool flag)
 
Additional Create Info

Used to share parts of the infos that are common to many shaders.

Selfadditional_info (StringRefNull info_name)
 
template<typename... Args>
Selfadditional_info (StringRefNull info_name, Args... args)
 
Typedef Sources

Some resource declarations might need some special structure defined. Adding a file using typedef_source will include it before the resource and interface definitions.

Selftypedef_source (StringRefNull filename)
 
Transform feedback properties

Transform feedback enablement and output binding assignment.

Selftransform_feedback_mode (eGPUShaderTFBType tf_mode)
 
Selftransform_feedback_output_name (const char *name)
 
API-Specific Parameters

Optional parameters exposed by specific back-ends to enable additional features and performance tuning. NOTE: These functions can be exposed as a pass-through on unsupported configurations.

Selfmtl_max_total_threads_per_threadgroup (ushort max_total_threads_per_threadgroup)
 
Recursive evaluation.

Flatten all dependency so that this descriptor contains all the data from the additional descriptors. This avoids tedious traversal in shader source creation.

void finalize (const bool recursive=false)
 
std::string check_error () const
 
bool is_vulkan_compatible () const
 
void validate_merge (const ShaderCreateInfo &other_info)
 
void validate_vertex_attributes (const ShaderCreateInfo *other_info=nullptr)
 

Public Attributes

StringRefNull name_
 
bool do_static_compilation_ = false
 
bool finalized_ = false
 
bool auto_resource_location_ = false
 
bool early_fragment_test_ = false
 
bool legacy_resource_location_ = false
 
DepthWrite depth_write_ = DepthWrite::UNCHANGED
 
bool metal_backend_only_ = false
 
size_t interface_names_size_ = 0
 
BuiltinBits builtins_ = BuiltinBits::NONE
 
std::string vertex_source_generated = ""
 
std::string fragment_source_generated = ""
 
std::string compute_source_generated = ""
 
std::string geometry_source_generated = ""
 
std::string typedef_source_generated = ""
 
Vector< const char *, 0 > dependencies_generated
 
Vector< VertInvertex_inputs_
 
GeometryStageLayout geometry_layout_
 
ComputeStageLayout compute_layout_
 
Vector< FragOutfragment_outputs_
 
Vector< SubpassInsubpass_inputs_
 
Vector< SpecializationConstantspecialization_constants_
 
Vector< Resourcepass_resources_
 
Vector< Resourcebatch_resources_
 
Vector< Resourcegeometry_resources_
 
Vector< StageInterfaceInfo * > vertex_out_interfaces_
 
Vector< StageInterfaceInfo * > geometry_out_interfaces_
 
Vector< PushConstpush_constants_
 
Vector< StringRefNulltypedef_sources_
 
StringRefNull vertex_source_
 
StringRefNull geometry_source_
 
StringRefNull fragment_source_
 
StringRefNull compute_source_
 
Vector< std::array< StringRefNull, 2 > > defines_
 
Vector< StringRefNulladditional_infos_
 
eGPUShaderTFBType tf_type_ = GPU_SHADER_TFB_NONE
 
Vector< const char * > tf_names_
 

Operators.

bool operator== (const ShaderCreateInfo &b) const
 
bool has_resource_type (Resource::BindType bind_type) const
 
bool has_resource_image () const
 
std::ostream & operator<< (std::ostream &stream, const ShaderCreateInfo &info)
 

Detailed Description

Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correctly provided, this is all that is needed to create and compile a GPUShader.

IMPORTANT: All strings are references only. Make sure all the strings used by a ShaderCreateInfo are not freed until it is consumed or deleted.

Definition at line 362 of file gpu_shader_create_info.hh.

Member Typedef Documentation

◆ Self

◆ SubpassIn

Constructor & Destructor Documentation

◆ ShaderCreateInfo()

blender::gpu::shader::ShaderCreateInfo::ShaderCreateInfo ( const char * name)
inline

Definition at line 626 of file gpu_shader_create_info.hh.

◆ ~ShaderCreateInfo()

blender::gpu::shader::ShaderCreateInfo::~ShaderCreateInfo ( )
inline

Definition at line 627 of file gpu_shader_create_info.hh.

Member Function Documentation

◆ additional_info() [1/2]

◆ additional_info() [2/2]

template<typename... Args>
Self & blender::gpu::shader::ShaderCreateInfo::additional_info ( StringRefNull info_name,
Args... args )
inline

Definition at line 964 of file gpu_shader_create_info.hh.

References additional_info().

◆ auto_resource_location()

Self & blender::gpu::shader::ShaderCreateInfo::auto_resource_location ( bool value)
inline

Definition at line 932 of file gpu_shader_create_info.hh.

References auto_resource_location_.

◆ builtins()

Self & blender::gpu::shader::ShaderCreateInfo::builtins ( BuiltinBits builtin)
inline

◆ check_error()

◆ compute_source()

Self & blender::gpu::shader::ShaderCreateInfo::compute_source ( StringRefNull filename)
inline

Definition at line 869 of file gpu_shader_create_info.hh.

References compute_source_.

Referenced by pygpu_shader_info_compute_source().

◆ define()

◆ depth_write()

Self & blender::gpu::shader::ShaderCreateInfo::depth_write ( DepthWrite value)
inline

Definition at line 926 of file gpu_shader_create_info.hh.

References depth_write_.

◆ do_static_compilation()

Self & blender::gpu::shader::ShaderCreateInfo::do_static_compilation ( bool value)
inline

Definition at line 913 of file gpu_shader_create_info.hh.

References do_static_compilation_.

◆ early_fragment_test()

Self & blender::gpu::shader::ShaderCreateInfo::early_fragment_test ( bool enable)
inline

Force fragment tests before fragment shader invocation. IMPORTANT: This is incompatible with using the gl_FragDepth output.

Definition at line 672 of file gpu_shader_create_info.hh.

References early_fragment_test_.

◆ finalize()

◆ fragment_out()

Self & blender::gpu::shader::ShaderCreateInfo::fragment_out ( int slot,
Type type,
StringRefNull name,
DualBlend blend = DualBlend::NONE,
int raster_order_group = -1 )
inline

◆ fragment_source()

◆ geometry_layout()

◆ geometry_out()

Self & blender::gpu::shader::ShaderCreateInfo::geometry_out ( StageInterfaceInfo & interface)
inline

Only needed if geometry shader is enabled. IMPORTANT: Input and output instance name will have respectively "_in" and "_out" suffix appended in the geometry shader IF AND ONLY IF the vertex_out interface instance name matches the geometry_out interface instance name.

Definition at line 684 of file gpu_shader_create_info.hh.

References geometry_out_interfaces_.

◆ geometry_source()

Self & blender::gpu::shader::ShaderCreateInfo::geometry_source ( StringRefNull filename)
inline

Definition at line 857 of file gpu_shader_create_info.hh.

References geometry_source_.

◆ has_resource_image()

bool blender::gpu::shader::ShaderCreateInfo::has_resource_image ( ) const
inline

◆ has_resource_type()

bool blender::gpu::shader::ShaderCreateInfo::has_resource_type ( Resource::BindType bind_type) const
inline

Definition at line 1126 of file gpu_shader_create_info.hh.

References batch_resources_, geometry_resources_, and pass_resources_.

Referenced by has_resource_image().

◆ image()

◆ is_vulkan_compatible()

bool blender::gpu::shader::ShaderCreateInfo::is_vulkan_compatible ( ) const

◆ legacy_resource_location()

Self & blender::gpu::shader::ShaderCreateInfo::legacy_resource_location ( bool value)
inline

Definition at line 938 of file gpu_shader_create_info.hh.

References legacy_resource_location_.

◆ local_group_size()

◆ metal_backend_only()

Self & blender::gpu::shader::ShaderCreateInfo::metal_backend_only ( bool flag)
inline

Definition at line 944 of file gpu_shader_create_info.hh.

References flag, and metal_backend_only_.

◆ mtl_max_total_threads_per_threadgroup()

Self & blender::gpu::shader::ShaderCreateInfo::mtl_max_total_threads_per_threadgroup ( ushort max_total_threads_per_threadgroup)
inline

Definition at line 1021 of file gpu_shader_create_info.hh.

References UNUSED_VARS.

◆ operator==()

◆ push_constant()

Self & blender::gpu::shader::ShaderCreateInfo::push_constant ( Type type,
StringRefNull name,
int array_size = 0 )
inline

◆ resources_get_()

◆ resources_get_all_()

◆ sampler()

◆ specialization_constant()

◆ storage_buf()

◆ subpass_in()

Self & blender::gpu::shader::ShaderCreateInfo::subpass_in ( int slot,
Type type,
StringRefNull name,
int raster_order_group = -1 )
inline

Allows to fetch frame-buffer values from previous render sub-pass.

On Apple Silicon, the additional raster_order_group is there to set the sub-pass dependencies. Any sub-pass input need to have the same raster_order_group defined in the shader writing them.

IMPORTANT: Currently emulated on all backend except Metal. This is only for debugging purpose as it is too slow to be viable.

TODO(fclem): Vulkan can implement that using subpassInput. However sub-pass boundaries might be difficult to inject implicitly and will require more high level changes. TODO(fclem): OpenGL can emulate that using GL_EXT_shader_framebuffer_fetch.

Definition at line 714 of file gpu_shader_create_info.hh.

References blender::gpu::shader::NONE, and subpass_inputs_.

Referenced by blender::gpu::tests::test_framebuffer_subpass_input().

◆ transform_feedback_mode()

Self & blender::gpu::shader::ShaderCreateInfo::transform_feedback_mode ( eGPUShaderTFBType tf_mode)
inline

Definition at line 995 of file gpu_shader_create_info.hh.

References BLI_assert, GPU_SHADER_TFB_NONE, and tf_type_.

◆ transform_feedback_output_name()

Self & blender::gpu::shader::ShaderCreateInfo::transform_feedback_output_name ( const char * name)
inline

◆ typedef_source()

Self & blender::gpu::shader::ShaderCreateInfo::typedef_source ( StringRefNull filename)
inline

◆ uniform_buf()

◆ validate_merge()

◆ validate_vertex_attributes()

void blender::gpu::shader::ShaderCreateInfo::validate_vertex_attributes ( const ShaderCreateInfo * other_info = nullptr)

Definition at line 401 of file gpu_shader_create_info.cc.

References BLI_assert, blender::gpu::shader::MAT4, name_, and vertex_inputs_.

Referenced by finalize().

◆ vertex_in()

Self & blender::gpu::shader::ShaderCreateInfo::vertex_in ( int slot,
Type type,
StringRefNull name )
inline

◆ vertex_out()

Self & blender::gpu::shader::ShaderCreateInfo::vertex_out ( StageInterfaceInfo & interface)
inline

◆ vertex_source()

Self & blender::gpu::shader::ShaderCreateInfo::vertex_source ( StringRefNull filename)
inline

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & stream,
const ShaderCreateInfo & info )
friend

Debug print

Definition at line 1090 of file gpu_shader_create_info.hh.

Member Data Documentation

◆ additional_infos_

Vector<StringRefNull> blender::gpu::shader::ShaderCreateInfo::additional_infos_

Name of other infos to recursively merge with this one. No data slot must overlap otherwise we throw an error.

Definition at line 614 of file gpu_shader_create_info.hh.

Referenced by additional_info(), finalize(), blender::eevee::ShaderModule::material_create_info_amend(), operator==(), blender::draw::overlay::shader_patch_common(), and blender::draw::overlay::ShaderModule::ShaderModule().

◆ auto_resource_location_

bool blender::gpu::shader::ShaderCreateInfo::auto_resource_location_ = false

If true, all resources will have an automatic location assigned.

Definition at line 370 of file gpu_shader_create_info.hh.

Referenced by auto_resource_location(), finalize(), blender::gpu::MSLGeneratorInterface::prepare_from_createinfo(), blender::gpu::GLShader::resources_declare(), and validate_merge().

◆ batch_resources_

◆ builtins_

◆ compute_layout_

◆ compute_source_

◆ compute_source_generated

std::string blender::gpu::shader::ShaderCreateInfo::compute_source_generated = ""

◆ defines_

Vector<std::array<StringRefNull, 2> > blender::gpu::shader::ShaderCreateInfo::defines_

◆ dependencies_generated

Vector<const char *, 0> blender::gpu::shader::ShaderCreateInfo::dependencies_generated

Manually set generated dependencies.

Definition at line 394 of file gpu_shader_create_info.hh.

Referenced by blender::gpu::ShaderCompiler::compile(), and GPUCodegen::generate_library().

◆ depth_write_

DepthWrite blender::gpu::shader::ShaderCreateInfo::depth_write_ = DepthWrite::UNCHANGED

Allow optimization when fragment shader writes to gl_FragDepth.

Definition at line 376 of file gpu_shader_create_info.hh.

Referenced by depth_write(), finalize(), blender::gpu::GLShader::fragment_interface_declare(), and blender::gpu::VKShader::fragment_interface_declare().

◆ do_static_compilation_

bool blender::gpu::shader::ShaderCreateInfo::do_static_compilation_ = false

True if the shader is static and can be pre-compiled at compile time.

Definition at line 366 of file gpu_shader_create_info.hh.

Referenced by do_static_compilation(), GPU_shader_create_from_info_name(), and blender::gpu::VKShader::init().

◆ early_fragment_test_

bool blender::gpu::shader::ShaderCreateInfo::early_fragment_test_ = false

If true, force depth and stencil tests to always happen before fragment shader invocation.

Definition at line 372 of file gpu_shader_create_info.hh.

Referenced by early_fragment_test(), finalize(), blender::gpu::GLShader::fragment_interface_declare(), and blender::gpu::VKShader::fragment_interface_declare().

◆ finalized_

bool blender::gpu::shader::ShaderCreateInfo::finalized_ = false

If true, all additionally linked create info will be merged into this one.

Definition at line 368 of file gpu_shader_create_info.hh.

Referenced by finalize(), and gpu_shader_create_info_get_unfinalized_copy().

◆ fragment_outputs_

◆ fragment_source_

◆ fragment_source_generated

std::string blender::gpu::shader::ShaderCreateInfo::fragment_source_generated = ""

◆ geometry_layout_

◆ geometry_out_interfaces_

◆ geometry_resources_

◆ geometry_source_

◆ geometry_source_generated

std::string blender::gpu::shader::ShaderCreateInfo::geometry_source_generated = ""

Definition at line 391 of file gpu_shader_create_info.hh.

◆ interface_names_size_

size_t blender::gpu::shader::ShaderCreateInfo::interface_names_size_ = 0

Maximum length of all the resource names including each null terminator. Only for names used by #gpu::ShaderInterface.

Definition at line 384 of file gpu_shader_create_info.hh.

Referenced by finalize(), blender::gpu::GLShaderInterface::GLShaderInterface(), image(), blender::gpu::VKShaderInterface::init(), push_constant(), sampler(), specialization_constant(), storage_buf(), uniform_buf(), and vertex_in().

◆ legacy_resource_location_

bool blender::gpu::shader::ShaderCreateInfo::legacy_resource_location_ = false

If true, force the use of the GL shader introspection for resource location.

Definition at line 374 of file gpu_shader_create_info.hh.

Referenced by blender::gpu::ShaderCompiler::compile(), legacy_resource_location(), and blender::gpu::GLShader::post_finalize().

◆ metal_backend_only_

bool blender::gpu::shader::ShaderCreateInfo::metal_backend_only_ = false

GPU Backend compatibility flag. Temporary requirement until Metal enablement is fully complete.

Definition at line 379 of file gpu_shader_create_info.hh.

Referenced by metal_backend_only().

◆ name_

StringRefNull blender::gpu::shader::ShaderCreateInfo::name_

◆ pass_resources_

Vector<Resource> blender::gpu::shader::ShaderCreateInfo::pass_resources_

Resources are grouped by frequency of change. Pass resources are meant to be valid for the whole pass. Batch resources can be changed in a more granular manner (per object/material). Geometry resources can be changed in a very granular manner (per draw-call). Misuse will only produce suboptimal performance.

Definition at line 559 of file gpu_shader_create_info.hh.

Referenced by blender::realtime_compositor::CachedShader::CachedShader(), finalize(), has_resource_type(), blender::gpu::VKShaderInterface::init(), operator==(), blender::gpu::GLShader::resources_declare(), blender::gpu::MTLShader::resources_declare(), blender::gpu::VKShader::resources_declare(), resources_get_(), resources_get_all_(), and validate_merge().

◆ push_constants_

◆ specialization_constants_

◆ subpass_inputs_

◆ tf_names_

Vector<const char *> blender::gpu::shader::ShaderCreateInfo::tf_names_

◆ tf_type_

◆ typedef_source_generated

std::string blender::gpu::shader::ShaderCreateInfo::typedef_source_generated = ""

◆ typedef_sources_

Vector<StringRefNull> blender::gpu::shader::ShaderCreateInfo::typedef_sources_

◆ vertex_inputs_

◆ vertex_out_interfaces_

◆ vertex_source_

StringRefNull blender::gpu::shader::ShaderCreateInfo::vertex_source_

◆ vertex_source_generated

std::string blender::gpu::shader::ShaderCreateInfo::vertex_source_generated = ""

The documentation for this struct was generated from the following files: