adding lots of unit tests, improving image sampling, adding image sampling deref
Build / build (push) Successful in 1m24s
Test / build (push) Successful in 9m42s

This commit is contained in:
2026-06-12 23:05:16 +02:00
parent 089a33981c
commit c7320325fd
18 changed files with 1714 additions and 147 deletions
+16 -3
View File
@@ -497,12 +497,20 @@ typedef struct
unsigned int w;
} SpvVec4u;
typedef struct
{
int x;
int y;
int z;
} SpvImageOffset;
typedef SpvResult (*SpvReadImageFloat4_PFN)(void* driver_image, SpvDim dim, int x, int y, int z, SpvVec4f* dst);
typedef SpvResult (*SpvReadImageInt4_PFN)(void* driver_image, SpvDim dim, int x, int y, int z, SpvVec4u* dst);
typedef SpvResult (*SpvWriteImageFloat4_PFN)(void* driver_image, SpvDim dim, int x, int y, int z, SpvVec4f src);
typedef SpvResult (*SpvWriteImageInt4_PFN)(void* driver_image, SpvDim dim, int x, int y, int z, SpvVec4u src);
typedef SpvResult (*SpvSampleImageFloat4_PFN)(void* driver_image, void* driver_sampler, SpvDim dim, float x, float y, float z, float lod, SpvVec4f* dst);
typedef SpvResult (*SpvSampleImageInt4_PFN)(void* driver_image, void* driver_sampler, SpvDim dim, float x, float y, float z, float lod, SpvVec4u* dst);
typedef SpvResult (*SpvSampleImageFloat4_PFN)(void* driver_image, void* driver_sampler, SpvDim dim, float x, float y, float z, SpvBool has_lod, float lod, SpvImageOffset offset, SpvVec4f* dst);
typedef SpvResult (*SpvSampleImageInt4_PFN)(void* driver_image, void* driver_sampler, SpvDim dim, float x, float y, float z, SpvBool has_lod, float lod, SpvImageOffset offset, SpvVec4u* dst);
typedef SpvResult (*SpvSampleImageDref_PFN)(void* driver_image, void* driver_sampler, SpvDim dim, float x, float y, float z, float dref, SpvBool has_lod, float lod, SpvImageOffset offset, float* dst);
typedef SpvResult (*SpvQueryImageSize_PFN)(void* driver_image, SpvDim dim, SpvBool arrayed, SpvVec4u* dst);
typedef struct
@@ -513,6 +521,7 @@ typedef struct
SpvWriteImageInt4_PFN SpvWriteImageInt4;
SpvSampleImageFloat4_PFN SpvSampleImageFloat4;
SpvSampleImageInt4_PFN SpvSampleImageInt4;
SpvSampleImageDref_PFN SpvSampleImageDref;
SpvQueryImageSize_PFN SpvQueryImageSize;
} SpvImageAPI;
@@ -523,6 +532,7 @@ SPV_API SpvResult SpvInitModule(SpvModule* module, const SpvWord* source, SpvSiz
SPV_API void SpvDeinitModule(SpvModule module);
SPV_API SpvModuleReflectionInfos SpvModuleGetReflectionInfos(SpvModule module);
SPV_API SpvResult SpvModuleGetBindingResult(SpvModule module, SpvWord set, SpvWord binding, SpvWord* result);
SPV_API SpvResult SpvInitRuntime(SpvRuntime* runtime, SpvModule module, SpvImageAPI image_api);
SPV_API void SpvDeinitRuntime(SpvRuntime runtime);
@@ -530,6 +540,10 @@ SPV_API void SpvDeinitRuntime(SpvRuntime runtime);
SPV_API SpvResult SpvFlushDescriptorSets(SpvRuntime runtime);
SPV_API SpvResult SpvAddSpecializationInfo(SpvRuntime runtime, SpvRuntimeSpecializationEntry entry, const SpvByte* data, SpvSize data_size);
SPV_API SpvResult SpvCopySpecializationConstantsFrom(SpvRuntime runtime, SpvRuntime other);
SPV_API SpvResult SpvSetDerivativeFromMemory(SpvRuntime runtime, SpvWord result, const SpvByte* dx, SpvSize dx_size, const SpvByte* dy, SpvSize dy_size);
SPV_API void SpvClearDerivative(SpvRuntime runtime, SpvWord result);
SPV_API SpvResult SpvCopyDerivative(SpvRuntime runtime, SpvWord dst, SpvWord src);
SPV_API SpvResult SpvPopulatePushConstants(SpvRuntime runtime, const SpvByte* data, SpvSize data_size);
SPV_API SpvResult SpvGetResultByName(SpvRuntime runtime, const char* name, SpvWord* result);
@@ -540,7 +554,6 @@ SPV_API SpvResult SpvGetEntryPointByName(SpvRuntime runtime, const char* name, S
SPV_API SpvResult SpvGetResultMemorySize(SpvRuntime runtime, SpvWord result, SpvSize* size);
SPV_API SpvResult SpvGetInputLocationMemorySize(SpvRuntime runtime, SpvWord location, SpvSize* size);
SPV_API SpvResult SpvGetResultPrimitiveType(SpvRuntime runtime, SpvWord result, SpvPrimitiveType* primitive_type);
SPV_API SpvBool SpvResultIsInteger(SpvRuntime runtime, SpvWord result);
SPV_API SpvBool SpvHasResultDecoration(SpvRuntime runtime, SpvWord result, SpvDecoration decoration);
SPV_API SpvResult SpvCallEntryPoint(SpvRuntime runtime, SpvWord entry_point_index);
+5
View File
@@ -68,3 +68,8 @@ export fn SpvModuleGetReflectionInfos(module: *spv.Module) callconv(.c) Reflecti
.has_control_barriers = if (module.reflection_infos.has_control_barriers) 1 else 0,
};
}
export fn SpvModuleGetBindingResult(module: *const spv.Module, set: ffi.SpvCWord, binding: ffi.SpvCWord, result: *ffi.SpvCWord) callconv(.c) ffi.Result {
result.* = module.getBindingResult(@intCast(set), @intCast(binding)) orelse return .NotFound;
return .Success;
}
+57 -10
View File
@@ -39,12 +39,19 @@ const Vec4u = extern struct {
w: c_uint,
};
const ImageOffset = extern struct {
x: c_int,
y: c_int,
z: c_int,
};
const readImageFloat4_PFN = *const fn (driver_image: ?*anyopaque, dim: spv.spv.SpvDim, x: c_int, y: c_int, z: c_int, dst: *Vec4f) callconv(.c) ffi.Result;
const readImageInt4_PFN = *const fn (driver_image: ?*anyopaque, dim: spv.spv.SpvDim, x: c_int, y: c_int, z: c_int, dst: *Vec4u) callconv(.c) ffi.Result;
const writeImageFloat4_PFN = *const fn (driver_image: ?*anyopaque, dim: spv.spv.SpvDim, x: c_int, y: c_int, z: c_int, src: Vec4f) callconv(.c) ffi.Result;
const writeImageInt4_PFN = *const fn (driver_image: ?*anyopaque, dim: spv.spv.SpvDim, x: c_int, y: c_int, z: c_int, src: Vec4u) callconv(.c) ffi.Result;
const sampleImageFloat4_PFN = *const fn (driver_image: ?*anyopaque, driver_sampler: ?*anyopaque, dim: spv.spv.SpvDim, x: f32, y: f32, z: f32, lod: f32, dst: *Vec4f) callconv(.c) ffi.Result;
const sampleImageInt4_PFN = *const fn (driver_image: ?*anyopaque, driver_sampler: ?*anyopaque, dim: spv.spv.SpvDim, x: f32, y: f32, z: f32, lod: f32, dst: *Vec4u) callconv(.c) ffi.Result;
const sampleImageFloat4_PFN = *const fn (driver_image: ?*anyopaque, driver_sampler: ?*anyopaque, dim: spv.spv.SpvDim, x: f32, y: f32, z: f32, has_lod: ffi.SpvCBool, lod: f32, offset: ImageOffset, dst: *Vec4f) callconv(.c) ffi.Result;
const sampleImageInt4_PFN = *const fn (driver_image: ?*anyopaque, driver_sampler: ?*anyopaque, dim: spv.spv.SpvDim, x: f32, y: f32, z: f32, has_lod: ffi.SpvCBool, lod: f32, offset: ImageOffset, dst: *Vec4u) callconv(.c) ffi.Result;
const sampleImageDref_PFN = *const fn (driver_image: ?*anyopaque, driver_sampler: ?*anyopaque, dim: spv.spv.SpvDim, x: f32, y: f32, z: f32, dref: f32, has_lod: ffi.SpvCBool, lod: f32, offset: ImageOffset, dst: *f32) callconv(.c) ffi.Result;
const queryImageSize_PFN = *const fn (driver_image: ?*anyopaque, dim: spv.spv.SpvDim, arrayed: ffi.SpvCBool, dst: *Vec4u) callconv(.c) ffi.Result;
const ImageAPI = extern struct {
@@ -54,6 +61,7 @@ const ImageAPI = extern struct {
writeImageInt4: writeImageInt4_PFN,
sampleImageFloat4: sampleImageFloat4_PFN,
sampleImageInt4: sampleImageInt4_PFN,
sampleImageDref: sampleImageDref_PFN,
queryImageSize: queryImageSize_PFN,
};
@@ -159,11 +167,19 @@ const ImageAPIBridge = struct {
try fromCResult(result);
}
fn sampleImageFloat4(driver_image: *anyopaque, driver_sampler: *anyopaque, dim: spv.spv.SpvDim, x: f32, y: f32, z: f32, lod: ?f32) spv.Runtime.RuntimeError!spv.Runtime.Vec4(f32) {
fn toCImageOffset(offset: spv.Runtime.ImageOffset) ImageOffset {
return .{
.x = @intCast(offset.x),
.y = @intCast(offset.y),
.z = @intCast(offset.z),
};
}
fn sampleImageFloat4(driver_image: *anyopaque, driver_sampler: *anyopaque, dim: spv.spv.SpvDim, x: f32, y: f32, z: f32, lod: ?f32, offset: spv.Runtime.ImageOffset) spv.Runtime.RuntimeError!spv.Runtime.Vec4(f32) {
const image_api = try getImageAPI();
var dst: Vec4f = undefined;
const result = image_api.sampleImageFloat4(driver_image, driver_sampler, dim, x, y, z, lod orelse 0.0, &dst);
const result = image_api.sampleImageFloat4(driver_image, driver_sampler, dim, x, y, z, if (lod == null) 0 else 1, lod orelse 0.0, toCImageOffset(offset), &dst);
try fromCResult(result);
@@ -175,11 +191,11 @@ const ImageAPIBridge = struct {
};
}
fn sampleImageInt4(driver_image: *anyopaque, driver_sampler: *anyopaque, dim: spv.spv.SpvDim, x: f32, y: f32, z: f32, lod: ?f32) spv.Runtime.RuntimeError!spv.Runtime.Vec4(u32) {
fn sampleImageInt4(driver_image: *anyopaque, driver_sampler: *anyopaque, dim: spv.spv.SpvDim, x: f32, y: f32, z: f32, lod: ?f32, offset: spv.Runtime.ImageOffset) spv.Runtime.RuntimeError!spv.Runtime.Vec4(u32) {
const image_api = try getImageAPI();
var dst: Vec4u = undefined;
const result = image_api.sampleImageInt4(driver_image, driver_sampler, dim, x, y, z, lod orelse 0.0, &dst);
const result = image_api.sampleImageInt4(driver_image, driver_sampler, dim, x, y, z, if (lod == null) 0 else 1, lod orelse 0.0, toCImageOffset(offset), &dst);
try fromCResult(result);
@@ -191,6 +207,17 @@ const ImageAPIBridge = struct {
};
}
fn sampleImageDref(driver_image: *anyopaque, driver_sampler: *anyopaque, dim: spv.spv.SpvDim, x: f32, y: f32, z: f32, dref: f32, lod: ?f32, offset: spv.Runtime.ImageOffset) spv.Runtime.RuntimeError!f32 {
const image_api = try getImageAPI();
var dst: f32 = undefined;
const result = image_api.sampleImageDref(driver_image, driver_sampler, dim, x, y, z, dref, if (lod == null) 0 else 1, lod orelse 0.0, toCImageOffset(offset), &dst);
try fromCResult(result);
return dst;
}
fn queryImageSize(driver_image: *anyopaque, dim: spv.spv.SpvDim, arrayed: bool) spv.Runtime.RuntimeError!spv.Runtime.Vec4(u32) {
const image_api = try getImageAPI();
@@ -229,6 +256,7 @@ export fn SpvInitRuntime(rt: **RuntimeWrapper, module: *spv.Module, image_api: I
.writeImageInt4 = ImageAPIBridge.writeImageInt4,
.sampleImageFloat4 = ImageAPIBridge.sampleImageFloat4,
.sampleImageInt4 = ImageAPIBridge.sampleImageInt4,
.sampleImageDref = ImageAPIBridge.sampleImageDref,
.queryImageSize = ImageAPIBridge.queryImageSize,
},
) catch |err| {
@@ -264,6 +292,29 @@ export fn SpvAddSpecializationInfo(rt: *RuntimeWrapper, entry: CSpecializationEn
return .Success;
}
export fn SpvCopySpecializationConstantsFrom(rt: *RuntimeWrapper, other: *const RuntimeWrapper) callconv(.c) ffi.Result {
const allocator = std.heap.c_allocator;
rt.rt.copySpecializationConstantsFrom(allocator, &other.rt) catch |err| return toCResult(err);
return .Success;
}
export fn SpvSetDerivativeFromMemory(rt: *RuntimeWrapper, result: spv.SpvWord, dx: [*]const u8, dx_size: c_ulong, dy: [*]const u8, dy_size: c_ulong) callconv(.c) ffi.Result {
const allocator = std.heap.c_allocator;
rt.rt.setDerivativeFromMemory(allocator, result, dx[0..dx_size], dy[0..dy_size]) catch |err| return toCResult(err);
return .Success;
}
export fn SpvClearDerivative(rt: *RuntimeWrapper, result: spv.SpvWord) callconv(.c) void {
const allocator = std.heap.c_allocator;
rt.rt.clearDerivative(allocator, result);
}
export fn SpvCopyDerivative(rt: *RuntimeWrapper, dst: spv.SpvWord, src: spv.SpvWord) callconv(.c) ffi.Result {
const allocator = std.heap.c_allocator;
rt.rt.copyDerivative(allocator, dst, src) catch |err| return toCResult(err);
return .Success;
}
export fn SpvPopulatePushConstants(rt: *RuntimeWrapper, data: [*]const u8, data_size: c_ulong) callconv(.c) ffi.Result {
rt.rt.populatePushConstants(data[0..data_size]) catch |err| return toCResult(err);
return .Success;
@@ -319,10 +370,6 @@ export fn SpvGetResultPrimitiveType(rt: *RuntimeWrapper, result: spv.SpvWord, pr
return .Success;
}
export fn SpvResultIsInteger(rt: *RuntimeWrapper, result: spv.SpvWord) callconv(.c) c_int {
return if (rt.rt.resultIsInteger(result)) 1 else 0;
}
export fn SpvHasResultDecoration(rt: *RuntimeWrapper, result: spv.SpvWord, decoration: spv.spv.SpvDecoration) callconv(.c) c_int {
return if (rt.rt.hasResultDecoration(result, decoration)) 1 else 0;
}