Skip to content

Commit

Permalink
gpu: Remove comments and &s suggesting reuse of adapters.
Browse files Browse the repository at this point in the history
Per the WebGPU specification, `Adapter` can only be used once to create
a device. Therefore, change our functions to take the adapter by value.
  • Loading branch information
kpreid committed Sep 3, 2024
1 parent 0054d06 commit 1b2ab0c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
- `block::EvalBlockError` is now a `struct` with an inner `ErrorKind` enum, instead of an enum, and contains more information.
- `block::Move`’s means of construction have been changed to be more systematic and orthogonal. In particular, paired moves are constructed from unpaired ones.

- `all-is-cubes-gpu` library:
- `in_wgpu::SurfaceRenderer::new()` requires `wgpu::Adapter` instead of `&wgpu::Adapter`.

- `all-is-cubes-port` library:
- All functionality is now conditional on feature flags, to allow omitting unneeded formats and operations.
- `ExportFormat` is now named `Format`.
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-desktop/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub async fn create_winit_wgpu_desktop_session(
let renderer = SurfaceRenderer::new(
session.create_cameras(viewport_cell.as_source()),
surface,
&adapter,
adapter,
executor.clone(),
)
.await?;
Expand Down
6 changes: 3 additions & 3 deletions all-is-cubes-gpu/src/in_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<I: time::Instant> SurfaceRenderer<I> {
pub async fn new(
cameras: StandardCameras,
surface: wgpu::Surface<'static>,
adapter: &wgpu::Adapter,
adapter: wgpu::Adapter,
executor: Arc<dyn Executor>,
) -> Result<Self, wgpu::RequestDeviceError> {
let (device, queue) = adapter
Expand All @@ -142,8 +142,8 @@ impl<I: time::Instant> SurfaceRenderer<I> {
executor,
device.clone(),
cameras,
choose_surface_format(&surface.get_capabilities(adapter)),
adapter,
choose_surface_format(&surface.get_capabilities(&adapter)),
&adapter,
);

Ok(Self {
Expand Down
9 changes: 6 additions & 3 deletions all-is-cubes-gpu/src/in_wgpu/shader_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::in_wgpu::{
// TODO: T is bad abstraction since it silently has to be f16
pub async fn run_shader_test<T>(
device_label: &str,
adapter: &wgpu::Adapter,
adapter: wgpu::Adapter,
output_viewport: Viewport,
test_wgsl: &str,
) -> Vec<T>
Expand All @@ -42,7 +42,10 @@ where
{
let (device, queue) = adapter
.request_device(
&in_wgpu::EverythingRenderer::<time::NoTime>::device_descriptor(device_label, adapter.limits()),
&in_wgpu::EverythingRenderer::<time::NoTime>::device_descriptor(
device_label,
adapter.limits(),
),
None,
)
.await
Expand All @@ -69,7 +72,7 @@ where
desired_maximum_frame_latency: 2,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
},
FbtFeatures::new(adapter),
FbtFeatures::new(&adapter),
&GraphicsOptions::default(),
true,
),
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-gpu/tests/shaders/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) async fn run_shader_test(device_label: &str, test_wgsl: &str) -> imag
let output_viewport = camera::Viewport::with_scale(1.0, [32, 32]);

let f16_pixels: Vec<f16> =
shader_testing::run_shader_test(device_label, &adapter, output_viewport, test_wgsl).await;
shader_testing::run_shader_test(device_label, adapter, output_viewport, test_wgsl).await;

// Convert f16 pixels to f32
image::ImageBuffer::from_raw(
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-wasm/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async fn start_game_with_dom(
let renderer = in_wgpu::SurfaceRenderer::new(
cameras,
surface,
&adapter,
adapter,
Arc::new(crate::web_glue::Executor),
)
.await?;
Expand Down
3 changes: 0 additions & 3 deletions test-renderers/tests/wgpu-render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ static WGPU_INSTANCE: OnceCell<wgpu::Instance> = OnceCell::const_new();
async fn get_factory(
label: String,
) -> Result<WgpuFactory, Box<dyn std::error::Error + Send + Sync>> {
// Temporary workaround for <https://github.com/gfx-rs/wgpu/issues/3498>:
// Create a new adapter every time, rather than sharing one.
// TODO: Either remove this or keep it and remove WGPU_ADAPTER.
let adapter =
init::create_adapter_for_test(WGPU_INSTANCE.get().expect("instance not initialized")).await;

Expand Down

0 comments on commit 1b2ab0c

Please sign in to comment.