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

surface_view: Add constructor for ViewParams

This commit is contained in:
ReinUsesLisp 2019-05-07 22:03:33 -03:00
parent 16e8625a30
commit 549fd18ac4
3 changed files with 23 additions and 39 deletions

View File

@ -226,13 +226,8 @@ CachedSurface::CachedSurface(const GPUVAddr gpu_addr, const SurfaceParams& param
target = GetTextureTarget(params.target);
texture = CreateTexture(params, target, internal_format);
DecorateSurfaceName();
ViewParams main{};
main.num_levels = params.num_levels;
main.base_level = 0;
main.base_layer = 0;
main.num_layers = params.is_layered ? params.depth : 1;
main.target = params.target;
main_view = CreateView(main);
main_view = CreateView(
ViewParams(params.target, 0, params.is_layered ? params.depth : 1, 0, params.num_levels));
main_view->DecorateViewName(gpu_addr,
params.TargetName() + "V:" + std::to_string(view_count++));
}
@ -378,13 +373,11 @@ void CachedSurfaceView::Attach(GLenum attachment) const {
switch (owner_params.target) {
case SurfaceTarget::Texture1D:
glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, attachment, surface.GetTarget(),
surface.GetTexture(),
params.base_level);
surface.GetTexture(), params.base_level);
break;
case SurfaceTarget::Texture2D:
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, surface.GetTarget(),
surface.GetTexture(),
params.base_level);
surface.GetTexture(), params.base_level);
break;
case SurfaceTarget::Texture1DArray:
case SurfaceTarget::Texture2DArray:

View File

@ -253,45 +253,30 @@ public:
}
TView EmplaceOverview(const SurfaceParams& overview_params) {
ViewParams vp{};
vp.base_level = 0;
vp.num_levels = params.num_levels;
vp.target = overview_params.target;
if (params.is_layered && !overview_params.is_layered) {
vp.base_layer = 0;
vp.num_layers = 1;
} else {
vp.base_layer = 0;
vp.num_layers = params.depth;
}
return GetView(vp);
const u32 num_layers{params.is_layered && !overview_params.is_layered ? 1 : params.depth};
const ViewParams view_params(overview_params.target, 0, num_layers, 0, params.num_levels);
return GetView(view_params);
}
std::optional<TView> EmplaceView(const SurfaceParams& view_params, const GPUVAddr view_addr) {
if (view_addr < gpu_addr)
return {};
if (params.target == SurfaceTarget::Texture3D ||
if (view_addr < gpu_addr || params.target == SurfaceTarget::Texture3D ||
view_params.target == SurfaceTarget::Texture3D) {
return {};
}
const std::size_t size = view_params.GetGuestSizeInBytes();
auto layer_mipmap = GetLayerMipmap(view_addr);
const std::size_t size{view_params.GetGuestSizeInBytes()};
const auto layer_mipmap{GetLayerMipmap(view_addr)};
if (!layer_mipmap) {
return {};
}
const u32 layer = (*layer_mipmap).first;
const u32 mipmap = (*layer_mipmap).second;
const u32 layer{layer_mipmap->first};
const u32 mipmap{layer_mipmap->second};
if (GetMipmapSize(mipmap) != size) {
// TODO: the view may cover many mimaps, this case can still go on
// TODO: The view may cover many mimaps, this case can still go on.
// This edge-case can be safely be ignored since it will just result in worse
// performance.
return {};
}
ViewParams vp{};
vp.base_layer = layer;
vp.num_layers = 1;
vp.base_level = mipmap;
vp.num_levels = 1;
vp.target = view_params.target;
return {GetView(vp)};
return GetView(ViewParams(params.target, layer, 1, mipmap, 1));
}
TView GetMainView() const {

View File

@ -13,15 +13,21 @@
namespace VideoCommon {
struct ViewParams {
ViewParams(VideoCore::Surface::SurfaceTarget target, u32 base_layer, u32 num_layers,
u32 base_level, u32 num_levels)
: target{target}, base_layer{base_layer}, num_layers{num_layers}, base_level{base_level},
num_levels{num_levels} {}
std::size_t Hash() const;
bool operator==(const ViewParams& rhs) const;
VideoCore::Surface::SurfaceTarget target{};
u32 base_layer{};
u32 num_layers{};
u32 base_level{};
u32 num_levels{};
VideoCore::Surface::SurfaceTarget target;
bool IsLayered() const {
switch (target) {
case VideoCore::Surface::SurfaceTarget::Texture1DArray: