fixing crashes
This commit is contained in:
+2
-2
@@ -31,8 +31,8 @@
|
|||||||
.lazy = true,
|
.lazy = true,
|
||||||
},
|
},
|
||||||
.SPIRV_Interpreter = .{
|
.SPIRV_Interpreter = .{
|
||||||
.url = "git+https://git.kbz8.me/kbz_8/SPIRV-Interpreter#236c6496ff567083ecd8084c792f02886b9c501a",
|
.url = "git+https://git.kbz8.me/kbz_8/SPIRV-Interpreter#a765246ee96bd2990471cab1d06468dab8ca5a90",
|
||||||
.hash = "SPIRV_Interpreter-0.0.1-ajmpn8pFBQCz_zQmSQ3OY_qRDfAanQDtvoNKTxxEEvpH",
|
.hash = "SPIRV_Interpreter-0.0.1-ajmpnwJJBQBf3lGA1o8VXvEotGeeajtQGgcrGeDVd21S",
|
||||||
.lazy = true,
|
.lazy = true,
|
||||||
},
|
},
|
||||||
//.SPIRV_Interpreter = .{
|
//.SPIRV_Interpreter = .{
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ const base = @import("base");
|
|||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
const Device = base.Device;
|
||||||
const Buffer = base.Buffer;
|
const Buffer = base.Buffer;
|
||||||
|
const BufferView = base.BufferView;
|
||||||
const ImageView = base.ImageView;
|
const ImageView = base.ImageView;
|
||||||
|
|
||||||
const SoftBuffer = @import("SoftBuffer.zig");
|
const SoftBuffer = @import("SoftBuffer.zig");
|
||||||
|
const SoftBufferView = @import("SoftBufferView.zig");
|
||||||
const SoftImageView = @import("SoftImageView.zig");
|
const SoftImageView = @import("SoftImageView.zig");
|
||||||
const SoftSampler = @import("SoftSampler.zig");
|
const SoftSampler = @import("SoftSampler.zig");
|
||||||
|
|
||||||
@@ -31,10 +33,15 @@ const DescriptorImage = struct {
|
|||||||
object: ?*SoftImageView,
|
object: ?*SoftImageView,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DescriptorTexel = struct {
|
||||||
|
object: ?*SoftBufferView,
|
||||||
|
};
|
||||||
|
|
||||||
const Descriptor = union(enum) {
|
const Descriptor = union(enum) {
|
||||||
buffer: []DescriptorBuffer,
|
buffer: []DescriptorBuffer,
|
||||||
texture: []DescriptorTexture,
|
texture: []DescriptorTexture,
|
||||||
image: []DescriptorImage,
|
image: []DescriptorImage,
|
||||||
|
texel_buffer: []DescriptorTexel,
|
||||||
unsupported: struct {},
|
unsupported: struct {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,8 +68,16 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, layout: *base.
|
|||||||
var size: usize = layout.bindings.len * @sizeOf(Descriptor);
|
var size: usize = layout.bindings.len * @sizeOf(Descriptor);
|
||||||
for (layout.bindings) |binding| {
|
for (layout.bindings) |binding| {
|
||||||
const struct_size: usize = switch (binding.descriptor_type) {
|
const struct_size: usize = switch (binding.descriptor_type) {
|
||||||
.storage_buffer, .storage_buffer_dynamic => @sizeOf(DescriptorBuffer),
|
.uniform_buffer,
|
||||||
.storage_image, .input_attachment => @sizeOf(DescriptorImage),
|
.storage_buffer,
|
||||||
|
.storage_buffer_dynamic,
|
||||||
|
=> @sizeOf(DescriptorBuffer),
|
||||||
|
.storage_image,
|
||||||
|
.input_attachment,
|
||||||
|
=> @sizeOf(DescriptorImage),
|
||||||
|
.storage_texel_buffer,
|
||||||
|
.uniform_texel_buffer,
|
||||||
|
=> @sizeOf(DescriptorTexel),
|
||||||
else => 0,
|
else => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -80,12 +95,22 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, layout: *base.
|
|||||||
const descriptors = local_allocator.alloc(Descriptor, layout.bindings.len) catch return VkError.OutOfHostMemory;
|
const descriptors = local_allocator.alloc(Descriptor, layout.bindings.len) catch return VkError.OutOfHostMemory;
|
||||||
for (descriptors, layout.bindings) |*descriptor, binding| {
|
for (descriptors, layout.bindings) |*descriptor, binding| {
|
||||||
switch (binding.descriptor_type) {
|
switch (binding.descriptor_type) {
|
||||||
.storage_buffer, .storage_buffer_dynamic => descriptor.* = .{
|
.uniform_buffer,
|
||||||
|
.storage_buffer,
|
||||||
|
.storage_buffer_dynamic,
|
||||||
|
=> descriptor.* = .{
|
||||||
.buffer = local_allocator.alloc(DescriptorBuffer, binding.array_size) catch return VkError.OutOfHostMemory,
|
.buffer = local_allocator.alloc(DescriptorBuffer, binding.array_size) catch return VkError.OutOfHostMemory,
|
||||||
},
|
},
|
||||||
.storage_image, .input_attachment => descriptor.* = .{
|
.storage_image,
|
||||||
|
.input_attachment,
|
||||||
|
=> descriptor.* = .{
|
||||||
.image = local_allocator.alloc(DescriptorImage, binding.array_size) catch return VkError.OutOfHostMemory,
|
.image = local_allocator.alloc(DescriptorImage, binding.array_size) catch return VkError.OutOfHostMemory,
|
||||||
},
|
},
|
||||||
|
.storage_texel_buffer,
|
||||||
|
.uniform_texel_buffer,
|
||||||
|
=> descriptor.* = .{
|
||||||
|
.texel_buffer = local_allocator.alloc(DescriptorTexel, binding.array_size) catch return VkError.OutOfHostMemory,
|
||||||
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,10 +133,24 @@ pub fn copy(interface: *Interface, src_interface: *const Interface, data: vk.Cop
|
|||||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||||
const src: *const Self = @alignCast(@fieldParentPtr("interface", src_interface));
|
const src: *const Self = @alignCast(@fieldParentPtr("interface", src_interface));
|
||||||
|
|
||||||
for (self.descriptors[data.dst_binding..(data.dst_binding + data.descriptor_count)], src.descriptors[data.src_binding..(data.src_binding + data.descriptor_count)]) |*dst_desc, src_desc| {
|
const dst_start = @min(@as(usize, @intCast(data.dst_binding)), self.descriptors.len);
|
||||||
|
const src_start = @min(@as(usize, @intCast(data.src_binding)), src.descriptors.len);
|
||||||
|
|
||||||
|
const descriptor_count: usize = @intCast(data.descriptor_count);
|
||||||
|
|
||||||
|
const dst_remaining = self.descriptors.len - dst_start;
|
||||||
|
const src_remaining = src.descriptors.len - src_start;
|
||||||
|
|
||||||
|
const copy_count = @min(descriptor_count, dst_remaining, src_remaining);
|
||||||
|
|
||||||
|
const dst_slice = self.descriptors[dst_start .. dst_start + copy_count];
|
||||||
|
const src_slice = src.descriptors[src_start .. src_start + copy_count];
|
||||||
|
|
||||||
|
for (dst_slice, src_slice) |*dst_desc, src_desc| {
|
||||||
switch (dst_desc.*) {
|
switch (dst_desc.*) {
|
||||||
.buffer => |dst_buffer| @memcpy(dst_buffer[0..], src_desc.buffer[0..]),
|
.buffer => |dst_buffer| @memcpy(dst_buffer[0..], src_desc.buffer[0..]),
|
||||||
.image => |dst_image| @memcpy(dst_image[0..], src_desc.image[0..]),
|
.image => |dst_image| @memcpy(dst_image[0..], src_desc.image[0..]),
|
||||||
|
.texel_buffer => |dst_texel| @memcpy(dst_texel[0..], src_desc.texel_buffer[0..]),
|
||||||
else => {
|
else => {
|
||||||
dst_desc.* = .{ .unsupported = .{} };
|
dst_desc.* = .{ .unsupported = .{} };
|
||||||
base.unsupported("descriptor type for copy", .{});
|
base.unsupported("descriptor type for copy", .{});
|
||||||
@@ -124,7 +163,10 @@ pub fn write(interface: *Interface, write_data: vk.WriteDescriptorSet) VkError!v
|
|||||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||||
|
|
||||||
switch (write_data.descriptor_type) {
|
switch (write_data.descriptor_type) {
|
||||||
.storage_buffer, .storage_buffer_dynamic => {
|
.uniform_buffer,
|
||||||
|
.storage_buffer,
|
||||||
|
.storage_buffer_dynamic,
|
||||||
|
=> {
|
||||||
for (write_data.p_buffer_info, 0..write_data.descriptor_count) |buffer_info, i| {
|
for (write_data.p_buffer_info, 0..write_data.descriptor_count) |buffer_info, i| {
|
||||||
const desc = &self.descriptors[write_data.dst_binding].buffer[i];
|
const desc = &self.descriptors[write_data.dst_binding].buffer[i];
|
||||||
desc.* = .{
|
desc.* = .{
|
||||||
@@ -141,7 +183,9 @@ pub fn write(interface: *Interface, write_data: vk.WriteDescriptorSet) VkError!v
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.storage_image, .input_attachment => {
|
.storage_image,
|
||||||
|
.input_attachment,
|
||||||
|
=> {
|
||||||
for (write_data.p_image_info, 0..write_data.descriptor_count) |image_info, i| {
|
for (write_data.p_image_info, 0..write_data.descriptor_count) |image_info, i| {
|
||||||
const desc = &self.descriptors[write_data.dst_binding].image[i];
|
const desc = &self.descriptors[write_data.dst_binding].image[i];
|
||||||
desc.* = .{ .object = null };
|
desc.* = .{ .object = null };
|
||||||
@@ -151,6 +195,18 @@ pub fn write(interface: *Interface, write_data: vk.WriteDescriptorSet) VkError!v
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
.storage_texel_buffer,
|
||||||
|
.uniform_texel_buffer,
|
||||||
|
=> {
|
||||||
|
for (write_data.p_texel_buffer_view, 0..write_data.descriptor_count) |view, i| {
|
||||||
|
const desc = &self.descriptors[write_data.dst_binding].texel_buffer[i];
|
||||||
|
desc.* = .{ .object = null };
|
||||||
|
if (view != .null_handle) {
|
||||||
|
const buffer_view = try NonDispatchable(BufferView).fromHandleObject(view);
|
||||||
|
desc.object = @as(*SoftBufferView, @alignCast(@fieldParentPtr("interface", buffer_view)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
else => {
|
else => {
|
||||||
self.descriptors[write_data.dst_binding] = .{ .unsupported = .{} };
|
self.descriptors[write_data.dst_binding] = .{ .unsupported = .{} };
|
||||||
base.unsupported("descriptor type {s} for writting", .{@tagName(write_data.descriptor_type)});
|
base.unsupported("descriptor type {s} for writting", .{@tagName(write_data.descriptor_type)});
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const lib = @import("lib.zig");
|
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
const Device = base.Device;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const spv = @import("spv");
|
const spv = @import("spv");
|
||||||
|
|
||||||
|
const zm = base.zm;
|
||||||
|
|
||||||
|
const blitter = @import("device/blitter.zig");
|
||||||
|
|
||||||
const Device = base.Device;
|
const Device = base.Device;
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const SpvRuntimeError = spv.Runtime.RuntimeError;
|
const SpvRuntimeError = spv.Runtime.RuntimeError;
|
||||||
@@ -11,6 +15,8 @@ const NonDispatchable = base.NonDispatchable;
|
|||||||
const ShaderModule = base.ShaderModule;
|
const ShaderModule = base.ShaderModule;
|
||||||
|
|
||||||
const SoftDevice = @import("SoftDevice.zig");
|
const SoftDevice = @import("SoftDevice.zig");
|
||||||
|
const SoftBuffer = @import("SoftBuffer.zig");
|
||||||
|
const SoftBufferView = @import("SoftBufferView.zig");
|
||||||
const SoftImage = @import("SoftImage.zig");
|
const SoftImage = @import("SoftImage.zig");
|
||||||
const SoftImageView = @import("SoftImageView.zig");
|
const SoftImageView = @import("SoftImageView.zig");
|
||||||
const SoftInstance = @import("SoftInstance.zig");
|
const SoftInstance = @import("SoftInstance.zig");
|
||||||
@@ -245,10 +251,17 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
|
|||||||
allocator.destroy(self);
|
allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn readImageFloat4(context: *anyopaque, x: i32, y: i32, z: i32) SpvRuntimeError!spv.Runtime.Vec4(f32) {
|
fn readImageFloat4(context: *anyopaque, dim: spv.SpvDim, x: i32, y: i32, z: i32) SpvRuntimeError!spv.Runtime.Vec4(f32) {
|
||||||
|
var pixel = zm.f32x4s(0.0);
|
||||||
|
if (dim == .Buffer) {
|
||||||
|
const buffer_view: *SoftBufferView = @ptrCast(@alignCast(context));
|
||||||
|
const buffer: *SoftBuffer = @alignCast(@fieldParentPtr("interface", buffer_view.interface.buffer));
|
||||||
|
const map = buffer.mapAsSliceWithOffset(u8, buffer_view.interface.offset, buffer_view.interface.range) catch return SpvRuntimeError.Unknown;
|
||||||
|
pixel = blitter.readFloat4(map[(@as(usize, @intCast(x)) * base.format.texelSize(buffer_view.interface.format))..], buffer_view.interface.format);
|
||||||
|
} else {
|
||||||
const image_view: *SoftImageView = @ptrCast(@alignCast(context));
|
const image_view: *SoftImageView = @ptrCast(@alignCast(context));
|
||||||
const image: *SoftImage = @alignCast(@fieldParentPtr("interface", image_view.interface.image));
|
const image: *SoftImage = @alignCast(@fieldParentPtr("interface", image_view.interface.image));
|
||||||
const pixel = image.readFloat4(
|
pixel = image.readFloat4(
|
||||||
.{
|
.{
|
||||||
.x = x,
|
.x = x,
|
||||||
.y = y,
|
.y = y,
|
||||||
@@ -261,6 +274,7 @@ fn readImageFloat4(context: *anyopaque, x: i32, y: i32, z: i32) SpvRuntimeError!
|
|||||||
},
|
},
|
||||||
image_view.interface.format,
|
image_view.interface.format,
|
||||||
) catch return SpvRuntimeError.Unknown;
|
) catch return SpvRuntimeError.Unknown;
|
||||||
|
}
|
||||||
return .{
|
return .{
|
||||||
.x = pixel[0],
|
.x = pixel[0],
|
||||||
.y = pixel[1],
|
.y = pixel[1],
|
||||||
@@ -269,10 +283,17 @@ fn readImageFloat4(context: *anyopaque, x: i32, y: i32, z: i32) SpvRuntimeError!
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn readImageInt4(context: *anyopaque, x: i32, y: i32, z: i32) SpvRuntimeError!spv.Runtime.Vec4(u32) {
|
fn readImageInt4(context: *anyopaque, dim: spv.SpvDim, x: i32, y: i32, z: i32) SpvRuntimeError!spv.Runtime.Vec4(u32) {
|
||||||
|
var pixel = @Vector(4, u32){ 0, 0, 0, 0 };
|
||||||
|
if (dim == .Buffer) {
|
||||||
|
const buffer_view: *SoftBufferView = @ptrCast(@alignCast(context));
|
||||||
|
const buffer: *SoftBuffer = @alignCast(@fieldParentPtr("interface", buffer_view.interface.buffer));
|
||||||
|
const map = buffer.mapAsSliceWithOffset(u8, buffer_view.interface.offset, buffer_view.interface.range) catch return SpvRuntimeError.Unknown;
|
||||||
|
pixel = blitter.readInt4(map[(@as(usize, @intCast(x)) * base.format.texelSize(buffer_view.interface.format))..], buffer_view.interface.format);
|
||||||
|
} else {
|
||||||
const image_view: *SoftImageView = @ptrCast(@alignCast(context));
|
const image_view: *SoftImageView = @ptrCast(@alignCast(context));
|
||||||
const image: *SoftImage = @alignCast(@fieldParentPtr("interface", image_view.interface.image));
|
const image: *SoftImage = @alignCast(@fieldParentPtr("interface", image_view.interface.image));
|
||||||
const pixel = image.readInt4(
|
pixel = image.readInt4(
|
||||||
.{
|
.{
|
||||||
.x = x,
|
.x = x,
|
||||||
.y = y,
|
.y = y,
|
||||||
@@ -285,6 +306,7 @@ fn readImageInt4(context: *anyopaque, x: i32, y: i32, z: i32) SpvRuntimeError!sp
|
|||||||
},
|
},
|
||||||
image_view.interface.format,
|
image_view.interface.format,
|
||||||
) catch return SpvRuntimeError.Unknown;
|
) catch return SpvRuntimeError.Unknown;
|
||||||
|
}
|
||||||
return .{
|
return .{
|
||||||
.x = pixel[0],
|
.x = pixel[0],
|
||||||
.y = pixel[1],
|
.y = pixel[1],
|
||||||
@@ -293,7 +315,14 @@ fn readImageInt4(context: *anyopaque, x: i32, y: i32, z: i32) SpvRuntimeError!sp
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writeImageFloat4(context: *anyopaque, x: i32, y: i32, z: i32, pixel: spv.Runtime.Vec4(f32)) SpvRuntimeError!void {
|
fn writeImageFloat4(context: *anyopaque, dim: spv.SpvDim, x: i32, y: i32, z: i32, pixel: spv.Runtime.Vec4(f32)) SpvRuntimeError!void {
|
||||||
|
const vec_pixel = zm.f32x4(pixel.x, pixel.y, pixel.z, pixel.w);
|
||||||
|
if (dim == .Buffer) {
|
||||||
|
const buffer_view: *SoftBufferView = @ptrCast(@alignCast(context));
|
||||||
|
const buffer: *SoftBuffer = @alignCast(@fieldParentPtr("interface", buffer_view.interface.buffer));
|
||||||
|
const map = buffer.mapAsSliceWithOffset(u8, buffer_view.interface.offset, buffer_view.interface.range) catch return SpvRuntimeError.Unknown;
|
||||||
|
blitter.writeFloat4(vec_pixel, map[(@as(usize, @intCast(x)) * base.format.texelSize(buffer_view.interface.format))..], buffer_view.interface.format);
|
||||||
|
} else {
|
||||||
const image_view: *SoftImageView = @ptrCast(@alignCast(context));
|
const image_view: *SoftImageView = @ptrCast(@alignCast(context));
|
||||||
const image: *SoftImage = @alignCast(@fieldParentPtr("interface", image_view.interface.image));
|
const image: *SoftImage = @alignCast(@fieldParentPtr("interface", image_view.interface.image));
|
||||||
image.writeFloat4(
|
image.writeFloat4(
|
||||||
@@ -308,11 +337,19 @@ fn writeImageFloat4(context: *anyopaque, x: i32, y: i32, z: i32, pixel: spv.Runt
|
|||||||
.array_layer = image_view.interface.subresource_range.base_array_layer,
|
.array_layer = image_view.interface.subresource_range.base_array_layer,
|
||||||
},
|
},
|
||||||
image_view.interface.format,
|
image_view.interface.format,
|
||||||
.{ pixel.x, pixel.y, pixel.z, pixel.w },
|
vec_pixel,
|
||||||
) catch return SpvRuntimeError.Unknown;
|
) catch return SpvRuntimeError.Unknown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writeImageInt4(context: *anyopaque, x: i32, y: i32, z: i32, pixel: spv.Runtime.Vec4(u32)) SpvRuntimeError!void {
|
fn writeImageInt4(context: *anyopaque, dim: spv.SpvDim, x: i32, y: i32, z: i32, pixel: spv.Runtime.Vec4(u32)) SpvRuntimeError!void {
|
||||||
|
const vec_pixel = @Vector(4, u32){ pixel.x, pixel.y, pixel.z, pixel.w };
|
||||||
|
if (dim == .Buffer) {
|
||||||
|
const buffer_view: *SoftBufferView = @ptrCast(@alignCast(context));
|
||||||
|
const buffer: *SoftBuffer = @alignCast(@fieldParentPtr("interface", buffer_view.interface.buffer));
|
||||||
|
const map = buffer.mapAsSliceWithOffset(u8, buffer_view.interface.offset, buffer_view.interface.range) catch return SpvRuntimeError.Unknown;
|
||||||
|
blitter.writeInt4(vec_pixel, map[(@as(usize, @intCast(x)) * base.format.texelSize(buffer_view.interface.format))..], buffer_view.interface.format);
|
||||||
|
} else {
|
||||||
const image_view: *SoftImageView = @ptrCast(@alignCast(context));
|
const image_view: *SoftImageView = @ptrCast(@alignCast(context));
|
||||||
const image: *SoftImage = @alignCast(@fieldParentPtr("interface", image_view.interface.image));
|
const image: *SoftImage = @alignCast(@fieldParentPtr("interface", image_view.interface.image));
|
||||||
image.writeInt4(
|
image.writeInt4(
|
||||||
@@ -327,6 +364,7 @@ fn writeImageInt4(context: *anyopaque, x: i32, y: i32, z: i32, pixel: spv.Runtim
|
|||||||
.array_layer = image_view.interface.subresource_range.base_array_layer,
|
.array_layer = image_view.interface.subresource_range.base_array_layer,
|
||||||
},
|
},
|
||||||
image_view.interface.format,
|
image_view.interface.format,
|
||||||
.{ pixel.x, pixel.y, pixel.z, pixel.w },
|
vec_pixel,
|
||||||
) catch return SpvRuntimeError.Unknown;
|
) catch return SpvRuntimeError.Unknown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,6 +194,17 @@ fn writeDescriptorSets(self: *Self, rt: *spv.Runtime) !void {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
.texel_buffer => |texel_data_array| for (texel_data_array, 0..) |texel_data, descriptor_index| {
|
||||||
|
if (texel_data.object) |buffer_view| {
|
||||||
|
const addr: usize = @intFromPtr(buffer_view);
|
||||||
|
try rt.writeDescriptorSet(
|
||||||
|
std.mem.asBytes(&addr),
|
||||||
|
@as(u32, @intCast(set_index)),
|
||||||
|
@as(u32, @intCast(binding_index)),
|
||||||
|
@as(u32, @intCast(descriptor_index)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+101
-14
@@ -558,15 +558,22 @@ pub fn readFloat4(map: []const u8, src_format: vk.Format) F32x4 {
|
|||||||
=> c[0] = @as(f32, @floatFromInt(std.mem.bytesToValue(u16, map))) / 255.0,
|
=> c[0] = @as(f32, @floatFromInt(std.mem.bytesToValue(u16, map))) / 255.0,
|
||||||
|
|
||||||
.r8g8b8a8_sint,
|
.r8g8b8a8_sint,
|
||||||
.r8g8b8a8_snorm,
|
|
||||||
.r8g8b8a8_unorm,
|
|
||||||
.r8g8b8a8_uint,
|
.r8g8b8a8_uint,
|
||||||
.r8g8b8a8_srgb,
|
.r8g8b8a8_srgb,
|
||||||
|
.r8g8b8a8_unorm,
|
||||||
=> {
|
=> {
|
||||||
c[0] = @as(f32, @floatFromInt(map[0])) / 255.0;
|
c[0] = @as(f32, @floatFromInt(map[0])) / std.math.maxInt(u8);
|
||||||
c[1] = @as(f32, @floatFromInt(map[1])) / 255.0;
|
c[1] = @as(f32, @floatFromInt(map[1])) / std.math.maxInt(u8);
|
||||||
c[2] = @as(f32, @floatFromInt(map[2])) / 255.0;
|
c[2] = @as(f32, @floatFromInt(map[2])) / std.math.maxInt(u8);
|
||||||
c[3] = @as(f32, @floatFromInt(map[3])) / 255.0;
|
c[3] = @as(f32, @floatFromInt(map[3])) / std.math.maxInt(u8);
|
||||||
|
},
|
||||||
|
|
||||||
|
.r8g8b8a8_snorm,
|
||||||
|
=> {
|
||||||
|
c[0] = @as(f32, @floatFromInt(map[0])) / std.math.maxInt(i8);
|
||||||
|
c[1] = @as(f32, @floatFromInt(map[1])) / std.math.maxInt(i8);
|
||||||
|
c[2] = @as(f32, @floatFromInt(map[2])) / std.math.maxInt(i8);
|
||||||
|
c[3] = @as(f32, @floatFromInt(map[3])) / std.math.maxInt(i8);
|
||||||
},
|
},
|
||||||
|
|
||||||
.r16_sint,
|
.r16_sint,
|
||||||
@@ -581,10 +588,56 @@ pub fn readFloat4(map: []const u8, src_format: vk.Format) F32x4 {
|
|||||||
.r32_sfloat,
|
.r32_sfloat,
|
||||||
=> c[0] = std.mem.bytesToValue(f32, map),
|
=> c[0] = std.mem.bytesToValue(f32, map),
|
||||||
|
|
||||||
|
.r16g16b16a16_sint,
|
||||||
|
.r16g16b16a16_uint,
|
||||||
|
.r16g16b16a16_unorm,
|
||||||
|
.r16g16b16a16_snorm,
|
||||||
|
=> c = std.mem.bytesToValue(@Vector(4, u16), map) / zm.f32x4s(std.math.maxInt(u16)),
|
||||||
|
|
||||||
|
.r16g16b16a16_sfloat => c = std.mem.bytesToValue(@Vector(4, f16), map),
|
||||||
.r32g32b32a32_sfloat => c = std.mem.bytesToValue(F32x4, map),
|
.r32g32b32a32_sfloat => c = std.mem.bytesToValue(F32x4, map),
|
||||||
|
|
||||||
.s8_uint => c[0] = @floatFromInt(map[0]),
|
.s8_uint => c[0] = @floatFromInt(map[0]),
|
||||||
|
|
||||||
|
.a8b8g8r8_uint_pack32,
|
||||||
|
.a8b8g8r8_sint_pack32,
|
||||||
|
.a8b8g8r8_unorm_pack32,
|
||||||
|
=> {
|
||||||
|
const pack = std.mem.bytesToValue(@Vector(4, u8), map);
|
||||||
|
c[0] = @as(f32, @floatFromInt(pack[0])) / std.math.maxInt(u8);
|
||||||
|
c[1] = @as(f32, @floatFromInt(pack[1])) / std.math.maxInt(u8);
|
||||||
|
c[2] = @as(f32, @floatFromInt(pack[2])) / std.math.maxInt(u8);
|
||||||
|
c[3] = @as(f32, @floatFromInt(pack[3])) / std.math.maxInt(u8);
|
||||||
|
},
|
||||||
|
|
||||||
|
.a8b8g8r8_snorm_pack32 => {
|
||||||
|
const pack = std.mem.bytesToValue(@Vector(4, u8), map);
|
||||||
|
c[0] = @as(f32, @floatFromInt(pack[0])) / std.math.maxInt(i8);
|
||||||
|
c[1] = @as(f32, @floatFromInt(pack[1])) / std.math.maxInt(i8);
|
||||||
|
c[2] = @as(f32, @floatFromInt(pack[2])) / std.math.maxInt(i8);
|
||||||
|
c[3] = @as(f32, @floatFromInt(pack[3])) / std.math.maxInt(i8);
|
||||||
|
},
|
||||||
|
|
||||||
|
.a2b10g10r10_uint_pack32,
|
||||||
|
.a2b10g10r10_unorm_pack32,
|
||||||
|
=> {
|
||||||
|
const pack = std.mem.bytesToValue(u32, map);
|
||||||
|
c[0] = @as(f32, @floatFromInt(pack & 0x000003FF)) / std.math.maxInt(u10);
|
||||||
|
c[1] = @as(f32, @floatFromInt((pack & 0x000FFC00) >> 10)) / std.math.maxInt(u10);
|
||||||
|
c[2] = @as(f32, @floatFromInt((pack & 0x3FF00000) >> 20)) / std.math.maxInt(u10);
|
||||||
|
c[3] = @as(f32, @floatFromInt((pack & 0xC0000000) >> 30)) / std.math.maxInt(u2);
|
||||||
|
},
|
||||||
|
|
||||||
|
.a2r10g10b10_uint_pack32,
|
||||||
|
.a2r10g10b10_unorm_pack32,
|
||||||
|
=> {
|
||||||
|
const pack = std.mem.bytesToValue(u32, map);
|
||||||
|
c[2] = @as(f32, @floatFromInt(pack & 0x000003FF)) / std.math.maxInt(u10);
|
||||||
|
c[1] = @as(f32, @floatFromInt((pack & 0x000FFC00) >> 10)) / std.math.maxInt(u10);
|
||||||
|
c[0] = @as(f32, @floatFromInt((pack & 0x3FF00000) >> 20)) / std.math.maxInt(u10);
|
||||||
|
c[3] = @as(f32, @floatFromInt((pack & 0xC0000000) >> 30)) / std.math.maxInt(u2);
|
||||||
|
},
|
||||||
|
|
||||||
else => base.unsupported("Blitter: read float from source format {any}", .{src_format}),
|
else => base.unsupported("Blitter: read float from source format {any}", .{src_format}),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,10 +669,10 @@ pub fn writeFloat4(color: F32x4, map: []u8, dst_format: vk.Format) void {
|
|||||||
.b8g8r8a8_srgb,
|
.b8g8r8a8_srgb,
|
||||||
.b8g8r8a8_unorm,
|
.b8g8r8a8_unorm,
|
||||||
=> {
|
=> {
|
||||||
map[0] = @intFromFloat(@round(color[2] * 255.0));
|
map[0] = @intFromFloat(@round(color[2] * std.math.maxInt(u8)));
|
||||||
map[1] = @intFromFloat(@round(color[1] * 255.0));
|
map[1] = @intFromFloat(@round(color[1] * std.math.maxInt(u8)));
|
||||||
map[2] = @intFromFloat(@round(color[0] * 255.0));
|
map[2] = @intFromFloat(@round(color[0] * std.math.maxInt(u8)));
|
||||||
map[3] = @intFromFloat(@round(color[3] * 255.0));
|
map[3] = @intFromFloat(@round(color[3] * std.math.maxInt(u8)));
|
||||||
},
|
},
|
||||||
|
|
||||||
.a8b8g8r8_unorm_pack32,
|
.a8b8g8r8_unorm_pack32,
|
||||||
@@ -631,10 +684,10 @@ pub fn writeFloat4(color: F32x4, map: []u8, dst_format: vk.Format) void {
|
|||||||
.r8g8b8a8_uscaled,
|
.r8g8b8a8_uscaled,
|
||||||
.a8b8g8r8_uscaled_pack32,
|
.a8b8g8r8_uscaled_pack32,
|
||||||
=> {
|
=> {
|
||||||
map[0] = @intFromFloat(@round(color[0] * 255.0));
|
map[0] = @intFromFloat(@round(color[0] * std.math.maxInt(u8)));
|
||||||
map[1] = @intFromFloat(@round(color[1] * 255.0));
|
map[1] = @intFromFloat(@round(color[1] * std.math.maxInt(u8)));
|
||||||
map[2] = @intFromFloat(@round(color[2] * 255.0));
|
map[2] = @intFromFloat(@round(color[2] * std.math.maxInt(u8)));
|
||||||
map[3] = @intFromFloat(@round(color[3] * 255.0));
|
map[3] = @intFromFloat(@round(color[3] * std.math.maxInt(u8)));
|
||||||
},
|
},
|
||||||
|
|
||||||
.r32g32b32a32_sfloat => std.mem.bytesAsValue(F32x4, map).* = color,
|
.r32g32b32a32_sfloat => std.mem.bytesAsValue(F32x4, map).* = color,
|
||||||
@@ -651,9 +704,11 @@ pub fn readInt4(map: []const u8, src_format: vk.Format) U32x4 {
|
|||||||
.r8_uint,
|
.r8_uint,
|
||||||
.s8_uint,
|
.s8_uint,
|
||||||
=> c[0] = map[0],
|
=> c[0] = map[0],
|
||||||
|
|
||||||
.r16_sint,
|
.r16_sint,
|
||||||
.r16_uint,
|
.r16_uint,
|
||||||
=> c[0] = std.mem.bytesToValue(u16, map),
|
=> c[0] = std.mem.bytesToValue(u16, map),
|
||||||
|
|
||||||
.r32_sint,
|
.r32_sint,
|
||||||
.r32_uint,
|
.r32_uint,
|
||||||
=> c[0] = std.mem.bytesToValue(u32, map),
|
=> c[0] = std.mem.bytesToValue(u32, map),
|
||||||
@@ -680,6 +735,38 @@ pub fn readInt4(map: []const u8, src_format: vk.Format) U32x4 {
|
|||||||
.r32g32b32a32_uint,
|
.r32g32b32a32_uint,
|
||||||
=> c = std.mem.bytesToValue(U32x4, map),
|
=> c = std.mem.bytesToValue(U32x4, map),
|
||||||
|
|
||||||
|
.a8b8g8r8_uint_pack32,
|
||||||
|
.a8b8g8r8_sint_pack32,
|
||||||
|
.a8b8g8r8_unorm_pack32,
|
||||||
|
.a8b8g8r8_snorm_pack32,
|
||||||
|
=> {
|
||||||
|
const pack = std.mem.bytesToValue(@Vector(4, u8), map);
|
||||||
|
c[0] = pack[0];
|
||||||
|
c[1] = pack[1];
|
||||||
|
c[2] = pack[2];
|
||||||
|
c[3] = pack[3];
|
||||||
|
},
|
||||||
|
|
||||||
|
.a2b10g10r10_unorm_pack32,
|
||||||
|
.a2b10g10r10_uint_pack32,
|
||||||
|
=> {
|
||||||
|
const pack = std.mem.bytesToValue(u32, map);
|
||||||
|
c[0] = (pack & 0x000003FF);
|
||||||
|
c[1] = (pack & 0x000FFC00) >> 10;
|
||||||
|
c[2] = (pack & 0x3FF00000) >> 20;
|
||||||
|
c[3] = (pack & 0xC0000000) >> 30;
|
||||||
|
},
|
||||||
|
|
||||||
|
.a2r10g10b10_unorm_pack32,
|
||||||
|
.a2r10g10b10_uint_pack32,
|
||||||
|
=> {
|
||||||
|
const pack = std.mem.bytesToValue(u32, map);
|
||||||
|
c[0] = (pack & 0x000003FF);
|
||||||
|
c[1] = (pack & 0x000FFC00) >> 10;
|
||||||
|
c[2] = (pack & 0x3FF00000) >> 20;
|
||||||
|
c[3] = (pack & 0xC0000000) >> 30;
|
||||||
|
},
|
||||||
|
|
||||||
else => base.unsupported("Blitter: read int from source format {any}", .{src_format}),
|
else => base.unsupported("Blitter: read int from source format {any}", .{src_format}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
|
|
||||||
const NonDispatchable = @import("NonDispatchable.zig");
|
|
||||||
|
|
||||||
const VkError = @import("error_set.zig").VkError;
|
const VkError = @import("error_set.zig").VkError;
|
||||||
|
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
||||||
|
|
||||||
const Device = @import("Device.zig");
|
const Device = @import("Device.zig");
|
||||||
|
const Buffer = @import("Buffer.zig");
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const ObjectType: vk.ObjectType = .buffer_view;
|
pub const ObjectType: vk.ObjectType = .buffer_view;
|
||||||
|
|
||||||
owner: *Device,
|
owner: *Device,
|
||||||
|
buffer: *Buffer,
|
||||||
|
format: vk.Format,
|
||||||
|
offset: vk.DeviceSize,
|
||||||
|
range: vk.DeviceSize,
|
||||||
|
|
||||||
vtable: *const VTable,
|
vtable: *const VTable,
|
||||||
|
|
||||||
@@ -20,10 +24,13 @@ pub const VTable = struct {
|
|||||||
|
|
||||||
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.BufferViewCreateInfo) VkError!Self {
|
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.BufferViewCreateInfo) VkError!Self {
|
||||||
_ = allocator;
|
_ = allocator;
|
||||||
_ = info;
|
|
||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
|
.buffer = try NonDispatchable(Buffer).fromHandleObject(info.buffer),
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
|
.format = info.format,
|
||||||
|
.offset = info.offset,
|
||||||
|
.range = info.range,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ const VkError = @import("error_set.zig").VkError;
|
|||||||
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
||||||
|
|
||||||
const Device = @import("Device.zig");
|
const Device = @import("Device.zig");
|
||||||
|
|
||||||
const DeviceMemory = @import("DeviceMemory.zig");
|
|
||||||
const Image = @import("Image.zig");
|
const Image = @import("Image.zig");
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Rende
|
|||||||
else
|
else
|
||||||
null,
|
null,
|
||||||
.depth_stencil_attachments = if (subpass_info.p_depth_stencil_attachment) |subpass_attachment|
|
.depth_stencil_attachments = if (subpass_info.p_depth_stencil_attachment) |subpass_attachment|
|
||||||
subpass_attachment.*
|
if (subpass_attachment.attachment != vk.ATTACHMENT_UNUSED) subpass_attachment.* else null
|
||||||
else
|
else
|
||||||
null,
|
null,
|
||||||
.preserve_attachments = if (subpass_info.p_preserve_attachments) |subpass_attachments|
|
.preserve_attachments = if (subpass_info.p_preserve_attachments) |subpass_attachments|
|
||||||
|
|||||||
Reference in New Issue
Block a user