Class Shader

Nested Relationships

Nested Types

Class Documentation

class Shader

Provides an API agnostic object for managing a shader.

Public Types

enum class Stage

Enumerates Shader pipeline stages.

Values:

enumerator kInvalid
enumerator kVertex
enumerator kHull
enumerator kTesselationControl
enumerator kDomain
enumerator kTesselationEvaluation
enumerator kGeometry
enumerator kAmplification
enumerator kMesh
enumerator kFragment
enumerator kCompute
enumerator kLibrary
enumerator kCount

Public Functions

bool operator!=(Shader const &other) const

Gets a value indicating whether or not this Shader is inequal to a given Shader.

Parameters

other -- The Shader to check for equality

Returns

Whether or not this Shader is inequal to the given Shader

Shader::Stage GetStage() const

Gets this Shader's ShaderStage.

Returns

This Shader's ShaderStage

api_types::ShaderLanguage GetLanguage() const

Gets this Shader's ShaderLanguage.

Returns

This Shader's ShaderLanguage

void GetSourceCode(size_t *pSizeBytes, char *pSourceCode) const

Gets this Shader's source code.

Parameters
  • pSizeBytes -- [out] A pointer to a size_t to write this Shader's source code size in bytes

  • pSourceCode -- [out] A pointer to a preallocated char buffer to copy this Shader

    's source code into

    NOTE : Call this method with nullptr for pSourceCode to populate only the pSizeBytes argument

    NOTE : Providing a buffer that isn't large enough results in undefined behavior

void GetEntryPoint(size_t *pSizeBytes, char *pEntryPoint) const

Gets this Shader's entry point.

Parameters
  • pSizeBytes -- [out] A pointer to a size_t to write this Shader's source code size in bytes

  • pEntryPoint -- [out] A pointer to a preallocated char buffer to copy this Shader

    's entry point into

    NOTE : Call this method with nullptr for pEntryPoint to populate only the pSizeBytes argument

    NOTE : Providing a buffer that isn't large enough results in undefined behavior

void GetByteCode(size_t *pSizeBytes, uint8_t *pByteCode) const

Gets this Shader's byte code.

Parameters
  • pSizeBytes -- [out] A pointer to a size_t to write this Shader's byte code size in bytes

  • pByteCode -- [out] A pointer to a preallocated uint8_t buffer to copy this Shader

    's byte code into

    NOTE : Call this method with nullptr for pByteCode to populate only the pSizeBytes argument

    NOTE : Providing a buffer that isn't large enough results in undefined behavior

uint32_t GetHash() const

Gets this Shader's hash.

Returns

This Shader hash

class CompileInfo

Compilation parameters for a Shader.

Public Members

Stage stage = {Stage::kInvalid}

The stage of the Shader to compile.

api_types::ManagedShaderSource sourceCode

Source code of the Shader to compile (optional)

std::vector<uint8_t> byteCode

A byte code of the Shader to compile (optional)

std::string shaderProfile

For HLSL, a shader profile string of the Shader to compile (optional)

void *shaderData = {nullptr}

A pipeline state (optional) Valid strings: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-models

class Compiler

Provides an API agnostic interface for Shader compilation.

Public Functions

Compiler() = default

Creates an instance of Shader::Compiler.

virtual ~Compiler() = 0

Destroys this Shader::Compiler.

void GetMessages(size_t *pMessageCount, char const **pMessages) const

Gets messages from the most recent Shader

compilation.

NOTE : The messages returned from this method are invalidated whenever any method besides

GetMessages() is called.

Parameters
  • pMessageCount -- [out] The number of messages generated during the most recent Shader compilation

  • pMessages -- [out] A pointer to a preallocated array of char const pointers to populate with messages NOTE : Call this method with nullptr for pMessageCount to populate only the pSizeBytes argument NOTE : Messages will be provided as null terminated C strings NOTE : Providing an array that isn't large enough results in undefined behavior

virtual bool Compile(Shader::CompileInfo &compileInfo, Shader *pShader) const = 0

Compiles a Shader from a given Shader::CompileInfo.

Parameters
  • compileInfo -- The Shader::CompileInfo to use for copmilation

  • pShader -- A pointer to an empty Shader object to store compilation results

Returns

Whether or not compilation was successful

Protected Functions

void CreateShader(Shader::Stage stage, const api_types::ShaderSource &source, const std::vector<uint8_t> &byteCode, Shader *pShader) const

Creates a Shader

.

NOTE : Any necessary validation should be performed by API specific compiler objects before calling this method.

Parameters
  • stage -- The Shader::Stage of the Shader to create

  • language -- The Shader::Language of the Shader to create

  • entryPoint -- The entry point of the Shader to create

  • byteCodeSize -- The size in bytes of the byte code of the Shader to create

  • pByteCode -- A pointer to the byte code of the Shader to create

  • pShader -- A pointer to an empty Shader object to store creation results

Protected Attributes

mutable std::vector<std::string> mMessages