From 8889d6402ed2c9d7420b85d98222eb289e5da254 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 18 Jul 2019 18:47:23 +0200 Subject: [PATCH] [dxvk] Use new fullscreen shaders for mip gen operations --- src/dxvk/dxvk_context.cpp | 2 +- src/dxvk/dxvk_device.cpp | 2 +- src/dxvk/dxvk_meta_mipgen.cpp | 47 ++++++++++++++--------- src/dxvk/dxvk_meta_mipgen.h | 12 +++--- src/dxvk/shaders/dxvk_mipgen_frag_1d.frag | 4 +- src/dxvk/shaders/dxvk_mipgen_frag_2d.frag | 4 +- src/dxvk/shaders/dxvk_mipgen_frag_3d.frag | 6 +-- 7 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 8f430ec4..d7d66fce 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -1733,7 +1733,7 @@ namespace dxvk { 0, sizeof(pushConstants), &pushConstants); - m_cmd->cmdDraw(1, passExtent.depth, 0, 0); + m_cmd->cmdDraw(3, passExtent.depth, 0, 0); m_cmd->cmdEndRenderPass(); } diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp index a0de8838..0b1f27ae 100644 --- a/src/dxvk/dxvk_device.cpp +++ b/src/dxvk/dxvk_device.cpp @@ -25,7 +25,7 @@ namespace dxvk { m_metaClearObjects (new DxvkMetaClearObjects (vkd)), m_metaCopyObjects (new DxvkMetaCopyObjects (this)), m_metaResolveObjects(new DxvkMetaResolveObjects (this)), - m_metaMipGenObjects (new DxvkMetaMipGenObjects (vkd)), + m_metaMipGenObjects (new DxvkMetaMipGenObjects (this)), m_metaPackObjects (new DxvkMetaPackObjects (vkd)), m_unboundResources (this), m_submissionQueue (this) { diff --git a/src/dxvk/dxvk_meta_mipgen.cpp b/src/dxvk/dxvk_meta_mipgen.cpp index d0c68497..99ef9690 100644 --- a/src/dxvk/dxvk_meta_mipgen.cpp +++ b/src/dxvk/dxvk_meta_mipgen.cpp @@ -1,7 +1,10 @@ +#include "dxvk_device.h" #include "dxvk_meta_mipgen.h" -#include -#include +#include +#include +#include + #include #include #include @@ -184,15 +187,18 @@ namespace dxvk { } - DxvkMetaMipGenObjects::DxvkMetaMipGenObjects(const Rc& vkd) - : m_vkd (vkd), + DxvkMetaMipGenObjects::DxvkMetaMipGenObjects(const DxvkDevice* device) + : m_vkd (device->vkd()), m_sampler (createSampler()), - m_shaderVert (createShaderModule(dxvk_mipgen_vert)), - m_shaderGeom (createShaderModule(dxvk_mipgen_geom)), m_shaderFrag1D(createShaderModule(dxvk_mipgen_frag_1d)), m_shaderFrag2D(createShaderModule(dxvk_mipgen_frag_2d)), m_shaderFrag3D(createShaderModule(dxvk_mipgen_frag_3d)) { - + if (device->extensions().extShaderViewportIndexLayer) { + m_shaderVert = createShaderModule(dxvk_fullscreen_layer_vert); + } else { + m_shaderVert = createShaderModule(dxvk_fullscreen_vert); + m_shaderGeom = createShaderModule(dxvk_fullscreen_geom); + } } @@ -398,8 +404,9 @@ namespace dxvk { VkPipelineLayout pipelineLayout, VkRenderPass renderPass) const { std::array stages; + uint32_t stageCount = 0; - VkPipelineShaderStageCreateInfo& vsStage = stages[0]; + VkPipelineShaderStageCreateInfo& vsStage = stages[stageCount++]; vsStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; vsStage.pNext = nullptr; vsStage.flags = 0; @@ -408,16 +415,18 @@ namespace dxvk { vsStage.pName = "main"; vsStage.pSpecializationInfo = nullptr; - VkPipelineShaderStageCreateInfo& gsStage = stages[1]; - gsStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - gsStage.pNext = nullptr; - gsStage.flags = 0; - gsStage.stage = VK_SHADER_STAGE_GEOMETRY_BIT; - gsStage.module = m_shaderGeom; - gsStage.pName = "main"; - gsStage.pSpecializationInfo = nullptr; + if (m_shaderGeom) { + VkPipelineShaderStageCreateInfo& gsStage = stages[stageCount++]; + gsStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + gsStage.pNext = nullptr; + gsStage.flags = 0; + gsStage.stage = VK_SHADER_STAGE_GEOMETRY_BIT; + gsStage.module = m_shaderGeom; + gsStage.pName = "main"; + gsStage.pSpecializationInfo = nullptr; + } - VkPipelineShaderStageCreateInfo& psStage = stages[2]; + VkPipelineShaderStageCreateInfo& psStage = stages[stageCount++]; psStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; psStage.pNext = nullptr; psStage.flags = 0; @@ -458,7 +467,7 @@ namespace dxvk { iaState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; iaState.pNext = nullptr; iaState.flags = 0; - iaState.topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + iaState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; iaState.primitiveRestartEnable = VK_FALSE; VkPipelineViewportStateCreateInfo vpState; @@ -525,7 +534,7 @@ namespace dxvk { info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; info.pNext = nullptr; info.flags = 0; - info.stageCount = stages.size(); + info.stageCount = stageCount; info.pStages = stages.data(); info.pVertexInputState = &viState; info.pInputAssemblyState = &iaState; diff --git a/src/dxvk/dxvk_meta_mipgen.h b/src/dxvk/dxvk_meta_mipgen.h index 9f6600ad..8a3a12cb 100644 --- a/src/dxvk/dxvk_meta_mipgen.h +++ b/src/dxvk/dxvk_meta_mipgen.h @@ -165,7 +165,7 @@ namespace dxvk { public: - DxvkMetaMipGenObjects(const Rc& vkd); + DxvkMetaMipGenObjects(const DxvkDevice* device); ~DxvkMetaMipGenObjects(); /** @@ -185,11 +185,11 @@ namespace dxvk { VkSampler m_sampler; - VkShaderModule m_shaderVert; - VkShaderModule m_shaderGeom; - VkShaderModule m_shaderFrag1D; - VkShaderModule m_shaderFrag2D; - VkShaderModule m_shaderFrag3D; + VkShaderModule m_shaderVert = VK_NULL_HANDLE; + VkShaderModule m_shaderGeom = VK_NULL_HANDLE; + VkShaderModule m_shaderFrag1D = VK_NULL_HANDLE; + VkShaderModule m_shaderFrag2D = VK_NULL_HANDLE; + VkShaderModule m_shaderFrag3D = VK_NULL_HANDLE; std::mutex m_mutex; diff --git a/src/dxvk/shaders/dxvk_mipgen_frag_1d.frag b/src/dxvk/shaders/dxvk_mipgen_frag_1d.frag index 0e181951..2f4901c4 100644 --- a/src/dxvk/shaders/dxvk_mipgen_frag_1d.frag +++ b/src/dxvk/shaders/dxvk_mipgen_frag_1d.frag @@ -3,9 +3,9 @@ layout(set = 0, binding = 0) uniform sampler1DArray s_texture; -layout(location = 0) in vec3 i_pos; +layout(location = 0) in vec2 i_pos; layout(location = 0) out vec4 o_color; void main() { - o_color = texture(s_texture, i_pos.xz); + o_color = texture(s_texture, vec2(i_pos.x, gl_Layer)); } \ No newline at end of file diff --git a/src/dxvk/shaders/dxvk_mipgen_frag_2d.frag b/src/dxvk/shaders/dxvk_mipgen_frag_2d.frag index e7a0b082..c6885ed7 100644 --- a/src/dxvk/shaders/dxvk_mipgen_frag_2d.frag +++ b/src/dxvk/shaders/dxvk_mipgen_frag_2d.frag @@ -3,9 +3,9 @@ layout(set = 0, binding = 0) uniform sampler2DArray s_texture; -layout(location = 0) in vec3 i_pos; +layout(location = 0) in vec2 i_pos; layout(location = 0) out vec4 o_color; void main() { - o_color = texture(s_texture, i_pos); + o_color = texture(s_texture, vec3(i_pos, gl_Layer)); } \ No newline at end of file diff --git a/src/dxvk/shaders/dxvk_mipgen_frag_3d.frag b/src/dxvk/shaders/dxvk_mipgen_frag_3d.frag index 42429cd9..12ceef34 100644 --- a/src/dxvk/shaders/dxvk_mipgen_frag_3d.frag +++ b/src/dxvk/shaders/dxvk_mipgen_frag_3d.frag @@ -3,7 +3,7 @@ layout(set = 0, binding = 0) uniform sampler3D s_texture; -layout(location = 0) in vec3 i_pos; +layout(location = 0) in vec2 i_pos; layout(location = 0) out vec4 o_color; layout(push_constant) @@ -12,6 +12,6 @@ uniform push_block { }; void main() { - o_color = texture(s_texture, vec3(i_pos.xy, - (i_pos.z + 0.5f) / float(p_layer_count))); + o_color = texture(s_texture, vec3(i_pos, + (float(gl_Layer) + 0.5f) / float(p_layer_count))); } \ No newline at end of file