adding OpImage
Build / build (push) Successful in 1m1s
Test / build (push) Successful in 1m3s

This commit is contained in:
2026-05-24 22:03:29 +02:00
parent a8372ce736
commit 1ffa20d07c
+25 -2
View File
@@ -71,9 +71,10 @@ const BitOp = enum {
const ImageOp = enum { const ImageOp = enum {
Fetch, Fetch,
Read, Read,
Write, Resolve,
SampleImplicitLod,
SampleExplicitLod, SampleExplicitLod,
SampleImplicitLod,
Write,
}; };
pub const OpCodeFunc = *const fn (std.mem.Allocator, SpvWord, *Runtime) RuntimeError!void; pub const OpCodeFunc = *const fn (std.mem.Allocator, SpvWord, *Runtime) RuntimeError!void;
@@ -159,6 +160,7 @@ pub const SetupDispatcher = block: {
.INotEqual = autoSetupConstant, .INotEqual = autoSetupConstant,
.ISub = autoSetupConstant, .ISub = autoSetupConstant,
.ISubBorrow = autoSetupConstant, .ISubBorrow = autoSetupConstant,
.Image = autoSetupConstant,
.ImageFetch = autoSetupConstant, .ImageFetch = autoSetupConstant,
.ImageRead = autoSetupConstant, .ImageRead = autoSetupConstant,
.ImageSampleExplicitLod = autoSetupConstant, .ImageSampleExplicitLod = autoSetupConstant,
@@ -292,6 +294,7 @@ pub fn initRuntimeDispatcher() void {
runtime_dispatcher[@intFromEnum(spv.SpvOp.INotEqual)] = CondEngine(.SInt, .NotEqual).op; runtime_dispatcher[@intFromEnum(spv.SpvOp.INotEqual)] = CondEngine(.SInt, .NotEqual).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.ISub)] = MathEngine(.SInt, .Sub, false).op; runtime_dispatcher[@intFromEnum(spv.SpvOp.ISub)] = MathEngine(.SInt, .Sub, false).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.ISubBorrow)] = opISubBorrow; runtime_dispatcher[@intFromEnum(spv.SpvOp.ISubBorrow)] = opISubBorrow;
runtime_dispatcher[@intFromEnum(spv.SpvOp.Image)] = ImageEngine(.Resolve).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageFetch)] = ImageEngine(.Fetch).op; runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageFetch)] = ImageEngine(.Fetch).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageRead)] = ImageEngine(.Read).op; runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageRead)] = ImageEngine(.Read).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageSampleExplicitLod)] = ImageEngine(.SampleExplicitLod).op; runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageSampleExplicitLod)] = ImageEngine(.SampleExplicitLod).op;
@@ -987,11 +990,13 @@ fn ConversionEngine(comptime from_kind: PrimitiveType, comptime to_kind: Primiti
fn ImageEngine(comptime Op: ImageOp) type { fn ImageEngine(comptime Op: ImageOp) type {
return struct { return struct {
const ImageOperand = struct { const ImageOperand = struct {
type_word: SpvWord,
driver_image: *anyopaque, driver_image: *anyopaque,
dim: spv.SpvDim, dim: spv.SpvDim,
}; };
const SampledImageOperand = struct { const SampledImageOperand = struct {
type_word: SpvWord,
driver_image: *anyopaque, driver_image: *anyopaque,
driver_sampler: *anyopaque, driver_sampler: *anyopaque,
dim: spv.SpvDim, dim: spv.SpvDim,
@@ -1001,6 +1006,7 @@ fn ImageEngine(comptime Op: ImageOp) type {
return switch ((try rt.results[type_word].getConstVariant()).*) { return switch ((try rt.results[type_word].getConstVariant()).*) {
.Type => |t| switch (t) { .Type => |t| switch (t) {
.Image => |i| i.dim, .Image => |i| i.dim,
.SampledImage => |i| return resolveImageDim(rt, i.image_type),
else => return RuntimeError.InvalidSpirV, else => return RuntimeError.InvalidSpirV,
}, },
else => return RuntimeError.InvalidSpirV, else => return RuntimeError.InvalidSpirV,
@@ -1010,6 +1016,7 @@ fn ImageEngine(comptime Op: ImageOp) type {
fn resolveImage(image: *Result, rt: *Runtime) RuntimeError!ImageOperand { fn resolveImage(image: *Result, rt: *Runtime) RuntimeError!ImageOperand {
return switch ((try image.getValue()).*) { return switch ((try image.getValue()).*) {
.Image => |img| .{ .Image => |img| .{
.type_word = img.type_word,
.driver_image = img.driver_image, .driver_image = img.driver_image,
.dim = try resolveImageDim(rt, img.type_word), .dim = try resolveImageDim(rt, img.type_word),
}, },
@@ -1029,6 +1036,7 @@ fn ImageEngine(comptime Op: ImageOp) type {
}; };
break :blk .{ break :blk .{
.type_word = img.type_word,
.driver_image = img.driver_image, .driver_image = img.driver_image,
.driver_sampler = img.driver_sampler, .driver_sampler = img.driver_sampler,
.dim = try resolveImageDim(rt, sampled_image_type.image_type), .dim = try resolveImageDim(rt, sampled_image_type.image_type),
@@ -1346,6 +1354,21 @@ fn ImageEngine(comptime Op: ImageOp) type {
} }
fn op(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void { fn op(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
if (comptime Op == .Resolve) {
_ = try rt.it.next(); // result type
const dst = try rt.results[try rt.it.next()].getValue();
const src = &rt.results[try rt.it.next()];
const image_operand = try resolveSampledImage(src, rt);
dst.Image = .{
.driver_image = image_operand.driver_image,
.type_word = image_operand.type_word,
};
return;
}
if (comptime Op == .Write) { if (comptime Op == .Write) {
const image = &rt.results[try rt.it.next()]; const image = &rt.results[try rt.it.next()];
const coordinate = try rt.results[try rt.it.next()].getValue(); const coordinate = try rt.results[try rt.it.next()].getValue();