diff --git a/examples/hello_triangle_c/main.c b/examples/hello_triangle_c/main.c index d3ad4c54c..8115e3d86 100644 --- a/examples/hello_triangle_c/main.c +++ b/examples/hello_triangle_c/main.c @@ -1,6 +1,10 @@ #include #include "./../../wgpu-bindings/wgpu.h" +#define STAGES_LENGTH (2) +#define BLEND_STATE_LENGTH (1) +#define FORMATS_LENGTH (1) + WGPUByteArray read_file(const char *name) { FILE *file = fopen(name, "rb"); @@ -63,7 +67,6 @@ int main() .entry_point = "main", }; - const unsigned int STAGES_LENGTH = 2; WGPUPipelineStageDescriptor stages[STAGES_LENGTH] = { vertex_stage, fragment_stage }; WGPUBlendDescriptor blend_alpha = { @@ -83,7 +86,6 @@ int main() .write_mask = 0, }; WGPUBlendStateId blend_state_0 = wgpu_device_create_blend_state(device, blend_state_0_desc); - const unsigned int BLEND_STATE_LENGTH = 1; WGPUBlendStateId blend_state[BLEND_STATE_LENGTH] = { blend_state_0 }; WGPUStencilStateFaceDescriptor stencil_state_front = { @@ -108,7 +110,6 @@ int main() }; WGPUDepthStencilStateId depth_stencil_state = wgpu_device_create_depth_stencil_state(device, depth_stencil_state_desc); - const unsigned int FORMATS_LENGTH = 1; WGPUTextureFormat formats[FORMATS_LENGTH] = { WGPUTextureFormat_R8g8b8a8Unorm }; WGPUAttachmentStateDescriptor attachment_state_desc = { .formats = formats, @@ -132,7 +133,7 @@ int main() WGPUCommandBufferDescriptor cmd_buf_desc = { }; WGPUCommandBufferId cmd_buf = wgpu_device_create_command_buffer(device, cmd_buf_desc); WGPUQueueId queue = wgpu_device_get_queue(device); - /*wgpu_queue_submit(queue, &cmd_buf, 1);*/ + wgpu_queue_submit(queue, &cmd_buf, 1); return 0; } diff --git a/wgpu-bindings/wgpu.h b/wgpu-bindings/wgpu.h index b0cad59a2..8a1b918fb 100644 --- a/wgpu-bindings/wgpu.h +++ b/wgpu-bindings/wgpu.h @@ -1,14 +1,13 @@ -#include -#include -#include - -#define WGPU_REMOTE 1 #ifdef WGPU_REMOTE typedef uint32_t WGPUId; #else typedef void *WGPUId; #endif +#include +#include +#include + #define WGPUColorWriteFlags_ALL 15 #define WGPUColorWriteFlags_ALPHA 8 diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 5b60aac87..fde26ac6e 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -1,3 +1,4 @@ +use hal::command::RawCommandBuffer; use hal::queue::RawCommandQueue; use hal::{self, Device as _Device}; use {back, binding_model, command, conv, memory, pipeline}; @@ -130,7 +131,11 @@ pub extern "C" fn wgpu_device_create_command_buffer( ) -> CommandBufferId { let mut device_guard = registry::DEVICE_REGISTRY.lock(); let device = device_guard.get_mut(device_id); - let cmd_buf = device.com_allocator.allocate(&device.device); + let mut cmd_buf = device.com_allocator.allocate(&device.device); + cmd_buf.raw.begin( + hal::command::CommandBufferFlags::ONE_TIME_SUBMIT, + hal::command::CommandBufferInheritanceInfo::default(), + ); registry::COMMAND_BUFFER_REGISTRY.lock().register(cmd_buf) } @@ -152,7 +157,8 @@ pub extern "C" fn wgpu_queue_submit( //TODO: submit at once, requires `get_all()` let mut command_buffer_guard = registry::COMMAND_BUFFER_REGISTRY.lock(); for &cmb_id in command_buffer_ids { - let cmd_buf = command_buffer_guard.take(cmb_id); + let mut cmd_buf = command_buffer_guard.take(cmb_id); + cmd_buf.raw.finish(); { let submission = hal::queue::RawSubmission { cmd_buffers: iter::once(&cmd_buf.raw), @@ -220,10 +226,6 @@ pub extern "C" fn wgpu_device_create_render_pipeline( let mut vertex = None; let mut fragment = None; for pipeline_stage in pipeline_stages.iter() { - let entry_name = unsafe { ffi::CStr::from_ptr(pipeline_stage.entry_point) } - .to_str() - .to_owned() - .unwrap(); let entry = hal::pso::EntryPoint:: { entry: unsafe { ffi::CStr::from_ptr(pipeline_stage.entry_point) } .to_str()