Skip to content

Commit

Permalink
Fix root signature highest version and barriers in uploaders
Browse files Browse the repository at this point in the history
  • Loading branch information
StarsX committed May 6, 2023
1 parent 4105d76 commit 1117675
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
35 changes: 34 additions & 1 deletion XUSG/Common/d3dx12_root_signature.h
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,40 @@ inline HRESULT D3DX12SerializeVersionedRootSignature(
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
case D3D_ROOT_SIGNATURE_VERSION_1_2:
#endif
return D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob);
{
HRESULT hr = S_OK;
const D3D12_ROOT_SIGNATURE_DESC1& desc_1_1 = pRootSignatureDesc->Desc_1_1;

D3D12_STATIC_SAMPLER_DESC* pStaticSamplers = nullptr;
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
if (desc_1_1.NumStaticSamplers > 0 && pRootSignatureDesc->Version == D3D_ROOT_SIGNATURE_VERSION_1_2)
{
const SIZE_T SamplersSize = sizeof(D3D12_STATIC_SAMPLER_DESC) * desc_1_1.NumStaticSamplers;
pStaticSamplers = static_cast<D3D12_STATIC_SAMPLER_DESC*>(HeapAlloc(GetProcessHeap(), 0, SamplersSize));

if (pStaticSamplers == nullptr)
{
hr = E_OUTOFMEMORY;
}
else
{
const D3D12_ROOT_SIGNATURE_DESC2& desc_1_2 = pRootSignatureDesc->Desc_1_2;
for (UINT n = 0; n < desc_1_1.NumStaticSamplers; ++n)
{
if ((desc_1_2.pStaticSamplers[n].Flags & ~D3D12_SAMPLER_FLAG_UINT_BORDER_COLOR) != 0)
{
hr = E_INVALIDARG;
break;
}
memcpy(pStaticSamplers + n, desc_1_2.pStaticSamplers + n, sizeof(D3D12_STATIC_SAMPLER_DESC));
}
}
}
#endif
const CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC pRootSignatureDesc1(desc_1_1.NumParameters, desc_1_1.pParameters, desc_1_1.NumStaticSamplers, pStaticSamplers == nullptr ? desc_1_1.pStaticSamplers : pStaticSamplers, desc_1_1.Flags);

return D3D12SerializeVersionedRootSignature(&pRootSignatureDesc1, ppBlob, ppErrorBlob);
}
}

return E_INVALIDARG;
Expand Down
2 changes: 1 addition & 1 deletion XUSG/Core/XUSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ uint8_t XUSG::CalculateMipLevels(uint64_t width, uint32_t height, uint32_t depth
return CalculateMipLevels(static_cast<uint32_t>(width), height, depth);
}

uint32_t XUSG::CalcSubresource(uint8_t mipSlice, uint8_t numMips, uint32_t arraySlice, uint32_t arraySize, uint8_t planeSlice)
uint32_t XUSG::CalculateSubresource(uint8_t mipSlice, uint8_t numMips, uint32_t arraySlice, uint32_t arraySize, uint8_t planeSlice)
{
return mipSlice + arraySlice * numMips + planeSlice * numMips * arraySize;
}
2 changes: 1 addition & 1 deletion XUSG/Core/XUSG.h
Original file line number Diff line number Diff line change
Expand Up @@ -2317,5 +2317,5 @@ namespace XUSG
XUSG_INTERFACE uint8_t Log2(uint32_t value);
XUSG_INTERFACE uint8_t CalculateMipLevels(uint32_t width, uint32_t height, uint32_t depth = 1);
XUSG_INTERFACE uint8_t CalculateMipLevels(uint64_t width, uint32_t height, uint32_t depth = 1);
XUSG_INTERFACE uint32_t CalcSubresource(uint8_t mipSlice, uint8_t numMips, uint32_t arraySlice, uint32_t arraySize, uint8_t planeSlice);
XUSG_INTERFACE uint32_t CalculateSubresource(uint8_t mipSlice, uint8_t numMips, uint32_t arraySlice, uint32_t arraySize, uint8_t planeSlice);
}
12 changes: 8 additions & 4 deletions XUSG/Core/XUSGPipelineLayout_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,15 @@ D3D_ROOT_SIGNATURE_VERSION PipelineLayoutLib_DX12::GetRootSignatureHighestVersio
{
D3D12_FEATURE_DATA_ROOT_SIGNATURE featureData = {};

if (FAILED(m_device->CheckFeatureSupport(D3D12_FEATURE_ROOT_SIGNATURE,
&featureData, sizeof(featureData))) || !featureData.HighestVersion)
return D3D_ROOT_SIGNATURE_VERSION_1_0;
// This is the highest version that XUSG supports. If CheckFeatureSupport succeeds, the HighestVersion returned will not be greater than this.
featureData.HighestVersion = D3D_ROOT_SIGNATURE_VERSION_1_2;
if (FAILED(m_device->CheckFeatureSupport(D3D12_FEATURE_ROOT_SIGNATURE, &featureData, sizeof(featureData))))
{
featureData.HighestVersion = D3D_ROOT_SIGNATURE_VERSION_1_1;
if (FAILED(m_device->CheckFeatureSupport(D3D12_FEATURE_ROOT_SIGNATURE, &featureData, sizeof(featureData))))
featureData.HighestVersion = D3D_ROOT_SIGNATURE_VERSION_1_0;
}

// This is the highest version the sample supports. If CheckFeatureSupport succeeds, the HighestVersion returned will not be greater than this.
return featureData.HighestVersion;
}

Expand Down
11 changes: 4 additions & 7 deletions XUSG/Core/XUSGResource_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,8 @@ bool ConstantBuffer_DX12::Upload(CommandList* pCommandList, Resource* pUploader,
const auto pGraphicsCommandList = static_cast<ID3D12GraphicsCommandList*>(pCommandList->GetHandle());
pGraphicsCommandList->CopyBufferRegion(m_resource.get(), offset, uploaderResource.get(), 0, size);

if (dstState != ResourceState::COMMON)
{
const ResourceBarrier barrier = { this, ResourceState::COPY_DEST, dstState, XUSG_BARRIER_ALL_SUBRESOURCES };
pCommandList->Barrier(1, &barrier);
}
const ResourceBarrier barrier = { this, ResourceState::COPY_DEST, dstState, XUSG_BARRIER_ALL_SUBRESOURCES };
pCommandList->Barrier(1, &barrier);

return true;
}
Expand Down Expand Up @@ -503,7 +500,7 @@ bool Texture_DX12::Upload(CommandList* pCommandList, Resource* pUploader,
for (auto i = 0u; i < numSubresources; ++i)
numBarriers = SetBarrier(barriers.data(), dstState, numBarriers,
firstSubresource + i, BarrierFlag::NONE, threadIdx);
if (dstState != ResourceState::COMMON) pCommandList->Barrier(numBarriers, barriers.data());
pCommandList->Barrier(numBarriers, barriers.data());

return true;
}
Expand Down Expand Up @@ -1829,7 +1826,7 @@ bool Buffer_DX12::Upload(CommandList* pCommandList, Resource* pUploader, const v
pGraphicsCommandList->CopyBufferRegion(m_resource.get(), offset, uploaderResource.get(), 0, size);

numBarriers = SetBarrier(&barrier, dstState, 0, XUSG_BARRIER_ALL_SUBRESOURCES, BarrierFlag::NONE, threadIdx);
if (dstState != ResourceState::COMMON) pCommandList->Barrier(numBarriers, &barrier);
pCommandList->Barrier(numBarriers, &barrier);

return true;
}
Expand Down

0 comments on commit 1117675

Please sign in to comment.