MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / OnInit

Method OnInit

Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.cpp:48–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48bool GPUTextureDX12::OnInit()
49{
50 ID3D12Resource* resource;
51
52 // Cache formats
53 const PixelFormat format = Format();
54 const PixelFormat typelessFormat = PixelFormatExtensions::MakeTypeless(format);
55 const DXGI_FORMAT dxgiFormat = RenderToolsDX::ToDxgiFormat(typelessFormat);
56 _dxgiFormatDSV = RenderToolsDX::ToDxgiFormat(PixelFormatExtensions::FindDepthStencilFormat(format));
57 _dxgiFormatSRV = RenderToolsDX::ToDxgiFormat(PixelFormatExtensions::FindShaderResourceFormat(format, _sRGB));
58 _dxgiFormatRTV = _dxgiFormatSRV;
59 _dxgiFormatUAV = RenderToolsDX::ToDxgiFormat(PixelFormatExtensions::FindUnorderedAccessFormat(format));
60
61 // Cache properties
62 auto device = _device->GetDevice();
63 bool useSRV = IsShaderResource();
64 bool useDSV = IsDepthStencil();
65 bool useRTV = IsRenderTarget();
66 bool useUAV = IsUnorderedAccess();
67 int32 depthOrArraySize = IsVolume() ? Depth() : ArraySize();
68
69 if (IsStaging())
70 {
71 // Initialize as a buffer
72 const int32 totalSize = ComputeBufferTotalSize(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT);
73 D3D12_HEAP_PROPERTIES heapProperties;
74 heapProperties.Type = D3D12_HEAP_TYPE_READBACK;
75 heapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
76 heapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
77 heapProperties.CreationNodeMask = 1;
78 heapProperties.VisibleNodeMask = 1;
79 D3D12_RESOURCE_DESC resourceDesc;
80 resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
81 resourceDesc.Alignment = 0;
82 resourceDesc.Width = totalSize;
83 resourceDesc.Height = 1;
84 resourceDesc.DepthOrArraySize = 1;
85 resourceDesc.MipLevels = 1;
86 resourceDesc.Format = DXGI_FORMAT_UNKNOWN;
87 resourceDesc.SampleDesc.Count = 1;
88 resourceDesc.SampleDesc.Quality = 0;
89 resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
90 resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
91 auto result = device->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&resource));
92 LOG_DIRECTX_RESULT_WITH_RETURN(result, true);
93 initResource(resource, D3D12_RESOURCE_STATE_COPY_DEST, 1);
94 DX_SET_DEBUG_NAME(_resource, GetName());
95 _memoryUsage = totalSize;
96 return false;
97 }
98
99 D3D12_RESOURCE_STATES initialState = D3D12_RESOURCE_STATE_COMMON;
100
101 // Create texture description
102 D3D12_RESOURCE_DESC resourceDesc;
103 resourceDesc.MipLevels = _desc.MipLevels;
104 resourceDesc.Format = dxgiFormat;
105 resourceDesc.Width = _desc.Width;

Callers

nothing calls this directly

Calls 11

ArraySizeFunction · 0.85
IsRegularTextureFunction · 0.85
FormatFunction · 0.50
IsShaderResourceFunction · 0.50
IsDepthStencilFunction · 0.50
IsUnorderedAccessFunction · 0.50
IsVolumeFunction · 0.50
DepthFunction · 0.50
IsMultiSampleFunction · 0.50
GetDeviceMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected