forked from Misaki/GhostEngine
Refactor core systems and improve resource management
- Updated dependencies, including `Misaki.HighPerformance` and `TerraFX.Interop`. - Refactored `Result` struct for better error handling and chaining. - Removed `Ptr<T>` struct as it was no longer necessary. - Enhanced `Win32Utility` with `Attach` and `Dispose` methods. - Improved `ProjectService` and `AppStateMachine` with `Result` integration. - Refactored `IShaderCompiler` to support SPIR-V cross-compilation and pass-level compilation. - Standardized Direct3D12 resource management with `UniquePtr` and added `D3D12Object` base class. - Improved shader reflection validation and pipeline creation in `D3D12PipelineLibrary`. - Updated `SDLCompiler` for better error handling during shader generation. - Enhanced logging, debugging, and code readability across the codebase. - Performed general code cleanup, including unused namespace removal and naming consistency.
This commit is contained in:
@@ -59,7 +59,7 @@ public readonly struct GraphicsPipelineKey
|
||||
{
|
||||
if (!value.TryFormat(destination, out _, "X16"))
|
||||
{
|
||||
return Result.Fail("Failed to format GraphicsPipelineKey to string.");
|
||||
return Result.Failure("Failed to format GraphicsPipelineKey to string.");
|
||||
}
|
||||
|
||||
destination[16] = '\0';
|
||||
@@ -166,7 +166,7 @@ public ref struct GraphicsPSODescriptor
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct CBufferPropertyInfo
|
||||
public readonly record struct CBufferPropertyInfo
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
@@ -184,7 +184,7 @@ public readonly struct CBufferPropertyInfo
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct CBufferInfo
|
||||
public readonly record struct CBufferInfo
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
|
||||
@@ -167,7 +167,7 @@ public interface ICommandBuffer : IDisposable
|
||||
/// <summary>
|
||||
/// Uploads the specified data to the buffer represented by the given handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The unmanaged value type of the elements to upload to the buffer.</typeparam>
|
||||
/// <typeparam name="T">The unmanaged Value type of the elements to upload to the buffer.</typeparam>
|
||||
/// <param name="buffer">A handle to the buffer that will receive the uploaded data.</param>
|
||||
/// <param name="data">A read-only span containing the data to upload to the buffer. The span must contain elements of type
|
||||
/// <typeparamref name="T"/>.</param>
|
||||
|
||||
@@ -26,22 +26,22 @@ public interface ICommandQueue : IDisposable
|
||||
public void Submit(params ReadOnlySpan<ICommandBuffer> commandBuffers);
|
||||
|
||||
/// <summary>
|
||||
/// Signals a fence with the specified value
|
||||
/// Signals a fence with the specified Value
|
||||
/// </summary>
|
||||
/// <param name="value">Value to signal</param>
|
||||
/// <returns>The fence value that was signaled</returns>
|
||||
/// <returns>The fence Value that was signaled</returns>
|
||||
public ulong Signal(ulong value);
|
||||
|
||||
/// <summary>
|
||||
/// Waits for the fence to reach the specified value
|
||||
/// Waits for the fence to reach the specified Value
|
||||
/// </summary>
|
||||
/// <param name="value">Value to wait for</param>
|
||||
public void WaitForValue(ulong value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last completed fence value
|
||||
/// Gets the last completed fence Value
|
||||
/// </summary>
|
||||
/// <returns>Last completed fence value</returns>
|
||||
/// <returns>Last completed fence Value</returns>
|
||||
public ulong GetCompletedValue();
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using Ghost.Graphics.Contracts;
|
||||
|
||||
namespace Ghost.Graphics.RHI;
|
||||
|
||||
public interface IGraphicsEngine : IDisposable
|
||||
@@ -7,6 +9,11 @@ public interface IGraphicsEngine : IDisposable
|
||||
get;
|
||||
}
|
||||
|
||||
IShaderCompiler ShaderCompiler
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
IPipelineLibrary PipelineLibrary
|
||||
{
|
||||
get;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Ghost.Core.Graphics;
|
||||
using Ghost.Core;
|
||||
using Ghost.Graphics.Contracts;
|
||||
|
||||
namespace Ghost.Graphics.RHI;
|
||||
|
||||
@@ -21,5 +22,6 @@ public interface IPipelineLibrary
|
||||
/// <param name="filePath">File path. If null, load default library.</param>
|
||||
void InitializeLibrary(string? filePath);
|
||||
void SaveLibraryToDisk(string filePath);
|
||||
GraphicsPipelineKey CompilePassPSO(IPassDescriptor descriptor, ReadOnlySpan<TextureFormat> rtvs, TextureFormat dsv);
|
||||
Result<GraphicsPipelineKey> CompilePSO(ref readonly GraphicsPSODescriptor descriptor, ref readonly GraphicsCompiledResult compiled);
|
||||
Result<CBufferInfo, ResultStatus> GetCBufferInfo(ShaderPassKey passId);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
namespace Ghost.Graphics.RHI;
|
||||
|
||||
[Flags]
|
||||
public enum FeatureSupport
|
||||
{
|
||||
None = 0,
|
||||
RayTracing = 1 << 0,
|
||||
VariableRateShading = 1 << 1,
|
||||
MeshShaders = 1 << 2,
|
||||
SamplerFeedback = 1 << 3,
|
||||
BindlessResources = 1 << 4,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// D3D12-native render device interface for creating graphics resources
|
||||
/// </summary>
|
||||
@@ -28,4 +39,6 @@ public interface IRenderDevice : IDisposable
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public FeatureSupport GetFeatureSupport();
|
||||
}
|
||||
@@ -48,5 +48,5 @@ public interface IResourceAllocator
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="Identifier{Shader}"/> representing the newly created shader.</returns>
|
||||
/// <param name="descriptor">The viewGroup containing the shader's properties and passes.</param>
|
||||
public Identifier<Shader> CreateShader(ShaderDescriptor descriptor);
|
||||
public Identifier<Shader> CreateGraphicsShader(ShaderDescriptor descriptor);
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@ public interface IResourceDatabase
|
||||
/// Retrieves the current state of the specified resource.
|
||||
/// </summary>
|
||||
/// <param name="handle">The handle that uniquely identifies the resource whose state is to be retrieved.</param>
|
||||
/// <returns>A ResourceState value representing the current state of the resource associated with the specified handle.</returns>
|
||||
/// <returns>A ResourceState Value representing the current state of the resource associated with the specified handle.</returns>
|
||||
ResourceState GetResourceState(Handle<GPUResource> handle);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the state of the specified resource handle to the given value.
|
||||
/// Sets the state of the specified resource handle to the given Value.
|
||||
/// </summary>
|
||||
/// <param name="handle">The handle that identifies the resource whose state will be updated.</param>
|
||||
/// <param name="state">The new state to assign to the resource represented by <paramref name="handle"/>.</param>
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
using Ghost.Core;
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
|
||||
namespace Ghost.Graphics.RHI;
|
||||
|
||||
public struct CompileResult : IDisposable
|
||||
{
|
||||
public UnsafeArray<byte> bytecode;
|
||||
|
||||
public readonly bool IsCreated => bytecode.IsCreated;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
bytecode.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct CompilerConfig
|
||||
{
|
||||
public ReadOnlySpan<string> defines;
|
||||
public string? include;
|
||||
public string shaderPath;
|
||||
public string entryPoint;
|
||||
public ShaderStage stage;
|
||||
public CompilerTier tier;
|
||||
public CompilerOptimizeLevel optimizeLevel;
|
||||
public CompilerOption options;
|
||||
}
|
||||
|
||||
public enum CompilerTier
|
||||
{
|
||||
Tier0,
|
||||
Tier1,
|
||||
Tier2
|
||||
}
|
||||
|
||||
public enum CompilerOptimizeLevel
|
||||
{
|
||||
O0,
|
||||
O1,
|
||||
O2,
|
||||
O3
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum CompilerOption
|
||||
{
|
||||
None = 0,
|
||||
KeepDebugInfo = 1 << 0,
|
||||
KeepReflections = 1 << 1,
|
||||
WarnAsError = 1 << 2
|
||||
}
|
||||
|
||||
public enum ShaderStage
|
||||
{
|
||||
TaskShader,
|
||||
MeshShader,
|
||||
PixelShader,
|
||||
ComputeShader
|
||||
}
|
||||
|
||||
public enum ShaderInputType
|
||||
{
|
||||
ConstantBuffer,
|
||||
Texture,
|
||||
Sampler,
|
||||
UAV,
|
||||
StructuredBuffer,
|
||||
ByteAddressBuffer,
|
||||
RWStructuredBuffer,
|
||||
RWByteAddressBuffer
|
||||
}
|
||||
|
||||
public struct ResourceBindingInfo
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public ShaderInputType Type
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public uint BindPoint
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public uint BindCount
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public uint Space
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public uint Size
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public IReadOnlyList<CBufferPropertyInfo>? Properties
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct ShaderReflectionData
|
||||
{
|
||||
public List<ResourceBindingInfo> ResourcesBindings
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public ShaderReflectionData()
|
||||
{
|
||||
ResourcesBindings = new List<ResourceBindingInfo>();
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe interface IShaderCompiler
|
||||
{
|
||||
Result<CompileResult> Compile(ref readonly CompilerConfig config, Allocator allocator, void** ppReflection);
|
||||
Result<ShaderReflectionData> PerformDXCReflection<T>(T* pReflectionBlob) where T : unmanaged;
|
||||
}
|
||||
Reference in New Issue
Block a user