Skip to content

Commit

Permalink
vk: Remove naomi2 vertex attributes when not needed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Wunkolo authored and flyinghead committed Oct 13, 2024
1 parent 8f74f78 commit 595842f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion core/rend/vulkan/oit/oit_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
29 changes: 23 additions & 6 deletions core/rend/vulkan/oit/oit_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[] =
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions core/rend/vulkan/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
(
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 26 additions & 5 deletions core/rend/vulkan/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[] =
Expand All @@ -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);
Expand Down

0 comments on commit 595842f

Please sign in to comment.