gpu: add Device.createShaderModuleWGSL helper
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
4ba5640da4
commit
358baf08e2
3 changed files with 18 additions and 12 deletions
|
|
@ -238,4 +238,6 @@ const descriptor = gpu.Surface.Descriptor{
|
|||
|
||||
### Others
|
||||
|
||||
* `Device.createShaderModuleWGSL` (helper to create WGSL shader modules more nicely)
|
||||
|
||||
There may be other opportunities for helpers, to improve the existing APIs, or add utility APIs on top of the existing APIs. If you find one, please open an issue we'd love to consider it.
|
||||
|
|
|
|||
|
|
@ -49,24 +49,14 @@ pub fn main() !void {
|
|||
\\ return vec4<f32>(pos[VertexIndex], 0.0, 1.0);
|
||||
\\ }
|
||||
;
|
||||
const vs_module = setup.device.createShaderModule(&.{
|
||||
.next_in_chain = .{ .wgsl_descriptor = &.{
|
||||
.source = vs,
|
||||
} },
|
||||
.label = "my vertex shader",
|
||||
});
|
||||
const vs_module = setup.device.createShaderModuleWGSL("my vertex shader", vs);
|
||||
|
||||
const fs =
|
||||
\\ @fragment fn main() -> @location(0) vec4<f32> {
|
||||
\\ return vec4<f32>(1.0, 0.0, 0.0, 1.0);
|
||||
\\ }
|
||||
;
|
||||
const fs_module = setup.device.createShaderModule(&.{
|
||||
.next_in_chain = .{ .wgsl_descriptor = &.{
|
||||
.source = fs,
|
||||
} },
|
||||
.label = "my fragment shader",
|
||||
});
|
||||
const fs_module = setup.device.createShaderModuleWGSL("my fragment shader", fs);
|
||||
|
||||
// Fragment state
|
||||
const blend = gpu.BlendState{
|
||||
|
|
|
|||
|
|
@ -194,6 +194,20 @@ pub const Device = opaque {
|
|||
return Impl.deviceCreateShaderModule(device, descriptor);
|
||||
}
|
||||
|
||||
/// Helper to make createShaderModule invocations slightly nicer.
|
||||
pub inline fn createShaderModuleWGSL(
|
||||
device: *Device,
|
||||
label: ?[*:0]const u8,
|
||||
wgsl_source: [*:0]const u8,
|
||||
) *ShaderModule {
|
||||
return device.createShaderModule(&ShaderModule.Descriptor{
|
||||
.next_in_chain = .{ .wgsl_descriptor = &.{
|
||||
.source = wgsl_source,
|
||||
} },
|
||||
.label = label,
|
||||
});
|
||||
}
|
||||
|
||||
pub inline fn createSwapChain(device: *Device, surface: ?*Surface, descriptor: *const SwapChain.Descriptor) *SwapChain {
|
||||
return Impl.deviceCreateSwapChain(device, surface, descriptor);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue