Skip to content

Commit

Permalink
Fix pipeline layout creations in EZ
Browse files Browse the repository at this point in the history
  • Loading branch information
StarsX committed Oct 21, 2022
1 parent 5a11dd2 commit 9164582
Show file tree
Hide file tree
Showing 12 changed files with 491 additions and 175 deletions.
57 changes: 49 additions & 8 deletions XUSG-EZ/XUSG-EZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ResourceView EZ::GetCBV(ConstantBuffer* pResource, uint32_t index)
resourceView.pResource = pResource;
resourceView.View = pResource->GetCBV(index);
resourceView.DstState = ResourceState::GENERAL_READ;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -50,6 +51,7 @@ ResourceView EZ::GetSRV(Buffer* pResource, uint32_t index, ResourceState dstStat
resourceView.Subresources = { XUSG_BARRIER_ALL_SUBRESOURCES };
resourceView.DstState = pResource->GetResourceState() == ResourceState::GENERAL_READ ?
ResourceState::GENERAL_READ : dstState;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -62,6 +64,7 @@ ResourceView EZ::GetSRV(VertexBuffer* pResource, uint32_t index, ResourceState d
resourceView.Subresources = { XUSG_BARRIER_ALL_SUBRESOURCES };
resourceView.DstState = pResource->GetResourceState() == ResourceState::GENERAL_READ ?
ResourceState::GENERAL_READ : dstState;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -74,6 +77,7 @@ ResourceView EZ::GetSRV(IndexBuffer* pResource, uint32_t index, ResourceState ds
resourceView.Subresources = { XUSG_BARRIER_ALL_SUBRESOURCES };
resourceView.DstState = pResource->GetResourceState() == ResourceState::GENERAL_READ ?
ResourceState::GENERAL_READ : dstState;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -84,6 +88,7 @@ ResourceView EZ::GetSRV(Texture* pResource, uint32_t index, ResourceState dstSta
resourceView.pResource = pResource;
resourceView.View = pResource->GetSRV(index);
resourceView.DstState = dstState;
resourceView.pCounter = nullptr;

const auto numMips = pResource->GetNumMips();
const auto arraySize = pResource->GetArraySize();
Expand All @@ -102,6 +107,7 @@ ResourceView EZ::GetSRV(Texture3D* pResource, ResourceState dstState)
resourceView.pResource = pResource;
resourceView.View = pResource->GetSRV();
resourceView.DstState = dstState;
resourceView.pCounter = nullptr;

const auto numMips = pResource->GetNumMips();
resourceView.Subresources.resize(numMips);
Expand All @@ -118,6 +124,7 @@ ResourceView EZ::GetSRVLevel(Texture* pResource, uint8_t level, ResourceState ds
resourceView.pResource = pResource;
resourceView.View = pResource->GetSRVLevel(level);
resourceView.DstState = dstState;
resourceView.pCounter = nullptr;
CalcSubresources(resourceView.Subresources, pResource, level);

return resourceView;
Expand All @@ -130,6 +137,19 @@ ResourceView EZ::GetSRVLevel(Texture3D* pResource, uint8_t level, ResourceState
resourceView.View = pResource->GetSRVLevel(level);
resourceView.DstState = dstState;
resourceView.Subresources = { CalcSubresource(pResource, level) };
resourceView.pCounter = nullptr;

return resourceView;
}

ResourceView EZ::GetUAV(StructuredBuffer* pResource, uint8_t index)
{
ResourceView resourceView;
resourceView.pResource = pResource;
resourceView.View = pResource->GetUAV(index);
resourceView.Subresources = { XUSG_BARRIER_ALL_SUBRESOURCES };
resourceView.DstState = ResourceState::UNORDERED_ACCESS;
resourceView.pCounter = pResource->GetCounter().get();

return resourceView;
}
Expand All @@ -141,6 +161,7 @@ ResourceView EZ::GetUAV(Buffer* pResource, uint8_t index)
resourceView.View = pResource->GetUAV(index);
resourceView.Subresources = { XUSG_BARRIER_ALL_SUBRESOURCES };
resourceView.DstState = ResourceState::UNORDERED_ACCESS;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -151,6 +172,7 @@ ResourceView EZ::GetUAV(Texture* pResource, uint8_t index)
resourceView.pResource = pResource;
resourceView.View = pResource->GetUAV(index);
resourceView.DstState = ResourceState::UNORDERED_ACCESS;
resourceView.pCounter = nullptr;
CalcSubresources(resourceView.Subresources, pResource, index);

return resourceView;
Expand All @@ -163,6 +185,7 @@ ResourceView EZ::GetUAV(Texture3D* pResource, uint8_t index)
resourceView.View = pResource->GetUAV(index);
resourceView.Subresources = { CalcSubresource(pResource, index) };
resourceView.DstState = ResourceState::UNORDERED_ACCESS;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -173,6 +196,7 @@ ResourceView EZ::GetPackedUAV(Texture* pResource, uint8_t index)
resourceView.pResource = pResource;
resourceView.View = pResource->GetPackedUAV(index);
resourceView.DstState = ResourceState::UNORDERED_ACCESS;
resourceView.pCounter = nullptr;
CalcSubresources(resourceView.Subresources, pResource, index);

return resourceView;
Expand All @@ -185,6 +209,7 @@ ResourceView EZ::GetPackedUAV(Texture3D* pResource, uint8_t index)
resourceView.View = pResource->GetPackedUAV(index);
resourceView.Subresources = { CalcSubresource(pResource, index) };
resourceView.DstState = ResourceState::UNORDERED_ACCESS;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -196,6 +221,7 @@ ResourceView EZ::GetPackedUAV(TypedBuffer* pResource, uint8_t index)
resourceView.View = pResource->GetPackedUAV(index);
resourceView.Subresources = { XUSG_BARRIER_ALL_SUBRESOURCES };
resourceView.DstState = ResourceState::UNORDERED_ACCESS;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -207,6 +233,7 @@ ResourceView EZ::GetRTV(RenderTarget* pResource, uint32_t slice, uint8_t mipLeve
resourceView.View = pResource->GetRTV(slice, mipLevel);
resourceView.Subresources = { CalcSubresource(pResource, mipLevel, slice) };
resourceView.DstState = ResourceState::RENDER_TARGET;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -217,6 +244,7 @@ ResourceView EZ::GetArrayRTV(RenderTarget* pResource, uint8_t mipLevel)
resourceView.pResource = pResource;
resourceView.View = pResource->GetRTV(0, mipLevel);
resourceView.DstState = ResourceState::RENDER_TARGET;
resourceView.pCounter = nullptr;
CalcSubresources(resourceView.Subresources, pResource, mipLevel);

return resourceView;
Expand All @@ -229,6 +257,7 @@ ResourceView EZ::GetDSV(DepthStencil* pResource, uint32_t slice, uint8_t mipLeve
resourceView.View = pResource->GetDSV(slice, mipLevel);
resourceView.Subresources = { CalcSubresource(pResource, mipLevel, slice) };
resourceView.DstState = ResourceState::DEPTH_WRITE;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -239,6 +268,7 @@ ResourceView EZ::GetArrayDSV(DepthStencil* pResource, uint8_t mipLevel)
resourceView.pResource = pResource;
resourceView.View = pResource->GetDSV(0, mipLevel);
resourceView.DstState = ResourceState::DEPTH_WRITE;
resourceView.pCounter = nullptr;
CalcSubresources(resourceView.Subresources, pResource, mipLevel);

return resourceView;
Expand All @@ -252,6 +282,7 @@ ResourceView EZ::GetReadOnlyDSV(DepthStencil* pResource, uint32_t slice, uint8_t
resourceView.Subresources = { CalcSubresource(pResource, mipLevel, slice) };
resourceView.DstState = ResourceState::DEPTH_READ;
resourceView.DstState |= pResource->GetSRV() ? dstSrvState : resourceView.DstState;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand All @@ -263,6 +294,7 @@ ResourceView EZ::GetReadOnlyArrayDSV(DepthStencil* pResource, uint8_t mipLevel,
resourceView.View = pResource->GetReadOnlyDSV(0, mipLevel);
resourceView.DstState = ResourceState::DEPTH_READ;
resourceView.DstState |= pResource->GetSRV() ? dstSrvState : resourceView.DstState;
resourceView.pCounter = nullptr;
CalcSubresources(resourceView.Subresources, pResource, mipLevel);

return resourceView;
Expand All @@ -275,6 +307,7 @@ ResourceView EZ::GetStencilSRV(DepthStencil* pResource, ResourceState dstSrvStat
resourceView.View = pResource->GetStencilSRV();
resourceView.Subresources = { XUSG_BARRIER_ALL_SUBRESOURCES };
resourceView.DstState = dstSrvState;
resourceView.pCounter = nullptr;

return resourceView;
}
Expand Down Expand Up @@ -312,21 +345,29 @@ EZ::CommandList::sptr EZ::CommandList::MakeShared(API api)
}

EZ::CommandList::uptr EZ::CommandList::MakeUnique(XUSG::CommandList* pCommandList,
uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize, uint32_t maxSamplers,
const uint32_t* pMaxCbvsEachSpace, const uint32_t* pMaxSrvsEachSpace,
const uint32_t* pMaxUavsEachSpace, uint32_t maxCbvSpaces,
uint32_t maxSrvSpaces, uint32_t maxUavSpaces, API api)
uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize,
const uint32_t maxSamplers[Shader::Stage::NUM_STAGE],
const uint32_t* pMaxCbvsEachSpace[Shader::Stage::NUM_STAGE],
const uint32_t* pMaxSrvsEachSpace[Shader::Stage::NUM_STAGE],
const uint32_t* pMaxUavsEachSpace[Shader::Stage::NUM_STAGE],
const uint32_t maxCbvSpaces[Shader::Stage::NUM_STAGE],
const uint32_t maxSrvSpaces[Shader::Stage::NUM_STAGE],
const uint32_t maxUavSpaces[Shader::Stage::NUM_STAGE], API api)
{
return make_unique<EZ::CommandList_DX12>(pCommandList, samplerPoolSize, cbvSrvUavPoolSize,
maxSamplers, pMaxCbvsEachSpace, pMaxSrvsEachSpace, pMaxUavsEachSpace,
maxCbvSpaces, maxSrvSpaces, maxUavSpaces);
}

EZ::CommandList::sptr EZ::CommandList::MakeShared(XUSG::CommandList* pCommandList,
uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize, uint32_t maxSamplers,
const uint32_t* pMaxCbvsEachSpace, const uint32_t* pMaxSrvsEachSpace,
const uint32_t* pMaxUavsEachSpace, uint32_t maxCbvSpaces,
uint32_t maxSrvSpaces, uint32_t maxUavSpaces, API api)
uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize,
const uint32_t maxSamplers[Shader::Stage::NUM_STAGE],
const uint32_t* pMaxCbvsEachSpace[Shader::Stage::NUM_STAGE],
const uint32_t* pMaxSrvsEachSpace[Shader::Stage::NUM_STAGE],
const uint32_t* pMaxUavsEachSpace[Shader::Stage::NUM_STAGE],
const uint32_t maxCbvSpaces[Shader::Stage::NUM_STAGE],
const uint32_t maxSrvSpaces[Shader::Stage::NUM_STAGE],
const uint32_t maxUavSpaces[Shader::Stage::NUM_STAGE], API api)
{
return make_shared<EZ::CommandList_DX12>(pCommandList, samplerPoolSize, cbvSrvUavPoolSize,
maxSamplers, pMaxCbvsEachSpace, pMaxSrvsEachSpace, pMaxUavsEachSpace,
Expand Down
52 changes: 39 additions & 13 deletions XUSG-EZ/XUSG-EZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace XUSG
Descriptor View;
std::vector<uint32_t> Subresources;
ResourceState DstState;
Resource* pCounter;
};

struct VertexBufferView
Expand Down Expand Up @@ -56,6 +57,7 @@ namespace XUSG
ResourceState dstState = SHADER_RESOURCE_STATE);
XUSG_INTERFACE ResourceView GetSRVLevel(Texture3D* pResource, uint8_t level,
ResourceState dstState = SHADER_RESOURCE_STATE);
XUSG_INTERFACE ResourceView GetUAV(StructuredBuffer* pResource, uint8_t index = 0);
XUSG_INTERFACE ResourceView GetUAV(Buffer* pResource, uint8_t index = 0);
XUSG_INTERFACE ResourceView GetUAV(Texture* pResource, uint8_t index = 0);
XUSG_INTERFACE ResourceView GetUAV(Texture3D* pResource, uint8_t index = 0);
Expand Down Expand Up @@ -88,13 +90,25 @@ namespace XUSG
//CommandList();
virtual ~CommandList() {}

// By default maxCbvsEachSpace = 14, maxSrvsEachSpace = 32, and maxUavsEachSpace = 16
virtual bool Create(XUSG::CommandList* pCommandList, uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize,
uint32_t maxSamplers = 16, const uint32_t* pMaxCbvsEachSpace = nullptr, const uint32_t* pMaxSrvsEachSpace = nullptr,
const uint32_t* pMaxUavsEachSpace = nullptr, uint32_t maxCbvSpaces = 1, uint32_t maxSrvSpaces = 1, uint32_t maxUavSpaces = 1) = 0;
virtual bool Create(const Device* pDevice, void* pHandle, uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize,
uint32_t maxSamplers = 16, const uint32_t* pMaxCbvsEachSpace = nullptr, const uint32_t* pMaxSrvsEachSpace = nullptr,
const uint32_t* pMaxUavsEachSpace = nullptr, uint32_t maxCbvSpaces = 1, uint32_t maxSrvSpaces = 1, uint32_t maxUavSpaces = 1,
// By default maxSamplers[stage] = 16, maxCbvsEachSpace[stage] = 14, maxSrvsEachSpace[stage] = 32, and maxUavsEachSpace[stage] = 16
virtual bool Create(XUSG::CommandList* pCommandList,
uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize,
const uint32_t maxSamplers[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxCbvsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxSrvsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxUavsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxCbvSpaces[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxSrvSpaces[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxUavSpaces[Shader::Stage::NUM_STAGE] = nullptr) = 0;
virtual bool Create(const Device* pDevice, void* pHandle,
uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize,
const uint32_t maxSamplers[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxCbvsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxSrvsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxUavsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxCbvSpaces[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxSrvSpaces[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxUavSpaces[Shader::Stage::NUM_STAGE] = nullptr,
const wchar_t* name = nullptr) = 0;
virtual bool Close(RenderTarget* pBackBuffer = nullptr) = 0;
virtual bool Reset(const CommandAllocator* pAllocator, const Pipeline& initialState) = 0;
Expand Down Expand Up @@ -205,13 +219,25 @@ namespace XUSG

static uptr MakeUnique(API api = API::DIRECTX_12);
static sptr MakeShared(API api = API::DIRECTX_12);
static uptr MakeUnique(XUSG::CommandList* pCommandList, uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize,
uint32_t maxSamplers = 16, const uint32_t* pMaxCbvsEachSpace = nullptr, const uint32_t* pMaxSrvsEachSpace = nullptr,
const uint32_t* pMaxUavsEachSpace = nullptr, uint32_t maxCbvSpaces = 1, uint32_t maxSrvSpaces = 1, uint32_t maxUavSpaces = 1,
static uptr MakeUnique(XUSG::CommandList* pCommandList,
uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize,
const uint32_t maxSamplers[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxCbvsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxSrvsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxUavsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxCbvSpaces[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxSrvSpaces[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxUavSpaces[Shader::Stage::NUM_STAGE] = nullptr,
API api = API::DIRECTX_12);
static sptr MakeShared(XUSG::CommandList* pCommandList, uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize,
uint32_t maxSamplers = 16, const uint32_t* pMaxCbvsEachSpace = nullptr, const uint32_t* pMaxSrvsEachSpace = nullptr,
const uint32_t* pMaxUavsEachSpace = nullptr, uint32_t maxCbvSpaces = 1, uint32_t maxSrvSpaces = 1, uint32_t maxUavSpaces = 1,
static sptr MakeShared(XUSG::CommandList* pCommandList,
uint32_t samplerPoolSize, uint32_t cbvSrvUavPoolSize,
const uint32_t maxSamplers[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxCbvsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxSrvsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t* pMaxUavsEachSpace[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxCbvSpaces[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxSrvSpaces[Shader::Stage::NUM_STAGE] = nullptr,
const uint32_t maxUavSpaces[Shader::Stage::NUM_STAGE] = nullptr,
API api = API::DIRECTX_12);
};
}
Expand Down
Loading

0 comments on commit 9164582

Please sign in to comment.