Re-added ability to change shaders #229
|
@ -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);
|
||||||
|
|
|
@ -507,9 +507,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);
|
||||||
|
|
|
@ -55,7 +55,8 @@ 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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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 = {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 */
|
||||||
|
|
Loading…
Reference in New Issue