forked from Misaki/GhostEngine
Refactor D3D12 Resource Management
Refactored and renamed components related to D3D12 graphics programming, replacing "descriptor" with "viewGroup" to improve resource grouping and management. Updated `D3D12CommandBuffer`, `D3D12DescriptorAllocator`, and `D3D12PipelineLibrary` to reflect these changes. Simplified material and shader creation in `D3D12ResourceAllocator`. Enhanced `D3D12ResourceDatabase` with resource naming for debugging and improved management. Refactored `Shader` and `ShaderPass` to use modern C# features and `IResourceReleasable` interface. Introduced `D3D12Utility` for centralized utility methods. Updated `Material` class for efficient buffer creation. Renamed `ShaderCompiler` to `SDLCompiler` with improved error handling. Updated `MeshRenderPass` to use new shader compilation process. Various improvements in error handling, code readability, and utility methods.
This commit is contained in:
@@ -18,20 +18,12 @@ internal struct CBufferCache : IResourceReleasable
|
||||
public readonly Handle<GraphicsBuffer> GpuResource => _gpuResource;
|
||||
public readonly uint AlignedSize => _alignedSize;
|
||||
|
||||
public unsafe CBufferCache(IResourceAllocator allocator, uint bufferSize)
|
||||
public unsafe CBufferCache(Handle<GraphicsBuffer> buffer, uint bufferSize)
|
||||
{
|
||||
_alignedSize = (bufferSize + 255u) & ~255u;
|
||||
|
||||
_cpuData = new((int)AlignedSize, Allocator.Persistent);
|
||||
|
||||
var desc = new BufferDesc
|
||||
{
|
||||
Size = bufferSize,
|
||||
Usage = BufferUsage.Constant,
|
||||
MemoryType = ResourceMemoryType.Default,
|
||||
};
|
||||
|
||||
_gpuResource = allocator.CreateBuffer(ref desc);
|
||||
_gpuResource = buffer;
|
||||
}
|
||||
|
||||
public void ReleaseResource(IResourceDatabase database)
|
||||
@@ -52,11 +44,6 @@ public struct Material : IResourceReleasable, IHandleType
|
||||
|
||||
public readonly Identifier<Shader> Shader => _shader;
|
||||
|
||||
public Material(Identifier<Shader> shader, IResourceAllocator allocator, IResourceDatabase database)
|
||||
{
|
||||
SetShader(shader, allocator, database);
|
||||
}
|
||||
|
||||
internal ref CBufferCache GetPassCache(int passIndex)
|
||||
{
|
||||
return ref _materialPropertiesCache[passIndex];
|
||||
@@ -77,7 +64,16 @@ public struct Material : IResourceReleasable, IHandleType
|
||||
{
|
||||
var pass = database.GetShaderPass(shader.GetPassKey(i));
|
||||
var cbufferInfo = pass.PassPropertyInfo;
|
||||
_materialPropertiesCache[i] = new CBufferCache(allocator, cbufferInfo.Size);
|
||||
|
||||
var desc = new BufferDesc
|
||||
{
|
||||
Size = cbufferInfo.Size,
|
||||
Usage = BufferUsage.Constant,
|
||||
MemoryType = ResourceMemoryType.Default,
|
||||
};
|
||||
|
||||
var buffer = allocator.CreateBuffer(ref desc);
|
||||
_materialPropertiesCache[i] = new CBufferCache(buffer, cbufferInfo.Size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +91,7 @@ public struct Material : IResourceReleasable, IHandleType
|
||||
public ref struct MaterialAccessor
|
||||
{
|
||||
private ref Material _materialData;
|
||||
private readonly ref Shader _shader;
|
||||
private Shader _shader;
|
||||
|
||||
private readonly IResourceDatabase _resourceDatabase;
|
||||
|
||||
@@ -104,7 +100,7 @@ public ref struct MaterialAccessor
|
||||
_resourceDatabase = resourceDatabase;
|
||||
|
||||
_materialData = ref resourceDatabase.GetMaterialReference(material);
|
||||
_shader = ref resourceDatabase.GetShaderReference(_materialData.Shader);
|
||||
_shader = resourceDatabase.GetShaderReference(_materialData.Shader);
|
||||
}
|
||||
|
||||
private readonly unsafe void WriteToCache<T>(string propertyName, in T value)
|
||||
|
||||
Reference in New Issue
Block a user