rsx/common: Use a typed class for texture dimension.

This commit is contained in:
Vincent Lejeune 2016-03-30 18:30:51 +02:00
parent d53a1d10ab
commit f2c82d3cf4
10 changed files with 78 additions and 43 deletions

View file

@ -333,7 +333,7 @@ public:
auto& vmfprog = vm::ps3::_ref<CgBinaryFragmentProgram>(ptr + vmprog.program);
u32 size;
u32 ctrl = (vmfprog.outputFromH0 ? 0 : 0x40) | (vmfprog.depthReplace ? 0xe : 0);
std::vector<texture_dimension> td;
std::vector<texture_dimension_extended> 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();

View file

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

View file

@ -124,18 +124,18 @@ std::vector<rsx_subresource_layout> 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;

View file

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

View file

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

View file

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

View file

@ -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<texture_dimension, 16> &dimensions)
void set_texture_dimension(const std::array<texture_dimension_extended, 16> &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;

View file

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

View file

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

View file

@ -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_dimension, 16> texture_dimensions;
std::array<texture_dimension_extended, 16> 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))