From 09c813c934adc2d0c8565151240834b40b37269e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 7 Oct 2019 12:41:18 +0200 Subject: [PATCH] [dxvk] Use packed rasterizer state --- src/dxvk/dxvk_context.cpp | 20 ++++---- src/dxvk/dxvk_graphics.cpp | 20 ++++---- src/dxvk/dxvk_graphics_state.h | 86 ++++++++++++++++++++++++++++++---- 3 files changed, 98 insertions(+), 28 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index a0509647..3b789a37 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -2173,8 +2173,8 @@ namespace dxvk { uint32_t viewportCount, const VkViewport* viewports, const VkRect2D* scissorRects) { - if (m_state.gp.state.rsViewportCount != viewportCount) { - m_state.gp.state.rsViewportCount = viewportCount; + if (m_state.gp.state.rs.viewportCount() != viewportCount) { + m_state.gp.state.rs.setViewportCount(viewportCount); m_flags.set(DxvkContextFlag::GpDirtyPipelineState); } @@ -2281,12 +2281,14 @@ namespace dxvk { void DxvkContext::setRasterizerState(const DxvkRasterizerState& rs) { - m_state.gp.state.rsDepthClipEnable = rs.depthClipEnable; - m_state.gp.state.rsDepthBiasEnable = rs.depthBiasEnable; - m_state.gp.state.rsPolygonMode = rs.polygonMode; - m_state.gp.state.rsCullMode = rs.cullMode; - m_state.gp.state.rsFrontFace = rs.frontFace; - m_state.gp.state.rsSampleCount = rs.sampleCount; + m_state.gp.state.rs = DxvkRsInfo( + rs.depthClipEnable, + rs.depthBiasEnable, + rs.polygonMode, + rs.cullMode, + rs.frontFace, + m_state.gp.state.rs.viewportCount(), + rs.sampleCount); m_flags.set(DxvkContextFlag::GpDirtyPipelineState); } @@ -4103,7 +4105,7 @@ namespace dxvk { if (m_flags.test(DxvkContextFlag::GpDirtyViewport)) { m_flags.clr(DxvkContextFlag::GpDirtyViewport); - uint32_t viewportCount = m_state.gp.state.rsViewportCount; + uint32_t viewportCount = m_state.gp.state.rs.viewportCount(); m_cmd->cmdSetViewport(0, viewportCount, m_state.vp.viewports.data()); m_cmd->cmdSetScissor (0, viewportCount, m_state.vp.scissorRects.data()); } diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp index 384f027c..38f076ce 100644 --- a/src/dxvk/dxvk_graphics.cpp +++ b/src/dxvk/dxvk_graphics.cpp @@ -160,8 +160,8 @@ namespace dxvk { if (state.msSampleCount) sampleCount = VkSampleCountFlagBits(state.msSampleCount); - else if (state.rsSampleCount) - sampleCount = VkSampleCountFlagBits(state.rsSampleCount); + else if (state.rs.sampleCount()) + sampleCount = VkSampleCountFlagBits(state.rs.sampleCount()); // Set up some specialization constants DxvkSpecConstants specData; @@ -301,9 +301,9 @@ namespace dxvk { vpInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; vpInfo.pNext = nullptr; vpInfo.flags = 0; - vpInfo.viewportCount = state.rsViewportCount; + vpInfo.viewportCount = state.rs.viewportCount(); vpInfo.pViewports = nullptr; - vpInfo.scissorCount = state.rsViewportCount; + vpInfo.scissorCount = state.rs.viewportCount(); vpInfo.pScissors = nullptr; VkPipelineRasterizationStateStreamCreateInfoEXT xfbStreamInfo; @@ -316,7 +316,7 @@ namespace dxvk { rsDepthClipInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT; rsDepthClipInfo.pNext = nullptr; rsDepthClipInfo.flags = 0; - rsDepthClipInfo.depthClipEnable = state.rsDepthClipEnable; + rsDepthClipInfo.depthClipEnable = state.rs.depthClipEnable(); VkPipelineRasterizationStateCreateInfo rsInfo; rsInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; @@ -324,10 +324,10 @@ namespace dxvk { rsInfo.flags = 0; rsInfo.depthClampEnable = VK_TRUE; rsInfo.rasterizerDiscardEnable = rasterizedStream < 0; - rsInfo.polygonMode = state.rsPolygonMode; - rsInfo.cullMode = state.rsCullMode; - rsInfo.frontFace = state.rsFrontFace; - rsInfo.depthBiasEnable = state.rsDepthBiasEnable; + rsInfo.polygonMode = state.rs.polygonMode(); + rsInfo.cullMode = state.rs.cullMode(); + rsInfo.frontFace = state.rs.frontFace(); + rsInfo.depthBiasEnable = state.rs.depthBiasEnable(); rsInfo.depthBiasConstantFactor= 0.0f; rsInfo.depthBiasClamp = 0.0f; rsInfo.depthBiasSlopeFactor = 0.0f; @@ -338,7 +338,7 @@ namespace dxvk { if (!m_pipeMgr->m_device->features().extDepthClipEnable.depthClipEnable) { rsInfo.pNext = rsDepthClipInfo.pNext; - rsInfo.depthClampEnable = !state.rsDepthClipEnable; + rsInfo.depthClampEnable = !state.rs.depthClipEnable(); } VkPipelineMultisampleStateCreateInfo msInfo; diff --git a/src/dxvk/dxvk_graphics_state.h b/src/dxvk/dxvk_graphics_state.h index 83020fe5..c8c9dbc2 100644 --- a/src/dxvk/dxvk_graphics_state.h +++ b/src/dxvk/dxvk_graphics_state.h @@ -207,6 +207,81 @@ namespace dxvk { }; + /** + * \brief Packed rasterizer state + * + * Stores a bunch of flags and parameters + * related to rasterization in four bytes. + */ + class DxvkRsInfo { + + public: + + DxvkRsInfo() = default; + + DxvkRsInfo( + VkBool32 depthClipEnable, + VkBool32 depthBiasEnable, + VkPolygonMode polygonMode, + VkCullModeFlags cullMode, + VkFrontFace frontFace, + uint32_t viewportCount, + VkSampleCountFlags sampleCount) + : m_depthClipEnable (uint32_t(depthClipEnable)), + m_depthBiasEnable (uint32_t(depthBiasEnable)), + m_polygonMode (uint32_t(polygonMode)), + m_cullMode (uint32_t(cullMode)), + m_frontFace (uint32_t(frontFace)), + m_viewportCount (uint32_t(viewportCount)), + m_sampleCount (uint32_t(sampleCount)), + m_reserved (0) { } + + VkBool32 depthClipEnable() const { + return VkBool32(m_depthClipEnable); + } + + VkBool32 depthBiasEnable() const { + return VkBool32(m_depthBiasEnable); + } + + VkPolygonMode polygonMode() const { + return VkPolygonMode(m_polygonMode); + } + + VkCullModeFlags cullMode() const { + return VkCullModeFlags(m_cullMode); + } + + VkFrontFace frontFace() const { + return VkFrontFace(m_frontFace); + } + + uint32_t viewportCount() const { + return m_viewportCount; + } + + VkSampleCountFlags sampleCount() const { + return VkSampleCountFlags(m_sampleCount); + } + + void setViewportCount(uint32_t viewportCount) { + m_viewportCount = viewportCount; + } + + private: + + uint32_t m_depthClipEnable : 1; + uint32_t m_depthBiasEnable : 1; + uint32_t m_polygonMode : 2; + uint32_t m_cullMode : 2; + uint32_t m_frontFace : 1; + uint32_t m_viewportCount : 5; + uint32_t m_sampleCount : 5; + uint32_t m_reserved : 15; + + }; + + /** * \brief Packed graphics pipeline state * @@ -241,7 +316,7 @@ namespace dxvk { } bool useDynamicDepthBias() const { - return rsDepthBiasEnable; + return rs.depthBiasEnable(); } bool useDynamicDepthBounds() const { @@ -265,14 +340,7 @@ namespace dxvk { DxvkBindingMask bsBindingMask; DxvkIaInfo ia; DxvkIlInfo il; - - VkBool32 rsDepthClipEnable; - VkBool32 rsDepthBiasEnable; - VkPolygonMode rsPolygonMode; - VkCullModeFlags rsCullMode; - VkFrontFace rsFrontFace; - uint32_t rsViewportCount; - VkSampleCountFlags rsSampleCount; + DxvkRsInfo rs; VkSampleCountFlags msSampleCount; uint32_t msSampleMask;