Added additional config to CompilePass in IShaderCompiler
This commit is contained in:
@@ -62,6 +62,7 @@ public class FullPassDescriptor : IPassDescriptor
|
||||
public ShaderEntryPoint meshShader;
|
||||
public ShaderEntryPoint pixelShader;
|
||||
public List<string>? defines;
|
||||
public List<string>? includes;
|
||||
public List<KeywordsGroup>? keywords;
|
||||
public PipelineState localPipeline;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public struct GraphicsCompiledResult : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct CompilerConfig
|
||||
public ref struct ShaderCompilationConfig
|
||||
{
|
||||
public ReadOnlySpan<string> defines;
|
||||
public string? include;
|
||||
@@ -143,7 +143,7 @@ public readonly struct ShaderReflectionData
|
||||
|
||||
public interface IShaderCompiler : IDisposable
|
||||
{
|
||||
Result<ShaderCompileResult> Compile(ref readonly CompilerConfig config, Allocator allocator);
|
||||
Result<GraphicsCompiledResult> CompilePass(IPassDescriptor descriptor, string? generatedCodePath);
|
||||
Result<ShaderCompileResult> Compile(ref readonly ShaderCompilationConfig config, Allocator allocator);
|
||||
Result<GraphicsCompiledResult> CompilePass(IPassDescriptor descriptor, ref readonly ShaderCompilationConfig additionalConfig, string? generatedCodePath);
|
||||
Result<GraphicsCompiledResult, ErrorStatus> LoadCompiledCache(ShaderPassKey key);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ internal sealed partial class DxcShaderCompiler
|
||||
};
|
||||
}
|
||||
|
||||
private static List<string> GetCompilerArguments(ref readonly CompilerConfig config)
|
||||
private static List<string> GetCompilerArguments(ref readonly ShaderCompilationConfig config)
|
||||
{
|
||||
var argsArray = new List<string>
|
||||
{
|
||||
@@ -242,17 +242,13 @@ internal sealed unsafe partial class DxcShaderCompiler : IShaderCompiler
|
||||
}
|
||||
}
|
||||
|
||||
public Result<ShaderCompileResult> Compile(ref readonly CompilerConfig config, Allocator allocator)
|
||||
public Result<ShaderCompileResult> Compile(ref readonly ShaderCompilationConfig config, Allocator allocator)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
using ComPtr<IDxcIncludeHandler> includeHandler = default;
|
||||
using ComPtr<IDxcBlobEncoding> sourceBlob = default;
|
||||
|
||||
// Create DXC _compiler.Get() and _utils.Get()
|
||||
var dxccID = CLSID.CLSID_DxcCompiler;
|
||||
var dxcuID = CLSID.CLSID_DxcUtils;
|
||||
|
||||
ThrowIfFailed(_utils.Get()->CreateDefaultIncludeHandler(includeHandler.GetAddressOf()));
|
||||
|
||||
// Create source blob
|
||||
@@ -344,7 +340,9 @@ internal sealed unsafe partial class DxcShaderCompiler : IShaderCompiler
|
||||
}
|
||||
}
|
||||
|
||||
public Result<GraphicsCompiledResult> CompilePass(IPassDescriptor descriptor, string? generatedCodePath)
|
||||
// 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, string? generatedCodePath)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
@@ -353,20 +351,23 @@ internal sealed unsafe partial class DxcShaderCompiler : IShaderCompiler
|
||||
return Result.Failure("FullPassDescriptor expected.");
|
||||
}
|
||||
|
||||
var fullDefines = fullDescriptor.defines ?? new List<string>();
|
||||
fullDefines.AddRange(additionalConfig.defines);
|
||||
|
||||
ShaderCompileResult tsResult = default;
|
||||
var tsEntry = fullDescriptor.taskShader;
|
||||
if (tsEntry.IsCreated)
|
||||
{
|
||||
var config = new CompilerConfig
|
||||
var config = new ShaderCompilationConfig
|
||||
{
|
||||
defines = fullDescriptor.defines.AsSpan(),
|
||||
defines = fullDefines.AsSpan(),
|
||||
include = generatedCodePath,
|
||||
shaderPath = tsEntry.shader,
|
||||
entryPoint = tsEntry.entry,
|
||||
stage = ShaderStage.TaskShader,
|
||||
tier = CompilerTier.Tier0,
|
||||
optimizeLevel = CompilerOptimizeLevel.O3,
|
||||
options = CompilerOption.KeepReflections,
|
||||
tier = additionalConfig.tier,
|
||||
optimizeLevel = additionalConfig.optimizeLevel,
|
||||
options = additionalConfig.options,
|
||||
};
|
||||
|
||||
var result = Compile(ref config, Allocator.Persistent);
|
||||
@@ -382,16 +383,16 @@ internal sealed unsafe partial class DxcShaderCompiler : IShaderCompiler
|
||||
var msEntry = fullDescriptor.meshShader;
|
||||
if (msEntry.IsCreated)
|
||||
{
|
||||
var config = new CompilerConfig
|
||||
var config = new ShaderCompilationConfig
|
||||
{
|
||||
defines = fullDescriptor.defines.AsSpan(),
|
||||
defines = fullDefines.AsSpan(),
|
||||
include = generatedCodePath,
|
||||
shaderPath = msEntry.shader,
|
||||
entryPoint = msEntry.entry,
|
||||
stage = ShaderStage.MeshShader,
|
||||
tier = CompilerTier.Tier0,
|
||||
optimizeLevel = CompilerOptimizeLevel.O3,
|
||||
options = CompilerOption.KeepReflections,
|
||||
tier = additionalConfig.tier,
|
||||
optimizeLevel = additionalConfig.optimizeLevel,
|
||||
options = additionalConfig.options,
|
||||
};
|
||||
|
||||
var result = Compile(ref config, Allocator.Persistent);
|
||||
@@ -411,16 +412,16 @@ internal sealed unsafe partial class DxcShaderCompiler : IShaderCompiler
|
||||
var psEntry = fullDescriptor.pixelShader;
|
||||
if (psEntry.IsCreated)
|
||||
{
|
||||
var config = new CompilerConfig
|
||||
var config = new ShaderCompilationConfig
|
||||
{
|
||||
defines = fullDescriptor.defines.AsSpan(),
|
||||
defines = fullDefines.AsSpan(),
|
||||
include = generatedCodePath,
|
||||
shaderPath = psEntry.shader,
|
||||
entryPoint = psEntry.entry,
|
||||
stage = ShaderStage.PixelShader,
|
||||
tier = CompilerTier.Tier0,
|
||||
optimizeLevel = CompilerOptimizeLevel.O3,
|
||||
options = CompilerOption.KeepReflections,
|
||||
tier = additionalConfig.tier,
|
||||
optimizeLevel = additionalConfig.optimizeLevel,
|
||||
options = additionalConfig.options,
|
||||
};
|
||||
|
||||
var result = Compile(ref config, Allocator.Persistent);
|
||||
|
||||
@@ -36,6 +36,7 @@ public partial struct Shader
|
||||
private static int s_nextPropertyID = 0;
|
||||
|
||||
private static readonly Dictionary<string, int> s_keywordNameToID = new Dictionary<string, int>();
|
||||
private static readonly Dictionary<int, string> s_keywordIDToName = new Dictionary<int, string>();
|
||||
private static int s_nextkeywordID = 0;
|
||||
|
||||
public static Identifier<ShaderPass> GetPassID(string passName)
|
||||
@@ -68,9 +69,20 @@ public partial struct Shader
|
||||
id = s_nextkeywordID++;
|
||||
}
|
||||
|
||||
s_keywordIDToName[id] = keywordName;
|
||||
return id;
|
||||
}
|
||||
|
||||
public static string? GetKeywordName(int keywordID)
|
||||
{
|
||||
if (s_keywordIDToName.TryGetValue(keywordID, out var name))
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: Global keywords
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,15 @@ internal class MeshRenderPass : IRenderPass
|
||||
for (var i = 0; i < shaderDescriptor.passes.Count; i++)
|
||||
{
|
||||
var pass = shaderDescriptor.passes[i];
|
||||
var compiled = ctx.ShaderCompiler.CompilePass(pass, shaderDescriptor.generatedCodePath).GetValueOrThrow();
|
||||
|
||||
var config = new ShaderCompilationConfig
|
||||
{
|
||||
optimizeLevel = CompilerOptimizeLevel.O3,
|
||||
options = CompilerOption.KeepReflections,
|
||||
tier = CompilerTier.Tier2
|
||||
};
|
||||
|
||||
var compiled = ctx.ShaderCompiler.CompilePass(pass, in config, shaderDescriptor.generatedCodePath).GetValueOrThrow();
|
||||
//if (pass is not FullPassDescriptor fullPass)
|
||||
//{
|
||||
// continue;
|
||||
|
||||
Reference in New Issue
Block a user