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

gl_rasterizer: Implement AccelerateDMA DmaBufferImageCopy

This commit is contained in:
ameerj 2023-03-06 21:53:51 -05:00
parent 6b9cc0ed23
commit 268942c8fe
2 changed files with 52 additions and 9 deletions

View File

@ -63,7 +63,7 @@ RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegra
buffer_cache(*this, cpu_memory_, buffer_cache_runtime), buffer_cache(*this, cpu_memory_, buffer_cache_runtime),
shader_cache(*this, emu_window_, device, texture_cache, buffer_cache, program_manager, shader_cache(*this, emu_window_, device, texture_cache, buffer_cache, program_manager,
state_tracker, gpu.ShaderNotify()), state_tracker, gpu.ShaderNotify()),
query_cache(*this), accelerate_dma(buffer_cache), query_cache(*this), accelerate_dma(buffer_cache, texture_cache),
fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache), fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache),
blit_image(program_manager_) {} blit_image(program_manager_) {}
@ -1262,7 +1262,8 @@ void RasterizerOpenGL::ReleaseChannel(s32 channel_id) {
query_cache.EraseChannel(channel_id); query_cache.EraseChannel(channel_id);
} }
AccelerateDMA::AccelerateDMA(BufferCache& buffer_cache_) : buffer_cache{buffer_cache_} {} AccelerateDMA::AccelerateDMA(BufferCache& buffer_cache_, TextureCache& texture_cache_)
: buffer_cache{buffer_cache_}, texture_cache{texture_cache_} {}
bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) { bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) {
std::scoped_lock lock{buffer_cache.mutex}; std::scoped_lock lock{buffer_cache.mutex};
@ -1274,4 +1275,44 @@ bool AccelerateDMA::BufferClear(GPUVAddr src_address, u64 amount, u32 value) {
return buffer_cache.DMAClear(src_address, amount, value); return buffer_cache.DMAClear(src_address, amount, value);
} }
template <bool IS_IMAGE_UPLOAD>
bool AccelerateDMA::DmaBufferImageCopy(const Tegra::DMA::ImageCopy& copy_info,
const Tegra::DMA::BufferOperand& buffer_operand,
const Tegra::DMA::ImageOperand& image_operand) {
std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex};
const auto image_id = texture_cache.DmaImageId(image_operand);
if (image_id == VideoCommon::NULL_IMAGE_ID) {
return false;
}
const u32 buffer_size = static_cast<u32>(buffer_operand.pitch * buffer_operand.height);
static constexpr auto sync_info = VideoCommon::ObtainBufferSynchronize::FullSynchronize;
const auto post_op = IS_IMAGE_UPLOAD ? VideoCommon::ObtainBufferOperation::DoNothing
: VideoCommon::ObtainBufferOperation::MarkAsWritten;
const auto [buffer, offset] =
buffer_cache.ObtainBuffer(buffer_operand.address, buffer_size, sync_info, post_op);
const auto [image, copy] = texture_cache.DmaBufferImageCopy(
copy_info, buffer_operand, image_operand, image_id, IS_IMAGE_UPLOAD);
const std::span copy_span{&copy, 1};
if constexpr (IS_IMAGE_UPLOAD) {
image->UploadMemory(buffer->Handle(), offset, copy_span);
} else {
image->DownloadMemory(buffer->Handle(), offset, copy_span);
}
return true;
}
bool AccelerateDMA::ImageToBuffer(const Tegra::DMA::ImageCopy& copy_info,
const Tegra::DMA::ImageOperand& image_operand,
const Tegra::DMA::BufferOperand& buffer_operand) {
return DmaBufferImageCopy<false>(copy_info, buffer_operand, image_operand);
}
bool AccelerateDMA::BufferToImage(const Tegra::DMA::ImageCopy& copy_info,
const Tegra::DMA::BufferOperand& buffer_operand,
const Tegra::DMA::ImageOperand& image_operand) {
return DmaBufferImageCopy<true>(copy_info, buffer_operand, image_operand);
}
} // namespace OpenGL } // namespace OpenGL

View File

@ -50,24 +50,26 @@ static_assert(sizeof(BindlessSSBO) * CHAR_BIT == 128);
class AccelerateDMA : public Tegra::Engines::AccelerateDMAInterface { class AccelerateDMA : public Tegra::Engines::AccelerateDMAInterface {
public: public:
explicit AccelerateDMA(BufferCache& buffer_cache); explicit AccelerateDMA(BufferCache& buffer_cache, TextureCache& texture_cache);
bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) override; bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) override;
bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override; bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override;
bool ImageToBuffer(const Tegra::DMA::ImageCopy& copy_info, const Tegra::DMA::ImageOperand& src, bool ImageToBuffer(const Tegra::DMA::ImageCopy& copy_info, const Tegra::DMA::ImageOperand& src,
const Tegra::DMA::BufferOperand& dst) override { const Tegra::DMA::BufferOperand& dst) override;
return false;
}
bool BufferToImage(const Tegra::DMA::ImageCopy& copy_info, const Tegra::DMA::BufferOperand& src, bool BufferToImage(const Tegra::DMA::ImageCopy& copy_info, const Tegra::DMA::BufferOperand& src,
const Tegra::DMA::ImageOperand& dst) override { const Tegra::DMA::ImageOperand& dst) override;
return false;
}
private: private:
template <bool IS_IMAGE_UPLOAD>
bool DmaBufferImageCopy(const Tegra::DMA::ImageCopy& copy_info,
const Tegra::DMA::BufferOperand& src,
const Tegra::DMA::ImageOperand& dst);
BufferCache& buffer_cache; BufferCache& buffer_cache;
TextureCache& texture_cache;
}; };
class RasterizerOpenGL : public VideoCore::RasterizerAccelerated, class RasterizerOpenGL : public VideoCore::RasterizerAccelerated,