summaryrefslogtreecommitdiffstats
path: root/src/video_core/texture_cache
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2019-09-10 14:57:05 +0200
committerGitHub <noreply@github.com>2019-09-10 14:57:05 +0200
commit434d0922dcf886c6bb3ac50b96a8c6091c5c6c11 (patch)
tree7a8789ba575866a8cdc03f8b4bd6d17789659fcd /src/video_core/texture_cache
parentMerge pull request #2847 from VelocityRa/nro-nacp-fix (diff)
parentgl_shader_decompiler: Keep track of written images and mark them as modified (diff)
downloadyuzu-434d0922dcf886c6bb3ac50b96a8c6091c5c6c11.tar
yuzu-434d0922dcf886c6bb3ac50b96a8c6091c5c6c11.tar.gz
yuzu-434d0922dcf886c6bb3ac50b96a8c6091c5c6c11.tar.bz2
yuzu-434d0922dcf886c6bb3ac50b96a8c6091c5c6c11.tar.lz
yuzu-434d0922dcf886c6bb3ac50b96a8c6091c5c6c11.tar.xz
yuzu-434d0922dcf886c6bb3ac50b96a8c6091c5c6c11.tar.zst
yuzu-434d0922dcf886c6bb3ac50b96a8c6091c5c6c11.zip
Diffstat (limited to 'src/video_core/texture_cache')
-rw-r--r--src/video_core/texture_cache/surface_base.h12
-rw-r--r--src/video_core/texture_cache/surface_params.cpp134
-rw-r--r--src/video_core/texture_cache/surface_params.h9
-rw-r--r--src/video_core/texture_cache/surface_view.cpp2
-rw-r--r--src/video_core/texture_cache/surface_view.h20
-rw-r--r--src/video_core/texture_cache/texture_cache.h21
6 files changed, 131 insertions, 67 deletions
diff --git a/src/video_core/texture_cache/surface_base.h b/src/video_core/texture_cache/surface_base.h
index bcce8d863..5e497e49f 100644
--- a/src/video_core/texture_cache/surface_base.h
+++ b/src/video_core/texture_cache/surface_base.h
@@ -195,18 +195,18 @@ public:
virtual void DownloadTexture(std::vector<u8>& staging_buffer) = 0;
- void MarkAsModified(const bool is_modified_, const u64 tick) {
+ void MarkAsModified(bool is_modified_, u64 tick) {
is_modified = is_modified_ || is_target;
modification_tick = tick;
}
- void MarkAsRenderTarget(const bool is_target, const u32 index) {
- this->is_target = is_target;
- this->index = index;
+ void MarkAsRenderTarget(bool is_target_, u32 index_) {
+ is_target = is_target_;
+ index = index_;
}
- void MarkAsPicked(const bool is_picked) {
- this->is_picked = is_picked;
+ void MarkAsPicked(bool is_picked_) {
+ is_picked = is_picked_;
}
bool IsModified() const {
diff --git a/src/video_core/texture_cache/surface_params.cpp b/src/video_core/texture_cache/surface_params.cpp
index fd5472451..1e4d3fb79 100644
--- a/src/video_core/texture_cache/surface_params.cpp
+++ b/src/video_core/texture_cache/surface_params.cpp
@@ -24,55 +24,62 @@ using VideoCore::Surface::SurfaceTarget;
using VideoCore::Surface::SurfaceTargetFromTextureType;
using VideoCore::Surface::SurfaceType;
-SurfaceTarget TextureType2SurfaceTarget(Tegra::Shader::TextureType type, bool is_array) {
+namespace {
+
+SurfaceTarget TextureTypeToSurfaceTarget(Tegra::Shader::TextureType type, bool is_array) {
switch (type) {
- case Tegra::Shader::TextureType::Texture1D: {
- if (is_array)
- return SurfaceTarget::Texture1DArray;
- else
- return SurfaceTarget::Texture1D;
- }
- case Tegra::Shader::TextureType::Texture2D: {
- if (is_array)
- return SurfaceTarget::Texture2DArray;
- else
- return SurfaceTarget::Texture2D;
- }
- case Tegra::Shader::TextureType::Texture3D: {
+ case Tegra::Shader::TextureType::Texture1D:
+ return is_array ? SurfaceTarget::Texture1DArray : SurfaceTarget::Texture1D;
+ case Tegra::Shader::TextureType::Texture2D:
+ return is_array ? SurfaceTarget::Texture2DArray : SurfaceTarget::Texture2D;
+ case Tegra::Shader::TextureType::Texture3D:
ASSERT(!is_array);
return SurfaceTarget::Texture3D;
- }
- case Tegra::Shader::TextureType::TextureCube: {
- if (is_array)
- return SurfaceTarget::TextureCubeArray;
- else
- return SurfaceTarget::TextureCubemap;
- }
- default: {
+ case Tegra::Shader::TextureType::TextureCube:
+ return is_array ? SurfaceTarget::TextureCubeArray : SurfaceTarget::TextureCubemap;
+ default:
UNREACHABLE();
return SurfaceTarget::Texture2D;
}
+}
+
+SurfaceTarget ImageTypeToSurfaceTarget(Tegra::Shader::ImageType type) {
+ switch (type) {
+ case Tegra::Shader::ImageType::Texture1D:
+ return SurfaceTarget::Texture1D;
+ case Tegra::Shader::ImageType::TextureBuffer:
+ return SurfaceTarget::TextureBuffer;
+ case Tegra::Shader::ImageType::Texture1DArray:
+ return SurfaceTarget::Texture1DArray;
+ case Tegra::Shader::ImageType::Texture2D:
+ return SurfaceTarget::Texture2D;
+ case Tegra::Shader::ImageType::Texture2DArray:
+ return SurfaceTarget::Texture2DArray;
+ case Tegra::Shader::ImageType::Texture3D:
+ return SurfaceTarget::Texture3D;
+ default:
+ UNREACHABLE();
+ return SurfaceTarget::Texture2D;
}
}
-namespace {
constexpr u32 GetMipmapSize(bool uncompressed, u32 mip_size, u32 tile) {
return uncompressed ? mip_size : std::max(1U, (mip_size + tile - 1) / tile);
}
+
} // Anonymous namespace
-SurfaceParams SurfaceParams::CreateForTexture(Core::System& system,
- const Tegra::Texture::FullTextureInfo& config,
+SurfaceParams SurfaceParams::CreateForTexture(const Tegra::Texture::TICEntry& tic,
const VideoCommon::Shader::Sampler& entry) {
SurfaceParams params;
- params.is_tiled = config.tic.IsTiled();
- params.srgb_conversion = config.tic.IsSrgbConversionEnabled();
- params.block_width = params.is_tiled ? config.tic.BlockWidth() : 0,
- params.block_height = params.is_tiled ? config.tic.BlockHeight() : 0,
- params.block_depth = params.is_tiled ? config.tic.BlockDepth() : 0,
- params.tile_width_spacing = params.is_tiled ? (1 << config.tic.tile_width_spacing.Value()) : 1;
- params.pixel_format = PixelFormatFromTextureFormat(config.tic.format, config.tic.r_type.Value(),
- params.srgb_conversion);
+ params.is_tiled = tic.IsTiled();
+ params.srgb_conversion = tic.IsSrgbConversionEnabled();
+ params.block_width = params.is_tiled ? tic.BlockWidth() : 0,
+ params.block_height = params.is_tiled ? tic.BlockHeight() : 0,
+ params.block_depth = params.is_tiled ? tic.BlockDepth() : 0,
+ params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1;
+ params.pixel_format =
+ PixelFormatFromTextureFormat(tic.format, tic.r_type.Value(), params.srgb_conversion);
params.type = GetFormatType(params.pixel_format);
if (entry.IsShadow() && params.type == SurfaceType::ColorTexture) {
switch (params.pixel_format) {
@@ -92,31 +99,72 @@ SurfaceParams SurfaceParams::CreateForTexture(Core::System& system,
}
params.type = GetFormatType(params.pixel_format);
}
- params.component_type = ComponentTypeFromTexture(config.tic.r_type.Value());
+ params.component_type = ComponentTypeFromTexture(tic.r_type.Value());
params.type = GetFormatType(params.pixel_format);
// TODO: on 1DBuffer we should use the tic info.
- if (!config.tic.IsBuffer()) {
- params.target = TextureType2SurfaceTarget(entry.GetType(), entry.IsArray());
- params.width = config.tic.Width();
- params.height = config.tic.Height();
- params.depth = config.tic.Depth();
- params.pitch = params.is_tiled ? 0 : config.tic.Pitch();
+ if (tic.IsBuffer()) {
+ params.target = SurfaceTarget::TextureBuffer;
+ params.width = tic.Width();
+ params.pitch = params.width * params.GetBytesPerPixel();
+ params.height = 1;
+ params.depth = 1;
+ params.num_levels = 1;
+ params.emulated_levels = 1;
+ params.is_layered = false;
+ } else {
+ params.target = TextureTypeToSurfaceTarget(entry.GetType(), entry.IsArray());
+ params.width = tic.Width();
+ params.height = tic.Height();
+ params.depth = tic.Depth();
+ params.pitch = params.is_tiled ? 0 : tic.Pitch();
if (params.target == SurfaceTarget::TextureCubemap ||
params.target == SurfaceTarget::TextureCubeArray) {
params.depth *= 6;
}
- params.num_levels = config.tic.max_mip_level + 1;
+ params.num_levels = tic.max_mip_level + 1;
params.emulated_levels = std::min(params.num_levels, params.MaxPossibleMipmap());
params.is_layered = params.IsLayered();
- } else {
+ }
+ return params;
+}
+
+SurfaceParams SurfaceParams::CreateForImage(const Tegra::Texture::TICEntry& tic,
+ const VideoCommon::Shader::Image& entry) {
+ SurfaceParams params;
+ params.is_tiled = tic.IsTiled();
+ params.srgb_conversion = tic.IsSrgbConversionEnabled();
+ params.block_width = params.is_tiled ? tic.BlockWidth() : 0,
+ params.block_height = params.is_tiled ? tic.BlockHeight() : 0,
+ params.block_depth = params.is_tiled ? tic.BlockDepth() : 0,
+ params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1;
+ params.pixel_format =
+ PixelFormatFromTextureFormat(tic.format, tic.r_type.Value(), params.srgb_conversion);
+ params.type = GetFormatType(params.pixel_format);
+ params.component_type = ComponentTypeFromTexture(tic.r_type.Value());
+ params.type = GetFormatType(params.pixel_format);
+ params.target = ImageTypeToSurfaceTarget(entry.GetType());
+ // TODO: on 1DBuffer we should use the tic info.
+ if (tic.IsBuffer()) {
params.target = SurfaceTarget::TextureBuffer;
- params.width = config.tic.Width();
+ params.width = tic.Width();
params.pitch = params.width * params.GetBytesPerPixel();
params.height = 1;
params.depth = 1;
params.num_levels = 1;
params.emulated_levels = 1;
params.is_layered = false;
+ } else {
+ params.width = tic.Width();
+ params.height = tic.Height();
+ params.depth = tic.Depth();
+ params.pitch = params.is_tiled ? 0 : tic.Pitch();
+ if (params.target == SurfaceTarget::TextureCubemap ||
+ params.target == SurfaceTarget::TextureCubeArray) {
+ params.depth *= 6;
+ }
+ params.num_levels = tic.max_mip_level + 1;
+ params.emulated_levels = std::min(params.num_levels, params.MaxPossibleMipmap());
+ params.is_layered = params.IsLayered();
}
return params;
}
diff --git a/src/video_core/texture_cache/surface_params.h b/src/video_core/texture_cache/surface_params.h
index e7ef66ee2..c58e7f8a4 100644
--- a/src/video_core/texture_cache/surface_params.h
+++ b/src/video_core/texture_cache/surface_params.h
@@ -4,8 +4,6 @@
#pragma once
-#include <map>
-
#include "common/alignment.h"
#include "common/bit_util.h"
#include "common/cityhash.h"
@@ -23,10 +21,13 @@ using VideoCore::Surface::SurfaceCompression;
class SurfaceParams {
public:
/// Creates SurfaceCachedParams from a texture configuration.
- static SurfaceParams CreateForTexture(Core::System& system,
- const Tegra::Texture::FullTextureInfo& config,
+ static SurfaceParams CreateForTexture(const Tegra::Texture::TICEntry& tic,
const VideoCommon::Shader::Sampler& entry);
+ /// Creates SurfaceCachedParams from an image configuration.
+ static SurfaceParams CreateForImage(const Tegra::Texture::TICEntry& tic,
+ const VideoCommon::Shader::Image& entry);
+
/// Creates SurfaceCachedParams for a depth buffer configuration.
static SurfaceParams CreateForDepthBuffer(
Core::System& system, u32 zeta_width, u32 zeta_height, Tegra::DepthFormat format,
diff --git a/src/video_core/texture_cache/surface_view.cpp b/src/video_core/texture_cache/surface_view.cpp
index 467696a4c..57a1f5803 100644
--- a/src/video_core/texture_cache/surface_view.cpp
+++ b/src/video_core/texture_cache/surface_view.cpp
@@ -10,7 +10,7 @@
namespace VideoCommon {
std::size_t ViewParams::Hash() const {
- return static_cast<std::size_t>(base_layer) ^ static_cast<std::size_t>(num_layers << 16) ^
+ return static_cast<std::size_t>(base_layer) ^ (static_cast<std::size_t>(num_layers) << 16) ^
(static_cast<std::size_t>(base_level) << 24) ^
(static_cast<std::size_t>(num_levels) << 32) ^ (static_cast<std::size_t>(target) << 36);
}
diff --git a/src/video_core/texture_cache/surface_view.h b/src/video_core/texture_cache/surface_view.h
index 04ca5639b..b17fd11a9 100644
--- a/src/video_core/texture_cache/surface_view.h
+++ b/src/video_core/texture_cache/surface_view.h
@@ -13,8 +13,8 @@
namespace VideoCommon {
struct ViewParams {
- ViewParams(VideoCore::Surface::SurfaceTarget target, u32 base_layer, u32 num_layers,
- u32 base_level, u32 num_levels)
+ constexpr explicit 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} {}
@@ -22,12 +22,6 @@ struct ViewParams {
bool operator==(const ViewParams& rhs) const;
- VideoCore::Surface::SurfaceTarget target{};
- u32 base_layer{};
- u32 num_layers{};
- u32 base_level{};
- u32 num_levels{};
-
bool IsLayered() const {
switch (target) {
case VideoCore::Surface::SurfaceTarget::Texture1DArray:
@@ -39,13 +33,19 @@ struct ViewParams {
return false;
}
}
+
+ VideoCore::Surface::SurfaceTarget target{};
+ u32 base_layer{};
+ u32 num_layers{};
+ u32 base_level{};
+ u32 num_levels{};
};
class ViewBase {
public:
- ViewBase(const ViewParams& params) : params{params} {}
+ constexpr explicit ViewBase(const ViewParams& params) : params{params} {}
- const ViewParams& GetViewParams() const {
+ constexpr const ViewParams& GetViewParams() const {
return params;
}
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index 2ec0203d1..877c6635d 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -89,14 +89,29 @@ public:
}
}
- TView GetTextureSurface(const Tegra::Texture::FullTextureInfo& config,
+ TView GetTextureSurface(const Tegra::Texture::TICEntry& tic,
const VideoCommon::Shader::Sampler& entry) {
std::lock_guard lock{mutex};
- const auto gpu_addr{config.tic.Address()};
+ const auto gpu_addr{tic.Address()};
if (!gpu_addr) {
return {};
}
- const auto params{SurfaceParams::CreateForTexture(system, config, entry)};
+ const auto params{SurfaceParams::CreateForTexture(tic, entry)};
+ const auto [surface, view] = GetSurface(gpu_addr, params, true, false);
+ if (guard_samplers) {
+ sampled_textures.push_back(surface);
+ }
+ return view;
+ }
+
+ TView GetImageSurface(const Tegra::Texture::TICEntry& tic,
+ const VideoCommon::Shader::Image& entry) {
+ std::lock_guard lock{mutex};
+ const auto gpu_addr{tic.Address()};
+ if (!gpu_addr) {
+ return {};
+ }
+ const auto params{SurfaceParams::CreateForImage(tic, entry)};
const auto [surface, view] = GetSurface(gpu_addr, params, true, false);
if (guard_samplers) {
sampled_textures.push_back(surface);