From 8b8be8e90c22c6197307d32d1452b5d774ad3464 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Wed, 4 Jun 2025 23:19:23 -0500 Subject: [PATCH] vertex manager base --- Source/Core/VideoCommon/VertexManagerBase.cpp | 45 ++++++++++++++----- Source/Core/VideoCommon/VertexManagerBase.h | 5 ++- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 56d2c2c609..03cb9a08ab 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -1333,7 +1333,8 @@ void VertexManagerBase::DrawEmulatedMesh(GraphicsModSystem::MaterialResource* ma } } -void VertexManagerBase::DrawCustomMesh(GraphicsModSystem::MeshResource* mesh_resource, +void VertexManagerBase::DrawCustomMesh(GraphicsModSystem::DrawCallID draw_call, + GraphicsModSystem::MeshResource* mesh_resource, const GraphicsModSystem::DrawDataView& draw_data, const Common::Matrix44& custom_transform, bool ignore_mesh_transform, @@ -1342,15 +1343,20 @@ void VertexManagerBase::DrawCustomMesh(GraphicsModSystem::MeshResource* mesh_res auto& system = Core::System::GetInstance(); auto& vertex_shader_manager = system.GetVertexShaderManager(); - for (const auto& mesh_chunk : mesh_resource->mesh_chunks) - { + const auto process_mesh_chunk = [&](const GraphicsModSystem::MeshChunkResource& mesh_chunk, + std::span index_data) { // TODO: draw with a generic material? if (!mesh_chunk.material) [[unlikely]] - continue; + return; if (!mesh_chunk.material->pipeline || !mesh_chunk.material->pipeline->m_config.vertex_shader || !mesh_chunk.material->pipeline->m_config.pixel_shader) [[unlikely]] - continue; + { + return; + } + + if (mesh_chunk.vertex_data.empty() || index_data.empty()) [[unlikely]] + return; vertex_shader_manager.SetVertexFormat(mesh_chunk.components_available, mesh_chunk.vertex_format->GetVertexDeclaration()); @@ -1365,14 +1371,33 @@ void VertexManagerBase::DrawCustomMesh(GraphicsModSystem::MeshResource* mesh_res 4 * sizeof(float4)); u32 base_vertex, base_index; - UploadUtilityVertices( - mesh_chunk.vertex_data.data(), mesh_chunk.vertex_stride, - static_cast(mesh_chunk.vertex_data.size()), mesh_chunk.index_data.data(), - static_cast(mesh_chunk.index_data.size()), &base_vertex, &base_index); + UploadUtilityVertices(mesh_chunk.vertex_data.data(), mesh_chunk.vertex_stride, + static_cast(mesh_chunk.vertex_data.size()), index_data.data(), + static_cast(index_data.size()), &base_vertex, &base_index); - DrawViewsWithMaterial(base_vertex, base_index, static_cast(mesh_chunk.index_data.size()), + DrawViewsWithMaterial(base_vertex, base_index, static_cast(index_data.size()), mesh_chunk.primitive_type, draw_data, mesh_chunk.material, camera_manager); + }; + + if (mesh_resource->draw_call_to_gpu_skinning_mesh_chunk.empty()) + { + for (const auto& mesh_chunk : mesh_resource->mesh_chunks) + { + process_mesh_chunk(mesh_chunk, mesh_chunk.index_data); + } + } + else + { + if (const auto iter = mesh_resource->draw_call_to_gpu_skinning_mesh_chunk.find(draw_call); + iter != mesh_resource->draw_call_to_gpu_skinning_mesh_chunk.end()) + { + auto& gpu_skinning_chunks = iter->second; + for (const auto& skinning_chunk : gpu_skinning_chunks) + { + process_mesh_chunk(skinning_chunk, skinning_chunk.index_data); + } + } } } diff --git a/Source/Core/VideoCommon/VertexManagerBase.h b/Source/Core/VideoCommon/VertexManagerBase.h index 2f627747b1..d2bc121b12 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.h +++ b/Source/Core/VideoCommon/VertexManagerBase.h @@ -28,6 +28,8 @@ struct PortableVertexDeclaration; namespace GraphicsModSystem { +enum class DrawCallID : unsigned long long; + struct DrawDataView; struct MaterialResource; struct MeshResource; @@ -199,7 +201,8 @@ public: VideoCommon::CameraManager& camera_manager); // Draw a custom mesh sourced from a mod, with a custom shader and custom vertex information - void DrawCustomMesh(GraphicsModSystem::MeshResource* mesh_resource, + void DrawCustomMesh(GraphicsModSystem::DrawCallID draw_call, + GraphicsModSystem::MeshResource* mesh_resource, const GraphicsModSystem::DrawDataView& draw_data, const Common::Matrix44& custom_transform, bool ignore_mesh_transform, VideoCommon::CameraManager& camera_manager);