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