Skip to content

Commit 8e01882

Browse files
committed
Evolve depth clamping into clip control
1 parent cf2fb0b commit 8e01882

File tree

19 files changed

+126
-148
lines changed

19 files changed

+126
-148
lines changed

deno_webgpu/src/lib.rs

Lines changed: 34 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ pub fn init(unstable: bool) -> Extension {
127127
fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
128128
let mut return_features: Vec<&'static str> = vec![];
129129

130-
if features.contains(wgpu_types::Features::DEPTH_CLAMPING) {
131-
return_features.push("depth-clamping");
130+
if features.contains(wgpu_types::Features::DEPTH_CLIP_CONTROL) {
131+
return_features.push("depth-clip-control");
132132
}
133133
if features.contains(wgpu_types::Features::PIPELINE_STATISTICS_QUERY) {
134134
return_features.push("pipeline-statistics-query");
@@ -309,105 +309,50 @@ pub struct GpuRequiredFeatures(HashSet<String>);
309309
impl From<GpuRequiredFeatures> for wgpu_types::Features {
310310
fn from(required_features: GpuRequiredFeatures) -> wgpu_types::Features {
311311
let mut features: wgpu_types::Features = wgpu_types::Features::empty();
312-
313-
if required_features.0.contains("depth-clamping") {
314-
features.set(wgpu_types::Features::DEPTH_CLAMPING, true);
315-
}
316-
if required_features.0.contains("pipeline-statistics-query") {
317-
features.set(wgpu_types::Features::PIPELINE_STATISTICS_QUERY, true);
318-
}
319-
if required_features.0.contains("texture-compression-bc") {
320-
features.set(wgpu_types::Features::TEXTURE_COMPRESSION_BC, true);
321-
}
322-
if required_features.0.contains("timestamp-query") {
323-
features.set(wgpu_types::Features::TIMESTAMP_QUERY, true);
324-
}
312+
features.set(wgpu_types::Features::DEPTH_CLIP_CONTROL, required_features.0.contains("depth-clip-control"));
313+
features.set(wgpu_types::Features::PIPELINE_STATISTICS_QUERY, required_features.0.contains("pipeline-statistics-query"));
314+
features.set(wgpu_types::Features::TEXTURE_COMPRESSION_BC, required_features.0.contains("texture-compression-bc"));
315+
features.set(wgpu_types::Features::TIMESTAMP_QUERY, required_features.0.contains("timestamp-query"));
325316

326317
// extended from spec
327-
if required_features.0.contains("mappable-primary-buffers") {
328-
features.set(wgpu_types::Features::MAPPABLE_PRIMARY_BUFFERS, true);
329-
}
330-
if required_features.0.contains("texture-binding-array") {
331-
features.set(wgpu_types::Features::TEXTURE_BINDING_ARRAY, true);
332-
}
333-
if required_features.0.contains("buffer-binding-array") {
334-
features.set(wgpu_types::Features::BUFFER_BINDING_ARRAY, true);
335-
}
336-
if required_features
318+
features.set(wgpu_types::Features::MAPPABLE_PRIMARY_BUFFERS, required_features.0.contains("mappable-primary-buffers"));
319+
features.set(wgpu_types::Features::TEXTURE_BINDING_ARRAY, required_features.0.contains("texture-binding-array"));
320+
features.set(wgpu_types::Features::BUFFER_BINDING_ARRAY, required_features.0.contains("buffer-binding-array"));
321+
features.set(wgpu_types::Features::STORAGE_RESOURCE_BINDING_ARRAY, required_features
337322
.0
338-
.contains("storage-resource-binding-array")
339-
{
340-
features.set(wgpu_types::Features::STORAGE_RESOURCE_BINDING_ARRAY, true);
341-
}
342-
if required_features
343-
.0
344-
.contains("sampled-texture-and-storage-buffer-array-non-uniform-indexing")
345-
{
323+
.contains("storage-resource-binding-array"));
346324
features.set(
347325
wgpu_types::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
348-
true,
349-
);
350-
}
351-
if required_features
326+
required_features
352327
.0
353-
.contains("uniform-buffer-and-storage-buffer-texture-non-uniform-indexing")
354-
{
328+
.contains("sampled-texture-and-storage-buffer-array-non-uniform-indexing"),
329+
);
355330
features.set(
356331
wgpu_types::Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
357-
true,
358-
);
359-
}
360-
if required_features.0.contains("unsized-binding-array") {
361-
features.set(wgpu_types::Features::UNSIZED_BINDING_ARRAY, true);
362-
}
363-
if required_features.0.contains("multi-draw-indirect") {
364-
features.set(wgpu_types::Features::MULTI_DRAW_INDIRECT, true);
365-
}
366-
if required_features.0.contains("multi-draw-indirect-count") {
367-
features.set(wgpu_types::Features::MULTI_DRAW_INDIRECT_COUNT, true);
368-
}
369-
if required_features.0.contains("push-constants") {
370-
features.set(wgpu_types::Features::PUSH_CONSTANTS, true);
371-
}
372-
if required_features.0.contains("address-mode-clamp-to-border") {
373-
features.set(wgpu_types::Features::ADDRESS_MODE_CLAMP_TO_BORDER, true);
374-
}
375-
if required_features.0.contains("texture-compression-etc2") {
376-
features.set(wgpu_types::Features::TEXTURE_COMPRESSION_ETC2, true);
377-
}
378-
if required_features.0.contains("texture-compression-astc-ldr") {
379-
features.set(wgpu_types::Features::TEXTURE_COMPRESSION_ASTC_LDR, true);
380-
}
381-
if required_features
332+
required_features
382333
.0
383-
.contains("texture-adapter-specific-format-features")
384-
{
334+
.contains("uniform-buffer-and-storage-buffer-texture-non-uniform-indexing"),
335+
);
336+
features.set(wgpu_types::Features::UNSIZED_BINDING_ARRAY, required_features.0.contains("unsized-binding-array"));
337+
features.set(wgpu_types::Features::MULTI_DRAW_INDIRECT, required_features.0.contains("multi-draw-indirect"));
338+
features.set(wgpu_types::Features::MULTI_DRAW_INDIRECT_COUNT, required_features.0.contains("multi-draw-indirect-count"));
339+
features.set(wgpu_types::Features::PUSH_CONSTANTS, required_features.0.contains("push-constants"));
340+
features.set(wgpu_types::Features::ADDRESS_MODE_CLAMP_TO_BORDER, required_features.0.contains("address-mode-clamp-to-border"));
341+
features.set(wgpu_types::Features::TEXTURE_COMPRESSION_ETC2, required_features.0.contains("texture-compression-etc2"));
342+
features.set(wgpu_types::Features::TEXTURE_COMPRESSION_ASTC_LDR, required_features.0.contains("texture-compression-astc-ldr"));
385343
features.set(
386344
wgpu_types::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES,
387-
true,
345+
required_features
346+
.0
347+
.contains("texture-adapter-specific-format-features"),
388348
);
389-
}
390-
if required_features.0.contains("shader-float64") {
391-
features.set(wgpu_types::Features::SHADER_FLOAT64, true);
392-
}
393-
if required_features.0.contains("vertex-attribute-64bit") {
394-
features.set(wgpu_types::Features::VERTEX_ATTRIBUTE_64BIT, true);
395-
}
396-
if required_features.0.contains("conservative-rasterization") {
397-
features.set(wgpu_types::Features::CONSERVATIVE_RASTERIZATION, true);
398-
}
399-
if required_features.0.contains("vertex-writable-storage") {
400-
features.set(wgpu_types::Features::VERTEX_WRITABLE_STORAGE, true);
401-
}
402-
if required_features.0.contains("clear-commands") {
403-
features.set(wgpu_types::Features::CLEAR_COMMANDS, true);
404-
}
405-
if required_features.0.contains("spirv-shader-passthrough") {
406-
features.set(wgpu_types::Features::SPIRV_SHADER_PASSTHROUGH, true);
407-
}
408-
if required_features.0.contains("shader-primitive-index") {
409-
features.set(wgpu_types::Features::SHADER_PRIMITIVE_INDEX, true);
410-
}
349+
features.set(wgpu_types::Features::SHADER_FLOAT64, required_features.0.contains("shader-float64"));
350+
features.set(wgpu_types::Features::VERTEX_ATTRIBUTE_64BIT, required_features.0.contains("vertex-attribute-64bit"));
351+
features.set(wgpu_types::Features::CONSERVATIVE_RASTERIZATION, required_features.0.contains("conservative-rasterization"));
352+
features.set(wgpu_types::Features::VERTEX_WRITABLE_STORAGE, required_features.0.contains("vertex-writable-storage"));
353+
features.set(wgpu_types::Features::CLEAR_COMMANDS, required_features.0.contains("clear-commands"));
354+
features.set(wgpu_types::Features::SPIRV_SHADER_PASSTHROUGH, required_features.0.contains("spirv-shader-passthrough"));
355+
features.set(wgpu_types::Features::SHADER_PRIMITIVE_INDEX, required_features.0.contains("shader-primitive-index"));
411356

412357
features
413358
}

deno_webgpu/src/pipeline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct GpuPrimitiveState {
171171
strip_index_format: Option<wgpu_types::IndexFormat>,
172172
front_face: wgpu_types::FrontFace,
173173
cull_mode: GpuCullMode,
174-
clamp_depth: bool,
174+
unclipped_depth: bool,
175175
}
176176

177177
impl From<GpuPrimitiveState> for wgpu_types::PrimitiveState {
@@ -181,7 +181,7 @@ impl From<GpuPrimitiveState> for wgpu_types::PrimitiveState {
181181
strip_index_format: value.strip_index_format,
182182
front_face: value.front_face,
183183
cull_mode: value.cull_mode.into(),
184-
clamp_depth: value.clamp_depth,
184+
unclipped_depth: value.unclipped_depth,
185185
polygon_mode: Default::default(), // native-only
186186
conservative: false, // native-only
187187
}

wgpu-core/src/command/bundle.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
/*! Render Bundles
22
3-
## Software implementation
3+
## Software implementation
44
5-
The path from nothing to using a render bundle consists of 3 phases.
5+
The path from nothing to using a render bundle consists of 3 phases.
66
7-
### Initial command encoding
7+
### Initial command encoding
88
9-
User creates a `RenderBundleEncoder` and populates it by issuing commands
10-
from `bundle_ffi` module, just like with `RenderPass`, except that the
11-
set of available commands is reduced. Everything is written into a `RawPass`.
9+
User creates a `RenderBundleEncoder` and populates it by issuing commands
10+
from `bundle_ffi` module, just like with `RenderPass`, except that the
11+
set of available commands is reduced. Everything is written into a `RawPass`.
1212
13-
### Bundle baking
13+
### Bundle baking
1414
15-
Once the commands are encoded, user calls `render_bundle_encoder_finish`.
16-
This is perhaps the most complex part of the logic. It consumes the
17-
commands stored in `RawPass`, while validating everything, tracking the state,
18-
and re-recording the commands into a separate `Vec<RenderCommand>`. It
19-
doesn't actually execute any commands.
15+
Once the commands are encoded, user calls `render_bundle_encoder_finish`.
16+
This is perhaps the most complex part of the logic. It consumes the
17+
commands stored in `RawPass`, while validating everything, tracking the state,
18+
and re-recording the commands into a separate `Vec<RenderCommand>`. It
19+
doesn't actually execute any commands.
2020
21-
What's more important, is that the produced vector of commands is "normalized",
22-
which means it can be executed verbatim without any state tracking. More
23-
formally, "normalized" command stream guarantees that any state required by
24-
a draw call is set explicitly by one of the commands between the draw call
25-
and the last changing of the pipeline.
21+
What's more important, is that the produced vector of commands is "normalized",
22+
which means it can be executed verbatim without any state tracking. More
23+
formally, "normalized" command stream guarantees that any state required by
24+
a draw call is set explicitly by one of the commands between the draw call
25+
and the last changing of the pipeline.
2626
27-
### Execution
27+
### Execution
2828
29-
When the bundle is used in an actual render pass, `RenderBundle::execute` is
30-
called. It goes through the commands and issues them into the native command
31-
buffer. Thanks to the "normalized" property, it doesn't track any bind group
32-
invalidations or index format changes.
29+
When the bundle is used in an actual render pass, `RenderBundle::execute` is
30+
called. It goes through the commands and issues them into the native command
31+
buffer. Thanks to the "normalized" property, it doesn't track any bind group
32+
invalidations or index format changes.
3333
!*/
3434
#![allow(clippy::reversed_empty_ranges)]
3535

wgpu-core/src/device/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,8 +2211,8 @@ impl<A: HalApi> Device<A> {
22112211
);
22122212
}
22132213

2214-
if desc.primitive.clamp_depth {
2215-
self.require_features(wgt::Features::DEPTH_CLAMPING)?;
2214+
if desc.primitive.unclipped_depth {
2215+
self.require_features(wgt::Features::DEPTH_CLIP_CONTROL)?;
22162216
}
22172217

22182218
if desc.primitive.polygon_mode == wgt::PolygonMode::Line {

wgpu-core/src/present.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*! Presentation.
22
3-
## Lifecycle
3+
## Lifecycle
44
5-
Whenever a submission detects the use of any surface texture, it adds it to the device
6-
tracker for the duration of the submission (temporarily, while recording).
7-
It's added with `UNINITIALIZED` state and transitioned into `empty()` state.
8-
When this texture is presented, we remove it from the device tracker as well as
9-
extract it from the hub.
5+
Whenever a submission detects the use of any surface texture, it adds it to the device
6+
tracker for the duration of the submission (temporarily, while recording).
7+
It's added with `UNINITIALIZED` state and transitioned into `empty()` state.
8+
When this texture is presented, we remove it from the device tracker as well as
9+
extract it from the hub.
1010
!*/
1111

1212
#[cfg(feature = "trace")]

wgpu-hal/src/dx12/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl super::Adapter {
169169
};
170170

171171
let mut features = wgt::Features::empty()
172-
| wgt::Features::DEPTH_CLAMPING
172+
| wgt::Features::DEPTH_CLIP_CONTROL
173173
| wgt::Features::MAPPABLE_PRIMARY_BUFFERS
174174
//TODO: Naga part
175175
//| wgt::Features::TEXTURE_BINDING_ARRAY

wgpu-hal/src/dx12/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ impl crate::Device<super::Api> for super::Device {
12751275
DepthBias: bias.constant,
12761276
DepthBiasClamp: bias.clamp,
12771277
SlopeScaledDepthBias: bias.slope_scale,
1278-
DepthClipEnable: if desc.primitive.clamp_depth { 0 } else { 1 },
1278+
DepthClipEnable: if desc.primitive.unclipped_depth { 0 } else { 1 },
12791279
MultisampleEnable: if desc.multisample.count > 1 { 1 } else { 0 },
12801280
ForcedSampleCount: 0,
12811281
AntialiasedLineEnable: 0,

wgpu-hal/src/gles/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl super::Adapter {
280280
| wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES
281281
| wgt::Features::CLEAR_COMMANDS;
282282
features.set(
283-
wgt::Features::DEPTH_CLAMPING,
283+
wgt::Features::DEPTH_CLIP_CONTROL,
284284
extensions.contains("GL_EXT_depth_clamp"),
285285
);
286286
features.set(

wgpu-hal/src/gles/conv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub(super) fn map_primitive_state(state: &wgt::PrimitiveState) -> super::Primiti
254254
Some(wgt::Face::Back) => glow::BACK,
255255
None => 0,
256256
},
257-
clamp_depth: state.clamp_depth,
257+
unclipped_depth: state.unclipped_depth,
258258
}
259259
}
260260

wgpu-hal/src/gles/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ struct StencilState {
546546
struct PrimitiveState {
547547
front_face: u32,
548548
cull_face: u32,
549-
clamp_depth: bool,
549+
unclipped_depth: bool,
550550
}
551551

552552
type InvalidatedAttachments = ArrayVec<u32, { crate::MAX_COLOR_TARGETS + 2 }>;

0 commit comments

Comments
 (0)