rsx/common: Use a typed enum for texture wrap mode.

This commit is contained in:
Vincent Lejeune 2016-03-30 18:55:43 +02:00
parent f2c82d3cf4
commit 7f25720bd3
10 changed files with 89 additions and 60 deletions

View File

@ -188,18 +188,18 @@ UINT get_texture_max_aniso(u8 aniso)
throw EXCEPTION("Invalid texture max aniso (0x%x)", aniso);
}
D3D12_TEXTURE_ADDRESS_MODE get_texture_wrap_mode(u8 wrap)
D3D12_TEXTURE_ADDRESS_MODE get_texture_wrap_mode(rsx::texture_wrap_mode wrap)
{
switch (wrap)
{
case CELL_GCM_TEXTURE_WRAP: return D3D12_TEXTURE_ADDRESS_MODE_WRAP;
case CELL_GCM_TEXTURE_MIRROR: return D3D12_TEXTURE_ADDRESS_MODE_MIRROR;
case CELL_GCM_TEXTURE_CLAMP_TO_EDGE: return D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
case CELL_GCM_TEXTURE_BORDER: return D3D12_TEXTURE_ADDRESS_MODE_BORDER;
case CELL_GCM_TEXTURE_CLAMP: return D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP_TO_EDGE: return D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE;
case CELL_GCM_TEXTURE_MIRROR_ONCE_BORDER: return D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE;
case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP: return D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE;
case rsx::texture_wrap_mode::wrap: return D3D12_TEXTURE_ADDRESS_MODE_WRAP;
case rsx::texture_wrap_mode::mirror: return D3D12_TEXTURE_ADDRESS_MODE_MIRROR;
case rsx::texture_wrap_mode::clamp_to_edge: return D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
case rsx::texture_wrap_mode::border: return D3D12_TEXTURE_ADDRESS_MODE_BORDER;
case rsx::texture_wrap_mode::clamp: return D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
case rsx::texture_wrap_mode::mirror_once_clamp_to_edge: return D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE;
case rsx::texture_wrap_mode::mirror_once_border: return D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE;
case rsx::texture_wrap_mode::mirror_once_clamp: return D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE;
}
throw EXCEPTION("Invalid texture wrap mode (0x%x)", wrap);
}

View File

@ -46,7 +46,7 @@ UINT get_texture_max_aniso(u8 aniso);
/**
* Convert texture wrap mode to D3D12_TEXTURE_ADDRESS_MODE
*/
D3D12_TEXTURE_ADDRESS_MODE get_texture_wrap_mode(u8 wrap);
D3D12_TEXTURE_ADDRESS_MODE get_texture_wrap_mode(rsx::texture_wrap_mode wrap);
/**
* Convert minify and magnify filter to D3D12_FILTER

View File

@ -877,8 +877,33 @@ enum
CELL_GCM_SURFACE_X8B8G8R8_O8B8G8R8 = 15,
CELL_GCM_SURFACE_A8B8G8R8 = 16,
// Wrap
CELL_GCM_TEXTURE_WRAP = 1,
CELL_GCM_TEXTURE_MIRROR = 2,
CELL_GCM_TEXTURE_CLAMP_TO_EDGE = 3,
CELL_GCM_TEXTURE_BORDER = 4,
CELL_GCM_TEXTURE_CLAMP = 5,
CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP_TO_EDGE = 6,
CELL_GCM_TEXTURE_MIRROR_ONCE_BORDER = 7,
CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP = 8,
};
rsx::texture_wrap_mode rsx::to_texture_wrap_mode(u8 in)
{
switch (in)
{
case CELL_GCM_TEXTURE_WRAP: return rsx::texture_wrap_mode::wrap;
case CELL_GCM_TEXTURE_MIRROR: return rsx::texture_wrap_mode::mirror;
case CELL_GCM_TEXTURE_CLAMP_TO_EDGE: return rsx::texture_wrap_mode::clamp_to_edge;
case CELL_GCM_TEXTURE_BORDER: return rsx::texture_wrap_mode::border;
case CELL_GCM_TEXTURE_CLAMP: return rsx::texture_wrap_mode::clamp;
case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP_TO_EDGE: return rsx::texture_wrap_mode::mirror_once_clamp_to_edge;
case CELL_GCM_TEXTURE_MIRROR_ONCE_BORDER: return rsx::texture_wrap_mode::mirror_once_border;
case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP: return rsx::texture_wrap_mode::mirror_once_clamp;
}
throw EXCEPTION("Unknow wrap mode %x", in);
}
rsx::surface_target rsx::to_surface_target(u8 in)
{
switch (in)
@ -1266,16 +1291,16 @@ namespace
std::string get_texture_wrap_mode(u8 wrap)
{
switch (wrap)
switch (rsx::to_texture_wrap_mode(wrap))
{
case CELL_GCM_TEXTURE_WRAP: return "WRAP";
case CELL_GCM_TEXTURE_MIRROR: return "MIRROR";
case CELL_GCM_TEXTURE_CLAMP_TO_EDGE: return "CLAMP_TO_EDGE";
case CELL_GCM_TEXTURE_BORDER: return "BORDER";
case CELL_GCM_TEXTURE_CLAMP: return "CLAMP";
case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP_TO_EDGE: return "MIRROR_ONCE_CLAMP_TO_EDGE";
case CELL_GCM_TEXTURE_MIRROR_ONCE_BORDER: return "MIRROR_ONCE_BORDER";
case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP: return "MIRROR_ONCE_CLAMP";
case rsx::texture_wrap_mode::wrap: return "WRAP";
case rsx::texture_wrap_mode::mirror: return "MIRROR";
case rsx::texture_wrap_mode::clamp_to_edge: return "CLAMP_TO_EDGE";
case rsx::texture_wrap_mode::border: return "BORDER";
case rsx::texture_wrap_mode::clamp: return "CLAMP";
case rsx::texture_wrap_mode::mirror_once_clamp_to_edge: return "MIRROR_ONCE_CLAMP_TO_EDGE";
case rsx::texture_wrap_mode::mirror_once_border: return "MIRROR_ONCE_BORDER";
case rsx::texture_wrap_mode::mirror_once_clamp: return "MIRROR_ONCE_CLAMP";
}
return "Error";
}

View File

@ -162,6 +162,20 @@ namespace rsx
};
texture_dimension to_texture_dimension(u8 in);
enum class texture_wrap_mode : u8
{
wrap,
mirror,
clamp_to_edge,
border,
clamp,
mirror_once_clamp_to_edge,
mirror_once_border,
mirror_once_clamp,
};
texture_wrap_mode to_texture_wrap_mode(u8 in);
}
enum
@ -248,16 +262,6 @@ enum
CELL_GCM_TEXTURE_MAX_ANISO_10 = 5,
CELL_GCM_TEXTURE_MAX_ANISO_12 = 6,
CELL_GCM_TEXTURE_MAX_ANISO_16 = 7,
// Wrap
CELL_GCM_TEXTURE_WRAP = 1,
CELL_GCM_TEXTURE_MIRROR = 2,
CELL_GCM_TEXTURE_CLAMP_TO_EDGE = 3,
CELL_GCM_TEXTURE_BORDER = 4,
CELL_GCM_TEXTURE_CLAMP = 5,
CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP_TO_EDGE = 6,
CELL_GCM_TEXTURE_MIRROR_ONCE_BORDER = 7,
CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP = 8,
};
// GCM Surface

View File

@ -200,18 +200,18 @@ namespace rsx
glGenTextures(1, &m_id);
}
int texture::gl_wrap(int wrap)
int texture::gl_wrap(rsx::texture_wrap_mode wrap)
{
switch (wrap)
{
case CELL_GCM_TEXTURE_WRAP: return GL_REPEAT;
case CELL_GCM_TEXTURE_MIRROR: return GL_MIRRORED_REPEAT;
case CELL_GCM_TEXTURE_CLAMP_TO_EDGE: return GL_CLAMP_TO_EDGE;
case CELL_GCM_TEXTURE_BORDER: return GL_CLAMP_TO_BORDER;
case CELL_GCM_TEXTURE_CLAMP: return GL_CLAMP;
case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP_TO_EDGE: return GL_MIRROR_CLAMP_TO_EDGE_EXT;
case CELL_GCM_TEXTURE_MIRROR_ONCE_BORDER: return GL_MIRROR_CLAMP_TO_BORDER_EXT;
case CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP: return GL_MIRROR_CLAMP_EXT;
case rsx::texture_wrap_mode::wrap: return GL_REPEAT;
case rsx::texture_wrap_mode::mirror: return GL_MIRRORED_REPEAT;
case rsx::texture_wrap_mode::clamp_to_edge: return GL_CLAMP_TO_EDGE;
case rsx::texture_wrap_mode::border: return GL_CLAMP_TO_BORDER;
case rsx::texture_wrap_mode::clamp: return GL_CLAMP;
case rsx::texture_wrap_mode::mirror_once_clamp_to_edge: return GL_MIRROR_CLAMP_TO_EDGE_EXT;
case rsx::texture_wrap_mode::mirror_once_border: return GL_MIRROR_CLAMP_TO_BORDER_EXT;
case rsx::texture_wrap_mode::mirror_once_clamp: return GL_MIRROR_CLAMP_EXT;
}
LOG_ERROR(RSX, "Texture wrap error: bad wrap (%d).", wrap);

View File

@ -1,4 +1,5 @@
#include "OpenGL.h"
#include "../GCM.h"
namespace rsx
{
@ -14,7 +15,7 @@ namespace rsx
public:
void create();
int gl_wrap(int wrap);
int gl_wrap(rsx::texture_wrap_mode in);
float max_aniso(int aniso);

View File

@ -81,19 +81,19 @@ namespace rsx
return std::min(mipmap(), max_mipmap_count);
}
u8 texture::wrap_s() const
rsx::texture_wrap_mode texture::wrap_s() const
{
return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)]) & 0xf);
return rsx::to_texture_wrap_mode((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)]) & 0xf);
}
u8 texture::wrap_t() const
rsx::texture_wrap_mode texture::wrap_t() const
{
return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 8) & 0xf);
return rsx::to_texture_wrap_mode((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 8) & 0xf);
}
u8 texture::wrap_r() const
rsx::texture_wrap_mode texture::wrap_r() const
{
return ((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 16) & 0xf);
return rsx::to_texture_wrap_mode((method_registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 16) & 0xf);
}
u8 texture::unsigned_remap() const

View File

@ -29,9 +29,9 @@ namespace rsx
u16 get_exact_mipmap_count() const;
// Address
u8 wrap_s() const;
u8 wrap_t() const;
u8 wrap_r() const;
rsx::texture_wrap_mode wrap_s() const;
rsx::texture_wrap_mode wrap_t() const;
rsx::texture_wrap_mode wrap_r() const;
u8 unsigned_remap() const;
u8 zfunc() const;
u8 gamma() const;

View File

@ -65,21 +65,20 @@ VkFilter get_mag_filter(u8 mag_filter)
throw EXCEPTION("Invalid mag filter (0x%x)", mag_filter);
}
VkSamplerAddressMode vk_wrap_mode(u32 gcm_wrap)
VkSamplerAddressMode vk_wrap_mode(rsx::texture_wrap_mode 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);
case rsx::texture_wrap_mode::wrap: return VK_SAMPLER_ADDRESS_MODE_REPEAT;
case rsx::texture_wrap_mode::mirror: return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
case rsx::texture_wrap_mode::clamp_to_edge: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
case rsx::texture_wrap_mode::border: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
case rsx::texture_wrap_mode::clamp: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
case rsx::texture_wrap_mode::mirror_once_clamp_to_edge: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
case rsx::texture_wrap_mode::mirror_once_border: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
case rsx::texture_wrap_mode::mirror_once_clamp: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
}
throw EXCEPTION("unhandled texture clamp mode");
}
float max_aniso(u32 gcm_aniso)

View File

@ -15,7 +15,7 @@ namespace vk
std::tuple<VkFilter, VkSamplerMipmapMode> get_min_filter_and_mip(u8 min_filter);
VkFilter get_mag_filter(u8 mag_filter);
VkSamplerAddressMode vk_wrap_mode(u32 gcm_wrap);
VkSamplerAddressMode vk_wrap_mode(rsx::texture_wrap_mode gcm_wrap);
float max_aniso(u32 gcm_aniso);
VkComponentMapping get_component_mapping(u32 format, u8 swizzle_mask);
VkPrimitiveTopology get_appropriate_topology(rsx::primitive_type& mode, bool &requires_modification);