VulkanShaderProgram class
Shader program of the Vulkan backend (aliased as RHI::ShaderProgram).
Carries the offline ShaderCompiler reflection (set with SetReflection() like the OpenGL backend) from which it imports uniforms, uniform blocks and attributes so the pipeline's uniform machinery runs. It also builds the VkShaderModule pair from the reflection's embedded VkVsSpirv/VkFsSpirv, a VkDescriptorSetLayout from the same reflection (set 0: optional _Globals UBO, then the std140 blocks, then the combined-image-samplers, in reflection order) and a VkPipeline per vertex format. Use() records the program as current on the device.
Public types
- struct DescriptorBinding
- One entry of the descriptor set (set 0), matching the offline emitter's binding scheme.
- struct LooseUniform
- A loose (default-block) uniform gathered into the "_Globals" UBO, with its std140 placement.
- struct VertexAttrib
- A vertex attribute for building the pipeline's vertex input state.
- enum class Introspection { Enabled, NoUniformsInBlocks, Disabled }
- enum class Status { NotLinked, CompilationFailed, LinkingFailed, Linked, LinkedWithDeferredQueries, LinkedWithIntrospection }
- enum class QueryPhase { Immediate, Deferred }
Public static variables
-
static std::
int32_t DefaultBatchSize constexpr - Default batch size, indicating the shader is not batched.
Constructors, destructors, conversion operators
- VulkanShaderProgram()
- VulkanShaderProgram(QueryPhase queryPhase) explicit
- VulkanShaderProgram(StringView vertexFile, StringView fragmentFile, Introspection introspection, QueryPhase queryPhase)
- VulkanShaderProgram(StringView vertexFile, StringView fragmentFile, Introspection introspection)
- VulkanShaderProgram(StringView vertexFile, StringView fragmentFile)
- ~VulkanShaderProgram()
- VulkanShaderProgram(const VulkanShaderProgram&) deleted
Public functions
- auto operator=(const VulkanShaderProgram&) -> VulkanShaderProgram& deleted
-
auto GetUniqueId() const -> std::
uint32_t - Returns a backend-neutral identifier uniquely identifying the program (feeds material sort keys; also keys the Vulkan pipeline/descriptor caches).
- auto GetStatus() const -> Status
- auto GetIntrospection() const -> Introspection
- auto GetQueryPhase() const -> QueryPhase
-
auto GetBatchSize() const -> std::
uint32_t -
void SetBatchSize(std::
uint32_t value) - auto IsLinked() const -> bool
-
auto RetrieveInfoLogLength() const -> std::
uint32_t -
void RetrieveInfoLog(std::
string& infoLog) const -
auto GetUniformsSize() const -> std::
uint32_t -
auto GetUniformBlocksSize() const -> std::
uint32_t - auto AttachShaderFromFile(ShaderStage stage, StringView filename) -> bool
- auto AttachShaderFromString(ShaderStage stage, StringView string) -> bool
- auto AttachShaderFromStrings(ShaderStage stage, ArrayView<const StringView> strings) -> bool
- auto AttachShaderFromStringsAndFile(ShaderStage stage, ArrayView<const StringView> strings, StringView filename) -> bool
-
void SetReflection(const ShaderCompiler::
ProgramVariant* reflection) - Sets the offline reflection consumed by Link() to import uniforms/blocks/attributes.
- auto Link(Introspection introspection) -> bool
- void Use()
- auto Validate() -> bool
- auto FinalizeAfterLinking(Introspection introspection) -> bool
-
auto GetAttributeCount() const -> std::
uint32_t - auto HasAttribute(const char* name) const -> bool
-
auto GetAttribute(const char* name) -> VulkanVertexFormat::
Attribute* - void DefineVertexFormat(const VulkanBufferObject* vbo)
- void DefineVertexFormat(const VulkanBufferObject* vbo, const VulkanBufferObject* ibo)
-
void DefineVertexFormat(const VulkanBufferObject* vbo,
const VulkanBufferObject* ibo,
std::
uint32_t vboOffset) - void Reset()
- void SetObjectLabel(StringView label)
- auto GetLogOnErrors() const -> bool
- void SetLogOnErrors(bool shouldLogOnErrors)
-
void SetResolvedUniform(const char* name,
const std::
uint8_t* data) - Publishes a committed loose-uniform value pointer for the device to gather into
_Globals. -
auto ResolveUniform(const char* name) const -> const std::
uint8_t* - Returns the last published value pointer of the named loose uniform, or
nullptr. - auto HasVertexAttributes() const -> bool
- Returns
trueif the vertex shader reads vertex attributes (needs vertex input state + a vertex buffer). - auto GetBoundVbo() const -> const VulkanBufferObject*
- Returns the vertex buffer bound by DefineVertexFormat(), or
nullptr. - auto GetBoundIbo() const -> const VulkanBufferObject*
- Returns the index buffer bound by DefineVertexFormat(), or
nullptr. - auto HasPipelineState() const -> bool
- Returns
trueif the SPIR-V modules and layouts were built successfully (draws are skipped otherwise). -
auto GetVsModule() const -> std::
uint64_t - The vertex-stage
VkShaderModule(asstd::uint64_t). -
auto GetFsModule() const -> std::
uint64_t - The fragment-stage
VkShaderModule. -
auto GetPipelineLayout() const -> std::
uint64_t - The
VkPipelineLayout(one descriptor set, set 0). -
auto GetDescriptorSetLayout() const -> std::
uint64_t - The
VkDescriptorSetLayoutfor set 0. -
auto GetDescriptorBindings() const -> const std::
vector<DescriptorBinding>& - The descriptor bindings (in reflection order) the device writes each draw.
-
auto GetLooseUniforms() const -> const std::
vector<LooseUniform>& - The loose uniforms gathered into "_Globals" (empty if the program has none).
-
auto GetGlobalsSize() const -> std::
uint32_t - std140 byte size of the "_Globals" UBO (0 if the program has no loose uniforms)
- auto HasGlobals() const -> bool
- The binding number of the "_Globals" UBO (always 0 when present).
-
auto GetVertexInput(VertexAttrib* outAttribs,
std::
uint32_t maxAttribs, std:: uint32_t& outStride) const -> std:: uint32_t - Fills the current vertex input layout (attributes + per-vertex stride) from the bound vertex format.
Function documentation
std:: uint32_t nCine:: RHI:: Vulkan:: VulkanShaderProgram:: GetVertexInput(VertexAttrib* outAttribs,
std:: uint32_t maxAttribs,
std:: uint32_t& outStride) const
Fills the current vertex input layout (attributes + per-vertex stride) from the bound vertex format.
Writes at most maxAttribs entries into outAttribs (a caller-provided array, so the per-draw pipeline-key computation never touches the heap) and returns the number written.