Nameless Engine
|
#include <ShaderCpuWriteResourceBinding.h>
Public Member Functions | |
void | copyResourceIndexToShaderConstants (PipelineShaderConstantsManager *pShaderConstantsManager, Pipeline *pUsedPipeline, size_t iCurrentFrameResourceIndex) |
size_t | getResourceDataSizeInBytes () const |
virtual std::optional< Error > | changeUsedPipelines (const std::unordered_set< Pipeline * > &pipelinesToUse) override |
Public Member Functions inherited from ne::ShaderResourceBindingBase | |
virtual std::optional< Error > | changeUsedPipelines (const std::unordered_set< Pipeline * > &pipelinesToUse)=0 |
std::string | getShaderResourceName () const |
Protected Member Functions | |
ShaderCpuWriteResourceBinding (const std::string &sShaderResourceName, size_t iResourceDataSizeInBytes, const std::function< void *()> &onStartedUpdatingResource, const std::function< void()> &onFinishedUpdatingResource, const std::unordered_map< Pipeline *, size_t > &uintShaderConstantOffsets) | |
virtual std::optional< Error > | onAfterAllPipelinesRefreshedResources () override |
Protected Member Functions inherited from ne::ShaderResourceBindingBase | |
ShaderResourceBindingBase (const std::string &sShaderResourceName) | |
virtual std::optional< Error > | onAfterAllPipelinesRefreshedResources ()=0 |
Static Protected Member Functions | |
static std::variant< std::unique_ptr< ShaderCpuWriteResourceBinding >, Error > | create (const std::string &sShaderResourceName, const std::string &sResourceAdditionalInfo, size_t iResourceSizeInBytes, const std::unordered_set< Pipeline * > &pipelinesToUse, const std::function< void *()> &onStartedUpdatingResource, const std::function< void()> &onFinishedUpdatingResource) |
static std::variant< std::unordered_map< Pipeline *, size_t >, Error > | getUintShaderConstantOffsetsFromPipelines (const std::unordered_set< Pipeline * > &pipelines, const std::string &sFieldName) |
Protected Attributes | |
std::pair< std::recursive_mutex, std::unordered_map< Pipeline *, size_t > > | mtxUintShaderConstantOffsets |
std::array< std::unique_ptr< DynamicCpuWriteShaderResourceArraySlot >, FrameResourceManager::getFrameResourceCount()> | vResourceData |
Private Member Functions | |
void | updateResource (size_t iCurrentFrameResourceIndex) |
Private Attributes | |
const std::function< void *()> | onStartedUpdatingResource |
const std::function< void()> | onFinishedUpdatingResource |
const size_t | iResourceDataSizeInBytes = 0 |
Friends | |
class | ShaderCpuWriteResourceBindingManager |
References a single (non-array) shader resource (that is written in a shader file) that has CPU write access available (can be updated from the CPU side).
|
protected |
Constructs a partially initialized object.
sShaderResourceName | Name of the resource we are referencing (should be exactly the same as the resource name written in the shader file we are referencing). |
iResourceDataSizeInBytes | Size (in bytes) of the data that this resource will contain. |
onStartedUpdatingResource | Function that will be called when started updating resource data. Function returns pointer to data of the specified resource data size that needs to be copied into the resource. |
onFinishedUpdatingResource | Function that will be called when finished updating (usually used for unlocking resource data mutex). |
uintShaderConstantOffsets | Offsets of root/push constants (per-pipeline) to copy an index into array to. |
|
overridevirtual |
Called to make the resource to discard currently used pipelines and bind/reference other pipelines.
draw
function while this function is not finished (i.e. make sure the CPU will not queue a new frame while this function is not finished).pipelinesToUse | Pipelines to use instead of the current ones. |
Implements ne::ShaderResourceBindingBase.
|
inline |
Copies resource index (into shader arrays) to a root/push constant.
pShaderConstantsManager | Shader constants manager. |
pUsedPipeline | Current pipeline. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
|
staticprotected |
Creates a new shader CPU-write resource.
sShaderResourceName | Name of the resource we are referencing (should be exactly the same as the resource name written in the shader file we are referencing). |
sResourceAdditionalInfo | Additional text that we will append to created resource name (used for logging). |
iResourceSizeInBytes | Size of the data that this resource will contain. |
pipelinesToUse | Pipelines that use shader/parameters we are referencing. |
onStartedUpdatingResource | Function that will be called when started updating resource data. Function returns pointer to data of the specified resource data size that needs to be copied into the resource. |
onFinishedUpdatingResource | Function that will be called when finished updating (usually used for unlocking resource data mutex). |
|
inline |
Returns size of the resource data.
|
staticprotected |
Looks for root/push constants (field) named after the shader resource in the specified pipelines and returns offsets of such fields.
pipelines | Pipelines to scan. |
sFieldName | Name of the root/push constant field to look for. |
|
overrideprotectedvirtual |
Called from pipeline manager to notify that all pipelines released their internal resources and now restored them so their internal resources (for example push constants) might be different now and shader resource now needs to check that everything that it needs is still there and possibly re-bind to pipeline's descriptors since these might have been also re-created.
Implements ne::ShaderResourceBindingBase.
|
inlineprivate |
Copies up to date data to the GPU resource of the specified frame resource.
iCurrentFrameResourceIndex | Index of currently used frame resource. |
|
private |
Size (in bytes) of the data that the resource contains.
|
protected |
Offsets of root/push constants (per-pipeline) to copy an index into array to.
|
private |
Function to call when finished updating (usually used for unlocking resource data mutex).
|
private |
Function used to update resource data. Returns pointer to data of size iResourceDataSizeInBytes that needs to be copied into resource data storage (GPU resource).
|
protected |
Stores data for shaders to use (per frame resource). Index (from array start) will be copied to push constant so that shaders can index into the array and access the data.