Skip to content

Commit

Permalink
Move texture-array example over to wgsl (#2618)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald authored Apr 25, 2022
1 parent bc850d2 commit e54a36e
Show file tree
Hide file tree
Showing 32 changed files with 539 additions and 364 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions deno_webgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
) {
return_features.push("uniform-buffer-and-storage-buffer-texture-non-uniform-indexing");
}
if features.contains(wgpu_types::Features::UNSIZED_BINDING_ARRAY) {
return_features.push("unsized-binding-array");
}
if features.contains(wgpu_types::Features::ADDRESS_MODE_CLAMP_TO_BORDER) {
return_features.push("address-mode-clamp-to-border");
}
Expand Down Expand Up @@ -341,10 +338,6 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
.0
.contains("uniform-buffer-and-storage-buffer-texture-non-uniform-indexing"),
);
features.set(
wgpu_types::Features::UNSIZED_BINDING_ARRAY,
required_features.0.contains("unsized-binding-array"),
);
features.set(
wgpu_types::Features::ADDRESS_MODE_CLAMP_TO_BORDER,
required_features.0.contains("address-mode-clamp-to-border"),
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/clear-buffer-texture.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0000_0020_0000_0000,
features: 0x0000_0010_0000_0000,
expectations: [
(
name: "Quad",
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ thiserror = "1"

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "85056524"
rev = "1aa91549"
#version = "0.8"
features = ["span", "validate", "wgsl-in"]

Expand Down
19 changes: 19 additions & 0 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,25 @@ impl<A: HalApi> Device<A> {
self.features
.contains(wgt::Features::SHADER_PRIMITIVE_INDEX),
);
caps.set(
Caps::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
self.features.contains(
wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
),
);
caps.set(
Caps::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
self.features.contains(
wgt::Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
),
);
// TODO: This needs a proper wgpu feature
caps.set(
Caps::SAMPLER_NON_UNIFORM_INDEXING,
self.features.contains(
wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
),
);
let info = naga::valid::Validator::new(naga::valid::ValidationFlags::all(), caps)
.validate(&module)
.map_err(|inner| {
Expand Down
9 changes: 8 additions & 1 deletion wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,14 @@ impl Interface {
Some(ref br) => br.clone(),
_ => continue,
};
let ty = match module.types[var.ty].inner {
let naga_ty = &module.types[var.ty].inner;

let inner_ty = match *naga_ty {
naga::TypeInner::BindingArray { base, .. } => &module.types[base].inner,
ref ty => ty,
};

let ty = match *inner_ty {
naga::TypeInner::Image {
dim,
arrayed,
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ js-sys = { version = "0.3" }

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "85056524"
rev = "1aa91549"
#version = "0.8"

# DEV dependencies

[dev-dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "85056524"
rev = "1aa91549"
#version = "0.8"
features = ["wgsl-in"]

Expand Down
34 changes: 21 additions & 13 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ impl super::Adapter {
)
});

let mut shader_model_support: d3d12::D3D12_FEATURE_DATA_SHADER_MODEL =
d3d12::D3D12_FEATURE_DATA_SHADER_MODEL {
HighestShaderModel: d3d12::D3D_SHADER_MODEL_6_0,
};
assert_eq!(0, unsafe {
device.CheckFeatureSupport(
d3d12::D3D12_FEATURE_SHADER_MODEL,
&mut shader_model_support as *mut _ as *mut _,
mem::size_of::<d3d12::D3D12_FEATURE_DATA_SHADER_MODEL>() as _,
)
});

let mut workarounds = super::Workarounds::default();

let info = wgt::AdapterInfo {
Expand Down Expand Up @@ -175,11 +187,6 @@ impl super::Adapter {
| wgt::Features::DEPTH_CLIP_CONTROL
| wgt::Features::INDIRECT_FIRST_INSTANCE
| wgt::Features::MAPPABLE_PRIMARY_BUFFERS
//TODO: Naga part
//| wgt::Features::TEXTURE_BINDING_ARRAY
//| wgt::Features::BUFFER_BINDING_ARRAY
//| wgt::Features::STORAGE_RESOURCE_BINDING_ARRAY
//| wgt::Features::UNSIZED_BINDING_ARRAY
| wgt::Features::MULTI_DRAW_INDIRECT
| wgt::Features::MULTI_DRAW_INDIRECT_COUNT
| wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER
Expand All @@ -204,6 +211,13 @@ impl super::Adapter {
!= d3d12::D3D12_CONSERVATIVE_RASTERIZATION_TIER_NOT_SUPPORTED,
);

features.set(
wgt::Features::TEXTURE_BINDING_ARRAY
| wgt::Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING
| wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
shader_model_support.HighestShaderModel >= d3d12::D3D_SHADER_MODEL_5_1,
);

let base = wgt::Limits::default();

Some(crate::ExposedAdapter {
Expand Down Expand Up @@ -282,7 +296,7 @@ impl super::Adapter {
impl crate::Adapter<super::Api> for super::Adapter {
unsafe fn open(
&self,
features: wgt::Features,
_features: wgt::Features,
_limits: &wgt::Limits,
) -> Result<crate::OpenDevice<super::Api>, crate::DeviceError> {
let queue = {
Expand All @@ -297,13 +311,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
.into_device_result("Queue creation")?
};

let device = super::Device::new(
self.device,
queue,
features,
self.private_caps,
&self.library,
)?;
let device = super::Device::new(self.device, queue, self.private_caps, &self.library)?;
Ok(crate::OpenDevice {
device,
queue: super::Queue {
Expand Down
Loading

0 comments on commit e54a36e

Please sign in to comment.