This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
/
pch.cpp
150 lines (136 loc) · 5.33 KB
/
pch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//--------------------------------------------------------------------------------------
// pch.cpp
//
// Include the standard header and generate the precompiled header.
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
namespace ATG
{
void CreateColorTextureAndViews(
ID3D12Device* device,
UINT width,
UINT height,
DXGI_FORMAT format,
ID3D12Resource** resource,
D3D12_CPU_DESCRIPTOR_HANDLE hRTV,
D3D12_CPU_DESCRIPTOR_HANDLE hSRV,
D3D12_CLEAR_VALUE* pOptimizedClearValue,
D3D12_HEAP_TYPE heapType)
{
D3D12_RESOURCE_DESC descTex = CD3DX12_RESOURCE_DESC::Tex2D(format, width, height, 1, 1);
D3D12_HEAP_FLAGS heapMiscFlag = D3D12_HEAP_FLAG_NONE;
D3D12_RESOURCE_STATES usage = D3D12_RESOURCE_STATE_COMMON;
switch (heapType)
{
case D3D12_HEAP_TYPE_DEFAULT:
descTex.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
break;
case D3D12_HEAP_TYPE_UPLOAD:
usage = D3D12_RESOURCE_STATE_GENERIC_READ;
break;
case D3D12_HEAP_TYPE_READBACK:
{
usage = D3D12_RESOURCE_STATE_COPY_DEST;
D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layout;
UINT NumRows;
UINT64 RowSize;
UINT64 TotalBytes;
device->GetCopyableFootprints(&descTex, 0, 1, 0, &Layout, &NumRows, &RowSize, &TotalBytes);
descTex = CD3DX12_RESOURCE_DESC::Buffer(TotalBytes);
}
break;
}
const D3D12_HEAP_PROPERTIES heapProperties = CD3DX12_HEAP_PROPERTIES(heapType);
DX::ThrowIfFailed(device->CreateCommittedResource(
&heapProperties,
heapMiscFlag,
&descTex,
usage,
pOptimizedClearValue,
IID_GRAPHICS_PPV_ARGS(resource)));
if (hRTV.ptr != 0)
{
D3D12_RENDER_TARGET_VIEW_DESC descRTV = {};
descRTV.Format = format;
descRTV.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
device->CreateRenderTargetView(*resource, &descRTV, hRTV);
}
if (hSRV.ptr != 0)
{
D3D12_SHADER_RESOURCE_VIEW_DESC descSRV = {};
descSRV.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
descSRV.Format = format;
descSRV.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
descSRV.Texture2D.MipLevels = 1;
device->CreateShaderResourceView(*resource, &descSRV, hSRV);
}
}
void CreateDepthTextureAndViews(
ID3D12Device* device,
UINT width,
UINT height,
DXGI_FORMAT format,
ID3D12Resource** resource,
D3D12_CPU_DESCRIPTOR_HANDLE hDSV,
D3D12_CPU_DESCRIPTOR_HANDLE hSRV,
D3D12_CLEAR_VALUE* pOptimizedClearValue,
D3D12_HEAP_TYPE heapType)
{
DXGI_FORMAT resFormat;
resFormat = (format == DXGI_FORMAT_D32_FLOAT) ? DXGI_FORMAT_R32_TYPELESS : format;
resFormat = (format == DXGI_FORMAT_D16_UNORM) ? DXGI_FORMAT_R16_TYPELESS : resFormat;
DXGI_FORMAT srvFormat;
srvFormat = (format == DXGI_FORMAT_D32_FLOAT) ? DXGI_FORMAT_R32_FLOAT : format;
srvFormat = (format == DXGI_FORMAT_D16_UNORM) ? DXGI_FORMAT_R16_UNORM : srvFormat;
D3D12_RESOURCE_DESC descTex = CD3DX12_RESOURCE_DESC::Tex2D(resFormat, width, height, 1, 1);
D3D12_HEAP_FLAGS heapMiscFlag = D3D12_HEAP_FLAG_NONE;
D3D12_RESOURCE_STATES usage = D3D12_RESOURCE_STATE_COMMON;
switch (heapType)
{
case D3D12_HEAP_TYPE_DEFAULT:
descTex.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
break;
case D3D12_HEAP_TYPE_UPLOAD:
usage = D3D12_RESOURCE_STATE_GENERIC_READ;
break;
case D3D12_HEAP_TYPE_READBACK:
{
usage = D3D12_RESOURCE_STATE_COPY_DEST;
D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layout;
UINT NumRows;
UINT64 RowSize;
UINT64 TotalBytes;
device->GetCopyableFootprints(&descTex, 0, 1, 0, &Layout, &NumRows, &RowSize, &TotalBytes);
descTex = CD3DX12_RESOURCE_DESC::Buffer(TotalBytes);
}
break;
}
const D3D12_HEAP_PROPERTIES heapProperties = CD3DX12_HEAP_PROPERTIES(heapType);
DX::ThrowIfFailed(device->CreateCommittedResource(
&heapProperties,
heapMiscFlag,
&descTex,
usage,
pOptimizedClearValue,
IID_GRAPHICS_PPV_ARGS(resource)));
if (hDSV.ptr != 0)
{
D3D12_DEPTH_STENCIL_VIEW_DESC descRTV = {};
descRTV.Format = format;
descRTV.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
device->CreateDepthStencilView(*resource, &descRTV, hDSV);
}
if (hSRV.ptr != 0)
{
D3D12_SHADER_RESOURCE_VIEW_DESC descSRV = {};
descSRV.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
descSRV.Format = srvFormat;
descSRV.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
descSRV.Texture2D.MipLevels = 1;
device->CreateShaderResourceView(*resource, &descSRV, hSRV);
}
}
}