mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-28 22:06:59 +01:00
Rename texture transfer types and download APIs
This commit is contained in:
+50
-50
@@ -924,7 +924,7 @@ ImageId TextureCache::ExpandImage(const ImageInfo& info, ImageId source_id) {
|
|||||||
return expanded_id;
|
return expanded_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TextureCache::TextureTransferPlan {
|
struct TextureCache::TextureTransfer {
|
||||||
TextureUploadLayout layout;
|
TextureUploadLayout layout;
|
||||||
std::vector<vk::BufferImageCopy> regions;
|
std::vector<vk::BufferImageCopy> regions;
|
||||||
std::vector<GpuTileInfo> tiles;
|
std::vector<GpuTileInfo> tiles;
|
||||||
@@ -940,13 +940,13 @@ struct TextureCache::TextureTransferPlan {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TextureCache::DownloadPlan {
|
struct TextureCache::ImageDownload {
|
||||||
TextureTransferPlan texture;
|
TextureTransfer texture;
|
||||||
bool depth_target = false;
|
bool depth_target = false;
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextureCache::TextureTransferPlan
|
TextureCache::TextureTransfer
|
||||||
TextureCache::BuildTextureTransfer(const Image& image, BindingType binding,
|
TextureCache::BuildTextureTransfer(const Image& image, BindingType binding,
|
||||||
TransferDirection direction) const {
|
TransferDirection direction) const {
|
||||||
const auto& info = image.info;
|
const auto& info = image.info;
|
||||||
@@ -959,8 +959,8 @@ TextureCache::BuildTextureTransfer(const Image& image, BindingType binding,
|
|||||||
bool allow_depth_tile = upload;
|
bool allow_depth_tile = upload;
|
||||||
const char* owner = "TextureCache readback";
|
const char* owner = "TextureCache readback";
|
||||||
|
|
||||||
TextureTransferPlan plan;
|
TextureTransfer transfer;
|
||||||
plan.swap_bgra16 = info.bgra16 && (!upload || render_target || video_out);
|
transfer.swap_bgra16 = info.bgra16 && (!upload || render_target || video_out);
|
||||||
if (render_target) {
|
if (render_target) {
|
||||||
format = ImageOps::RenderTargetTransferFormat(info.bytes_per_block);
|
format = ImageOps::RenderTargetTransferFormat(info.bytes_per_block);
|
||||||
}
|
}
|
||||||
@@ -990,44 +990,44 @@ TextureCache::BuildTextureTransfer(const Image& image, BindingType binding,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plan.layout = TextureCalcUploadLayout(format, info.extent.width, info.extent.height,
|
transfer.layout = TextureCalcUploadLayout(format, info.extent.width, info.extent.height,
|
||||||
info.resources.levels, layers, info.tile_mode,
|
info.resources.levels, layers, info.tile_mode,
|
||||||
info.data.size, allow_depth_tile, volume, owner);
|
info.data.size, allow_depth_tile, volume, owner);
|
||||||
plan.regions = TextureBuildImageCopies(plan.layout);
|
transfer.regions = TextureBuildImageCopies(transfer.layout);
|
||||||
if (info.IsDepth()) {
|
if (info.IsDepth()) {
|
||||||
for (auto& region: plan.regions) {
|
for (auto& region: transfer.regions) {
|
||||||
region.imageSubresource.aspectMask = vk::ImageAspectFlagBits::eDepth;
|
region.imageSubresource.aspectMask = vk::ImageAspectFlagBits::eDepth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plan.layout.surface.description.tile_mode != Prospero::TileMode::kLinear) {
|
if (transfer.layout.surface.description.tile_mode != Prospero::TileMode::kLinear) {
|
||||||
if (!TextureBuildGpuTileInfos(info.data.size, plan.regions, plan.layout,
|
if (!TextureBuildGpuTileInfos(info.data.size, transfer.regions, transfer.layout,
|
||||||
info.resources.levels, plan.tiles)) {
|
info.resources.levels, transfer.tiles)) {
|
||||||
return plan;
|
return transfer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
plan.valid = true;
|
transfer.valid = true;
|
||||||
return plan;
|
return transfer;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureCache::DownloadPlan TextureCache::BuildDownload(const Image& image) const {
|
TextureCache::ImageDownload TextureCache::BuildDownload(const Image& image) const {
|
||||||
const auto& info = image.info;
|
const auto& info = image.info;
|
||||||
const auto binding = UploadBinding(image);
|
const auto binding = UploadBinding(image);
|
||||||
DownloadPlan plan {.depth_target = binding == BindingType::DepthTarget};
|
ImageDownload transfer {.depth_target = binding == BindingType::DepthTarget};
|
||||||
if (info.samples != 1 || image.backing.samples != 1) {
|
if (info.samples != 1 || image.backing.samples != 1) {
|
||||||
return plan;
|
return transfer;
|
||||||
}
|
}
|
||||||
if (plan.depth_target) {
|
if (transfer.depth_target) {
|
||||||
plan.valid = IsSupportedDepthPlaneReadback(info) && info.resources.layers != 0 &&
|
transfer.valid = IsSupportedDepthPlaneReadback(info) && info.resources.layers != 0 &&
|
||||||
info.data.size % info.resources.layers == 0 &&
|
info.data.size % info.resources.layers == 0 &&
|
||||||
Prospero::NumBytesPerElement(info.guest_format) == info.bytes_per_block;
|
Prospero::NumBytesPerElement(info.guest_format) == info.bytes_per_block;
|
||||||
return plan;
|
return transfer;
|
||||||
}
|
}
|
||||||
if (info.metadata.compression != VideoOutCompression::Uncompressed) {
|
if (info.metadata.compression != VideoOutCompression::Uncompressed) {
|
||||||
return plan;
|
return transfer;
|
||||||
}
|
}
|
||||||
plan.texture = BuildTextureTransfer(image, binding, TransferDirection::Download);
|
transfer.texture = BuildTextureTransfer(image, binding, TransferDirection::Download);
|
||||||
plan.valid = plan.texture.valid;
|
transfer.valid = transfer.texture.valid;
|
||||||
return plan;
|
return transfer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureCache::UploadImage(Image& image, Buffer& source, uint64_t source_offset) {
|
void TextureCache::UploadImage(Image& image, Buffer& source, uint64_t source_offset) {
|
||||||
@@ -1041,26 +1041,26 @@ void TextureCache::UploadImage(Image& image, Buffer& source, uint64_t source_off
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (binding != BindingType::DepthTarget) {
|
if (binding != BindingType::DepthTarget) {
|
||||||
auto plan = BuildTextureTransfer(image, binding, TransferDirection::Upload);
|
auto transfer = BuildTextureTransfer(image, binding, TransferDirection::Upload);
|
||||||
if (!plan.valid) {
|
if (!transfer.valid) {
|
||||||
EXIT("TextureCache: invalid texture upload: binding=%u addr=0x%016" PRIx64
|
EXIT("TextureCache: invalid texture upload: binding=%u addr=0x%016" PRIx64
|
||||||
" size=0x%016" PRIx64 " format=%u tile=%u family=%u extent=%ux%ux%u "
|
" size=0x%016" PRIx64 " format=%u tile=%u family=%u extent=%ux%ux%u "
|
||||||
"pitch=%u levels=%u layers=%u samples=%u\n",
|
"pitch=%u levels=%u layers=%u samples=%u\n",
|
||||||
static_cast<uint32_t>(binding), info.data.address, info.data.size,
|
static_cast<uint32_t>(binding), info.data.address, info.data.size,
|
||||||
static_cast<uint32_t>(info.guest_format), static_cast<uint32_t>(info.tile_mode),
|
static_cast<uint32_t>(info.guest_format), static_cast<uint32_t>(info.tile_mode),
|
||||||
static_cast<uint32_t>(plan.layout.surface.texture.block.family), info.extent.width,
|
static_cast<uint32_t>(transfer.layout.surface.texture.block.family), info.extent.width,
|
||||||
info.extent.height, info.extent.depth, info.pitch, info.resources.levels,
|
info.extent.height, info.extent.depth, info.pitch, info.resources.levels,
|
||||||
info.resources.layers, info.samples);
|
info.resources.layers, info.samples);
|
||||||
}
|
}
|
||||||
TileManager::Result linear {source.Handle(), source_offset, info.data.size};
|
TileManager::Result linear {source.Handle(), source_offset, info.data.size};
|
||||||
if (!plan.tiles.empty()) {
|
if (!transfer.tiles.empty()) {
|
||||||
linear = m_tiler.Detile(source.Handle(), source_offset, info.data.size,
|
linear = m_tiler.Detile(source.Handle(), source_offset, info.data.size,
|
||||||
plan.LinearSize(), plan.tiles);
|
transfer.LinearSize(), transfer.tiles);
|
||||||
}
|
}
|
||||||
if (plan.swap_bgra16) {
|
if (transfer.swap_bgra16) {
|
||||||
linear = m_tiler.SwapBgra16(linear);
|
linear = m_tiler.SwapBgra16(linear);
|
||||||
}
|
}
|
||||||
upload(plan.regions, linear);
|
upload(transfer.regions, linear);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1669,12 +1669,12 @@ void TextureCache::DownloadDepth(Image& image, Buffer& destination, uint64_t des
|
|||||||
destination_offset, info.data.size, tiles);
|
destination_offset, info.data.size, tiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureCache::DownloadImageData(Image& image, Buffer& destination, uint64_t destination_offset,
|
void TextureCache::DownloadImage(Image& image, Buffer& destination, uint64_t destination_offset,
|
||||||
uint64_t destination_size, DownloadPlan plan) {
|
uint64_t destination_size, ImageDownload transfer) {
|
||||||
if (!plan.valid) {
|
if (!transfer.valid) {
|
||||||
EXIT("TextureCache: invalid image download plan\n");
|
EXIT("TextureCache: invalid image download transfer\n");
|
||||||
}
|
}
|
||||||
if (plan.depth_target) {
|
if (transfer.depth_target) {
|
||||||
if (destination_size != image.info.data.size) {
|
if (destination_size != image.info.data.size) {
|
||||||
EXIT("TextureCache: partial depth image download is unsupported\n");
|
EXIT("TextureCache: partial depth image download is unsupported\n");
|
||||||
}
|
}
|
||||||
@@ -1682,7 +1682,7 @@ void TextureCache::DownloadImageData(Image& image, Buffer& destination, uint64_t
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& texture = plan.texture;
|
auto& texture = transfer.texture;
|
||||||
const auto transform = texture.swap_bgra16 ? TileManager::ColorTransform::SwapBgra16
|
const auto transform = texture.swap_bgra16 ? TileManager::ColorTransform::SwapBgra16
|
||||||
: TileManager::ColorTransform::None;
|
: TileManager::ColorTransform::None;
|
||||||
if (texture.tiles.empty()) {
|
if (texture.tiles.empty()) {
|
||||||
@@ -1743,15 +1743,15 @@ bool BufferCache::SynchronizeBufferFromImage(Buffer& buffer, uint64_t vaddr, uin
|
|||||||
if (copy_size == 0) {
|
if (copy_size == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto plan = m_texture_cache.BuildDownload(image);
|
auto transfer = m_texture_cache.BuildDownload(image);
|
||||||
if (!plan.valid) {
|
if (!transfer.valid) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plan.depth_target && copy_size != image.info.data.size) {
|
if (transfer.depth_target && copy_size != image.info.data.size) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plan.depth_target && levels < image.info.resources.levels) {
|
if (!transfer.depth_target && levels < image.info.resources.levels) {
|
||||||
auto& texture = plan.texture;
|
auto& texture = transfer.texture;
|
||||||
std::erase_if(texture.regions, [levels](const vk::BufferImageCopy& region) {
|
std::erase_if(texture.regions, [levels](const vk::BufferImageCopy& region) {
|
||||||
return region.imageSubresource.mipLevel >= levels;
|
return region.imageSubresource.mipLevel >= levels;
|
||||||
});
|
});
|
||||||
@@ -1766,17 +1766,17 @@ bool BufferCache::SynchronizeBufferFromImage(Buffer& buffer, uint64_t vaddr, uin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_texture_cache.DownloadImageData(image, buffer, buf_offset, copy_size, std::move(plan));
|
m_texture_cache.DownloadImage(image, buffer, buf_offset, copy_size, std::move(transfer));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextureCache::TryDownloadImage(ImageId id) {
|
bool TextureCache::DownloadImageMemory(ImageId id) {
|
||||||
auto& image = m_slot_images[id];
|
auto& image = m_slot_images[id];
|
||||||
if (image.depth_id) {
|
if (image.depth_id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto plan = BuildDownload(image);
|
auto transfer = BuildDownload(image);
|
||||||
if (!plan.valid || !SafeToDownload(image)) {
|
if (!transfer.valid || !SafeToDownload(image)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto range = image.info.data;
|
const auto range = image.info.data;
|
||||||
@@ -1792,7 +1792,7 @@ bool TextureCache::TryDownloadImage(ImageId id) {
|
|||||||
}
|
}
|
||||||
download.Flush(offset, range.size);
|
download.Flush(offset, range.size);
|
||||||
|
|
||||||
DownloadImageData(image, download, offset, range.size, std::move(plan));
|
DownloadImage(image, download, offset, range.size, std::move(transfer));
|
||||||
vk::BufferMemoryBarrier barrier {};
|
vk::BufferMemoryBarrier barrier {};
|
||||||
barrier.srcAccessMask = vk::AccessFlagBits::eMemoryWrite | vk::AccessFlagBits::eTransferWrite |
|
barrier.srcAccessMask = vk::AccessFlagBits::eMemoryWrite | vk::AccessFlagBits::eTransferWrite |
|
||||||
vk::AccessFlagBits::eShaderWrite;
|
vk::AccessFlagBits::eShaderWrite;
|
||||||
@@ -2007,7 +2007,7 @@ void TextureCache::RunGarbageCollector() {
|
|||||||
if (safe && !pressured) {
|
if (safe && !pressured) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (safe && !TryDownloadImage(id)) {
|
if (safe && !DownloadImageMemory(id)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2033,7 +2033,7 @@ void TextureCache::ProcessDownloadImages() {
|
|||||||
for (const auto id: m_download_images) {
|
for (const auto id: m_download_images) {
|
||||||
const auto owner = m_slot_images.try_get(id);
|
const auto owner = m_slot_images.try_get(id);
|
||||||
if (owner != nullptr && owner->registered && owner->IsGpuModified()) {
|
if (owner != nullptr && owner->registered && owner->IsGpuModified()) {
|
||||||
(void)TryDownloadImage(id);
|
(void)DownloadImageMemory(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_download_images.clear();
|
m_download_images.clear();
|
||||||
|
|||||||
+7
-7
@@ -77,8 +77,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
enum class TransferDirection { Upload, Download };
|
enum class TransferDirection { Upload, Download };
|
||||||
struct TextureTransferPlan;
|
struct TextureTransfer;
|
||||||
struct DownloadPlan;
|
struct ImageDownload;
|
||||||
|
|
||||||
struct MetaDataInfo {
|
struct MetaDataInfo {
|
||||||
// A guest metadata-fill dispatch may initialize DCC before its render target is bound.
|
// A guest metadata-fill dispatch may initialize DCC before its render target is bound.
|
||||||
@@ -151,12 +151,12 @@ private:
|
|||||||
void RefreshImage(ImageId id);
|
void RefreshImage(ImageId id);
|
||||||
void PrepareDccClear(ImageId id, const ImageDesc& desc);
|
void PrepareDccClear(ImageId id, const ImageDesc& desc);
|
||||||
void InitializeImage(ImageId id);
|
void InitializeImage(ImageId id);
|
||||||
[[nodiscard]] TextureTransferPlan
|
[[nodiscard]] TextureTransfer
|
||||||
BuildTextureTransfer(const Image& image, BindingType binding, TransferDirection direction) const;
|
BuildTextureTransfer(const Image& image, BindingType binding, TransferDirection direction) const;
|
||||||
[[nodiscard]] DownloadPlan BuildDownload(const Image& image) const;
|
[[nodiscard]] ImageDownload BuildDownload(const Image& image) const;
|
||||||
void UploadImage(Image& image, Buffer& source, uint64_t source_offset);
|
void UploadImage(Image& image, Buffer& source, uint64_t source_offset);
|
||||||
void DownloadImageData(Image& image, Buffer& destination, uint64_t destination_offset,
|
void DownloadImage(Image& image, Buffer& destination, uint64_t destination_offset,
|
||||||
uint64_t destination_size, DownloadPlan plan);
|
uint64_t destination_size, ImageDownload transfer);
|
||||||
void DownloadDepth(Image& image, Buffer& destination, uint64_t destination_offset);
|
void DownloadDepth(Image& image, Buffer& destination, uint64_t destination_offset);
|
||||||
void CommitGpuWrite(Image& image);
|
void CommitGpuWrite(Image& image);
|
||||||
// Caller holds m_lock. Volume layer ranges select depth slices.
|
// Caller holds m_lock. Volume layer ranges select depth slices.
|
||||||
@@ -171,7 +171,7 @@ private:
|
|||||||
void ValidateImageDesc(const ImageDesc& desc) const;
|
void ValidateImageDesc(const ImageDesc& desc) const;
|
||||||
|
|
||||||
void InvalidateCpuAliases(uint64_t address, uint64_t size);
|
void InvalidateCpuAliases(uint64_t address, uint64_t size);
|
||||||
[[nodiscard]] bool TryDownloadImage(ImageId id);
|
[[nodiscard]] bool DownloadImageMemory(ImageId id);
|
||||||
|
|
||||||
GraphicContext& m_graphics;
|
GraphicContext& m_graphics;
|
||||||
CommandScheduler& m_scheduler;
|
CommandScheduler& m_scheduler;
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ struct TextureCacheTestAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool TryDownload(TextureCache &cache, ImageId id) {
|
static bool TryDownload(TextureCache &cache, ImageId id) {
|
||||||
return cache.TryDownloadImage(id);
|
return cache.DownloadImageMemory(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RegisterHtileMeta(TextureCache &cache, uint64_t address) {
|
static void RegisterHtileMeta(TextureCache &cache, uint64_t address) {
|
||||||
|
|||||||
Reference in New Issue
Block a user