Re-added ability to change shaders #229
|
@ -174,7 +174,6 @@ namespace SHADE
|
|||
bool shaderChanged = false;
|
||||
const auto* SHADER_INFO = SHAssetManager::GetData<SHShaderAsset>(currentMatSpec->fragShader);
|
||||
const std::string SHADER_NAME = SHADER_INFO ? SHADER_INFO->name : "Unknown Shader";
|
||||
ImGui::BeginDisabled();
|
||||
isDirty |= SHEditorWidgets::DragDropReadOnlyField<AssetID>
|
||||
(
|
||||
"Fragment Shader", SHADER_NAME.data(),
|
||||
|
@ -182,7 +181,6 @@ namespace SHADE
|
|||
[this](const AssetID& id) { currentMatSpec->fragShader = id; },
|
||||
SHDragDrop::DRAG_RESOURCE
|
||||
);
|
||||
ImGui::EndDisabled();
|
||||
|
||||
// Load the shader to access it's data
|
||||
auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->fragShader);
|
||||
|
|
|
@ -219,9 +219,13 @@ namespace SHADE
|
|||
for (int i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i)
|
||||
{
|
||||
drawDataBuffer[i].Free();
|
||||
drawDataBuffer[i] = {};
|
||||
transformDataBuffer[i].Free();
|
||||
transformDataBuffer[i] = {};
|
||||
instancedIntegerBuffer[i].Free();
|
||||
instancedIntegerBuffer[i] = {};
|
||||
matPropsBuffer[i].Free();
|
||||
matPropsBuffer[i] = {};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -538,9 +542,13 @@ namespace SHADE
|
|||
return;
|
||||
}
|
||||
|
||||
// Nothing to draw
|
||||
if (subBatches.empty())
|
||||
return;
|
||||
|
||||
// Bind all required objects before drawing
|
||||
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->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0);
|
||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0);
|
||||
|
|
|
@ -55,13 +55,14 @@ namespace SHADE
|
|||
|
||||
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
|
||||
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
|
||||
if (batch == batches.end())
|
||||
|
|
|
@ -890,7 +890,9 @@ namespace SHADE
|
|||
Handle<SHMaterialInstance> prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial();
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -905,6 +907,14 @@ namespace SHADE
|
|||
// Unset change flag
|
||||
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
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ namespace SHADE
|
|||
if (_pipeline == pipeline)
|
||||
return;
|
||||
|
||||
// Mark old pipeline and set new pipeline
|
||||
oldPipeline = pipeline;
|
||||
pipeline = _pipeline;
|
||||
|
||||
// Set up properties based on the pipeline
|
||||
|
@ -41,9 +43,6 @@ namespace SHADE
|
|||
|
||||
// Reset since pipeline changed
|
||||
ResetProperties();
|
||||
|
||||
// Mark changed so that we know to update dependent material instances
|
||||
propertiesChanged = true;
|
||||
}
|
||||
|
||||
Handle<SHVkPipeline> SHMaterial::GetPipeline() const
|
||||
|
@ -111,4 +110,9 @@ namespace SHADE
|
|||
{
|
||||
propertiesChanged = false;
|
||||
}
|
||||
|
||||
void SHMaterial::ForgetOldPipeline() noexcept
|
||||
{
|
||||
oldPipeline = {};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------*/
|
||||
void SetPipeline(Handle<SHVkPipeline> _pipeline);
|
||||
Handle<SHVkPipeline> GetPipeline() const;
|
||||
Handle<SHVkPipeline> GetPrevPipeline() const { return oldPipeline; };
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Property Functions */
|
||||
|
@ -68,10 +69,11 @@ namespace SHADE
|
|||
/* Query Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
Handle<SHShaderBlockInterface> GetShaderBlockInterface() const noexcept;
|
||||
bool HasPipelineChanged() const noexcept { return pipelineChanged; }
|
||||
bool HasPipelineChanged() const noexcept { return oldPipeline; }
|
||||
bool HasPropertiesChanged() const noexcept { return propertiesChanged; }
|
||||
bool HasChanged() const noexcept { return pipelineChanged || propertiesChanged; }
|
||||
bool HasChanged() const noexcept { return oldPipeline || propertiesChanged; }
|
||||
void ClearChangeFlag() noexcept;
|
||||
void ForgetOldPipeline() noexcept;
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -81,7 +83,7 @@ namespace SHADE
|
|||
std::unique_ptr<char> propMemory;
|
||||
Byte propMemorySize = 0;
|
||||
bool propertiesChanged = true;
|
||||
bool pipelineChanged = true;
|
||||
Handle<SHVkPipeline> oldPipeline;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
|
|
|
@ -129,7 +129,7 @@ namespace SHADE
|
|||
// Otherwise just copy the data over
|
||||
else
|
||||
{
|
||||
bufferHandle->MapWriteUnmap(src, size, 0, 0);
|
||||
bufferHandle->WriteToMemory(src, size, 0, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue