1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-28 02:19:26 +01:00

[dxvk] Compute attachment usage mask for each pipeline instance

This commit is contained in:
Philip Rebohle 2025-03-21 23:06:11 +01:00
parent 97cff85280
commit bd27980ae8
2 changed files with 62 additions and 3 deletions

View File

@ -1193,7 +1193,7 @@ namespace dxvk {
this->logPipelineState(LogLevel::Error, state);
m_stats->numGraphicsPipelines += 1;
return &(*m_pipelines.emplace(state, baseHandle, fastHandle));
return &(*m_pipelines.emplace(state, baseHandle, fastHandle, computeAttachmentMask(state)));
}
@ -1487,6 +1487,57 @@ namespace dxvk {
}
DxvkAttachmentMask DxvkGraphicsPipeline::computeAttachmentMask(
const DxvkGraphicsPipelineStateInfo& state) const {
// Scan color attachments first, we only need to check if any given
// attachment is accessed by the shader and has a non-zero write mask.
DxvkAttachmentMask result = { };
if (m_shaders.fs) {
uint32_t colorMask = m_shaders.fs->info().outputMask;
for (auto i : bit::BitMask(colorMask)) {
if (state.writesRenderTarget(i))
result.trackColorWrite(i);
}
}
// Check depth buffer access
auto depthFormat = state.rt.getDepthStencilFormat();
if (depthFormat) {
auto dsReadable = lookupFormatInfo(depthFormat)->aspectMask;
auto dsWritable = dsReadable & ~state.rt.getDepthStencilReadOnlyAspects();
if (dsReadable & VK_IMAGE_ASPECT_DEPTH_BIT) {
if (state.ds.enableDepthBoundsTest())
result.trackDepthRead();
if (state.ds.enableDepthTest()) {
result.trackDepthRead();
if (state.ds.enableDepthWrite() && (dsWritable & VK_IMAGE_ASPECT_DEPTH_BIT))
result.trackDepthWrite();
}
}
if (dsReadable & VK_IMAGE_ASPECT_STENCIL_BIT) {
if (state.ds.enableStencilTest()) {
auto f = state.dsFront.state(dsWritable & VK_IMAGE_ASPECT_STENCIL_BIT);
auto b = state.dsBack.state(dsWritable & VK_IMAGE_ASPECT_STENCIL_BIT);
result.trackStencilRead();
if (f.writeMask | b.writeMask)
result.trackStencilWrite();
}
}
}
return result;
}
bool DxvkGraphicsPipeline::validatePipelineState(
const DxvkGraphicsPipelineStateInfo& state,
bool trusted) const {

View File

@ -351,6 +351,7 @@ namespace dxvk {
struct DxvkGraphicsPipelineHandle {
VkPipeline handle = VK_NULL_HANDLE;
DxvkGraphicsPipelineType type = DxvkGraphicsPipelineType::FastPipeline;
DxvkAttachmentMask attachments = { };
};
@ -365,16 +366,19 @@ namespace dxvk {
DxvkGraphicsPipelineInstance(
const DxvkGraphicsPipelineStateInfo& state_,
VkPipeline baseHandle_,
VkPipeline fastHandle_)
VkPipeline fastHandle_,
DxvkAttachmentMask attachments_)
: state (state_),
baseHandle (baseHandle_),
fastHandle (fastHandle_),
isCompiling (fastHandle_ != VK_NULL_HANDLE) { }
isCompiling (fastHandle_ != VK_NULL_HANDLE),
attachments (attachments_) { }
DxvkGraphicsPipelineStateInfo state;
std::atomic<VkPipeline> baseHandle = { VK_NULL_HANDLE };
std::atomic<VkPipeline> fastHandle = { VK_NULL_HANDLE };
std::atomic<VkBool32> isCompiling = { VK_FALSE };
DxvkAttachmentMask attachments = { };
DxvkGraphicsPipelineHandle getHandle() const {
// Find a pipeline handle to use. If no optimized pipeline has
@ -382,6 +386,7 @@ namespace dxvk {
DxvkGraphicsPipelineHandle result;
result.handle = fastHandle.load(std::memory_order_acquire);
result.type = DxvkGraphicsPipelineType::FastPipeline;
result.attachments = attachments;
if (likely(fastHandle))
return result;
@ -667,6 +672,9 @@ namespace dxvk {
uint32_t computeSpecConstantMask() const;
DxvkAttachmentMask computeAttachmentMask(
const DxvkGraphicsPipelineStateInfo& state) const;
bool validatePipelineState(
const DxvkGraphicsPipelineStateInfo& state,
bool trusted) const;