From 86dab65af4f4b28faa020e90eb9a287aef75eca2 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Fri, 18 Nov 2022 21:41:23 +0000 Subject: [PATCH] Commonise maxwell3d state updater --- .../{maxwell_3d => common}/state_updater.h | 49 +++++++++++++------ .../interconnect/maxwell_3d/active_state.cpp | 2 +- .../interconnect/maxwell_3d/maxwell_3d.cpp | 2 +- 3 files changed, 37 insertions(+), 16 deletions(-) rename app/src/main/cpp/skyline/gpu/interconnect/{maxwell_3d => common}/state_updater.h (87%) diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/state_updater.h b/app/src/main/cpp/skyline/gpu/interconnect/common/state_updater.h similarity index 87% rename from app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/state_updater.h rename to app/src/main/cpp/skyline/gpu/interconnect/common/state_updater.h index 738e782f..2ceda797 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/state_updater.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/common/state_updater.h @@ -6,7 +6,7 @@ #include #include "common.h" -namespace skyline::gpu::interconnect::maxwell3d { +namespace skyline::gpu::interconnect { /** * @brief Header for a singly-linked state update command */ @@ -35,17 +35,30 @@ namespace skyline::gpu::interconnect::maxwell3d { } }; + static constexpr size_t MaxVertexBufferCount{16}; + struct SetVertexBuffersCmdImpl { void Record(GPU &gpu, vk::raii::CommandBuffer &commandBuffer) { - commandBuffer.bindVertexBuffers(firstBinding, - span(buffers).subspan(firstBinding, bindingCount), - span(offsets).subspan(firstBinding, bindingCount)); + if (ext) { + commandBuffer.bindVertexBuffers2EXT(firstBinding, + span(buffers).subspan(firstBinding, bindingCount), + span(offsets).subspan(firstBinding, bindingCount), + span(sizes).subspan(firstBinding, bindingCount), + span(strides).subspan(firstBinding, bindingCount)); + } else { + commandBuffer.bindVertexBuffers(firstBinding, + span(buffers).subspan(firstBinding, bindingCount), + span(offsets).subspan(firstBinding, bindingCount)); + } } + bool ext{}; u32 firstBinding{}; u32 bindingCount{}; - std::array buffers; - std::array offsets; + std::array buffers; + std::array offsets; + std::array strides; + std::array sizes; }; using SetVertexBuffersCmd = CmdHolder; @@ -54,13 +67,14 @@ namespace skyline::gpu::interconnect::maxwell3d { for (u32 i{base.firstBinding}; i < base.firstBinding + base.bindingCount; i++) { base.buffers[i] = views[i].GetBuffer()->GetBacking(); base.offsets[i] = views[i].GetOffset(); + base.sizes[i] = views[i].size; } base.Record(gpu, commandBuffer); } SetVertexBuffersCmdImpl base{}; - std::array views; + std::array views; }; using SetVertexBuffersDynamicCmd = CmdHolder; @@ -239,10 +253,11 @@ namespace skyline::gpu::interconnect::maxwell3d { struct SetPipelineCmdImpl { void Record(GPU &gpu, vk::raii::CommandBuffer &commandBuffer) { - commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline); + commandBuffer.bindPipeline(bindPoint, pipeline); } vk::Pipeline pipeline; + vk::PipelineBindPoint bindPoint; }; using SetPipelineCmd = CmdHolder; @@ -309,10 +324,11 @@ namespace skyline::gpu::interconnect::maxwell3d { return {head}; } - void SetVertexBuffer(u32 index, const BufferBinding &binding) { - if (index != vertexBatchBindNextBinding || vertexBatchBind->header.record != &SetVertexBuffersCmd::Record) { + void SetVertexBuffer(u32 index, const BufferBinding &binding, bool ext = false, vk::DeviceSize stride = 0) { + if (index != vertexBatchBindNextBinding || vertexBatchBind->header.record != &SetVertexBuffersCmd::Record || vertexBatchBind->cmd.base.ext != ext) { FlushVertexBatchBind(); vertexBatchBind->header.record = &SetVertexBuffersCmd::Record; + vertexBatchBind->cmd.base.ext = ext; vertexBatchBind->cmd.base.firstBinding = index; vertexBatchBindNextBinding = index; } @@ -320,21 +336,25 @@ namespace skyline::gpu::interconnect::maxwell3d { u32 bindingIdx{vertexBatchBindNextBinding++}; vertexBatchBind->cmd.base.buffers[bindingIdx] = binding.buffer; vertexBatchBind->cmd.base.offsets[bindingIdx] = binding.offset; + vertexBatchBind->cmd.base.sizes[bindingIdx] = binding.size; + vertexBatchBind->cmd.base.strides[bindingIdx] = stride; vertexBatchBind->cmd.base.bindingCount++; } - void SetVertexBuffer(u32 index, BufferView view) { + void SetVertexBuffer(u32 index, BufferView view, bool ext = false, vk::DeviceSize stride = 0) { view.GetBuffer()->BlockSequencedCpuBackingWrites(); - if (index != vertexBatchBindNextBinding || vertexBatchBind->header.record != &SetVertexBuffersDynamicCmd::Record) { + if (index != vertexBatchBindNextBinding || vertexBatchBind->header.record != &SetVertexBuffersDynamicCmd::Record || vertexBatchBind->cmd.base.ext != ext) { FlushVertexBatchBind(); vertexBatchBind->header.record = &SetVertexBuffersDynamicCmd::Record; + vertexBatchBind->cmd.base.ext = ext; vertexBatchBind->cmd.base.firstBinding = index; vertexBatchBindNextBinding = index; } u32 bindingIdx{vertexBatchBindNextBinding++}; vertexBatchBind->cmd.views[bindingIdx] = view; + vertexBatchBind->cmd.base.strides[bindingIdx] = stride; vertexBatchBind->cmd.base.bindingCount++; } @@ -409,7 +429,7 @@ namespace skyline::gpu::interconnect::maxwell3d { }); } - void SetBlendConstants(const std::array &blendConstants) { + void SetBlendConstants(const std::array &blendConstants) { AppendCmd( { .blendConstants = blendConstants, @@ -443,10 +463,11 @@ namespace skyline::gpu::interconnect::maxwell3d { }); } - void SetPipeline(vk::Pipeline pipeline) { + void SetPipeline(vk::Pipeline pipeline, vk::PipelineBindPoint bindPoint) { AppendCmd( { .pipeline = pipeline, + .bindPoint = bindPoint, }); } diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.cpp b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.cpp index 3dd9abc9..fadaae0f 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/active_state.cpp @@ -9,8 +9,8 @@ #include #include #include +#include #include "common.h" -#include "state_updater.h" #include "active_state.h" namespace skyline::gpu::interconnect::maxwell3d { diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/maxwell_3d.cpp b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/maxwell_3d.cpp index 6b245ce8..e09b03b8 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/maxwell_3d.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/maxwell_3d.cpp @@ -4,11 +4,11 @@ #include #include +#include #include #include "common/utils.h" #include "maxwell_3d.h" #include "common.h" -#include "state_updater.h" namespace skyline::gpu::interconnect::maxwell3d { Maxwell3D::Maxwell3D(GPU &gpu,