Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
upload_buffer.h
1 #pragma once
2 
3 #include "renderer/d3d12_includes.h"
4 #include "renderer/device.h"
5 #include "renderer/buffers/gpu_buffer.h"
6 #include "renderer/buffers/byte_address_buffer.h"
7 
8 #include "util/string.h"
9 
10 namespace blowbox
11 {
19  class UploadBuffer : public GpuBuffer
20  {
21  public:
29  void Create(const WString& name, UINT num_elements, UINT element_size, void* initial_data = nullptr);
30 
32  virtual void CreateDerivedViews() override;
33 
35  virtual void Destroy() override;
36 
37  void Map();
38  void Unmap();
39 
45  void InsertDataByElement(UINT element_id, void* data);
46 
52  void InsertDataByElement(UINT element_id, const void* data);
53 
58  void ClearDataByElement(UINT element_id);
59 
65  void InsertDataByBuffer(void* data, UINT size_of_data_in_bytes);
66 
68  void ClearDataByBuffer();
69 
74  D3D12_GPU_VIRTUAL_ADDRESS GetAddressByElement(UINT element_id);
75 
77  BYTE* GetMappedData();
78  private:
79  bool is_mapped_ = false;
80  BYTE* mapped_data_ = nullptr;
81  };
82 }
bool is_mapped_
Is the buffer currently mapped to CPU memory?
Definition: upload_buffer.h:79
BYTE * GetMappedData()
Definition: upload_buffer.cc:130
void ClearDataByBuffer()
Clear all data that resides in the entire buffer and set it to 0x0.
Definition: upload_buffer.cc:115
void Unmap()
"Unmaps" the resource from CPU memory to GPU memory, making it non-writable & non-readable ...
Definition: upload_buffer.cc:81
void 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 != ...
Definition: upload_buffer.cc:109
virtual void CreateDerivedViews() override
Creates any views that this buffer type may have.
Definition: upload_buffer.cc:47
Wraps buffer-type GpuResource's.
Definition: gpu_buffer.h:17
eastl::wstring WString
Typedef for wrapping the EASTL wstring.
Definition: string.h:20
The main Blowbox namespace.
Definition: image.cc:8
void Create(const WString &name, UINT num_elements, UINT element_size, void *initial_data=nullptr)
Creates the upload buffer.
Definition: upload_buffer.cc:10
Wraps upload buffer types, which allow you to upload data to the GPU.
Definition: upload_buffer.h:19
void ClearDataByElement(UINT element_id)
Clear all data that resides in an element and set it to 0x0.
Definition: upload_buffer.cc:103
void Map()
"Maps" the resource from GPU memory to CPU memory, making it writable & readable (although reading is...
Definition: upload_buffer.cc:71
D3D12_GPU_VIRTUAL_ADDRESS GetAddressByElement(UINT element_id)
Query for the GPU memory address of an element in the UploadBuffer.
Definition: upload_buffer.cc:121
virtual void Destroy() override
Destroys this resource and clears it from GPU memory.
Definition: upload_buffer.cc:64
void 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 C...
Definition: upload_buffer.cc:91
BYTE * mapped_data_
The data that is mapped to CPU memory - can be freely written to and read from when it is mapped...
Definition: upload_buffer.h:80