Skip to content

Commit

Permalink
wgpu: Instead of asking for large resolution limits, use the reported…
Browse files Browse the repository at this point in the history
… available limits.

This is a reasonable choice for us because our texture usage is all
either dynamic (block textures) or window-size-dependent; we have no
fixed sizes.

This makes All is Cubes compatible with (at least my own) phone browser
which it had not been before (because the 2D texture size limit was
4096, but `Limits::default()` contains 8192).
  • Loading branch information
kpreid committed Nov 16, 2023
1 parent b5e3cbc commit dd04992
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions all-is-cubes-gpu/src/in_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ impl<I: time::Instant> SurfaceRenderer<I> {
adapter: &wgpu::Adapter,
) -> Result<Self, GraphicsResourceError> {
let (device, queue) = adapter
.request_device(&EverythingRenderer::<I>::device_descriptor(), None)
.request_device(
&EverythingRenderer::<I>::device_descriptor(adapter.limits()),
None,
)
.await
.map_err(|e| {
GraphicsResourceError::new(
Expand Down Expand Up @@ -232,13 +235,12 @@ pub struct EverythingRenderer<I> {

impl<I: time::Instant> EverythingRenderer<I> {
/// A device descriptor suitable for the expectations of [`EverythingRenderer`].
pub fn device_descriptor() -> wgpu::DeviceDescriptor<'static> {
pub fn device_descriptor(available_limits: wgpu::Limits) -> wgpu::DeviceDescriptor<'static> {
wgpu::DeviceDescriptor {
features: wgpu::Features::empty(),
limits: wgpu::Limits {
max_inter_stage_shader_components: 32, // number used by blocks-and-lines shader
..wgpu::Limits::downlevel_webgl2_defaults()
.using_resolution(wgpu::Limits::default())
..wgpu::Limits::downlevel_webgl2_defaults().using_resolution(available_limits)
},
label: None,
}
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-gpu/src/in_wgpu/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Builder {
) -> Result<Self, wgpu::RequestDeviceError> {
let (device, queue) = adapter
.request_device(
&in_wgpu::EverythingRenderer::<AdaptedInstant>::device_descriptor(),
&in_wgpu::EverythingRenderer::<AdaptedInstant>::device_descriptor(adapter.limits()),
None,
)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-gpu/src/in_wgpu/shader_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
{
let (device, queue) = adapter
.request_device(
&in_wgpu::EverythingRenderer::<time::NoTime>::device_descriptor(),
&in_wgpu::EverythingRenderer::<time::NoTime>::device_descriptor(adapter.limits()),
None,
)
.await
Expand Down

0 comments on commit dd04992

Please sign in to comment.