nCine::RHI::GX2::Gx2ShaderProgram class

Shader program of the GX2 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. Its stage binaries come from the identity SetProgramIdentity() plumbs in, looked up in Gx2GeneratedShaders.h, the table of CafeGLSL output that ShaderCompiler --emit-gx2 writes - there is no shader compiler on the console that the game can rely on.

Both stages are compiled in uniform-block mode. CafeGLSL gathers each stage's loose uniforms into a block of its own (__cafe_loose_uniforms); the device fills that one per draw from the values the uniform caches publish (SetResolvedUniform()). The explicit std140 blocks are handed over as the ranges the pipeline bound to the engine's binding points (Gx2Device::GetUniformRange()), matched by name. A program without an entry in the table links from its reflection alone and HasBinaries() is false; the device skips draws with it.

Public types

struct LooseUniform
One loose uniform of a stage, copied into the stage's loose-uniform block per draw.
struct BlockBinding
An explicit uniform block of a stage and the engine binding point that feeds it.
struct StageBindings
What the device uploads for one stage before a draw.
struct SamplerBinding
A pixel-stage sampler: the unit the shader samples and the unit the pipeline binds to.
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

Gx2ShaderProgram()
Gx2ShaderProgram(QueryPhase queryPhase) explicit
Gx2ShaderProgram(StringView vertexFile, StringView fragmentFile, Introspection introspection, QueryPhase queryPhase)
Gx2ShaderProgram(StringView vertexFile, StringView fragmentFile, Introspection introspection)
Gx2ShaderProgram(StringView vertexFile, StringView fragmentFile)
~Gx2ShaderProgram()
Gx2ShaderProgram(const Gx2ShaderProgram&) deleted

Public functions

auto operator=(const Gx2ShaderProgram&) -> Gx2ShaderProgram& deleted
auto GetUniqueId() const -> std::uint32_t
Returns a backend-neutral identifier uniquely identifying the program (feeds material sort keys).
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.
void SetProgramIdentity(const char* programName, const char* variantName)
Records the true (program, variant) identity of the loaded shader.
auto GetProgramName() const -> const char*
Returns the generated program's name, or nullptr for one that carries no identity.
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 IsIntegerAttribute(const char* name) const -> bool
Returns true if the reflection declares name with an integer type (a batch element index).
auto GetAttribute(const char* name) -> Gx2VertexFormat::Attribute*
void DefineVertexFormat(const Gx2BufferObject* vbo)
void DefineVertexFormat(const Gx2BufferObject* vbo, const Gx2BufferObject* ibo)
void DefineVertexFormat(const Gx2BufferObject* vbo, const Gx2BufferObject* 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 upload.
auto ResolveUniform(const char* name) const -> const std::uint8_t*
Returns the last published value pointer of the named loose uniform, or nullptr.
auto HasBinaries() const -> bool
Returns true when the program has GX2 vertex and pixel shaders to bind.
auto GetVertexShader() const -> const GX2VertexShader*
auto GetPixelShader() const -> const GX2PixelShader*
auto GetVertexBindings() const -> const StageBindings&
auto GetPixelBindings() const -> const StageBindings&
auto GetSamplers() const -> const SmallVector<SamplerBinding, 0>&
auto GetFetchShader() -> const GX2FetchShader*
Returns the fetch shader for the current vertex format, building it on first use.
auto GetVertexFormat() -> Gx2VertexFormat&
Returns the vertex format the pipeline last defined on this program.

Function documentation

void nCine::RHI::GX2::Gx2ShaderProgram::SetProgramIdentity(const char* programName, const char* variantName)

Records the true (program, variant) identity of the loaded shader.

This backend will resolve its generated shader binaries from this identity, the same way the fixed-function console backends resolve their generated effect tables from it.

const GX2FetchShader* nCine::RHI::GX2::Gx2ShaderProgram::GetFetchShader()

Returns the fetch shader for the current vertex format, building it on first use.

Every enabled attribute of the format becomes one stream, read from attribute buffer streamBuffers[i]; the device sets those buffers up with GX2SetAttribBuffer(). A program without attributes (the sprites build their quad from gl_VertexID) gets an empty fetch shader.