Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
gpu_buffer.h
1 #pragma once
2 
3 #include "util/string.h"
4 
5 #include "gpu_resource.h"
6 
7 namespace blowbox
8 {
17  class GpuBuffer : public GpuResource
18  {
19  public:
21  virtual ~GpuBuffer() { Destroy(); }
22 
24  virtual void Destroy();
25 
34  virtual void Create(const WString& name, UINT num_elements, UINT element_size, void* initial_data = nullptr, bool create_views = true);
35 
37  const UINT& GetUAV() const { return uav_id_; }
38 
40  const UINT& GetSRV() const { return srv_id_; }
41 
43  const D3D12_GPU_VIRTUAL_ADDRESS& GetRootCBV() const { return gpu_virtual_address_; }
44 
46  D3D12_GPU_VIRTUAL_ADDRESS GetRootCBV() { return gpu_virtual_address_; }
47 
54  D3D12_VERTEX_BUFFER_VIEW GetVertexBufferView(UINT offset, UINT size, UINT stride) const;
55 
60  D3D12_VERTEX_BUFFER_VIEW GetVertexBufferView(UINT base_vertex_index = 0) const;
61 
68  D3D12_INDEX_BUFFER_VIEW GetIndexBufferView(UINT offset, UINT size, bool is_32_bit = false) const;
69 
74  D3D12_INDEX_BUFFER_VIEW GetIndexBufferView(UINT start_index = 0) const;
75 
76  protected:
78  GpuBuffer();
79 
84  D3D12_RESOURCE_DESC DescribeBuffer();
85 
87  virtual void CreateDerivedViews() = 0;
88 
89  UINT uav_id_;
90  UINT srv_id_;
93  UINT buffer_size_;
94  D3D12_RESOURCE_FLAGS resource_flags_;
95  };
96 }
GpuBuffer()
Constructs a GpuBuffer.
Definition: gpu_buffer.cc:87
virtual void Destroy()
Destroys the GpuBuffer.
Definition: gpu_buffer.cc:11
D3D12_INDEX_BUFFER_VIEW GetIndexBufferView(UINT offset, UINT size, bool is_32_bit=false) const
Definition: gpu_buffer.cc:70
virtual void CreateDerivedViews()=0
Creates the descriptors (views) for this GpuBuffer.
Wraps ID3D12Resource objects.
Definition: gpu_resource.h:19
UINT srv_id_
The SRV descriptor for this GpuBuffer.
Definition: gpu_buffer.h:90
virtual ~GpuBuffer()
Destructs the GpuBuffer.
Definition: gpu_buffer.h:21
const D3D12_GPU_VIRTUAL_ADDRESS & GetRootCBV() const
Definition: gpu_buffer.h:43
UINT element_count_
The number of elements in this GpuBuffer.
Definition: gpu_buffer.h:91
Wraps buffer-type GpuResource's.
Definition: gpu_buffer.h:17
eastl::wstring WString
Typedef for wrapping the EASTL wstring.
Definition: string.h:20
D3D12_VERTEX_BUFFER_VIEW GetVertexBufferView(UINT offset, UINT size, UINT stride) const
Definition: gpu_buffer.cc:53
const UINT & GetUAV() const
Definition: gpu_buffer.h:37
The main Blowbox namespace.
Definition: image.cc:8
D3D12_RESOURCE_DESC DescribeBuffer()
Generates a D3D12_RESOURCE_DESC based on the buffer size and resource flags.
Definition: gpu_buffer.cc:95
UINT buffer_size_
The total buffer size of this GpuBuffer.
Definition: gpu_buffer.h:93
D3D12_RESOURCE_FLAGS resource_flags_
The resource flags set on this GpuBuffer.
Definition: gpu_buffer.h:94
virtual void Create(const WString &name, UINT num_elements, UINT element_size, void *initial_data=nullptr, bool create_views=true)
Creates actual buffer resource.
Definition: gpu_buffer.cc:16
UINT element_size_
The size of each element in this GpuBuffer.
Definition: gpu_buffer.h:92
const UINT & GetSRV() const
Definition: gpu_buffer.h:40
UINT uav_id_
The UAV descriptor for this GpuBuffer.
Definition: gpu_buffer.h:89
D3D12_GPU_VIRTUAL_ADDRESS gpu_virtual_address_
The virtual address of the ID3D12Resource in VRAM.
Definition: gpu_resource.h:92
D3D12_GPU_VIRTUAL_ADDRESS GetRootCBV()
Definition: gpu_buffer.h:46