diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/maxwell_to_vk.cpp | 483 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/maxwell_to_vk.h | 58 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_device.cpp | 13 |
4 files changed, 553 insertions, 3 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 57f31cd58..dac992d44 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -112,6 +112,8 @@ add_library(video_core STATIC | |||
| 112 | if (ENABLE_VULKAN) | 112 | if (ENABLE_VULKAN) |
| 113 | target_sources(video_core PRIVATE | 113 | target_sources(video_core PRIVATE |
| 114 | renderer_vulkan/declarations.h | 114 | renderer_vulkan/declarations.h |
| 115 | renderer_vulkan/maxwell_to_vk.cpp | ||
| 116 | renderer_vulkan/maxwell_to_vk.h | ||
| 115 | renderer_vulkan/vk_buffer_cache.cpp | 117 | renderer_vulkan/vk_buffer_cache.cpp |
| 116 | renderer_vulkan/vk_buffer_cache.h | 118 | renderer_vulkan/vk_buffer_cache.h |
| 117 | renderer_vulkan/vk_device.cpp | 119 | renderer_vulkan/vk_device.cpp |
diff --git a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp new file mode 100644 index 000000000..34bf26ff2 --- /dev/null +++ b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp | |||
| @@ -0,0 +1,483 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/assert.h" | ||
| 6 | #include "common/common_types.h" | ||
| 7 | #include "common/logging/log.h" | ||
| 8 | #include "video_core/engines/maxwell_3d.h" | ||
| 9 | #include "video_core/renderer_vulkan/declarations.h" | ||
| 10 | #include "video_core/renderer_vulkan/maxwell_to_vk.h" | ||
| 11 | #include "video_core/renderer_vulkan/vk_device.h" | ||
| 12 | #include "video_core/surface.h" | ||
| 13 | |||
| 14 | namespace Vulkan::MaxwellToVK { | ||
| 15 | |||
| 16 | namespace Sampler { | ||
| 17 | |||
| 18 | vk::Filter Filter(Tegra::Texture::TextureFilter filter) { | ||
| 19 | switch (filter) { | ||
| 20 | case Tegra::Texture::TextureFilter::Linear: | ||
| 21 | return vk::Filter::eLinear; | ||
| 22 | case Tegra::Texture::TextureFilter::Nearest: | ||
| 23 | return vk::Filter::eNearest; | ||
| 24 | } | ||
| 25 | UNIMPLEMENTED_MSG("Unimplemented sampler filter={}", static_cast<u32>(filter)); | ||
| 26 | return {}; | ||
| 27 | } | ||
| 28 | |||
| 29 | vk::SamplerMipmapMode MipmapMode(Tegra::Texture::TextureMipmapFilter mipmap_filter) { | ||
| 30 | switch (mipmap_filter) { | ||
| 31 | case Tegra::Texture::TextureMipmapFilter::None: | ||
| 32 | // TODO(Rodrigo): None seems to be mapped to OpenGL's mag and min filters without mipmapping | ||
| 33 | // (e.g. GL_NEAREST and GL_LINEAR). Vulkan doesn't have such a thing, find out if we have to | ||
| 34 | // use an image view with a single mipmap level to emulate this. | ||
| 35 | return vk::SamplerMipmapMode::eLinear; | ||
| 36 | case Tegra::Texture::TextureMipmapFilter::Linear: | ||
| 37 | return vk::SamplerMipmapMode::eLinear; | ||
| 38 | case Tegra::Texture::TextureMipmapFilter::Nearest: | ||
| 39 | return vk::SamplerMipmapMode::eNearest; | ||
| 40 | } | ||
| 41 | UNIMPLEMENTED_MSG("Unimplemented sampler mipmap mode={}", static_cast<u32>(mipmap_filter)); | ||
| 42 | return {}; | ||
| 43 | } | ||
| 44 | |||
| 45 | vk::SamplerAddressMode WrapMode(Tegra::Texture::WrapMode wrap_mode) { | ||
| 46 | switch (wrap_mode) { | ||
| 47 | case Tegra::Texture::WrapMode::Wrap: | ||
| 48 | return vk::SamplerAddressMode::eRepeat; | ||
| 49 | case Tegra::Texture::WrapMode::Mirror: | ||
| 50 | return vk::SamplerAddressMode::eMirroredRepeat; | ||
| 51 | case Tegra::Texture::WrapMode::ClampToEdge: | ||
| 52 | return vk::SamplerAddressMode::eClampToEdge; | ||
| 53 | case Tegra::Texture::WrapMode::Border: | ||
| 54 | return vk::SamplerAddressMode::eClampToBorder; | ||
| 55 | case Tegra::Texture::WrapMode::ClampOGL: | ||
| 56 | // TODO(Rodrigo): GL_CLAMP was removed as of OpenGL 3.1, to implement GL_CLAMP, we can use | ||
| 57 | // eClampToBorder to get the border color of the texture, and then sample the edge to | ||
| 58 | // manually mix them. However the shader part of this is not yet implemented. | ||
| 59 | return vk::SamplerAddressMode::eClampToBorder; | ||
| 60 | case Tegra::Texture::WrapMode::MirrorOnceClampToEdge: | ||
| 61 | return vk::SamplerAddressMode::eMirrorClampToEdge; | ||
| 62 | case Tegra::Texture::WrapMode::MirrorOnceBorder: | ||
| 63 | UNIMPLEMENTED(); | ||
| 64 | return vk::SamplerAddressMode::eMirrorClampToEdge; | ||
| 65 | } | ||
| 66 | UNIMPLEMENTED_MSG("Unimplemented wrap mode={}", static_cast<u32>(wrap_mode)); | ||
| 67 | return {}; | ||
| 68 | } | ||
| 69 | |||
| 70 | vk::CompareOp DepthCompareFunction(Tegra::Texture::DepthCompareFunc depth_compare_func) { | ||
| 71 | switch (depth_compare_func) { | ||
| 72 | case Tegra::Texture::DepthCompareFunc::Never: | ||
| 73 | return vk::CompareOp::eNever; | ||
| 74 | case Tegra::Texture::DepthCompareFunc::Less: | ||
| 75 | return vk::CompareOp::eLess; | ||
| 76 | case Tegra::Texture::DepthCompareFunc::LessEqual: | ||
| 77 | return vk::CompareOp::eLessOrEqual; | ||
| 78 | case Tegra::Texture::DepthCompareFunc::Equal: | ||
| 79 | return vk::CompareOp::eEqual; | ||
| 80 | case Tegra::Texture::DepthCompareFunc::NotEqual: | ||
| 81 | return vk::CompareOp::eNotEqual; | ||
| 82 | case Tegra::Texture::DepthCompareFunc::Greater: | ||
| 83 | return vk::CompareOp::eGreater; | ||
| 84 | case Tegra::Texture::DepthCompareFunc::GreaterEqual: | ||
| 85 | return vk::CompareOp::eGreaterOrEqual; | ||
| 86 | case Tegra::Texture::DepthCompareFunc::Always: | ||
| 87 | return vk::CompareOp::eAlways; | ||
| 88 | } | ||
| 89 | UNIMPLEMENTED_MSG("Unimplemented sampler depth compare function={}", | ||
| 90 | static_cast<u32>(depth_compare_func)); | ||
| 91 | return {}; | ||
| 92 | } | ||
| 93 | |||
| 94 | } // namespace Sampler | ||
| 95 | |||
| 96 | struct FormatTuple { | ||
| 97 | vk::Format format; ///< Vulkan format | ||
| 98 | ComponentType component_type; ///< Abstracted component type | ||
| 99 | bool attachable; ///< True when this format can be used as an attachment | ||
| 100 | }; | ||
| 101 | |||
| 102 | static constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex_format_tuples = {{ | ||
| 103 | {vk::Format::eA8B8G8R8UnormPack32, ComponentType::UNorm, true}, // ABGR8U | ||
| 104 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ABGR8S | ||
| 105 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ABGR8UI | ||
| 106 | {vk::Format::eB5G6R5UnormPack16, ComponentType::UNorm, false}, // B5G6R5U | ||
| 107 | {vk::Format::eA2B10G10R10UnormPack32, ComponentType::UNorm, true}, // A2B10G10R10U | ||
| 108 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // A1B5G5R5U | ||
| 109 | {vk::Format::eR8Unorm, ComponentType::UNorm, true}, // R8U | ||
| 110 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // R8UI | ||
| 111 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RGBA16F | ||
| 112 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RGBA16U | ||
| 113 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RGBA16UI | ||
| 114 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // R11FG11FB10F | ||
| 115 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RGBA32UI | ||
| 116 | {vk::Format::eBc1RgbaUnormBlock, ComponentType::UNorm, false}, // DXT1 | ||
| 117 | {vk::Format::eBc2UnormBlock, ComponentType::UNorm, false}, // DXT23 | ||
| 118 | {vk::Format::eBc3UnormBlock, ComponentType::UNorm, false}, // DXT45 | ||
| 119 | {vk::Format::eBc4UnormBlock, ComponentType::UNorm, false}, // DXN1 | ||
| 120 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // DXN2UNORM | ||
| 121 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // DXN2SNORM | ||
| 122 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // BC7U | ||
| 123 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // BC6H_UF16 | ||
| 124 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // BC6H_SF16 | ||
| 125 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_4X4 | ||
| 126 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // BGRA8 | ||
| 127 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RGBA32F | ||
| 128 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RG32F | ||
| 129 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // R32F | ||
| 130 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // R16F | ||
| 131 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // R16U | ||
| 132 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // R16S | ||
| 133 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // R16UI | ||
| 134 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // R16I | ||
| 135 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RG16 | ||
| 136 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RG16F | ||
| 137 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RG16UI | ||
| 138 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RG16I | ||
| 139 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RG16S | ||
| 140 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RGB32F | ||
| 141 | {vk::Format::eA8B8G8R8SrgbPack32, ComponentType::UNorm, true}, // RGBA8_SRGB | ||
| 142 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RG8U | ||
| 143 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RG8S | ||
| 144 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // RG32UI | ||
| 145 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // R32UI | ||
| 146 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_8X8 | ||
| 147 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_8X5 | ||
| 148 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_5X4 | ||
| 149 | |||
| 150 | // Compressed sRGB formats | ||
| 151 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // BGRA8_SRGB | ||
| 152 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // DXT1_SRGB | ||
| 153 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // DXT23_SRGB | ||
| 154 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // DXT45_SRGB | ||
| 155 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // BC7U_SRGB | ||
| 156 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_4X4_SRGB | ||
| 157 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_8X8_SRGB | ||
| 158 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_8X5_SRGB | ||
| 159 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_5X4_SRGB | ||
| 160 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_5X5 | ||
| 161 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_5X5_SRGB | ||
| 162 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_10X8 | ||
| 163 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // ASTC_2D_10X8_SRGB | ||
| 164 | |||
| 165 | // Depth formats | ||
| 166 | {vk::Format::eD32Sfloat, ComponentType::Float, true}, // Z32F | ||
| 167 | {vk::Format::eD16Unorm, ComponentType::UNorm, true}, // Z16 | ||
| 168 | |||
| 169 | // DepthStencil formats | ||
| 170 | {vk::Format::eD24UnormS8Uint, ComponentType::UNorm, true}, // Z24S8 | ||
| 171 | {vk::Format::eD24UnormS8Uint, ComponentType::UNorm, true}, // S8Z24 (emulated) | ||
| 172 | {vk::Format::eUndefined, ComponentType::Invalid, false}, // Z32FS8 | ||
| 173 | }}; | ||
| 174 | |||
| 175 | static constexpr bool IsZetaFormat(PixelFormat pixel_format) { | ||
| 176 | return pixel_format >= PixelFormat::MaxColorFormat && | ||
| 177 | pixel_format < PixelFormat::MaxDepthStencilFormat; | ||
| 178 | } | ||
| 179 | |||
| 180 | std::pair<vk::Format, bool> SurfaceFormat(const VKDevice& device, FormatType format_type, | ||
| 181 | PixelFormat pixel_format, ComponentType component_type) { | ||
| 182 | ASSERT(static_cast<std::size_t>(pixel_format) < tex_format_tuples.size()); | ||
| 183 | |||
| 184 | const auto tuple = tex_format_tuples[static_cast<u32>(pixel_format)]; | ||
| 185 | UNIMPLEMENTED_IF_MSG(tuple.format == vk::Format::eUndefined, | ||
| 186 | "Unimplemented texture format with pixel format={} and component type={}", | ||
| 187 | static_cast<u32>(pixel_format), static_cast<u32>(component_type)); | ||
| 188 | ASSERT_MSG(component_type == tuple.component_type, "Component type mismatch"); | ||
| 189 | |||
| 190 | auto usage = vk::FormatFeatureFlagBits::eSampledImage | | ||
| 191 | vk::FormatFeatureFlagBits::eTransferDst | vk::FormatFeatureFlagBits::eTransferSrc; | ||
| 192 | if (tuple.attachable) { | ||
| 193 | usage |= IsZetaFormat(pixel_format) ? vk::FormatFeatureFlagBits::eDepthStencilAttachment | ||
| 194 | : vk::FormatFeatureFlagBits::eColorAttachment; | ||
| 195 | } | ||
| 196 | return {device.GetSupportedFormat(tuple.format, usage, format_type), tuple.attachable}; | ||
| 197 | } | ||
| 198 | |||
| 199 | vk::ShaderStageFlagBits ShaderStage(Maxwell::ShaderStage stage) { | ||
| 200 | switch (stage) { | ||
| 201 | case Maxwell::ShaderStage::Vertex: | ||
| 202 | return vk::ShaderStageFlagBits::eVertex; | ||
| 203 | case Maxwell::ShaderStage::TesselationControl: | ||
| 204 | return vk::ShaderStageFlagBits::eTessellationControl; | ||
| 205 | case Maxwell::ShaderStage::TesselationEval: | ||
| 206 | return vk::ShaderStageFlagBits::eTessellationEvaluation; | ||
| 207 | case Maxwell::ShaderStage::Geometry: | ||
| 208 | return vk::ShaderStageFlagBits::eGeometry; | ||
| 209 | case Maxwell::ShaderStage::Fragment: | ||
| 210 | return vk::ShaderStageFlagBits::eFragment; | ||
| 211 | } | ||
| 212 | UNIMPLEMENTED_MSG("Unimplemented shader stage={}", static_cast<u32>(stage)); | ||
| 213 | return {}; | ||
| 214 | } | ||
| 215 | |||
| 216 | vk::PrimitiveTopology PrimitiveTopology(Maxwell::PrimitiveTopology topology) { | ||
| 217 | switch (topology) { | ||
| 218 | case Maxwell::PrimitiveTopology::Points: | ||
| 219 | return vk::PrimitiveTopology::ePointList; | ||
| 220 | case Maxwell::PrimitiveTopology::Lines: | ||
| 221 | return vk::PrimitiveTopology::eLineList; | ||
| 222 | case Maxwell::PrimitiveTopology::LineStrip: | ||
| 223 | return vk::PrimitiveTopology::eLineStrip; | ||
| 224 | case Maxwell::PrimitiveTopology::Triangles: | ||
| 225 | return vk::PrimitiveTopology::eTriangleList; | ||
| 226 | case Maxwell::PrimitiveTopology::TriangleStrip: | ||
| 227 | return vk::PrimitiveTopology::eTriangleStrip; | ||
| 228 | } | ||
| 229 | UNIMPLEMENTED_MSG("Unimplemented topology={}", static_cast<u32>(topology)); | ||
| 230 | return {}; | ||
| 231 | } | ||
| 232 | |||
| 233 | vk::Format VertexFormat(Maxwell::VertexAttribute::Type type, Maxwell::VertexAttribute::Size size) { | ||
| 234 | switch (type) { | ||
| 235 | case Maxwell::VertexAttribute::Type::SignedNorm: | ||
| 236 | break; | ||
| 237 | case Maxwell::VertexAttribute::Type::UnsignedNorm: | ||
| 238 | switch (size) { | ||
| 239 | case Maxwell::VertexAttribute::Size::Size_8_8_8_8: | ||
| 240 | return vk::Format::eR8G8B8A8Unorm; | ||
| 241 | default: | ||
| 242 | break; | ||
| 243 | } | ||
| 244 | break; | ||
| 245 | case Maxwell::VertexAttribute::Type::SignedInt: | ||
| 246 | break; | ||
| 247 | case Maxwell::VertexAttribute::Type::UnsignedInt: | ||
| 248 | switch (size) { | ||
| 249 | case Maxwell::VertexAttribute::Size::Size_32: | ||
| 250 | return vk::Format::eR32Uint; | ||
| 251 | default: | ||
| 252 | break; | ||
| 253 | } | ||
| 254 | case Maxwell::VertexAttribute::Type::UnsignedScaled: | ||
| 255 | case Maxwell::VertexAttribute::Type::SignedScaled: | ||
| 256 | break; | ||
| 257 | case Maxwell::VertexAttribute::Type::Float: | ||
| 258 | switch (size) { | ||
| 259 | case Maxwell::VertexAttribute::Size::Size_32_32_32_32: | ||
| 260 | return vk::Format::eR32G32B32A32Sfloat; | ||
| 261 | case Maxwell::VertexAttribute::Size::Size_32_32_32: | ||
| 262 | return vk::Format::eR32G32B32Sfloat; | ||
| 263 | case Maxwell::VertexAttribute::Size::Size_32_32: | ||
| 264 | return vk::Format::eR32G32Sfloat; | ||
| 265 | case Maxwell::VertexAttribute::Size::Size_32: | ||
| 266 | return vk::Format::eR32Sfloat; | ||
| 267 | default: | ||
| 268 | break; | ||
| 269 | } | ||
| 270 | break; | ||
| 271 | } | ||
| 272 | UNIMPLEMENTED_MSG("Unimplemented vertex format of type={} and size={}", static_cast<u32>(type), | ||
| 273 | static_cast<u32>(size)); | ||
| 274 | return {}; | ||
| 275 | } | ||
| 276 | |||
| 277 | vk::CompareOp ComparisonOp(Maxwell::ComparisonOp comparison) { | ||
| 278 | switch (comparison) { | ||
| 279 | case Maxwell::ComparisonOp::Never: | ||
| 280 | case Maxwell::ComparisonOp::NeverOld: | ||
| 281 | return vk::CompareOp::eNever; | ||
| 282 | case Maxwell::ComparisonOp::Less: | ||
| 283 | case Maxwell::ComparisonOp::LessOld: | ||
| 284 | return vk::CompareOp::eLess; | ||
| 285 | case Maxwell::ComparisonOp::Equal: | ||
| 286 | case Maxwell::ComparisonOp::EqualOld: | ||
| 287 | return vk::CompareOp::eEqual; | ||
| 288 | case Maxwell::ComparisonOp::LessEqual: | ||
| 289 | case Maxwell::ComparisonOp::LessEqualOld: | ||
| 290 | return vk::CompareOp::eLessOrEqual; | ||
| 291 | case Maxwell::ComparisonOp::Greater: | ||
| 292 | case Maxwell::ComparisonOp::GreaterOld: | ||
| 293 | return vk::CompareOp::eGreater; | ||
| 294 | case Maxwell::ComparisonOp::NotEqual: | ||
| 295 | case Maxwell::ComparisonOp::NotEqualOld: | ||
| 296 | return vk::CompareOp::eNotEqual; | ||
| 297 | case Maxwell::ComparisonOp::GreaterEqual: | ||
| 298 | case Maxwell::ComparisonOp::GreaterEqualOld: | ||
| 299 | return vk::CompareOp::eGreaterOrEqual; | ||
| 300 | case Maxwell::ComparisonOp::Always: | ||
| 301 | case Maxwell::ComparisonOp::AlwaysOld: | ||
| 302 | return vk::CompareOp::eAlways; | ||
| 303 | } | ||
| 304 | UNIMPLEMENTED_MSG("Unimplemented comparison op={}", static_cast<u32>(comparison)); | ||
| 305 | return {}; | ||
| 306 | } | ||
| 307 | |||
| 308 | vk::IndexType IndexFormat(Maxwell::IndexFormat index_format) { | ||
| 309 | switch (index_format) { | ||
| 310 | case Maxwell::IndexFormat::UnsignedByte: | ||
| 311 | UNIMPLEMENTED_MSG("Vulkan does not support native u8 index format"); | ||
| 312 | return vk::IndexType::eUint16; | ||
| 313 | case Maxwell::IndexFormat::UnsignedShort: | ||
| 314 | return vk::IndexType::eUint16; | ||
| 315 | case Maxwell::IndexFormat::UnsignedInt: | ||
| 316 | return vk::IndexType::eUint32; | ||
| 317 | } | ||
| 318 | UNIMPLEMENTED_MSG("Unimplemented index_format={}", static_cast<u32>(index_format)); | ||
| 319 | return {}; | ||
| 320 | } | ||
| 321 | |||
| 322 | vk::StencilOp StencilOp(Maxwell::StencilOp stencil_op) { | ||
| 323 | switch (stencil_op) { | ||
| 324 | case Maxwell::StencilOp::Keep: | ||
| 325 | case Maxwell::StencilOp::KeepOGL: | ||
| 326 | return vk::StencilOp::eKeep; | ||
| 327 | case Maxwell::StencilOp::Zero: | ||
| 328 | case Maxwell::StencilOp::ZeroOGL: | ||
| 329 | return vk::StencilOp::eZero; | ||
| 330 | case Maxwell::StencilOp::Replace: | ||
| 331 | case Maxwell::StencilOp::ReplaceOGL: | ||
| 332 | return vk::StencilOp::eReplace; | ||
| 333 | case Maxwell::StencilOp::Incr: | ||
| 334 | case Maxwell::StencilOp::IncrOGL: | ||
| 335 | return vk::StencilOp::eIncrementAndClamp; | ||
| 336 | case Maxwell::StencilOp::Decr: | ||
| 337 | case Maxwell::StencilOp::DecrOGL: | ||
| 338 | return vk::StencilOp::eDecrementAndClamp; | ||
| 339 | case Maxwell::StencilOp::Invert: | ||
| 340 | case Maxwell::StencilOp::InvertOGL: | ||
| 341 | return vk::StencilOp::eInvert; | ||
| 342 | case Maxwell::StencilOp::IncrWrap: | ||
| 343 | case Maxwell::StencilOp::IncrWrapOGL: | ||
| 344 | return vk::StencilOp::eIncrementAndWrap; | ||
| 345 | case Maxwell::StencilOp::DecrWrap: | ||
| 346 | case Maxwell::StencilOp::DecrWrapOGL: | ||
| 347 | return vk::StencilOp::eDecrementAndWrap; | ||
| 348 | } | ||
| 349 | UNIMPLEMENTED_MSG("Unimplemented stencil op={}", static_cast<u32>(stencil_op)); | ||
| 350 | return {}; | ||
| 351 | } | ||
| 352 | |||
| 353 | vk::BlendOp BlendEquation(Maxwell::Blend::Equation equation) { | ||
| 354 | switch (equation) { | ||
| 355 | case Maxwell::Blend::Equation::Add: | ||
| 356 | case Maxwell::Blend::Equation::AddGL: | ||
| 357 | return vk::BlendOp::eAdd; | ||
| 358 | case Maxwell::Blend::Equation::Subtract: | ||
| 359 | case Maxwell::Blend::Equation::SubtractGL: | ||
| 360 | return vk::BlendOp::eSubtract; | ||
| 361 | case Maxwell::Blend::Equation::ReverseSubtract: | ||
| 362 | case Maxwell::Blend::Equation::ReverseSubtractGL: | ||
| 363 | return vk::BlendOp::eReverseSubtract; | ||
| 364 | case Maxwell::Blend::Equation::Min: | ||
| 365 | case Maxwell::Blend::Equation::MinGL: | ||
| 366 | return vk::BlendOp::eMin; | ||
| 367 | case Maxwell::Blend::Equation::Max: | ||
| 368 | case Maxwell::Blend::Equation::MaxGL: | ||
| 369 | return vk::BlendOp::eMax; | ||
| 370 | } | ||
| 371 | UNIMPLEMENTED_MSG("Unimplemented blend equation={}", static_cast<u32>(equation)); | ||
| 372 | return {}; | ||
| 373 | } | ||
| 374 | |||
| 375 | vk::BlendFactor BlendFactor(Maxwell::Blend::Factor factor) { | ||
| 376 | switch (factor) { | ||
| 377 | case Maxwell::Blend::Factor::Zero: | ||
| 378 | case Maxwell::Blend::Factor::ZeroGL: | ||
| 379 | return vk::BlendFactor::eZero; | ||
| 380 | case Maxwell::Blend::Factor::One: | ||
| 381 | case Maxwell::Blend::Factor::OneGL: | ||
| 382 | return vk::BlendFactor::eOne; | ||
| 383 | case Maxwell::Blend::Factor::SourceColor: | ||
| 384 | case Maxwell::Blend::Factor::SourceColorGL: | ||
| 385 | return vk::BlendFactor::eSrcColor; | ||
| 386 | case Maxwell::Blend::Factor::OneMinusSourceColor: | ||
| 387 | case Maxwell::Blend::Factor::OneMinusSourceColorGL: | ||
| 388 | return vk::BlendFactor::eOneMinusSrcColor; | ||
| 389 | case Maxwell::Blend::Factor::SourceAlpha: | ||
| 390 | case Maxwell::Blend::Factor::SourceAlphaGL: | ||
| 391 | return vk::BlendFactor::eSrcAlpha; | ||
| 392 | case Maxwell::Blend::Factor::OneMinusSourceAlpha: | ||
| 393 | case Maxwell::Blend::Factor::OneMinusSourceAlphaGL: | ||
| 394 | return vk::BlendFactor::eOneMinusSrcAlpha; | ||
| 395 | case Maxwell::Blend::Factor::DestAlpha: | ||
| 396 | case Maxwell::Blend::Factor::DestAlphaGL: | ||
| 397 | return vk::BlendFactor::eDstAlpha; | ||
| 398 | case Maxwell::Blend::Factor::OneMinusDestAlpha: | ||
| 399 | case Maxwell::Blend::Factor::OneMinusDestAlphaGL: | ||
| 400 | return vk::BlendFactor::eOneMinusDstAlpha; | ||
| 401 | case Maxwell::Blend::Factor::DestColor: | ||
| 402 | case Maxwell::Blend::Factor::DestColorGL: | ||
| 403 | return vk::BlendFactor::eDstColor; | ||
| 404 | case Maxwell::Blend::Factor::OneMinusDestColor: | ||
| 405 | case Maxwell::Blend::Factor::OneMinusDestColorGL: | ||
| 406 | return vk::BlendFactor::eOneMinusDstColor; | ||
| 407 | case Maxwell::Blend::Factor::SourceAlphaSaturate: | ||
| 408 | case Maxwell::Blend::Factor::SourceAlphaSaturateGL: | ||
| 409 | return vk::BlendFactor::eSrcAlphaSaturate; | ||
| 410 | case Maxwell::Blend::Factor::Source1Color: | ||
| 411 | case Maxwell::Blend::Factor::Source1ColorGL: | ||
| 412 | return vk::BlendFactor::eSrc1Color; | ||
| 413 | case Maxwell::Blend::Factor::OneMinusSource1Color: | ||
| 414 | case Maxwell::Blend::Factor::OneMinusSource1ColorGL: | ||
| 415 | return vk::BlendFactor::eOneMinusSrc1Color; | ||
| 416 | case Maxwell::Blend::Factor::Source1Alpha: | ||
| 417 | case Maxwell::Blend::Factor::Source1AlphaGL: | ||
| 418 | return vk::BlendFactor::eSrc1Alpha; | ||
| 419 | case Maxwell::Blend::Factor::OneMinusSource1Alpha: | ||
| 420 | case Maxwell::Blend::Factor::OneMinusSource1AlphaGL: | ||
| 421 | return vk::BlendFactor::eOneMinusSrc1Alpha; | ||
| 422 | case Maxwell::Blend::Factor::ConstantColor: | ||
| 423 | case Maxwell::Blend::Factor::ConstantColorGL: | ||
| 424 | return vk::BlendFactor::eConstantColor; | ||
| 425 | case Maxwell::Blend::Factor::OneMinusConstantColor: | ||
| 426 | case Maxwell::Blend::Factor::OneMinusConstantColorGL: | ||
| 427 | return vk::BlendFactor::eOneMinusConstantColor; | ||
| 428 | case Maxwell::Blend::Factor::ConstantAlpha: | ||
| 429 | case Maxwell::Blend::Factor::ConstantAlphaGL: | ||
| 430 | return vk::BlendFactor::eConstantAlpha; | ||
| 431 | case Maxwell::Blend::Factor::OneMinusConstantAlpha: | ||
| 432 | case Maxwell::Blend::Factor::OneMinusConstantAlphaGL: | ||
| 433 | return vk::BlendFactor::eOneMinusConstantAlpha; | ||
| 434 | } | ||
| 435 | UNIMPLEMENTED_MSG("Unimplemented blend factor={}", static_cast<u32>(factor)); | ||
| 436 | return {}; | ||
| 437 | } | ||
| 438 | |||
| 439 | vk::FrontFace FrontFace(Maxwell::Cull::FrontFace front_face) { | ||
| 440 | switch (front_face) { | ||
| 441 | case Maxwell::Cull::FrontFace::ClockWise: | ||
| 442 | return vk::FrontFace::eClockwise; | ||
| 443 | case Maxwell::Cull::FrontFace::CounterClockWise: | ||
| 444 | return vk::FrontFace::eCounterClockwise; | ||
| 445 | } | ||
| 446 | UNIMPLEMENTED_MSG("Unimplemented front face={}", static_cast<u32>(front_face)); | ||
| 447 | return {}; | ||
| 448 | } | ||
| 449 | |||
| 450 | vk::CullModeFlags CullFace(Maxwell::Cull::CullFace cull_face) { | ||
| 451 | switch (cull_face) { | ||
| 452 | case Maxwell::Cull::CullFace::Front: | ||
| 453 | return vk::CullModeFlagBits::eFront; | ||
| 454 | case Maxwell::Cull::CullFace::Back: | ||
| 455 | return vk::CullModeFlagBits::eBack; | ||
| 456 | case Maxwell::Cull::CullFace::FrontAndBack: | ||
| 457 | return vk::CullModeFlagBits::eFrontAndBack; | ||
| 458 | } | ||
| 459 | UNIMPLEMENTED_MSG("Unimplemented cull face={}", static_cast<u32>(cull_face)); | ||
| 460 | return {}; | ||
| 461 | } | ||
| 462 | |||
| 463 | vk::ComponentSwizzle SwizzleSource(Tegra::Texture::SwizzleSource swizzle) { | ||
| 464 | switch (swizzle) { | ||
| 465 | case Tegra::Texture::SwizzleSource::Zero: | ||
| 466 | return vk::ComponentSwizzle::eZero; | ||
| 467 | case Tegra::Texture::SwizzleSource::R: | ||
| 468 | return vk::ComponentSwizzle::eR; | ||
| 469 | case Tegra::Texture::SwizzleSource::G: | ||
| 470 | return vk::ComponentSwizzle::eG; | ||
| 471 | case Tegra::Texture::SwizzleSource::B: | ||
| 472 | return vk::ComponentSwizzle::eB; | ||
| 473 | case Tegra::Texture::SwizzleSource::A: | ||
| 474 | return vk::ComponentSwizzle::eA; | ||
| 475 | case Tegra::Texture::SwizzleSource::OneInt: | ||
| 476 | case Tegra::Texture::SwizzleSource::OneFloat: | ||
| 477 | return vk::ComponentSwizzle::eOne; | ||
| 478 | } | ||
| 479 | UNIMPLEMENTED_MSG("Unimplemented swizzle source={}", static_cast<u32>(swizzle)); | ||
| 480 | return {}; | ||
| 481 | } | ||
| 482 | |||
| 483 | } // 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 new file mode 100644 index 000000000..4cadc0721 --- /dev/null +++ b/src/video_core/renderer_vulkan/maxwell_to_vk.h | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <utility> | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "video_core/engines/maxwell_3d.h" | ||
| 10 | #include "video_core/renderer_vulkan/declarations.h" | ||
| 11 | #include "video_core/renderer_vulkan/vk_device.h" | ||
| 12 | #include "video_core/surface.h" | ||
| 13 | #include "video_core/textures/texture.h" | ||
| 14 | |||
| 15 | namespace Vulkan::MaxwellToVK { | ||
| 16 | |||
| 17 | using Maxwell = Tegra::Engines::Maxwell3D::Regs; | ||
| 18 | using PixelFormat = VideoCore::Surface::PixelFormat; | ||
| 19 | using ComponentType = VideoCore::Surface::ComponentType; | ||
| 20 | |||
| 21 | namespace Sampler { | ||
| 22 | |||
| 23 | vk::Filter Filter(Tegra::Texture::TextureFilter filter); | ||
| 24 | |||
| 25 | vk::SamplerMipmapMode MipmapMode(Tegra::Texture::TextureMipmapFilter mipmap_filter); | ||
| 26 | |||
| 27 | vk::SamplerAddressMode WrapMode(Tegra::Texture::WrapMode wrap_mode); | ||
| 28 | |||
| 29 | vk::CompareOp DepthCompareFunction(Tegra::Texture::DepthCompareFunc depth_compare_func); | ||
| 30 | |||
| 31 | } // namespace Sampler | ||
| 32 | |||
| 33 | std::pair<vk::Format, bool> SurfaceFormat(const VKDevice& device, FormatType format_type, | ||
| 34 | PixelFormat pixel_format, ComponentType component_type); | ||
| 35 | |||
| 36 | vk::ShaderStageFlagBits ShaderStage(Maxwell::ShaderStage stage); | ||
| 37 | |||
| 38 | vk::PrimitiveTopology PrimitiveTopology(Maxwell::PrimitiveTopology topology); | ||
| 39 | |||
| 40 | vk::Format VertexFormat(Maxwell::VertexAttribute::Type type, Maxwell::VertexAttribute::Size size); | ||
| 41 | |||
| 42 | vk::CompareOp ComparisonOp(Maxwell::ComparisonOp comparison); | ||
| 43 | |||
| 44 | vk::IndexType IndexFormat(Maxwell::IndexFormat index_format); | ||
| 45 | |||
| 46 | vk::StencilOp StencilOp(Maxwell::StencilOp stencil_op); | ||
| 47 | |||
| 48 | vk::BlendOp BlendEquation(Maxwell::Blend::Equation equation); | ||
| 49 | |||
| 50 | vk::BlendFactor BlendFactor(Maxwell::Blend::Factor factor); | ||
| 51 | |||
| 52 | vk::FrontFace FrontFace(Maxwell::Cull::FrontFace front_face); | ||
| 53 | |||
| 54 | vk::CullModeFlags CullFace(Maxwell::Cull::CullFace cull_face); | ||
| 55 | |||
| 56 | vk::ComponentSwizzle SwizzleSource(Tegra::Texture::SwizzleSource swizzle); | ||
| 57 | |||
| 58 | } // namespace Vulkan::MaxwellToVK | ||
diff --git a/src/video_core/renderer_vulkan/vk_device.cpp b/src/video_core/renderer_vulkan/vk_device.cpp index 78a4e5f0e..00242ecbe 100644 --- a/src/video_core/renderer_vulkan/vk_device.cpp +++ b/src/video_core/renderer_vulkan/vk_device.cpp | |||
| @@ -122,8 +122,7 @@ bool VKDevice::IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlag | |||
| 122 | FormatType format_type) const { | 122 | FormatType format_type) const { |
| 123 | const auto it = format_properties.find(wanted_format); | 123 | const auto it = format_properties.find(wanted_format); |
| 124 | if (it == format_properties.end()) { | 124 | if (it == format_properties.end()) { |
| 125 | LOG_CRITICAL(Render_Vulkan, "Unimplemented format query={}", | 125 | LOG_CRITICAL(Render_Vulkan, "Unimplemented format query={}", vk::to_string(wanted_format)); |
| 126 | static_cast<u32>(wanted_format)); | ||
| 127 | UNREACHABLE(); | 126 | UNREACHABLE(); |
| 128 | return true; | 127 | return true; |
| 129 | } | 128 | } |
| @@ -219,11 +218,19 @@ std::map<vk::Format, vk::FormatProperties> VKDevice::GetFormatProperties( | |||
| 219 | format_properties.emplace(format, physical.getFormatProperties(format, dldi)); | 218 | format_properties.emplace(format, physical.getFormatProperties(format, dldi)); |
| 220 | }; | 219 | }; |
| 221 | AddFormatQuery(vk::Format::eA8B8G8R8UnormPack32); | 220 | AddFormatQuery(vk::Format::eA8B8G8R8UnormPack32); |
| 222 | AddFormatQuery(vk::Format::eR5G6B5UnormPack16); | 221 | AddFormatQuery(vk::Format::eB5G6R5UnormPack16); |
| 222 | AddFormatQuery(vk::Format::eA2B10G10R10UnormPack32); | ||
| 223 | AddFormatQuery(vk::Format::eR8G8B8A8Srgb); | ||
| 224 | AddFormatQuery(vk::Format::eR8Unorm); | ||
| 223 | AddFormatQuery(vk::Format::eD32Sfloat); | 225 | AddFormatQuery(vk::Format::eD32Sfloat); |
| 226 | AddFormatQuery(vk::Format::eD16Unorm); | ||
| 224 | AddFormatQuery(vk::Format::eD16UnormS8Uint); | 227 | AddFormatQuery(vk::Format::eD16UnormS8Uint); |
| 225 | AddFormatQuery(vk::Format::eD24UnormS8Uint); | 228 | AddFormatQuery(vk::Format::eD24UnormS8Uint); |
| 226 | AddFormatQuery(vk::Format::eD32SfloatS8Uint); | 229 | AddFormatQuery(vk::Format::eD32SfloatS8Uint); |
| 230 | AddFormatQuery(vk::Format::eBc1RgbaUnormBlock); | ||
| 231 | AddFormatQuery(vk::Format::eBc2UnormBlock); | ||
| 232 | AddFormatQuery(vk::Format::eBc3UnormBlock); | ||
| 233 | AddFormatQuery(vk::Format::eBc4UnormBlock); | ||
| 227 | 234 | ||
| 228 | return format_properties; | 235 | return format_properties; |
| 229 | } | 236 | } |