mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 06:21:13 +01:00
refactor(test): extract create_discarded_texture_and_view
This prepares for a second caller in the subsequent commit.
This commit is contained in:
1 parent
d183b267d2
commit
3c2c89c051
1 file changed
+54
-46
@@ -167,6 +167,59 @@ fn create_texture_and_view(
|
||||
texture.create_view(&wgpu::TextureViewDescriptor::default())
|
||||
}
|
||||
|
||||
/// Helper function to create a 2x2 `Rgba8Unorm` texture whose contents are a non-zero
|
||||
/// sentinel in memory, but which is nonetheless uninitialized as far as `wgpu` is
|
||||
/// concerned, and return a view of it.
|
||||
///
|
||||
/// The texture is cleared to a non-zero sentinel and then discarded, rather than
|
||||
/// merely left freshly allocated: discarding returns it to the uninitialized state
|
||||
/// while leaving the sentinel in memory, so a missing init action is observable
|
||||
/// without relying on the allocator to hand back dirty pages.
|
||||
fn create_discarded_texture_and_view(ctx: &TestingContext) -> wgpu::TextureView {
|
||||
let texture = ctx.device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: None,
|
||||
size: wgpu::Extent3d {
|
||||
width: 2,
|
||||
height: 2,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Rgba8Unorm,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[],
|
||||
});
|
||||
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
let mut encoder = ctx
|
||||
.device
|
||||
.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
||||
// Store the sentinel, then discard it in a second pass. A single
|
||||
// clear-and-discard pass would let the backend elide the write.
|
||||
for (load, store) in [
|
||||
(wgpu::LoadOp::Clear(wgpu::Color::RED), wgpu::StoreOp::Store),
|
||||
(wgpu::LoadOp::Load, wgpu::StoreOp::Discard),
|
||||
] {
|
||||
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: None,
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view: &view,
|
||||
depth_slice: None,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations { load, store },
|
||||
})],
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
}
|
||||
ctx.queue.submit(Some(encoder.finish()));
|
||||
|
||||
view
|
||||
}
|
||||
|
||||
/// Helper function to perform textureDimensions() and return the result.
|
||||
fn get_dimensions(ctx: &TestingContext, texture_resource: wgpu::BindingResource) -> [u32; 2] {
|
||||
let module = ctx
|
||||
@@ -1133,11 +1186,6 @@ static EXTERNAL_TEXTURE_SAMPLE_TRANSFORM: GpuTestConfiguration = GpuTestConfigur
|
||||
/// This path must register the same `NeedsInitializedMemory` init action as the
|
||||
/// ordinary sampled-texture path. Without it, nothing clears the texture before the
|
||||
/// shader samples plane 0, and the load returns whatever the allocation held.
|
||||
///
|
||||
/// The texture is cleared to a non-zero sentinel and then discarded, rather than
|
||||
/// merely left freshly allocated: discarding returns it to the uninitialized state
|
||||
/// while leaving the sentinel in memory, so a missing init action is observable
|
||||
/// without relying on the allocator to hand back dirty pages.
|
||||
#[apply(gpu_test!)]
|
||||
static EXTERNAL_TEXTURE_FROM_VIEW_ZERO_INIT_AFTER_DISCARD: GpuTestConfiguration =
|
||||
GpuTestConfiguration::new()
|
||||
@@ -1147,47 +1195,7 @@ static EXTERNAL_TEXTURE_FROM_VIEW_ZERO_INIT_AFTER_DISCARD: GpuTestConfiguration
|
||||
.features(wgpu::Features::EXTERNAL_TEXTURE),
|
||||
)
|
||||
.run_async(|ctx| async move {
|
||||
let texture = ctx.device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: None,
|
||||
size: wgpu::Extent3d {
|
||||
width: 2,
|
||||
height: 2,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Rgba8Unorm,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
|
||||
| wgpu::TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[],
|
||||
});
|
||||
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
let mut encoder = ctx
|
||||
.device
|
||||
.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
||||
// Store the sentinel, then discard it in a second pass. A single
|
||||
// clear-and-discard pass would let the backend elide the write.
|
||||
for (load, store) in [
|
||||
(wgpu::LoadOp::Clear(wgpu::Color::RED), wgpu::StoreOp::Store),
|
||||
(wgpu::LoadOp::Load, wgpu::StoreOp::Discard),
|
||||
] {
|
||||
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: None,
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view: &view,
|
||||
depth_slice: None,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations { load, store },
|
||||
})],
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
}
|
||||
ctx.queue.submit(Some(encoder.finish()));
|
||||
let view = create_discarded_texture_and_view(&ctx);
|
||||
|
||||
let loads = get_loads(
|
||||
&ctx,
|
||||
|
||||
Reference in new issue
Block a user