Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
|
#include <upload_buffer.h>
Public Member Functions | |
void | Create (const WString &name, UINT num_elements, UINT element_size, void *initial_data=nullptr) |
virtual void | CreateDerivedViews () override |
virtual void | Destroy () override |
void | Map () |
void | Unmap () |
void | InsertDataByElement (UINT element_id, void *data) |
void | InsertDataByElement (UINT element_id, const void *data) |
void | ClearDataByElement (UINT element_id) |
void | InsertDataByBuffer (void *data, UINT size_of_data_in_bytes) |
void | ClearDataByBuffer () |
D3D12_GPU_VIRTUAL_ADDRESS | GetAddressByElement (UINT element_id) |
BYTE * | GetMappedData () |
Public Member Functions inherited from blowbox::GpuBuffer | |
virtual | ~GpuBuffer () |
virtual void | Create (const WString &name, UINT num_elements, UINT element_size, void *initial_data=nullptr, bool create_views=true) |
const UINT & | GetUAV () const |
const UINT & | GetSRV () const |
const D3D12_GPU_VIRTUAL_ADDRESS & | GetRootCBV () const |
D3D12_GPU_VIRTUAL_ADDRESS | GetRootCBV () |
D3D12_VERTEX_BUFFER_VIEW | GetVertexBufferView (UINT offset, UINT size, UINT stride) const |
D3D12_VERTEX_BUFFER_VIEW | GetVertexBufferView (UINT base_vertex_index=0) const |
D3D12_INDEX_BUFFER_VIEW | GetIndexBufferView (UINT offset, UINT size, bool is_32_bit=false) const |
D3D12_INDEX_BUFFER_VIEW | GetIndexBufferView (UINT start_index=0) const |
Public Member Functions inherited from blowbox::GpuResource | |
GpuResource () | |
GpuResource (ID3D12Resource *resource, D3D12_RESOURCE_STATES current_state) | |
virtual | ~GpuResource () |
void | Associate (ID3D12Resource *resource, D3D12_RESOURCE_STATES current_state) |
void | Destroy () |
ID3D12Resource * | operator-> () |
const ID3D12Resource * | operator-> () const |
operator ID3D12Resource * () | |
ID3D12Resource * | Get () |
const D3D12_RESOURCE_STATES & | GetState () const |
const D3D12_RESOURCE_STATES & | GetTransitionState () const |
Private Attributes | |
bool | is_mapped_ = false |
BYTE * | mapped_data_ = nullptr |
Additional Inherited Members | |
Protected Member Functions inherited from blowbox::GpuBuffer | |
GpuBuffer () | |
D3D12_RESOURCE_DESC | DescribeBuffer () |
Protected Member Functions inherited from blowbox::GpuResource | |
void | AddToMemoryProfiler () |
void | RemoveFromMemoryProfiler () |
Protected Attributes inherited from blowbox::GpuBuffer | |
UINT | uav_id_ |
UINT | srv_id_ |
UINT | element_count_ |
UINT | element_size_ |
UINT | buffer_size_ |
D3D12_RESOURCE_FLAGS | resource_flags_ |
Protected Attributes inherited from blowbox::GpuResource | |
WString | name_ |
ID3D12Resource * | resource_ |
D3D12_RESOURCE_STATES | usage_state_ |
D3D12_RESOURCE_STATES | transition_state_ |
D3D12_GPU_VIRTUAL_ADDRESS | gpu_virtual_address_ |
Wraps upload buffer types, which allow you to upload data to the GPU.
The UploadBuffer enables you to create a buffer that exists in an upload heap, allowing you to upload data to the GPU by having the resource mapped to CPU memory. You can do this by using the various insert methods provided.
void blowbox::UploadBuffer::ClearDataByBuffer | ( | ) |
Clear all data that resides in the entire buffer and set it to 0x0.
void blowbox::UploadBuffer::ClearDataByElement | ( | UINT | element_id | ) |
Clear all data that resides in an element and set it to 0x0.
[in] | element_id | The index (id) of the element you want to clear. |
void blowbox::UploadBuffer::Create | ( | const WString & | name, |
UINT | num_elements, | ||
UINT | element_size, | ||
void * | initial_data = nullptr |
||
) |
Creates the upload buffer.
[in] | name | The name of the buffer you're creating. This will be used internally to easily identify the buffer. |
[in] | num_elements | The number of elements that should be able to fit in this buffer. |
[in] | element_size | The size of each elements that should be able to fit in this buffer. |
[in] | initial_data | (optional) The data that this buffer should be initialized with. |
|
overridevirtual |
Creates any views that this buffer type may have.
Implements blowbox::GpuBuffer.
|
overridevirtual |
Destroys this resource and clears it from GPU memory.
Reimplemented from blowbox::GpuBuffer.
D3D12_GPU_VIRTUAL_ADDRESS blowbox::UploadBuffer::GetAddressByElement | ( | UINT | element_id | ) |
Query for the GPU memory address of an element in the UploadBuffer.
[in] | element_id | The index (id) of the element you want the address of |
BYTE * blowbox::UploadBuffer::GetMappedData | ( | ) |
void blowbox::UploadBuffer::InsertDataByBuffer | ( | void * | data, |
UINT | size_of_data_in_bytes | ||
) |
Set ALL data in the UploadBuffer to what you pass in. Throws an error when (size_of_data_in_bytes != element_size * element_count)
[in] | data | The data you want to set in the entire buffer. |
[in] | size_of_data_in_bytes | The size of the data you are writing into the buffer. |
void blowbox::UploadBuffer::InsertDataByElement | ( | UINT | element_id, |
void * | data | ||
) |
Insert data into the buffer by a certain element index. Make sure the resource has been Map()-ed to CPU memory (by default, all UploadBuffers are mapped).
[in] | element_id | The index (id) of the element you want to write to. |
[in] | data | The data you want to write into the element. |
void blowbox::UploadBuffer::InsertDataByElement | ( | UINT | element_id, |
const void * | data | ||
) |
Insert data into the buffer by a certain element index. Make sure the resource has been Map()-ed to CPU memory (by default, all UploadBuffers are mapped).
[in] | element_id | The index (id) of the element you want to write to. |
[in] | data | The data you want to write into the element. |
void blowbox::UploadBuffer::Map | ( | ) |
"Maps" the resource from GPU memory to CPU memory, making it writable & readable (although reading is strongly advised against!)
void blowbox::UploadBuffer::Unmap | ( | ) |
"Unmaps" the resource from CPU memory to GPU memory, making it non-writable & non-readable
|
private |
Is the buffer currently mapped to CPU memory?
|
private |
The data that is mapped to CPU memory - can be freely written to and read from when it is mapped.