Skip to content

Commit

Permalink
[dxvk] Remove workaround for non-dynamic depth clip
Browse files Browse the repository at this point in the history
Kind of pointless and everyone supports the required EDS3 subset anyway.
  • Loading branch information
doitsujin committed Apr 29, 2024
1 parent 6537379 commit ea4cb84
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 73 deletions.
4 changes: 1 addition & 3 deletions src/dxvk/dxvk_compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ namespace dxvk {
// Retrieve actual pipeline handle on first use. This
// may wait for an ongoing compile job to finish, or
// compile the pipeline immediately on the calling thread.
m_libraryHandle = m_library->acquirePipelineHandle(
DxvkShaderPipelineLibraryCompileArgs()).handle;

m_libraryHandle = m_library->acquirePipelineHandle().handle;
return m_libraryHandle;
} else {
// Slow path for compute shaders that do use spec constants
Expand Down
15 changes: 10 additions & 5 deletions src/dxvk/dxvk_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ namespace dxvk {
if (doCreateBasePipeline)
baseHandle = this->getBasePipeline(state);

// Fast-linking may fail in some situations
if (!baseHandle)
fastHandle = this->getOptimizedPipeline(state);

Expand Down Expand Up @@ -1149,6 +1150,13 @@ namespace dxvk {
|| (state.rs.lineMode() != VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT && isLineRendering))
return false;

// Depth clip is assumed to be enabled. If the driver does not
// support dynamic depth clip, we'd have to late-compile anyway
// unless the pipeline is used multiple times.
if (!m_device->features().extExtendedDynamicState3.extendedDynamicState3DepthClipEnable
&& !state.rs.depthClipEnable())
return false;

if (m_shaders.tcs != nullptr) {
// If tessellation shaders are present, the input patch
// vertex count must match the shader's definition.
Expand Down Expand Up @@ -1220,9 +1228,6 @@ namespace dxvk {
key.viLibrary = m_manager->createVertexInputLibrary(viState);
key.foLibrary = m_manager->createFragmentOutputLibrary(foState);

if (!m_device->features().extExtendedDynamicState3.extendedDynamicState3DepthClipEnable)
key.args.depthClipEnable = state.rs.depthClipEnable();

auto entry = m_basePipelines.find(key);
if (entry != m_basePipelines.end())
return entry->second;
Expand All @@ -1237,8 +1242,8 @@ namespace dxvk {
const DxvkGraphicsPipelineBaseInstanceKey& key) const {
auto vk = m_device->vkd();

DxvkShaderPipelineLibraryHandle vs = m_vsLibrary->acquirePipelineHandle(key.args);
DxvkShaderPipelineLibraryHandle fs = m_fsLibrary->acquirePipelineHandle(key.args);
DxvkShaderPipelineLibraryHandle vs = m_vsLibrary->acquirePipelineHandle();
DxvkShaderPipelineLibraryHandle fs = m_fsLibrary->acquirePipelineHandle();

std::array<VkPipeline, 4> libraries = {{
key.viLibrary->getHandle(), vs.handle, fs.handle,
Expand Down
5 changes: 1 addition & 4 deletions src/dxvk/dxvk_graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,16 @@ namespace dxvk {
struct DxvkGraphicsPipelineBaseInstanceKey {
const DxvkGraphicsPipelineVertexInputLibrary* viLibrary = nullptr;
const DxvkGraphicsPipelineFragmentOutputLibrary* foLibrary = nullptr;
DxvkShaderPipelineLibraryCompileArgs args;

bool eq(const DxvkGraphicsPipelineBaseInstanceKey& other) const {
return viLibrary == other.viLibrary
&& foLibrary == other.foLibrary
&& args == other.args;
&& foLibrary == other.foLibrary;
}

size_t hash() const {
DxvkHashState hash;
hash.add(size_t(viLibrary));
hash.add(size_t(foLibrary));
hash.add(args.hash());
return hash;
}
};
Expand Down
45 changes: 16 additions & 29 deletions src/dxvk/dxvk_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ namespace dxvk {


DxvkShaderPipelineLibrary::~DxvkShaderPipelineLibrary() {
this->destroyShaderPipelinesLocked();
this->destroyShaderPipelineLocked();
}


Expand All @@ -1042,22 +1042,17 @@ namespace dxvk {
}


DxvkShaderPipelineLibraryHandle DxvkShaderPipelineLibrary::acquirePipelineHandle(
const DxvkShaderPipelineLibraryCompileArgs& args) {
DxvkShaderPipelineLibraryHandle DxvkShaderPipelineLibrary::acquirePipelineHandle() {
std::lock_guard lock(m_mutex);

if (m_device->mustTrackPipelineLifetime())
m_useCount += 1;

DxvkShaderPipelineLibraryHandle& pipeline = (m_shaders.vs && !args.depthClipEnable)
? m_pipelineNoDepthClip
: m_pipeline;
if (m_pipeline.handle)
return m_pipeline;

if (pipeline.handle)
return pipeline;

pipeline = compileShaderPipelineLocked(args);
return pipeline;
m_pipeline = compileShaderPipelineLocked();
return m_pipeline;
}


Expand All @@ -1066,7 +1061,7 @@ namespace dxvk {
std::lock_guard lock(m_mutex);

if (!(--m_useCount))
this->destroyShaderPipelinesLocked();
this->destroyShaderPipelineLocked();
}
}

Expand All @@ -1079,8 +1074,7 @@ namespace dxvk {
return;

// Compile the pipeline with default args
DxvkShaderPipelineLibraryHandle pipeline = compileShaderPipelineLocked(
DxvkShaderPipelineLibraryCompileArgs());
DxvkShaderPipelineLibraryHandle pipeline = compileShaderPipelineLocked();

// On 32-bit, destroy the pipeline immediately in order to
// save memory. We should hit the driver's disk cache once
Expand All @@ -1097,33 +1091,28 @@ namespace dxvk {
}


void DxvkShaderPipelineLibrary::destroyShaderPipelinesLocked() {
void DxvkShaderPipelineLibrary::destroyShaderPipelineLocked() {
auto vk = m_device->vkd();

vk->vkDestroyPipeline(vk->device(), m_pipeline.handle, nullptr);
vk->vkDestroyPipeline(vk->device(), m_pipelineNoDepthClip.handle, nullptr);

m_pipeline.handle = VK_NULL_HANDLE;
m_pipelineNoDepthClip.handle = VK_NULL_HANDLE;
}


DxvkShaderPipelineLibraryHandle DxvkShaderPipelineLibrary::compileShaderPipelineLocked(
const DxvkShaderPipelineLibraryCompileArgs& args) {
DxvkShaderPipelineLibraryHandle DxvkShaderPipelineLibrary::compileShaderPipelineLocked() {
this->notifyLibraryCompile();

// If this is not the first time we're compiling the pipeline,
// try to get a cache hit using the shader module identifier
// so that we don't have to decompress our SPIR-V shader again.
DxvkShaderPipelineLibraryHandle pipeline = { VK_NULL_HANDLE, 0 };

if (m_compiledOnce && canUsePipelineCacheControl()) {
pipeline = this->compileShaderPipeline(args,
VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT);
}
if (m_compiledOnce && canUsePipelineCacheControl())
pipeline = this->compileShaderPipeline(VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT);

if (!pipeline.handle)
pipeline = this->compileShaderPipeline(args, 0);
pipeline = this->compileShaderPipeline(0);

// Well that didn't work
if (!pipeline.handle)
Expand All @@ -1145,7 +1134,6 @@ namespace dxvk {


DxvkShaderPipelineLibraryHandle DxvkShaderPipelineLibrary::compileShaderPipeline(
const DxvkShaderPipelineLibraryCompileArgs& args,
VkPipelineCreateFlags flags) {
DxvkShaderStageInfo stageInfo(m_device);
VkShaderStageFlags stageMask = getShaderStages();
Expand Down Expand Up @@ -1181,7 +1169,7 @@ namespace dxvk {
VkPipeline pipeline = VK_NULL_HANDLE;

if (stageMask & VK_SHADER_STAGE_VERTEX_BIT)
pipeline = compileVertexShaderPipeline(args, stageInfo, flags);
pipeline = compileVertexShaderPipeline(stageInfo, flags);
else if (stageMask & VK_SHADER_STAGE_FRAGMENT_BIT)
pipeline = compileFragmentShaderPipeline(stageInfo, flags);
else if (stageMask & VK_SHADER_STAGE_COMPUTE_BIT)
Expand All @@ -1193,7 +1181,6 @@ namespace dxvk {


VkPipeline DxvkShaderPipelineLibrary::compileVertexShaderPipeline(
const DxvkShaderPipelineLibraryCompileArgs& args,
const DxvkShaderStageInfo& stageInfo,
VkPipelineCreateFlags flags) {
auto vk = m_device->vkd();
Expand Down Expand Up @@ -1240,10 +1227,10 @@ namespace dxvk {
// Only use the fixed depth clip state if we can't make it dynamic
if (!m_device->features().extExtendedDynamicState3.extendedDynamicState3DepthClipEnable) {
rsDepthClipInfo.pNext = std::exchange(rsInfo.pNext, &rsDepthClipInfo);
rsDepthClipInfo.depthClipEnable = args.depthClipEnable;
rsDepthClipInfo.depthClipEnable = VK_TRUE;
}
} else {
rsInfo.depthClampEnable = !args.depthClipEnable;
rsInfo.depthClampEnable = VK_FALSE;
}

// Only the view mask is used as input, and since we do not use MultiView, it is always 0
Expand Down
38 changes: 6 additions & 32 deletions src/dxvk/dxvk_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,26 +368,6 @@ namespace dxvk {
};


/**
* \brief Shader pipeline library compile args
*/
struct DxvkShaderPipelineLibraryCompileArgs {
VkBool32 depthClipEnable = VK_TRUE;

bool operator == (const DxvkShaderPipelineLibraryCompileArgs& other) const {
return depthClipEnable == other.depthClipEnable;
}

bool operator != (const DxvkShaderPipelineLibraryCompileArgs& other) const {
return !this->operator == (other);
}

size_t hash() const {
return size_t(depthClipEnable);
}
};


/**
* \brief Shader set
*
Expand Down Expand Up @@ -532,11 +512,9 @@ namespace dxvk {
* Either returns an already compiled pipeline library object, or
* performs the compilation step if that has not happened yet.
* Increments the use count by one.
* \param [in] args Compile arguments
* \returns Vulkan pipeline handle
*/
DxvkShaderPipelineLibraryHandle acquirePipelineHandle(
const DxvkShaderPipelineLibraryCompileArgs& args);
DxvkShaderPipelineLibraryHandle acquirePipelineHandle();

/**
* \brief Releases pipeline
Expand Down Expand Up @@ -564,25 +542,21 @@ namespace dxvk {
const DxvkBindingLayoutObjects* m_layout;

dxvk::mutex m_mutex;
DxvkShaderPipelineLibraryHandle m_pipeline = { VK_NULL_HANDLE, 0 };
DxvkShaderPipelineLibraryHandle m_pipelineNoDepthClip = { VK_NULL_HANDLE, 0 };
uint32_t m_useCount = 0u;
bool m_compiledOnce = false;
DxvkShaderPipelineLibraryHandle m_pipeline = { VK_NULL_HANDLE, 0 };
uint32_t m_useCount = 0u;
bool m_compiledOnce = false;

dxvk::mutex m_identifierMutex;
DxvkShaderIdentifierSet m_identifiers;

void destroyShaderPipelinesLocked();
void destroyShaderPipelineLocked();

DxvkShaderPipelineLibraryHandle compileShaderPipelineLocked(
const DxvkShaderPipelineLibraryCompileArgs& args);
DxvkShaderPipelineLibraryHandle compileShaderPipelineLocked();

DxvkShaderPipelineLibraryHandle compileShaderPipeline(
const DxvkShaderPipelineLibraryCompileArgs& args,
VkPipelineCreateFlags flags);

VkPipeline compileVertexShaderPipeline(
const DxvkShaderPipelineLibraryCompileArgs& args,
const DxvkShaderStageInfo& stageInfo,
VkPipelineCreateFlags flags);

Expand Down

0 comments on commit ea4cb84

Please sign in to comment.