diff --git a/examples/hello_triangle_c/CMakeLists.txt b/examples/hello_triangle_c/CMakeLists.txt index ab7252918..ad6a9e6b2 100644 --- a/examples/hello_triangle_c/CMakeLists.txt +++ b/examples/hello_triangle_c/CMakeLists.txt @@ -7,7 +7,7 @@ set(TARGET_NAME hello_triangle) add_executable(hello_triangle main.c) if(MSVC) - target_compile_options(${TARGET_NAME} PRIVATE /W4 /WX) + target_compile_options(${TARGET_NAME} PRIVATE /W4) else(MSVC) target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic) endif(MSVC) @@ -24,4 +24,4 @@ find_library(WGPU_LIBRARY wgpu_native HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug" ) -target_link_libraries(${TARGET_NAME} glfw ${WGPU_LIBRARY} ${OS_LIBRARIES}) +target_link_libraries(${TARGET_NAME} glfw3 ${WGPU_LIBRARY} ${OS_LIBRARIES}) diff --git a/examples/hello_triangle_c/main.c b/examples/hello_triangle_c/main.c index c46a06f8b..415749e4c 100644 --- a/examples/hello_triangle_c/main.c +++ b/examples/hello_triangle_c/main.c @@ -191,7 +191,9 @@ int main() } #elif WGPU_TARGET == WGPU_TARGET_WINDOWS { - // TODO + HWND hwnd = glfwGetWin32Window(window); + HINSTANCE hinstance = GetModuleHandle(NULL); + surface = wgpu_instance_create_surface_from_windows_hwnd(instance, hinstance, hwnd); } #endif @@ -206,7 +208,7 @@ int main() while (!glfwWindowShouldClose(window)) { WGPUSwapChainOutput next_texture = wgpu_swap_chain_get_next_texture(swap_chain); - WGPUCommandBufferDescriptor cmd_buf_desc = {}; + WGPUCommandBufferDescriptor cmd_buf_desc = { .todo = 0 }; WGPUCommandBufferId cmd_buf = wgpu_device_create_command_buffer(device, &cmd_buf_desc); WGPURenderPassColorAttachmentDescriptor_TextureViewId color_attachments[ATTACHMENTS_LENGTH] = { { diff --git a/examples/hello_triangle_rust/main.rs b/examples/hello_triangle_rust/main.rs index 2568bb67b..30890d92b 100644 --- a/examples/hello_triangle_rust/main.rs +++ b/examples/hello_triangle_rust/main.rs @@ -93,7 +93,7 @@ fn main() { } let (_, view) = swap_chain.get_next_texture(); - let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor {}); + let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor { todo: 0 }); { let mut rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { diff --git a/wgpu-bindings/wgpu.h b/wgpu-bindings/wgpu.h index 9fda96863..e5308f063 100644 --- a/wgpu-bindings/wgpu.h +++ b/wgpu-bindings/wgpu.h @@ -257,7 +257,7 @@ typedef struct { } WGPUBufferDescriptor; typedef struct { - + uint32_t todo; } WGPUCommandBufferDescriptor; typedef WGPUId WGPUDepthStencilStateId; @@ -509,6 +509,10 @@ WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id); WGPUSurfaceId wgpu_instance_create_surface_from_macos_layer(WGPUInstanceId instance_id, void *layer); +WGPUSurfaceId wgpu_instance_create_surface_from_windows_hwnd(WGPUInstanceId instance_id, + void *hinstance, + void *hwnd); + WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id, const WGPUAdapterDescriptor *desc); diff --git a/wgpu-native/src/command/mod.rs b/wgpu-native/src/command/mod.rs index 6ee037a19..cff0871e9 100644 --- a/wgpu-native/src/command/mod.rs +++ b/wgpu-native/src/command/mod.rs @@ -145,7 +145,11 @@ impl CommandBuffer { } #[repr(C)] -pub struct CommandBufferDescriptor {} +pub struct CommandBufferDescriptor { + // 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( diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index 514f0adc0..638482604 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -63,6 +63,7 @@ pub extern "C" fn wgpu_instance_create_surface_from_winit( .register(surface) } +#[allow(unused)] #[no_mangle] pub extern "C" fn wgpu_instance_create_surface_from_macos_layer( instance_id: InstanceId, @@ -87,6 +88,49 @@ pub extern "C" fn wgpu_instance_create_surface_from_macos_layer( } } +#[allow(unused)] +#[no_mangle] +pub extern "C" fn wgpu_instance_create_surface_from_windows_hwnd( + instance_id: InstanceId, + hinstance: *mut std::ffi::c_void, + hwnd: *mut std::ffi::c_void, +) -> SurfaceId { + #[cfg(not(any(feature = "gfx-backend-dx11", feature = "gfx-backend-dx12", feature = "gfx-backend-vulkan")))] + unimplemented!(); + + #[cfg(any(feature = "gfx-backend-dx11", feature = "gfx-backend-dx12"))] + { + let raw = HUB.instances + .read() + .get(instance_id) + .create_surface_from_hwnd(hwnd); + + let surface = Surface { + raw, + }; + + HUB.surfaces + .write() + .register(surface) + } + + #[cfg(any(feature = "gfx-backend-vulkan"))] + { + let raw = HUB.instances + .read() + .get(instance_id) + .create_surface_from_hwnd(hinstance, hwnd); + + let surface = Surface { + raw, + }; + + HUB.surfaces + .write() + .register(surface) + } +} + #[no_mangle] pub extern "C" fn wgpu_instance_get_adapter( instance_id: InstanceId,