video_core: Run clang format

This commit is contained in:
emufan4568 2022-08-21 22:45:08 +03:00
parent f478e3093f
commit 31e6b553dc
24 changed files with 147 additions and 150 deletions

View file

@ -3,15 +3,15 @@
// Refer to the license.txt file included.
#include "common/microprofile.h"
#include "common/texture.h"
#include "common/scope_exit.h"
#include "common/texture.h"
#include "core/core.h"
#include "video_core/rasterizer_cache/cached_surface.h"
#include "video_core/rasterizer_cache/morton_swizzle.h"
#include "video_core/rasterizer_cache/rasterizer_cache.h"
#include "video_core/renderer_opengl/texture_filters/texture_filterer.h"
#include "video_core/renderer_opengl/gl_state.h"
#include "video_core/renderer_opengl/texture_downloader_es.h"
#include "video_core/renderer_opengl/texture_filters/texture_filterer.h"
namespace OpenGL {
@ -306,8 +306,8 @@ void CachedSurface::UploadGLTexture(Common::Rectangle<u32> rect) {
if (is_custom) {
const auto& tuple = GetFormatTuple(PixelFormat::RGBA8);
unscaled_tex = owner.AllocateSurfaceTexture(tuple, custom_tex_info.width,
custom_tex_info.height);
unscaled_tex =
owner.AllocateSurfaceTexture(tuple, custom_tex_info.width, custom_tex_info.height);
} else {
unscaled_tex = owner.AllocateSurfaceTexture(tuple, rect.GetWidth(), rect.GetHeight());
}
@ -367,8 +367,7 @@ void CachedSurface::UploadGLTexture(Common::Rectangle<u32> rect) {
if (!owner.texture_filterer->Filter(unscaled_tex, from_rect, texture, scaled_rect, type)) {
const Aspect aspect = ToAspect(type);
runtime.BlitTextures(unscaled_tex, {aspect, from_rect},
texture, {aspect, scaled_rect});
runtime.BlitTextures(unscaled_tex, {aspect, from_rect}, texture, {aspect, scaled_rect});
}
}
@ -396,7 +395,8 @@ void CachedSurface::DownloadGLTexture(const Common::Rectangle<u32>& rect) {
// Ensure no bad interactions with GL_PACK_ALIGNMENT
ASSERT(stride * GetBytesPerPixel(pixel_format) % 4 == 0);
glPixelStorei(GL_PACK_ROW_LENGTH, static_cast<GLint>(stride));
const std::size_t buffer_offset = (rect.bottom * stride + rect.left) * GetBytesPerPixel(pixel_format);
const std::size_t buffer_offset =
(rect.bottom * stride + rect.left) * GetBytesPerPixel(pixel_format);
// If not 1x scale, blit scaled texture to a new 1x texture and use that to flush
const Aspect aspect = ToAspect(type);
@ -408,11 +408,10 @@ void CachedSurface::DownloadGLTexture(const Common::Rectangle<u32>& rect) {
scaled_rect.bottom *= res_scale;
const Common::Rectangle<u32> unscaled_tex_rect{0, rect.GetHeight(), rect.GetWidth(), 0};
auto unscaled_tex = owner.AllocateSurfaceTexture(tuple, rect.GetWidth(),
rect.GetHeight());
auto unscaled_tex = owner.AllocateSurfaceTexture(tuple, rect.GetWidth(), rect.GetHeight());
// Blit scaled texture to the unscaled one
runtime.BlitTextures(texture, {aspect, scaled_rect},
unscaled_tex, {aspect, unscaled_tex_rect});
runtime.BlitTextures(texture, {aspect, scaled_rect}, unscaled_tex,
{aspect, unscaled_tex_rect});
state.texture_units[0].texture_2d = unscaled_tex.handle;
state.Apply();
@ -432,7 +431,8 @@ void CachedSurface::DownloadGLTexture(const Common::Rectangle<u32>& rect) {
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
}
bool CachedSurface::CanFill(const SurfaceParams& dest_surface, SurfaceInterval fill_interval) const {
bool CachedSurface::CanFill(const SurfaceParams& dest_surface,
SurfaceInterval fill_interval) const {
if (type == SurfaceType::Fill && IsRegionValid(fill_interval) &&
boost::icl::first(fill_interval) >= addr &&
boost::icl::last_next(fill_interval) <= end && // dest_surface is within our fill range
@ -459,7 +459,8 @@ bool CachedSurface::CanFill(const SurfaceParams& dest_surface, SurfaceInterval f
return false;
}
bool CachedSurface::CanCopy(const SurfaceParams& dest_surface, SurfaceInterval copy_interval) const {
bool CachedSurface::CanCopy(const SurfaceParams& dest_surface,
SurfaceInterval copy_interval) const {
SurfaceParams subrect_params = dest_surface.FromInterval(copy_interval);
ASSERT(subrect_params.GetInterval() == copy_interval);
if (CanSubRect(subrect_params))

View file

@ -17,9 +17,9 @@ namespace OpenGL {
*/
class SurfaceWatcher {
friend class CachedSurface;
public:
explicit SurfaceWatcher(std::weak_ptr<CachedSurface>&& surface) :
surface(std::move(surface)) {}
explicit SurfaceWatcher(std::weak_ptr<CachedSurface>&& surface) : surface(std::move(surface)) {}
/// Checks whether the surface has been changed.
bool IsValid() const {
@ -46,8 +46,8 @@ class RasterizerCacheOpenGL;
class CachedSurface : public SurfaceParams, public std::enable_shared_from_this<CachedSurface> {
public:
CachedSurface(SurfaceParams params, RasterizerCacheOpenGL& owner,TextureRuntime& runtime) :
SurfaceParams(params), owner(owner), runtime(runtime) {}
CachedSurface(SurfaceParams params, RasterizerCacheOpenGL& owner, TextureRuntime& runtime)
: SurfaceParams(params), owner(owner), runtime(runtime) {}
~CachedSurface();
/// Read/Write data in 3DS memory to/from gl_buffer

View file

@ -5,8 +5,8 @@
#pragma once
#include <string_view>
#include "core/hw/gpu.h"
#include "video_core/regs_texturing.h"
#include "video_core/regs_framebuffer.h"
#include "video_core/regs_texturing.h"
namespace OpenGL {
@ -98,8 +98,7 @@ constexpr PixelFormat PixelFormatFromColorFormat(Pica::FramebufferRegs::ColorFor
constexpr PixelFormat PixelFormatFromDepthFormat(Pica::FramebufferRegs::DepthFormat format) {
const u32 format_index = static_cast<u32>(format);
return (format_index < 4) ? static_cast<PixelFormat>(format_index + 14)
: PixelFormat::Invalid;
return (format_index < 4) ? static_cast<PixelFormat>(format_index + 14) : PixelFormat::Invalid;
}
constexpr PixelFormat PixelFormatFromGPUPixelFormat(GPU::Regs::PixelFormat format) {

View file

@ -9,9 +9,9 @@
#include "common/microprofile.h"
#include "video_core/pica_state.h"
#include "video_core/rasterizer_cache/rasterizer_cache.h"
#include "video_core/renderer_opengl/texture_filters/texture_filterer.h"
#include "video_core/renderer_opengl/texture_downloader_es.h"
#include "video_core/renderer_opengl/gl_format_reinterpreter.h"
#include "video_core/renderer_opengl/texture_downloader_es.h"
#include "video_core/renderer_opengl/texture_filters/texture_filterer.h"
namespace OpenGL {
@ -75,8 +75,8 @@ static constexpr auto RangeFromInterval(Map& map, const Interval& interval) {
}
// Allocate an uninitialized texture of appropriate size and format for the surface
OGLTexture RasterizerCacheOpenGL::AllocateSurfaceTexture(const FormatTuple& tuple,
u32 width, u32 height) {
OGLTexture RasterizerCacheOpenGL::AllocateSurfaceTexture(const FormatTuple& tuple, u32 width,
u32 height) {
auto recycled_tex = host_texture_recycler.find({tuple, width, height});
if (recycled_tex != host_texture_recycler.end()) {
OGLTexture texture = std::move(recycled_tex->second);
@ -116,8 +116,8 @@ void RasterizerCacheOpenGL::CopySurface(const Surface& src_surface, const Surfac
}
const auto clear_rect = dst_surface->GetScaledSubRect(subrect_params);
const ClearValue clear_value = ToClearValue(aspect, dst_surface->pixel_format,
fill_buffer.data());
const ClearValue clear_value =
ToClearValue(aspect, dst_surface->pixel_format, fill_buffer.data());
runtime.ClearTexture(dst_surface->texture, {aspect, clear_rect}, clear_value);
return;
@ -127,8 +127,8 @@ void RasterizerCacheOpenGL::CopySurface(const Surface& src_surface, const Surfac
const auto src_rect = src_surface->GetScaledSubRect(subrect_params);
const auto dst_rect = dst_surface->GetScaledSubRect(subrect_params);
runtime.BlitTextures(src_surface->texture, {aspect, src_rect},
dst_surface->texture, {aspect, dst_rect});
runtime.BlitTextures(src_surface->texture, {aspect, src_rect}, dst_surface->texture,
{aspect, dst_rect});
return;
}
@ -264,8 +264,8 @@ bool RasterizerCacheOpenGL::BlitSurfaces(const Surface& src_surface,
dst_surface->InvalidateAllWatcher();
const Aspect aspect = ToAspect(src_surface->type);
return runtime.BlitTextures(src_surface->texture, {aspect, src_rect},
dst_surface->texture, {aspect, dst_rect});
return runtime.BlitTextures(src_surface->texture, {aspect, src_rect}, dst_surface->texture,
{aspect, dst_rect});
}
return false;
@ -569,8 +569,8 @@ const CachedTextureCube& RasterizerCacheOpenGL::GetTextureCube(const TextureCube
const auto src_rect = surface->GetScaledRect();
const auto dst_rect = Common::Rectangle<u32>{0, scaled_size, scaled_size, 0};
const Aspect aspect = ToAspect(surface->type);
runtime.BlitTextures(surface->texture, {aspect, src_rect},
cube.texture, {aspect, dst_rect});
runtime.BlitTextures(surface->texture, {aspect, src_rect}, cube.texture,
{aspect, dst_rect});
face.watcher->Validate();
}
@ -585,10 +585,13 @@ SurfaceSurfaceRect_Tuple RasterizerCacheOpenGL::GetFramebufferSurfaces(
const auto& config = regs.framebuffer.framebuffer;
// Update resolution_scale_factor and reset cache if changed
const bool resolution_scale_changed = resolution_scale_factor != VideoCore::GetResolutionScaleFactor();
const bool texture_filter_changed = VideoCore::g_texture_filter_update_requested.exchange(false)
&& texture_filterer->Reset(Settings::values.texture_filter_name, VideoCore::GetResolutionScaleFactor());
const bool resolution_scale_changed =
resolution_scale_factor != VideoCore::GetResolutionScaleFactor();
const bool texture_filter_changed =
VideoCore::g_texture_filter_update_requested.exchange(false) &&
texture_filterer->Reset(Settings::values.texture_filter_name,
VideoCore::GetResolutionScaleFactor());
if (resolution_scale_changed || texture_filter_changed) {
resolution_scale_factor = VideoCore::GetResolutionScaleFactor();
FlushAll();
@ -843,8 +846,10 @@ bool RasterizerCacheOpenGL::IntervalHasInvalidPixelFormat(SurfaceParams& params,
params.pixel_format = PixelFormat::Invalid;
for (const auto& set : RangeFromInterval(surface_cache, interval))
for (const auto& surface : set.second)
if (surface->pixel_format == PixelFormat::Invalid && surface->type != SurfaceType::Fill) {
LOG_DEBUG(Render_OpenGL, "Surface {:#x} found with invalid pixel format", surface->addr);
if (surface->pixel_format == PixelFormat::Invalid &&
surface->type != SurfaceType::Fill) {
LOG_DEBUG(Render_OpenGL, "Surface {:#x} found with invalid pixel format",
surface->addr);
return true;
}
return false;
@ -880,19 +885,19 @@ bool RasterizerCacheOpenGL::ValidateByReinterpretation(const Surface& surface,
const Common::Rectangle<u32> tmp_rect{0, width, height, 0};
OGLTexture tmp_tex = AllocateSurfaceTexture(tuple, height, width);
reinterpreter->Reinterpret(reinterpret_surface->texture, src_rect,
tmp_tex, tmp_rect);
reinterpreter->Reinterpret(reinterpret_surface->texture, src_rect, tmp_tex,
tmp_rect);
if (!texture_filterer->Filter(tmp_tex, tmp_rect,
surface->texture, dest_rect, type)) {
if (!texture_filterer->Filter(tmp_tex, tmp_rect, surface->texture, dest_rect,
type)) {
const Aspect aspect = ToAspect(type);
runtime.BlitTextures(tmp_tex, {aspect, tmp_rect},
surface->texture, {aspect, dest_rect});
runtime.BlitTextures(tmp_tex, {aspect, tmp_rect}, surface->texture,
{aspect, dest_rect});
}
} else {
reinterpreter->Reinterpret(reinterpret_surface->texture, src_rect,
surface->texture, dest_rect);
reinterpreter->Reinterpret(reinterpret_surface->texture, src_rect, surface->texture,
dest_rect);
}
return true;
@ -1034,8 +1039,8 @@ Surface RasterizerCacheOpenGL::CreateSurface(const SurfaceParams& params) {
// Allocate surface texture
const FormatTuple& tuple = GetFormatTuple(surface->pixel_format);
surface->texture = AllocateSurfaceTexture(tuple, surface->GetScaledWidth(),
surface->GetScaledHeight());
surface->texture =
AllocateSurfaceTexture(tuple, surface->GetScaledWidth(), surface->GetScaledHeight());
return surface;
}

View file

@ -20,20 +20,19 @@ using Surface = std::shared_ptr<CachedSurface>;
using SurfaceInterval = boost::icl::right_open_interval<PAddr>;
using SurfaceSet = std::set<Surface>;
using SurfaceRegions = boost::icl::interval_set<PAddr, std::less, SurfaceInterval>;
using SurfaceMap = boost::icl::interval_map<PAddr, Surface, boost::icl::partial_absorber,
std::less, boost::icl::inplace_plus,
boost::icl::inter_section, SurfaceInterval>;
using SurfaceCache = boost::icl::interval_map<PAddr, SurfaceSet, boost::icl::partial_absorber,
std::less, boost::icl::inplace_plus,
boost::icl::inter_section, SurfaceInterval>;
using SurfaceMap =
boost::icl::interval_map<PAddr, Surface, boost::icl::partial_absorber, std::less,
boost::icl::inplace_plus, boost::icl::inter_section, SurfaceInterval>;
using SurfaceCache =
boost::icl::interval_map<PAddr, SurfaceSet, boost::icl::partial_absorber, std::less,
boost::icl::inplace_plus, boost::icl::inter_section, SurfaceInterval>;
static_assert(std::is_same<SurfaceRegions::interval_type, SurfaceCache::interval_type>() &&
std::is_same<SurfaceMap::interval_type, SurfaceCache::interval_type>(),
std::is_same<SurfaceMap::interval_type, SurfaceCache::interval_type>(),
"Incorrect interval types");
using SurfaceRect_Tuple = std::tuple<Surface, Common::Rectangle<u32>>;
using SurfaceSurfaceRect_Tuple = std::tuple<Surface, Surface, Common::Rectangle<u32>>;
using PageMap = boost::icl::interval_map<u32, int>;
} // namespace OpenGL

View file

@ -14,9 +14,9 @@ SurfaceParams SurfaceParams::FromInterval(SurfaceInterval interval) const {
const u32 stride_tiled_bytes = BytesInPixels(stride * tiled_size);
PAddr aligned_start =
addr + Common::AlignDown(boost::icl::first(interval) - addr, stride_tiled_bytes);
addr + Common::AlignDown(boost::icl::first(interval) - addr, stride_tiled_bytes);
PAddr aligned_end =
addr + Common::AlignUp(boost::icl::last_next(interval) - addr, stride_tiled_bytes);
addr + Common::AlignUp(boost::icl::last_next(interval) - addr, stride_tiled_bytes);
if (aligned_end - aligned_start > stride_tiled_bytes) {
params.addr = aligned_start;
@ -27,9 +27,9 @@ SurfaceParams SurfaceParams::FromInterval(SurfaceInterval interval) const {
const u32 tiled_alignment = BytesInPixels(is_tiled ? 8 * 8 : 1);
aligned_start =
addr + Common::AlignDown(boost::icl::first(interval) - addr, tiled_alignment);
addr + Common::AlignDown(boost::icl::first(interval) - addr, tiled_alignment);
aligned_end =
addr + Common::AlignUp(boost::icl::last_next(interval) - addr, tiled_alignment);
addr + Common::AlignUp(boost::icl::last_next(interval) - addr, tiled_alignment);
params.addr = aligned_start;
params.width = PixelsInBytes(aligned_end - aligned_start) / tiled_size;

View file

@ -39,15 +39,15 @@ void TextureRuntime::ReadTexture(const OGLTexture& tex, Subresource subresource,
const u32 level = subresource.level;
switch (subresource.aspect) {
case Aspect::Color:
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
tex.handle, level);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D,
0, 0);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.handle,
level);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0,
0);
break;
case Aspect::Depth:
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
tex.handle, level);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex.handle,
level);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
break;
case Aspect::DepthStencil:
@ -58,8 +58,8 @@ void TextureRuntime::ReadTexture(const OGLTexture& tex, Subresource subresource,
}
const auto& rect = subresource.region;
glReadPixels(rect.left, rect.bottom, rect.GetWidth(), rect.GetHeight(),
tuple.format, tuple.type, pixels);
glReadPixels(rect.left, rect.bottom, rect.GetWidth(), rect.GetHeight(), tuple.format,
tuple.type, pixels);
}
bool TextureRuntime::ClearTexture(const OGLTexture& tex, Subresource subresource,
@ -81,10 +81,10 @@ bool TextureRuntime::ClearTexture(const OGLTexture& tex, Subresource subresource
const u32 level = subresource.level;
switch (subresource.aspect) {
case Aspect::Color:
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
tex.handle, level);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D,
0, 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.handle,
level);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0,
0);
state.color_mask.red_enabled = true;
state.color_mask.green_enabled = true;
@ -96,8 +96,8 @@ bool TextureRuntime::ClearTexture(const OGLTexture& tex, Subresource subresource
break;
case Aspect::Depth:
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
tex.handle, level);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex.handle,
level);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
state.depth.write_mask = GL_TRUE;
@ -136,9 +136,8 @@ bool TextureRuntime::BlitTextures(const OGLTexture& src_tex, Subresource src_sub
state.draw.draw_framebuffer = draw_fbo.handle;
state.Apply();
auto BindAttachment = [src_level = src_subresource.level,
dst_level = dst_subresource.level](GLenum target, u32 src_tex,
u32 dst_tex) -> void {
auto BindAttachment = [src_level = src_subresource.level, dst_level = dst_subresource.level](
GLenum target, u32 src_tex, u32 dst_tex) -> void {
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, target, GL_TEXTURE_2D, src_tex, src_level);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, target, GL_TEXTURE_2D, dst_tex, dst_level);
};
@ -172,8 +171,8 @@ bool TextureRuntime::BlitTextures(const OGLTexture& src_tex, Subresource src_sub
const GLenum filter = src_subresource.aspect == Aspect::Color ? GL_LINEAR : GL_NEAREST;
const auto& src_rect = src_subresource.region;
const auto& dst_rect = dst_subresource.region;
glBlitFramebuffer(src_rect.left, src_rect.bottom, src_rect.right, src_rect.top,
dst_rect.left, dst_rect.bottom, dst_rect.right, dst_rect.top,
glBlitFramebuffer(src_rect.left, src_rect.bottom, src_rect.right, src_rect.top, dst_rect.left,
dst_rect.bottom, dst_rect.right, dst_rect.top,
ToBufferMask(src_subresource.aspect), filter);
return true;

View file

@ -10,11 +10,7 @@
namespace OpenGL {
// Describes the type of data a texture holds
enum class Aspect {
Color = 0,
Depth = 1,
DepthStencil = 2
};
enum class Aspect { Color = 0, Depth = 1, DepthStencil = 2 };
// A union for both color and depth/stencil clear values
union ClearValue {
@ -26,8 +22,8 @@ union ClearValue {
};
struct Subresource {
Subresource(Aspect aspect, Common::Rectangle<u32> region, u32 level = 0, u32 layer = 0) :
aspect(aspect), region(region), level(level), layer(layer) {}
Subresource(Aspect aspect, Common::Rectangle<u32> region, u32 level = 0, u32 layer = 0)
: aspect(aspect), region(region), level(level), layer(layer) {}
Aspect aspect;
Common::Rectangle<u32> region;
@ -47,8 +43,8 @@ public:
~TextureRuntime() = default;
// Copies the GPU pixel data to the provided pixels buffer
void ReadTexture(const OGLTexture& tex, Subresource subresource,
const FormatTuple& tuple, u8* pixels);
void ReadTexture(const OGLTexture& tex, Subresource subresource, const FormatTuple& tuple,
u8* pixels);
// Fills the rectangle of the texture with the clear value provided
bool ClearTexture(const OGLTexture& texture, Subresource subresource, ClearValue value);