Accounted for Shaders with no SHShaderBlockInterface

This commit is contained in:
Kah Wei 2022-09-19 00:11:44 +08:00
parent 23fe51b483
commit 8070b2dafa
3 changed files with 42 additions and 14 deletions

View File

@ -107,18 +107,20 @@ namespace SHADE
transformData.reserve(numTotalElements); transformData.reserve(numTotalElements);
transformData.clear(); transformData.clear();
// - Material Properties Data // - Material Properties Data
const Byte SINGLE_MAT_PROPS_SIZE = pipeline->GetPipelineLayout()->GetShaderBlockInterface const Handle<SHShaderBlockInterface> SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface
( (
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
vk::ShaderStageFlagBits::eFragment vk::ShaderStageFlagBits::eFragment
)->GetBytesRequired(); );
const Byte SINGLE_MAT_PROPS_SIZE = SHADER_INFO->GetBytesRequired();
const Byte MATPROPS_TOTAL_BYTES = drawData.size() * SINGLE_MAT_PROPS_SIZE; const Byte MATPROPS_TOTAL_BYTES = drawData.size() * SINGLE_MAT_PROPS_SIZE;
if (matPropsDataSize < MATPROPS_TOTAL_BYTES) if (matPropsDataSize < MATPROPS_TOTAL_BYTES)
{ {
matPropsData.reset(new char[MATPROPS_TOTAL_BYTES]); matPropsData.reset(new char[MATPROPS_TOTAL_BYTES]);
matPropsDataSize = MATPROPS_TOTAL_BYTES; matPropsDataSize = MATPROPS_TOTAL_BYTES;
} }
const bool EMPTY_MAT_PROPS = MATPROPS_TOTAL_BYTES <= 0;
// Build Sub Batches // Build Sub Batches
uint32_t nextInstanceIndex = 0; uint32_t nextInstanceIndex = 0;
@ -141,8 +143,11 @@ namespace SHADE
// Transform // Transform
transformData.emplace_back(renderable->TransformMatrix); transformData.emplace_back(renderable->TransformMatrix);
// Material Properties // Material Properties
renderable->GetMaterial()->ExportProperties(propsCurrPtr); if (!EMPTY_MAT_PROPS)
propsCurrPtr += SINGLE_MAT_PROPS_SIZE; {
renderable->GetMaterial()->ExportProperties(propsCurrPtr);
propsCurrPtr += SINGLE_MAT_PROPS_SIZE;
}
} }
} }
@ -177,6 +182,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
void SHBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer) void SHBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer)
{ {
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer, 0);
cmdBuffer->DrawMultiIndirect(drawDataBuffer, static_cast<uint32_t>(drawData.size())); cmdBuffer->DrawMultiIndirect(drawDataBuffer, static_cast<uint32_t>(drawData.size()));
} }
} }

View File

@ -71,6 +71,17 @@ namespace SHADE
static constexpr uint32_t BATCHED_PER_INST_DATA = 0; static constexpr uint32_t BATCHED_PER_INST_DATA = 0;
}; };
struct VertexBufferBindings
{
/***************************************************************************/
/*!
\brief
Vertex buffer bindings for the transform matrix buffer.
*/
/***************************************************************************/
static constexpr uint32_t TRANSFORM = 4;
};
/*******************************************************************************/ /*******************************************************************************/
/*! /*!
\brief \brief

View File

@ -22,9 +22,17 @@ namespace SHADE
return; return;
} }
// Allocate memory for properties // Allocate memory for properties
propMemorySize = getShaderBlockInterface()->GetBytesRequired(); const Handle<SHShaderBlockInterface> SHADER_INFO = getShaderBlockInterface();
propMemory.reset(new char[propMemorySize]); propMemorySize = SHADER_INFO ? SHADER_INFO->GetBytesRequired() : 0;
if (propMemorySize <= 0)
{
propMemory.reset();
}
else
{
propMemory.reset(new char[propMemorySize]);
}
ResetProperties(); ResetProperties();
} }
@ -39,17 +47,20 @@ namespace SHADE
void SHMaterial::ResetProperties() void SHMaterial::ResetProperties()
{ {
// Reset all the properties to default values // Reset all the properties to default values
memset(propMemory.get(), 0, propMemorySize); if (propMemory)
memset(propMemory.get(), 0, propMemorySize);
} }
void SHMaterial::ExportProperties(void* dest) const noexcept void SHMaterial::ExportProperties(void* dest) const noexcept
{ {
memcpy(dest, propMemory.get(), propMemorySize); if (propMemory)
memcpy(dest, propMemory.get(), propMemorySize);
} }
size_t SHMaterial::GetPropertiesMemorySize() const noexcept size_t SHMaterial::GetPropertiesMemorySize() const noexcept
{ {
return getShaderBlockInterface()->GetBytesRequired(); const Handle<SHShaderBlockInterface> SHADER_INFO = getShaderBlockInterface();
return SHADER_INFO ? SHADER_INFO->GetBytesRequired() : 0;
} }
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/