feat(shader): refactor and enhance shader compilation

Refactored shader compilation and resource management systems:
- Introduced `DXCShaderCompiler` for HLSL compilation and reflection.
- Added `BuildFinalShaderCode` method for robust shader code generation.
- Replaced raw strings with `ShaderEntryPoint` struct for shader paths.
- Updated `RenderContext` and `RenderGraphContext` for new pipeline methods.
- Added thread-safe resource management methods in `ResourceManager`.
- Introduced `DXCShaderReflectionData` for shader reflection handling.
- Removed redundant code and simplified `ShaderPropertiesRegistry`.

BREAKING CHANGE: Updated shader and resource APIs to use new structures and methods.
This commit is contained in:
2026-04-11 00:45:46 +09:00
parent 4ed5572ce7
commit f9a6e9cbbe
131 changed files with 13135 additions and 1002 deletions

View File

@@ -0,0 +1,36 @@
namespace Ghost.Core.Graphics;
[AttributeUsage(AttributeTargets.Struct)]
public class GenerateShaderPropertyAttribute : Attribute
{
public GenerateShaderPropertyAttribute(string shaderName, string? name = null)
{
}
}
[AttributeUsage(AttributeTargets.Field)]
public class GenerateAsHLSLTypeAttribute : Attribute
{
public GenerateAsHLSLTypeAttribute(string hlslTypeName)
{
}
}
public enum PackingRules
{
Exact,
Aligned,
}
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Enum)]
public class GenerateHLSLAttribute : Attribute
{
private readonly PackingRules _packingRules;
private readonly string? _outputSource;
public GenerateHLSLAttribute(PackingRules packingRules, string? outputSource)
{
_packingRules = packingRules;
_outputSource = outputSource;
}
}

View File

@@ -14,12 +14,12 @@ public enum KeywordSpace
Global,
}
public struct ShaderEntryPoint
public struct ShaderCode
{
public string entry;
public string shader;
public string code;
public string entryPoint;
public readonly bool IsCreated => !string.IsNullOrEmpty(entry) && !string.IsNullOrEmpty(shader);
public readonly bool IsCreated => !string.IsNullOrEmpty(code) && !string.IsNullOrEmpty(entryPoint);
}
public struct KeywordsGroup
@@ -35,35 +35,29 @@ public struct PassDescriptor
public ulong identifier;
public string name;
public string? hlsl;
public ShaderEntryPoint taskShader;
public ShaderEntryPoint meshShader;
public ShaderEntryPoint pixelShader;
public ShaderCode amplificationShaderCode;
public ShaderCode meshShaderCode;
public ShaderCode pixelShaderCode;
public string[] defines;
public string[] includes;
public KeywordsGroup[] keywords;
public PipelineState localPipeline;
}
public class GraphicsShaderDescriptor
{
public string name = string.Empty;
public string propertiesCode = string.Empty;
public uint propertyBufferSize;
public ShaderModel shaderModel;
public PassDescriptor[] passes = Array.Empty<PassDescriptor>();
public required string name = string.Empty;
public required uint propertyBufferSize;
public required ShaderModel shaderModel;
public required PassDescriptor[] passes = Array.Empty<PassDescriptor>();
}
public class ComputeShaderDescriptor
{
public ulong identifier;
public string name = string.Empty;
public string propertiesCode = string.Empty;
public uint propertyBufferSize;
public string? hlsl;
public ShaderModel shaderModel;
public string[] defines = Array.Empty<string>();
public string[] includes = Array.Empty<string>();
public KeywordsGroup[] keywords = Array.Empty<KeywordsGroup>();
public ShaderEntryPoint[] entryPoints = Array.Empty<ShaderEntryPoint>();
public required ulong identifier;
public required string name = string.Empty;
public required uint propertyBufferSize;
public required ShaderModel shaderModel;
public required ShaderCode[] shaderCodes;
public required string[] defines;
public required KeywordsGroup[] keywords;
}

View File

@@ -1,41 +0,0 @@
namespace Ghost.Core.Graphics;
[AttributeUsage(AttributeTargets.Struct)]
public class GenerateShaderPropertyAttribute : Attribute
{
public GenerateShaderPropertyAttribute(string shaderName, string? name = null)
{
}
}
[AttributeUsage(AttributeTargets.Field)]
public class GenerateAsHLSLTypeAttribute : Attribute
{
public GenerateAsHLSLTypeAttribute(string hlslTypeName)
{
}
}
#if DEBUG || GHOST_EDITOR
public struct ShaderPropertyInfo
{
public string shaderName;
public string code;
public uint size;
}
public static class ShaderPropertiesRegistry
{
private static readonly Dictionary<string, ShaderPropertyInfo> s_nameToCode = new Dictionary<string, ShaderPropertyInfo>(StringComparer.Ordinal);
public static void Register(string name, string code, uint size)
{
s_nameToCode[name] = new ShaderPropertyInfo { shaderName = name, code = code, size = size };
}
public static bool TryGetInfo(string name, out ShaderPropertyInfo info)
{
return s_nameToCode.TryGetValue(name, out info);
}
}
#endif

View File

@@ -433,4 +433,41 @@ public static class ResultExtensions
return func(result.Value);
}
}
public static void Match(this Result result, Action onSuccess, Action<string?> onFailure)
{
if (result.IsSuccess)
{
onSuccess();
}
else
{
onFailure(result.Message);
}
}
public static U Match<T, U>(this Result<T> result, Func<T, U> onSuccess, Func<string?, U> onFailure)
{
if (result.IsSuccess)
{
return onSuccess(result.Value);
}
else
{
return onFailure(result.Message);
}
}
public static U Match<T, U, E>(this Result<T, E> result, Func<T, U> onSuccess, Func<E, U> onFailure)
where E : struct, Enum
{
if (result.IsSuccess)
{
return onSuccess(result.Value);
}
else
{
return onFailure(result.Error);
}
}
}