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

Out-of-pass image clears #2016

Merged
merged 5 commits into from
May 12, 2018
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
5 changes: 5 additions & 0 deletions reftests/local.ron
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
jobs: ["copy-image-buf"],
expect: Buffer("buffer.output", [52, 53, 54, 55]),
),
"clear-image": (
features: (bits: 0),
jobs: ["clear-image"],
expect: ImageRow("image.output", 0, [128, 128, 128, 128]),
),
"blit-image": (
features: (bits: 0),
jobs: ["blit-image"],
Expand Down
14 changes: 14 additions & 0 deletions reftests/scenes/transfer.ron
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@
],
),
),
"clear-image": Transfer(
ClearImage(
image: "image.output",
color: Float((0.5, 0.5, 0.5, 0.5)),
depth_stencil: (0.0, 0),
ranges: [
(
aspects: (bits: 0x1), //COLOR
levels: (start: 0, end: 1),
layers: (start: 0, end: 1),
),
],
),
),
"blit-image": Transfer(
BlitImage(
src: "image.input",
Expand Down
55 changes: 25 additions & 30 deletions src/backend/dx12/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
self.reset();
}

fn begin_render_pass_raw<T>(
fn begin_render_pass<T>(
&mut self,
render_pass: &n::RenderPass,
framebuffer: &n::Framebuffer,
Expand Down Expand Up @@ -1105,38 +1105,33 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
}
}

fn clear_color_image_raw(
fn clear_image<T>(
&mut self,
image: &n::Image,
_: image::Layout,
range: image::SubresourceRange,
value: com::ClearColorRaw,
) {
assert_eq!(range.aspects, Aspects::COLOR);
assert_eq!(range.levels, 0 .. 1); //TODO
for layer in range.layers {
let rtv = image.clear_cv[layer as usize];
self.clear_render_target_view(rtv, value, &[]);
}
}

fn clear_depth_stencil_image_raw(
&mut self,
image: &n::Image,
_layout: image::Layout,
range: image::SubresourceRange,
value: com::ClearDepthStencilRaw,
) {
assert!((Aspects::DEPTH | Aspects::STENCIL).contains(range.aspects));
assert_eq!(range.levels, 0 .. 1); //TODO
for layer in range.layers {
if range.aspects.contains(Aspects::DEPTH) {
let dsv = image.clear_dv[layer as usize];
self.clear_depth_stencil_view(dsv, Some(value.depth), None, &[]);
}
if range.aspects.contains(Aspects::STENCIL) {
let dsv = image.clear_sv[layer as usize];
self.clear_depth_stencil_view(dsv, None, Some(value.stencil as _), &[]);
color: com::ClearColorRaw,
depth_stencil: com::ClearDepthStencilRaw,
subresource_ranges: T,
) where
T: IntoIterator,
T::Item: Borrow<image::SubresourceRange>,
{
for subresource_range in subresource_ranges {
let sub = subresource_range.borrow();
assert_eq!(sub.levels, 0 .. 1); //TODO
for layer in sub.layers.clone() {
if sub.aspects.contains(Aspects::COLOR) {
let rtv = image.clear_cv[layer as usize];
self.clear_render_target_view(rtv, color, &[]);
}
if sub.aspects.contains(Aspects::DEPTH) {
let dsv = image.clear_dv[layer as usize];
self.clear_depth_stencil_view(dsv, Some(depth_stencil.depth), None, &[]);
}
if sub.aspects.contains(Aspects::STENCIL) {
let dsv = image.clear_sv[layer as usize];
self.clear_depth_stencil_view(dsv, None, Some(depth_stencil.stencil as _), &[]);
}
}
}
}
Expand Down
20 changes: 7 additions & 13 deletions src/backend/empty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,23 +434,17 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {
unimplemented!()
}

fn clear_color_image_raw(
fn clear_image<T>(
&mut self,
_: &(),
_: image::Layout,
_: image::SubresourceRange,
_: command::ClearColorRaw,
) {
unimplemented!()
}

fn clear_depth_stencil_image_raw(
&mut self,
_: &(),
_: image::Layout,
_: image::SubresourceRange,
_: command::ClearDepthStencilRaw,
) {
_: T,
) where
T: IntoIterator,
T::Item: Borrow<image::SubresourceRange>,
{
unimplemented!()
}

Expand Down Expand Up @@ -533,7 +527,7 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {
}


fn begin_render_pass_raw<T>(
fn begin_render_pass<T>(
&mut self,
_: &(),
_: &(),
Expand Down
30 changes: 12 additions & 18 deletions src/backend/gl/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {
unimplemented!()
}

fn begin_render_pass_raw<T>(
fn begin_render_pass<T>(
&mut self,
render_pass: &n::RenderPass,
framebuffer: &n::FrameBuffer,
Expand Down Expand Up @@ -609,13 +609,17 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {
// TODO
}

fn clear_color_image_raw(
fn clear_image<T>(
&mut self,
image: &n::Image,
_: image::Layout,
_range: image::SubresourceRange,
value: command::ClearColorRaw,
) {
color: command::ClearColorRaw,
_depth_stencil: command::ClearDepthStencilRaw,
_subresource_ranges: T,
) where
T: IntoIterator,
T::Item: Borrow<image::SubresourceRange>,
{
// TODO: clearing strategies
// 1. < GL 3.0 / GL ES 3.0: glClear
// 2. < GL 4.4: glClearBuffer
Expand All @@ -635,22 +639,12 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {
match image.channel {
ChannelType::Unorm | ChannelType::Inorm | ChannelType::Ufloat |
ChannelType::Float | ChannelType::Srgb | ChannelType::Uscaled |
ChannelType::Iscaled => self.push_cmd(Command::ClearBufferColorF(0, unsafe { value.float32 })),
ChannelType::Uint => self.push_cmd(Command::ClearBufferColorU(0, unsafe { value.uint32 })),
ChannelType::Int => self.push_cmd(Command::ClearBufferColorI(0, unsafe { value.int32 })),
ChannelType::Iscaled => self.push_cmd(Command::ClearBufferColorF(0, unsafe { color.float32 })),
ChannelType::Uint => self.push_cmd(Command::ClearBufferColorU(0, unsafe { color.uint32 })),
ChannelType::Int => self.push_cmd(Command::ClearBufferColorI(0, unsafe { color.int32 })),
}
}

fn clear_depth_stencil_image_raw(
&mut self,
_image: &n::Image,
_: image::Layout,
_range: image::SubresourceRange,
_value: command::ClearDepthStencilRaw,
) {
unimplemented!()
}

fn clear_attachments<T, U>(&mut self, _: T, _: U)
where
T: IntoIterator,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/metal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name = "gfx_backend_metal"
gfx-hal = { path = "../../hal", version = "0.1" }
log = "0.4"
winit = { version = "0.13", optional = true }
metal-rs = "0.9.2"
metal-rs = "0.9.3"
foreign-types = "0.3"
objc = "0.2"
block = "0.1"
Expand Down
38 changes: 38 additions & 0 deletions src/backend/metal/shaders/commands.metal
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
#include <metal_stdlib>
using namespace metal;

// -------------- Image Clears -------------- //

typedef struct {
float4 coords [[attribute(0)]];
} ClearAttributes;

typedef struct {
float4 position [[position]];
uint layer [[render_target_array_index]];
} ClearVertexData;

vertex ClearVertexData vs_clear(ClearAttributes in [[stage_in]]) {
float4 pos = { 0.0, 0.0, 0.0f, 1.0f };
pos.xy = in.coords.xy * 2.0 - 1.0;
return ClearVertexData { pos, uint(in.coords.z) };
}

fragment float4 ps_blit_float(
ClearVertexData in [[stage_in]],
constant float4 &value [[ buffer(0) ]]
) {
return value;
}

fragment int4 ps_blit_int(
ClearVertexData in [[stage_in]],
constant int4 &value [[ buffer(0) ]]
) {
return value;
}

fragment uint4 ps_blit_uint(
ClearVertexData in [[stage_in]],
constant uint4 &value [[ buffer(0) ]]
) {
return value;
}

// -------------- Image Blits -------------- //

typedef struct {
Expand Down
Loading