Cogs.Core
IEffects.h
1#pragma once
2#include "Common.h"
3
4#include "VertexFormat.h"
5
6#include "IBindGroups.h"
7
8#include "Foundation/StringView.h"
9
10#include <cstdint>
11#include <string>
12#include <vector>
13
14namespace Cogs
15{
17 typedef std::pair<std::string, std::string> PreprocessorDefinition;
18
20 typedef std::vector<PreprocessorDefinition> PreprocessorDefinitions;
21
24 {
27 {
29 None = 0,
31 HLSL = 0x1,
33 GLSL = 0x2,
37 Pinned = 0x8,
43 WGSL = 0x40,
44 };
45 };
46
51 {
53 File,
55 Source,
56 };
57
62 {
65
68
71
74
77
80
83
86
89
92
95
98
101
104
107
110 };
111
116 {
117 virtual ~IIOHandler() {}
118
125 virtual bool openFile(const StringView & fileName, std::string & content) = 0;
126
135 virtual bool resolveFile(const StringView & source, const StringView & fileName, std::string & content) = 0;
136
137 enum class FileType
138 {
139 ShaderDump = 0,
140 ShaderCache,
141 PipelineCache
142 };
143
144 virtual bool exists(FileType type, const StringView & fileName) = 0;
145
146 virtual bool writeBinaryFile(FileType type, const StringView & fileName, const void * content, size_t contentSize) = 0;
147 virtual bool openBinaryFile(FileType type, const StringView & fileName, std::vector<uint8_t> & content) = 0;
148
149 virtual void pushSearchPaths() = 0;
150 virtual void addSearchPath(const StringView & path) = 0;
151 virtual void popSearchPaths() = 0;
152 };
153
157 struct IEffects
158 {
166 virtual EffectHandle loadEffect(const EffectDescription & description) = 0;
167
175
183
191 virtual EffectHandle loadComputeEffect(const StringView & fileName, const PreprocessorDefinitions & definitions, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
192
200 virtual EffectHandle loadEffect(const StringView & vsFileName, const StringView & psFileName, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
201
210 virtual EffectHandle loadEffect(const StringView & vsFileName, const StringView & psFileName, const PreprocessorDefinitions & definitions, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
211
220 virtual EffectHandle loadEffectSource(const StringView & vsSource, const StringView & psSource, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
221
231 virtual EffectHandle loadEffectSource(const StringView & vsSource, const StringView & gsSource, const StringView & psSource, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
232
242 virtual EffectHandle loadEffectSource(const StringView & vsSource, const StringView & psSource, const PreprocessorDefinitions & definitions, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
243
254 virtual EffectHandle loadEffectSource(const StringView & vsSource, const StringView & gsSource, const StringView & psSource, const PreprocessorDefinitions & definitions, EffectFlags::EEffectFlags effectFlags = EffectFlags::None) = 0;
255
265 virtual ResourceStatus checkEffect(EffectHandle effectHandle) = 0;
266
272 virtual void releaseEffect(EffectHandle effectHandle) = 0;
273
281 virtual EffectVariableHandle getEffectVariable(EffectHandle effectHandle, const StringView & name) = 0;
282
293
305 virtual TextureBindingHandle getTextureBinding(EffectHandle effectHandle, const StringView & name, const unsigned int slot) = 0;
306
310 virtual BufferBindingHandle getBufferBinding(EffectHandle effectHandle, const StringView & name) = 0;
311
315 virtual void releaseBufferBinding(BufferBindingHandle bufferBindingHandle) = 0;
316
331 virtual SamplerStateBindingHandle getSamplerStateBinding(EffectHandle effectHandle, const StringView & name, const unsigned int slot) = 0;
332
336 virtual uint32_t getNumBindGroups(EffectHandle effectHandle)
337 {
338 (void)effectHandle;
339 return 0;
340 }
341
342 virtual const BindGroupDescription &getBindGroupDescription(EffectHandle effectHandle, uint32_t groupIndex)
343 {
344 (void)effectHandle;
345 (void)groupIndex;
346 static const BindGroupDescription empty;
347 return empty;
348 }
349
350 virtual bool hasCompatibleBindGroupLayout(EffectHandle effectHandle, uint32_t groupIndex, const BindGroupDescription& layout)
351 {
352 (void)effectHandle;
353 (void)groupIndex;
354 (void)layout;
355 return false;
356 }
357
366 virtual bool getBindGroupLayout(EffectHandle effectHandle, uint32_t groupIndex, BindGroupDescription& layoutOutput)
367 {
368 (void)effectHandle;
369 (void)groupIndex;
370 (void)layoutOutput;
371 return false;
372 }
373
374
378 virtual void releaseResources() = 0;
379
383 virtual void annotate(EffectHandle handle, const StringView & name) { (void)handle; (void)name; }
384
388 virtual void annotateVS(EffectHandle handle, const StringView & name) { (void)handle; (void)name; }
389
393 virtual void annotateGS(EffectHandle handle, const StringView & name) { (void)handle; (void)name; }
394
398 virtual void annotatePS(EffectHandle handle, const StringView & name) { (void)handle; (void)name; }
399
403 virtual void annotateCS(EffectHandle handle, const StringView & name) { (void)handle; (void)name; }
404
410 virtual void setIOHandler(IIOHandler * handler) = 0;
411
415 virtual IIOHandler * getIOHandler() { return nullptr; }
416 };
417}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:50
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
ResourceStatus
Status of an asynchronously loaded resource, such as an effect or a pipeline.
Definition: Common.h:198
std::pair< std::string, std::string > PreprocessorDefinition
Preprocessor definition.
Definition: IEffects.h:17
EffectDescriptionType
Type of contents in effect description.
Definition: IEffects.h:51
std::vector< PreprocessorDefinition > PreprocessorDefinitions
A set of preprocessor definitions.
Definition: IEffects.h:20
Contains an effect description used to load a single effect.
Definition: IEffects.h:62
StringView hsEntryPoint
Entry point of the hull shader.
Definition: IEffects.h:85
StringView gsEntryPoint
Entry point of the geometry shader.
Definition: IEffects.h:91
EffectFlags::EEffectFlags flags
Effect loading flags.
Definition: IEffects.h:106
StringView geometryShader
Geometry shader file name or source.
Definition: IEffects.h:73
BindGroupSetDescription bindGroupLayoutDesc
Optional bind-group layout metadata. Backends may use this instead of source introspection.
Definition: IEffects.h:103
StringView vsEntryPoint
Entry point of the vertex shader.
Definition: IEffects.h:82
StringView effect
Effect file name or source.
Definition: IEffects.h:79
StringView domainShader
Domain shader file name or source.
Definition: IEffects.h:70
StringView dsEntryPoint
Entry point of the domain shader.
Definition: IEffects.h:88
PreprocessorDefinitions definitions
Definitions.
Definition: IEffects.h:100
StringView vertexShader
Vertex shader file name or source.
Definition: IEffects.h:64
StringView name
Name of the effect. Used for tracking purposes, like naming shader dumps.
Definition: IEffects.h:97
StringView psEntryPoint
Entry point of the pixel shader.
Definition: IEffects.h:94
EffectDescriptionType type
Type of effect description. Defaults to file names.
Definition: IEffects.h:109
StringView pixelShader
Pixel shader file name or source.
Definition: IEffects.h:76
StringView hullShader
Hull shader file name or source.
Definition: IEffects.h:67
Flags used to describe effect source.
Definition: IEffects.h:24
EEffectFlags
Effect source flags.
Definition: IEffects.h:27
@ LogShaderSource
Log the contents of the shader on error.
Definition: IEffects.h:41
@ HLSL
Effect source is HLSL.
Definition: IEffects.h:31
@ WGSL
Effect source is WGSL.
Definition: IEffects.h:43
@ LogShaderInfo
Log detailed info about shaders.
Definition: IEffects.h:39
@ GeometryShader
Effect source contains geometry shader.
Definition: IEffects.h:35
@ GLSL
Effect source is GLSL.
Definition: IEffects.h:33
@ Pinned
Effect can only be released explicitly, not using releaseResources().
Definition: IEffects.h:37
Provides effects and shader management functionality.
Definition: IEffects.h:158
virtual SamplerStateBindingHandle getSamplerStateBinding(EffectHandle effectHandle, const StringView &name, const unsigned int slot)=0
Get a handle to a sampler state object binding, mapping how to bind the sampler state to the given ef...
virtual void annotatePS(EffectHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IEffects.h:398
virtual EffectHandle loadEffectSource(const StringView &vsSource, const StringView &psSource, const PreprocessorDefinitions &definitions, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex and pixel shader sources given, applying the given preprocesso...
virtual ConstantBufferBindingHandle getConstantBufferBinding(EffectHandle effectHandle, const StringView &name)=0
Get a handle to a constant buffer binding, mapping how to bind a constant buffer to the given effect.
virtual EffectHandle loadComputeEffect(const StringView &fileName, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load the compute shader with the given file name and create an effect.
virtual EffectHandle loadEffectSource(const StringView &vsSource, const StringView &gsSource, const StringView &psSource, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex, geometry, and pixel shader sources given.
virtual TextureBindingHandle getTextureBinding(EffectHandle effectHandle, const StringView &name, const unsigned int slot)=0
Get a handle to a texture object binding, mapping how to bind textures to the given effect.
virtual EffectHandle loadEffect(const StringView &fileName, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load the given single file effect.
virtual BufferBindingHandle getBufferBinding(EffectHandle effectHandle, const StringView &name)=0
Get a handle to a buffer binding.
virtual void releaseResources()=0
Release all allocated effect resources.
virtual EffectHandle loadEffectSource(const StringView &vsSource, const StringView &gsSource, const StringView &psSource, const PreprocessorDefinitions &definitions, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex, geometry, and pixel shader sources given, applying the given ...
virtual void releaseEffect(EffectHandle effectHandle)=0
Release the effect with the given handle, freeing all resources generated during program loading.
virtual EffectHandle loadEffectSource(const StringView &vsSource, const StringView &psSource, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex and pixel shader sources given.
virtual bool getBindGroupLayout(EffectHandle effectHandle, uint32_t groupIndex, BindGroupDescription &layoutOutput)
Get bind-group layout metadata for the given effect and bind-group index.
Definition: IEffects.h:366
virtual void annotateCS(EffectHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IEffects.h:403
virtual EffectHandle loadEffect(const StringView &vsFileName, const StringView &psFileName, const PreprocessorDefinitions &definitions, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex and pixel shader files given, applying the given preprocessor ...
virtual EffectHandle loadEffect(const StringView &vsFileName, const StringView &psFileName, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load an effect created from the vertex and pixel shader files given.
virtual IIOHandler * getIOHandler()
Gets the external I/O handler.
Definition: IEffects.h:415
virtual void annotateVS(EffectHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IEffects.h:388
virtual void releaseBufferBinding(BufferBindingHandle bufferBindingHandle)=0
Release a handle to a buffer binding.
virtual EffectVariableHandle getEffectVariable(EffectHandle effectHandle, const StringView &name)=0
Get a handle to the variable with the given name in the effect with the given effectHandle.
virtual EffectHandle loadEffect(const EffectDescription &description)=0
Load an effect from the given description.
virtual void annotateGS(EffectHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IEffects.h:393
virtual ResourceStatus checkEffect(EffectHandle effectHandle)=0
Check the load status of the effect with the given effectHandle.
virtual EffectHandle loadComputeEffect(const StringView &fileName, const PreprocessorDefinitions &definitions, EffectFlags::EEffectFlags effectFlags=EffectFlags::None)=0
Load the compute shader with the given file name and create an effect.
virtual void annotate(EffectHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IEffects.h:383
virtual uint32_t getNumBindGroups(EffectHandle effectHandle)
Query the number of bind-group layouts exposed by the given effect.
Definition: IEffects.h:336
virtual void setIOHandler(IIOHandler *handler)=0
Sets an external I/O handler to use for I/O operations.
I/O handler.
Definition: IEffects.h:116
virtual bool resolveFile(const StringView &source, const StringView &fileName, std::string &content)=0
Callback method used to resolve include statements in shader code and get the contents to include.
virtual bool openFile(const StringView &fileName, std::string &content)=0
Callback method used to open files.