Skip to content

Commit d631b2c

Browse files
committed
Fix depth clamping semantics
1 parent cdc9d65 commit d631b2c

File tree

7 files changed

+12
-15
lines changed

7 files changed

+12
-15
lines changed

examples/hello_triangle_rust/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn main() {
4040
cull_mode: wgpu::CullMode::None,
4141
depth_bias: 0,
4242
depth_bias_slope_scale: 0.0,
43-
depth_bias_clamp: wgpu::MAX_DEPTH_BIAS_CLAMP,
43+
depth_bias_clamp: 0.0,
4444
},
4545
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
4646
color_states: &[

gfx-examples/src/cube.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl framework::Example for Example {
280280
cull_mode: wgpu::CullMode::Back,
281281
depth_bias: 0,
282282
depth_bias_slope_scale: 0.0,
283-
depth_bias_clamp: wgpu::MAX_DEPTH_BIAS_CLAMP,
283+
depth_bias_clamp: 0.0,
284284
},
285285
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
286286
color_states: &[

gfx-examples/src/shadow.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl framework::Example for Example {
219219
});
220220

221221
let local_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
222-
bindings: &[
222+
bindings: &[
223223
wgpu::BindGroupLayoutBinding {
224224
binding: 0,
225225
visibility: wgpu::ShaderStageFlags::VERTEX | wgpu::ShaderStageFlags::FRAGMENT,
@@ -380,7 +380,7 @@ impl framework::Example for Example {
380380
let light_uniform_size = (Self::MAX_LIGHTS * mem::size_of::<LightRaw>()) as u32;
381381
let light_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
382382
size: light_uniform_size,
383-
usage: wgpu::BufferUsageFlags::UNIFORM | wgpu::BufferUsageFlags::TRANSFER_DST,
383+
usage: wgpu::BufferUsageFlags::UNIFORM | wgpu::BufferUsageFlags::TRANSFER_SRC | wgpu::BufferUsageFlags::TRANSFER_DST,
384384
});
385385

386386
let vb_desc = wgpu::VertexBufferDescriptor {
@@ -459,7 +459,7 @@ impl framework::Example for Example {
459459
cull_mode: wgpu::CullMode::Back,
460460
depth_bias: 2, // corresponds to bilinear filtering
461461
depth_bias_slope_scale: 2.0,
462-
depth_bias_clamp: wgpu::MAX_DEPTH_BIAS_CLAMP,
462+
depth_bias_clamp: 0.0,
463463
},
464464
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
465465
color_states: &[],
@@ -579,7 +579,7 @@ impl framework::Example for Example {
579579
cull_mode: wgpu::CullMode::Back,
580580
depth_bias: 0,
581581
depth_bias_slope_scale: 0.0,
582-
depth_bias_clamp: wgpu::MAX_DEPTH_BIAS_CLAMP,
582+
depth_bias_clamp: 0.0,
583583
},
584584
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
585585
color_states: &[

wgpu-bindings/wgpu.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
#define WGPUBITS_PER_BYTE 8
77

8-
#define WGPUMAX_DEPTH_BIAS_CLAMP 16
9-
108
typedef enum {
119
WGPUAddressMode_ClampToEdge = 0,
1210
WGPUAddressMode_Repeat = 1,
@@ -169,6 +167,8 @@ typedef struct {
169167
WGPUExtensions extensions;
170168
} WGPUDeviceDescriptor;
171169

170+
typedef WGPUId WGPUBindGroupId;
171+
172172
typedef WGPUId WGPUBufferId;
173173

174174
typedef void (*WGPUBufferMapReadCallback)(WGPUBufferMapAsyncStatus status, const uint8_t *data, uint8_t *userdata);
@@ -243,8 +243,6 @@ typedef struct {
243243
const WGPURenderPassDepthStencilAttachmentDescriptor_TextureViewId *depth_stencil_attachment;
244244
} WGPURenderPassDescriptor;
245245

246-
typedef WGPUId WGPUBindGroupId;
247-
248246
typedef WGPUId WGPUComputePipelineId;
249247

250248
typedef WGPUId WGPUInstanceId;
@@ -557,6 +555,8 @@ typedef struct {
557555

558556
WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id, const WGPUDeviceDescriptor *desc);
559557

558+
void wgpu_bind_group_destroy(WGPUBindGroupId bind_group_id);
559+
560560
void wgpu_buffer_destroy(WGPUBufferId buffer_id);
561561

562562
void wgpu_buffer_map_read_async(WGPUBufferId buffer_id,

wgpu-native/src/conv.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::{
22
binding_model, command, pipeline, resource, Color,
33
Extent3d, Origin3d,
4-
MAX_DEPTH_BIAS_CLAMP,
54
};
65

76

@@ -491,7 +490,7 @@ pub fn map_rasterization_state_descriptor(
491490
pipeline::FrontFace::Ccw => hal::pso::FrontFace::CounterClockwise,
492491
pipeline::FrontFace::Cw => hal::pso::FrontFace::Clockwise,
493492
},
494-
depth_bias: if desc.depth_bias != 0 || desc.depth_bias_slope_scale != 0.0 || desc.depth_bias_clamp < MAX_DEPTH_BIAS_CLAMP {
493+
depth_bias: if desc.depth_bias != 0 || desc.depth_bias_slope_scale != 0.0 || desc.depth_bias_clamp != 0.0 {
495494
Some(hal::pso::State::Static(hal::pso::DepthBias {
496495
const_factor: desc.depth_bias as f32,
497496
slope_factor: desc.depth_bias_slope_scale,

wgpu-native/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub use self::hub::{HUB, Id, IdentityManager, Registry};
4444
use std::ptr;
4545
use std::sync::atomic::{AtomicUsize, Ordering};
4646

47-
pub const MAX_DEPTH_BIAS_CLAMP: f32 = 16.0;
4847
type SubmissionIndex = usize;
4948

5049
//TODO: make it private. Currently used for swapchain creation impl.

wgpu-rs/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::slice;
1010

1111
pub use wgn::winit;
1212
pub use wgn::{
13-
MAX_DEPTH_BIAS_CLAMP,
1413
AdapterDescriptor, BindGroupLayoutBinding, BindingType,
1514
BlendDescriptor, BlendOperation, BlendFactor, BufferMapAsyncStatus, ColorWriteFlags,
1615
RasterizationStateDescriptor, CullMode, FrontFace,
@@ -253,7 +252,7 @@ impl Instance {
253252
id: wgn::wgpu_instance_create_surface_from_winit(self.id, window),
254253
}
255254
}
256-
255+
257256
#[cfg(feature = "metal")]
258257
pub fn create_surface_with_metal_layer(&self, window: *mut std::ffi::c_void) -> Surface {
259258
Surface {

0 commit comments

Comments
 (0)