Shader Programs

struct ShaderSource
#include <dag_shader.h>

Holds a direct pointer to a (compressed) shader data in bindump Supports both compressed (if dictionary not nullptr) and uncompressed data The spans are guaranteed to be alive for the lifetime of the shaders bindump.

Subclassed by ShaderSourceExt

Public Functions

const uint32_t *uncompress(Tab<uint8_t> &tmpbuf) const

Uncompresses the shader data, in case of no compression just copies it.

Parameters:

tmpbuf – Temporary memory that will hold resulting shader data

Returns:

Pointer to uncompressed shader data.

Public Members

dag::ConstSpan<uint8_t> compressedData
dag::ConstSpan<uint8_t> metadata
uint32_t uncompressedSize = 0
void *dictionary = nullptr
struct ShaderSourceExt : public ShaderSource
#include <dag_shader.h>

Extends ShaderSource with an optional debug name pointer+len, must be null terminated Unlike the base structure, the user only guarantees debugName to be valid during shader creation call, so drivers may store only the spliced out base ShaderSource.

Public Functions

inline eastl::string_view getDebugName() const

Get the string view of the debug name.

The user guarantees the debugName pointer to be alive only for the duration of the d3d:: call where the ShaderSource is passed The driver guarantees to copy the string if it needs it, and not retain the pointer The name is not stored as string_view initially to allow to put more data in the padding in the future

Returns:

String view from debugName/debugNameLen.

Public Members

uint32_t debugNameLen = 0
const char *debugName = nullptr
namespace _MULTI_INTERFACE

Functions

PROGRAM create_program(VPROG vprog, FSHADER fsh, VDECL vdecl, unsigned *strides = nullptr, unsigned streams = 0)

Creates a program with a vertex shader, fragment shader, and vertex declaration.

If strides and streams are not set, they will be obtained from the vertex declaration. The program should be deleted externally using delete_program().

Parameters:
  • vprog – The vertex shader program.

  • fsh – The fragment shader program.

  • vdecl – The vertex declaration.

  • strides – The stride values for each vertex stream (optional, default is 0).

  • streams – The number of vertex streams (optional, default is 0).

Returns:

The created program.

PROGRAM create_program_cs(const ShaderSourceExt &cs_native, CSPreloaded preloaded)

Creates a compute shader program with native code.

Parameters:
  • cs_native – The native code for the compute shader.

  • preloaded – The preloaded data for the compute shader.

Returns:

The created program.

bool set_program(PROGRAM program)

Sets the program as the current program, including the pixel shader, vertex shader, and vertex declaration.

Parameters:

program – The program to set.

Returns:

True if the program was set successfully, false otherwise.

void delete_program(PROGRAM program)

Deletes a program, including the vertex shader and fragment shader.

Warning

The vertex declaration should be deleted independently.

Parameters:

program – The program to delete.

VPROG create_vertex_shader(const ShaderSourceExt &native_code)

Creates a vertex shader with native code.

Parameters:

native_code – The native code for the vertex shader.

Returns:

The created vertex shader.

void delete_vertex_shader(VPROG vs)

Deletes a vertex shader.

Parameters:

vs – The vertex shader to delete.

FSHADER create_pixel_shader(const ShaderSourceExt &native_code)

Creates a pixel shader with native code.

Parameters:

native_code – The native code for the pixel shader.

Returns:

The created pixel shader.

void delete_pixel_shader(FSHADER ps)

Deletes a pixel shader.

Parameters:

ps – The pixel shader to delete.

PROGRAM get_debug_program()

Gets the debug program.

This program’s bytecode is written in the source code of the driver, so the program is always available (if a driver supports this API). The debug program is used to draw debug stuff (vertex colored primitives).

Returns:

The debug program.