Kanzi 4.0.0-beta2
kanzi::ShaderCompiler Class Referenceabstract

Provides the interface for a shader compiler that prepares the GLSL shader source code so that it conforms to the Vulkan GLSL extension (https://github.com/KhronosGroup/GLSL/blob/master/extensions/khr/GL_KHR_vulkan_glsl.txt) for use with the KzGFx library. More...

#include <kanzi/shadercompiler/shadercompiler.hpp>

Classes

struct  CompileResult
 Result type of the compile operation. More...
 
struct  ShaderErrors
 Shader compilation error messages. More...
 
struct  ShaderIncludeResult
 When providing custom shader include logic, communicates the result of a shader include operation. More...
 
struct  ShaderSource
 Shader input data for a shader stage. More...
 
struct  StageResult
 Shader compiler results for a single stage. More...
 

Public Types

using CustomIncluderFunction
 The callback function that resolves custom includes.
 
enum struct  OptionFlags {
  None , Optimize , EmitReflection , EmitBlob ,
  EmitHumanReadable , ConvertLegacyShader , Default
}
 Configuration options for the shader compiler. More...
 
using ProgramResults
 Map of stages to stage results.
 

Public Member Functions

virtual CompileResult compile (span< ShaderSource > sources, OptionFlags options, span< const gfx::ShaderFormat > formats, string_view defines="", CustomIncluderFunction systemIncluder={}, CustomIncluderFunction localIncluder={})=0
 Invokes the shader compiler for a given set of shader sources.
 
virtual ~ShaderCompiler ()=default
 Destructor.
 

Detailed Description

Provides the interface for a shader compiler that prepares the GLSL shader source code so that it conforms to the Vulkan GLSL extension (https://github.com/KhronosGroup/GLSL/blob/master/extensions/khr/GL_KHR_vulkan_glsl.txt) for use with the KzGFx library.

To provide syntax checking for the provided source code, the shader compiler internally uses the OpenGL ES reference compiler (https://www.khronos.org/opengles/sdk/tools/Reference-Compiler/). The shader compiler returns errors to the caller.

The shader compiler can output reflection information about the resulting shader program, such as input attributes, uniform buffer definitions, and image and sampler definitions.

Since
Kanzi 4.0.0

Member Typedef Documentation

◆ ProgramResults

Map of stages to stage results.

◆ CustomIncluderFunction

The callback function that resolves custom includes.

The first parameter is the requested source file. The second parameter is the source file that contains the include directive. The third parameter is the inclusion depth.

Member Enumeration Documentation

◆ OptionFlags

Configuration options for the shader compiler.

Enumerator
None 

No options specified.

Optimize 

Perform shader optimization.

EmitReflection 

Emit the reflection information.

EmitBlob 

Emit the shader blob in the target format.

EmitHumanReadable 

Emit the human-readable shader format.

ConvertLegacyShader 

Convert legacy shaders.

Default 

Perform shader optimization, emit reflection information, and emit the human-readable shader format.

The default option.

Constructor & Destructor Documentation

◆ ~ShaderCompiler()

virtual kanzi::ShaderCompiler::~ShaderCompiler ( )
virtualdefault

Destructor.

Member Function Documentation

◆ compile()

virtual CompileResult kanzi::ShaderCompiler::compile ( span< ShaderSource > sources,
OptionFlags options,
span< const gfx::ShaderFormat > formats,
string_view defines = "",
CustomIncluderFunction systemIncluder = {},
CustomIncluderFunction localIncluder = {} )
pure virtual

Invokes the shader compiler for a given set of shader sources.

Parameters
sourcesThe list of ShaderSource objects to compile. A vertex shader is required, other stages are optional. The shader compiler will assemble all stages into a single program.
optionsThe set of options to use for the compilation.
formatsThe list of shader formats to create.
definesA list of preprocessor definitions that are prepended to all shader compilations.
systemIncluderA system level includer function to use when the parser encounters an include operation in the shader.
localIncluderA local level includer function to use when the parser encounters an include operation in the shader.
Returns
The CompileResult structure that contains the result of the compilation operation.

The documentation for this class was generated from the following file: