Graphics/MaterialPipeline: Rework GetRenderPipeline
Decrease the need for memory allocations in most cases (especially for sprites)
This commit is contained in:
parent
017a6c7af3
commit
04d2f4a6c2
|
|
@ -59,7 +59,7 @@ namespace Nz
|
|||
MaterialPipeline& operator=(MaterialPipeline&&) = delete;
|
||||
|
||||
inline const MaterialPipelineInfo& GetInfo() const;
|
||||
const std::shared_ptr<RenderPipeline>& GetRenderPipeline(const std::vector<RenderPipelineInfo::VertexBufferData>& vertexBuffers) const;
|
||||
const std::shared_ptr<RenderPipeline>& GetRenderPipeline(const RenderPipelineInfo::VertexBufferData* vertexBuffers, std::size_t vertexBufferCount) const;
|
||||
|
||||
static const std::shared_ptr<MaterialPipeline>& Get(const MaterialPipelineInfo& pipelineInfo);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,15 +31,11 @@ namespace Nz
|
|||
|
||||
const std::shared_ptr<VertexDeclaration>& vertexDeclaration = VertexDeclaration::Get(VertexLayout::XYZ_Color_UV);
|
||||
|
||||
std::vector<RenderPipelineInfo::VertexBufferData> vertexBufferData = {
|
||||
{
|
||||
{
|
||||
0,
|
||||
vertexDeclaration
|
||||
}
|
||||
}
|
||||
RenderPipelineInfo::VertexBufferData vertexBufferData = {
|
||||
0,
|
||||
vertexDeclaration
|
||||
};
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(vertexBufferData);
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(&vertexBufferData, 1);
|
||||
|
||||
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)];
|
||||
|
||||
|
|
|
|||
|
|
@ -30,13 +30,15 @@ namespace Nz
|
|||
*
|
||||
* \return Pipeline instance
|
||||
*/
|
||||
const std::shared_ptr<RenderPipeline>& MaterialPipeline::GetRenderPipeline(const std::vector<RenderPipelineInfo::VertexBufferData>& vertexBuffers) const
|
||||
const std::shared_ptr<RenderPipeline>& MaterialPipeline::GetRenderPipeline(const RenderPipelineInfo::VertexBufferData* vertexBuffers, std::size_t vertexBufferCount) const
|
||||
{
|
||||
for (const auto& pipeline : m_renderPipelines)
|
||||
{
|
||||
const auto& pipelineInfo = pipeline->GetPipelineInfo();
|
||||
if (pipelineInfo.vertexBuffers.size() != vertexBufferCount)
|
||||
continue;
|
||||
|
||||
bool isEqual = std::equal(pipelineInfo.vertexBuffers.begin(), pipelineInfo.vertexBuffers.end(), vertexBuffers.begin(), [](const auto& v1, const auto& v2)
|
||||
bool isEqual = std::equal(pipelineInfo.vertexBuffers.begin(), pipelineInfo.vertexBuffers.end(), vertexBuffers, [](const auto& v1, const auto& v2)
|
||||
{
|
||||
return v1.binding == v2.binding && v1.declaration == v2.declaration;
|
||||
});
|
||||
|
|
@ -58,19 +60,19 @@ namespace Nz
|
|||
optionValues[option.hash] = option.value;
|
||||
}
|
||||
|
||||
renderPipelineInfo.vertexBuffers.assign(vertexBuffers, vertexBuffers + vertexBufferCount);
|
||||
|
||||
for (const auto& shader : m_pipelineInfo.shaders)
|
||||
{
|
||||
if (shader.uberShader)
|
||||
{
|
||||
UberShader::Config config{ optionValues };
|
||||
shader.uberShader->UpdateConfig(config, vertexBuffers);
|
||||
shader.uberShader->UpdateConfig(config, renderPipelineInfo.vertexBuffers);
|
||||
|
||||
renderPipelineInfo.shaderModules.push_back(shader.uberShader->Get(config));
|
||||
}
|
||||
}
|
||||
|
||||
renderPipelineInfo.vertexBuffers = vertexBuffers;
|
||||
|
||||
return m_renderPipelines.emplace_back(Graphics::Instance()->GetRenderDevice()->InstantiateRenderPipeline(std::move(renderPipelineInfo)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace Nz
|
|||
|
||||
const auto& indexBuffer = m_graphicalMesh->GetIndexBuffer(i);
|
||||
const auto& vertexBuffer = m_graphicalMesh->GetVertexBuffer(i);
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(submeshData.vertexBufferData);
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(submeshData.vertexBufferData.data(), submeshData.vertexBufferData.size());
|
||||
|
||||
std::size_t indexCount = m_graphicalMesh->GetIndexCount(i);
|
||||
IndexType indexType = m_graphicalMesh->GetIndexType(i);
|
||||
|
|
|
|||
|
|
@ -28,15 +28,11 @@ namespace Nz
|
|||
|
||||
const std::shared_ptr<VertexDeclaration>& vertexDeclaration = VertexDeclaration::Get(VertexLayout::XYZ_Color_UV);
|
||||
|
||||
std::vector<RenderPipelineInfo::VertexBufferData> vertexBufferData = {
|
||||
{
|
||||
{
|
||||
0,
|
||||
vertexDeclaration
|
||||
}
|
||||
}
|
||||
RenderPipelineInfo::VertexBufferData vertexBufferData = {
|
||||
0,
|
||||
vertexDeclaration
|
||||
};
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(vertexBufferData);
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(&vertexBufferData, 1);
|
||||
|
||||
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)];
|
||||
|
||||
|
|
|
|||
|
|
@ -32,15 +32,11 @@ namespace Nz
|
|||
|
||||
const std::shared_ptr<VertexDeclaration>& vertexDeclaration = VertexDeclaration::Get(VertexLayout::XYZ_Color_UV);
|
||||
|
||||
std::vector<RenderPipelineInfo::VertexBufferData> vertexBufferData = {
|
||||
{
|
||||
{
|
||||
0,
|
||||
vertexDeclaration
|
||||
}
|
||||
}
|
||||
RenderPipelineInfo::VertexBufferData vertexBufferData = {
|
||||
0,
|
||||
vertexDeclaration
|
||||
};
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(vertexBufferData);
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(&vertexBufferData, 1);
|
||||
|
||||
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)];
|
||||
|
||||
|
|
|
|||
|
|
@ -27,15 +27,11 @@ namespace Nz
|
|||
|
||||
const std::shared_ptr<VertexDeclaration>& vertexDeclaration = VertexDeclaration::Get(VertexLayout::XYZ_Color_UV);
|
||||
|
||||
std::vector<RenderPipelineInfo::VertexBufferData> vertexBufferData = {
|
||||
{
|
||||
{
|
||||
0,
|
||||
vertexDeclaration
|
||||
}
|
||||
}
|
||||
RenderPipelineInfo::VertexBufferData vertexBufferData = {
|
||||
0,
|
||||
vertexDeclaration
|
||||
};
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(vertexBufferData);
|
||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(&vertexBufferData, 1);
|
||||
|
||||
for (auto& pair : m_renderInfos)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue