Class Shader

Inheritance Relationships

Base Type

Derived Type

Class Documentation

class Shader : public portal::Resource

Manages shader variants with different permutations.

Compiles and caches shader variants for different sets of defines, allowing multiple materials to share shader code with different configurations.

Subclassed by portal::renderer::vulkan::VulkanShader

Public Functions

explicit Shader(const StringId &id)
void load_source(Buffer &&new_source, const std::filesystem::path &shader_path)

Loads shader source code.

Parameters:
  • new_sourceShader source buffer

  • shader_path – Source file path

uint64_t compile_with_permutations(const std::vector<ShaderDefine> &permutations)

Compiles shader with given defines.

Parameters:

permutations – List of shader defines

Returns:

Hash to retrieve compiled variant

virtual WeakReference<ShaderVariant> get_shader(uint64_t shader_hash) = 0

Gets compiled shader variant.

Parameters:

shader_hash – Permutation hash

Returns:

Shader variant reference

Public Static Functions

static inline portal::ResourceType static_type()

Protected Functions

uint64_t calculate_permutations_hash(const std::vector<ShaderDefine> &permutations) const

Calculates hash from permutations.

Parameters:

permutationsShader defines

Returns:

Unique hash for permutation set

Protected Attributes

std::filesystem::path source_path
Buffer source
SpinLock shader_cache_lock
std::unordered_map<uint64_t, CompiledShader> shaders