yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

gl_rasterizer_cache: Refactor to make SurfaceParams members const.

This commit is contained in:
bunnei 2018-06-24 09:50:08 -04:00
parent 5f57ab1b2a
commit 9f2f819bb6
2 changed files with 37 additions and 52 deletions

View File

@ -29,6 +29,28 @@ struct FormatTuple {
bool compressed; bool compressed;
}; };
SurfaceParams::SurfaceParams(const Tegra::Texture::FullTextureInfo& config)
: addr(config.tic.Address()), is_tiled(config.tic.IsTiled()),
block_height(is_tiled ? config.tic.BlockHeight() : 0),
pixel_format(PixelFormatFromTextureFormat(config.tic.format)),
component_type(ComponentTypeFromTexture(config.tic.r_type.Value())),
type(GetFormatType(pixel_format)),
width(Common::AlignUp(config.tic.Width(), GetCompressionFactor(pixel_format))),
height(Common::AlignUp(config.tic.Height(), GetCompressionFactor(pixel_format))) {
// TODO(Subv): Different types per component are not supported.
ASSERT(config.tic.r_type.Value() == config.tic.g_type.Value() &&
config.tic.r_type.Value() == config.tic.b_type.Value() &&
config.tic.r_type.Value() == config.tic.a_type.Value());
}
SurfaceParams::SurfaceParams(const Tegra::Engines::Maxwell3D::Regs::RenderTargetConfig& config)
: addr(config.Address()), is_tiled(true),
block_height(Tegra::Texture::TICEntry::DefaultBlockHeight),
pixel_format(PixelFormatFromRenderTargetFormat(config.format)),
component_type(ComponentTypeFromRenderTarget(config.format)),
type(GetFormatType(pixel_format)), width(config.width), height(config.height) {}
static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_format_tuples = {{ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_format_tuples = {{
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, false}, // ABGR8 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, false}, // ABGR8
{GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, false}, // B5G6R5 {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, false}, // B5G6R5
@ -333,57 +355,20 @@ RasterizerCacheOpenGL::RasterizerCacheOpenGL() {
} }
Surface RasterizerCacheOpenGL::GetTextureSurface(const Tegra::Texture::FullTextureInfo& config) { Surface RasterizerCacheOpenGL::GetTextureSurface(const Tegra::Texture::FullTextureInfo& config) {
auto& gpu = Core::System::GetInstance().GPU(); return GetSurface(SurfaceParams(config));
SurfaceParams params;
params.addr = config.tic.Address();
params.is_tiled = config.tic.IsTiled();
params.pixel_format = SurfaceParams::PixelFormatFromTextureFormat(config.tic.format);
params.component_type = SurfaceParams::ComponentTypeFromTexture(config.tic.r_type.Value());
params.type = SurfaceParams::GetFormatType(params.pixel_format);
params.width = Common::AlignUp(config.tic.Width(), params.GetCompressionFactor());
params.height = Common::AlignUp(config.tic.Height(), params.GetCompressionFactor());
if (params.is_tiled) {
params.block_height = config.tic.BlockHeight();
}
// TODO(Subv): Different types per component are not supported.
ASSERT(config.tic.r_type.Value() == config.tic.g_type.Value() &&
config.tic.r_type.Value() == config.tic.b_type.Value() &&
config.tic.r_type.Value() == config.tic.a_type.Value());
return GetSurface(params);
} }
SurfaceSurfaceRect_Tuple RasterizerCacheOpenGL::GetFramebufferSurfaces( SurfaceSurfaceRect_Tuple RasterizerCacheOpenGL::GetFramebufferSurfaces(
bool using_color_fb, bool using_depth_fb, const MathUtil::Rectangle<s32>& viewport) { bool using_color_fb, bool using_depth_fb, const MathUtil::Rectangle<s32>& viewport) {
const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs;
const auto& config = regs.rt[0];
// TODO(bunnei): This is hard corded to use just the first render buffer // TODO(bunnei): This is hard corded to use just the first render buffer
NGLOG_WARNING(Render_OpenGL, "hard-coded for render target 0!"); NGLOG_WARNING(Render_OpenGL, "hard-coded for render target 0!");
MathUtil::Rectangle<u32> viewport_clamped{
static_cast<u32>(std::clamp(viewport.left, 0, static_cast<s32>(config.width))),
static_cast<u32>(std::clamp(viewport.top, 0, static_cast<s32>(config.height))),
static_cast<u32>(std::clamp(viewport.right, 0, static_cast<s32>(config.width))),
static_cast<u32>(std::clamp(viewport.bottom, 0, static_cast<s32>(config.height)))};
// get color and depth surfaces // get color and depth surfaces
SurfaceParams color_params; SurfaceParams color_params(regs.rt[0]);
color_params.is_tiled = true;
color_params.width = config.width;
color_params.height = config.height;
// TODO(Subv): Can framebuffers use a different block height?
color_params.block_height = Tegra::Texture::TICEntry::DefaultBlockHeight;
SurfaceParams depth_params = color_params; SurfaceParams depth_params = color_params;
color_params.addr = config.Address();
color_params.pixel_format = SurfaceParams::PixelFormatFromRenderTargetFormat(config.format);
color_params.component_type = SurfaceParams::ComponentTypeFromRenderTarget(config.format);
color_params.type = SurfaceParams::GetFormatType(color_params.pixel_format);
ASSERT_MSG(!using_depth_fb, "depth buffer is unimplemented"); ASSERT_MSG(!using_depth_fb, "depth buffer is unimplemented");
MathUtil::Rectangle<u32> color_rect{}; MathUtil::Rectangle<u32> color_rect{};

View File

@ -10,6 +10,7 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/math_util.h" #include "common/math_util.h"
#include "video_core/engines/maxwell_3d.h"
#include "video_core/renderer_opengl/gl_resource_manager.h" #include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/textures/texture.h" #include "video_core/textures/texture.h"
@ -83,9 +84,6 @@ struct SurfaceParams {
ASSERT(static_cast<size_t>(format) < compression_factor_table.size()); ASSERT(static_cast<size_t>(format) < compression_factor_table.size());
return compression_factor_table[static_cast<size_t>(format)]; return compression_factor_table[static_cast<size_t>(format)];
} }
u32 GetCompressionFactor() const {
return GetCompressionFactor(pixel_format);
}
static constexpr u32 GetFormatBpp(PixelFormat format) { static constexpr u32 GetFormatBpp(PixelFormat format) {
if (format == PixelFormat::Invalid) if (format == PixelFormat::Invalid)
@ -238,25 +236,27 @@ struct SurfaceParams {
} }
size_t SizeInBytes() const { size_t SizeInBytes() const {
const u32 compression_factor{GetCompressionFactor()}; const u32 compression_factor{GetCompressionFactor(pixel_format)};
ASSERT(width % compression_factor == 0); ASSERT(width % compression_factor == 0);
ASSERT(height % compression_factor == 0); ASSERT(height % compression_factor == 0);
return (width / compression_factor) * (height / compression_factor) * return (width / compression_factor) * (height / compression_factor) *
GetFormatBpp(pixel_format) / CHAR_BIT; GetFormatBpp(pixel_format) / CHAR_BIT;
} }
SurfaceParams(const Tegra::Texture::FullTextureInfo& config);
SurfaceParams(const Tegra::Engines::Maxwell3D::Regs::RenderTargetConfig& config);
VAddr GetCpuAddr() const; VAddr GetCpuAddr() const;
Tegra::GPUVAddr addr; const Tegra::GPUVAddr addr;
u32 width; const bool is_tiled;
u32 height; const u32 block_height;
u32 block_height; const PixelFormat pixel_format;
bool is_tiled; const ComponentType component_type;
PixelFormat pixel_format; const SurfaceType type;
SurfaceType type; const u32 width;
ComponentType component_type; const u32 height;
}; };
static_assert(std::is_pod<SurfaceParams>::value, "SurfaceParams is not POD");
class CachedSurface final { class CachedSurface final {
public: public: