From 595842f606bf6a9513f67281f44fe9bab1954dc2 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Sat, 12 Oct 2024 10:24:27 -0700 Subject: [PATCH] vk: Remove naomi2 vertex attributes when not needed Disables the naomi2 vertex input attribute when emitting non-naomi2 pipelines. This addresses some validation messages involving unused vertex inputs and optimizes the bandwidth of the input assembler a little bit for non-naomi2 games. --- core/rend/vulkan/oit/oit_pipeline.cpp | 2 +- core/rend/vulkan/oit/oit_pipeline.h | 29 +++++++++++++++++++------ core/rend/vulkan/pipeline.cpp | 6 +++--- core/rend/vulkan/pipeline.h | 31 ++++++++++++++++++++++----- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/core/rend/vulkan/oit/oit_pipeline.cpp b/core/rend/vulkan/oit/oit_pipeline.cpp index b6d3d31db..d7543934b 100644 --- a/core/rend/vulkan/oit/oit_pipeline.cpp +++ b/core/rend/vulkan/oit/oit_pipeline.cpp @@ -23,7 +23,7 @@ void OITPipelineManager::CreatePipeline(u32 listType, bool autosort, const PolyParam& pp, Pass pass, int gpuPalette) { - vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo = GetMainVertexInputStateCreateInfo(); + vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo = GetMainVertexInputStateCreateInfo(true, pp.isNaomi2()); // Input assembly state vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(), diff --git a/core/rend/vulkan/oit/oit_pipeline.h b/core/rend/vulkan/oit/oit_pipeline.h index e50057381..a3c7b103e 100644 --- a/core/rend/vulkan/oit/oit_pipeline.h +++ b/core/rend/vulkan/oit/oit_pipeline.h @@ -417,7 +417,7 @@ class OITPipelineManager return ((int)mode << 2) | cullMode | ((u32)naomi2 << 5) | ((u32)(!settings.platform.isNaomi2() && config::NativeDepthInterpolation) << 6); } - vk::PipelineVertexInputStateCreateInfo GetMainVertexInputStateCreateInfo(bool full = true) const + vk::PipelineVertexInputStateCreateInfo GetMainVertexInputStateCreateInfo(bool full = true, bool naomi2 = false) const { // Vertex input state static const vk::VertexInputBindingDescription vertexBindingDescriptions[] = @@ -439,12 +439,29 @@ class OITPipelineManager { vk::VertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, x)), // pos }; + + const vk::VertexInputAttributeDescription* attributeDescription = vertexInputLightAttributeDescriptions; + u32 attributeDescriptionSize = std::size(vertexInputLightAttributeDescriptions); + + if (full) + { + attributeDescription = vertexInputAttributeDescriptions; + + if (naomi2) + { + attributeDescriptionSize = std::size(vertexInputAttributeDescriptions); + } + else + { + // naomi2 normal not needed + attributeDescriptionSize = std::size(vertexInputAttributeDescriptions) - 1; + } + } return vk::PipelineVertexInputStateCreateInfo( - vk::PipelineVertexInputStateCreateFlags(), - std::size(vertexBindingDescriptions), - vertexBindingDescriptions, - full ? std::size(vertexInputAttributeDescriptions) : std::size(vertexInputLightAttributeDescriptions), - full ? vertexInputAttributeDescriptions : vertexInputLightAttributeDescriptions); + vk::PipelineVertexInputStateCreateFlags(), + std::size(vertexBindingDescriptions), vertexBindingDescriptions, + attributeDescriptionSize, attributeDescription + ); } void CreatePipeline(u32 listType, bool autosort, const PolyParam& pp, Pass pass, int gpuPalette); diff --git a/core/rend/vulkan/pipeline.cpp b/core/rend/vulkan/pipeline.cpp index eed633be8..faba68abe 100644 --- a/core/rend/vulkan/pipeline.cpp +++ b/core/rend/vulkan/pipeline.cpp @@ -31,7 +31,7 @@ void PipelineManager::CreateModVolPipeline(ModVolMode mode, int cullMode, bool n if (mode == ModVolMode::Final) { - pipelineVertexInputStateCreateInfo = GetMainVertexInputStateCreateInfo(false); + pipelineVertexInputStateCreateInfo = GetMainVertexInputStateCreateInfo(false, naomi2); pipelineInputAssemblyStateCreateInfo = vk::PipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleStrip); } @@ -172,7 +172,7 @@ void PipelineManager::CreateModVolPipeline(ModVolMode mode, int cullMode, bool n void PipelineManager::CreateDepthPassPipeline(int cullMode, bool naomi2) { // Vertex input state - vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo = GetMainVertexInputStateCreateInfo(false); + vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo = GetMainVertexInputStateCreateInfo(false, false); // Input assembly state vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo ( @@ -284,7 +284,7 @@ void PipelineManager::CreateDepthPassPipeline(int cullMode, bool naomi2) void PipelineManager::CreatePipeline(u32 listType, bool sortTriangles, const PolyParam& pp, int gpuPalette, bool dithering) { - vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo = GetMainVertexInputStateCreateInfo(); + vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo = GetMainVertexInputStateCreateInfo(true, pp.isNaomi2()); // Input assembly state vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo; diff --git a/core/rend/vulkan/pipeline.h b/core/rend/vulkan/pipeline.h index e158ef3a4..5e5e32fb0 100644 --- a/core/rend/vulkan/pipeline.h +++ b/core/rend/vulkan/pipeline.h @@ -286,7 +286,7 @@ class PipelineManager return cullMode | ((int)naomi2 << 2) | ((int)(!settings.platform.isNaomi2() && config::NativeDepthInterpolation) << 3); } - vk::PipelineVertexInputStateCreateInfo GetMainVertexInputStateCreateInfo(bool full = true) const + vk::PipelineVertexInputStateCreateInfo GetMainVertexInputStateCreateInfo(bool full = true, bool naomi2 = false) const { // Vertex input state static const vk::VertexInputBindingDescription vertexBindingDescriptions[] = @@ -305,12 +305,33 @@ class PipelineManager { vk::VertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, x)), // pos }; + + + const vk::VertexInputAttributeDescription* attributeDescription = vertexInputLightAttributeDescriptions; + u32 attributeDescriptionSize = std::size(vertexInputLightAttributeDescriptions); + + if (full) + { + attributeDescription = vertexInputAttributeDescriptions; + + if (naomi2) + { + attributeDescriptionSize = std::size(vertexInputAttributeDescriptions); + } + else + { + // naomi2 normal not needed + attributeDescriptionSize = std::size(vertexInputAttributeDescriptions) - 1; + } + } + + + return vk::PipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateFlags(), - std::size(vertexBindingDescriptions), - vertexBindingDescriptions, - full ? std::size(vertexInputAttributeDescriptions) : std::size(vertexInputLightAttributeDescriptions), - full ? vertexInputAttributeDescriptions : vertexInputLightAttributeDescriptions); + std::size(vertexBindingDescriptions), vertexBindingDescriptions, + attributeDescriptionSize, attributeDescription + ); } void CreatePipeline(u32 listType, bool sortTriangles, const PolyParam& pp, int gpuPalette, bool dithering);