summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2020-05-04 23:31:17 +0200
committerReinUsesLisp <reinuseslisp@airmail.cc>2020-05-04 23:31:17 +0200
commit2dbf5290f28efa47b2484537e9316909831fee05 (patch)
tree8532b1b39dc83cb9d6e6460a21b6fbebd3084b65 /src
parentgl_rasterizer: Implement viewport swizzles with NV_viewport_swizzle (diff)
downloadyuzu-2dbf5290f28efa47b2484537e9316909831fee05.tar
yuzu-2dbf5290f28efa47b2484537e9316909831fee05.tar.gz
yuzu-2dbf5290f28efa47b2484537e9316909831fee05.tar.bz2
yuzu-2dbf5290f28efa47b2484537e9316909831fee05.tar.lz
yuzu-2dbf5290f28efa47b2484537e9316909831fee05.tar.xz
yuzu-2dbf5290f28efa47b2484537e9316909831fee05.tar.zst
yuzu-2dbf5290f28efa47b2484537e9316909831fee05.zip
Diffstat (limited to 'src')
-rw-r--r--src/video_core/engines/maxwell_3d.h1
-rw-r--r--src/video_core/renderer_vulkan/fixed_pipeline_state.cpp8
-rw-r--r--src/video_core/renderer_vulkan/fixed_pipeline_state.h7
-rw-r--r--src/video_core/renderer_vulkan/maxwell_to_vk.cpp23
-rw-r--r--src/video_core/renderer_vulkan/maxwell_to_vk.h2
-rw-r--r--src/video_core/renderer_vulkan/vk_device.cpp5
-rw-r--r--src/video_core/renderer_vulkan/vk_device.h6
-rw-r--r--src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp32
8 files changed, 84 insertions, 0 deletions
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h
index 4aeff4cc9..89e29a0d3 100644
--- a/src/video_core/engines/maxwell_3d.h
+++ b/src/video_core/engines/maxwell_3d.h
@@ -630,6 +630,7 @@ public:
f32 translate_y;
f32 translate_z;
union {
+ u32 raw;
BitField<0, 3, ViewportSwizzle> x;
BitField<4, 3, ViewportSwizzle> y;
BitField<8, 3, ViewportSwizzle> z;
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp
index 648b1e71b..6cead3a28 100644
--- a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp
+++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <algorithm>
#include <cstring>
#include <tuple>
@@ -101,6 +102,12 @@ void FixedPipelineState::ColorBlending::Fill(const Maxwell& regs) noexcept {
}
}
+void FixedPipelineState::ViewportSwizzles::Fill(const Maxwell& regs) noexcept {
+ const auto& transform = regs.viewport_transform;
+ std::transform(transform.begin(), transform.end(), swizzles.begin(),
+ [](const auto& viewport) { return static_cast<u16>(viewport.swizzle.raw); });
+}
+
void FixedPipelineState::BlendingAttachment::Fill(const Maxwell& regs, std::size_t index) {
const auto& mask = regs.color_mask[regs.color_mask_common ? 0 : index];
@@ -144,6 +151,7 @@ void FixedPipelineState::Fill(const Maxwell& regs) {
rasterizer.Fill(regs);
depth_stencil.Fill(regs);
color_blending.Fill(regs);
+ viewport_swizzles.Fill(regs);
}
std::size_t FixedPipelineState::Hash() const noexcept {
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.h b/src/video_core/renderer_vulkan/fixed_pipeline_state.h
index 8652067a7..cecaee48d 100644
--- a/src/video_core/renderer_vulkan/fixed_pipeline_state.h
+++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.h
@@ -233,10 +233,17 @@ struct FixedPipelineState {
void Fill(const Maxwell& regs) noexcept;
};
+ struct ViewportSwizzles {
+ std::array<u16, Maxwell::NumViewports> swizzles;
+
+ void Fill(const Maxwell& regs) noexcept;
+ };
+
VertexInput vertex_input;
Rasterizer rasterizer;
DepthStencil depth_stencil;
ColorBlending color_blending;
+ ViewportSwizzles viewport_swizzles;
void Fill(const Maxwell& regs);
diff --git a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
index 8681b821f..850165606 100644
--- a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
+++ b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
@@ -672,4 +672,27 @@ VkComponentSwizzle SwizzleSource(Tegra::Texture::SwizzleSource swizzle) {
return {};
}
+VkViewportCoordinateSwizzleNV ViewportSwizzle(Maxwell::ViewportSwizzle swizzle) {
+ switch (swizzle) {
+ case Maxwell::ViewportSwizzle::PositiveX:
+ return VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_X_NV;
+ case Maxwell::ViewportSwizzle::NegativeX:
+ return VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_X_NV;
+ case Maxwell::ViewportSwizzle::PositiveY:
+ return VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_Y_NV;
+ case Maxwell::ViewportSwizzle::NegativeY:
+ return VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_Y_NV;
+ case Maxwell::ViewportSwizzle::PositiveZ:
+ return VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_Z_NV;
+ case Maxwell::ViewportSwizzle::NegativeZ:
+ return VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_Z_NV;
+ case Maxwell::ViewportSwizzle::PositiveW:
+ return VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_W_NV;
+ case Maxwell::ViewportSwizzle::NegativeW:
+ return VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_W_NV;
+ }
+ UNREACHABLE_MSG("Invalid swizzle={}", static_cast<int>(swizzle));
+ return {};
+}
+
} // namespace Vulkan::MaxwellToVK
diff --git a/src/video_core/renderer_vulkan/maxwell_to_vk.h b/src/video_core/renderer_vulkan/maxwell_to_vk.h
index 81bce4c6c..7e213452f 100644
--- a/src/video_core/renderer_vulkan/maxwell_to_vk.h
+++ b/src/video_core/renderer_vulkan/maxwell_to_vk.h
@@ -59,4 +59,6 @@ VkCullModeFlags CullFace(Maxwell::CullFace cull_face);
VkComponentSwizzle SwizzleSource(Tegra::Texture::SwizzleSource swizzle);
+VkViewportCoordinateSwizzleNV ViewportSwizzle(Maxwell::ViewportSwizzle swizzle);
+
} // namespace Vulkan::MaxwellToVK
diff --git a/src/video_core/renderer_vulkan/vk_device.cpp b/src/video_core/renderer_vulkan/vk_device.cpp
index 0e4bbca97..e1f65e3a7 100644
--- a/src/video_core/renderer_vulkan/vk_device.cpp
+++ b/src/video_core/renderer_vulkan/vk_device.cpp
@@ -260,6 +260,10 @@ bool VKDevice::Create() {
LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively");
}
+ if (!nv_viewport_swizzle) {
+ LOG_INFO(Render_Vulkan, "Device doesn't support viewport swizzles");
+ }
+
VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout;
if (khr_uniform_buffer_standard_layout) {
std430_layout.sType =
@@ -521,6 +525,7 @@ std::vector<const char*> VKDevice::LoadExtensions() {
bool has_ext_subgroup_size_control{};
bool has_ext_transform_feedback{};
for (const auto& extension : physical.EnumerateDeviceExtensionProperties()) {
+ Test(extension, nv_viewport_swizzle, VK_NV_VIEWPORT_SWIZZLE_EXTENSION_NAME, true);
Test(extension, khr_uniform_buffer_standard_layout,
VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_EXTENSION_NAME, true);
Test(extension, has_khr_shader_float16_int8, VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME,
diff --git a/src/video_core/renderer_vulkan/vk_device.h b/src/video_core/renderer_vulkan/vk_device.h
index c8640762d..12b05651b 100644
--- a/src/video_core/renderer_vulkan/vk_device.h
+++ b/src/video_core/renderer_vulkan/vk_device.h
@@ -147,6 +147,11 @@ public:
return is_formatless_image_load_supported;
}
+ /// Returns true if the device supports VK_NV_viewport_swizzle.
+ bool IsNvViewportSwizzleSupported() const {
+ return nv_viewport_swizzle;
+ }
+
/// Returns true if the device supports VK_EXT_scalar_block_layout.
bool IsKhrUniformBufferStandardLayoutSupported() const {
return khr_uniform_buffer_standard_layout;
@@ -222,6 +227,7 @@ private:
bool is_float16_supported{}; ///< Support for float16 arithmetics.
bool is_warp_potentially_bigger{}; ///< Host warp size can be bigger than guest.
bool is_formatless_image_load_supported{}; ///< Support for shader image read without format.
+ bool nv_viewport_swizzle{}; ///< Support for VK_NV_viewport_swizzle.
bool khr_uniform_buffer_standard_layout{}; ///< Support for std430 on UBOs.
bool ext_index_type_uint8{}; ///< Support for VK_EXT_index_type_uint8.
bool ext_depth_range_unrestricted{}; ///< Support for VK_EXT_depth_range_unrestricted.
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
index 1ac981974..5beea6a03 100644
--- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
+++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <algorithm>
#include <array>
#include <cstring>
#include <vector>
@@ -50,6 +51,23 @@ bool SupportsPrimitiveRestart(VkPrimitiveTopology topology) {
topology) == std::end(unsupported_topologies);
}
+VkViewportSwizzleNV UnpackViewportSwizzle(u16 swizzle) {
+ union {
+ u32 raw;
+ BitField<0, 3, Maxwell::ViewportSwizzle> x;
+ BitField<4, 3, Maxwell::ViewportSwizzle> y;
+ BitField<8, 3, Maxwell::ViewportSwizzle> z;
+ BitField<12, 3, Maxwell::ViewportSwizzle> w;
+ } const unpacked{swizzle};
+
+ VkViewportSwizzleNV result;
+ result.x = MaxwellToVK::ViewportSwizzle(unpacked.x);
+ result.y = MaxwellToVK::ViewportSwizzle(unpacked.y);
+ result.z = MaxwellToVK::ViewportSwizzle(unpacked.z);
+ result.w = MaxwellToVK::ViewportSwizzle(unpacked.w);
+ return result;
+}
+
} // Anonymous namespace
VKGraphicsPipeline::VKGraphicsPipeline(const VKDevice& device, VKScheduler& scheduler,
@@ -162,6 +180,7 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const RenderPassParams& renderpa
const auto& ds = fixed_state.depth_stencil;
const auto& cd = fixed_state.color_blending;
const auto& rs = fixed_state.rasterizer;
+ const auto& viewport_swizzles = fixed_state.viewport_swizzles.swizzles;
std::vector<VkVertexInputBindingDescription> vertex_bindings;
std::vector<VkVertexInputBindingDivisorDescriptionEXT> vertex_binding_divisors;
@@ -244,6 +263,19 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const RenderPassParams& renderpa
viewport_ci.scissorCount = Maxwell::NumViewports;
viewport_ci.pScissors = nullptr;
+ std::array<VkViewportSwizzleNV, Maxwell::NumViewports> swizzles;
+ std::transform(viewport_swizzles.begin(), viewport_swizzles.end(), swizzles.begin(),
+ UnpackViewportSwizzle);
+ VkPipelineViewportSwizzleStateCreateInfoNV swizzle_ci;
+ swizzle_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV;
+ swizzle_ci.pNext = nullptr;
+ swizzle_ci.flags = 0;
+ swizzle_ci.viewportCount = Maxwell::NumViewports;
+ swizzle_ci.pViewportSwizzles = swizzles.data();
+ if (device.IsNvViewportSwizzleSupported()) {
+ viewport_ci.pNext = &swizzle_ci;
+ }
+
VkPipelineRasterizationStateCreateInfo rasterization_ci;
rasterization_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
rasterization_ci.pNext = nullptr;