mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 00:03:29 +00:00
Merge #57
57: Command encoder interface r=grovesNL a=kvark Implements https://github.com/gpuweb/gpuweb/pull/203 Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
This commit is contained in:
commit
edef343439
@ -14,5 +14,4 @@ before_install:
|
||||
|
||||
script:
|
||||
- cargo test
|
||||
- cargo build --manifest-path wgpu-native/Cargo.toml --features remote
|
||||
- cargo build
|
||||
- cargo check --manifest-path wgpu-native/Cargo.toml --features remote
|
||||
|
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -131,8 +131,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cbindgen"
|
||||
version = "0.6.8"
|
||||
source = "git+https://github.com/eqrion/cbindgen?rev=2932819#2932819567de0b1c83432af4070105a13502e471"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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)",
|
||||
@ -459,7 +459,6 @@ dependencies = [
|
||||
"glsl-to-spirv 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wgpu 0.1.0",
|
||||
"wgpu-native 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1267,7 +1266,7 @@ dependencies = [
|
||||
name = "wgpu-bindings"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cbindgen 0.6.8 (git+https://github.com/eqrion/cbindgen?rev=2932819)",
|
||||
"cbindgen 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1409,7 +1408,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab"
|
||||
"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40"
|
||||
"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb"
|
||||
"checksum cbindgen 0.6.8 (git+https://github.com/eqrion/cbindgen?rev=2932819)" = "<none>"
|
||||
"checksum cbindgen 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "32e01024aaf5390d6a8145047371a4f5b0063a14c1e411bc731353bd2278ca44"
|
||||
"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 cgmath 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "283944cdecc44bf0b8dd010ec9af888d3b4f142844fdbe026c20ef68148d6fe7"
|
||||
|
9
Makefile
9
Makefile
@ -32,7 +32,7 @@ endif
|
||||
|
||||
.PHONY: all check test doc clear lib-native lib-rust examples-native examples-rust
|
||||
|
||||
all: examples-native examples-rust
|
||||
all: examples-native examples-rust examples-gfx
|
||||
|
||||
check:
|
||||
cargo check --all
|
||||
@ -57,7 +57,10 @@ wgpu-bindings/wgpu.h: Cargo.lock wgpu-bindings/src/*.rs lib-native
|
||||
cargo +nightly-2018-12-27 run --manifest-path wgpu-bindings/Cargo.toml
|
||||
|
||||
examples-native: lib-native wgpu-bindings/wgpu.h $(wildcard wgpu-native/**/*.c)
|
||||
$(MAKE) -C examples
|
||||
#$(MAKE) -C examples
|
||||
|
||||
examples-rust: lib-rust examples/Cargo.toml $(wildcard wgpu-native/**/*.rs)
|
||||
cargo build --manifest-path examples/Cargo.toml --bin hello_triangle --features $(FEATURE_RUST)
|
||||
cargo build --manifest-path examples/Cargo.toml --features winit,$(FEATURE_RUST)
|
||||
|
||||
examples-gfx: lib-rust gfx-examples/Cargo.toml $(wildcard gfx-examples/*.rs)
|
||||
cargo build --manifest-path gfx-examples/Cargo.toml --features $(FEATURE_RUST)
|
||||
|
@ -18,10 +18,10 @@ path = "hello_compute_rust/main.rs"
|
||||
[features]
|
||||
default = []
|
||||
remote = ["wgpu-native/remote"]
|
||||
metal = ["wgpu-native/gfx-backend-metal"]
|
||||
dx11 = ["wgpu-native/gfx-backend-dx11"]
|
||||
dx12 = ["wgpu-native/gfx-backend-dx12"]
|
||||
vulkan = ["wgpu-native/gfx-backend-vulkan"]
|
||||
metal = ["wgpu/metal"]
|
||||
dx11 = ["wgpu/dx11"]
|
||||
dx12 = ["wgpu/dx12"]
|
||||
vulkan = ["wgpu/vulkan"]
|
||||
|
||||
[dependencies]
|
||||
wgpu-native = { path = "../wgpu-native" }
|
||||
|
@ -86,22 +86,18 @@ fn main() {
|
||||
},
|
||||
});
|
||||
|
||||
let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor { todo: 0 });
|
||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 });
|
||||
encoder.copy_buffer_tobuffer(&staging_buffer, 0, &storage_buffer, 0, size);
|
||||
{
|
||||
cmd_buf.copy_buffer_tobuffer(&staging_buffer, 0, &storage_buffer, 0, size);
|
||||
}
|
||||
{
|
||||
let mut cpass = cmd_buf.begin_compute_pass();
|
||||
let mut cpass = encoder.begin_compute_pass();
|
||||
cpass.set_pipeline(&compute_pipeline);
|
||||
cpass.set_bind_group(0, &bind_group);
|
||||
cpass.dispatch(numbers.len() as u32, 1, 1);
|
||||
cpass.end_pass();
|
||||
}
|
||||
{
|
||||
cmd_buf.copy_buffer_tobuffer(&storage_buffer, 0, &staging_buffer, 0, size);
|
||||
}
|
||||
encoder.copy_buffer_tobuffer(&storage_buffer, 0, &staging_buffer, 0, size);
|
||||
|
||||
// TODO: read the results back out of the staging buffer
|
||||
|
||||
device.get_queue().submit(&[cmd_buf]);
|
||||
device.get_queue().submit(&[encoder.finish()]);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
extern crate env_logger;
|
||||
extern crate wgpu;
|
||||
extern crate wgpu_native;
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
@ -58,7 +57,7 @@ fn main() {
|
||||
vertex_buffers: &[],
|
||||
});
|
||||
|
||||
use wgpu_native::winit::{ControlFlow, Event, ElementState, EventsLoop, KeyboardInput, Window, WindowEvent, VirtualKeyCode};
|
||||
use wgpu::winit::{ControlFlow, Event, ElementState, EventsLoop, KeyboardInput, Window, WindowEvent, VirtualKeyCode};
|
||||
|
||||
let mut events_loop = EventsLoop::new();
|
||||
let window = Window::new(&events_loop).unwrap();
|
||||
@ -96,9 +95,9 @@ fn main() {
|
||||
}
|
||||
|
||||
let frame = swap_chain.get_next_texture();
|
||||
let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor { todo: 0 });
|
||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 });
|
||||
{
|
||||
let mut rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
@ -114,7 +113,7 @@ fn main() {
|
||||
|
||||
device
|
||||
.get_queue()
|
||||
.submit(&[cmd_buf]);
|
||||
.submit(&[encoder.finish()]);
|
||||
|
||||
ControlFlow::Continue
|
||||
});
|
||||
|
@ -14,13 +14,12 @@ path = "src/cube.rs"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
metal = ["wgpu-native/gfx-backend-metal"]
|
||||
dx11 = ["wgpu-native/gfx-backend-dx11"]
|
||||
dx12 = ["wgpu-native/gfx-backend-dx12"]
|
||||
vulkan = ["wgpu-native/gfx-backend-vulkan"]
|
||||
metal = ["wgpu/metal"]
|
||||
dx11 = ["wgpu/dx11"]
|
||||
dx12 = ["wgpu/dx12"]
|
||||
vulkan = ["wgpu/vulkan"]
|
||||
|
||||
[dependencies]
|
||||
wgpu-native = { path = "../wgpu-native" }
|
||||
wgpu = { path = "../wgpu-rs", features = ["winit"] }
|
||||
cgmath = "0.17"
|
||||
env_logger = "0.5"
|
||||
|
@ -95,7 +95,7 @@ impl framework::Example for Cube {
|
||||
fn init(device: &mut wgpu::Device, sc_desc: &wgpu::SwapChainDescriptor) -> Self {
|
||||
use std::mem;
|
||||
|
||||
let mut init_command_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor {
|
||||
let mut init_encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
todo: 0,
|
||||
});
|
||||
|
||||
@ -158,7 +158,7 @@ impl framework::Example for Cube {
|
||||
usage: wgpu::BufferUsageFlags::TRANSFER_SRC | wgpu::BufferUsageFlags::TRANSFER_DST
|
||||
});
|
||||
temp_buf.set_sub_data(0, &texels);
|
||||
init_command_buf.copy_buffer_to_texture(
|
||||
init_encoder.copy_buffer_to_texture(
|
||||
wgpu::BufferCopyView {
|
||||
buffer: &temp_buf,
|
||||
offset: 0,
|
||||
@ -287,6 +287,7 @@ impl framework::Example for Cube {
|
||||
});
|
||||
|
||||
// Done
|
||||
let init_command_buf = init_encoder.finish();
|
||||
device.get_queue().submit(&[init_command_buf]);
|
||||
Cube {
|
||||
vertex_buf,
|
||||
@ -297,13 +298,13 @@ impl framework::Example for Cube {
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, _event: framework::winit::WindowEvent) {
|
||||
fn update(&mut self, _event: wgpu::winit::WindowEvent) {
|
||||
}
|
||||
|
||||
fn render(&mut self, frame: &wgpu::SwapChainOutput, device: &mut wgpu::Device) {
|
||||
let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor { todo: 0 });
|
||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 });
|
||||
{
|
||||
let mut rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
@ -322,7 +323,7 @@ impl framework::Example for Cube {
|
||||
|
||||
device
|
||||
.get_queue()
|
||||
.submit(&[cmd_buf]);
|
||||
.submit(&[encoder.finish()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
pub use wgpu_native::winit;
|
||||
|
||||
use log::info;
|
||||
|
||||
|
||||
@ -32,12 +30,12 @@ pub fn load_glsl(name: &str, stage: wgpu::ShaderStage) -> Vec<u8> {
|
||||
|
||||
pub trait Example {
|
||||
fn init(device: &mut wgpu::Device, sc_desc: &wgpu::SwapChainDescriptor) -> Self;
|
||||
fn update(&mut self, event: winit::WindowEvent);
|
||||
fn update(&mut self, event: wgpu::winit::WindowEvent);
|
||||
fn render(&mut self, frame: &wgpu::SwapChainOutput, device: &mut wgpu::Device);
|
||||
}
|
||||
|
||||
pub fn run<E: Example>(title: &str) {
|
||||
use wgpu_native::winit::{
|
||||
use wgpu::winit::{
|
||||
Event, ElementState, EventsLoop, KeyboardInput, Window, WindowEvent, VirtualKeyCode
|
||||
};
|
||||
|
||||
|
@ -11,4 +11,4 @@ edition = "2018"
|
||||
default = []
|
||||
|
||||
[dependencies]
|
||||
cbindgen = { git = "https://github.com/eqrion/cbindgen", rev = "2932819" }
|
||||
cbindgen = "0.7.1"
|
||||
|
@ -164,9 +164,39 @@ typedef struct {
|
||||
|
||||
typedef WGPUId WGPUBufferId;
|
||||
|
||||
typedef WGPUId WGPUCommandBufferId;
|
||||
|
||||
typedef struct {
|
||||
WGPUBufferId buffer;
|
||||
uint32_t offset;
|
||||
uint32_t row_pitch;
|
||||
uint32_t image_height;
|
||||
} WGPUBufferCopyView;
|
||||
|
||||
typedef WGPUId WGPUTextureId;
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} WGPUOrigin3d;
|
||||
|
||||
typedef struct {
|
||||
WGPUTextureId texture;
|
||||
uint32_t level;
|
||||
uint32_t slice;
|
||||
WGPUOrigin3d origin;
|
||||
} WGPUTextureCopyView;
|
||||
|
||||
typedef struct {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t depth;
|
||||
} WGPUExtent3d;
|
||||
|
||||
typedef WGPUId WGPUComputePassId;
|
||||
|
||||
typedef WGPUId WGPUCommandBufferId;
|
||||
typedef WGPUCommandBufferId WGPUCommandEncoderId;
|
||||
|
||||
typedef WGPUId WGPURenderPassId;
|
||||
|
||||
@ -202,34 +232,6 @@ typedef struct {
|
||||
const WGPURenderPassDepthStencilAttachmentDescriptor_TextureViewId *depth_stencil_attachment;
|
||||
} WGPURenderPassDescriptor;
|
||||
|
||||
typedef struct {
|
||||
WGPUBufferId buffer;
|
||||
uint32_t offset;
|
||||
uint32_t row_pitch;
|
||||
uint32_t image_height;
|
||||
} WGPUBufferCopyView;
|
||||
|
||||
typedef WGPUId WGPUTextureId;
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} WGPUOrigin3d;
|
||||
|
||||
typedef struct {
|
||||
WGPUTextureId texture;
|
||||
uint32_t level;
|
||||
uint32_t slice;
|
||||
WGPUOrigin3d origin;
|
||||
} WGPUTextureCopyView;
|
||||
|
||||
typedef struct {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t depth;
|
||||
} WGPUExtent3d;
|
||||
|
||||
typedef WGPUId WGPUBindGroupId;
|
||||
|
||||
typedef WGPUId WGPUComputePipelineId;
|
||||
@ -323,7 +325,22 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
uint32_t todo;
|
||||
} WGPUCommandBufferDescriptor;
|
||||
} WGPUCommandEncoderDescriptor;
|
||||
|
||||
typedef WGPUId WGPUPipelineLayoutId;
|
||||
|
||||
typedef WGPUId WGPUShaderModuleId;
|
||||
|
||||
typedef struct {
|
||||
WGPUShaderModuleId module;
|
||||
WGPUShaderStage stage;
|
||||
const char *entry_point;
|
||||
} WGPUPipelineStageDescriptor;
|
||||
|
||||
typedef struct {
|
||||
WGPUPipelineLayoutId layout;
|
||||
WGPUPipelineStageDescriptor compute_stage;
|
||||
} WGPUComputePipelineDescriptor;
|
||||
|
||||
typedef WGPUId WGPUDepthStencilStateId;
|
||||
|
||||
@ -343,8 +360,6 @@ typedef struct {
|
||||
uint32_t stencil_write_mask;
|
||||
} WGPUDepthStencilStateDescriptor;
|
||||
|
||||
typedef WGPUId WGPUPipelineLayoutId;
|
||||
|
||||
typedef struct {
|
||||
const WGPUBindGroupLayoutId *bind_group_layouts;
|
||||
uintptr_t bind_group_layouts_length;
|
||||
@ -352,14 +367,6 @@ typedef struct {
|
||||
|
||||
typedef WGPUId WGPURenderPipelineId;
|
||||
|
||||
typedef WGPUId WGPUShaderModuleId;
|
||||
|
||||
typedef struct {
|
||||
WGPUShaderModuleId module;
|
||||
WGPUShaderStage stage;
|
||||
const char *entry_point;
|
||||
} WGPUPipelineStageDescriptor;
|
||||
|
||||
typedef struct {
|
||||
WGPUTextureFormat format;
|
||||
uint32_t samples;
|
||||
@ -448,7 +455,7 @@ typedef struct {
|
||||
WGPUTextureUsageFlags usage;
|
||||
} WGPUTextureDescriptor;
|
||||
|
||||
typedef WGPUId WGPUQueueId;
|
||||
typedef WGPUDeviceId WGPUQueueId;
|
||||
|
||||
typedef struct {
|
||||
WGPUPowerPreference power_preference;
|
||||
@ -553,11 +560,6 @@ void wgpu_buffer_set_sub_data(WGPUBufferId buffer_id,
|
||||
uint32_t count,
|
||||
const uint8_t *data);
|
||||
|
||||
WGPUComputePassId wgpu_command_buffer_begin_compute_pass(WGPUCommandBufferId command_buffer_id);
|
||||
|
||||
WGPURenderPassId wgpu_command_buffer_begin_render_pass(WGPUCommandBufferId command_buffer_id,
|
||||
WGPURenderPassDescriptor desc);
|
||||
|
||||
void wgpu_command_buffer_copy_buffer_to_buffer(WGPUCommandBufferId command_buffer_id,
|
||||
WGPUBufferId src,
|
||||
uint32_t src_offset,
|
||||
@ -580,6 +582,13 @@ void wgpu_command_buffer_copy_texture_to_texture(WGPUCommandBufferId command_buf
|
||||
const WGPUTextureCopyView *destination,
|
||||
WGPUExtent3d copy_size);
|
||||
|
||||
WGPUComputePassId wgpu_command_encoder_begin_compute_pass(WGPUCommandEncoderId command_encoder_id);
|
||||
|
||||
WGPURenderPassId wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId command_encoder_id,
|
||||
WGPURenderPassDescriptor desc);
|
||||
|
||||
WGPUCommandBufferId wgpu_command_encoder_finish(WGPUCommandEncoderId command_encoder_id);
|
||||
|
||||
void wgpu_compute_pass_dispatch(WGPUComputePassId pass_id, uint32_t x, uint32_t y, uint32_t z);
|
||||
|
||||
WGPUCommandBufferId wgpu_compute_pass_end_pass(WGPUComputePassId pass_id);
|
||||
@ -603,8 +612,11 @@ WGPUBlendStateId wgpu_device_create_blend_state(WGPUDeviceId _device_id,
|
||||
|
||||
WGPUBufferId wgpu_device_create_buffer(WGPUDeviceId device_id, const WGPUBufferDescriptor *desc);
|
||||
|
||||
WGPUCommandBufferId wgpu_device_create_command_buffer(WGPUDeviceId device_id,
|
||||
const WGPUCommandBufferDescriptor *_desc);
|
||||
WGPUCommandEncoderId wgpu_device_create_command_encoder(WGPUDeviceId device_id,
|
||||
const WGPUCommandEncoderDescriptor *_desc);
|
||||
|
||||
WGPUComputePipelineId wgpu_device_create_compute_pipeline(WGPUDeviceId device_id,
|
||||
const WGPUComputePipelineDescriptor *desc);
|
||||
|
||||
WGPUDepthStencilStateId wgpu_device_create_depth_stencil_state(WGPUDeviceId _device_id,
|
||||
const WGPUDepthStencilStateDescriptor *desc);
|
||||
|
@ -82,6 +82,7 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
||||
|
||||
CommandBuffer {
|
||||
raw: vec![init],
|
||||
is_recording: true,
|
||||
recorded_thread_id: thread_id,
|
||||
device_id,
|
||||
life_guard: LifeGuard::new(),
|
||||
|
@ -18,8 +18,8 @@ use crate::swap_chain::{SwapChainLink, SwapImageEpoch};
|
||||
use crate::track::{BufferTracker, TextureTracker};
|
||||
use crate::{conv, resource};
|
||||
use crate::{
|
||||
BufferId, CommandBufferId, ComputePassId, DeviceId,
|
||||
RenderPassId, TextureId, TextureViewId,
|
||||
BufferId, CommandBufferId, CommandEncoderId, DeviceId,
|
||||
ComputePassId, RenderPassId, TextureId, TextureViewId,
|
||||
BufferUsageFlags, TextureUsageFlags, Color,
|
||||
LifeGuard, Stored, WeaklyStored,
|
||||
B,
|
||||
@ -77,6 +77,7 @@ pub struct RenderPassDescriptor {
|
||||
|
||||
pub struct CommandBuffer<B: hal::Backend> {
|
||||
pub(crate) raw: Vec<B::CommandBuffer>,
|
||||
is_recording: bool,
|
||||
recorded_thread_id: ThreadId,
|
||||
device_id: Stored<DeviceId>,
|
||||
pub(crate) life_guard: LifeGuard,
|
||||
@ -137,19 +138,30 @@ impl CommandBuffer<B> {
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CommandBufferDescriptor {
|
||||
pub struct CommandEncoderDescriptor {
|
||||
// MSVC doesn't allow zero-sized structs
|
||||
// We can remove this when we actually have a field
|
||||
pub todo: u32,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
command_buffer_id: CommandBufferId,
|
||||
pub extern "C" fn wgpu_command_encoder_finish(
|
||||
command_encoder_id: CommandEncoderId,
|
||||
) -> CommandBufferId {
|
||||
HUB.command_buffers
|
||||
.write()
|
||||
.get_mut(command_encoder_id)
|
||||
.is_recording = false; //TODO: check for the old value
|
||||
command_encoder_id
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_command_encoder_begin_render_pass(
|
||||
command_encoder_id: CommandEncoderId,
|
||||
desc: RenderPassDescriptor,
|
||||
) -> RenderPassId {
|
||||
let mut cmb_guard = HUB.command_buffers.write();
|
||||
let cmb = cmb_guard.get_mut(command_buffer_id);
|
||||
let cmb = cmb_guard.get_mut(command_encoder_id);
|
||||
let device_guard = HUB.devices.read();
|
||||
let device = device_guard.get(cmb.device_id.value);
|
||||
let view_guard = HUB.texture_views.read();
|
||||
@ -342,22 +354,22 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
HUB.render_passes.write().register(RenderPass::new(
|
||||
current_comb,
|
||||
Stored {
|
||||
value: command_buffer_id,
|
||||
value: command_encoder_id,
|
||||
ref_count: cmb.life_guard.ref_count.clone(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_command_buffer_begin_compute_pass(
|
||||
command_buffer_id: CommandBufferId,
|
||||
pub extern "C" fn wgpu_command_encoder_begin_compute_pass(
|
||||
command_encoder_id: CommandEncoderId,
|
||||
) -> ComputePassId {
|
||||
let mut cmb_guard = HUB.command_buffers.write();
|
||||
let cmb = cmb_guard.get_mut(command_buffer_id);
|
||||
let cmb = cmb_guard.get_mut(command_encoder_id);
|
||||
|
||||
let raw = cmb.raw.pop().unwrap();
|
||||
let stored = Stored {
|
||||
value: command_buffer_id,
|
||||
value: command_encoder_id,
|
||||
ref_count: cmb.life_guard.ref_count.clone(),
|
||||
};
|
||||
|
||||
|
@ -2,10 +2,13 @@ use crate::{back, binding_model, command, conv, pipeline, resource, swap_chain};
|
||||
use crate::registry::{HUB, Items};
|
||||
use crate::track::{BufferTracker, TextureTracker, TrackPermit};
|
||||
use crate::{
|
||||
AdapterId, BindGroupId, BindGroupLayoutId, BlendStateId, BufferId, CommandBufferId,
|
||||
ComputePipelineId, DepthStencilStateId, DeviceId, LifeGuard, PipelineLayoutId, QueueId,
|
||||
RefCount, RenderPipelineId, SamplerId, ShaderModuleId, Stored, SubmissionIndex, SurfaceId,
|
||||
SwapChainId, TextureId, TextureViewId, WeaklyStored,
|
||||
LifeGuard, RefCount, Stored, SubmissionIndex, WeaklyStored,
|
||||
BindGroupLayoutId, BindGroupId,
|
||||
BlendStateId, BufferId, CommandBufferId, CommandEncoderId, DepthStencilStateId,
|
||||
ComputePipelineId, RenderPipelineId,
|
||||
AdapterId, DeviceId, PipelineLayoutId, QueueId, ShaderModuleId,
|
||||
SamplerId, TextureId, TextureViewId,
|
||||
SurfaceId, SwapChainId,
|
||||
};
|
||||
|
||||
use hal::command::RawCommandBuffer;
|
||||
@ -233,13 +236,17 @@ impl<B: hal::Backend> Device<B> {
|
||||
}.unwrap()
|
||||
);
|
||||
|
||||
// don't start submission index at zero
|
||||
let life_guard = LifeGuard::new();
|
||||
life_guard.submission_index.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
Device {
|
||||
raw,
|
||||
adapter_id,
|
||||
//mem_allocator,
|
||||
com_allocator: command::CommandAllocator::new(queue_group.family()),
|
||||
queue_group,
|
||||
life_guard: LifeGuard::new(),
|
||||
life_guard,
|
||||
buffer_tracker: Mutex::new(BufferTracker::new()),
|
||||
texture_tracker: Mutex::new(TextureTracker::new()),
|
||||
mem_props,
|
||||
@ -760,10 +767,10 @@ pub extern "C" fn wgpu_device_create_shader_module(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_command_buffer(
|
||||
pub extern "C" fn wgpu_device_create_command_encoder(
|
||||
device_id: DeviceId,
|
||||
_desc: &command::CommandBufferDescriptor,
|
||||
) -> CommandBufferId {
|
||||
_desc: &command::CommandEncoderDescriptor,
|
||||
) -> CommandEncoderId {
|
||||
let device_guard = HUB.devices.read();
|
||||
let device = device_guard.get(device_id);
|
||||
|
||||
@ -771,14 +778,14 @@ pub extern "C" fn wgpu_device_create_command_buffer(
|
||||
value: device_id,
|
||||
ref_count: device.life_guard.ref_count.clone(),
|
||||
};
|
||||
let mut cmd_buf = device.com_allocator.allocate(dev_stored, &device.raw);
|
||||
let mut cmb = device.com_allocator.allocate(dev_stored, &device.raw);
|
||||
unsafe {
|
||||
cmd_buf.raw.last_mut().unwrap().begin(
|
||||
cmb.raw.last_mut().unwrap().begin(
|
||||
hal::command::CommandBufferFlags::ONE_TIME_SUBMIT,
|
||||
hal::command::CommandBufferInheritanceInfo::default(),
|
||||
);
|
||||
}
|
||||
HUB.command_buffers.write().register(cmd_buf)
|
||||
HUB.command_buffers.write().register(cmb)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -905,7 +912,9 @@ pub extern "C" fn wgpu_queue_submit(
|
||||
last_done
|
||||
};
|
||||
|
||||
device.com_allocator.maintain(last_done);
|
||||
if last_done != 0 {
|
||||
device.com_allocator.maintain(last_done);
|
||||
}
|
||||
|
||||
// finally, return the command buffers to the allocator
|
||||
for &cmb_id in command_buffer_ids {
|
||||
|
@ -184,7 +184,7 @@ pub type AdapterId = Id;
|
||||
type AdapterHandle = hal::Adapter<B>;
|
||||
pub type DeviceId = Id;
|
||||
type DeviceHandle = Device<B>;
|
||||
pub type QueueId = Id;
|
||||
pub type QueueId = DeviceId;
|
||||
pub type BufferId = Id;
|
||||
type BufferHandle = Buffer<B>;
|
||||
|
||||
@ -219,6 +219,7 @@ type ComputePipelineHandle = ComputePipeline<B>;
|
||||
|
||||
pub type CommandBufferId = Id;
|
||||
type CommandBufferHandle = CommandBuffer<B>;
|
||||
pub type CommandEncoderId = CommandBufferId;
|
||||
pub type RenderPassId = Id;
|
||||
type RenderPassHandle = RenderPass<B>;
|
||||
pub type ComputePassId = Id;
|
||||
|
@ -190,7 +190,7 @@ impl<I: Clone + Hash + Eq, U: Copy + GenericUsage + BitOr<Output = U> + PartialE
|
||||
}
|
||||
|
||||
impl<U: Copy + GenericUsage + BitOr<Output = U> + PartialEq> Tracker<Id, U> {
|
||||
fn get_with_usage<'a, T: 'a + Borrow<RefCount>, V: Items<T>>(
|
||||
fn _get_with_usage<'a, T: 'a + Borrow<RefCount>, V: Items<T>>(
|
||||
&mut self,
|
||||
items: &'a V,
|
||||
id: Id,
|
||||
|
@ -8,16 +8,19 @@ use std::marker::PhantomData;
|
||||
use std::ops::Range;
|
||||
use std::ptr;
|
||||
|
||||
#[cfg(feature = "winit")]
|
||||
pub use wgn::winit;
|
||||
|
||||
pub use wgn::{
|
||||
AdapterDescriptor, AddressMode, Attachment, BindGroupLayoutBinding, BindingType,
|
||||
BlendStateDescriptor, BorderColor, BufferDescriptor, BufferUsageFlags, Color, ColorWriteFlags,
|
||||
CommandBufferDescriptor, CompareFunction, DepthStencilStateDescriptor, DeviceDescriptor,
|
||||
Extensions, Extent3d, FilterMode, IndexFormat, InputStepMode, LoadOp, Origin3d,
|
||||
PowerPreference, PrimitiveTopology, RenderPassColorAttachmentDescriptor,
|
||||
RenderPassDepthStencilAttachmentDescriptor, SamplerDescriptor, ShaderAttributeIndex,
|
||||
AdapterDescriptor, Attachment, BindGroupLayoutBinding, BindingType, BlendStateDescriptor,
|
||||
BufferDescriptor, BufferUsageFlags,
|
||||
IndexFormat, InputStepMode, ShaderAttributeIndex, VertexAttributeDescriptor, VertexFormat,
|
||||
Color, ColorWriteFlags, CommandEncoderDescriptor, DepthStencilStateDescriptor,
|
||||
DeviceDescriptor, Extensions, Extent3d, LoadOp, Origin3d, PowerPreference, PrimitiveTopology,
|
||||
RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
|
||||
ShaderModuleDescriptor, ShaderStage, ShaderStageFlags, StoreOp, SwapChainDescriptor,
|
||||
SamplerDescriptor, AddressMode, FilterMode, BorderColor, CompareFunction,
|
||||
TextureDescriptor, TextureDimension, TextureFormat, TextureUsageFlags, TextureViewDescriptor,
|
||||
VertexAttributeDescriptor, VertexFormat,
|
||||
};
|
||||
|
||||
pub struct Instance {
|
||||
@ -103,17 +106,21 @@ pub struct ComputePipeline {
|
||||
}
|
||||
|
||||
pub struct CommandBuffer {
|
||||
id: wgn::CommandBufferId,
|
||||
_id: wgn::CommandBufferId,
|
||||
}
|
||||
|
||||
pub struct CommandEncoder {
|
||||
id: wgn::CommandEncoderId,
|
||||
}
|
||||
|
||||
pub struct RenderPass<'a> {
|
||||
id: wgn::RenderPassId,
|
||||
parent: &'a mut CommandBuffer,
|
||||
_parent: &'a mut CommandEncoder,
|
||||
}
|
||||
|
||||
pub struct ComputePass<'a> {
|
||||
id: wgn::ComputePassId,
|
||||
parent: &'a mut CommandBuffer,
|
||||
_parent: &'a mut CommandEncoder,
|
||||
}
|
||||
|
||||
pub struct Queue<'a> {
|
||||
@ -229,7 +236,7 @@ impl Instance {
|
||||
}
|
||||
|
||||
#[cfg(feature = "winit")]
|
||||
pub fn create_surface(&self, window: &wgn::winit::Window) -> Surface {
|
||||
pub fn create_surface(&self, window: &winit::Window) -> Surface {
|
||||
Surface {
|
||||
id: wgn::wgpu_instance_create_surface_from_winit(self.id, window),
|
||||
}
|
||||
@ -264,9 +271,9 @@ impl Device {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_command_buffer(&self, desc: &CommandBufferDescriptor) -> CommandBuffer {
|
||||
CommandBuffer {
|
||||
id: wgn::wgpu_device_create_command_buffer(self.id, desc),
|
||||
pub fn create_command_encoder(&self, desc: &CommandEncoderDescriptor) -> CommandEncoder {
|
||||
CommandEncoder {
|
||||
id: wgn::wgpu_device_create_command_encoder(self.id, desc),
|
||||
}
|
||||
}
|
||||
|
||||
@ -475,7 +482,13 @@ impl Texture {
|
||||
}
|
||||
}
|
||||
|
||||
impl CommandBuffer {
|
||||
impl CommandEncoder {
|
||||
pub fn finish(self) -> CommandBuffer {
|
||||
CommandBuffer {
|
||||
_id: wgn::wgpu_command_encoder_finish(self.id),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn begin_render_pass(&mut self, desc: &RenderPassDescriptor) -> RenderPass {
|
||||
let colors = desc
|
||||
.color_attachments
|
||||
@ -501,7 +514,7 @@ impl CommandBuffer {
|
||||
});
|
||||
|
||||
RenderPass {
|
||||
id: wgn::wgpu_command_buffer_begin_render_pass(
|
||||
id: wgn::wgpu_command_encoder_begin_render_pass(
|
||||
self.id,
|
||||
wgn::RenderPassDescriptor {
|
||||
color_attachments: colors.as_ptr(),
|
||||
@ -512,14 +525,14 @@ impl CommandBuffer {
|
||||
.unwrap_or(ptr::null()),
|
||||
},
|
||||
),
|
||||
parent: self,
|
||||
_parent: self,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn begin_compute_pass(&mut self) -> ComputePass {
|
||||
ComputePass {
|
||||
id: wgn::wgpu_command_buffer_begin_compute_pass(self.id),
|
||||
parent: self,
|
||||
id: wgn::wgpu_command_encoder_begin_compute_pass(self.id),
|
||||
_parent: self,
|
||||
}
|
||||
}
|
||||
|
||||
@ -585,9 +598,8 @@ impl CommandBuffer {
|
||||
}
|
||||
|
||||
impl<'a> RenderPass<'a> {
|
||||
pub fn end_pass(self) -> &'a mut CommandBuffer {
|
||||
pub fn end_pass(self) {
|
||||
wgn::wgpu_render_pass_end_pass(self.id);
|
||||
self.parent
|
||||
}
|
||||
|
||||
pub fn set_bind_group(&mut self, index: u32, bind_group: &BindGroup) {
|
||||
@ -640,9 +652,8 @@ impl<'a> RenderPass<'a> {
|
||||
}
|
||||
|
||||
impl<'a> ComputePass<'a> {
|
||||
pub fn end_pass(self) -> &'a mut CommandBuffer {
|
||||
pub fn end_pass(self) {
|
||||
wgn::wgpu_compute_pass_end_pass(self.id);
|
||||
self.parent
|
||||
}
|
||||
|
||||
pub fn set_bind_group(&mut self, index: u32, bind_group: &BindGroup) {
|
||||
|
Loading…
Reference in New Issue
Block a user