gpu: fix string handling / pointer casting
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
ce46b2a652
commit
bd1d91faa3
5 changed files with 22 additions and 22 deletions
|
|
@ -79,7 +79,7 @@ pub inline fn nativeCreateSwapChain(device: Device, surface: ?Surface, descripto
|
||||||
|
|
||||||
// TODO: docs
|
// TODO: docs
|
||||||
pub const Descriptor = struct {
|
pub const Descriptor = struct {
|
||||||
label: ?[]const u8 = null,
|
label: ?[*:0]const u8 = null,
|
||||||
required_features: ?[]Feature = null,
|
required_features: ?[]Feature = null,
|
||||||
required_limits: ?Limits = null,
|
required_limits: ?Limits = null,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.D
|
||||||
desc.layer = src.layer;
|
desc.layer = src.layer;
|
||||||
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
||||||
.nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc),
|
.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: {
|
.windows_hwnd => |src| blk: {
|
||||||
|
|
@ -140,7 +140,7 @@ pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.D
|
||||||
desc.hwnd = src.hwnd;
|
desc.hwnd = src.hwnd;
|
||||||
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
||||||
.nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc),
|
.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: {
|
.windows_core_window => |src| blk: {
|
||||||
|
|
@ -150,7 +150,7 @@ pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.D
|
||||||
desc.coreWindow = src.core_window;
|
desc.coreWindow = src.core_window;
|
||||||
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
||||||
.nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc),
|
.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: {
|
.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;
|
desc.swapChainPanel = src.swap_chain_panel;
|
||||||
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
||||||
.nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc),
|
.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: {
|
.xlib => |src| blk: {
|
||||||
|
|
@ -171,17 +171,17 @@ pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.D
|
||||||
desc.window = src.window;
|
desc.window = src.window;
|
||||||
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
||||||
.nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc),
|
.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: {
|
.canvas_html_selector => |src| blk: {
|
||||||
var desc: c.WGPUSurfaceDescriptorFromCanvasHTMLSelector = undefined;
|
var desc: c.WGPUSurfaceDescriptorFromCanvasHTMLSelector = undefined;
|
||||||
desc.chain.next = null;
|
desc.chain.next = null;
|
||||||
desc.chain.sType = c.WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector;
|
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{
|
break :blk c.wgpuInstanceCreateSurface(native.instance, &c.WGPUSurfaceDescriptor{
|
||||||
.nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc),
|
.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{
|
const desc = c.WGPUDeviceDescriptor{
|
||||||
.nextInChain = null,
|
.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,
|
.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,
|
.requiredFeatures = if (descriptor.required_features) |f| @ptrCast([*c]const c_uint, &f[0]) else null,
|
||||||
.requiredLimits = if (required_limits) |*l| l else null,
|
.requiredLimits = if (required_limits) |*l| l else null,
|
||||||
|
|
@ -336,7 +336,7 @@ const device_vtable = Device.VTable{
|
||||||
};
|
};
|
||||||
const desc = c.WGPUShaderModuleDescriptor{
|
const desc = c.WGPUShaderModuleDescriptor{
|
||||||
.nextInChain = @ptrCast(*const c.WGPUChainedStruct, &wgsl_desc),
|
.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));
|
return wrapShaderModule(c.wgpuDeviceCreateShaderModule(@ptrCast(c.WGPUDevice, ptr), &desc));
|
||||||
},
|
},
|
||||||
|
|
@ -351,7 +351,7 @@ const device_vtable = Device.VTable{
|
||||||
};
|
};
|
||||||
const desc = c.WGPUShaderModuleDescriptor{
|
const desc = c.WGPUShaderModuleDescriptor{
|
||||||
.nextInChain = @ptrCast(*const c.WGPUChainedStruct, &spirv_desc),
|
.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));
|
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 {
|
pub fn nativeCreateSwapChain(ptr: *anyopaque, surface: ?Surface, descriptor: *const SwapChain.Descriptor) SwapChain {
|
||||||
const desc = c.WGPUSwapChainDescriptor{
|
const desc = c.WGPUSwapChainDescriptor{
|
||||||
.nextInChain = null,
|
.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),
|
.usage = @enumToInt(descriptor.usage),
|
||||||
.format = @enumToInt(descriptor.format),
|
.format = @enumToInt(descriptor.format),
|
||||||
.width = descriptor.width,
|
.width = descriptor.width,
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ pub const CodeTag = enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Descriptor = struct {
|
pub const Descriptor = struct {
|
||||||
label: ?[]const u8 = null,
|
label: ?[*:0]const u8 = null,
|
||||||
code: union(CodeTag) {
|
code: union(CodeTag) {
|
||||||
wgsl: [:0]const u8,
|
wgsl: [*:0]const u8,
|
||||||
spirv: []const u32,
|
spirv: []const u32,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -32,30 +32,30 @@ pub const DescriptorTag = enum {
|
||||||
// TODO: docs
|
// TODO: docs
|
||||||
pub const Descriptor = union(DescriptorTag) {
|
pub const Descriptor = union(DescriptorTag) {
|
||||||
metal_layer: struct {
|
metal_layer: struct {
|
||||||
label: ?[]const u8,
|
label: ?[*:0]const u8 = null,
|
||||||
layer: *anyopaque,
|
layer: *anyopaque,
|
||||||
},
|
},
|
||||||
windows_hwnd: struct {
|
windows_hwnd: struct {
|
||||||
label: ?[]const u8,
|
label: ?[*:0]const u8 = null,
|
||||||
hinstance: *anyopaque,
|
hinstance: *anyopaque,
|
||||||
hwnd: *anyopaque,
|
hwnd: *anyopaque,
|
||||||
},
|
},
|
||||||
windows_core_window: struct {
|
windows_core_window: struct {
|
||||||
label: ?[]const u8,
|
label: ?[*:0]const u8 = null,
|
||||||
core_window: *anyopaque,
|
core_window: *anyopaque,
|
||||||
},
|
},
|
||||||
windows_swap_chain_panel: struct {
|
windows_swap_chain_panel: struct {
|
||||||
label: ?[]const u8,
|
label: ?[*:0]const u8 = null,
|
||||||
swap_chain_panel: *anyopaque,
|
swap_chain_panel: *anyopaque,
|
||||||
},
|
},
|
||||||
xlib: struct {
|
xlib: struct {
|
||||||
label: ?[]const u8,
|
label: ?[*:0]const u8 = null,
|
||||||
display: *anyopaque,
|
display: *anyopaque,
|
||||||
window: u32,
|
window: u32,
|
||||||
},
|
},
|
||||||
canvas_html_selector: struct {
|
canvas_html_selector: struct {
|
||||||
label: ?[]const u8,
|
label: ?[*:0]const u8 = null,
|
||||||
selector: []const u8,
|
selector: ?[*:0]const u8,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ pub inline fn configure(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const Descriptor = struct {
|
pub const Descriptor = struct {
|
||||||
label: ?[]const u8 = null,
|
label: ?[:0]const u8 = null,
|
||||||
usage: TextureUsage,
|
usage: TextureUsage,
|
||||||
format: TextureFormat,
|
format: TextureFormat,
|
||||||
width: u32,
|
width: u32,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue