Skip to content

Commit

Permalink
[dxvk] Do not pass line rasterization info if not needed
Browse files Browse the repository at this point in the history
Works around some weird RADV issue and also ensures that we don't
accidentally invalidate all sorts of shader caches.
  • Loading branch information
doitsujin committed Jul 19, 2023
1 parent 113431a commit 83a6e9a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
41 changes: 26 additions & 15 deletions src/dxvk/dxvk_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ namespace dxvk {
DxvkGraphicsPipelinePreRasterizationState::DxvkGraphicsPipelinePreRasterizationState(
const DxvkDevice* device,
const DxvkGraphicsPipelineStateInfo& state,
const DxvkShader* tes,
const DxvkShader* gs) {
// Set up tessellation state
tsInfo.patchControlPoints = state.ia.patchVertexCount();
Expand Down Expand Up @@ -498,7 +499,7 @@ namespace dxvk {

// Set up line rasterization mode as requested by the application.
// Line width for rectangular lines matches D3D11 behaviour.
if (state.rs.lineMode() != VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT) {
if (state.rs.lineMode() != VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT && isLineRendering(state, tes, gs)) {
rsLineInfo.pNext = std::exchange(rsInfo.pNext, &rsLineInfo);
rsLineInfo.lineRasterizationMode = state.rs.lineMode();

Expand Down Expand Up @@ -560,6 +561,29 @@ namespace dxvk {
}


bool DxvkGraphicsPipelinePreRasterizationState::isLineRendering(
const DxvkGraphicsPipelineStateInfo& state,
const DxvkShader* tes,
const DxvkShader* gs) {
bool isLineRendering = state.rs.polygonMode() == VK_POLYGON_MODE_LINE;

if (gs) {
isLineRendering |= gs->info().outputTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
} else if (tes) {
isLineRendering |= tes->info().outputTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
} else {
VkPrimitiveTopology topology = state.ia.primitiveTopology();

isLineRendering |= topology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST
|| topology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP
|| topology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY
|| topology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY;
}

return isLineRendering;
}


DxvkGraphicsPipelineFragmentShaderState::DxvkGraphicsPipelineFragmentShaderState() {

}
Expand Down Expand Up @@ -1095,20 +1119,7 @@ namespace dxvk {

// We do not implement setting certain rarely used render
// states dynamically since they are generally not used
bool isLineRendering = state.rs.polygonMode() == VK_POLYGON_MODE_LINE;

if (m_shaders.gs != nullptr) {
isLineRendering |= m_shaders.gs->info().outputTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
} else if (m_shaders.tes != nullptr) {
isLineRendering |= m_shaders.tes->info().outputTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
} else {
VkPrimitiveTopology topology = state.ia.primitiveTopology();

isLineRendering |= topology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST
|| topology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP
|| topology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY
|| topology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY;
}
bool isLineRendering = DxvkGraphicsPipelinePreRasterizationState::isLineRendering(state, m_shaders.tes.ptr(), m_shaders.gs.ptr());

if (state.rs.polygonMode() != VK_POLYGON_MODE_FILL
|| state.rs.conservativeMode() != VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT
Expand Down
9 changes: 8 additions & 1 deletion src/dxvk/dxvk_graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ namespace dxvk {
DxvkGraphicsPipelinePreRasterizationState(
const DxvkDevice* device,
const DxvkGraphicsPipelineStateInfo& state,
const DxvkShader* tes,
const DxvkShader* gs);

VkPipelineViewportStateCreateInfo vpInfo = { VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO };
Expand All @@ -181,6 +182,12 @@ namespace dxvk {
bool eq(const DxvkGraphicsPipelinePreRasterizationState& other) const;

size_t hash() const;

static bool isLineRendering(
const DxvkGraphicsPipelineStateInfo& state,
const DxvkShader* tes,
const DxvkShader* gs);

};


Expand Down Expand Up @@ -407,7 +414,7 @@ namespace dxvk {
: shState(shaders, state),
dyState(device, state, flags),
viState(device, state, shaders.vs.ptr()),
prState(device, state, shaders.gs.ptr()),
prState(device, state, shaders.tes.ptr(), shaders.gs.ptr()),
fsState(device, state),
foState(device, state, shaders.fs.ptr()),
scState(specConstantMask, state.sc) { }
Expand Down

0 comments on commit 83a6e9a

Please sign in to comment.