This commit is contained in:
Rian Drake 2026-10-15 14:09:11 +13:00
commit b578433e37
3 changed files with 784842 additions and 0 deletions

View file

@ -0,0 +1,484 @@
namespace Brutal.ShaderCApi
{
public enum TargetEnv : uint
{
Vulkan, // SPIR-V under Vulkan semantics
Opengl, // SPIR-V under OpenGL semantics
OpenglCompat, // SPIR-V under OpenGL semantics, including compatibility profile functions
[Obsolete("Deprecated, SPIR-V under WebGPU semantics")]
Webgpu, // Deprecated, SPIR-V under WebGPU semantics
Default = Vulkan,
}
public enum EnvVersion : uint
{
/// For Vulkan, use Vulkan's mapping of version numbers to integers.
/// See vulkan.h
Vulkan_1_0 = ((1u << 22)),
/// For Vulkan, use Vulkan's mapping of version numbers to integers.
/// See vulkan.h
Vulkan_1_1 = ((1u << 22) | (1 << 12)),
/// For Vulkan, use Vulkan's mapping of version numbers to integers.
/// See vulkan.h
Vulkan_1_2 = ((1u << 22) | (2 << 12)),
/// For Vulkan, use Vulkan's mapping of version numbers to integers.
/// See vulkan.h
Vulkan_1_3 = ((1u << 22) | (3 << 12)),
/// For Vulkan, use Vulkan's mapping of version numbers to integers.
/// See vulkan.h
Vulkan_1_4 = ((1u << 22) | (4 << 12)),
/// For OpenGL, use the number from #version in shaders.
/// TODO(dneto): Currently no difference between OpenGL 4.5 and 4.6.
/// See glslang/Standalone/Standalone.cpp
/// TODO(dneto): Glslang doesn't accept a OpenGL client version of 460.
Opengl_4_5 = 450,
[Obsolete("Deprecated, WebGPU env never defined versions")]
Webgpu, // Deprecated, WebGPU env never defined versions
}
/// The known versions of SPIR-V.
public enum SpirvVersion : uint
{
/// Use the values used for word 1 of a SPIR-V binary:
/// - bits 24 to 31: zero
/// - bits 16 to 23: major version number
/// - bits 8 to 15: minor version number
/// - bits 0 to 7: zero
_1_0 = 0x010000u,
/// Use the values used for word 1 of a SPIR-V binary:
/// - bits 24 to 31: zero
/// - bits 16 to 23: major version number
/// - bits 8 to 15: minor version number
/// - bits 0 to 7: zero
_1_1 = 0x010100u,
/// Use the values used for word 1 of a SPIR-V binary:
/// - bits 24 to 31: zero
/// - bits 16 to 23: major version number
/// - bits 8 to 15: minor version number
/// - bits 0 to 7: zero
_1_2 = 0x010200u,
/// Use the values used for word 1 of a SPIR-V binary:
/// - bits 24 to 31: zero
/// - bits 16 to 23: major version number
/// - bits 8 to 15: minor version number
/// - bits 0 to 7: zero
_1_3 = 0x010300u,
/// Use the values used for word 1 of a SPIR-V binary:
/// - bits 24 to 31: zero
/// - bits 16 to 23: major version number
/// - bits 8 to 15: minor version number
/// - bits 0 to 7: zero
_1_4 = 0x010400u,
/// Use the values used for word 1 of a SPIR-V binary:
/// - bits 24 to 31: zero
/// - bits 16 to 23: major version number
/// - bits 8 to 15: minor version number
/// - bits 0 to 7: zero
_1_5 = 0x010500u,
/// Use the values used for word 1 of a SPIR-V binary:
/// - bits 24 to 31: zero
/// - bits 16 to 23: major version number
/// - bits 8 to 15: minor version number
/// - bits 0 to 7: zero
_1_6 = 0x010600u,
}
/// Indicate the status of a compilation.
public enum CompilationStatus : uint
{
Success = 0,
InvalidStage = 1, // error stage deduction
CompilationError = 2,
InternalError = 3, // unexpected failure
NullResultObject = 4,
InvalidAssembly = 5,
ValidationError = 6,
TransformationError = 7,
ConfigurationError = 8,
}
/// Source language kind.
public enum SourceLanguage : uint
{
Glsl,
Hlsl,
}
public enum ShaderKind : uint
{
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
VertexShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
FragmentShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
ComputeShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
GeometryShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
TessControlShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
TessEvaluationShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
GlslVertexShader = VertexShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
GlslFragmentShader = FragmentShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
GlslComputeShader = ComputeShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
GlslGeometryShader = GeometryShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
GlslTessControlShader = TessControlShader,
/// Forced shader kinds. These shader kinds force the compiler to compile the
/// source code as the specified kind of shader.
GlslTessEvaluationShader = TessEvaluationShader,
/// Deduce the shader kind from #pragma annotation in the source code. Compiler
/// will emit error if #pragma annotation is not found.
GlslInferFromSource,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultVertexShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultFragmentShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultComputeShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultGeometryShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultTessControlShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultTessEvaluationShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
SpirvAssembly,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
RayGenShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
AnyHitShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
ClosestHitShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
MissShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
IntersectionShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
CallableShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslRayGenShader = RayGenShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslAnyHitShader = AnyHitShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslClosestHitShader = ClosestHitShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslMissShader = MissShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslIntersectionShader = IntersectionShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslCallableShader = CallableShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultRayGenShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultAnyHitShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultClosestHitShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultMissShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultIntersectionShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultCallableShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
TaskShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
MeshShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslTaskShader = TaskShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslMeshShader = MeshShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultTaskShader,
/// Default shader kinds. Compiler will fall back to compile the source code as
/// the specified kind of shader when #pragma annotation is not found in the
/// source code.
GlslDefaultMeshShader,
}
public enum Profile : uint
{
None, // Used if and only if GLSL version did not specify profiles.
Core,
Compatibility, // Disabled. This generates an error
Es,
}
/// Optimization level.
public enum OptimizationLevel : uint
{
Zero, // no optimization
Size, // optimize towards reducing code size
Performance, // optimize towards performance
}
/// Resource limits.
public enum Limit : uint
{
MaxLights,
MaxClipPlanes,
MaxTextureUnits,
MaxTextureCoords,
MaxVertexAttribs,
MaxVertexUniformComponents,
MaxVaryingFloats,
MaxVertexTextureImageUnits,
MaxCombinedTextureImageUnits,
MaxTextureImageUnits,
MaxFragmentUniformComponents,
MaxDrawBuffers,
MaxVertexUniformVectors,
MaxVaryingVectors,
MaxFragmentUniformVectors,
MaxVertexOutputVectors,
MaxFragmentInputVectors,
MinProgramTexelOffset,
MaxProgramTexelOffset,
MaxClipDistances,
MaxComputeWorkGroupCountX,
MaxComputeWorkGroupCountY,
MaxComputeWorkGroupCountZ,
MaxComputeWorkGroupSizeX,
MaxComputeWorkGroupSizeY,
MaxComputeWorkGroupSizeZ,
MaxComputeUniformComponents,
MaxComputeTextureImageUnits,
MaxComputeImageUniforms,
MaxComputeAtomicCounters,
MaxComputeAtomicCounterBuffers,
MaxVaryingComponents,
MaxVertexOutputComponents,
MaxGeometryInputComponents,
MaxGeometryOutputComponents,
MaxFragmentInputComponents,
MaxImageUnits,
MaxCombinedImageUnitsAndFragmentOutputs,
MaxCombinedShaderOutputResources,
MaxImageSamples,
MaxVertexImageUniforms,
MaxTessControlImageUniforms,
MaxTessEvaluationImageUniforms,
MaxGeometryImageUniforms,
MaxFragmentImageUniforms,
MaxCombinedImageUniforms,
MaxGeometryTextureImageUnits,
MaxGeometryOutputVertices,
MaxGeometryTotalOutputComponents,
MaxGeometryUniformComponents,
MaxGeometryVaryingComponents,
MaxTessControlInputComponents,
MaxTessControlOutputComponents,
MaxTessControlTextureImageUnits,
MaxTessControlUniformComponents,
MaxTessControlTotalOutputComponents,
MaxTessEvaluationInputComponents,
MaxTessEvaluationOutputComponents,
MaxTessEvaluationTextureImageUnits,
MaxTessEvaluationUniformComponents,
MaxTessPatchComponents,
MaxPatchVertices,
MaxTessGenLevel,
MaxViewports,
MaxVertexAtomicCounters,
MaxTessControlAtomicCounters,
MaxTessEvaluationAtomicCounters,
MaxGeometryAtomicCounters,
MaxFragmentAtomicCounters,
MaxCombinedAtomicCounters,
MaxAtomicCounterBindings,
MaxVertexAtomicCounterBuffers,
MaxTessControlAtomicCounterBuffers,
MaxTessEvaluationAtomicCounterBuffers,
MaxGeometryAtomicCounterBuffers,
MaxFragmentAtomicCounterBuffers,
MaxCombinedAtomicCounterBuffers,
MaxAtomicCounterBufferSize,
MaxTransformFeedbackBuffers,
MaxTransformFeedbackInterleavedComponents,
MaxCullDistances,
MaxCombinedClipAndCullDistances,
MaxSamples,
MaxMeshOutputVerticesNv,
MaxMeshOutputPrimitivesNv,
MaxMeshWorkGroupSizeXNv,
MaxMeshWorkGroupSizeYNv,
MaxMeshWorkGroupSizeZNv,
MaxTaskWorkGroupSizeXNv,
MaxTaskWorkGroupSizeYNv,
MaxTaskWorkGroupSizeZNv,
MaxMeshViewCountNv,
MaxMeshOutputVerticesExt,
MaxMeshOutputPrimitivesExt,
MaxMeshWorkGroupSizeXExt,
MaxMeshWorkGroupSizeYExt,
MaxMeshWorkGroupSizeZExt,
MaxTaskWorkGroupSizeXExt,
MaxTaskWorkGroupSizeYExt,
MaxTaskWorkGroupSizeZExt,
MaxMeshViewCountExt,
MaxDualSourceDrawBuffersExt,
}
/// Uniform resource kinds.
/// In Vulkan, uniform resources are bound to the pipeline via descriptors
/// with numbered bindings and sets.
public enum UniformKind : uint
{
/// Image and image buffer.
Image,
/// Pure sampler.
Sampler,
/// Sampled texture in GLSL, and Shader Resource View in HLSL.
Texture,
/// Uniform Buffer Object (UBO) in GLSL. Cbuffer in HLSL.
Buffer,
/// Shader Storage Buffer Object (SSBO) in GLSL.
StorageBuffer,
/// Unordered Access View, in HLSL. (Writable storage image or storage
/// buffer.)
UnorderedAccessView,
}
/// The kinds of include requests.
public enum IncludeType : uint
{
Relative, // E.g. #include "source"
Standard, // E.g. #include <source>
}
}

View file

@ -0,0 +1,265 @@
using System.Runtime.InteropServices;
namespace Brutal.ShaderCApi
{
public static partial class ShaderC
{
public static unsafe partial class PInvoke
{
[LibraryImport("shaderc")]
public static partial Compiler shaderc_compiler_initialize();
[LibraryImport("shaderc")]
public static partial void shaderc_compiler_release(Compiler arg);
[LibraryImport("shaderc")]
public static partial CompileOptions shaderc_compile_options_initialize();
[LibraryImport("shaderc")]
public static partial CompileOptions shaderc_compile_options_clone(CompileOptions options);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_release(CompileOptions options);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_add_macro_definition(
CompileOptions options,
byte* name,
ByteSize64 nameLength,
byte* value,
ByteSize64 valueLength
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_source_language(
CompileOptions options,
SourceLanguage lang
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_generate_debug_info(CompileOptions options);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_emit_nonsemantic_shader_debug_info(
CompileOptions options
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_optimization_level(
CompileOptions options,
OptimizationLevel level
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_forced_version_profile(
CompileOptions options,
int version,
Profile profile
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_include_callbacks(
CompileOptions options,
IncludeResolveFn resolver,
IncludeResultReleaseFn resultReleaser,
void* userData
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_suppress_warnings(CompileOptions options);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_target_env(
CompileOptions options,
TargetEnv target,
uint version
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_target_spirv(
CompileOptions options,
SpirvVersion version
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_warnings_as_errors(CompileOptions options);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_limit(
CompileOptions options,
Limit limit,
int value
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_auto_bind_uniforms(
CompileOptions options,
Bool8 autoBind
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_auto_combined_image_sampler(
CompileOptions options,
Bool8 upgrade
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_hlsl_io_mapping(
CompileOptions options,
Bool8 hlslIomap
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_hlsl_offsets(
CompileOptions options,
Bool8 hlslOffsets
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_binding_base(
CompileOptions options,
UniformKind kind,
uint @base
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_binding_base_for_stage(
CompileOptions options,
ShaderKind shaderKind,
UniformKind kind,
uint @base
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_preserve_bindings(
CompileOptions options,
Bool8 preserveBindings
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_max_id_bound(
CompileOptions options,
uint maxIdBound
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_auto_map_locations(
CompileOptions options,
Bool8 autoMap
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage(
CompileOptions options,
ShaderKind shaderKind,
byte* reg,
byte* set,
byte* binding
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_hlsl_register_set_and_binding(
CompileOptions options,
byte* reg,
byte* set,
byte* binding
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_hlsl_functionality1(
CompileOptions options,
Bool8 enable
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_hlsl_16bit_types(
CompileOptions options,
Bool8 enable
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_vulkan_rules_relaxed(
CompileOptions options,
Bool8 enable
);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_invert_y(CompileOptions options, Bool8 enable);
[LibraryImport("shaderc")]
public static partial void shaderc_compile_options_set_nan_clamp(CompileOptions options, Bool8 enable);
[LibraryImport("shaderc")]
public static partial CompilationResult shaderc_compile_into_spv(
Compiler compiler,
byte* sourceText,
ByteSize64 sourceTextSize,
ShaderKind shaderKind,
byte* inputFileName,
byte* entryPointName,
CompileOptions additionalOptions
);
[LibraryImport("shaderc")]
public static partial CompilationResult shaderc_compile_into_spv_assembly(
Compiler compiler,
byte* sourceText,
ByteSize64 sourceTextSize,
ShaderKind shaderKind,
byte* inputFileName,
byte* entryPointName,
CompileOptions additionalOptions
);
[LibraryImport("shaderc")]
public static partial CompilationResult shaderc_compile_into_preprocessed_text(
Compiler compiler,
byte* sourceText,
ByteSize64 sourceTextSize,
ShaderKind shaderKind,
byte* inputFileName,
byte* entryPointName,
CompileOptions additionalOptions
);
[LibraryImport("shaderc")]
public static partial CompilationResult shaderc_assemble_into_spv(
Compiler compiler,
byte* sourceAssembly,
ByteSize64 sourceAssemblySize,
CompileOptions additionalOptions
);
[LibraryImport("shaderc")]
public static partial void shaderc_result_release(CompilationResult result);
[LibraryImport("shaderc")]
public static partial ByteSize64 shaderc_result_get_length(CompilationResult result);
[LibraryImport("shaderc")]
public static partial ByteSize64 shaderc_result_get_num_warnings(CompilationResult result);
[LibraryImport("shaderc")]
public static partial ByteSize64 shaderc_result_get_num_errors(CompilationResult result);
[LibraryImport("shaderc")]
public static partial CompilationStatus shaderc_result_get_compilation_status(CompilationResult arg);
[LibraryImport("shaderc")]
public static partial byte* shaderc_result_get_bytes(CompilationResult result);
[LibraryImport(
"shaderc",
StringMarshalling = StringMarshalling.Custom,
StringMarshallingCustomType = typeof(Brutal.Interop.InteropStringMarshaller)
)]
public static partial string shaderc_result_get_error_message(CompilationResult result);
[LibraryImport("shaderc")]
public static partial void shaderc_get_spv_version(uint* version, uint* revision);
[LibraryImport("shaderc")]
public static partial Bool8 shaderc_parse_version_profile(byte* str, int* version, Profile* profile);
}
}
}

View file

@ -0,0 +1,288 @@
using System.Runtime.InteropServices.Marshalling;
using Brutal.Interop;
namespace Brutal.ShaderCApi
{
[InteropHandle]
public readonly unsafe partial struct Compiler : IDisposable
{
public void Dispose() => ShaderC.PInvoke.shaderc_compiler_release(this);
public CompilationResult CompileIntoSpv(
ReadOnlySpan<byte> sourceText,
ShaderKind shaderKind,
RefString8 inputFileName,
RefString8 entryPointName,
CompileOptions additionalOptions
)
{
fixed (byte* sourceTextFixed = sourceText)
{
fixed (byte* inputFileNameFixed = inputFileName)
{
fixed (byte* entryPointNameFixed = entryPointName)
{
return ShaderC.PInvoke.shaderc_compile_into_spv(
this,
sourceTextFixed,
ByteSize.Of(sourceText),
shaderKind,
inputFileNameFixed,
entryPointNameFixed,
additionalOptions
);
}
}
}
}
public CompilationResult CompileIntoSpvAssembly(
ReadOnlySpan<byte> sourceText,
ShaderKind shaderKind,
RefString8 inputFileName,
RefString8 entryPointName,
CompileOptions additionalOptions
)
{
fixed (byte* sourceTextFixed = sourceText)
{
fixed (byte* inputFileNameFixed = inputFileName)
{
fixed (byte* entryPointNameFixed = entryPointName)
{
return ShaderC.PInvoke.shaderc_compile_into_spv_assembly(
this,
sourceTextFixed,
ByteSize.Of(sourceText),
shaderKind,
inputFileNameFixed,
entryPointNameFixed,
additionalOptions
);
}
}
}
}
public CompilationResult CompileIntoPreprocessedText(
ReadOnlySpan<byte> sourceText,
ShaderKind shaderKind,
RefString8 inputFileName,
RefString8 entryPointName,
CompileOptions additionalOptions
)
{
fixed (byte* sourceTextFixed = sourceText)
{
fixed (byte* inputFileNameFixed = inputFileName)
{
fixed (byte* entryPointNameFixed = entryPointName)
{
return ShaderC.PInvoke.shaderc_compile_into_preprocessed_text(
this,
sourceTextFixed,
ByteSize.Of(sourceText),
shaderKind,
inputFileNameFixed,
entryPointNameFixed,
additionalOptions
);
}
}
}
}
public CompilationResult AssembleIntoSpv(ReadOnlySpan<byte> sourceAssembly, CompileOptions additionalOptions)
{
fixed (byte* sourceAssemblyFixed = sourceAssembly)
{
return ShaderC.PInvoke.shaderc_assemble_into_spv(
this,
sourceAssemblyFixed,
ByteSize.Of(sourceAssembly),
additionalOptions
);
}
}
}
[InteropHandle]
public readonly unsafe partial struct CompileOptions : IDisposable
{
public CompileOptions Clone() => ShaderC.PInvoke.shaderc_compile_options_clone(this);
public void Dispose() => ShaderC.PInvoke.shaderc_compile_options_release(this);
public void AddMacroDefinition(ReadOnlySpan<byte> name, ReadOnlySpan<byte> value)
{
fixed (byte* nameFixed = name)
{
fixed (byte* valueFixed = value)
{
ShaderC.PInvoke.shaderc_compile_options_add_macro_definition(
this,
nameFixed,
ByteSize.Of(name),
valueFixed,
ByteSize.Of(value)
);
}
}
}
public void SetSourceLanguage(SourceLanguage lang) =>
ShaderC.PInvoke.shaderc_compile_options_set_source_language(this, lang);
public void SetGenerateDebugInfo() => ShaderC.PInvoke.shaderc_compile_options_set_generate_debug_info(this);
public void SetEmitNonsemanticShaderDebugInfo() =>
ShaderC.PInvoke.shaderc_compile_options_set_emit_nonsemantic_shader_debug_info(this);
public void SetOptimizationLevel(OptimizationLevel level) =>
ShaderC.PInvoke.shaderc_compile_options_set_optimization_level(this, level);
public void SetForcedVersionProfile(int version, Profile profile) =>
ShaderC.PInvoke.shaderc_compile_options_set_forced_version_profile(this, version, profile);
public void SetIncludeCallbacks(
IncludeResolveFn resolver,
IncludeResultReleaseFn resultReleaser,
void* userData
) => ShaderC.PInvoke.shaderc_compile_options_set_include_callbacks(this, resolver, resultReleaser, userData);
public void SetSuppressWarnings() => ShaderC.PInvoke.shaderc_compile_options_set_suppress_warnings(this);
public void SetTargetEnv(TargetEnv target, uint version) =>
ShaderC.PInvoke.shaderc_compile_options_set_target_env(this, target, version);
public void SetTargetSpirv(SpirvVersion version) =>
ShaderC.PInvoke.shaderc_compile_options_set_target_spirv(this, version);
public void SetWarningsAsErrors() => ShaderC.PInvoke.shaderc_compile_options_set_warnings_as_errors(this);
public void SetLimit(Limit limit, int value) =>
ShaderC.PInvoke.shaderc_compile_options_set_limit(this, limit, value);
public void SetAutoBindUniforms(Bool8 autoBind) =>
ShaderC.PInvoke.shaderc_compile_options_set_auto_bind_uniforms(this, autoBind);
public void SetAutoCombinedImageSampler(Bool8 upgrade) =>
ShaderC.PInvoke.shaderc_compile_options_set_auto_combined_image_sampler(this, upgrade);
public void SetHlslIoMapping(Bool8 hlslIomap) =>
ShaderC.PInvoke.shaderc_compile_options_set_hlsl_io_mapping(this, hlslIomap);
public void SetHlslOffsets(Bool8 hlslOffsets) =>
ShaderC.PInvoke.shaderc_compile_options_set_hlsl_offsets(this, hlslOffsets);
public void SetBindingBase(UniformKind kind, uint @base) =>
ShaderC.PInvoke.shaderc_compile_options_set_binding_base(this, kind, @base);
public void SetBindingBaseForStage(ShaderKind shaderKind, UniformKind kind, uint @base) =>
ShaderC.PInvoke.shaderc_compile_options_set_binding_base_for_stage(this, shaderKind, kind, @base);
public void SetPreserveBindings(Bool8 preserveBindings) =>
ShaderC.PInvoke.shaderc_compile_options_set_preserve_bindings(this, preserveBindings);
public void SetMaxIdBound(uint maxIdBound) =>
ShaderC.PInvoke.shaderc_compile_options_set_max_id_bound(this, maxIdBound);
public void SetAutoMapLocations(Bool8 autoMap) =>
ShaderC.PInvoke.shaderc_compile_options_set_auto_map_locations(this, autoMap);
public void SetHlslRegisterSetAndBindingForStage(
ShaderKind shaderKind,
RefString8 reg,
RefString8 set,
RefString8 binding
)
{
fixed (byte* regFixed = reg)
{
fixed (byte* setFixed = set)
{
fixed (byte* bindingFixed = binding)
{
ShaderC.PInvoke.shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage(
this,
shaderKind,
regFixed,
setFixed,
bindingFixed
);
}
}
}
}
public void SetHlslRegisterSetAndBinding(RefString8 reg, RefString8 set, RefString8 binding)
{
fixed (byte* regFixed = reg)
{
fixed (byte* setFixed = set)
{
fixed (byte* bindingFixed = binding)
{
ShaderC.PInvoke.shaderc_compile_options_set_hlsl_register_set_and_binding(
this,
regFixed,
setFixed,
bindingFixed
);
}
}
}
}
public void SetHlslFunctionality1(Bool8 enable) =>
ShaderC.PInvoke.shaderc_compile_options_set_hlsl_functionality1(this, enable);
public void SetHlsl16BitTypes(Bool8 enable) =>
ShaderC.PInvoke.shaderc_compile_options_set_hlsl_16bit_types(this, enable);
public void SetVulkanRulesRelaxed(Bool8 enable) =>
ShaderC.PInvoke.shaderc_compile_options_set_vulkan_rules_relaxed(this, enable);
public void SetInvertY(Bool8 enable) => ShaderC.PInvoke.shaderc_compile_options_set_invert_y(this, enable);
public void SetNanClamp(Bool8 enable) => ShaderC.PInvoke.shaderc_compile_options_set_nan_clamp(this, enable);
}
/// An include result.
public unsafe partial struct IncludeResult
{
/// The name of the source file. The name should be fully resolved
/// in the sense that it should be a unique name in the context of the
/// includer. For example, if the includer maps source names to files in
/// a filesystem, then this name should be the absolute path of the file.
/// For a failed inclusion, this string is empty.
public byte* SourceName;
public ByteSize64 SourceNameLength;
/// The text contents of the source file in the normal case.
/// For a failed inclusion, this contains the error message.
public byte* Content;
public ByteSize64 ContentLength;
/// User data to be passed along with this request.
public void* UserData;
}
[InteropHandle]
public readonly unsafe partial struct CompilationResult : IDisposable
{
public void Dispose() => ShaderC.PInvoke.shaderc_result_release(this);
public ByteSize64 GetLength() => ShaderC.PInvoke.shaderc_result_get_length(this);
public ByteSize64 GetNumWarnings() => ShaderC.PInvoke.shaderc_result_get_num_warnings(this);
public ByteSize64 GetNumErrors() => ShaderC.PInvoke.shaderc_result_get_num_errors(this);
public CompilationStatus GetCompilationStatus() => ShaderC.PInvoke.shaderc_result_get_compilation_status(this);
public byte* GetBytes() => ShaderC.PInvoke.shaderc_result_get_bytes(this);
public string GetErrorMessage() => ShaderC.PInvoke.shaderc_result_get_error_message(this);
}
}