Nameless Engine
|
#include <DynamicCpuWriteShaderResourceArray.h>
Classes | |
struct | InternalResources |
Public Member Functions | |
DynamicCpuWriteShaderResourceArray (const DynamicCpuWriteShaderResourceArray &)=delete | |
DynamicCpuWriteShaderResourceArray & | operator= (const DynamicCpuWriteShaderResourceArray &)=delete |
size_t | getSize () |
size_t | getCapacity () |
size_t | getSizeInBytes () |
size_t | getElementSize () const |
size_t | getCapacityStepSize () const |
std::string_view | getHandledShaderResourceName () const |
std::pair< std::recursive_mutex, InternalResources > * | getInternalResources () |
Private Member Functions | |
DynamicCpuWriteShaderResourceArray (GpuResourceManager *pResourceManager, const std::string &sHandledShaderResourceName, size_t iElementSizeInBytes, size_t iCapacityStepSize) | |
std::variant< std::unique_ptr< DynamicCpuWriteShaderResourceArraySlot >, Error > | insert (ShaderCpuWriteResourceBinding *pShaderResource) |
void | markSlotAsNoLongerBeingUsed (DynamicCpuWriteShaderResourceArraySlot *pSlot) |
void | updateSlotData (DynamicCpuWriteShaderResourceArraySlot *pSlot, void *pData) |
std::optional< Error > | createArray (size_t iCapacity) |
std::optional< Error > | expandArray () |
std::optional< Error > | shrinkArray () |
Static Private Member Functions | |
static std::variant< std::unique_ptr< DynamicCpuWriteShaderResourceArray >, Error > | create (GpuResourceManager *pResourceManager, const std::string &sHandledShaderResourceName, size_t iElementSizeInBytes) |
static std::string | formatBytesToKilobytes (size_t iSizeInBytes) |
static std::variant< size_t, Error > | calculateCapacityStepSize (size_t iElementSizeInBytes) |
Private Attributes | |
std::pair< std::recursive_mutex, InternalResources > | mtxInternalResources |
GpuResourceManager *const | pResourceManager = nullptr |
const size_t | iCapacityStepSize = 0 |
const std::string | sHandledShaderResourceName |
const size_t | iElementSizeInBytes = 0 |
Friends | |
class | DynamicCpuWriteShaderResourceArraySlot |
class | DynamicCpuWriteShaderResourceArrayManager |
Allows storing elements of the same size in one GPU buffer.
|
private |
Creates initialized array.
pResourceManager | Resource manager that will allocate GPU buffers. |
sHandledShaderResourceName | Name of the shader resource this array handles. It will be used to bind the array to pipelines. |
iElementSizeInBytes | Size (in bytes) of one element in the array. |
iCapacityStepSize | Capacity step size to use. Expecting it to be even and not zero. |
|
staticprivate |
Calculates array capacity step size depending on the size of the elements in the array.
iElementSizeInBytes | Size (in bytes) of one element in the array. |
|
staticprivate |
Creates a new initialized array.
pResourceManager | Resource manager that will be used to allocate GPU buffers. |
sHandledShaderResourceName | Name of the shader resource this array handles. It will be used to bind the array to pipelines. |
iElementSizeInBytes | Size (in bytes) of one element in the array. |
|
private |
(Re)creates the internal GPU buffer with the specified capacity.
iCapacity | Size of the array (in elements, not bytes). |
|
private |
Recreates the array to expand its capacity to support iCapacityStepSize more elements.
|
staticprivate |
Formats the specified size in bytes to the following format: "<number> KB", for example the number 1512 will be formatted to the following text: "1.47 KB".
iSizeInBytes | Size in bytes to format. |
size_t ne::DynamicCpuWriteShaderResourceArray::getCapacity | ( | ) |
Returns the maximum number of elements that could be added to the array without expanding (recreating with a bigger size) the buffer.
size_t ne::DynamicCpuWriteShaderResourceArray::getCapacityStepSize | ( | ) | const |
Returns the capacity to add to the new (expanded) array when there is no more free space left in the current array or capacity to remove from the new (shrinked) array when shrinking.
size_t ne::DynamicCpuWriteShaderResourceArray::getElementSize | ( | ) | const |
Returns size (in bytes) of one element in the array.
std::string_view ne::DynamicCpuWriteShaderResourceArray::getHandledShaderResourceName | ( | ) | const |
Returns name of the shader resource (from shader code) this array handles.
std::pair< std::recursive_mutex, DynamicCpuWriteShaderResourceArray::InternalResources > * ne::DynamicCpuWriteShaderResourceArray::getInternalResources | ( | ) |
Returns internal resources.
size_t ne::DynamicCpuWriteShaderResourceArray::getSize | ( | ) |
Returns the actual number of elements in the array (smaller or equal to getCapacity).
size_t ne::DynamicCpuWriteShaderResourceArray::getSizeInBytes | ( | ) |
Returns size in bytes that this array takes up.
|
private |
Inserts a new element in the array.
erase
function because slot destruction automatically uses internal erase
, see documentation on the returned slot object.pShaderResource | Shader resource that requires a slot in the array. If the array will resize the specified resource (if it has an active slot in the array) will be marked as "needs update" through the shader resource manager. |
|
private |
Called by slots in their destructors to notify the array that the slot can be reused.
pSlot | Slot that can be reused now. |
|
private |
Recreates the array to shrink its capacity to support iCapacityStepSize less elements.
|
private |
Called by slots to update their data.
pSlot | Slot that needs to be updated. |
pData | Data to copy to slot. |
|
private |
Used for 2 things:
|
private |
Size in bytes of one element in the array.
|
private |
Internal resources of the array.
|
private |
Used to allocate GPU buffers.
|
private |
Name of the shader resource (from shader code) this array handles.