improving image api
This commit is contained in:
+4
-4
@@ -55,10 +55,10 @@ pub fn Vec4(comptime T: type) type {
|
||||
}
|
||||
|
||||
pub const ImageAPI = struct {
|
||||
readImageFloat4: *const fn (driver_image: *anyopaque, x: i32, y: i32, z: i32) RuntimeError!Vec4(f32),
|
||||
readImageInt4: *const fn (driver_image: *anyopaque, x: i32, y: i32, z: i32) RuntimeError!Vec4(u32),
|
||||
writeImageFloat4: *const fn (driver_image: *anyopaque, x: i32, y: i32, z: i32, pixel: Vec4(f32)) RuntimeError!void,
|
||||
writeImageInt4: *const fn (driver_image: *anyopaque, x: i32, y: i32, z: i32, pixel: Vec4(u32)) RuntimeError!void,
|
||||
readImageFloat4: *const fn (driver_image: *anyopaque, dim: spv.SpvDim, x: i32, y: i32, z: i32) RuntimeError!Vec4(f32),
|
||||
readImageInt4: *const fn (driver_image: *anyopaque, dim: spv.SpvDim, x: i32, y: i32, z: i32) RuntimeError!Vec4(u32),
|
||||
writeImageFloat4: *const fn (driver_image: *anyopaque, dim: spv.SpvDim, x: i32, y: i32, z: i32, pixel: Vec4(f32)) RuntimeError!void,
|
||||
writeImageInt4: *const fn (driver_image: *anyopaque, dim: spv.SpvDim, x: i32, y: i32, z: i32, pixel: Vec4(u32)) RuntimeError!void,
|
||||
};
|
||||
|
||||
mod: *Module,
|
||||
|
||||
@@ -41,6 +41,8 @@ pub const SpvByte = spv.SpvByte;
|
||||
pub const SpvWord = spv.SpvWord;
|
||||
pub const SpvBool = spv.SpvBool;
|
||||
|
||||
pub const SpvDim = spv.SpvDim;
|
||||
|
||||
pub const Vec4f32 = @Vector(4, f32);
|
||||
pub const Vec3f32 = @Vector(3, f32);
|
||||
pub const Vec2f32 = @Vector(2, f32);
|
||||
|
||||
+24
-12
@@ -2495,8 +2495,14 @@ fn opImageRead(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void
|
||||
const coordinate = try rt.results[try rt.it.next()].getValue();
|
||||
const dst = try rt.results[result_id].getValue();
|
||||
|
||||
const driver_image = switch ((try image.getValue()).*) {
|
||||
.Image => |img| img.driver_image,
|
||||
const driver_image, const image_type = switch ((try image.getValue()).*) {
|
||||
.Image => |img| .{ img.driver_image, switch ((try rt.results[img.type_word].getConstVariant()).*) {
|
||||
.Type => |t| switch (t) {
|
||||
.Image => |i| i,
|
||||
else => return RuntimeError.InvalidSpirV,
|
||||
},
|
||||
else => return RuntimeError.InvalidSpirV,
|
||||
} },
|
||||
else => return RuntimeError.InvalidSpirV,
|
||||
};
|
||||
|
||||
@@ -2586,13 +2592,13 @@ fn opImageRead(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void
|
||||
const z = helpers.readCoordLane(coordinate, 2) catch 0;
|
||||
|
||||
switch (dst.*) {
|
||||
.Vector4f32, .Vector3f32, .Vector2f32 => try helpers.writeFloatTexel(dst, try rt.image_api.readImageFloat4(driver_image, x, y, z)),
|
||||
.Vector4i32, .Vector3i32, .Vector2i32, .Vector4u32, .Vector3u32, .Vector2u32 => try helpers.writeIntTexel(dst, try rt.image_api.readImageInt4(driver_image, x, y, z)),
|
||||
.Vector4f32, .Vector3f32, .Vector2f32 => try helpers.writeFloatTexel(dst, try rt.image_api.readImageFloat4(driver_image, image_type.dim, x, y, z)),
|
||||
.Vector4i32, .Vector3i32, .Vector2i32, .Vector4u32, .Vector3u32, .Vector2u32 => try helpers.writeIntTexel(dst, try rt.image_api.readImageInt4(driver_image, image_type.dim, x, y, z)),
|
||||
.Vector => |lanes| {
|
||||
if (lanes.len == 0) return RuntimeError.InvalidSpirV;
|
||||
switch (lanes[0]) {
|
||||
.Float => try helpers.writeFloatTexel(dst, try rt.image_api.readImageFloat4(driver_image, x, y, z)),
|
||||
.Int => try helpers.writeIntTexel(dst, try rt.image_api.readImageInt4(driver_image, x, y, z)),
|
||||
.Float => try helpers.writeFloatTexel(dst, try rt.image_api.readImageFloat4(driver_image, image_type.dim, x, y, z)),
|
||||
.Int => try helpers.writeIntTexel(dst, try rt.image_api.readImageInt4(driver_image, image_type.dim, x, y, z)),
|
||||
else => return RuntimeError.InvalidValueType,
|
||||
}
|
||||
},
|
||||
@@ -2605,8 +2611,14 @@ fn opImageWrite(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!voi
|
||||
const coordinate = try rt.results[try rt.it.next()].getValue();
|
||||
const texel = try rt.results[try rt.it.next()].getValue();
|
||||
|
||||
const driver_image = switch ((try image.getValue()).*) {
|
||||
.Image => |img| img.driver_image,
|
||||
const driver_image, const image_type = switch ((try image.getValue()).*) {
|
||||
.Image => |img| .{ img.driver_image, switch ((try rt.results[img.type_word].getConstVariant()).*) {
|
||||
.Type => |t| switch (t) {
|
||||
.Image => |i| i,
|
||||
else => return RuntimeError.InvalidSpirV,
|
||||
},
|
||||
else => return RuntimeError.InvalidSpirV,
|
||||
} },
|
||||
else => return RuntimeError.InvalidSpirV,
|
||||
};
|
||||
|
||||
@@ -2741,7 +2753,7 @@ fn opImageWrite(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!voi
|
||||
.Vector4f32,
|
||||
.Vector3f32,
|
||||
.Vector2f32,
|
||||
=> try rt.image_api.writeImageFloat4(driver_image, x, y, z, try helpers.readFloatTexel(texel)),
|
||||
=> try rt.image_api.writeImageFloat4(driver_image, image_type.dim, x, y, z, try helpers.readFloatTexel(texel)),
|
||||
.Int,
|
||||
.Vector4i32,
|
||||
.Vector3i32,
|
||||
@@ -2749,12 +2761,12 @@ fn opImageWrite(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!voi
|
||||
.Vector4u32,
|
||||
.Vector3u32,
|
||||
.Vector2u32,
|
||||
=> try rt.image_api.writeImageInt4(driver_image, x, y, z, try helpers.readIntTexel(texel)),
|
||||
=> try rt.image_api.writeImageInt4(driver_image, image_type.dim, x, y, z, try helpers.readIntTexel(texel)),
|
||||
.Vector => |lanes| {
|
||||
if (lanes.len == 0) return RuntimeError.InvalidSpirV;
|
||||
switch (lanes[0]) {
|
||||
.Float => try rt.image_api.writeImageFloat4(driver_image, x, y, z, try helpers.readFloatTexel(texel)),
|
||||
.Int => try rt.image_api.writeImageInt4(driver_image, x, y, z, try helpers.readIntTexel(texel)),
|
||||
.Float => try rt.image_api.writeImageFloat4(driver_image, image_type.dim, x, y, z, try helpers.readFloatTexel(texel)),
|
||||
.Int => try rt.image_api.writeImageInt4(driver_image, image_type.dim, x, y, z, try helpers.readIntTexel(texel)),
|
||||
else => return RuntimeError.InvalidValueType,
|
||||
}
|
||||
},
|
||||
|
||||
+3
-3
@@ -263,9 +263,9 @@ pub const SpvStorageClass = enum(u32) {
|
||||
};
|
||||
|
||||
pub const SpvDim = enum(u32) {
|
||||
_1D = 0,
|
||||
_2D = 1,
|
||||
_3D = 2,
|
||||
@"1D" = 0,
|
||||
@"2D" = 1,
|
||||
@"3D" = 2,
|
||||
Cube = 3,
|
||||
Rect = 4,
|
||||
Buffer = 5,
|
||||
|
||||
Reference in New Issue
Block a user