Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
gpu_resource.h
1 #pragma once
2 
3 #include "renderer/d3d12_includes.h"
4 #include "util/string.h"
5 
6 #define D3D12_RESOURCE_STATE_INVALID ((D3D12_RESOURCE_STATES)-1)
7 
8 namespace blowbox
9 {
20  {
21  friend class CommandContext;
22  friend class MemoryProfiler;
23  friend class CompareGpuResourceByName;
24  friend class CompareGpuResourceBySize;
25  friend class CompareGpuResourceByFormat;
26  friend class CompareGpuResourceByNameReverted;
27  friend class CompareGpuResourceBySizeReverted;
28  friend class CompareGpuResourceByFormatReverted;
29  public:
31  GpuResource();
32 
38  GpuResource(ID3D12Resource* resource, D3D12_RESOURCE_STATES current_state);
39 
41  virtual ~GpuResource();
42 
48  void Associate(ID3D12Resource* resource, D3D12_RESOURCE_STATES current_state);
49 
51  void Destroy();
52 
54  ID3D12Resource* operator->() { return resource_; }
55 
57  const ID3D12Resource* operator->() const { return resource_; }
58 
60  operator ID3D12Resource*() { return resource_; }
61 
63  ID3D12Resource* Get() { return resource_; }
64 
69  const D3D12_RESOURCE_STATES& GetState() const { return usage_state_; }
70 
79  const D3D12_RESOURCE_STATES& GetTransitionState() const { return transition_state_; }
80 
81  protected:
83  void AddToMemoryProfiler();
86 
87  protected:
89  ID3D12Resource* resource_;
90  D3D12_RESOURCE_STATES usage_state_;
91  D3D12_RESOURCE_STATES transition_state_;
92  D3D12_GPU_VIRTUAL_ADDRESS gpu_virtual_address_;
93  };
94 }
const D3D12_RESOURCE_STATES & GetTransitionState() const
Returns the current transition state of the resource.
Definition: gpu_resource.h:79
Wrapper around D3D12 command lists.
Definition: command_context.h:77
void AddToMemoryProfiler()
Adds this GpuResource to the MemoryProfiler.
Definition: gpu_resource.cc:51
const D3D12_RESOURCE_STATES & GetState() const
Returns the current resource state of the resource.
Definition: gpu_resource.h:69
ID3D12Resource * operator->()
Pointer operator that returns the underlying resource.
Definition: gpu_resource.h:54
GpuResource()
Constructs an empty GpuResource.
Definition: gpu_resource.cc:10
D3D12_RESOURCE_STATES transition_state_
The current transition state of the GpuResource.
Definition: gpu_resource.h:91
virtual ~GpuResource()
Destructs a GpuResource.
Definition: gpu_resource.cc:29
ID3D12Resource * resource_
The ID3D12Resource that is being wrapped by the GpuResource.
Definition: gpu_resource.h:89
void Destroy()
Destroys the underlying GpuResource.
Definition: gpu_resource.cc:45
const ID3D12Resource * operator->() const
Pointer operator that returns the underlying resource.
Definition: gpu_resource.h:57
Wraps ID3D12Resource objects.
Definition: gpu_resource.h:19
eastl::wstring WString
Typedef for wrapping the EASTL wstring.
Definition: string.h:20
ID3D12Resource * Get()
Returns the underlying ID3D12Resource.
Definition: gpu_resource.h:63
WString name_
The name of this resource.
Definition: gpu_resource.h:88
void Associate(ID3D12Resource *resource, D3D12_RESOURCE_STATES current_state)
Associate this GpuResource with another ID3D12Resource.
Definition: gpu_resource.cc:36
The main Blowbox namespace.
Definition: image.cc:8
D3D12_RESOURCE_STATES usage_state_
The current resource state of the ID3D12Resource.
Definition: gpu_resource.h:90
Provides memory profiling statistics.
Definition: memory_profiler.h:23
D3D12_GPU_VIRTUAL_ADDRESS gpu_virtual_address_
The virtual address of the ID3D12Resource in VRAM.
Definition: gpu_resource.h:92
void RemoveFromMemoryProfiler()
Removes this GpuResource from the MemoryProfiler.
Definition: gpu_resource.cc:57