Skip to content

Commit c918630

Browse files
committed
fix resources initial state
1 parent 2d6924c commit c918630

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

lib/API/DX/Device.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,17 @@ class DXDevice : public offloadtest::Device {
416416
const D3D12_RESOURCE_DESC BufferDesc =
417417
CD3DX12_RESOURCE_DESC::Buffer(SizeInBytes, Flags);
418418

419+
D3D12_RESOURCE_STATES InitialState = D3D12_RESOURCE_STATE_COMMON;
420+
if (HeapType == D3D12_HEAP_TYPE_UPLOAD)
421+
InitialState = D3D12_RESOURCE_STATE_GENERIC_READ;
422+
else if (HeapType == D3D12_HEAP_TYPE_READBACK)
423+
InitialState = D3D12_RESOURCE_STATE_COPY_DEST;
424+
419425
ComPtr<ID3D12Resource> DeviceBuffer;
420426
if (auto Err = HR::toError(Device->CreateCommittedResource(
421427
&HeapProps, D3D12_HEAP_FLAG_NONE,
422-
&BufferDesc, D3D12_RESOURCE_STATE_COMMON,
423-
nullptr, IID_PPV_ARGS(&DeviceBuffer)),
428+
&BufferDesc, InitialState, nullptr,
429+
IID_PPV_ARGS(&DeviceBuffer)),
424430
"Failed to create buffer."))
425431
return Err;
426432

@@ -467,10 +473,16 @@ class DXDevice : public offloadtest::Device {
467473
ClearValuePtr = &ClearValue;
468474
}
469475

476+
D3D12_RESOURCE_STATES InitialState = D3D12_RESOURCE_STATE_COMMON;
477+
if ((Desc.Usage & TextureUsage::RenderTarget) != 0)
478+
InitialState = D3D12_RESOURCE_STATE_RENDER_TARGET;
479+
else if ((Desc.Usage & TextureUsage::DepthStencil) != 0)
480+
InitialState = D3D12_RESOURCE_STATE_DEPTH_WRITE;
481+
470482
ComPtr<ID3D12Resource> DeviceTexture;
471483
if (auto Err = HR::toError(Device->CreateCommittedResource(
472484
&HeapProps, D3D12_HEAP_FLAG_NONE, &TexDesc,
473-
D3D12_RESOURCE_STATE_COMMON, ClearValuePtr,
485+
InitialState, ClearValuePtr,
474486
IID_PPV_ARGS(&DeviceTexture)),
475487
"Failed to create texture."))
476488
return Err;

0 commit comments

Comments
 (0)