Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Warden test framework #1589

Merged
merged 10 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"src/backend/metal",
"src/backend/vulkan",
"src/hal",
"src/warden",
"src/render",
"examples/hal/quad",
"examples/render/quad_render",
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RUST_BACKTRACE:=1
EXCLUDES:=
FEATURES_WARDEN:=
FEATURES_RENDER:=
FEATURES_RENDER_ADD:= mint serialize
FEATURES_QUAD:=
Expand All @@ -14,12 +15,14 @@ SDL2_PPA=http://ppa.launchpad.net/zoogie/sdl2-snapshots/ubuntu/pool/main/libs/li
ifeq ($(OS),Windows_NT)
EXCLUDES+= --exclude gfx-backend-metal
FEATURES_QUAD=vulkan
FEATURES_WARDEN+=vulkan
ifeq ($(TARGET),x86_64-pc-windows-gnu)
# No d3d12 support on GNU windows ATM
# context: https://github.com/gfx-rs/gfx/pull/1417
EXCLUDES+= --exclude gfx-backend-dx12
else
FEATURES_QUAD2=dx12
FEATURES_WARDEN+=dx12
endif
else
UNAME_S:=$(shell uname -s)
Expand All @@ -28,24 +31,32 @@ else
ifeq ($(UNAME_S),Linux)
EXCLUDES+= --exclude gfx-backend-metal
FEATURES_QUAD=vulkan
FEATURES_WARDEN+=vulkan
endif
ifeq ($(UNAME_S),Darwin)
EXCLUDES+= --exclude gfx-backend-vulkan
EXCLUDES+= --exclude quad-render
FEATURES_QUAD=metal
FEATURES_WARDEN+=metal
CMD_QUAD_RENDER=pwd
endif
endif


.PHONY: all check ex-hal-quad render ex-render-quad travis-sdl2
.PHONY: all check ex-hal-quad warden reftests render ex-render-quad travis-sdl2

all: check ex-hal-quad render ex-render-quad
all: check ex-hal-quad warden render ex-render-quad

check:
cargo check --all $(EXCLUDES)
cargo test --all $(EXCLUDES)

warden:
cd src/warden && cargo test

reftests: warden
cd src/warden && cargo run --bin reftest --features "$(FEATURES_WARDEN)"

render:
cd src/render && cargo test --features "$(FEATURES_RENDER)"
cd src/render && cargo test --features "$(FEATURES_RENDER) $(FEATURES_RENDER_ADD)"
Expand Down
2 changes: 1 addition & 1 deletion examples/hal/quad/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn main() {
accesses: i::Access::empty() .. (i::COLOR_ATTACHMENT_READ | i::COLOR_ATTACHMENT_WRITE),
};

device.create_renderpass(&[attachment], &[subpass], &[dependency])
device.create_render_pass(&[attachment], &[subpass], &[dependency])
};

//
Expand Down
59 changes: 59 additions & 0 deletions reftests/scenes/basic.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(
resources: {
"im-color": Image(
kind: D2(1, 1, Single),
num_levels: 1,
format: (R8_G8_B8_A8, Unorm),
usage: (bits: 4),
),
"pass": RenderPass(
attachments: {
"c": (
format: (R8_G8_B8_A8, Unorm),
ops: (load: Clear, store: Store),
layouts: (start: General, end: General),
),
},
subpasses: {
"main": (
colors: [("c", General)],
depth_stencil: None,
)
},
dependencies: [],
),
"im-color-view": ImageView(
image: "im-color",
format: (R8_G8_B8_A8, Unorm),
range: (
aspects: (bits: 1),
levels: (start: 0, end: 1),
layers: (start: 0, end: 1),
),
),
"fbo": Framebuffer(
pass: "pass",
views: {
"c": "im-color-view"
},
extent: (
width: 1,
height: 1,
depth: 1,
),
),
},
jobs: {
"empty": Graphics(
descriptors: {},
framebuffer: "fbo",
clear_values: [
Color(Float((0.8, 0.8, 0.8, 1.0))),
],
pass: ("pass", {
"main": (commands: [
]),
}),
),
},
)
8 changes: 8 additions & 0 deletions reftests/suite.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"basic": {
"render-pass-clear": (
jobs: ["empty"],
expect: ImageRow("im-color", 0, [204,204,204,255])
),
},
}
4 changes: 2 additions & 2 deletions src/backend/dx12/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ pub fn map_buffer_resource_state(access: buffer::Access) -> D3D12_RESOURCE_STATE
let mut state = D3D12_RESOURCE_STATE_COMMON;

if access.contains(buffer::TRANSFER_READ) {
state = state | D3D12_RESOURCE_STATE_COPY_SOURCE | D3D12_RESOURCE_STATE_RESOLVE_DEST;
state = state | D3D12_RESOURCE_STATE_COPY_SOURCE;
}
if access.contains(buffer::INDEX_BUFFER_READ) {
state = state | D3D12_RESOURCE_STATE_INDEX_BUFFER;
Expand Down Expand Up @@ -472,7 +472,7 @@ pub fn map_image_resource_state(access: image::Access, layout: image::ImageLayou
let mut state = D3D12_RESOURCE_STATE_COMMON;

if access.contains(image::TRANSFER_READ) {
state = state | D3D12_RESOURCE_STATE_COPY_SOURCE | D3D12_RESOURCE_STATE_RESOLVE_DEST;
state = state | D3D12_RESOURCE_STATE_COPY_SOURCE;
}
if access.contains(image::INPUT_ATTACHMENT_READ) {
state = state | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/dx12/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl d::Device<B> for Device {
})
}

fn create_renderpass(
fn create_render_pass(
&mut self,
attachments: &[pass::Attachment],
subpasses: &[pass::SubpassDesc],
Expand Down
4 changes: 3 additions & 1 deletion src/backend/dx12/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,9 @@ impl Instance {
}
}

impl core::Instance<Backend> for Instance {
impl core::Instance for Instance {
type Backend = Backend;

fn enumerate_adapters(&self) -> Vec<Adapter> {
// Enumerate adapters
let mut cur_index = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/backend/empty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl core::Device<Backend> for Device {
unimplemented!()
}

fn create_renderpass(&mut self, _: &[pass::Attachment], _: &[pass::SubpassDesc], _: &[pass::SubpassDependency]) -> () {
fn create_render_pass(&mut self, _: &[pass::Attachment], _: &[pass::SubpassDesc], _: &[pass::SubpassDependency]) -> () {
unimplemented!()
}

Expand Down Expand Up @@ -562,7 +562,8 @@ impl core::Swapchain<Backend> for Swapchain {
}

pub struct Instance;
impl core::Instance<Backend> for Instance {
impl core::Instance for Instance {
type Backend = Backend;
fn enumerate_adapters(&self) -> Vec<Adapter> {
Vec::new()
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/gl/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl d::Device<B> for Device {
})
}

fn create_renderpass(
fn create_render_pass(
&mut self,
attachments: &[pass::Attachment],
subpasses: &[pass::SubpassDesc],
Expand Down
6 changes: 4 additions & 2 deletions src/backend/gl/src/window/glutin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ impl core::Surface<B> for Surface {
}
}

impl core::Instance<B> for Surface {
impl core::Instance for Surface {
type Backend = B;
fn enumerate_adapters(&self) -> Vec<Adapter> {
unsafe { self.window.make_current().unwrap() };
let adapter = Adapter::new(|s| self.window.get_proc_address(s) as *const _);
Expand Down Expand Up @@ -142,7 +143,8 @@ pub fn config_context(

pub struct Headless(pub glutin::HeadlessContext);

impl core::Instance<B> for Headless {
impl core::Instance for Headless {
type Backend = B;
fn enumerate_adapters(&self) -> Vec<Adapter> {
unsafe { self.0.make_current().unwrap() };
let adapter = Adapter::new(|s| self.0.get_proc_address(s) as *const _);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/metal/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ impl core::Device<Backend> for Device {
&self.limits
}

fn create_renderpass(
fn create_render_pass(
&mut self,
attachments: &[pass::Attachment],
_subpasses: &[pass::SubpassDesc],
Expand Down
4 changes: 3 additions & 1 deletion src/backend/metal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ use core_graphics::geometry::CGRect;
pub struct Instance {
}

impl core::Instance<Backend> for Instance {
impl core::Instance for Instance {
type Backend = Backend;

fn enumerate_adapters(&self) -> Vec<Adapter> {
// TODO: enumerate all devices

Expand Down
2 changes: 1 addition & 1 deletion src/backend/vulkan/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl d::Device<B> for Device {
Ok(n::Memory { inner: memory, ptr })
}

fn create_renderpass(&mut self, attachments: &[pass::Attachment],
fn create_render_pass(&mut self, attachments: &[pass::Attachment],
subpasses: &[pass::SubpassDesc], dependencies: &[pass::SubpassDependency]) -> n::RenderPass
{
let map_subpass_ref = |pass: pass::SubpassRef| {
Expand Down
4 changes: 3 additions & 1 deletion src/backend/vulkan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ impl Instance {
}
}

impl core::Instance<Backend> for Instance {
impl core::Instance for Instance {
type Backend = Backend;

fn enumerate_adapters(&self) -> Vec<Adapter> {
self.raw.0.enumerate_physical_devices()
.expect("Unable to enumerate adapter")
Expand Down
2 changes: 1 addition & 1 deletion src/hal/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub trait Device<B: Backend>: Clone {
fn allocate_memory(&mut self, &MemoryType, size: u64) -> Result<B::Memory, OutOfMemory>;

///
fn create_renderpass(
fn create_render_pass(
&mut self,
&[pass::Attachment],
&[pass::SubpassDesc],
Expand Down
6 changes: 6 additions & 0 deletions src/hal/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ impl Swizzle {
pub const NO: Swizzle = Swizzle(Component::R, Component::G, Component::B, Component::A);
}

impl Default for Swizzle {
fn default() -> Self {
Self::NO
}
}

/// Complete run-time surface format.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature="serialize", derive(Serialize, Deserialize))]
Expand Down
6 changes: 4 additions & 2 deletions src/hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,11 @@ pub struct MemoryType {
}

/// Basic backend instance trait.
pub trait Instance<B: Backend> {
pub trait Instance {
/// Associated backend type of this instance.
type Backend: Backend;
/// Enumerate all available adapters.
fn enumerate_adapters(&self) -> Vec<B::Adapter>;
fn enumerate_adapters(&self) -> Vec<<Self::Backend as Backend>::Adapter>;
}

/// Different types of a specific API.
Expand Down
5 changes: 5 additions & 0 deletions src/hal/src/pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ impl AttachmentOps {
store,
}
}

fn whatever() -> Self {
Self::DONT_CARE
}
}

///
Expand All @@ -65,6 +69,7 @@ pub struct Attachment {
/// Load and store operations of the attachment
pub ops: AttachmentOps,
/// Load and store operations of the stencil aspect, if any
#[cfg_attr(feature = "serialize", serde(default = "AttachmentOps::whatever"))]
pub stencil_ops: AttachmentOps,
/// Initial and final image layouts of the renderpass.
pub layouts: Range<AttachmentLayout>,
Expand Down
2 changes: 1 addition & 1 deletion src/hal/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<B: Backend, C> CommandPool<B, C> {
/// You can only record to one command buffer per pool at the same time.
/// If more command buffers are requested than allocated, new buffers will be reserved.
/// The command buffer will be returned in 'recording' state.
pub fn acquire_command_buffer<'a>(&'a mut self) -> CommandBuffer<'a, B, C> {
pub fn acquire_command_buffer(&mut self) -> CommandBuffer<B, C> {
self.reserve(1);

let buffer = &mut self.buffers[self.next_buffer];
Expand Down
2 changes: 1 addition & 1 deletion src/hal/src/pso/input_assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub struct VertexBufferSet<'a, B: Backend>(

impl<'a, B: Backend> VertexBufferSet<'a, B> {
/// Create an empty set
pub fn new() -> VertexBufferSet<'a, B> {
pub fn new() -> Self {
VertexBufferSet(Vec::new())
}
}
4 changes: 2 additions & 2 deletions src/render/src/allocators/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<B: Backend> Allocator<B> for StackAllocator<B> {
device.mut_raw(), &buffer, usage);
let memory_type = device.find_usage_memory(inner.usage, requirements.type_mask)
.expect("could not find suitable memory");
let mut stack = inner.stacks.entry(memory_type.id)
let stack = inner.stacks.entry(memory_type.id)
.or_insert_with(|| ChunkStack::new(memory_type));
let (memory, offset, release) = stack.allocate(
device,
Expand All @@ -91,7 +91,7 @@ impl<B: Backend> Allocator<B> for StackAllocator<B> {
let requirements = device.mut_raw().get_image_requirements(&image);
let memory_type = device.find_usage_memory(inner.usage, requirements.type_mask)
.expect("could not find suitable memory");
let mut stack = inner.stacks.entry(memory_type.id)
let stack = inner.stacks.entry(memory_type.id)
.or_insert_with(|| ChunkStack::new(memory_type));
let (memory, offset, release) = stack.allocate(
device,
Expand Down
4 changes: 2 additions & 2 deletions src/render/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,13 @@ impl<B: Backend> Device<B> {
}

#[doc(hidden)]
pub fn create_renderpass_raw(
pub fn create_render_pass_raw(
&mut self,
attachments: &[core::pass::Attachment],
subpasses: &[core::pass::SubpassDesc],
dependencies: &[core::pass::SubpassDependency],
) -> handle::raw::RenderPass<B> {
let pass = self.raw.create_renderpass(attachments, subpasses, dependencies);
let pass = self.raw.create_render_pass(attachments, subpasses, dependencies);
RenderPass::new(pass, (), self.garbage.clone()).into()
}

Expand Down
2 changes: 1 addition & 1 deletion src/render/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ macro_rules! gfx_graphics_pipeline {
preserves: &[],
};

device.create_renderpass_raw(&attachments[..], &[subpass], &[])
device.create_render_pass_raw(&attachments[..], &[subpass], &[])
};

let mut pipeline_desc = cpso::GraphicsPipelineDesc::new(
Expand Down
Loading