mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Merge #186
186: Fix clear value filtering and integer support r=grovesNL a=kvark Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
/* Generated with cbindgen:0.8.6 */
|
||||
/* Generated with cbindgen:0.8.7 */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#define WGPU_LOCAL
|
||||
|
||||
/* Generated with cbindgen:0.8.6 */
|
||||
/* Generated with cbindgen:0.8.7 */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -263,7 +263,7 @@ pub fn command_encoder_begin_render_pass(
|
||||
};
|
||||
|
||||
let mut render_pass_cache = device.render_passes.lock();
|
||||
let render_pass = match render_pass_cache.entry(rp_key) {
|
||||
let render_pass = match render_pass_cache.entry(rp_key.clone()) {
|
||||
Entry::Occupied(e) => e.into_mut(),
|
||||
Entry::Vacant(e) => {
|
||||
let color_ids = [
|
||||
@@ -329,14 +329,42 @@ pub fn command_encoder_begin_render_pass(
|
||||
|
||||
let clear_values = color_attachments
|
||||
.iter()
|
||||
.map(|at| {
|
||||
//TODO: integer types?
|
||||
let value = hal::command::ClearColor::Float(conv::map_color(&at.clear_color));
|
||||
hal::command::ClearValueRaw::from(hal::command::ClearValue::Color(value))
|
||||
.zip(&rp_key.colors)
|
||||
.flat_map(|(at, key)| {
|
||||
match at.load_op {
|
||||
LoadOp::Load => None,
|
||||
LoadOp::Clear => {
|
||||
use hal::format::ChannelType;
|
||||
//TODO: validate sign/unsign and normalized ranges of the color values
|
||||
let value = match key.format.unwrap().base_format().1 {
|
||||
ChannelType::Unorm |
|
||||
ChannelType::Snorm |
|
||||
ChannelType::Ufloat |
|
||||
ChannelType::Sfloat |
|
||||
ChannelType::Uscaled |
|
||||
ChannelType::Sscaled |
|
||||
ChannelType::Srgb => {
|
||||
hal::command::ClearColor::Float(conv::map_color_f32(&at.clear_color))
|
||||
}
|
||||
ChannelType::Sint => {
|
||||
hal::command::ClearColor::Int(conv::map_color_i32(&at.clear_color))
|
||||
}
|
||||
ChannelType::Uint => {
|
||||
hal::command::ClearColor::Uint(conv::map_color_u32(&at.clear_color))
|
||||
}
|
||||
};
|
||||
Some(hal::command::ClearValueRaw::from(hal::command::ClearValue::Color(value)))
|
||||
}
|
||||
}
|
||||
})
|
||||
.chain(depth_stencil_attachment.map(|at| {
|
||||
let value = hal::command::ClearDepthStencil(at.clear_depth, at.clear_stencil);
|
||||
hal::command::ClearValueRaw::from(hal::command::ClearValue::DepthStencil(value))
|
||||
.chain(depth_stencil_attachment.and_then(|at| {
|
||||
match (at.depth_load_op, at.stencil_load_op) {
|
||||
(LoadOp::Load, LoadOp::Load) => None,
|
||||
(LoadOp::Clear, _) | (_, LoadOp::Clear) => {
|
||||
let value = hal::command::ClearDepthStencil(at.clear_depth, at.clear_stencil);
|
||||
Some(hal::command::ClearValueRaw::from(hal::command::ClearValue::DepthStencil(value)))
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
unsafe {
|
||||
|
||||
@@ -382,7 +382,7 @@ pub extern "C" fn wgpu_render_pass_set_blend_color(pass_id: RenderPassId, color:
|
||||
pass.blend_color_status = OptionalState::Set;
|
||||
|
||||
unsafe {
|
||||
pass.raw.set_blend_constants(conv::map_color(color));
|
||||
pass.raw.set_blend_constants(conv::map_color_f32(color));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -553,10 +553,18 @@ pub fn map_load_store_ops(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_color(color: &Color) -> hal::pso::ColorValue {
|
||||
pub fn map_color_f32(color: &Color) -> hal::pso::ColorValue {
|
||||
[color.r, color.g, color.b, color.a]
|
||||
}
|
||||
|
||||
pub fn map_color_i32(color: &Color) -> [i32; 4] {
|
||||
[color.r as i32, color.g as i32, color.b as i32, color.a as i32]
|
||||
}
|
||||
|
||||
pub fn map_color_u32(color: &Color) -> [u32; 4] {
|
||||
[color.r as u32, color.g as u32, color.b as u32, color.a as u32]
|
||||
}
|
||||
|
||||
pub fn map_filter(filter: resource::FilterMode) -> hal::image::Filter {
|
||||
match filter {
|
||||
resource::FilterMode::Nearest => hal::image::Filter::Nearest,
|
||||
|
||||
Reference in New Issue
Block a user