From f2c82d3cf453946f1600e3bb02668aca8db8be15 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Wed, 30 Mar 2016 18:30:51 +0200 Subject: [PATCH] rsx/common: Use a typed class for texture dimension. --- rpcs3/Emu/RSX/CgBinaryProgram.h | 2 +- .../RSX/Common/FragmentProgramDecompiler.cpp | 32 +++++++++---------- rpcs3/Emu/RSX/Common/TextureUtils.cpp | 6 ++-- rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp | 12 +++---- rpcs3/Emu/RSX/GCM.cpp | 21 ++++++++++++ rpcs3/Emu/RSX/GCM.h | 9 ++++++ rpcs3/Emu/RSX/RSXFragmentProgram.h | 14 +++++--- rpcs3/Emu/RSX/RSXTexture.cpp | 4 +-- rpcs3/Emu/RSX/RSXTexture.h | 3 +- rpcs3/Emu/RSX/RSXThread.cpp | 18 +++++------ 10 files changed, 78 insertions(+), 43 deletions(-) diff --git a/rpcs3/Emu/RSX/CgBinaryProgram.h b/rpcs3/Emu/RSX/CgBinaryProgram.h index 31b9dfefbb..f9ecd4eb9c 100644 --- a/rpcs3/Emu/RSX/CgBinaryProgram.h +++ b/rpcs3/Emu/RSX/CgBinaryProgram.h @@ -333,7 +333,7 @@ public: auto& vmfprog = vm::ps3::_ref(ptr + vmprog.program); u32 size; u32 ctrl = (vmfprog.outputFromH0 ? 0 : 0x40) | (vmfprog.depthReplace ? 0xe : 0); - std::vector td; + std::vector td; RSXFragmentProgram prog; prog.size = 0, prog.addr = vm::base(ptr + vmprog.ucode), prog.offset = 0, prog.ctrl = ctrl; GLFragmentDecompilerThread(m_glsl_shader, param_array, prog, size).Task(); diff --git a/rpcs3/Emu/RSX/Common/FragmentProgramDecompiler.cpp b/rpcs3/Emu/RSX/Common/FragmentProgramDecompiler.cpp index 3ea0501525..c35750f819 100644 --- a/rpcs3/Emu/RSX/Common/FragmentProgramDecompiler.cpp +++ b/rpcs3/Emu/RSX/Common/FragmentProgramDecompiler.cpp @@ -130,16 +130,16 @@ std::string FragmentProgramDecompiler::AddTex() std::string sampler; switch (m_prog.get_texture_dimension(dst.tex_num)) { - case texture_dimension::texture_dimension_1d: + case texture_dimension_extended::texture_dimension_1d: sampler = "sampler1D"; break; - case texture_dimension::texture_dimension_cubemap: + case texture_dimension_extended::texture_dimension_cubemap: sampler = "samplerCube"; break; - case texture_dimension::texture_dimension_2d: + case texture_dimension_extended::texture_dimension_2d: sampler = "sampler2D"; break; - case texture_dimension::texture_dimension_3d: + case texture_dimension_extended::texture_dimension_3d: sampler = "sampler3D"; break; } @@ -442,16 +442,16 @@ bool FragmentProgramDecompiler::handle_tex_srb(u32 opcode) case RSX_FP_OPCODE_TEX: switch (m_prog.get_texture_dimension(dst.tex_num)) { - case texture_dimension::texture_dimension_1d: + case texture_dimension_extended::texture_dimension_1d: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE1D)); return true; - case texture_dimension::texture_dimension_2d: + case texture_dimension_extended::texture_dimension_2d: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE2D)); return true; - case texture_dimension::texture_dimension_cubemap: + case texture_dimension_extended::texture_dimension_cubemap: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE)); return true; - case texture_dimension::texture_dimension_3d: + case texture_dimension_extended::texture_dimension_3d: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE3D)); return true; } @@ -460,16 +460,16 @@ bool FragmentProgramDecompiler::handle_tex_srb(u32 opcode) case RSX_FP_OPCODE_TXP: switch (m_prog.get_texture_dimension(dst.tex_num)) { - case texture_dimension::texture_dimension_1d: + case texture_dimension_extended::texture_dimension_1d: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE1D_PROJ)); return true; - case texture_dimension::texture_dimension_2d: + case texture_dimension_extended::texture_dimension_2d: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_PROJ)); return true; - case texture_dimension::texture_dimension_cubemap: + case texture_dimension_extended::texture_dimension_cubemap: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE_PROJ)); return true; - case texture_dimension::texture_dimension_3d: + case texture_dimension_extended::texture_dimension_3d: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE3D_PROJ)); return true; } @@ -480,16 +480,16 @@ bool FragmentProgramDecompiler::handle_tex_srb(u32 opcode) case RSX_FP_OPCODE_TXL: switch (m_prog.get_texture_dimension(dst.tex_num)) { - case texture_dimension::texture_dimension_1d: + case texture_dimension_extended::texture_dimension_1d: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE1D_LOD)); return true; - case texture_dimension::texture_dimension_2d: + case texture_dimension_extended::texture_dimension_2d: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_LOD)); return true; - case texture_dimension::texture_dimension_cubemap: + case texture_dimension_extended::texture_dimension_cubemap: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE_LOD)); return true; - case texture_dimension::texture_dimension_3d: + case texture_dimension_extended::texture_dimension_3d: SetDst(getFunction(FUNCTION::FUNCTION_TEXTURE_SAMPLE3D_LOD)); return true; } diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.cpp b/rpcs3/Emu/RSX/Common/TextureUtils.cpp index fdd138d694..c129acfe94 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.cpp +++ b/rpcs3/Emu/RSX/Common/TextureUtils.cpp @@ -124,18 +124,18 @@ std::vector get_subresources_layout(const rsx::texture & u16 depth; u8 layer; - if (texture.dimension() == 1) + if (texture.dimension() == rsx::texture_dimension::dimension1d) { depth = 1; layer = 1; h = 1; } - else if (texture.dimension() == 2) + else if (texture.dimension() == rsx::texture_dimension::dimension2d) { depth = 1; layer = texture.cubemap() ? 6 : 1; } - else if (texture.dimension() == 3) + else if (texture.dimension() == rsx::texture_dimension::dimension3d) { depth = texture.depth(); layer = 1; diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp index 301802d05b..0a566f248c 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp @@ -47,17 +47,17 @@ namespace const u8 format = texture.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN); DXGI_FORMAT dxgi_format = get_texture_format(format); - if (texture.dimension() == 1) // 1D texture or cubemap + if (texture.dimension() == rsx::texture_dimension::dimension1d) { return CD3DX12_RESOURCE_DESC::Tex1D(dxgi_format, texture.width(), 1, texture.get_exact_mipmap_count()); } - else if (texture.dimension() == 2) // 2D texture or cubemap + else if (texture.dimension() == rsx::texture_dimension::dimension2d) { // if (texture.depth() < 2); size_t depth = (texture.cubemap()) ? 6 : 1; return CD3DX12_RESOURCE_DESC::Tex2D(dxgi_format, texture.width(), texture.height(), (UINT)depth, texture.get_exact_mipmap_count()); } - else if (texture.dimension() == 3) // 3d texture + else if (texture.dimension() == rsx::texture_dimension::dimension3d) { return CD3DX12_RESOURCE_DESC::Tex3D(dxgi_format, texture.width(), texture.height(), texture.depth(), texture.get_exact_mipmap_count()); } @@ -146,13 +146,13 @@ ComPtr upload_single_texture( D3D12_SHADER_RESOURCE_VIEW_DESC get_srv_descriptor_with_dimensions(const rsx::texture &tex) { D3D12_SHADER_RESOURCE_VIEW_DESC shared_resource_view_desc = {}; - if (tex.dimension() == 1) + if (tex.dimension() == rsx::texture_dimension::dimension1d) { shared_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1D; shared_resource_view_desc.Texture1D.MipLevels = tex.get_exact_mipmap_count(); return shared_resource_view_desc; } - if (tex.dimension() == 2) + if (tex.dimension() == rsx::texture_dimension::dimension2d) { if (tex.cubemap()) { @@ -164,7 +164,7 @@ D3D12_SHADER_RESOURCE_VIEW_DESC get_srv_descriptor_with_dimensions(const rsx::te shared_resource_view_desc.Texture2D.MipLevels = tex.get_exact_mipmap_count(); return shared_resource_view_desc; } - if (tex.dimension() == 3) + if (tex.dimension() == rsx::texture_dimension::dimension3d) { shared_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; shared_resource_view_desc.Texture3D.MipLevels = tex.get_exact_mipmap_count(); diff --git a/rpcs3/Emu/RSX/GCM.cpp b/rpcs3/Emu/RSX/GCM.cpp index 57f8b4269b..8b7c402e04 100644 --- a/rpcs3/Emu/RSX/GCM.cpp +++ b/rpcs3/Emu/RSX/GCM.cpp @@ -830,6 +830,16 @@ rsx::fog_mode rsx::to_fog_mode(u32 in) throw EXCEPTION("Wrong fog mode %x", in); } +rsx::texture_dimension rsx::to_texture_dimension(u8 in) +{ + switch (in) + { + case 1: return rsx::texture_dimension::dimension1d; + case 2: return rsx::texture_dimension::dimension2d; + case 3: return rsx::texture_dimension::dimension3d; + } + throw EXCEPTION("Wrong texture dimension %d", in); +} enum { @@ -1099,6 +1109,17 @@ namespace return "Error"; } + std::string texture_dimension(u8 dim) + { + switch(rsx::to_texture_dimension(dim)) + { + case rsx::texture_dimension::dimension1d: return "1D"; + case rsx::texture_dimension::dimension2d: return "2D"; + case rsx::texture_dimension::dimension3d: return "3D"; + } + return ""; + } + std::string surface_target(u32 target) { switch (rsx::to_surface_target(target)) diff --git a/rpcs3/Emu/RSX/GCM.h b/rpcs3/Emu/RSX/GCM.h index f9d6aae57b..4311e0ee8d 100644 --- a/rpcs3/Emu/RSX/GCM.h +++ b/rpcs3/Emu/RSX/GCM.h @@ -153,6 +153,15 @@ namespace rsx }; fog_mode to_fog_mode(u32 in); + + enum class texture_dimension : u8 + { + dimension1d, + dimension2d, + dimension3d, + }; + + texture_dimension to_texture_dimension(u8 in); } enum diff --git a/rpcs3/Emu/RSX/RSXFragmentProgram.h b/rpcs3/Emu/RSX/RSXFragmentProgram.h index c019f96269..f403294dcf 100644 --- a/rpcs3/Emu/RSX/RSXFragmentProgram.h +++ b/rpcs3/Emu/RSX/RSXFragmentProgram.h @@ -205,7 +205,11 @@ static const std::string rsx_fp_op_names[] = "NULL", "BRK", "CAL", "IFE", "LOOP", "REP", "RET" }; -enum class texture_dimension : u8 + +/** + * Use an extra cubemap format + */ +enum class texture_dimension_extended : u8 { texture_dimension_1d = 0, texture_dimension_2d = 1, @@ -230,15 +234,15 @@ struct RSXFragmentProgram rsx::fog_mode fog_equation; u16 height; - texture_dimension get_texture_dimension(u8 id) const + texture_dimension_extended get_texture_dimension(u8 id) const { - return (texture_dimension)((texture_dimensions >> (id * 2)) & 0x3); + return (texture_dimension_extended)((texture_dimensions >> (id * 2)) & 0x3); } - void set_texture_dimension(const std::array &dimensions) + void set_texture_dimension(const std::array &dimensions) { size_t id = 0; - for (const texture_dimension &dim : dimensions) + for (const texture_dimension_extended &dim : dimensions) { texture_dimensions &= ~(0x3 << (id * 2)); u8 d = (u8)dim; diff --git a/rpcs3/Emu/RSX/RSXTexture.cpp b/rpcs3/Emu/RSX/RSXTexture.cpp index 9a4ba54355..a0729e7bf4 100644 --- a/rpcs3/Emu/RSX/RSXTexture.cpp +++ b/rpcs3/Emu/RSX/RSXTexture.cpp @@ -60,9 +60,9 @@ namespace rsx return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 3) & 0x1); } - u8 texture::dimension() const + rsx::texture_dimension texture::dimension() const { - return ((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 4) & 0xf); + return rsx::to_texture_dimension((method_registers[NV4097_SET_TEXTURE_FORMAT + (m_index * 8)] >> 4) & 0xf); } u8 texture::format() const diff --git a/rpcs3/Emu/RSX/RSXTexture.h b/rpcs3/Emu/RSX/RSXTexture.h index d1bc8c719c..7aba4488af 100644 --- a/rpcs3/Emu/RSX/RSXTexture.h +++ b/rpcs3/Emu/RSX/RSXTexture.h @@ -1,4 +1,5 @@ #pragma once +#include "GCM.h" namespace rsx { @@ -18,7 +19,7 @@ namespace rsx u8 location() const; bool cubemap() const; u8 border_type() const; - u8 dimension() const; + rsx::texture_dimension dimension() const; u8 format() const; u16 mipmap() const; /** diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 965e2fd257..3cafd5b58d 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -719,22 +719,22 @@ namespace rsx result.pixel_center_mode = rsx::to_window_pixel_center((shader_window >> 16) & 0xF); result.height = shader_window & 0xFFF; - std::array texture_dimensions; + std::array texture_dimensions; for (u32 i = 0; i < rsx::limits::textures_count; ++i) { if (!textures[i].enabled()) - texture_dimensions[i] = texture_dimension::texture_dimension_2d; - else if (textures[i].dimension() == 1) - texture_dimensions[i] = texture_dimension::texture_dimension_1d; - else if (textures[i].dimension() == 2) + texture_dimensions[i] = texture_dimension_extended::texture_dimension_2d; + else if (textures[i].dimension() == rsx::texture_dimension::dimension1d) + texture_dimensions[i] = texture_dimension_extended::texture_dimension_1d; + else if (textures[i].dimension() == rsx::texture_dimension::dimension2d) { if (textures[i].cubemap()) - texture_dimensions[i] = texture_dimension::texture_dimension_cubemap; + texture_dimensions[i] = texture_dimension_extended::texture_dimension_cubemap; else - texture_dimensions[i] = texture_dimension::texture_dimension_2d; + texture_dimensions[i] = texture_dimension_extended::texture_dimension_2d; } - else if (textures[i].dimension() == 3) - texture_dimensions[i] = texture_dimension::texture_dimension_3d; + else if (textures[i].dimension() == rsx::texture_dimension::dimension3d) + texture_dimensions[i] = texture_dimension_extended::texture_dimension_3d; else throw EXCEPTION("Unable to determine texture dimension"); if (textures[i].enabled() && (textures[i].format() & CELL_GCM_TEXTURE_UN))