forked from Misaki/GhostEngine
Refactor shader system: arrays, keywords, property syntax
Major refactor of shader compiler and related systems:
- Switch ShaderDescriptor/PassDescriptor to arrays; remove IPassDescriptor
- Rewrite keywords block parser/semantic analysis for flexible syntax
- Change property initializers to brace syntax `{ ... }`
- Simplify TokenStream API (remove ref index params)
- Make GetBindlessIndex return uint (~0u for not found)
- Update shader compilation and variant logic for new descriptors
- Update test shader syntax to match new property/keyword formats
- Add AGENTS.md agent development guide
- Add Antlr4 dependency to Ghost.DSL
- Miscellaneous code style and error handling improvements
This commit is contained in:
@@ -367,26 +367,23 @@ internal sealed unsafe partial class DxcShaderCompiler : IShaderCompiler
|
||||
|
||||
// TODO: This should be shader variant specific compile instead of pass specific.
|
||||
// TODO: Build final shader code in memory before compiling.
|
||||
public Result<GraphicsCompiledResult> CompilePass(IPassDescriptor descriptor, ref readonly ShaderCompilationConfig additionalConfig, Key64<ShaderVariant> key)
|
||||
public Result<GraphicsCompiledResult> CompilePass(ref readonly PassDescriptor descriptor, ref readonly ShaderCompilationConfig additionalConfig, Key64<ShaderVariant> key)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
if (descriptor is not PassDescriptor fullDescriptor)
|
||||
{
|
||||
return Result.Failure("FullPassDescriptor expected.");
|
||||
}
|
||||
|
||||
var fullDefines = fullDescriptor.defines ?? new List<string>();
|
||||
fullDefines.AddRange(additionalConfig.defines);
|
||||
var defineCountInDescriptor = descriptor.defines?.Length ?? 0;
|
||||
var fullDefines = new string[defineCountInDescriptor + additionalConfig.defines.Length];
|
||||
descriptor.defines?.CopyTo(fullDefines);
|
||||
additionalConfig.defines.CopyTo(fullDefines.AsSpan(defineCountInDescriptor));
|
||||
|
||||
ShaderCompileResult tsResult = default;
|
||||
var tsEntry = fullDescriptor.taskShader;
|
||||
var tsEntry = descriptor.taskShader;
|
||||
if (tsEntry.IsCreated)
|
||||
{
|
||||
var config = new ShaderCompilationConfig
|
||||
{
|
||||
defines = fullDefines.AsSpan(),
|
||||
includes = fullDescriptor.includes.AsSpan(),
|
||||
includes = descriptor.includes.AsSpan(),
|
||||
shaderPath = tsEntry.shader,
|
||||
entryPoint = tsEntry.entry,
|
||||
stage = ShaderStage.TaskShader,
|
||||
@@ -405,13 +402,13 @@ internal sealed unsafe partial class DxcShaderCompiler : IShaderCompiler
|
||||
}
|
||||
|
||||
ShaderCompileResult msResult;
|
||||
var msEntry = fullDescriptor.meshShader;
|
||||
var msEntry = descriptor.meshShader;
|
||||
if (msEntry.IsCreated)
|
||||
{
|
||||
var config = new ShaderCompilationConfig
|
||||
{
|
||||
defines = fullDefines.AsSpan(),
|
||||
includes = fullDescriptor.includes.AsSpan(),
|
||||
includes = descriptor.includes.AsSpan(),
|
||||
shaderPath = msEntry.shader,
|
||||
entryPoint = msEntry.entry,
|
||||
stage = ShaderStage.MeshShader,
|
||||
@@ -434,13 +431,13 @@ internal sealed unsafe partial class DxcShaderCompiler : IShaderCompiler
|
||||
}
|
||||
|
||||
ShaderCompileResult psResult;
|
||||
var psEntry = fullDescriptor.pixelShader;
|
||||
var psEntry = descriptor.pixelShader;
|
||||
if (psEntry.IsCreated)
|
||||
{
|
||||
var config = new ShaderCompilationConfig
|
||||
{
|
||||
defines = fullDefines.AsSpan(),
|
||||
includes = fullDescriptor.includes.AsSpan(),
|
||||
includes = descriptor.includes.AsSpan(),
|
||||
shaderPath = psEntry.shader,
|
||||
entryPoint = psEntry.entry,
|
||||
stage = ShaderStage.PixelShader,
|
||||
|
||||
@@ -116,8 +116,8 @@ public readonly unsafe ref struct RenderingContext
|
||||
localToWorld = localToWorld,
|
||||
worldBoundsMin = meshData.BoundingBox.Min,
|
||||
worldBoundsMax = meshData.BoundingBox.Max,
|
||||
vertexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.VertexBuffer.AsResource()).GetValueOrThrow(),
|
||||
indexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.IndexBuffer.AsResource()).GetValueOrThrow(),
|
||||
vertexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.VertexBuffer.AsResource()),
|
||||
indexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.IndexBuffer.AsResource()),
|
||||
};
|
||||
|
||||
var bufferHandle = meshData.ObjectDataBuffer.AsResource();
|
||||
@@ -214,8 +214,8 @@ public readonly unsafe ref struct RenderingContext
|
||||
|
||||
var data = new PushConstantsData
|
||||
{
|
||||
objectIndex = _engine.ResourceDatabase.GetBindlessIndex(meshRef.ObjectDataBuffer.AsResource()).GetValueOrThrow(),
|
||||
materialIndex = _engine.ResourceDatabase.GetBindlessIndex(materialRef._cBufferCache.GpuResource.AsResource()).GetValueOrThrow(),
|
||||
objectIndex = _engine.ResourceDatabase.GetBindlessIndex(meshRef.ObjectDataBuffer.AsResource()),
|
||||
materialIndex = _engine.ResourceDatabase.GetBindlessIndex(materialRef._cBufferCache.GpuResource.AsResource()),
|
||||
};
|
||||
|
||||
var pushConstantSpan = new ReadOnlySpan<uint>(&data, sizeof(PushConstantsData) / sizeof(uint));
|
||||
|
||||
@@ -102,30 +102,23 @@ public partial struct Shader : IResourceReleasable
|
||||
internal Shader(ShaderDescriptor descriptor)
|
||||
{
|
||||
_cbufferSize = descriptor.cbufferSize;
|
||||
_shaderPasses = new UnsafeArray<ShaderPass>(descriptor.passes.Count, Allocator.Persistent);
|
||||
_passIDToLocal = new UnsafeHashMap<int, int>(descriptor.passes.Count, Allocator.Persistent);
|
||||
_shaderPasses = new UnsafeArray<ShaderPass>(descriptor.passes.Length, Allocator.Persistent);
|
||||
_passIDToLocal = new UnsafeHashMap<int, int>(descriptor.passes.Length, Allocator.Persistent);
|
||||
_keywordIDToLocal = new UnsafeHashMap<int, int>(32, Allocator.Persistent);
|
||||
|
||||
for (var i = 0; i < descriptor.passes.Count; i++)
|
||||
for (var i = 0; i < descriptor.passes.Length; i++)
|
||||
{
|
||||
var pass = descriptor.passes[i];
|
||||
|
||||
// TODO: Handle inherited passes
|
||||
if (pass is not PassDescriptor fullPass)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var passKey = RHIUtility.CreateShaderPassKey(pass.Identifier);
|
||||
var passKey = RHIUtility.CreateShaderPassKey(pass.identifier);
|
||||
var keywords = default(LocalKeywordSet);
|
||||
|
||||
if (fullPass.keywords != null && fullPass.keywords.Count > 0)
|
||||
if (pass.keywords.Length > 0)
|
||||
{
|
||||
var localKeywordIndex = 0;
|
||||
|
||||
for (var j = 0; j < fullPass.keywords.Count; j++)
|
||||
for (var j = 0; j < pass.keywords.Length; j++)
|
||||
{
|
||||
var group = fullPass.keywords[j];
|
||||
var group = pass.keywords[j];
|
||||
if (group.keywords == null)
|
||||
{
|
||||
continue;
|
||||
@@ -150,11 +143,11 @@ public partial struct Shader : IResourceReleasable
|
||||
_shaderPasses[i] = new ShaderPass
|
||||
{
|
||||
Key = passKey,
|
||||
DeafaultState = fullPass.localPipeline,
|
||||
DeafaultState = pass.localPipeline,
|
||||
KeywordIDs = keywords,
|
||||
};
|
||||
|
||||
_passIDToLocal[GetPassID(pass.Name)] = (ushort)i;
|
||||
_passIDToLocal[GetPassID(pass.name)] = (ushort)i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user