Skip to content

Commit 47cc1cd

Browse files
committed
♻️ Refactor render api D3D12 by removing useless code
1 parent 15ac162 commit 47cc1cd

File tree

1 file changed

+0
-80
lines changed

1 file changed

+0
-80
lines changed

Plugin/PluginInteropUnityCUDA/src/RenderAPI/renderAPI_D3D12.cpp

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ class RenderAPI_D3D12 : public RenderAPI
2222
virtual void ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces);
2323

2424
private:
25-
UINT64 AlignPow2(UINT64 value);
26-
UINT64 GetAlignedSize(int width, int height, int pixelSize, int rowPitch);
27-
ID3D12Resource* GetUploadResource(UINT64 size);
2825
void CreateResources();
2926
void ReleaseResources();
3027

3128
private:
3229
IUnityGraphicsD3D12v2* s_D3D12;
33-
ID3D12Resource* s_D3D12Upload;
3430
ID3D12CommandAllocator* s_D3D12CmdAlloc;
3531
ID3D12GraphicsCommandList* s_D3D12CmdList;
3632
UINT64 s_D3D12FenceValue = 0;
@@ -49,88 +45,13 @@ const UINT kNodeMask = 0;
4945

5046
RenderAPI_D3D12::RenderAPI_D3D12()
5147
: s_D3D12(NULL)
52-
, s_D3D12Upload(NULL)
5348
, s_D3D12CmdAlloc(NULL)
5449
, s_D3D12CmdList(NULL)
5550
, s_D3D12FenceValue(0)
5651
, s_D3D12Event(NULL)
5752
{
5853
}
5954

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-
13455

13556
void RenderAPI_D3D12::CreateResources()
13657
{
@@ -153,7 +74,6 @@ void RenderAPI_D3D12::CreateResources()
15374

15475
void RenderAPI_D3D12::ReleaseResources()
15576
{
156-
SAFE_RELEASE(s_D3D12Upload);
15777
if (s_D3D12Event)
15878
CloseHandle(s_D3D12Event);
15979
SAFE_RELEASE(s_D3D12CmdList);

0 commit comments

Comments
 (0)