GiiGaTeam / GiiGaEngine

0 stars 0 forks source link

PSOManager #81

Open damibran opened 2 weeks ago

damibran commented 2 weeks ago

TODO:

PlantUML @startuml class PSOManager { + void SetCommonDescriptors(ShaderResourceDescriptor); + void SetPerObjectDrawDescriptors(PerObjectData); + PSO* GetPSOfor(MeshID, MaterialID) + PerObjectData* CreatePerObjectDataFor(StaticMeshComponent, isStatic) + ShaderResources* CreateShaderResourcesFor(Material*) + Material* CreateDynamicMaterialInstance(MaterialID) - ShaderResources* CreateDynamicShaderResourcesFor(Material*) } class ShaderResource { - vector desciptors - bool IsDirty + bool IsStatic + vector GetDescs() + void UpdateGPUData() } abstract PerObjectData { - vector desciptors - bool IsDirty + vector GetDescs() + void UpdateGPUData() = 0 } class WorldMatrix { WorldMatrix(StaticMeshComponent* ) } class PerSkeletalMeshData { PerSkeletalMeshData(SkeletalMeshComponent* ) } class WorldMatrixStatic { GPULocalResource buffer + WorldMatrixStatic() + void UpdateGPUData() } class WorldMatrixDynamic { + WorldMatrixDynamic() + void UpdateGPUData() } PerObjectData .. PSOManager ShaderResource .. PSOManager PSO "1" -- "0.." PSOManager : manages PerObjectData <|-- WorldMatrix PerObjectData <|-- PerSkeletalMeshData WorldMatrix <|-- WorldMatrixStatic WorldMatrix <|-- WorldMatrixDynamic note as CreatePerObjectDataForNote CreatePerObjectDataFor(StaticMeshComponent*, isStatic): if isStatic: return WorldMatrixStatic(StaticMeshComponent*) else: return WorldMatrixDynamic(StaticMeshComponent*) end note PSOManager::CreatePerObjectDataFor .. CreatePerObjectDataForNote note as CreateShaderResourcesForNote is called on material load to RRM end note PSOManager::CreateShaderResourcesFor .. CreateShaderResourcesForNote note as CreateDynamicMaterialInstanceNote CreateDynamicMaterialInstance(MaterialID): newResources = CreateDynamicShaderResourcesFor(MaterialID) newMaterial = Material(MaterialID) newMaterial.ShaderResources = newResources return newMaterial end note PSOManager::CreateDynamicMaterialInstance .. CreateDynamicMaterialInstanceNote WorldMatrixStatic .. CreatePerObjectDataForNote WorldMatrixDynamic .. CreatePerObjectDataForNote note as WorldMatrix_WorldMatrix WorldMatrix(StaticMeshComponent*): get reference to WorldMatrix end note WorldMatrix::WorldMatrix .. WorldMatrix_WorldMatrix note as WorldMatrixStatic_WorldMatrixStatic WorldMatrixStatic(): buffer = GPULocalResource(device, resDesc) BufferView bv = buffer.CreateConstantBufferView(desc) desciptors.push_back(bv.getDescriptor()) end note WorldMatrixStatic::WorldMatrixStatic .. WorldMatrixStatic_WorldMatrixStatic note as WorldMatrixStatic_UpdateGPUData UpdateGPUData(): if isDirty: buffer.UpdateContents(render_context, MatrixData, stateAfer) end note WorldMatrixStatic::UpdateGPUData .. WorldMatrixStatic_UpdateGPUData note as WorldMatrixDynamic_WorldMatrixDynamic WorldMatrixDynamic(): descriptors.reserve(1) end note WorldMatrixDynamic::WorldMatrixDynamic .. WorldMatrixDynamic_WorldMatrixDynamic note as WorldMatrixDynamic_UpdateGPUData UpdateGPUData(): BufferView bv = RenderContext::AllocateDynamicConstantView(MatrixData, alignment, ConstBufDesc) desciptors[0] = bv.getDescriptor() end note WorldMatrixDynamic::UpdateGPUData .. WorldMatrixDynamic_UpdateGPUData note as ShaderResourceIsStaticNote is used to place DrawCall to diffrent CommonResourceGroup and use in UpdateGPUData end note ShaderResource::IsStatic .. ShaderResourceIsStaticNote note as ShaderResourceUpdateGPUDataNote ShaderResource::UpdateGPUData() <> if IsStatic: if isDirty: buffer.UpdateContents(render_context, MatrixData, stateAfer) else: BufferView bv = RenderContext::AllocateDynamicConstantView(MatrixData, alignment, ConstBufDesc) desciptors[0] = bv.getDescriptor() end note ShaderResourceUpdateGPUDataNote .. ShaderResource::UpdateGPUData @enduml

image

damibran commented 1 week ago

^^^ need review. Вы же этого ожидали? @TheKarasik @if0ne @Crechted @ainurdada

damibran commented 1 week ago

Может PerObjectData isDirty сделать через Event и подписку?

Пока что я не очень понимаю, как это будет доходить до сюда

if0ne commented 1 week ago

Может PerObjectData isDirty сделать через Event и подписку?

А что будет в ивенте?

damibran commented 1 week ago

Ну главная проблема в чем: в случае PerObjectData изменяется TransformComponent, а уведомить об изменении нужно какой-то IRenderable.

Я думаю, в TransfromComponent нужно добавить Dispatcher/Notifier, который будет триггериться во всех сеттерах TransfromComponent, если он впервые становится грязным. А подписаться\присоединиться к этому может любой.