yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

vk_graphics_pipeline: Implement viewport swizzles with NV_viewport_swizzle

This commit is contained in:
ReinUsesLisp 2020-05-04 18:31:17 -03:00
parent f813cd3ff7
commit 2dbf5290f2
8 changed files with 84 additions and 0 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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);

View File

@ -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

View File

@ -59,4 +59,6 @@ VkCullModeFlags CullFace(Maxwell::CullFace cull_face);
VkComponentSwizzle SwizzleSource(Tegra::Texture::SwizzleSource swizzle);
VkViewportCoordinateSwizzleNV ViewportSwizzle(Maxwell::ViewportSwizzle swizzle);
} // namespace Vulkan::MaxwellToVK

View File

@ -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,

View File

@ -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.

View File

@ -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;