Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade metal_shaderconverter bindings and headers to 2.0 (patch 5) #32

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "saxaboom"
version = "0.2.0-beta.1+irconverter-2.0.4"
version = "0.2.0-beta.1+irconverter-2.0"
authors = ["Traverse Research <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use saxaboom::{ffi, MetalIrConverter};

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load the library
let metal_irconverter = MetalIrConverter::new("libmetalirconverter.dylib").unwrap();
let metal_irconverter =
MetalIrConverter::new(libloading::library_filename("metalirconverter")).unwrap();
// Create an instance of IRCompiler
let mut compiler = metal_irconverter.create_compiler();
// Create an object containing DXIL bytes, replace &[0u8] with your DXIL data
Expand Down
7 changes: 6 additions & 1 deletion bindings_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@ impl ParseCallbacks for RenameCallback {
enum_name = String::from("IRRuntimeTessellatorOutput");
}

// For this specific enum, strip off the `Mode` suffix
// For these two specific enums, strip off the `Mode` suffix which is not repeated in
// their variants. Note that a generic `strip_suffix()` solution won't work because
// enums like `IRTextureAddressMode` _do_ share the `Mode` suffix in their variants.
if enum_name == "IRRayGenerationCompilationMode" {
enum_name = String::from("IRRayGenerationCompilation");
}
if enum_name == "IRIntersectionFunctionCompilationMode" {
enum_name = String::from("IRIntersectionFunctionCompilation");
}

let new_name = original_variant_name
.strip_prefix(&enum_name)
Expand Down
2 changes: 1 addition & 1 deletion bindings_generator/vendor/metal_irconverter/ir_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#define IR_VERSION_MAJOR 2
#define IR_VERSION_MINOR 0
#define IR_VERSION_PATCH 4
#define IR_VERSION_PATCH 5

#define IR_SUPPORTS_VERSION(major, minor, patch) \
((major < IR_VERSION_MAJOR) || \
Expand Down
19 changes: 14 additions & 5 deletions bindings_generator/vendor/metal_irconverter/metal_irconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ typedef enum IRRayGenerationCompilationMode
IRRayGenerationCompilationVisibleFunction
} IRRayGenerationCompilationMode;

typedef enum IRIntersectionFunctionCompilationMode
{
IRIntersectionFunctionCompilationVisibleFunction,
IRIntersectionFunctionCompilationIntersectionFunction,
} IRIntersectionFunctionCompilationMode;

enum IRErrorCode
{
IRErrorCodeNoError,
Expand All @@ -357,6 +363,8 @@ enum IRErrorCode
IRErrorCodeUnrecognizedDXILHeader,
IRErrorCodeInvalidRaytracingAttribute,
IRErrorCodeNullHullShaderInputOutputMismatch,
IRErrorCodeInvalidRaytracingUserAttributeSize,
IRErrorCodeIncorrectHitgroupType,
IRErrorCodeUnknown
};

Expand Down Expand Up @@ -579,15 +587,16 @@ uint64_t IRObjectGatherRaytracingIntrinsics(IRObject* input, const char* entryPo
* @param compiler compiler to configure
* @param maxAttributeSizeInBytes the maximum number of ray tracing attributes (in bytes) that a pipeline consisting of these shaders uses.
* @param raytracingPipelineFlags flags for the ray tracing pipeline your application builds from these shaders.
* @param chs bitwise OR mask of all closest hit shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskClosestHitAll`).
* @param miss bitwise OR mask of all miss shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskMissShaderAll`).
* @param anyHit bitwise OR mask of all any hit shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskAnyHitShaderAll`).
* @param callableArgs bitwise OR mask of all callable shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskCallableShaderAll`).
* @param chs bitwise OR mask of all closest hit shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskClosestHitAll`). The value must match across all functions of all types used in this RT pipeline.
* @param miss bitwise OR mask of all miss shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskMissShaderAll`). The value must match across all functions of all types used in this RT pipeline.
* @param anyHit bitwise OR mask of all any hit shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskAnyHitShaderAll`). The value must match across all functions of all types used in this RT pipeline.
* @param callableArgs bitwise OR mask of all callable shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskCallableShaderAll`). The value must match across all functions of all types used in this RT pipeline.
* @param maxRecursiveDepth stop point for recursion. Pass `IRRayTracingUnlimitedRecursionDepth` for no limit.
* @param rayGenerationCompilationMode set the ray-generation shader compilation mode to compile either as a compute kernel, or as a visible function for a shader binding table.
* @param intersectionFunctionCompilationMode set the any-hit/intersection function compilation mode to compile either as a visible function or Metal Intersection Function. The value must match across all functions of all types used in this RT pipeline.
* @warning providing mask values other than the defaults or those returned by `IRObjectGatherRaytracingIntrinsics` may cause subsequent shader compilations to fail.
*/
void IRCompilerSetRayTracingPipelineArguments(IRCompiler* compiler, uint32_t maxAttributeSizeInBytes, IRRaytracingPipelineFlags raytracingPipelineFlags, uint64_t chs, uint64_t miss, uint64_t anyHit, uint64_t callableArgs, int maxRecursiveDepth, IRRayGenerationCompilationMode rayGenerationCompilationMode);
void IRCompilerSetRayTracingPipelineArguments(IRCompiler* compiler, uint32_t maxAttributeSizeInBytes, IRRaytracingPipelineFlags raytracingPipelineFlags, uint64_t chs, uint64_t miss, uint64_t anyHit, uint64_t callableArgs, int maxRecursiveDepth, IRRayGenerationCompilationMode rayGenerationCompilationMode, IRIntersectionFunctionCompilationMode intersectionFunctionCompilationMode);

/**
* Configure compiler compatibility flags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@

#ifdef __METAL_VERSION__
#define IR_CONSTANT_PTR(ptr) constant ptr*
#define IR_DEVICE_PTR(ptr) device ptr*
#else
#define IR_CONSTANT_PTR(ptr) uint64_t
#define IR_DEVICE_PTR(ptr) uint64_t
#endif // __METAL_VERSION__

typedef struct IRShaderIdentifier
Expand Down Expand Up @@ -96,9 +98,11 @@ typedef struct IRDispatchRaysDescriptor
using RaygenFunctionType = void(constant top_level_global_ab*, constant top_level_local_ab*, constant res_desc_heap_ab*, constant smp_desc_heap_ab*, constant IRDispatchRaysArgument*, uint3);
#define RaygenFunctionPointerTable metal::visible_function_table<RaygenFunctionType>
#define IFT metal::raytracing::intersection_function_table<>
#define MSLAccelerationStructure metal::raytracing::instance_acceleration_structure
#else
#define RaygenFunctionPointerTable resourceid_t
#define IFT resourceid_t
#define MSLAccelerationStructure uint64_t
#endif

typedef struct IRDispatchRaysArgument
Expand All @@ -109,7 +113,7 @@ typedef struct IRDispatchRaysArgument
IR_CONSTANT_PTR(smp_desc_heap_ab) SmpDescHeap;
RaygenFunctionPointerTable VisibleFunctionTable;
IFT IntersectionFunctionTable;
uint32_t Pad[7];
IR_CONSTANT_PTR(IFT) IntersectionFunctionTables;
} IRDispatchRaysArgument;

#ifdef IR_RUNTIME_METALCPP
Expand All @@ -120,8 +124,8 @@ typedef MTLDispatchThreadgroupsIndirectArguments dispatchthreadgroupsindirectarg

typedef struct IRRaytracingAccelerationStructureGPUHeader
{
IR_CONSTANT_PTR(metal::raytracing::instance_acceleration_structure) accelerationStructureID;
IR_CONSTANT_PTR(uint32_t) addressOfInstanceContributions;
MSLAccelerationStructure accelerationStructureID;
IR_DEVICE_PTR(uint32_t) addressOfInstanceContributions;
uint64_t pad0[4];
dispatchthreadgroupsindirectargs_t pad1;
} IRRaytracingAccelerationStructureGPUHeader;
Expand All @@ -142,15 +146,15 @@ typedef struct IRRaytracingInstanceDescriptor

#ifdef __METAL_VERSION__
void IRRaytracingUpdateInstanceContributions(IRRaytracingAccelerationStructureGPUHeader header,
IRRaytracingInstanceDescriptor instanceDescriptor,
device IRRaytracingInstanceDescriptor* instanceDescriptor,
uint32_t index);

#ifdef IR_PRIVATE_IMPLEMENTATION
void IRRaytracingUpdateInstanceContributions(IRRaytracingAccelerationStructureGPUHeader header,
IRRaytracingInstanceDescriptor instanceDescriptor,
device IRRaytracingInstanceDescriptor* instanceDescriptor,
uint32_t index)
{
header.addressOfInstanceContributions[index] = instanceDescriptor.InstanceContributionToHitGroupIndex[index];
header.addressOfInstanceContributions[index] = instanceDescriptor[index].InstanceContributionToHitGroupIndex;
}
#endif // IR_PRIVATE_IMPLEMENTATION
#endif // __METAL_VERSION__
Expand Down
3 changes: 2 additions & 1 deletion examples/compute_shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ fn create_static_sampler(

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load the library
let metal_irconverter = MetalIrConverter::new("libmetalirconverter.dylib").unwrap();
let metal_irconverter =
MetalIrConverter::new(libloading::library_filename("metalirconverter")).unwrap();
// Create an instance of IRCompiler
let mut compiler = metal_irconverter.create_compiler();

Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "saxaboom-runtime"
version = "0.2.0-beta.1+irconverter-2.0.4"
version = "0.2.0-beta.1+irconverter-2.0"
authors = ["Traverse Research <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub struct IRDispatchRaysArgument {
pub SmpDescHeap: u64,
pub VisibleFunctionTable: resourceid_t,
pub IntersectionFunctionTable: resourceid_t,
pub Pad: [u32; 7usize],
pub IntersectionFunctionTables: u64,
}
impl Default for IRDispatchRaysArgument {
fn default() -> Self {
Expand Down
18 changes: 15 additions & 3 deletions src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pub const IR_VERSION_MAJOR: u32 = 2;
pub const IR_VERSION_MINOR: u32 = 0;
pub const IR_VERSION_PATCH: u32 = 4;
pub const IR_VERSION_PATCH: u32 = 5;
pub const IRDescriptorRangeOffsetAppend: u32 = 4294967295;
pub const IRIntrinsicMaskClosestHitAll: u64 = 2147483647;
pub const IRIntrinsicMaskMissShaderAll: u64 = 32767;
Expand Down Expand Up @@ -851,6 +851,13 @@ pub enum IRRayGenerationCompilationMode {
#[repr(u32)]
#[non_exhaustive]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum IRIntersectionFunctionCompilationMode {
VisibleFunction = 0,
IntersectionFunction = 1,
}
#[repr(u32)]
#[non_exhaustive]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum IRErrorCode {
NoError = 0,
ShaderRequiresRootSignature = 1,
Expand All @@ -869,7 +876,9 @@ pub enum IRErrorCode {
UnrecognizedDXILHeader = 14,
InvalidRaytracingAttribute = 15,
NullHullShaderInputOutputMismatch = 16,
Unknown = 17,
InvalidRaytracingUserAttributeSize = 17,
IncorrectHitgroupType = 18,
Unknown = 19,
}
#[repr(u32)]
#[non_exhaustive]
Expand Down Expand Up @@ -1285,6 +1294,7 @@ pub struct metal_irconverter {
callableArgs: u64,
maxRecursiveDepth: ::std::os::raw::c_int,
rayGenerationCompilationMode: IRRayGenerationCompilationMode,
intersectionFunctionCompilationMode: IRIntersectionFunctionCompilationMode,
),
pub IRCompilerSetCompatibilityFlags:
unsafe extern "C" fn(compiler: *mut IRCompiler, flags: IRCompatibilityFlags),
Expand Down Expand Up @@ -1967,7 +1977,7 @@ impl metal_irconverter {
) -> u64 {
(self.IRObjectGatherRaytracingIntrinsics)(input, entryPoint)
}
#[doc = " Configure a compiler with upfront information to generate an optimal interface between ray tracing functions.\n Calling this function is optional, but when omitted, the compiler needs to assume a worst-case scenario, significantly affecting runtime performance.\n Use function `IRObjectGatherRaytracingIntrinsics` to collect the intrinsic usage mask for all closest hit, any hit, intersection, and callable shaders in the pipeline to build.\n After calling this function, all subsequent shaders compiled need to conform to the masks provided, otherwise undefined behavior occurs.\n Specifying a mask and then adding additional shaders to a pipeline that don't conform to it causes undefined behavior.\n @param compiler compiler to configure\n @param maxAttributeSizeInBytes the maximum number of ray tracing attributes (in bytes) that a pipeline consisting of these shaders uses.\n @param raytracingPipelineFlags flags for the ray tracing pipeline your application builds from these shaders.\n @param chs bitwise OR mask of all closest hit shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskClosestHitAll`).\n @param miss bitwise OR mask of all miss shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskMissShaderAll`).\n @param anyHit bitwise OR mask of all any hit shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskAnyHitShaderAll`).\n @param callableArgs bitwise OR mask of all callable shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskCallableShaderAll`).\n @param maxRecursiveDepth stop point for recursion. Pass `IRRayTracingUnlimitedRecursionDepth` for no limit.\n @param rayGenerationCompilationMode set the ray-generation shader compilation mode to compile either as a compute kernel, or as a visible function for a shader binding table.\n @warning providing mask values other than the defaults or those returned by `IRObjectGatherRaytracingIntrinsics` may cause subsequent shader compilations to fail."]
#[doc = " Configure a compiler with upfront information to generate an optimal interface between ray tracing functions.\n Calling this function is optional, but when omitted, the compiler needs to assume a worst-case scenario, significantly affecting runtime performance.\n Use function `IRObjectGatherRaytracingIntrinsics` to collect the intrinsic usage mask for all closest hit, any hit, intersection, and callable shaders in the pipeline to build.\n After calling this function, all subsequent shaders compiled need to conform to the masks provided, otherwise undefined behavior occurs.\n Specifying a mask and then adding additional shaders to a pipeline that don't conform to it causes undefined behavior.\n @param compiler compiler to configure\n @param maxAttributeSizeInBytes the maximum number of ray tracing attributes (in bytes) that a pipeline consisting of these shaders uses.\n @param raytracingPipelineFlags flags for the ray tracing pipeline your application builds from these shaders.\n @param chs bitwise OR mask of all closest hit shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskClosestHitAll`). The value must match across all functions of all types used in this RT pipeline.\n @param miss bitwise OR mask of all miss shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskMissShaderAll`). The value must match across all functions of all types used in this RT pipeline.\n @param anyHit bitwise OR mask of all any hit shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskAnyHitShaderAll`). The value must match across all functions of all types used in this RT pipeline.\n @param callableArgs bitwise OR mask of all callable shaders for a ray tracing pipeline your application builds using subsequent converted shaders (defaults to `IRIntrinsicMaskCallableShaderAll`). The value must match across all functions of all types used in this RT pipeline.\n @param maxRecursiveDepth stop point for recursion. Pass `IRRayTracingUnlimitedRecursionDepth` for no limit.\n @param rayGenerationCompilationMode set the ray-generation shader compilation mode to compile either as a compute kernel, or as a visible function for a shader binding table.\n @param intersectionFunctionCompilationMode set the any-hit/intersection function compilation mode to compile either as a visible function or Metal Intersection Function. The value must match across all functions of all types used in this RT pipeline.\n @warning providing mask values other than the defaults or those returned by `IRObjectGatherRaytracingIntrinsics` may cause subsequent shader compilations to fail."]
pub unsafe fn IRCompilerSetRayTracingPipelineArguments(
&self,
compiler: *mut IRCompiler,
Expand All @@ -1979,6 +1989,7 @@ impl metal_irconverter {
callableArgs: u64,
maxRecursiveDepth: ::std::os::raw::c_int,
rayGenerationCompilationMode: IRRayGenerationCompilationMode,
intersectionFunctionCompilationMode: IRIntersectionFunctionCompilationMode,
) {
(self.IRCompilerSetRayTracingPipelineArguments)(
compiler,
Expand All @@ -1990,6 +2001,7 @@ impl metal_irconverter {
callableArgs,
maxRecursiveDepth,
rayGenerationCompilationMode,
intersectionFunctionCompilationMode,
)
}
#[doc = " Configure compiler compatibility flags.\n Compatibility flags allow you to tailor code generation to the specific requirements of your shaders.\n You typically enable compatibility flags to support a broader set of features and behaviors (such as out-of-bounds reads) when your shader needs them to operate correctly.\n These flags, however, carry a performance cost.\n Always use the minimum set of compatibility flags your shader needs to attain the highest runtime performance for IR code you compile.\n @param compiler the compiler to configure\n @param flags bitmask of compatibility flags to enable."]
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ impl IRCompiler {
callable_args: u64,
max_recursive_depth: i32,
ray_generation_compilation_mode: ffi::IRRayGenerationCompilationMode,
intersection_function_compilation_mode: ffi::IRIntersectionFunctionCompilationMode,
) {
unsafe {
self.funcs.IRCompilerSetRayTracingPipelineArguments(
Expand All @@ -353,6 +354,7 @@ impl IRCompiler {
callable_args,
max_recursive_depth,
ray_generation_compilation_mode,
intersection_function_compilation_mode,
)
}
}
Expand Down
Loading