Skip to content

Commit

Permalink
Minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Flone-dnb committed Nov 17, 2024
1 parent ef74f25 commit ae0d9b3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace ne {
FrameResourceManager& operator=(const FrameResourceManager&) = delete;

/**
* Returns the number of used frame resources.
* Returns the total number of frames in-flight (that the CPU can submit before waiting for the GPU).
*
* @return Number of frame resources being used.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace ne {
inline void updateResource(size_t iCurrentFrameResourceIndex) {
void* pDataToCopy = onStartedUpdatingResource();

vResourceData[iCurrentFrameResourceIndex]->updateData(pDataToCopy);
vResourceData[iCurrentFrameResourceIndex]->updateDataBecauseGpuUnused(pDataToCopy);

onFinishedUpdatingResource();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,30 @@ namespace ne {

/**
* Creates a new global shader resource binding (that don't change on a per-object
* basis) and assigns it to the specified resources. When resources will be destroyed
* the binding will also be removed.
* basis) and assigns it to the specified resources (one resource per frame). When resources will be
* destroyed the binding will also be removed.
*
* @remark If you only need to bind the same GPU resource for all frames in-flight then either
* use @ref createGlobalShaderResourceBindingSingleResource that accepts a single GPU resource
* pointer (preferred) or just pass an array of the same pointers.
*
* @remark The actual type of the binding (cbuffer, uniform, structured buffer, storage buffer or
* etc) will be determined from the resource. For example, in DirectX in order to bind a `cbuffer`
* shader resource you need to pass a resource that already has a CBV binded and in Vulkan in
* shader resource you need to pass a resource that already has a CBV bound and in Vulkan in
* order to bind a `uniform` you need to make sure that your resource was created with
* the "uniform" hint/flag.
*
* @remark This function will create a binding that binds a separate GPU resource per frame in-flight,
* this is generally used for some CPU-write resources (but there are exceptions and you can bind a
* single CPU-write resource in @ref createGlobalShaderResourceBindingSingleResource if you only
* update the resource while it's unused by the GPU) so generally you have a CPU-write GPU buffer
* that you plan to update without CPU-GPU synchronization (for example each time the CPU is
* submitting a new frame) then you need to pass a separate buffer per frame resource to avoid
* modifying a buffer that may be used by the GPU.
*
* @param sShaderResourceName Name of the shader resource (name from shader code) to bind the
* resources.
* @param vResourcesToBind Resources to bind to pipelines. This function will create a binding
* that binds a separate GPU resource per frame, this is generally used for some CPU-write resources
* so in this case you have a CPU-write GPU buffer that you plan to update without CPU-GPU
* synchronization (for example each time the CPU is submitting a new frame) then you need to pass a
* separate buffer per frame resource to avoid modifying a buffer that may be used by the GPU.
* @param vResourcesToBind Resources to bind to pipelines.
*
* @return Error if something went wrong.
*/
Expand All @@ -67,12 +71,14 @@ namespace ne {
*
* @remark Also see @ref createGlobalShaderResourceBindingResourcePerFrame for important remarks.
*
* @remark This function will create a binding that binds the same GPU resource for all frames
* in-flight (this can be used for textures or some buffer resources). This is used when you guarantee
* the CPU-GPU synchronization or don't plan to update the resource's contents from the CPU (but there
* are exceptions, see remarks of @ref createGlobalShaderResourceBindingResourcePerFrame).
*
* @param sShaderResourceName Name of the shader resource (name from shader code) to bind the
* resource.
* @param pResourceToBind Resources to bind to pipelines. This function will create a binding
* that binds the same GPU resource for all frames in-flight (this can be used for textures
* or some buffer resources). This is used when you guarantee the CPU-GPU synchronization or
* don't plan to update the resource's contents from the CPU.
* @param pResourceToBind Resources to bind to pipelines.
*
* @return Error if something went wrong.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace ne {
pArray->markSlotAsNoLongerBeingUsed(this);
}

void DynamicCpuWriteShaderResourceArraySlot::updateData(void* pData) {
void DynamicCpuWriteShaderResourceArraySlot::updateDataBecauseGpuUnused(void* pData) {
pArray->updateSlotData(this, pData);
}

Expand Down Expand Up @@ -259,7 +259,9 @@ namespace ne {
// Get global shader resource binding manager.
const auto pGlobalBindingManager = pRenderer->getGlobalShaderResourceBindingManager();

// Bind as global shader resource.
// Bind a single resource even though it's a CPU write resource because we have
// a warning in the documentation of the slot's update function that it can only be used
// while the GPU is not using it.
auto optionalError = pGlobalBindingManager->createGlobalShaderResourceBindingSingleResource(
sHandledShaderResourceName, mtxInternalResources.second.pUploadBuffer->getInternalResource());
if (optionalError.has_value()) [[unlikely]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ namespace ne {
* @warning Should only be called when shader resource manager tells that it's the time
* to update shader resource data.
*
* @warning Can only be used when the GPU is not using (processing) this data.
*
* @param pData Data to copy.
*/
void updateData(void* pData);
void updateDataBecauseGpuUnused(void* pData);

/**
* Returns index into the array (that owns this slot) to access the slot's data.
Expand Down

0 comments on commit ae0d9b3

Please sign in to comment.