mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Add Quad play test
This commit is contained in:
parent
bba82724a8
commit
d05d1aeec1
@ -2,5 +2,6 @@
|
||||
backends: (bits: 0x7),
|
||||
tests: [
|
||||
"buffer-copy.ron",
|
||||
"quad.ron",
|
||||
],
|
||||
)
|
@ -5,7 +5,7 @@
|
||||
name: "basic",
|
||||
buffer: (index: 0, epoch: 1),
|
||||
offset: 0,
|
||||
data: [0x00, 0x00, 0x80, 0xBF],
|
||||
data: Raw([0x00, 0x00, 0x80, 0xBF]),
|
||||
)
|
||||
],
|
||||
actions: [
|
||||
|
1
player/tests/data/quad.bin
Normal file
1
player/tests/data/quad.bin
Normal file
File diff suppressed because one or more lines are too long
7
player/tests/data/quad.frag
Normal file
7
player/tests/data/quad.frag
Normal file
@ -0,0 +1,7 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
BIN
player/tests/data/quad.frag.spv
Normal file
BIN
player/tests/data/quad.frag.spv
Normal file
Binary file not shown.
155
player/tests/data/quad.ron
Normal file
155
player/tests/data/quad.ron
Normal file
@ -0,0 +1,155 @@
|
||||
(
|
||||
features: (bits: 0x0),
|
||||
expectations: [
|
||||
(
|
||||
name: "Quad",
|
||||
buffer: (index: 1, epoch: 1),
|
||||
offset: 0,
|
||||
data: File("quad.bin", 16384),
|
||||
)
|
||||
],
|
||||
actions: [
|
||||
CreateShaderModule(
|
||||
id: Id(0, 1, Empty),
|
||||
data: "quad.vert.spv",
|
||||
),
|
||||
CreateShaderModule(
|
||||
id: Id(1, 1, Empty),
|
||||
data: "quad.frag.spv",
|
||||
),
|
||||
CreateTexture(Id(0, 1, Empty), (
|
||||
label: Some("Output Texture"),
|
||||
size: (
|
||||
width: 64,
|
||||
height: 64,
|
||||
depth: 1,
|
||||
),
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: D2,
|
||||
format: Rgba8Unorm,
|
||||
usage: (
|
||||
bits: 27,
|
||||
),
|
||||
)),
|
||||
CreateTextureView(
|
||||
id: Id(0, 1, Empty),
|
||||
parent_id: Id(0, 1, Empty),
|
||||
desc: (),
|
||||
),
|
||||
CreateBuffer(
|
||||
Id(1, 1, Empty),
|
||||
(
|
||||
label: Some("Output Buffer"),
|
||||
size: 16384,
|
||||
usage: (
|
||||
bits: 9,
|
||||
),
|
||||
mapped_at_creation: false,
|
||||
),
|
||||
),
|
||||
CreatePipelineLayout(Id(0, 1, Empty), (
|
||||
label: None,
|
||||
bind_group_layouts: [],
|
||||
push_constant_ranges: [],
|
||||
)),
|
||||
CreateRenderPipeline(Id(0, 1, Empty), (
|
||||
label: None,
|
||||
layout: Some(Id(0, 1, Empty)),
|
||||
vertex_stage: (
|
||||
module: Id(0, 1, Empty),
|
||||
entry_point: "main",
|
||||
),
|
||||
fragment_stage: Some((
|
||||
module: Id(1, 1, Empty),
|
||||
entry_point: "main",
|
||||
)),
|
||||
rasterization_state: None,
|
||||
primitive_topology: TriangleList,
|
||||
color_states: [
|
||||
(
|
||||
format: Rgba8Unorm,
|
||||
alpha_blend: (
|
||||
src_factor: One,
|
||||
dst_factor: Zero,
|
||||
operation: Add,
|
||||
),
|
||||
color_blend: (
|
||||
src_factor: One,
|
||||
dst_factor: Zero,
|
||||
operation: Add,
|
||||
),
|
||||
write_mask: (
|
||||
bits: 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
depth_stencil_state: None,
|
||||
vertex_state: (
|
||||
index_format: Uint16,
|
||||
vertex_buffers: [],
|
||||
),
|
||||
sample_count: 1,
|
||||
sample_mask: 4294967295,
|
||||
alpha_to_coverage_enabled: false,
|
||||
)),
|
||||
Submit(1, [
|
||||
RunRenderPass(
|
||||
base: (
|
||||
commands: [
|
||||
SetPipeline(Id(0, 1, Empty)),
|
||||
Draw(
|
||||
vertex_count: 3,
|
||||
instance_count: 1,
|
||||
first_vertex: 0,
|
||||
first_instance: 0,
|
||||
),
|
||||
],
|
||||
dynamic_offsets: [],
|
||||
string_data: [],
|
||||
push_constant_data: [],
|
||||
),
|
||||
target_colors: [
|
||||
(
|
||||
attachment: Id(0, 1, Empty),
|
||||
resolve_target: None,
|
||||
channel: (
|
||||
load_op: Clear,
|
||||
store_op: Store,
|
||||
clear_value: (
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 1,
|
||||
),
|
||||
read_only: false,
|
||||
),
|
||||
),
|
||||
],
|
||||
target_depth_stencil: None,
|
||||
),
|
||||
CopyTextureToBuffer(
|
||||
src: (
|
||||
texture: Id(0, 1, Empty),
|
||||
mip_level: 0,
|
||||
array_layer: 0,
|
||||
),
|
||||
dst: (
|
||||
buffer: Id(1, 1, Empty),
|
||||
layout: (
|
||||
offset: 0,
|
||||
bytes_per_row: 256,
|
||||
rows_per_image: 64,
|
||||
),
|
||||
),
|
||||
size: (
|
||||
width: 64,
|
||||
height: 64,
|
||||
depth: 1,
|
||||
),
|
||||
),
|
||||
]),
|
||||
DestroyShaderModule(Id(0, 1, Empty)),
|
||||
DestroyShaderModule(Id(1, 1, Empty)),
|
||||
],
|
||||
)
|
10
player/tests/data/quad.vert
Normal file
10
player/tests/data/quad.vert
Normal file
@ -0,0 +1,10 @@
|
||||
#version 450
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
void main() {
|
||||
vec2 pos = vec2(gl_VertexIndex == 2 ? 3.0 : -1.0, gl_VertexIndex == 1 ? 3.0 : -1.0);
|
||||
gl_Position = vec4(pos, 0.0, 1.0);
|
||||
}
|
BIN
player/tests/data/quad.vert.spv
Normal file
BIN
player/tests/data/quad.vert.spv
Normal file
Binary file not shown.
@ -16,6 +16,7 @@
|
||||
use player::{gfx_select, GlobalPlay, IdentityPassThroughFactory};
|
||||
use std::{
|
||||
fs::{read_to_string, File},
|
||||
io::{Read, Seek, SeekFrom},
|
||||
path::{Path, PathBuf},
|
||||
ptr, slice,
|
||||
};
|
||||
@ -26,12 +27,27 @@ struct RawId {
|
||||
epoch: u32,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
enum ExpectedData {
|
||||
Raw(Vec<u8>),
|
||||
File(String, usize),
|
||||
}
|
||||
|
||||
impl ExpectedData {
|
||||
fn len(&self) -> usize {
|
||||
match self {
|
||||
ExpectedData::Raw(vec) => vec.len(),
|
||||
ExpectedData::File(_, size) => *size,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct Expectation {
|
||||
name: String,
|
||||
buffer: RawId,
|
||||
offset: wgt::BufferAddress,
|
||||
data: Vec<u8>,
|
||||
data: ExpectedData,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
@ -67,6 +83,7 @@ impl Test<'_> {
|
||||
dir: &Path,
|
||||
global: &wgc::hub::Global<IdentityPassThroughFactory>,
|
||||
adapter: wgc::id::AdapterId,
|
||||
test_num: u32,
|
||||
) {
|
||||
let backend = adapter.backend();
|
||||
let device = gfx_select!(adapter => global.adapter_request_device(
|
||||
@ -77,7 +94,7 @@ impl Test<'_> {
|
||||
shader_validation: true,
|
||||
},
|
||||
None,
|
||||
wgc::id::TypedId::zip(1, 0, backend)
|
||||
wgc::id::TypedId::zip(test_num, 0, backend)
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
@ -111,7 +128,19 @@ impl Test<'_> {
|
||||
gfx_select!(device => global.buffer_get_mapped_range(buffer, expect.offset, None))
|
||||
.unwrap();
|
||||
let contents = unsafe { slice::from_raw_parts(ptr, expect.data.len()) };
|
||||
assert_eq!(&expect.data[..], contents);
|
||||
let expected_data = match expect.data {
|
||||
ExpectedData::Raw(vec) => vec,
|
||||
ExpectedData::File(name, size) => {
|
||||
let mut bin = vec![0; size];
|
||||
let mut file = File::open(dir.join(name)).unwrap();
|
||||
file.seek(SeekFrom::Start(expect.offset)).unwrap();
|
||||
file.read_exact(&mut bin[..]).unwrap();
|
||||
|
||||
bin
|
||||
}
|
||||
};
|
||||
|
||||
assert_eq!(&expected_data[..], contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -158,6 +187,7 @@ impl Corpus {
|
||||
println!("\tBackend {:?}", backend);
|
||||
let supported_features =
|
||||
gfx_select!(adapter => global.adapter_features(adapter)).unwrap();
|
||||
let mut test_num = 0;
|
||||
for test_path in &corpus.tests {
|
||||
println!("\t\tTest '{:?}'", test_path);
|
||||
let test = Test::load(dir.join(test_path), adapter.backend());
|
||||
@ -168,7 +198,8 @@ impl Corpus {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
test.run(dir, &global, adapter);
|
||||
test.run(dir, &global, adapter, test_num);
|
||||
test_num += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ impl<B: hal::Backend> Borrow<TextureSelector> for Texture<B> {
|
||||
/// Describes a [`TextureView`].
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
|
||||
#[cfg_attr(feature = "replay", derive(serde::Deserialize), serde(default))]
|
||||
pub struct TextureViewDescriptor<'a> {
|
||||
/// Debug label of the texture view. This will show up in graphics debuggers for easy identification.
|
||||
pub label: Label<'a>,
|
||||
|
@ -1838,6 +1838,7 @@ pub struct TextureCopyView<T> {
|
||||
/// The target mip level of the texture.
|
||||
pub mip_level: u32,
|
||||
/// The base texel of the texture in the selected `mip_level`.
|
||||
#[cfg_attr(any(feature = "replay", feature = "trace"), serde(default))]
|
||||
pub origin: Origin3d,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user