From bd1d91faa33bb69bea67b390391fbe300cb2a742 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 11 Mar 2022 08:36:06 -0700 Subject: [PATCH] gpu: fix string handling / pointer casting Signed-off-by: Stephen Gutekanst --- gpu/src/Device.zig | 2 +- gpu/src/NativeInstance.zig | 22 +++++++++++----------- gpu/src/ShaderModule.zig | 4 ++-- gpu/src/Surface.zig | 14 +++++++------- gpu/src/SwapChain.zig | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/gpu/src/Device.zig b/gpu/src/Device.zig index 8e2585b0..e8145e84 100644 --- a/gpu/src/Device.zig +++ b/gpu/src/Device.zig @@ -79,7 +79,7 @@ pub inline fn nativeCreateSwapChain(device: Device, surface: ?Surface, descripto // TODO: docs pub const Descriptor = struct { - label: ?[]const u8 = null, + label: ?[*:0]const u8 = null, required_features: ?[]Feature = null, required_limits: ?Limits = null, }; diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index 20287529..55d45930 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -129,7 +129,7 @@ pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.D desc.layer = src.layer; break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{ .nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc), - .label = if (src.label) |l| @ptrCast([*c]const u8, l) else null, + .label = if (src.label) |l| l else null, }); }, .windows_hwnd => |src| blk: { @@ -140,7 +140,7 @@ pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.D desc.hwnd = src.hwnd; break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{ .nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc), - .label = if (src.label) |l| @ptrCast([*c]const u8, l) else null, + .label = if (src.label) |l| l else null, }); }, .windows_core_window => |src| blk: { @@ -150,7 +150,7 @@ pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.D desc.coreWindow = src.core_window; break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{ .nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc), - .label = if (src.label) |l| @ptrCast([*c]const u8, l) else null, + .label = if (src.label) |l| l else null, }); }, .windows_swap_chain_panel => |src| blk: { @@ -160,7 +160,7 @@ pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.D desc.swapChainPanel = src.swap_chain_panel; break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{ .nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc), - .label = if (src.label) |l| @ptrCast([*c]const u8, l) else null, + .label = if (src.label) |l| l else null, }); }, .xlib => |src| blk: { @@ -171,17 +171,17 @@ pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.D desc.window = src.window; break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{ .nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc), - .label = if (src.label) |l| @ptrCast([*c]const u8, l) else null, + .label = if (src.label) |l| l else null, }); }, .canvas_html_selector => |src| blk: { var desc: c.WGPUSurfaceDescriptorFromCanvasHTMLSelector = undefined; desc.chain.next = null; desc.chain.sType = c.WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector; - desc.selector = @ptrCast([*c]const u8, src.selector); + desc.selector = src.selector; break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{ .nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc), - .label = if (src.label) |l| @ptrCast([*c]const u8, l) else null, + .label = if (src.label) |l| l else null, }); }, }; @@ -260,7 +260,7 @@ const adapter_vtable = Adapter.VTable{ const desc = c.WGPUDeviceDescriptor{ .nextInChain = null, - .label = if (descriptor.label) |l| @ptrCast([*c]const u8, l) else null, + .label = if (descriptor.label) |l| l else null, .requiredFeaturesCount = if (descriptor.required_features) |f| @intCast(u32, f.len) else 0, .requiredFeatures = if (descriptor.required_features) |f| @ptrCast([*c]const c_uint, &f[0]) else null, .requiredLimits = if (required_limits) |*l| l else null, @@ -336,7 +336,7 @@ const device_vtable = Device.VTable{ }; const desc = c.WGPUShaderModuleDescriptor{ .nextInChain = @ptrCast(*const c.WGPUChainedStruct, &wgsl_desc), - .label = if (descriptor.label) |l| @ptrCast([*c]const u8, l) else null, + .label = if (descriptor.label) |l| l else null, }; return wrapShaderModule(c.wgpuDeviceCreateShaderModule(@ptrCast(c.WGPUDevice, ptr), &desc)); }, @@ -351,7 +351,7 @@ const device_vtable = Device.VTable{ }; const desc = c.WGPUShaderModuleDescriptor{ .nextInChain = @ptrCast(*const c.WGPUChainedStruct, &spirv_desc), - .label = if (descriptor.label) |l| @ptrCast([*c]const u8, l) else null, + .label = if (descriptor.label) |l| l else null, }; return wrapShaderModule(c.wgpuDeviceCreateShaderModule(@ptrCast(c.WGPUDevice, ptr), &desc)); }, @@ -362,7 +362,7 @@ const device_vtable = Device.VTable{ pub fn nativeCreateSwapChain(ptr: *anyopaque, surface: ?Surface, descriptor: *const SwapChain.Descriptor) SwapChain { const desc = c.WGPUSwapChainDescriptor{ .nextInChain = null, - .label = if (descriptor.label) |l| @ptrCast([*c]const u8, l) else null, + .label = if (descriptor.label) |l| l else null, .usage = @enumToInt(descriptor.usage), .format = @enumToInt(descriptor.format), .width = descriptor.width, diff --git a/gpu/src/ShaderModule.zig b/gpu/src/ShaderModule.zig index 224f6f18..15f47b90 100644 --- a/gpu/src/ShaderModule.zig +++ b/gpu/src/ShaderModule.zig @@ -27,9 +27,9 @@ pub const CodeTag = enum { }; pub const Descriptor = struct { - label: ?[]const u8 = null, + label: ?[*:0]const u8 = null, code: union(CodeTag) { - wgsl: [:0]const u8, + wgsl: [*:0]const u8, spirv: []const u32, }, }; diff --git a/gpu/src/Surface.zig b/gpu/src/Surface.zig index 99fd7852..43c2d892 100644 --- a/gpu/src/Surface.zig +++ b/gpu/src/Surface.zig @@ -32,30 +32,30 @@ pub const DescriptorTag = enum { // TODO: docs pub const Descriptor = union(DescriptorTag) { metal_layer: struct { - label: ?[]const u8, + label: ?[*:0]const u8 = null, layer: *anyopaque, }, windows_hwnd: struct { - label: ?[]const u8, + label: ?[*:0]const u8 = null, hinstance: *anyopaque, hwnd: *anyopaque, }, windows_core_window: struct { - label: ?[]const u8, + label: ?[*:0]const u8 = null, core_window: *anyopaque, }, windows_swap_chain_panel: struct { - label: ?[]const u8, + label: ?[*:0]const u8 = null, swap_chain_panel: *anyopaque, }, xlib: struct { - label: ?[]const u8, + label: ?[*:0]const u8 = null, display: *anyopaque, window: u32, }, canvas_html_selector: struct { - label: ?[]const u8, - selector: []const u8, + label: ?[*:0]const u8 = null, + selector: ?[*:0]const u8, }, }; diff --git a/gpu/src/SwapChain.zig b/gpu/src/SwapChain.zig index 6acbb845..299a2f61 100644 --- a/gpu/src/SwapChain.zig +++ b/gpu/src/SwapChain.zig @@ -38,7 +38,7 @@ pub inline fn configure( } pub const Descriptor = struct { - label: ?[]const u8 = null, + label: ?[:0]const u8 = null, usage: TextureUsage, format: TextureFormat, width: u32,