Class ResourceLoader#

Nested Relationships#

Nested Types#

Class Documentation#

class ResourceLoader#

Resource loader. Does the heavy lifting of sending data between the CPU and GPU.

Public Functions

explicit ResourceLoader(const RendererAPI::ResourceLoaderDesc &desc = {8ull << 20u, 2u})#

Instantiate the resource loader.

Parameters:

descOptional settings.

~ResourceLoader() = default#

Destructor.

consteval ResourceLoader(const ResourceLoader&) noexcept = delete#

Copy constructor.

consteval ResourceLoader &operator=(const ResourceLoader&) noexcept = delete#

Copy assignment operator.

consteval ResourceLoader(ResourceLoader&&) noexcept = delete#

Move constructor.

consteval ResourceLoader &operator=(ResourceLoader&&) noexcept = delete#

Move assignment operator.

void AddResource(RendererAPI::BufferLoadDesc &desc, SyncToken *token)#

Add a resource to GPU. If called with a data size larger than the ResourceLoader’s staging buffer, the ResourceLoader will perform multiple copies/flushes rather than failing the copy.

Parameters:
  • desc – Description of buffer resource to add.

  • token – If token is nullptr, the resource will be available when AllResourceLoadsCompleted() returns true. If token is not nullptr, the resource will be available after IsTokenCompleted(token) returns true.

void AddResource(RendererAPI::TextureLoadDesc &textureDesc, SyncToken *token)#

Add a resource to GPU.

Parameters:
  • textureDesc – Description of texture resource to add.

  • token – If token is nullptr, the resource will be available when AllResourceLoadsCompleted() returns true. If token is not nullptr, the resource will be available after IsTokenCompleted(token) returns true.

void EndUpdateResource(RendererAPI::BufferUpdateDesc &desc, SyncToken *token)#

End updating a buffer resource.

Parameters:
  • desc – Description of updated buffer resource.

  • token – If token is nullptr, the resource will be available when AllResourceLoadsCompleted() returns true. If token is not nullptr, the resource will be available after IsTokenCompleted(token) returns true.

void EndUpdateResource(RendererAPI::TextureUpdateDesc &desc, SyncToken *token)#

End updating a texture resource.

Parameters:
  • desc – Description of updated texture resource.

  • token – If token is nullptr, the resource will be available when AllResourceLoadsCompleted() returns true. If token is not nullptr, the resource will be available after IsTokenCompleted(token) returns true.

void CopyResource(const RendererAPI::TextureCopyDesc &textureDesc, SyncToken *token)#

Copy data from GPU to the CPU. For optimal use, the amount of data to transfer should be minimized as much as possible and applications should provide additional graphics/compute work that the GPU can execute alongside the copy.

Parameters:
  • textureDesc – Description of the texture copy.

  • token – If token is nullptr, the resource will be available when AllResourceLoadsCompleted() returns true. If token is not nullptr, the resource will be available after IsTokenCompleted(token) return true.

bool AllResourceLoadsCompleted() const noexcept#

Retrieve whether all submitted resource loads and updates have been completed.

Returns:

True if all loads and updates have finished, false otherwise.

void WaitForAllResourceLoads()#

Block the calling thread until AllResourceLoadsCompleted() returns true.

Note

If more resource loads or updates are submitted from a different thread while the calling thread is blocked, those loads or updates are not guaranteed to have completed when this function returns.

SyncToken GetLastTokenCompleted() const noexcept#

Retrieve the last sync token which has finished loading or updating.

Returns:

Last value for which IsTokenCompleted(token) is guaranteed to return true.

bool IsTokenCompleted(const SyncToken &token) const#

Retrieve whether a sync token has finished loading or updating.

Parameters:

token – Token to check.

Returns:

True if the token has finished, false otherwise.

void WaitForToken(const SyncToken &token)#

Block the calling thread until IsTokenCompleted(token) for the provided token returns true.

Parameters:

token – Token to wait for completion.

SyncToken GetLastTokenSubmitted() const noexcept#

Retrieve the last sync token which has been submitted for copying.

Returns:

Last value for which IsTokenSubmitted(token) is guaranteed to return true.

bool IsTokenSubmitted(const SyncToken &token) const#

Retrieve whether a sync token has been submitted for copying.

Parameters:

token – Token to check.

Returns:

True if the token has been submitted for copying, false otherwise.

void WaitForTokenSubmitted(const SyncToken &token)#

Block the calling thread until IsTokenSubmitted(token) for the provided token returns true.

Parameters:

token – Token to wait for submission.

TRAP::Ref<Semaphore> GetLastSemaphoreCompleted()#

Retrieve the semaphore for the last copy operation that has been submitted.

Note

This can be nullptr if no operations have been executed.

Returns:

Semaphore for the last copy operation that has been submitted.

Public Static Functions

static void BeginUpdateResource(RendererAPI::BufferUpdateDesc &desc)#

Start updating a buffer resource.

Parameters:

desc – Description of buffer resource to update.

static void BeginUpdateResource(RendererAPI::TextureUpdateDesc &desc)#

Start updating a texture resource.

Parameters:

desc – Description of texture resource to update.