Skip to content

Commit

Permalink
feat(debug_shader): use to instance flags
Browse files Browse the repository at this point in the history
  • Loading branch information
wicast committed Oct 20, 2023
1 parent ae90d7e commit dbe5c82
Show file tree
Hide file tree
Showing 28 changed files with 17 additions and 57 deletions.
1 change: 0 additions & 1 deletion deno_webgpu/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub fn op_webgpu_create_shader_module(
let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor {
label: Some(label),
shader_bound_checks: wgpu_types::ShaderBoundChecks::default(),
debug: false,
};

gfx_put!(device => instance.device_create_shader_module(
Expand Down
2 changes: 0 additions & 2 deletions examples/boids/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ impl wgpu_example::framework::Example for Example {
let compute_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("compute.wgsl"))),
debug: false,
});
let draw_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("draw.wgsl"))),
debug: false,
});

// buffer for simulation parameters uniform
Expand Down
1 change: 0 additions & 1 deletion examples/bunnymark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl wgpu_example::framework::Example for Example {
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!(
"../../../wgpu-hal/examples/halmark/shader.wgsl"
))),
debug: false,
});

let global_bind_group_layout =
Expand Down
2 changes: 0 additions & 2 deletions examples/conservative-raster/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ impl wgpu_example::framework::Example for Example {
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!(
"triangle_and_lines.wgsl"
))),
debug: false,
});

let pipeline_triangle_conservative =
Expand Down Expand Up @@ -198,7 +197,6 @@ impl wgpu_example::framework::Example for Example {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("upscale.wgsl"))),
debug: false,
});
(
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
Expand Down
1 change: 0 additions & 1 deletion examples/cube/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ impl wgpu_example::framework::Example for Example {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
debug: false,
});

let vertex_buffers = [wgpu::VertexBufferLayout {
Expand Down
1 change: 0 additions & 1 deletion examples/hello-compute/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ async fn execute_gpu_inner(
let cs_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
debug: false,
});

// Gets the size in bytes of the buffer.
Expand Down
1 change: 0 additions & 1 deletion examples/hello-triangle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
debug: false,
});

let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
Expand Down
2 changes: 0 additions & 2 deletions examples/mipmap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ impl Example {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("blit.wgsl"))),
debug: false,
});

let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
Expand Down Expand Up @@ -283,7 +282,6 @@ impl wgpu_example::framework::Example for Example {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("draw.wgsl"))),
debug: false,
});

let draw_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
Expand Down
1 change: 0 additions & 1 deletion examples/msaa-line/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ impl wgpu_example::framework::Example for Example {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
debug: false,
});

let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
Expand Down
1 change: 0 additions & 1 deletion examples/shadow/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ impl wgpu_example::framework::Example for Example {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
debug: false,
});

let shadow_pass = {
Expand Down
1 change: 0 additions & 1 deletion examples/skybox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ impl wgpu_example::framework::Example for Example {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
debug: false,
});

let camera = Camera {
Expand Down
1 change: 0 additions & 1 deletion examples/stencil-triangles/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ impl wgpu_example::framework::Example for Example {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
debug: false,
});

let vertex_buffers = [wgpu::VertexBufferLayout {
Expand Down
1 change: 0 additions & 1 deletion examples/timestamp-queries/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ fn submit_render_and_compute_pass_with_queries(
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!("shader.wgsl"))),
debug: false,
});

encoder.write_timestamp(&queries.set, queries.next_unused_query);
Expand Down
2 changes: 0 additions & 2 deletions examples/water/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,10 @@ impl wgpu_example::framework::Example for Example {
let terrain_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("terrain"),
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("terrain.wgsl"))),
debug: false,
});
let water_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("water"),
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("water.wgsl"))),
debug: false,
});

// Create the render pipelines. These describe how the data will flow through the GPU, and what
Expand Down
3 changes: 1 addition & 2 deletions player/tests/data/bind-group.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
id: Id(0, 1, Empty),
desc: (
label: None,
flags: (bits: 3),
debug: false,
flags: (bits: 3)
),
data: "empty.wgsl",
),
Expand Down
1 change: 0 additions & 1 deletion player/tests/data/pipeline-statistics-query.ron
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
desc: (
label: None,
flags: (bits: 3),
debug: false,
),
data: "empty.wgsl",
),
Expand Down
1 change: 0 additions & 1 deletion player/tests/data/quad.ron
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
desc: (
label: None,
flags: (bits: 3),
debug: false,
),
data: "quad.wgsl",
),
Expand Down
1 change: 0 additions & 1 deletion player/tests/data/zero-init-buffer.ron
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
desc: (
label: None,
flags: (bits: 3),
debug: false,
),
data: "zero-init-buffer-for-binding.wgsl",
),
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/zero-init-texture-binding.ron
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
desc: (
label: None,
flags: (bits: 3),
debug: false,

),
data: "zero-init-texture-binding.wgsl",
),
Expand Down
1 change: 0 additions & 1 deletion tests/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ fn copy_via_compute(
let sm = device.create_shader_module(ShaderModuleDescriptor {
label: Some("shader copy_texture_to_buffer.wgsl"),
source: ShaderSource::Wgsl(Cow::Borrowed(&processed_source)),
debug: false,
});

let pipeline_copy = device.create_compute_pipeline(&ComputePipelineDescriptor {
Expand Down
1 change: 0 additions & 1 deletion tests/tests/occlusion_query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new()
.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader module"),
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
debug: false,
});
let pipeline = ctx
.device
Expand Down
1 change: 0 additions & 1 deletion tests/tests/shader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ fn shader_input_output_test(
let sm = ctx.device.create_shader_module(ShaderModuleDescriptor {
label: Some(&format!("shader {test_name}")),
source: ShaderSource::Wgsl(Cow::Borrowed(&processed)),
debug: false,
});

let pipeline = ctx
Expand Down
11 changes: 4 additions & 7 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use hal::{CommandEncoder as _, Device as _};
use parking_lot::{Mutex, MutexGuard};
use smallvec::SmallVec;
use thiserror::Error;
use wgt::{TextureFormat, TextureSampleType, TextureViewDimension};
use wgt::{InstanceFlags, TextureFormat, TextureSampleType, TextureViewDimension};

use std::{borrow::Cow, iter, num::NonZeroU32};

Expand Down Expand Up @@ -1317,7 +1317,7 @@ impl<A: HalApi> Device<A> {
.contains(wgt::DownlevelFlags::CUBE_ARRAY_TEXTURES),
);

let debug_source = if desc.debug {
let debug_source = if self.instance_flags.contains(InstanceFlags::DEBUG) {
Some(hal::DebugSource {
file_name: Cow::Owned(
desc.label
Expand All @@ -1339,17 +1339,14 @@ impl<A: HalApi> Device<A> {
inner: Box::new(inner),
})
})?;
let interface = validation::Interface::new(&module, &info, self.limits.clone());

let interface =
validation::Interface::new(&module, &info, self.limits.clone(), self.features);
let hal_shader = hal::ShaderInput::Naga(hal::NagaShader {
module,
info,
debug_source,
});
let interface =
validation::Interface::new(&module, &info, self.limits.clone(), self.features);
let hal_shader = hal::ShaderInput::Naga(hal::NagaShader { module, info });

let hal_desc = hal::ShaderModuleDescriptor {
label: desc.label.to_hal(self.instance_flags),
runtime_checks: desc.shader_bound_checks.runtime_checks(),
Expand Down
3 changes: 1 addition & 2 deletions wgpu-core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ pub enum ShaderModuleSource<'a> {
pub struct ShaderModuleDescriptor<'a> {
pub label: Label<'a>,
#[cfg_attr(feature = "serde", serde(default))]
pub shader_bound_checks: wgt::ShaderBoundChecks,
pub debug: bool,
pub shader_bound_checks: wgt::ShaderBoundChecks
}

#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ impl super::Device {
if let Some(ref debug) = naga_shader.debug_source {
temp_options.debug_info = Some(naga::back::spv::DebugInfo {
source_code: &debug.source_code,
file_name: &debug.file_name,
file_name: debug.file_name.as_ref().as_ref(),
})
}

Expand Down Expand Up @@ -1529,7 +1529,7 @@ impl crate::Device<super::Api> for super::Device {
.as_ref()
.map(|d| naga::back::spv::DebugInfo {
source_code: d.source_code.as_ref(),
file_name: d.file_name.as_ref(),
file_name: d.file_name.as_ref().as_ref(),
});
if !desc.runtime_checks {
naga_options.bounds_check_policies = naga::proc::BoundsCheckPolicies {
Expand Down
2 changes: 0 additions & 2 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,6 @@ impl crate::Context for Context {
let descriptor = wgc::pipeline::ShaderModuleDescriptor {
label: desc.label.map(Borrowed),
shader_bound_checks,
debug: desc.debug,
};
let source = match desc.source {
#[cfg(feature = "spirv")]
Expand Down Expand Up @@ -959,7 +958,6 @@ impl crate::Context for Context {
// Doesn't matter the value since spirv shaders aren't mutated to include
// runtime checks
shader_bound_checks: unsafe { wgt::ShaderBoundChecks::unchecked() },
debug: false,
};
let (id, error) = wgc::gfx_select!(
device => global.device_create_shader_module_spirv(*device, &descriptor, Borrowed(&desc.source), ())
Expand Down
2 changes: 0 additions & 2 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,6 @@ pub struct ShaderModuleDescriptor<'a> {
pub label: Label<'a>,
/// Source code for the shader.
pub source: ShaderSource<'a>,
/// Generate debug symbols, only available in spv-out
pub debug: bool,
}
static_assertions::assert_impl_all!(ShaderModuleDescriptor: Send, Sync);

Expand Down
23 changes: 8 additions & 15 deletions wgpu/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,13 @@ macro_rules! include_spirv_raw {
/// Macro to load a WGSL module statically.
#[macro_export]
macro_rules! include_wgsl {
($name:tt) => {{
// log::info!("including '{}'", $name);
$crate::ShaderModuleDescriptor {
label: Some($name),
source: $crate::ShaderSource::Wgsl(include_str!($name).into()),
debug: false,
}
}};
($name:tt, $debug:tt) => {{
// log::info!("including '{}', '{}'", $name, $debug);
$crate::ShaderModuleDescriptor {
label: Some($name),
source: $crate::ShaderSource::Wgsl(include_str!($name).into()),
debug: $debug,
($($token:tt)*) => {
{
//log::info!("including '{}'", $($token)*);
$crate::ShaderModuleDescriptor {
label: Some($($token)*),
source: $crate::ShaderSource::Wgsl(include_str!($($token)*).into()),
}
}
}};
};
}

0 comments on commit dbe5c82

Please sign in to comment.