From 4484e8c3f0eec1852229003c2179cac2d329d4ad Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 19 Mar 2016 18:12:43 +0100 Subject: [PATCH] vulkan: Move vk_wrap_mode and max_aniso to vkFormat --- rpcs3/Emu/RSX/VK/VKFormats.cpp | 34 ++++++++++++++++++++++++++ rpcs3/Emu/RSX/VK/VKFormats.h | 2 ++ rpcs3/Emu/RSX/VK/VKHelpers.h | 3 --- rpcs3/Emu/RSX/VK/VKTexture.cpp | 44 ++++------------------------------ 4 files changed, 41 insertions(+), 42 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/VKFormats.cpp b/rpcs3/Emu/RSX/VK/VKFormats.cpp index c0b95dd11b..54b46445f4 100644 --- a/rpcs3/Emu/RSX/VK/VKFormats.cpp +++ b/rpcs3/Emu/RSX/VK/VKFormats.cpp @@ -39,4 +39,38 @@ VkFormat get_compatible_depth_surface_format(const gpu_formats_support &support, throw EXCEPTION("Invalid format (0x%x)", format); } +VkSamplerAddressMode vk_wrap_mode(u32 gcm_wrap) +{ + switch (gcm_wrap) + { + case CELL_GCM_TEXTURE_WRAP: return VK_SAMPLER_ADDRESS_MODE_REPEAT; + case CELL_GCM_TEXTURE_MIRROR: return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; + case CELL_GCM_TEXTURE_CLAMP_TO_EDGE: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + case CELL_GCM_TEXTURE_BORDER: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; + case CELL_GCM_TEXTURE_CLAMP: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP_TO_EDGE: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; + case CELL_GCM_TEXTURE_MIRROR_ONCE_BORDER: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; + case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; + default: + throw EXCEPTION("unhandled texture clamp mode 0x%X", gcm_wrap); + } +} + +float max_aniso(u32 gcm_aniso) +{ + switch (gcm_aniso) + { + case CELL_GCM_TEXTURE_MAX_ANISO_1: return 1.0f; + case CELL_GCM_TEXTURE_MAX_ANISO_2: return 2.0f; + case CELL_GCM_TEXTURE_MAX_ANISO_4: return 4.0f; + case CELL_GCM_TEXTURE_MAX_ANISO_6: return 6.0f; + case CELL_GCM_TEXTURE_MAX_ANISO_8: return 8.0f; + case CELL_GCM_TEXTURE_MAX_ANISO_10: return 10.0f; + case CELL_GCM_TEXTURE_MAX_ANISO_12: return 12.0f; + case CELL_GCM_TEXTURE_MAX_ANISO_16: return 16.0f; + } + + throw EXCEPTION("Texture anisotropy error: bad max aniso (%d).", gcm_aniso); +} + } \ No newline at end of file diff --git a/rpcs3/Emu/RSX/VK/VKFormats.h b/rpcs3/Emu/RSX/VK/VKFormats.h index 3b69c68316..f8d111adfe 100644 --- a/rpcs3/Emu/RSX/VK/VKFormats.h +++ b/rpcs3/Emu/RSX/VK/VKFormats.h @@ -11,4 +11,6 @@ namespace vk gpu_formats_support get_optimal_tiling_supported_formats(VkPhysicalDevice physical_device); VkFormat get_compatible_depth_surface_format(const gpu_formats_support &support, rsx::surface_depth_format format); + VkSamplerAddressMode vk_wrap_mode(u32 gcm_wrap); + float max_aniso(u32 gcm_aniso); } \ No newline at end of file diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.h b/rpcs3/Emu/RSX/VK/VKHelpers.h index 49572bd79f..b94f9125ee 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.h +++ b/rpcs3/Emu/RSX/VK/VKHelpers.h @@ -357,9 +357,6 @@ namespace vk vk::texture *staging_texture = nullptr; bool ready = false; - - VkSamplerAddressMode vk_wrap_mode(u32 gcm_wrap_mode); - float max_aniso(u32 gcm_aniso); void sampler_setup(rsx::texture& tex, VkImageViewType type, VkComponentMapping swizzle); public: diff --git a/rpcs3/Emu/RSX/VK/VKTexture.cpp b/rpcs3/Emu/RSX/VK/VKTexture.cpp index 7a919a18e5..301bbd9ccf 100644 --- a/rpcs3/Emu/RSX/VK/VKTexture.cpp +++ b/rpcs3/Emu/RSX/VK/VKTexture.cpp @@ -5,6 +5,7 @@ #include "../RSXTexture.h" #include "../rsx_utils.h" #include "../Common/TextureUtils.h" +#include "VKFormats.h" namespace vk { @@ -268,46 +269,11 @@ namespace vk create(device, format, usage, tiling, width, height, mipmaps, gpu_only, swizzle); } - VkSamplerAddressMode texture::vk_wrap_mode(u32 gcm_wrap) - { - switch (gcm_wrap) - { - case CELL_GCM_TEXTURE_WRAP: return VK_SAMPLER_ADDRESS_MODE_REPEAT; - case CELL_GCM_TEXTURE_MIRROR: return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; - case CELL_GCM_TEXTURE_CLAMP_TO_EDGE: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - case CELL_GCM_TEXTURE_BORDER: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; - case CELL_GCM_TEXTURE_CLAMP: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP_TO_EDGE: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; - case CELL_GCM_TEXTURE_MIRROR_ONCE_BORDER: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; - case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE; - default: - throw EXCEPTION("unhandled texture clamp mode 0x%X", gcm_wrap); - } - } - - float texture::max_aniso(u32 gcm_aniso) - { - switch (gcm_aniso) - { - case CELL_GCM_TEXTURE_MAX_ANISO_1: return 1.0f; - case CELL_GCM_TEXTURE_MAX_ANISO_2: return 2.0f; - case CELL_GCM_TEXTURE_MAX_ANISO_4: return 4.0f; - case CELL_GCM_TEXTURE_MAX_ANISO_6: return 6.0f; - case CELL_GCM_TEXTURE_MAX_ANISO_8: return 8.0f; - case CELL_GCM_TEXTURE_MAX_ANISO_10: return 10.0f; - case CELL_GCM_TEXTURE_MAX_ANISO_12: return 12.0f; - case CELL_GCM_TEXTURE_MAX_ANISO_16: return 16.0f; - } - - LOG_ERROR(RSX, "Texture anisotropy error: bad max aniso (%d).", gcm_aniso); - return 1.0f; - } - void texture::sampler_setup(rsx::texture &tex, VkImageViewType type, VkComponentMapping swizzle) { - VkSamplerAddressMode clamp_s = vk_wrap_mode(tex.wrap_s()); - VkSamplerAddressMode clamp_t = vk_wrap_mode(tex.wrap_t()); - VkSamplerAddressMode clamp_r = vk_wrap_mode(tex.wrap_r()); + VkSamplerAddressMode clamp_s = vk::vk_wrap_mode(tex.wrap_s()); + VkSamplerAddressMode clamp_t = vk::vk_wrap_mode(tex.wrap_t()); + VkSamplerAddressMode clamp_r = vk::vk_wrap_mode(tex.wrap_r()); VkSamplerCreateInfo sampler_info = {}; sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; @@ -318,7 +284,7 @@ namespace vk sampler_info.compareEnable = VK_FALSE; sampler_info.unnormalizedCoordinates = !!(tex.format() & CELL_GCM_TEXTURE_UN); sampler_info.mipLodBias = tex.bias(); - sampler_info.maxAnisotropy = max_aniso(tex.max_aniso()); + sampler_info.maxAnisotropy = vk::max_aniso(tex.max_aniso()); sampler_info.maxLod = tex.max_lod(); sampler_info.minLod = tex.min_lod(); sampler_info.magFilter = VK_FILTER_LINEAR;