@@ -22,15 +22,11 @@ class RenderAPI_D3D12 : public RenderAPI
22
22
virtual void ProcessDeviceEvent (UnityGfxDeviceEventType type, IUnityInterfaces* interfaces);
23
23
24
24
private:
25
- UINT64 AlignPow2 (UINT64 value);
26
- UINT64 GetAlignedSize (int width, int height, int pixelSize, int rowPitch);
27
- ID3D12Resource* GetUploadResource (UINT64 size);
28
25
void CreateResources ();
29
26
void ReleaseResources ();
30
27
31
28
private:
32
29
IUnityGraphicsD3D12v2* s_D3D12;
33
- ID3D12Resource* s_D3D12Upload;
34
30
ID3D12CommandAllocator* s_D3D12CmdAlloc;
35
31
ID3D12GraphicsCommandList* s_D3D12CmdList;
36
32
UINT64 s_D3D12FenceValue = 0 ;
@@ -49,88 +45,13 @@ const UINT kNodeMask = 0;
49
45
50
46
RenderAPI_D3D12::RenderAPI_D3D12 ()
51
47
: s_D3D12(NULL )
52
- , s_D3D12Upload(NULL )
53
48
, s_D3D12CmdAlloc(NULL )
54
49
, s_D3D12CmdList(NULL )
55
50
, s_D3D12FenceValue(0 )
56
51
, s_D3D12Event(NULL )
57
52
{
58
53
}
59
54
60
- UINT64 RenderAPI_D3D12::AlignPow2 (UINT64 value)
61
- {
62
- UINT64 aligned = pow (2 , (int )log2 (value));
63
- return aligned >= value ? aligned : aligned * 2 ;
64
- }
65
-
66
- UINT64 RenderAPI_D3D12::GetAlignedSize ( int width, int height, int pixelSize, int rowPitch)
67
- {
68
- UINT64 size = width * height * pixelSize;
69
-
70
- size = AlignPow2 (size);
71
-
72
- if (size < D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT)
73
- {
74
- return D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT;
75
- }
76
- else if (width * pixelSize < rowPitch)
77
- {
78
- return rowPitch * height;
79
- }
80
- else
81
- {
82
- return size;
83
- }
84
- }
85
-
86
- ID3D12Resource* RenderAPI_D3D12::GetUploadResource (UINT64 size)
87
- {
88
- if (s_D3D12Upload)
89
- {
90
- D3D12_RESOURCE_DESC desc = s_D3D12Upload->GetDesc ();
91
- if (desc.Width == size)
92
- return s_D3D12Upload;
93
- else
94
- s_D3D12Upload->Release ();
95
- }
96
-
97
- // Texture upload buffer
98
- D3D12_HEAP_PROPERTIES heapProps = {};
99
- heapProps.Type = D3D12_HEAP_TYPE_UPLOAD;
100
- heapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
101
- heapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
102
- heapProps.CreationNodeMask = kNodeMask ;
103
- heapProps.VisibleNodeMask = kNodeMask ;
104
-
105
- D3D12_RESOURCE_DESC heapDesc = {};
106
- heapDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
107
- heapDesc.Alignment = 0 ;
108
- heapDesc.Width = size;
109
- heapDesc.Height = 1 ;
110
- heapDesc.DepthOrArraySize = 1 ;
111
- heapDesc.MipLevels = 1 ;
112
- heapDesc.Format = DXGI_FORMAT_UNKNOWN;
113
- heapDesc.SampleDesc .Count = 1 ;
114
- heapDesc.SampleDesc .Quality = 0 ;
115
- heapDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
116
- heapDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
117
-
118
- ID3D12Device* device = s_D3D12->GetDevice ();
119
- HRESULT hr = device->CreateCommittedResource (
120
- &heapProps,
121
- D3D12_HEAP_FLAG_NONE,
122
- &heapDesc,
123
- D3D12_RESOURCE_STATE_GENERIC_READ,
124
- nullptr ,
125
- IID_PPV_ARGS (&s_D3D12Upload));
126
- if (FAILED (hr))
127
- {
128
- OutputDebugStringA (" Failed to CreateCommittedResource.\n " );
129
- }
130
-
131
- return s_D3D12Upload;
132
- }
133
-
134
55
135
56
void RenderAPI_D3D12::CreateResources ()
136
57
{
@@ -153,7 +74,6 @@ void RenderAPI_D3D12::CreateResources()
153
74
154
75
void RenderAPI_D3D12::ReleaseResources ()
155
76
{
156
- SAFE_RELEASE (s_D3D12Upload);
157
77
if (s_D3D12Event)
158
78
CloseHandle (s_D3D12Event);
159
79
SAFE_RELEASE (s_D3D12CmdList);
0 commit comments