Skip to main content

Shader

The Shader class represents a shader program, enabling the creation, loading, and management of shaders in various types and formats like native, GLSL, and SPIR-V. It provides functionality to configure and retrieve properties such as shader type, name, macros, and resource offsets for textures, surfaces, and uniforms. The class supports shader creation and compilation, management of global shader caches, and handling global macros and includes.

#include <platform/TellusimShader.h>

Constructors

Shader()

Methods

Shader platform.

Platform getPlatform() const
const char *getPlatformName() const

Shader device index.

uint32_t getIndex() const

Clear shader.

void clear()

Check shader.

bool isCreated() const

Shader parameters.

bool saveState(Stream &stream) const

Shader type.

Type getType() const
static const char *getTypeName(Type type)
const char *getTypeName() const
bool isVertex() const
bool isControl() const
bool isEvaluate() const
bool isGeometry() const
bool isFragment() const
bool isCompute() const
bool isTask() const
bool isMesh() const
bool isRayGen() const
bool isRayMiss() const
bool isClosest() const
bool isFirstHit() const
bool isIntersection() const
bool isCallable() const
bool isGraphicsType() const
bool isTessellationType() const
bool isTracingType() const
bool isMeshType() const

Shader name.

String getName() const
String getMacros() const

Shader samplers.

void setSamplerOffset(int32_t offset)
int32_t getSamplerOffset() const

Shader textures.

void setTextureOffset(int32_t offset)
int32_t getTextureOffset() const

Shader surfaces.

void setSurfaceOffset(int32_t offset)
int32_t getSurfaceOffset() const

Shader uniforms.

void setUniformOffset(int32_t offset)
int32_t getUniformOffset() const

Shader storages.

void setStorageOffset(int32_t offset)
int32_t getStorageOffset() const

Shader tracings.

void setTracingOffset(int32_t offset)
int32_t getTracingOffset() const

Shader texels.

void setTexelOffset(int32_t offset)
int32_t getTexelOffset() const

Shader tables.

void setTableOffset(int32_t offset)
int32_t getTableOffset() const

Shader patch size.

void setPatchSize(uint32_t size)
uint32_t getPatchSize() const

Shader input size.

void setInputSize(uint32_t size)
uint32_t getInputSize() const

Shader output size.

void setOutputSize(uint32_t size)
uint32_t getOutputSize() const

Create native shader.

bool load(Type type, const char *name, const char *format)
bool create(Type type, const char *src, const char *format)
bool load(Type type, const char *name, const String &macros = String::null, const char **includes = nullptr, uint32_t size = 0)
bool create(Type type, const char *src, const String &macros = String::null, const char **includes = nullptr, uint32_t size = 0)

Create GLSL shader.

bool loadGLSL(Type type, const char *name, const char *format)
bool createGLSL(Type type, const char *src, const char *format)
bool loadGLSL(Type type, const char *name, const String &macros = String::null, const char **includes = nullptr, uint32_t size = 0)
bool createGLSL(Type type, const char *src, const String &macros = String::null, const char **includes = nullptr, uint32_t size = 0)

Create SPIR-V shader.

bool loadSPIRV(Type type, const char *name)
bool createSPIRV(Type type, Array<uint32_t> data)

Global shader cache.

static bool hasCache()
static bool setCache(const char *name)
static bool loadCache(const String &hash, Stream &stream)
static bool saveCache(const String &hash, Stream &stream)
static void clearCache()

Global macro definitions.

static bool isMacro(const char *name)
static bool setMacro(const char *name, int32_t value)
static bool setMacro(const char *name, uint32_t value)
static bool setMacro(const char *name, const char *value = nullptr)
static bool setMacros(const char *macros)
static bool removeMacro(const char *name)
static void clearMacros()

Global include definitions.

static bool isInclude(const char *name)
static bool setInclude(const char *name, const String &src)
static bool removeInclude(const char *name)
static void clearIncludes()

Global macro preprocessor.

static String preprocessor(const char *src, const char *format)
static String preprocessor(const char *src, const String &macros = String::null, const char **includes = nullptr, uint32_t size = 0)

Enums

Type

Shader types.

NameValueDescription
TypeUnknown0
TypeVertex1Vertex shader.
TypeControl2Tessellation control shader.
TypeEvaluate3Tessellation evaluate shader.
TypeGeometry4Geometry shader.
TypeFragment5Fragment shader.
TypeCompute6Compute shader.
TypeTask7Task shader.
TypeMesh8Mesh shader.
TypeRayGen9Ray gen shader.
TypeRayMiss10Ray miss shader.
TypeClosest11Ray closest shader.
TypeFirstHit12Ray first hit shader.
TypeIntersection13Ray intersection shader.
TypeCallable14Ray callable shader.
NumTypes15

Mask

Shader masks.

NameValueDescription
MaskNone0
MaskVertex(1 << TypeVertex)Vertex shader mask.
MaskControl(1 << TypeControl)Tessellation control shader mask.
MaskEvaluate(1 << TypeEvaluate)Tessellation evaluate shader mask.
MaskGeometry(1 << TypeGeometry)Geometry shader mask.
MaskFragment(1 << TypeFragment)Fragment shader mask.
MaskCompute(1 << TypeCompute)Compute shader mask.
MaskTask(1 << TypeTask)Task shader mask.
MaskMesh(1 << TypeMesh)Mesh shader mask.
MaskRayGen(1 << TypeRayGen)Ray gen shader mask.
MaskRayMiss(1 << TypeRayMiss)Ray miss shader mask.
MaskClosest(1 << TypeClosest)Closest shader mask.
MaskFirstHit(1 << TypeFirstHit)First hit shader mask.
MaskIntersection(1 << TypeIntersection)Intersection shader mask.
MaskCallable(1 << TypeCallable)Callable shader mask.
MaskVertexFragment(MaskVertex | MaskFragment)
MaskGraphics(MaskVertex | MaskControl | MaskEvaluate | MaskGeometry | MaskFragment)
MaskTracing(MaskRayGen | MaskRayMiss | MaskClosest | MaskFirstHit | MaskIntersection | MaskCallable)
MaskAll(MaskGraphics | MaskCompute | MaskTask | MaskMesh | MaskTracing)