Foundation
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Foundation::Rendering::UploadContext Class Reference

Deferred upload context for transferring data to GPU resources. More...

#include <UploadContext.hpp>

Public Member Functions

 UploadContext (RHIDevice *device, Allocator *allocator, size_t stagingBudget=16_MB)
 
void Upload (RHIBuffer *dst, Span< const char > data, size_t dstOffset=0, size_t alignment=4, RHIResourceAccess dst_access=RHIResourceAccessBits::ShaderRead, RHIPipelineStage dst_stage=RHIPipelineStageBits::AllGraphics)
 
void Upload (RHITexture *dst, Span< const char > data, RHITextureSubresourceRange range, RHICommandList::CopyImageRegion region, RHIResourceAccess dst_access=RHIResourceAccessBits::ShaderRead, RHIPipelineStage dst_stage=RHIPipelineStageBits::AllGraphics, RHITextureLayout dst_layout=RHITextureLayout::ShaderReadOnly)
 
void Upload (RHITexture *dst, Span< const char > data, uint32_t mipLevel=0, uint32_t arrayLayer=0, RHITextureAspectFlag aspect=RHITextureAspectFlagBits::Color, RHIResourceAccess dst_access=RHIResourceAccessBits::ShaderRead, RHIPipelineStage dst_stage=RHIPipelineStageBits::AllGraphics, RHITextureLayout dst_layout=RHITextureLayout::ShaderReadOnly)
 
void SubmitAndWait ()
 
 ~UploadContext ()
 

Private Attributes

RHIDevicemDevice
 
AllocatormAllocator
 
RHIDeviceQueuemQueue
 
RHIDeviceScopedObjectHandle< RHICommandPoolmCommandPool
 
Vector< RHICommandPoolScopedHandle< RHICommandList > > mCommandLists
 
RHIDeviceScopedObjectHandle< RHIDeviceFencemFence
 
StagingBuffer mStagingBuffer
 
Async::Mutex mMutex
 

Detailed Description

Deferred upload context for transferring data to GPU resources.

Note
This is thread-safe, and can be used from multiple threads.
This is intended for one-off uploads, and not for streaming data. For streaming data, consider using a StagingBuffer for data that might be modified often e.g. every frame.
All uploads are submitted to the Graphics Queue, and are only executed when Submit() is called.
This is RAII - and is encouraged to be used as such. The destructor will flush all pending upload and wait for all uploads to complete.
Parameters
deviceThe RHI device to use for uploads.
allocatorThe allocator to use for internal allocations.
stagingBudgetThe size of the internal staging buffer to use for uploads.

Constructor & Destructor Documentation

◆ UploadContext()

UploadContext::UploadContext ( RHIDevice device,
Allocator allocator,
size_t  stagingBudget = 16_MB 
)

◆ ~UploadContext()

UploadContext::~UploadContext ( )

Member Function Documentation

◆ SubmitAndWait()

void UploadContext::SubmitAndWait ( )

◆ Upload() [1/3]

void UploadContext::Upload ( RHIBuffer dst,
Span< const char data,
size_t  dstOffset = 0,
size_t  alignment = 4,
RHIResourceAccess  dst_access = RHIResourceAccessBits::ShaderRead,
RHIPipelineStage  dst_stage = RHIPipelineStageBits::AllGraphics 
)

◆ Upload() [2/3]

void UploadContext::Upload ( RHITexture dst,
Span< const char data,
RHITextureSubresourceRange  range,
RHICommandList::CopyImageRegion  region,
RHIResourceAccess  dst_access = RHIResourceAccessBits::ShaderRead,
RHIPipelineStage  dst_stage = RHIPipelineStageBits::AllGraphics,
RHITextureLayout  dst_layout = RHITextureLayout::ShaderReadOnly 
)

◆ Upload() [3/3]

void UploadContext::Upload ( RHITexture dst,
Span< const char data,
uint32_t  mipLevel = 0,
uint32_t  arrayLayer = 0,
RHITextureAspectFlag  aspect = RHITextureAspectFlagBits::Color,
RHIResourceAccess  dst_access = RHIResourceAccessBits::ShaderRead,
RHIPipelineStage  dst_stage = RHIPipelineStageBits::AllGraphics,
RHITextureLayout  dst_layout = RHITextureLayout::ShaderReadOnly 
)

Member Data Documentation

◆ mAllocator

Allocator* Foundation::Rendering::UploadContext::mAllocator
private

◆ mCommandLists

Vector<RHICommandPoolScopedHandle<RHICommandList> > Foundation::Rendering::UploadContext::mCommandLists
private

◆ mCommandPool

RHIDeviceScopedObjectHandle<RHICommandPool> Foundation::Rendering::UploadContext::mCommandPool
private

◆ mDevice

RHIDevice* Foundation::Rendering::UploadContext::mDevice
private

◆ mFence

RHIDeviceScopedObjectHandle<RHIDeviceFence> Foundation::Rendering::UploadContext::mFence
private

◆ mMutex

Async::Mutex Foundation::Rendering::UploadContext::mMutex
private

◆ mQueue

RHIDeviceQueue* Foundation::Rendering::UploadContext::mQueue
private

◆ mStagingBuffer

StagingBuffer Foundation::Rendering::UploadContext::mStagingBuffer
private

The documentation for this class was generated from the following files: