summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock140
-rw-r--r--devenv.nix2
-rw-r--r--games/00_triangle/Cargo.toml3
-rw-r--r--games/00_triangle/src/main.rs54
-rw-r--r--games/00_triangle/src/shader.wgsl19
5 files changed, 76 insertions, 142 deletions
diff --git a/Cargo.lock b/Cargo.lock
index cf75049..59301ad 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,22 +3,6 @@
version = 4
[[package]]
-name = "ab_glyph"
-version = "0.2.32"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "01c0457472c38ea5bd1c3b5ada5e368271cb550be7a4ca4a0b4634e9913f6cc2"
-dependencies = [
- "ab_glyph_rasterizer",
- "owned_ttf_parser",
-]
-
-[[package]]
-name = "ab_glyph_rasterizer"
-version = "0.1.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618"
-
-[[package]]
name = "ahash"
version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -88,24 +72,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902"
[[package]]
-name = "arrayref"
-version = "0.3.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
-
-[[package]]
name = "arrayvec"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
[[package]]
-name = "as-raw-xcb-connection"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b"
-
-[[package]]
name = "ash"
version = "0.38.0+1.3.281"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -480,16 +452,6 @@ dependencies = [
]
[[package]]
-name = "gethostname"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"
-dependencies = [
- "rustix 1.1.6",
- "windows-link",
-]
-
-[[package]]
name = "getrandom"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1212,15 +1174,6 @@ dependencies = [
]
[[package]]
-name = "owned_ttf_parser"
-version = "0.25.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "36820e9051aca1014ddc75770aab4d68bc1e9e632f0f5627c4086bc216fb583b"
-dependencies = [
- "ttf-parser",
-]
-
-[[package]]
name = "parking_lot"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1244,12 +1197,6 @@ dependencies = [
]
[[package]]
-name = "percent-encoding"
-version = "2.3.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
-
-[[package]]
name = "pin-project"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1531,19 +1478,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
-name = "sctk-adwaita"
-version = "0.10.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec"
-dependencies = [
- "ab_glyph",
- "log",
- "memmap2",
- "smithay-client-toolkit",
- "tiny-skia",
-]
-
-[[package]]
name = "semver"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1672,12 +1606,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
-name = "strict-num"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
-
-[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1749,31 +1677,6 @@ dependencies = [
]
[[package]]
-name = "tiny-skia"
-version = "0.11.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab"
-dependencies = [
- "arrayref",
- "arrayvec",
- "bytemuck",
- "cfg-if",
- "log",
- "tiny-skia-path",
-]
-
-[[package]]
-name = "tiny-skia-path"
-version = "0.11.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93"
-dependencies = [
- "arrayref",
- "bytemuck",
- "strict-num",
-]
-
-[[package]]
name = "tokio"
version = "1.54.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1829,12 +1732,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
[[package]]
-name = "ttf-parser"
-version = "0.25.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
-
-[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2446,7 +2343,6 @@ dependencies = [
"atomic-waker",
"bitflags 2.13.2",
"block2 0.5.1",
- "bytemuck",
"calloop",
"cfg_aliases",
"concurrent-queue",
@@ -2463,12 +2359,10 @@ dependencies = [
"objc2-foundation 0.2.2",
"objc2-ui-kit",
"orbclient",
- "percent-encoding",
"pin-project",
"raw-window-handle",
"redox_syscall 0.4.1",
"rustix 0.38.44",
- "sctk-adwaita",
"smithay-client-toolkit",
"smol_str",
"tracing",
@@ -2482,8 +2376,6 @@ dependencies = [
"web-sys",
"web-time",
"windows-sys 0.52.0",
- "x11-dl",
- "x11rb",
"xkbcommon-dl",
]
@@ -2497,38 +2389,6 @@ dependencies = [
]
[[package]]
-name = "x11-dl"
-version = "2.21.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "38735924fedd5314a6e548792904ed8c6de6636285cb9fec04d5b1db85c1516f"
-dependencies = [
- "libc",
- "once_cell",
- "pkg-config",
-]
-
-[[package]]
-name = "x11rb"
-version = "0.13.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9993aa5be5a26815fe2c3eacfc1fde061fc1a1f094bf1ad2a18bf9c495dd7414"
-dependencies = [
- "as-raw-xcb-connection",
- "gethostname",
- "libc",
- "libloading",
- "once_cell",
- "rustix 1.1.6",
- "x11rb-protocol",
-]
-
-[[package]]
-name = "x11rb-protocol"
-version = "0.13.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd"
-
-[[package]]
name = "xcursor"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/devenv.nix b/devenv.nix
index c5a39e4..fab80f9 100644
--- a/devenv.nix
+++ b/devenv.nix
@@ -11,6 +11,8 @@
# https://devenv.sh/packages/
packages = with pkgs; [
bacon
+ wgsl-analyzer
+
wayland
libxkbcommon
vulkan-loader
diff --git a/games/00_triangle/Cargo.toml b/games/00_triangle/Cargo.toml
index 6e183e5..646903a 100644
--- a/games/00_triangle/Cargo.toml
+++ b/games/00_triangle/Cargo.toml
@@ -5,7 +5,8 @@ edition = "2024"
[dependencies]
anyhow = "1.0"
-winit = { version = "0.30", features = ["android-native-activity"] }
+# winit = { version = "0.30", features = ["android-native-activity"] }
+winit = { version = "0.30", default-features = false, features = ["wayland", "rwh_06"] }
env_logger = "0.10"
log = "0.4"
wgpu = "30.0"
diff --git a/games/00_triangle/src/main.rs b/games/00_triangle/src/main.rs
index fd4a166..e9de614 100644
--- a/games/00_triangle/src/main.rs
+++ b/games/00_triangle/src/main.rs
@@ -15,6 +15,7 @@ pub struct State {
config: wgpu::SurfaceConfiguration,
is_surface_configured: bool,
window: Arc<Window>,
+ render_pipeline: wgpu::RenderPipeline,
}
impl State {
@@ -70,12 +71,60 @@ impl State {
color_space: wgpu::SurfaceColorSpace::Auto,
};
+ let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));
+
+ let render_pipeline_layout =
+ device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: Some("Render Pipeline Layout"),
+ bind_group_layouts: &[],
+ immediate_size: 0,
+ });
+
+ let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
+ label: Some("Render Pipeline"),
+ layout: Some(&render_pipeline_layout),
+ vertex: wgpu::VertexState {
+ module: &shader,
+ entry_point: Some("vs_main"),
+ buffers: &[],
+ compilation_options: wgpu::PipelineCompilationOptions::default(),
+ },
+ fragment: Some(wgpu::FragmentState {
+ module: &shader,
+ entry_point: Some("fs_main"),
+ targets: &[Some(wgpu::ColorTargetState {
+ format: config.format,
+ blend: Some(wgpu::BlendState::REPLACE),
+ write_mask: wgpu::ColorWrites::ALL,
+ })],
+ compilation_options: wgpu::PipelineCompilationOptions::default(),
+ }),
+ primitive: wgpu::PrimitiveState {
+ topology: wgpu::PrimitiveTopology::TriangleList,
+ strip_index_format: None,
+ front_face: wgpu::FrontFace::Ccw,
+ cull_mode: Some(wgpu::Face::Back),
+ polygon_mode: wgpu::PolygonMode::Fill,
+ unclipped_depth: false,
+ conservative: false,
+ },
+ depth_stencil: None,
+ multisample: wgpu::MultisampleState {
+ count: 1,
+ mask: !0,
+ alpha_to_coverage_enabled: false,
+ },
+ multiview_mask: None,
+ cache: None,
+ });
+
Ok(Self {
surface,
device,
queue,
config,
is_surface_configured: false,
+ render_pipeline,
window,
})
}
@@ -132,7 +181,7 @@ impl State {
});
{
- let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
+ let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
@@ -153,6 +202,9 @@ impl State {
timestamp_writes: None,
multiview_mask: None,
});
+
+ render_pass.set_pipeline(&self.render_pipeline);
+ render_pass.draw(0..3, 0..1);
}
self.queue.submit(std::iter::once(encoder.finish()));
diff --git a/games/00_triangle/src/shader.wgsl b/games/00_triangle/src/shader.wgsl
new file mode 100644
index 0000000..9ff0e3f
--- /dev/null
+++ b/games/00_triangle/src/shader.wgsl
@@ -0,0 +1,19 @@
+// Vertex shader
+
+struct VertexOutput {
+ @builtin(position) clip_position : vec4<f32>,
+};
+
+@vertex fn vs_main(@builtin(vertex_index) in_vertex_index : u32, )
+ -> VertexOutput {
+ var out : VertexOutput;
+ let x = f32(1 - i32(in_vertex_index)) * 0.5;
+ let y = f32(i32(in_vertex_index & 1u) * 2 - 1) * 0.5;
+ out.clip_position = vec4<f32>(x, y, 0.0, 1.0);
+ return out;
+}
+
+// Fragment shader
+@fragment fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
+ return vec4<f32>(0.3, 0.2, 0.1, 1.0);
+}