39: Remove generic and option from render pass descriptor r=kvark a=grovesNL

- Temporarily lock cbindgen to known working revision until a new version is published
- Remove generic and `Option` from `RenderPassDescriptor`, map between wgpu/wgpu-native types like other descriptors, and add a missing length field (this appears necessary to generate bindings)
- Regenerate bindings (using `a7be40c65 2018-12-26`, earlier versions should work too)
- Remove `+nightly` for bindings generation from Makefile, because newer nightlies won't work at the moment
- Fix typo in Makefile `clean`

Co-authored-by: Joshua Groves <josh@joshgroves.com>
This commit is contained in:
bors[bot] 2019-01-21 03:08:18 +00:00
commit 8f312af8e6
7 changed files with 138 additions and 56 deletions

6
Cargo.lock generated
View File

@ -105,7 +105,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cbindgen"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "git+https://github.com/eqrion/cbindgen?rev=2932819#2932819567de0b1c83432af4070105a13502e471"
dependencies = [
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1079,7 +1079,7 @@ dependencies = [
name = "wgpu-bindings"
version = "0.1.0"
dependencies = [
"cbindgen 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"cbindgen 0.6.8 (git+https://github.com/eqrion/cbindgen?rev=2932819)",
]
[[package]]
@ -1208,7 +1208,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d"
"checksum cbindgen 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "89ae8c2f780373f1842acb548fa53c7fd3acd6ca27d47966c69351719b239eae"
"checksum cbindgen 0.6.8 (git+https://github.com/eqrion/cbindgen?rev=2932819)" = "<none>"
"checksum cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4a8b715cb4597106ea87c7c84b2f1d452c7492033765df7f32651e66fcf749"
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"

View File

@ -44,7 +44,7 @@ doc:
cargo doc --all
clear:
cargo clear
cargo clean
rm wgpu-bindings/wgpu.h
lib-native: Cargo.lock wgpu-native/Cargo.toml $(wildcard wgpu-native/**/*.rs)
@ -54,7 +54,7 @@ lib-rust: Cargo.lock wgpu-rs/Cargo.toml $(wildcard wgpu-rs/**/*.rs)
cargo build --manifest-path wgpu-rs/Cargo.toml --features $(FEATURE_RUST)
wgpu-bindings/wgpu.h: Cargo.lock wgpu-bindings/src/*.rs lib-native
cargo +nightly run --manifest-path wgpu-bindings/Cargo.toml
cargo run --manifest-path wgpu-bindings/Cargo.toml
examples-native: lib-native wgpu-bindings/wgpu.h $(wildcard wgpu-native/**/*.c)
$(MAKE) -C examples

1
examples/vendor/glfw vendored Submodule

@ -0,0 +1 @@
Subproject commit 29d8ca4ce4aef8e0afca62b8ace9ee18a24a9ffd

View File

@ -11,4 +11,4 @@ edition = "2018"
default = []
[dependencies]
cbindgen = "0.6.8"
cbindgen = { git = "https://github.com/eqrion/cbindgen", rev = "2932819" }

View File

@ -4,9 +4,10 @@
typedef void *WGPUId;
#endif
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
typedef enum {
WGPUBindingType_UniformBuffer = 0,
@ -50,6 +51,11 @@ typedef enum {
WGPUCompareFunction_Always = 7,
} WGPUCompareFunction;
typedef enum {
WGPULoadOp_Clear = 0,
WGPULoadOp_Load = 1,
} WGPULoadOp;
typedef enum {
WGPUPowerPreference_Default = 0,
WGPUPowerPreference_LowPower = 1,
@ -81,6 +87,10 @@ typedef enum {
WGPUStencilOperation_DecrementWrap = 7,
} WGPUStencilOperation;
typedef enum {
WGPUStoreOp_Store = 0,
} WGPUStoreOp;
typedef enum {
WGPUTextureDimension_D1,
WGPUTextureDimension_D2,
@ -103,8 +113,6 @@ typedef enum {
WGPUTextureViewDimension_D3,
} WGPUTextureViewDimension;
typedef struct WGPURenderPassDescriptor_TextureViewId WGPURenderPassDescriptor_TextureViewId;
typedef WGPUId WGPUDeviceId;
typedef WGPUId WGPUAdapterId;
@ -123,6 +131,38 @@ typedef WGPUId WGPUCommandBufferId;
typedef WGPUId WGPURenderPassId;
typedef WGPUId WGPUTextureViewId;
typedef struct {
float r;
float g;
float b;
float a;
} WGPUColor;
typedef struct {
WGPUTextureViewId attachment;
WGPULoadOp load_op;
WGPUStoreOp store_op;
WGPUColor clear_color;
} WGPURenderPassColorAttachmentDescriptor_TextureViewId;
typedef struct {
WGPUTextureViewId attachment;
WGPULoadOp depth_load_op;
WGPUStoreOp depth_store_op;
float clear_depth;
WGPULoadOp stencil_load_op;
WGPUStoreOp stencil_store_op;
uint32_t clear_stencil;
} WGPURenderPassDepthStencilAttachmentDescriptor_TextureViewId;
typedef struct {
const WGPURenderPassColorAttachmentDescriptor_TextureViewId *color_attachments;
uintptr_t color_attachments_length;
const WGPURenderPassDepthStencilAttachmentDescriptor_TextureViewId *depth_stencil_attachment;
} WGPURenderPassDescriptor;
typedef WGPUId WGPUBindGroupId;
typedef WGPUId WGPUComputePipelineId;
@ -231,6 +271,19 @@ typedef struct {
WGPUByteArray code;
} WGPUShaderModuleDescriptor;
typedef WGPUId WGPUSwapChainId;
typedef WGPUId WGPUSurfaceId;
typedef uint32_t WGPUTextureUsageFlags;
typedef struct {
WGPUTextureUsageFlags usage;
WGPUTextureFormat format;
uint32_t width;
uint32_t height;
} WGPUSwapChainDescriptor;
typedef WGPUId WGPUTextureId;
typedef struct {
@ -239,8 +292,6 @@ typedef struct {
uint32_t depth;
} WGPUExtent3d;
typedef uint32_t WGPUTextureUsageFlags;
typedef struct {
WGPUExtent3d size;
uint32_t array_size;
@ -255,7 +306,10 @@ typedef struct {
WGPUPowerPreference power_preference;
} WGPUAdapterDescriptor;
typedef WGPUId WGPUTextureViewId;
typedef struct {
WGPUTextureId texture_id;
WGPUTextureViewId view_id;
} WGPUSwapChainOutput;
typedef uint32_t WGPUTextureAspectFlags;
@ -337,13 +391,17 @@ typedef struct {
#define WGPUTextureUsageFlags_TRANSFER_SRC 1
#define WGPUTrackPermit_EXTEND (WGPUTrackPermit){ .bits = 1 }
#define WGPUTrackPermit_REPLACE (WGPUTrackPermit){ .bits = 2 }
WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id,
const WGPUDeviceDescriptor *_desc);
WGPUComputePassId wgpu_command_buffer_begin_compute_pass(WGPUCommandBufferId command_buffer_id);
WGPURenderPassId wgpu_command_buffer_begin_render_pass(WGPUCommandBufferId command_buffer_id,
WGPURenderPassDescriptor_TextureViewId desc);
WGPURenderPassDescriptor desc);
void wgpu_compute_pass_dispatch(WGPUComputePassId pass_id, uint32_t x, uint32_t y, uint32_t z);
@ -378,6 +436,10 @@ WGPURenderPipelineId wgpu_device_create_render_pipeline(WGPUDeviceId device_id,
WGPUShaderModuleId wgpu_device_create_shader_module(WGPUDeviceId device_id,
const WGPUShaderModuleDescriptor *desc);
WGPUSwapChainId wgpu_device_create_swap_chain(WGPUDeviceId device_id,
WGPUSurfaceId surface_id,
const WGPUSwapChainDescriptor *desc);
WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextureDescriptor *desc);
WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id);
@ -391,6 +453,10 @@ void wgpu_queue_submit(WGPUQueueId queue_id,
WGPUCommandBufferId wgpu_render_pass_end_pass(WGPURenderPassId pass_id);
WGPUSwapChainOutput wgpu_swap_chain_get_next_texture(WGPUSwapChainId swap_chain_id);
void wgpu_swap_chain_present(WGPUSwapChainId swap_chain_id);
WGPUTextureViewId wgpu_texture_create_default_texture_view(WGPUTextureId texture_id);
WGPUTextureViewId wgpu_texture_create_texture_view(WGPUTextureId texture_id,

View File

@ -25,6 +25,7 @@ use log::trace;
use std::collections::hash_map::Entry;
use std::ops::Range;
use std::slice;
use std::thread::ThreadId;
@ -61,9 +62,10 @@ pub struct RenderPassDepthStencilAttachmentDescriptor<T> {
}
#[repr(C)]
pub struct RenderPassDescriptor<'a, T: 'a> {
pub color_attachments: &'a [RenderPassColorAttachmentDescriptor<T>],
pub depth_stencil_attachment: Option<RenderPassDepthStencilAttachmentDescriptor<T>>,
pub struct RenderPassDescriptor {
pub color_attachments: *const RenderPassColorAttachmentDescriptor<TextureViewId>,
pub color_attachments_length: usize,
pub depth_stencil_attachment: *const RenderPassDepthStencilAttachmentDescriptor<TextureViewId>,
}
#[repr(C)]
@ -147,7 +149,7 @@ pub struct CommandBufferDescriptor {}
#[no_mangle]
pub extern "C" fn wgpu_command_buffer_begin_render_pass(
command_buffer_id: CommandBufferId,
desc: RenderPassDescriptor<TextureViewId>,
desc: RenderPassDescriptor,
) -> RenderPassId {
let mut cmb_guard = HUB.command_buffers.write();
let cmb = cmb_guard.get_mut(command_buffer_id);
@ -164,35 +166,42 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
}
let mut extent = None;
let color_attachments = unsafe {
slice::from_raw_parts(
desc.color_attachments,
desc.color_attachments_length,
)
};
let depth_stencil_attachment = unsafe {
desc.depth_stencil_attachment.as_ref()
};
let rp_key = {
let tracker = &mut cmb.texture_tracker;
let swap_chain_links = &mut cmb.swap_chain_links;
let depth_stencil_key = match desc.depth_stencil_attachment {
Some(ref at) => {
let view = view_guard.get(at.attachment);
if let Some(ex) = extent {
assert_eq!(ex, view.extent);
} else {
extent = Some(view.extent);
}
let query = tracker.query(&view.texture_id, TextureUsageFlags::empty());
let (_, layout) = conv::map_texture_state(
query.usage,
hal::format::Aspects::DEPTH | hal::format::Aspects::STENCIL,
);
Some(hal::pass::Attachment {
format: Some(conv::map_texture_format(view.format)),
samples: view.samples,
ops: conv::map_load_store_ops(at.depth_load_op, at.depth_store_op),
stencil_ops: conv::map_load_store_ops(at.stencil_load_op, at.stencil_store_op),
layouts: layout..layout,
})
let depth_stencil_key = depth_stencil_attachment.map(|at| {
let view = view_guard.get(at.attachment);
if let Some(ex) = extent {
assert_eq!(ex, view.extent);
} else {
extent = Some(view.extent);
}
None => None,
};
let query = tracker.query(&view.texture_id, TextureUsageFlags::empty());
let (_, layout) = conv::map_texture_state(
query.usage,
hal::format::Aspects::DEPTH | hal::format::Aspects::STENCIL,
);
hal::pass::Attachment {
format: Some(conv::map_texture_format(view.format)),
samples: view.samples,
ops: conv::map_load_store_ops(at.depth_load_op, at.depth_store_op),
stencil_ops: conv::map_load_store_ops(at.stencil_load_op, at.stencil_store_op),
layouts: layout..layout,
}
});
let color_keys = desc.color_attachments.iter().map(|at| {
let color_keys = color_attachments.iter().map(|at| {
let view = view_guard.get(at.attachment);
if view.is_owned_by_swap_chain {
@ -243,13 +252,13 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
(3, hal::image::Layout::ColorAttachmentOptimal),
];
let depth_id = (
desc.color_attachments.len(),
color_attachments.len(),
hal::image::Layout::DepthStencilAttachmentOptimal,
);
let subpass = hal::pass::SubpassDesc {
colors: &color_ids[..desc.color_attachments.len()],
depth_stencil: desc.depth_stencil_attachment.as_ref().map(|_| &depth_id),
colors: &color_ids[..color_attachments.len()],
depth_stencil: depth_stencil_attachment.map(|_| &depth_id),
inputs: &[],
resolves: &[],
preserves: &[],
@ -267,14 +276,11 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
let mut framebuffer_cache = device.framebuffers.lock();
let fb_key = FramebufferKey {
attachments: desc
.color_attachments
attachments: color_attachments
.iter()
.map(|at| WeaklyStored(at.attachment))
.chain(
desc.depth_stencil_attachment
.as_ref()
.map(|at| WeaklyStored(at.attachment)),
depth_stencil_attachment.map(|at| WeaklyStored(at.attachment)),
)
.collect(),
};
@ -308,15 +314,15 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
h: ex.height as _,
}
};
let clear_values = desc
.color_attachments
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))
})
.chain(desc.depth_stencil_attachment.map(|at| {
.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))
}));

View File

@ -11,7 +11,7 @@ pub use wgn::{
Color, ColorWriteFlags, CommandBufferDescriptor, DepthStencilStateDescriptor, DeviceDescriptor,
Extensions, Extent3d, LoadOp, Origin3d, PowerPreference, PrimitiveTopology,
RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
RenderPassDescriptor, ShaderModuleDescriptor, ShaderStage, ShaderStageFlags, StoreOp,
ShaderModuleDescriptor, ShaderStage, ShaderStageFlags, StoreOp,
TextureDescriptor, TextureDimension, TextureFormat, TextureUsageFlags, TextureViewDescriptor,
SwapChainDescriptor,
};
@ -122,6 +122,11 @@ pub struct RenderPipelineDescriptor<'a> {
pub depth_stencil_state: &'a DepthStencilState,
}
pub struct RenderPassDescriptor<'a> {
pub color_attachments: &'a [RenderPassColorAttachmentDescriptor<&'a TextureView>],
pub depth_stencil_attachment: Option<RenderPassDepthStencilAttachmentDescriptor<&'a TextureView>>,
}
impl Instance {
pub fn new() -> Self {
Instance {
@ -295,7 +300,7 @@ impl Texture {
}
impl CommandBuffer {
pub fn begin_render_pass(&mut self, desc: &RenderPassDescriptor<&TextureView>) -> RenderPass {
pub fn begin_render_pass(&mut self, desc: &RenderPassDescriptor) -> RenderPass {
let colors = desc
.color_attachments
.iter()
@ -322,9 +327,13 @@ impl CommandBuffer {
RenderPass {
id: wgn::wgpu_command_buffer_begin_render_pass(
self.id,
RenderPassDescriptor {
color_attachments: &colors,
depth_stencil_attachment: depth_stencil,
wgn::RenderPassDescriptor {
color_attachments: colors.as_ptr(),
color_attachments_length: colors.len(),
depth_stencil_attachment: depth_stencil
.as_ref()
.map(|at| at as *const _)
.unwrap_or(ptr::null()),
},
),
parent: self,