Added Collision Tags #233

Merged
direnbharwani merged 10 commits from SP3-2-Physics into main 2022-11-20 22:40:53 +08:00
7 changed files with 38 additions and 15 deletions
Showing only changes of commit b8530dfc89 - Show all commits

View File

@ -174,7 +174,6 @@ namespace SHADE
bool shaderChanged = false; bool shaderChanged = false;
const auto* SHADER_INFO = SHAssetManager::GetData<SHShaderAsset>(currentMatSpec->fragShader); const auto* SHADER_INFO = SHAssetManager::GetData<SHShaderAsset>(currentMatSpec->fragShader);
const std::string SHADER_NAME = SHADER_INFO ? SHADER_INFO->name : "Unknown Shader"; const std::string SHADER_NAME = SHADER_INFO ? SHADER_INFO->name : "Unknown Shader";
ImGui::BeginDisabled();
isDirty |= SHEditorWidgets::DragDropReadOnlyField<AssetID> isDirty |= SHEditorWidgets::DragDropReadOnlyField<AssetID>
( (
"Fragment Shader", SHADER_NAME.data(), "Fragment Shader", SHADER_NAME.data(),
@ -182,7 +181,6 @@ namespace SHADE
[this](const AssetID& id) { currentMatSpec->fragShader = id; }, [this](const AssetID& id) { currentMatSpec->fragShader = id; },
SHDragDrop::DRAG_RESOURCE SHDragDrop::DRAG_RESOURCE
); );
ImGui::EndDisabled();
// Load the shader to access it's data // Load the shader to access it's data
auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->fragShader); auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->fragShader);

View File

@ -219,9 +219,13 @@ namespace SHADE
for (int i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i) for (int i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i)
{ {
drawDataBuffer[i].Free(); drawDataBuffer[i].Free();
drawDataBuffer[i] = {};
transformDataBuffer[i].Free(); transformDataBuffer[i].Free();
transformDataBuffer[i] = {};
instancedIntegerBuffer[i].Free(); instancedIntegerBuffer[i].Free();
instancedIntegerBuffer[i] = {};
matPropsBuffer[i].Free(); matPropsBuffer[i].Free();
matPropsBuffer[i] = {};
} }
} }
@ -538,9 +542,13 @@ namespace SHADE
return; return;
} }
// Nothing to draw
if (subBatches.empty())
return;
// Bind all required objects before drawing // Bind all required objects before drawing
static std::array<uint32_t, 1> dynamicOffset{ 0 }; static std::array<uint32_t, 1> dynamicOffset{ 0 };
cmdBuffer->BeginLabeledSegment("SHBatch"); cmdBuffer->BeginLabeledSegment("SHBatch for Pipeline #" + std::to_string(pipeline.GetId().Data.Index));
cmdBuffer->BindPipeline(pipeline); cmdBuffer->BindPipeline(pipeline);
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0);
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0);

View File

@ -55,13 +55,14 @@ namespace SHADE
void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept
{ {
const Handle<SHVkPipeline> PIPELINE = renderable->GetMaterial()->GetBaseMaterial()->GetPipeline(); Handle<SHMaterial> baseMat = renderable->GetMaterial()->GetBaseMaterial();
const Handle<SHVkPipeline> PIPELINE = baseMat->HasPipelineChanged() ? baseMat->GetPrevPipeline() : baseMat->GetPipeline();
// Check if we have a Batch with the same pipeline yet // Check if we have a Batch with the same pipeline yet
auto batch = std::find_if(batches.begin(), batches.end(), [&](const SHBatch& batch) auto batch = std::find_if(batches.begin(), batches.end(), [&](const SHBatch& batch)
{ {
return batch.GetPipeline() == PIPELINE; return batch.GetPipeline() == PIPELINE;
}); });
// Attempt to remove if it exists // Attempt to remove if it exists
if (batch == batches.end()) if (batch == batches.end())

View File

@ -890,7 +890,9 @@ namespace SHADE
Handle<SHMaterialInstance> prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial(); Handle<SHMaterialInstance> prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial();
if (prevMaterial) if (prevMaterial)
{ {
Handle<SHSuperBatch> oldSuperBatch = prevMaterial->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch(); Handle<SHMaterial> baseMat = prevMaterial->GetBaseMaterial();
Handle<SHVkPipeline> prevPipeline = baseMat->HasPipelineChanged() ? baseMat->GetPrevPipeline() : baseMat->GetPipeline();
Handle<SHSuperBatch> oldSuperBatch = prevPipeline->GetPipelineState().GetSubpass()->GetSuperBatch();
oldSuperBatch->Remove(&renderable); oldSuperBatch->Remove(&renderable);
} }
@ -905,6 +907,14 @@ namespace SHADE
// Unset change flag // Unset change flag
renderable.ResetChangedFlag(); renderable.ResetChangedFlag();
} }
// Unset all material old pipeline since we would have finished processing
auto gfxSystem = reinterpret_cast<SHGraphicsSystem*>(system);
auto [matBegin, matEnd] = gfxSystem->resourceManager.GetDenseAccess<SHMaterial>();
for (auto iter = matBegin; iter != matEnd; ++iter)
{
iter->ForgetOldPipeline();
}
} }
#pragma endregion ROUTINES #pragma endregion ROUTINES

View File

@ -21,6 +21,8 @@ namespace SHADE
if (_pipeline == pipeline) if (_pipeline == pipeline)
return; return;
// Mark old pipeline and set new pipeline
oldPipeline = pipeline;
pipeline = _pipeline; pipeline = _pipeline;
// Set up properties based on the pipeline // Set up properties based on the pipeline
@ -41,9 +43,6 @@ namespace SHADE
// Reset since pipeline changed // Reset since pipeline changed
ResetProperties(); ResetProperties();
// Mark changed so that we know to update dependent material instances
propertiesChanged = true;
} }
Handle<SHVkPipeline> SHMaterial::GetPipeline() const Handle<SHVkPipeline> SHMaterial::GetPipeline() const
@ -111,4 +110,9 @@ namespace SHADE
{ {
propertiesChanged = false; propertiesChanged = false;
} }
void SHMaterial::ForgetOldPipeline() noexcept
{
oldPipeline = {};
}
} }

View File

@ -44,6 +44,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
void SetPipeline(Handle<SHVkPipeline> _pipeline); void SetPipeline(Handle<SHVkPipeline> _pipeline);
Handle<SHVkPipeline> GetPipeline() const; Handle<SHVkPipeline> GetPipeline() const;
Handle<SHVkPipeline> GetPrevPipeline() const { return oldPipeline; };
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Property Functions */ /* Property Functions */
@ -68,10 +69,11 @@ namespace SHADE
/* Query Functions */ /* Query Functions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
Handle<SHShaderBlockInterface> GetShaderBlockInterface() const noexcept; Handle<SHShaderBlockInterface> GetShaderBlockInterface() const noexcept;
bool HasPipelineChanged() const noexcept { return pipelineChanged; } bool HasPipelineChanged() const noexcept { return oldPipeline; }
bool HasPropertiesChanged() const noexcept { return propertiesChanged; } bool HasPropertiesChanged() const noexcept { return propertiesChanged; }
bool HasChanged() const noexcept { return pipelineChanged || propertiesChanged; } bool HasChanged() const noexcept { return oldPipeline || propertiesChanged; }
void ClearChangeFlag() noexcept; void ClearChangeFlag() noexcept;
void ForgetOldPipeline() noexcept;
private: private:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -81,7 +83,7 @@ namespace SHADE
std::unique_ptr<char> propMemory; std::unique_ptr<char> propMemory;
Byte propMemorySize = 0; Byte propMemorySize = 0;
bool propertiesChanged = true; bool propertiesChanged = true;
bool pipelineChanged = true; Handle<SHVkPipeline> oldPipeline;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */

View File

@ -129,7 +129,7 @@ namespace SHADE
// Otherwise just copy the data over // Otherwise just copy the data over
else else
{ {
bufferHandle->MapWriteUnmap(src, size, 0, 0); bufferHandle->WriteToMemory(src, size, 0, 0);
} }
} }
else else