Skip to content

Commit b8982d5

Browse files
committed
More minor cleanups
1 parent e2dcc16 commit b8982d5

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

wgpu-ffx/src/jitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn halton(index: i32, base: i32) -> f32 {
1313
while current_index > 0 {
1414
f /= base as f32;
1515
result += f * (current_index % base) as f32;
16-
current_index = f32::floor(current_index as f32 / base as f32) as i32;
16+
current_index /= base;
1717
}
1818

1919
result

wgpu-ffx/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,18 @@ impl FsrContext {
226226
/// The returned [`FsrView`] holds all textures and temporal accumulation
227227
/// state. Multiple views can be created from the same context for
228228
/// multi-camera or split-screen rendering.
229+
///
230+
/// # Panics
231+
///
232+
/// Panics if any dimension of `max_render_size` is less than 2, or any
233+
/// dimension of `max_upscale_size` is 0.
229234
pub fn create_view(
230235
&self,
231236
queue: &wgpu::Queue,
232237
max_render_size: [u32; 2],
233238
max_upscale_size: [u32; 2],
234239
) -> FsrView {
240+
FsrView::validate_sizes(max_render_size, max_upscale_size);
235241
FsrView::new(
236242
self.device.clone(),
237243
queue,
@@ -657,6 +663,22 @@ impl FsrContext {
657663
}
658664

659665
impl FsrView {
666+
fn validate_sizes(max_render_size: [u32; 2], max_upscale_size: [u32; 2]) {
667+
assert!(
668+
max_render_size[0] >= 2 && max_render_size[1] >= 2,
669+
"max_render_size must be at least [2, 2], got [{}, {}] \
670+
(internal half-resolution textures require dimensions >= 1)",
671+
max_render_size[0],
672+
max_render_size[1],
673+
);
674+
assert!(
675+
max_upscale_size[0] >= 1 && max_upscale_size[1] >= 1,
676+
"max_upscale_size must be at least [1, 1], got [{}, {}]",
677+
max_upscale_size[0],
678+
max_upscale_size[1],
679+
);
680+
}
681+
660682
fn new(
661683
device: wgpu::Device,
662684
queue: &wgpu::Queue,
@@ -698,12 +720,18 @@ impl FsrView {
698720
///
699721
/// Resets all temporal history — the next dispatch will behave as the
700722
/// first frame.
723+
///
724+
/// # Panics
725+
///
726+
/// Panics if any dimension of `max_render_size` is less than 2, or any
727+
/// dimension of `max_upscale_size` is 0.
701728
pub fn resize(
702729
&mut self,
703730
queue: &wgpu::Queue,
704731
max_render_size: [u32; 2],
705732
max_upscale_size: [u32; 2],
706733
) {
734+
Self::validate_sizes(max_render_size, max_upscale_size);
707735
self.resources =
708736
resources::FsrResources::new(&self.device, queue, max_render_size, max_upscale_size);
709737
self.max_render_size = max_render_size;

wgpu-ffx/src/validation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ pub enum FsrDispatchError {
6161
)]
6262
FrameTimeDeltaTooLow(f32),
6363

64-
#[error("Pre-exposure is 0.0, which is invalid")]
65-
PreExposureZero,
64+
#[error("Pre-exposure {0} must be greater than 0.0")]
65+
PreExposureNotPositive(f32),
6666

6767
#[error(
6868
"DEPTH_INVERTED flag is set, but camera near ({camera_near}) is less than camera far ({camera_far})"
@@ -193,8 +193,8 @@ pub fn check_dispatch(
193193
}
194194

195195
// Check pre-exposure
196-
if info.pre_exposure == 0.0 {
197-
return Err(FsrDispatchError::PreExposureZero);
196+
if info.pre_exposure <= 0.0 {
197+
return Err(FsrDispatchError::PreExposureNotPositive(info.pre_exposure));
198198
}
199199

200200
// Check depth configuration

0 commit comments

Comments
 (0)