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.clear();
// - Material Properties Data
const Byte SINGLE_MAT_PROPS_SIZE = pipeline->GetPipelineLayout()->GetShaderBlockInterface
(
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
vk::ShaderStageFlagBits::eFragment
)->GetBytesRequired();
const Handle<SHShaderBlockInterface> SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface
(
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
vk::ShaderStageFlagBits::eFragment
);
const Byte SINGLE_MAT_PROPS_SIZE = SHADER_INFO->GetBytesRequired();
const Byte MATPROPS_TOTAL_BYTES = drawData.size() * SINGLE_MAT_PROPS_SIZE;
if (matPropsDataSize < MATPROPS_TOTAL_BYTES)
{
matPropsData.reset(new char[MATPROPS_TOTAL_BYTES]);
matPropsDataSize = MATPROPS_TOTAL_BYTES;
}
const bool EMPTY_MAT_PROPS = MATPROPS_TOTAL_BYTES <= 0;
// Build Sub Batches
uint32_t nextInstanceIndex = 0;
@ -141,8 +143,11 @@ namespace SHADE
// Transform
transformData.emplace_back(renderable->TransformMatrix);
// Material Properties
renderable->GetMaterial()->ExportProperties(propsCurrPtr);
propsCurrPtr += SINGLE_MAT_PROPS_SIZE;
if (!EMPTY_MAT_PROPS)
{
renderable->GetMaterial()->ExportProperties(propsCurrPtr);
propsCurrPtr += SINGLE_MAT_PROPS_SIZE;
}
}
}
@ -177,6 +182,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
void SHBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer)
{
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer, 0);
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;
};
struct VertexBufferBindings
{
/***************************************************************************/
/*!
\brief
Vertex buffer bindings for the transform matrix buffer.
*/
/***************************************************************************/
static constexpr uint32_t TRANSFORM = 4;
};
/*******************************************************************************/
/*!
\brief

View File

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