gpu-dawn: cleanup hello_triangle example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
ef2288309e
commit
412023ef1e
2 changed files with 7 additions and 146 deletions
|
|
@ -3,14 +3,6 @@ const sample_utils = @import("sample_utils.zig");
|
||||||
const c = @import("c.zig").c;
|
const c = @import("c.zig").c;
|
||||||
const glfw = @import("glfw");
|
const glfw = @import("glfw");
|
||||||
|
|
||||||
// #include "utils/SystemUtils.h"
|
|
||||||
// #include "utils/WGPUHelpers.h"
|
|
||||||
|
|
||||||
// WGPUSwapChain swapchain;
|
|
||||||
// WGPURenderPipeline pipeline;
|
|
||||||
|
|
||||||
// WGPUTextureFormat swapChainFormat;
|
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
var allocator = gpa.allocator();
|
var allocator = gpa.allocator();
|
||||||
|
|
@ -26,9 +18,9 @@ pub fn main() !void {
|
||||||
c.wgpuSwapChainConfigure(swap_chain, swap_chain_format, c.WGPUTextureUsage_RenderAttachment, 640, 480);
|
c.wgpuSwapChainConfigure(swap_chain, swap_chain_format, c.WGPUTextureUsage_RenderAttachment, 640, 480);
|
||||||
|
|
||||||
const vs =
|
const vs =
|
||||||
\\ [[stage(vertex)]] fn main(
|
\\ @stage(vertex) fn main(
|
||||||
\\ [[builtin(vertex_index)]] VertexIndex : u32
|
\\ @builtin(vertex_index) VertexIndex : u32
|
||||||
\\ ) -> [[builtin(position)]] vec4<f32> {
|
\\ ) -> @builtin(position) vec4<f32> {
|
||||||
\\ var pos = array<vec2<f32>, 3>(
|
\\ var pos = array<vec2<f32>, 3>(
|
||||||
\\ vec2<f32>( 0.0, 0.5),
|
\\ vec2<f32>( 0.0, 0.5),
|
||||||
\\ vec2<f32>(-0.5, -0.5),
|
\\ vec2<f32>(-0.5, -0.5),
|
||||||
|
|
@ -48,7 +40,7 @@ pub fn main() !void {
|
||||||
const vs_module = c.wgpuDeviceCreateShaderModule(setup.device, &vs_shader_descriptor);
|
const vs_module = c.wgpuDeviceCreateShaderModule(setup.device, &vs_shader_descriptor);
|
||||||
|
|
||||||
const fs =
|
const fs =
|
||||||
\\ [[stage(fragment)]] fn main() -> [[location(0)]] vec4<f32> {
|
\\ @stage(fragment) fn main() -> @location(0) vec4<f32> {
|
||||||
\\ return vec4<f32>(1.0, 0.0, 0.0, 1.0);
|
\\ return vec4<f32>(1.0, 0.0, 0.0, 1.0);
|
||||||
\\ }
|
\\ }
|
||||||
;
|
;
|
||||||
|
|
@ -168,11 +160,5 @@ fn frame(params: FrameParams) !void {
|
||||||
c.wgpuSwapChainPresent(params.swap_chain);
|
c.wgpuSwapChainPresent(params.swap_chain);
|
||||||
c.wgpuTextureViewRelease(back_buffer_view);
|
c.wgpuTextureViewRelease(back_buffer_view);
|
||||||
|
|
||||||
// if (cmdBufType == CmdBufType::Terrible) {
|
|
||||||
// bool c2sSuccess = c2sBuf->Flush();
|
|
||||||
// bool s2cSuccess = s2cBuf->Flush();
|
|
||||||
|
|
||||||
// ASSERT(c2sSuccess && s2cSuccess);
|
|
||||||
// }
|
|
||||||
try glfw.pollEvents();
|
try glfw.pollEvents();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,6 @@ const assert = std.debug.assert;
|
||||||
const glfw = @import("glfw");
|
const glfw = @import("glfw");
|
||||||
const c = @import("c.zig").c;
|
const c = @import("c.zig").c;
|
||||||
|
|
||||||
// #include "SampleUtils.h"
|
|
||||||
|
|
||||||
// #include "common/Assert.h"
|
|
||||||
// #include "common/Log.h"
|
|
||||||
// #include "common/Platform.h"
|
|
||||||
// #include "common/SystemUtils.h"
|
|
||||||
// #include "utils/BackendBinding.h"
|
|
||||||
// #include "utils/GLFWUtils.h"
|
|
||||||
// #include "utils/TerribleCommandBuffer.h"
|
|
||||||
|
|
||||||
// #include <dawn/dawn_proc.h>
|
|
||||||
// #include <dawn/dawn_wsi.h>
|
|
||||||
// #include <dawn_native/DawnNative.h>
|
|
||||||
// #include <dawn_wire/WireClient.h>
|
|
||||||
// #include <dawn_wire/WireServer.h>
|
|
||||||
// #include "GLFW/glfw3.h"
|
|
||||||
|
|
||||||
// #include <algorithm>
|
|
||||||
// #include <cstring>
|
|
||||||
|
|
||||||
fn printDeviceError(error_type: c.WGPUErrorType, message: [*c]const u8, _: ?*anyopaque) callconv(.C) void {
|
fn printDeviceError(error_type: c.WGPUErrorType, message: [*c]const u8, _: ?*anyopaque) callconv(.C) void {
|
||||||
switch (error_type) {
|
switch (error_type) {
|
||||||
c.WGPUErrorType_Validation => std.debug.print("dawn: validation error: {s}\n", .{message}),
|
c.WGPUErrorType_Validation => std.debug.print("dawn: validation error: {s}\n", .{message}),
|
||||||
|
|
@ -33,18 +13,6 @@ fn printDeviceError(error_type: c.WGPUErrorType, message: [*c]const u8, _: ?*any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CmdBufType = enum { none, terrible };
|
|
||||||
|
|
||||||
// static std::unique_ptr<dawn_native::Instance> instance;
|
|
||||||
// static utils::BackendBinding* binding = nullptr;
|
|
||||||
|
|
||||||
// static GLFWwindow* window = nullptr;
|
|
||||||
|
|
||||||
// static dawn_wire::WireServer* wireServer = nullptr;
|
|
||||||
// static dawn_wire::WireClient* wireClient = nullptr;
|
|
||||||
// static utils::TerribleCommandBuffer* c2sBuf = nullptr;
|
|
||||||
// static utils::TerribleCommandBuffer* s2cBuf = nullptr;
|
|
||||||
|
|
||||||
const Setup = struct {
|
const Setup = struct {
|
||||||
device: c.WGPUDevice,
|
device: c.WGPUDevice,
|
||||||
binding: c.MachUtilsBackendBinding,
|
binding: c.MachUtilsBackendBinding,
|
||||||
|
|
@ -93,7 +61,6 @@ fn backendTypeString(t: c.WGPUBackendType) []const u8 {
|
||||||
|
|
||||||
pub fn setup(allocator: std.mem.Allocator) !Setup {
|
pub fn setup(allocator: std.mem.Allocator) !Setup {
|
||||||
const backend_type = try detectBackendType(allocator);
|
const backend_type = try detectBackendType(allocator);
|
||||||
const cmd_buf_type = CmdBufType.none;
|
|
||||||
|
|
||||||
try glfw.init(.{});
|
try glfw.init(.{});
|
||||||
|
|
||||||
|
|
@ -128,46 +95,10 @@ pub fn setup(allocator: std.mem.Allocator) !Setup {
|
||||||
@panic("failed to create binding");
|
@panic("failed to create binding");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Choose whether to use the backend procs and devices directly, or set up the wire.
|
c.dawnProcSetProcs(backend_procs);
|
||||||
var procs: ?*const c.DawnProcTable = null;
|
backend_procs.*.deviceSetUncapturedErrorCallback.?(backend_device, printDeviceError, null);
|
||||||
var c_device: ?c.WGPUDevice = null;
|
|
||||||
switch (cmd_buf_type) {
|
|
||||||
CmdBufType.none => {
|
|
||||||
procs = backend_procs;
|
|
||||||
c_device = backend_device;
|
|
||||||
},
|
|
||||||
CmdBufType.terrible => {
|
|
||||||
// TODO(slimsag):
|
|
||||||
@panic("not implemented");
|
|
||||||
// c2sBuf = new utils::TerribleCommandBuffer();
|
|
||||||
// s2cBuf = new utils::TerribleCommandBuffer();
|
|
||||||
|
|
||||||
// dawn_wire::WireServerDescriptor serverDesc = {};
|
|
||||||
// serverDesc.procs = &backendProcs;
|
|
||||||
// serverDesc.serializer = s2cBuf;
|
|
||||||
|
|
||||||
// wireServer = new dawn_wire::WireServer(serverDesc);
|
|
||||||
// c2sBuf->SetHandler(wireServer);
|
|
||||||
|
|
||||||
// dawn_wire::WireClientDescriptor clientDesc = {};
|
|
||||||
// clientDesc.serializer = c2sBuf;
|
|
||||||
|
|
||||||
// wireClient = new dawn_wire::WireClient(clientDesc);
|
|
||||||
// procs = dawn_wire::client::GetProcs();
|
|
||||||
// s2cBuf->SetHandler(wireClient);
|
|
||||||
|
|
||||||
// auto deviceReservation = wireClient->ReserveDevice();
|
|
||||||
// wireServer->InjectDevice(backendDevice, deviceReservation.id,
|
|
||||||
// deviceReservation.generation);
|
|
||||||
|
|
||||||
// cDevice = deviceReservation.device;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
c.dawnProcSetProcs(procs.?);
|
|
||||||
procs.?.deviceSetUncapturedErrorCallback.?(c_device.?, printDeviceError, null);
|
|
||||||
return Setup{
|
return Setup{
|
||||||
.device = c_device.?,
|
.device = backend_device,
|
||||||
.binding = binding,
|
.binding = binding,
|
||||||
.window = window,
|
.window = window,
|
||||||
};
|
};
|
||||||
|
|
@ -233,59 +164,3 @@ fn discoverAdapter(instance: c.MachDawnNativeInstance, window: glfw.Window, typ:
|
||||||
// auto depthStencilTexture = device.CreateTexture(&descriptor);
|
// auto depthStencilTexture = device.CreateTexture(&descriptor);
|
||||||
// return depthStencilTexture.CreateView();
|
// return depthStencilTexture.CreateView();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// bool InitSample(int argc, const char** argv) {
|
|
||||||
// for (int i = 1; i < argc; i++) {
|
|
||||||
// if (std::string("-b") == argv[i] || std::string("--backend") == argv[i]) {
|
|
||||||
// i++;
|
|
||||||
// if (i < argc && std::string("d3d12") == argv[i]) {
|
|
||||||
// backendType = wgpu::BackendType::D3D12;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// if (i < argc && std::string("metal") == argv[i]) {
|
|
||||||
// backendType = wgpu::BackendType::Metal;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// if (i < argc && std::string("null") == argv[i]) {
|
|
||||||
// backendType = wgpu::BackendType::Null;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// if (i < argc && std::string("opengl") == argv[i]) {
|
|
||||||
// backendType = wgpu::BackendType::OpenGL;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// if (i < argc && std::string("opengles") == argv[i]) {
|
|
||||||
// backendType = wgpu::BackendType::OpenGLES;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// if (i < argc && std::string("vulkan") == argv[i]) {
|
|
||||||
// backendType = wgpu::BackendType::Vulkan;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// fprintf(stderr,
|
|
||||||
// "--backend expects a backend name (opengl, opengles, metal, d3d12, null, "
|
|
||||||
// "vulkan)\n");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// if (std::string("-c") == argv[i] || std::string("--command-buffer") == argv[i]) {
|
|
||||||
// i++;
|
|
||||||
// if (i < argc && std::string("none") == argv[i]) {
|
|
||||||
// cmdBufType = CmdBufType::None;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// if (i < argc && std::string("terrible") == argv[i]) {
|
|
||||||
// cmdBufType = CmdBufType::Terrible;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// fprintf(stderr, "--command-buffer expects a command buffer name (none, terrible)\n");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// if (std::string("-h") == argv[i] || std::string("--help") == argv[i]) {
|
|
||||||
// printf("Usage: %s [-b BACKEND] [-c COMMAND_BUFFER]\n", argv[0]);
|
|
||||||
// printf(" BACKEND is one of: d3d12, metal, null, opengl, opengles, vulkan\n");
|
|
||||||
// printf(" COMMAND_BUFFER is one of: none, terrible\n");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue