mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-20 22:05:12 +00:00
rsx/vk: Support ingesting pre-processed GPU data as texture input
This commit is contained in:
parent
bef7d793d3
commit
ca054644ef
5 changed files with 104 additions and 26 deletions
|
|
@ -1,3 +1,5 @@
|
|||
#include "VKCompute.h"
|
||||
#include "VKDMA.h"
|
||||
#include "VKRenderTargets.h"
|
||||
#include "VKResourceManager.h"
|
||||
#include "Emu/RSX/rsx_methods.h"
|
||||
|
|
@ -681,32 +683,75 @@ namespace vk
|
|||
subres.depth = 1;
|
||||
subres.data = { vm::get_super_ptr<const std::byte>(base_addr), static_cast<std::span<const std::byte>::size_type>(rsx_pitch * surface_height * samples_y) };
|
||||
|
||||
// FIXME: Move to GPU queue
|
||||
std::vector<std::byte> ext_data;
|
||||
const auto range = get_memory_range();
|
||||
rsx::flags32_t upload_flags = upload_contents_inline;
|
||||
u32 heap_align = rsx_pitch;
|
||||
|
||||
if (auto region = rsx::get_current_renderer()->get_tiled_memory_region(range))
|
||||
if (auto tiled_region = rsx::get_current_renderer()->get_tiled_memory_region(range))
|
||||
{
|
||||
auto real_data = vm::get_super_ptr<u8>(range.start);
|
||||
ext_data.resize(region.tile->size);
|
||||
rsx::tile_texel_data<u32, true>(
|
||||
ext_data.data(),
|
||||
real_data,
|
||||
region.base_address,
|
||||
range.start - region.base_address,
|
||||
region.tile->size,
|
||||
region.tile->bank,
|
||||
region.tile->pitch,
|
||||
subres.width_in_block,
|
||||
subres.height_in_block
|
||||
);
|
||||
subres.data = std::span(ext_data);
|
||||
const auto available_tile_size = tiled_region.tile->size - (range.start - tiled_region.base_address);
|
||||
const auto max_content_size = tiled_region.tile->pitch * utils::align<u32>(subres.height_in_block, 64);
|
||||
const auto section_length = std::min(max_content_size, available_tile_size);
|
||||
|
||||
const auto dma_mapping = vk::map_dma(range.start, section_length);
|
||||
const auto scratch_buf = vk::get_scratch_buffer(cmd, section_length * 3); // 0 = linear data, 1 = padding (deswz), 2 = tiled data
|
||||
const auto tiled_data_scratch_offset = section_length * 2;
|
||||
const auto linear_data_scratch_offset = 0;
|
||||
|
||||
// Schedule the job
|
||||
const RSX_detiler_config config =
|
||||
{
|
||||
.tile_base_address = tiled_region.base_address,
|
||||
.tile_base_offset = range.start - tiled_region.base_address,
|
||||
.tile_size = tiled_region.tile->size,
|
||||
.tile_pitch = tiled_region.tile->pitch,
|
||||
.bank = tiled_region.tile->bank,
|
||||
|
||||
.dst = scratch_buf,
|
||||
.dst_offset = linear_data_scratch_offset,
|
||||
.src = scratch_buf,
|
||||
.src_offset = section_length * 2,
|
||||
|
||||
.image_width = subres.width_in_block,
|
||||
.image_height = subres.height_in_block,
|
||||
.image_pitch = subres.width_in_block * static_cast<u32>(get_bpp()),
|
||||
.image_bpp = get_bpp()
|
||||
};
|
||||
|
||||
// Transfer
|
||||
VkBufferCopy copy_rgn
|
||||
{
|
||||
.srcOffset = dma_mapping.first,
|
||||
.dstOffset = tiled_data_scratch_offset,
|
||||
.size = section_length
|
||||
};
|
||||
vkCmdCopyBuffer(cmd, dma_mapping.second->value, scratch_buf->value, 1, ©_rgn);
|
||||
|
||||
// Barrier
|
||||
vk::insert_buffer_memory_barrier(
|
||||
cmd, scratch_buf->value, linear_data_scratch_offset, section_length,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||
|
||||
// Detile
|
||||
vk::get_compute_task<vk::cs_tile_memcpy<RSX_detiler_op::decode>>()->run(cmd, config);
|
||||
|
||||
// Barrier
|
||||
vk::insert_buffer_memory_barrier(
|
||||
cmd, scratch_buf->value, linear_data_scratch_offset, subres.width_in_block * get_bpp() * subres.height_in_block,
|
||||
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT);
|
||||
|
||||
// FIXME: !!EVIL!!
|
||||
subres.data = { scratch_buf, linear_data_scratch_offset };
|
||||
upload_flags |= source_is_gpu_resident;
|
||||
heap_align = subres.width_in_block * get_bpp();
|
||||
}
|
||||
|
||||
if (g_cfg.video.resolution_scale_percent == 100 && spp == 1) [[likely]]
|
||||
{
|
||||
push_layout(cmd, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
vk::upload_image(cmd, this, { subres }, get_gcm_format(), is_swizzled, 1, aspect(), upload_heap, rsx_pitch, upload_contents_inline);
|
||||
vk::upload_image(cmd, this, { subres }, get_gcm_format(), is_swizzled, 1, aspect(), upload_heap, heap_align, upload_flags);
|
||||
pop_layout(cmd);
|
||||
}
|
||||
else
|
||||
|
|
@ -735,7 +780,7 @@ namespace vk
|
|||
}
|
||||
|
||||
// Load Cell data into temp buffer
|
||||
vk::upload_image(cmd, content, { subres }, get_gcm_format(), is_swizzled, 1, aspect(), upload_heap, rsx_pitch, upload_contents_inline);
|
||||
vk::upload_image(cmd, content, { subres }, get_gcm_format(), is_swizzled, 1, aspect(), upload_heap, heap_align, upload_flags);
|
||||
|
||||
// Write into final image
|
||||
if (content != final_dst)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue