From 642c7ffd00b42c4ec93e436806004249051b13ee Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Sat, 11 Jul 2020 19:01:48 -0700 Subject: [PATCH] Switch shader texture usage from sampler2D to texture2D plus sampler (fixes #1) --- .vscode/launch.json | 7 +++++-- Cargo.lock | 49 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 +++++- shaders/shader.frag | 6 ++++-- shaders/shader.vert | 2 +- src/gui_node.rs | 1 + src/main.rs | 4 ++++ src/pipeline.rs | 1 + 8 files changed, 70 insertions(+), 6 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 860b867e..7ad2b8e8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,7 +7,7 @@ { "type": "lldb", "request": "launch", - "name": "Debug executable 'graphite'", + "name": "Graphite debug executable", "cargo": { "args": [ "build", @@ -20,7 +20,10 @@ } }, "args": [], - "cwd": "${workspaceFolder}" + "cwd": "${workspaceFolder}", + "env": { + "RUST_LOG": "error" + } }, { "type": "lldb", diff --git a/Cargo.lock b/Cargo.lock index 4a1d6d8b..033562f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -80,6 +80,17 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c86699c3f02778ec07158376991c8f783dd1f2f95c579ffaf0738dc984b2fe2" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.8", +] + [[package]] name = "autocfg" version = "0.1.7" @@ -436,6 +447,19 @@ version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "failure" version = "0.1.8" @@ -799,6 +823,7 @@ dependencies = [ "bytemuck", "cgmath", "css-color-parser", + "env_logger", "failure", "futures", "glsl-to-spirv", @@ -829,6 +854,15 @@ dependencies = [ "atom", ] +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "image" version = "0.22.5" @@ -1384,6 +1418,12 @@ dependencies = [ "unicode-xid 0.2.0", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "0.6.13" @@ -1816,6 +1856,15 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "termcolor" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +dependencies = [ + "winapi-util", +] + [[package]] name = "thread_local" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index 909bd470..e7fba78e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,4 +19,8 @@ bytemuck = "1.2.0" rctree = "0.3.3" xmlparser = "0.13.1" regex = "1.3.7" -css-color-parser = "0.1.2" \ No newline at end of file +css-color-parser = "0.1.2" +env_logger = { version = "0.7.1", optional = true } + +[features] +debug = ["env_logger"] diff --git a/shaders/shader.frag b/shaders/shader.frag index 329fc409..e3437658 100644 --- a/shaders/shader.frag +++ b/shaders/shader.frag @@ -16,8 +16,10 @@ layout(set=0, binding=0) uniform GuiNodeUniform { vec4 border_color; vec4 fill_color; }; -layout(set=0, binding=1) uniform sampler2D t_texture; + +layout(set=0, binding=1) uniform texture2D t_texture; +layout(set=0, binding=2) uniform sampler s_texture; void main() { - f_color = fill_color * texture(t_texture, v_uv / textureSize(t_texture, 0) * 100); + f_color = fill_color * texture(sampler2D(t_texture, s_texture), v_uv / textureSize(sampler2D(t_texture, s_texture), 0) * 500); } diff --git a/shaders/shader.vert b/shaders/shader.vert index 06ede5f9..f4a13ced 100644 --- a/shaders/shader.vert +++ b/shaders/shader.vert @@ -5,6 +5,6 @@ layout(location=0) in vec2 a_position; layout(location=0) out vec2 v_uv; void main() { - v_uv = a_position; + v_uv = (a_position + 1) / 2; gl_Position = vec4(a_position, 0.0, 1.0); } \ No newline at end of file diff --git a/src/gui_node.rs b/src/gui_node.rs index bc0bd03f..b52f7688 100644 --- a/src/gui_node.rs +++ b/src/gui_node.rs @@ -60,6 +60,7 @@ impl GuiNode { let bind_group = Pipeline::build_bind_group(device, &pipeline.bind_group_layout, vec![ Pipeline::build_binding_resource(&binding_staging_buffer), wgpu::BindingResource::TextureView(&texture.texture_view), + wgpu::BindingResource::Sampler(&texture.sampler), ]); vec![ diff --git a/src/main.rs b/src/main.rs index 4791f43d..13dc69e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,10 @@ use winit::event_loop::EventLoop; use winit::window::WindowBuilder; fn main() { + // Display graphics API errors (requires Vulkan SDK is installed) + #[cfg(feature = "debug")] + env_logger::init(); + // Handles all window events, user input, and redraws let event_loop = EventLoop::new(); diff --git a/src/pipeline.rs b/src/pipeline.rs index 5d5599fe..9b355a93 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -20,6 +20,7 @@ impl Pipeline { component_type: wgpu::TextureComponentType::Float, multisampled: false, }, + wgpu::BindingType::Sampler { comparison: false }, ]); // Combine all bind group layouts