Refactor and optimize rendering pipeline
- Added `<IsTrimmable>` property in project files for trimming. - Replaced bindless texture types with non-bindless equivalents. - Refactored `ShaderDescriptor` and `ShaderPass` for better modularity. - Introduced `ShaderDescriptorExtensions` for property size calculations. - Simplified constant buffer handling in `Material.cs`. - Improved resource management in `D3D12` components. - Added support for static meshes and optimized resource barriers. - Refactored shader code generation and property merging in `SDLCompiler`. - Removed unused or redundant code (e.g., `IncludesBlock` parser). - Updated comments, documentation, and error handling for clarity.
This commit is contained in:
@@ -10,17 +10,18 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<IsAotCompatible>True</IsAotCompatible>
|
||||
<DefineConstants>$(DefineConstants);PLATEFORME_WIN64</DefineConstants>
|
||||
<IsTrimmable>True</IsTrimmable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<IsAotCompatible>True</IsAotCompatible>
|
||||
<DefineConstants>$(DefineConstants);PLATEFORME_WIN64</DefineConstants>
|
||||
<IsTrimmable>True</IsTrimmable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Misaki.HighPerformance" Version="1.0.1" />
|
||||
<PackageReference Include="Misaki.HighPerformance.Jobs" Version="1.1.0" />
|
||||
<PackageReference Include="Misaki.HighPerformance.LowLevel" Version="1.2.1" />
|
||||
<PackageReference Include="Misaki.HighPerformance.LowLevel" Version="1.2.5" />
|
||||
<PackageReference Include="Misaki.HighPerformance.Mathematics" Version="1.2.6" />
|
||||
<PackageReference Include="System.IO.Hashing" Version="10.0.0" />
|
||||
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.26100.5" />
|
||||
|
||||
@@ -10,11 +10,12 @@ public enum ShaderPropertyType
|
||||
{
|
||||
None,
|
||||
Float, Float2, Float3, Float4,
|
||||
Float4x4,
|
||||
Int, Int2, Int3, Int4,
|
||||
UInt, UInt2, UInt3, UInt4,
|
||||
Bool, Bool2, Bool3, Bool4,
|
||||
Texture2DBindless, Texture3DBindless, TextureCubeBindless,
|
||||
Texture2DArrayBindless, TextureCubeArrayBindless,
|
||||
Texture2D, Texture3D, TextureCube,
|
||||
Texture2DArray, TextureCubeArray,
|
||||
}
|
||||
|
||||
public struct ShaderEntryPoint
|
||||
@@ -77,11 +78,8 @@ public class FullPassDescriptor : IPassDescriptor
|
||||
public ShaderEntryPoint taskShader;
|
||||
public ShaderEntryPoint meshShader;
|
||||
public ShaderEntryPoint pixelShader;
|
||||
public string? generatedCodePath;
|
||||
public List<string>? defines;
|
||||
public List<string>? includes;
|
||||
public List<KeywordsGroup>? keywords;
|
||||
public List<PropertyDescriptor>? properties;
|
||||
public PipelineDescriptor localPipeline;
|
||||
|
||||
public string Identifier => uniqueIdentifier;
|
||||
@@ -100,6 +98,42 @@ public class FallbackPassDescriptor : IPassDescriptor
|
||||
public class ShaderDescriptor
|
||||
{
|
||||
public string name = string.Empty;
|
||||
public string? generatedCodePath;
|
||||
public uint cbufferSize;
|
||||
public List<PropertyDescriptor> globalProperties = new();
|
||||
public List<PropertyDescriptor> properties = new();
|
||||
public List<IPassDescriptor> passes = new();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ShaderDescriptorExtensions
|
||||
{
|
||||
public static uint GetSize(this ShaderPropertyType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
ShaderPropertyType.Float => 4,
|
||||
ShaderPropertyType.Float2 => 8,
|
||||
ShaderPropertyType.Float3 => 12,
|
||||
ShaderPropertyType.Float4 => 16,
|
||||
ShaderPropertyType.Float4x4 => 64,
|
||||
ShaderPropertyType.Int => 4,
|
||||
ShaderPropertyType.Int2 => 8,
|
||||
ShaderPropertyType.Int3 => 12,
|
||||
ShaderPropertyType.Int4 => 16,
|
||||
ShaderPropertyType.UInt => 4,
|
||||
ShaderPropertyType.UInt2 => 8,
|
||||
ShaderPropertyType.UInt3 => 12,
|
||||
ShaderPropertyType.UInt4 => 16,
|
||||
ShaderPropertyType.Bool => 4,
|
||||
ShaderPropertyType.Bool2 => 8,
|
||||
ShaderPropertyType.Bool3 => 12,
|
||||
ShaderPropertyType.Bool4 => 16,
|
||||
ShaderPropertyType.Texture2D => 4, // Bindless resource use uint32
|
||||
ShaderPropertyType.Texture3D => 4,
|
||||
ShaderPropertyType.TextureCube => 4,
|
||||
ShaderPropertyType.Texture2DArray => 4,
|
||||
ShaderPropertyType.TextureCubeArray => 4,
|
||||
_ => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Ghost.Core;
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace Ghost.Core;
|
||||
|
||||
@@ -44,6 +43,11 @@ public readonly struct Result
|
||||
return new Result<T, S>(value, status);
|
||||
}
|
||||
|
||||
public static RefResult<T, S> CreateRef<T, S>(ref T value, S status)
|
||||
{
|
||||
return new RefResult<T, S>(ref value, status);
|
||||
}
|
||||
|
||||
public override string ToString() => IsSuccess ? "OK" : $"Error: {Message}";
|
||||
|
||||
public static implicit operator bool(Result result) => result.IsSuccess;
|
||||
@@ -68,16 +72,6 @@ public readonly struct Result<T>
|
||||
_message = message;
|
||||
}
|
||||
|
||||
public ref readonly T GetValueRef()
|
||||
{
|
||||
if (!IsSuccess)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot get value from a failed Result.");
|
||||
}
|
||||
|
||||
return ref Unsafe.AsRef(in _value);
|
||||
}
|
||||
|
||||
public static Result<T> Success(T value)
|
||||
{
|
||||
return new Result<T>(true, value);
|
||||
@@ -92,9 +86,7 @@ public readonly struct Result<T>
|
||||
|
||||
public static implicit operator Result<T>(T? data) => data is not null ? Success(data) : Failure(null);
|
||||
public static implicit operator Result<T>(Result result) => result.IsSuccess ? Success(default!) : Failure(result.Message);
|
||||
|
||||
public static implicit operator bool(Result<T> result) => result.IsSuccess;
|
||||
public static implicit operator Result(Result<T> result) => result.IsSuccess ? Result.Success() : Result.Failure(result.Message);
|
||||
}
|
||||
|
||||
public enum ResultStatus : byte
|
||||
@@ -126,11 +118,6 @@ public readonly struct Result<T, S>
|
||||
_status = status;
|
||||
}
|
||||
|
||||
public ref readonly T GetValueRef()
|
||||
{
|
||||
return ref Unsafe.AsRef(in _value);
|
||||
}
|
||||
|
||||
public static Result<T, S> Create(T value, S status)
|
||||
{
|
||||
return new Result<T, S>(value, status);
|
||||
@@ -139,6 +126,28 @@ public readonly struct Result<T, S>
|
||||
public override string ToString() => $"Value: {_value}, Status: {_status}";
|
||||
}
|
||||
|
||||
public readonly ref struct RefResult<T, S>
|
||||
{
|
||||
private readonly ref T _value;
|
||||
private readonly S _status;
|
||||
|
||||
public ref T Value => ref _value;
|
||||
public S Status => _status;
|
||||
|
||||
public RefResult(ref T value, S status)
|
||||
{
|
||||
_value = ref value;
|
||||
_status = status;
|
||||
}
|
||||
|
||||
public static RefResult<T, S> Create(ref T value, S status)
|
||||
{
|
||||
return new RefResult<T, S>(ref value, status);
|
||||
}
|
||||
|
||||
public override string ToString() => $"Value: {_value}, Status: {_status}";
|
||||
}
|
||||
|
||||
public static class ResultExtensions
|
||||
{
|
||||
public static void ThrowIfFailed(this Result result)
|
||||
|
||||
@@ -32,14 +32,14 @@ internal static unsafe partial class Win32Utility
|
||||
public static Guid* IID_NULL
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in TerraFX.Interop.Windows.IID.IID_NULL));
|
||||
get => (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in IID.IID_NULL));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static IID_PPV IID_PPV_ARGS<T>(ComPtr<T> comPtr)
|
||||
public static IID_PPV IID_PPV_ARGS<T>(ComPtr<T>* comPtr)
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
return new IID_PPV(Windows.__uuidof<T>(), comPtr.PPV());
|
||||
return new IID_PPV(Windows.__uuidof<T>(), (void**)comPtr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -80,27 +80,6 @@ internal static unsafe partial class Win32Utility
|
||||
return Result.Failure($"{op} failed with code {hr}");
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Guid* IID<T>(this ComPtr<T> comPtr)
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
return Windows.__uuidof<T>();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Guid* IID<T>(this T ptr)
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
return Windows.__uuidof<T>();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void** PPV<T>(ref this ComPtr<T> comPtr)
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
return (void**)comPtr.GetAddressOf();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void** ReleaseAndGetVoidAddressOf<T>(ref this ComPtr<T> comPtr)
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
|
||||
Reference in New Issue
Block a user