From 58e9ddfc3f1cdb7bc1e9fee58042f1f3ebbabbd2 Mon Sep 17 00:00:00 2001 From: Ian Elliott Date: Fri, 6 Feb 2015 18:10:35 -0700 Subject: [PATCH] Win: Allow the demos "tri" and "xglinfo" to build on Windows. These had the WSI hacked out of them, since there isn't yet a standard API in this space, and what was originally done is only for X11. --- CMakeLists.txt | 2 -- demos/CMakeLists.txt | 63 ++++++++++++++++++++++++++++++++------------------- demos/tri.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ loader/CMakeLists.txt | 2 +- 4 files changed, 99 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67ef772..01097fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,5 @@ if (NOT WIN32) add_subdirectory(tests) endif() add_subdirectory(layers) -if (NOT WIN32) add_subdirectory(demos) -endif() add_subdirectory(tools/glave) diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index 98c611d..da3d892 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -1,10 +1,14 @@ -find_package(XCB REQUIRED) - -if(NOT EXISTS /usr/include/glm/glm.hpp) - message(FATAL_ERROR "Necessary libglm-dev headers cannot be found: sudo apt-get install libglm-dev") +if(NOT WIN32) + find_package(XCB REQUIRED) endif() -if(NOT EXISTS /usr/include/png.h) - message(FATAL_ERROR "Necessary png12-dev headers cannot be found: sudo apt-get install libpng12-dev") + +if(NOT WIN32) + if(NOT EXISTS /usr/include/glm/glm.hpp) + message(FATAL_ERROR "Necessary libglm-dev headers cannot be found: sudo apt-get install libglm-dev") + endif() + if(NOT EXISTS /usr/include/png.h) + message(FATAL_ERROR "Necessary png12-dev headers cannot be found: sudo apt-get install libpng12-dev") + endif() endif() file(GLOB TEXTURES @@ -14,29 +18,42 @@ file(COPY ${TEXTURES} DESTINATION ${CMAKE_BINARY_DIR}/demos) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXGL_PROTOTYPES") -add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-vert.bil - COMMAND ${GLSLANG_PREFIX}/build/install/bin/glslangValidator -s -b ${PROJECT_SOURCE_DIR}/demos/cube.vert - COMMAND mv vert.bil ${CMAKE_BINARY_DIR}/demos/cube-vert.bil - DEPENDS cube.vert ${GLSLANG_PREFIX}/build/install/bin/glslangValidator - ) +if(NOT WIN32) + add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-vert.bil + COMMAND ${GLSLANG_PREFIX}/build/install/bin/glslangValidator -s -b ${PROJECT_SOURCE_DIR}/demos/cube.vert + COMMAND mv vert.bil ${CMAKE_BINARY_DIR}/demos/cube-vert.bil + DEPENDS cube.vert ${GLSLANG_PREFIX}/build/install/bin/glslangValidator + ) + + add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-frag.bil + COMMAND ${GLSLANG_PREFIX}/build/install/bin/glslangValidator -s -b ${PROJECT_SOURCE_DIR}/demos/cube.frag + COMMAND mv frag.bil ${CMAKE_BINARY_DIR}/demos/cube-frag.bil + DEPENDS cube.frag ${GLSLANG_PREFIX}/build/install/bin/glslangValidator + ) +endif() -add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/demos/cube-frag.bil - COMMAND ${GLSLANG_PREFIX}/build/install/bin/glslangValidator -s -b ${PROJECT_SOURCE_DIR}/demos/cube.frag - COMMAND mv frag.bil ${CMAKE_BINARY_DIR}/demos/cube-frag.bil - DEPENDS cube.frag ${GLSLANG_PREFIX}/build/install/bin/glslangValidator - ) +if(NOT WIN32) + include_directories ( + ${XCB_INCLUDE_DIRS} + "${PROJECT_SOURCE_DIR}/icd/common" + ) -include_directories ( - ${XCB_INCLUDE_DIRS} - "${PROJECT_SOURCE_DIR}/icd/common" - ) + link_libraries(${XCB_LIBRARIES} XGL png m) +endif() +if(WIN32) + include_directories ( + "${PROJECT_SOURCE_DIR}/icd/common" + ) -link_libraries(${XCB_LIBRARIES} XGL png m) + link_libraries(XGL) +endif() add_executable(xglinfo xglinfo.c) add_executable(tri tri.c) target_link_libraries(tri) -add_executable(cube cube.c ${CMAKE_BINARY_DIR}/demos/cube-vert.bil ${CMAKE_BINARY_DIR}/demos/cube-frag.bil) -target_link_libraries(cube) +if(NOT WIN32) + add_executable(cube cube.c ${CMAKE_BINARY_DIR}/demos/cube-vert.bil ${CMAKE_BINARY_DIR}/demos/cube-frag.bil) + target_link_libraries(cube) +endif() diff --git a/demos/tri.c b/demos/tri.c index 5a770f4..ee2fe34 100644 --- a/demos/tri.c +++ b/demos/tri.c @@ -10,10 +10,14 @@ #include #include +#if defined(__linux__) #include +#endif #include #include +#if defined(__linux__) #include +#endif #include "icd-bil.h" @@ -21,8 +25,10 @@ #define DEMO_TEXTURE_COUNT 1 struct demo { +#if defined(__linux__) xcb_connection_t *connection; xcb_screen_t *screen; +#endif XGL_INSTANCE inst; XGL_PHYSICAL_GPU gpu; @@ -81,8 +87,10 @@ struct demo { XGL_DESCRIPTOR_REGION desc_region; XGL_DESCRIPTOR_SET desc_set; +#if defined(__linux__) xcb_window_t window; xcb_intern_atom_reply_t *atom_wm_delete_window; +#endif bool quit; uint32_t current_buffer; @@ -90,10 +98,12 @@ struct demo { static void demo_draw_build_cmd(struct demo *demo) { +#if defined(__linux__) const XGL_COLOR_ATTACHMENT_BIND_INFO color_attachment = { .view = demo->buffers[demo->current_buffer].view, .layout = XGL_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, }; +#endif const XGL_DEPTH_STENCIL_BIND_INFO depth_stencil = { .view = demo->depth.view, .layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, @@ -118,7 +128,9 @@ static void demo_draw_build_cmd(struct demo *demo) .sType = XGL_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, .pNext = NULL, .colorAttachmentCount = 1, +#if defined(__linux__) .pColorAttachments = (XGL_COLOR_ATTACHMENT_BIND_INFO*) &color_attachment, +#endif .pDepthStencilAttachment = (XGL_DEPTH_STENCIL_BIND_INFO*) &depth_stencil, .sampleCount = 1, .width = demo->width, @@ -181,10 +193,12 @@ static void demo_draw_build_cmd(struct demo *demo) static void demo_draw(struct demo *demo) { +#if defined(__linux__) const XGL_WSI_X11_PRESENT_INFO present = { .destWindow = demo->window, .srcImage = demo->buffers[demo->current_buffer].image, }; +#endif XGL_FENCE fence = demo->buffers[demo->current_buffer].fence; XGL_RESULT err; @@ -217,14 +231,17 @@ static void demo_draw(struct demo *demo) idx, memRefs, XGL_NULL_HANDLE); assert(!err); +#if defined(__linux__) err = xglWsiX11QueuePresent(demo->queue, &present, fence); assert(!err); +#endif demo->current_buffer = (demo->current_buffer + 1) % DEMO_BUFFER_COUNT; } static void demo_prepare_buffers(struct demo *demo) { +#if defined(__linux__) const XGL_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO presentable_image = { .format = demo->format, .usage = XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, @@ -234,6 +251,7 @@ static void demo_prepare_buffers(struct demo *demo) }, .flags = 0, }; +#endif const XGL_FENCE_CREATE_INFO fence = { .sType = XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO, .pNext = NULL, @@ -252,9 +270,14 @@ static void demo_prepare_buffers(struct demo *demo) .arraySize = 1, }; +#if defined(__linux__) err = xglWsiX11CreatePresentableImage(demo->device, &presentable_image, &demo->buffers[i].image, &demo->buffers[i].mem); assert(!err); +#else + demo->buffers[i].image = NULL; + demo->buffers[i].mem = NULL; +#endif color_attachment_view.image = demo->buffers[i].image; @@ -915,9 +938,14 @@ static void demo_prepare(struct demo *demo) demo_prepare_descriptor_set(demo); } +#if defined(__linux__) static void demo_handle_event(struct demo *demo, const xcb_generic_event_t *event) +#else +static void demo_handle_event(struct demo *demo) +#endif { +#if defined(__linux__) switch (event->response_type & 0x7f) { case XCB_EXPOSE: demo_draw(demo); @@ -943,10 +971,15 @@ static void demo_handle_event(struct demo *demo, default: break; } +#else + // Since we don't yet support events, we'll just do a draw + demo_draw(demo); +#endif } static void demo_run(struct demo *demo) { +#if defined(__linux__) xcb_flush(demo->connection); while (!demo->quit) { @@ -958,10 +991,16 @@ static void demo_run(struct demo *demo) free(event); } } +#else + // Since we don't yet support events, just call demo_handle_event to do a draw + demo_handle_event(demo); + +#endif } static void demo_create_window(struct demo *demo) { +#if defined(__linux__) uint32_t value_mask, value_list[32]; demo->window = xcb_generate_id(demo->connection); @@ -994,6 +1033,7 @@ static void demo_create_window(struct demo *demo) free(reply); xcb_map_window(demo->connection, demo->window); +#endif } static void demo_init_xgl(struct demo *demo) @@ -1007,17 +1047,23 @@ static void demo_init_xgl(struct demo *demo) .engineVersion = 0, .apiVersion = XGL_MAKE_VERSION(0, 22, 0), }; +#if defined(__linux__) const XGL_WSI_X11_CONNECTION_INFO connection = { .pConnection = demo->connection, .root = demo->screen->root, .provider = 0, }; +#endif const XGL_DEVICE_QUEUE_CREATE_INFO queue = { .queueNodeIndex = 0, .queueCount = 1, }; const char *ext_names[] = { +#if defined(__linux__) "XGL_WSI_X11", +#else + "XGL_WSI_WINDOWS", +#endif }; const XGL_DEVICE_CREATE_INFO device = { .sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO, @@ -1043,8 +1089,10 @@ static void demo_init_xgl(struct demo *demo) assert(!err); } +#if defined(__linux__) err = xglWsiX11AssociateConnection(demo->gpu, &connection); assert(!err); +#endif err = xglCreateDevice(demo->gpu, &device, &demo->device); assert(!err); @@ -1056,6 +1104,7 @@ static void demo_init_xgl(struct demo *demo) static void demo_init_connection(struct demo *demo) { +#if defined(__linux__) const xcb_setup_t *setup; xcb_screen_iterator_t iter; int scr; @@ -1068,6 +1117,7 @@ static void demo_init_connection(struct demo *demo) xcb_screen_next(&iter); demo->screen = iter.data; +#endif } static void demo_init(struct demo *demo) @@ -1122,14 +1172,18 @@ static void demo_cleanup(struct demo *demo) for (i = 0; i < DEMO_BUFFER_COUNT; i++) { xglDestroyObject(demo->buffers[i].fence); xglDestroyObject(demo->buffers[i].view); +#if defined(__linux__) xglDestroyObject(demo->buffers[i].image); +#endif } xglDestroyDevice(demo->device); xglDestroyInstance(demo->inst); +#if defined(__linux__) xcb_destroy_window(demo->connection, demo->window); xcb_disconnect(demo->connection); +#endif } int main(void) @@ -1144,5 +1198,9 @@ int main(void) demo_cleanup(&demo); +#if defined(__linux__) +#else + printf("try exitting...\n"); fflush(stdout); +#endif return 0; } diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt index 2d2febf..bbf5799 100644 --- a/loader/CMakeLists.txt +++ b/loader/CMakeLists.txt @@ -15,7 +15,7 @@ include_directories( if (WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXGL_PROTOTYPES -D_CRT_SECURE_NO_WARNINGS") - add_library(XGL SHARED loader.c dirent_on_windows.c dispatch.c table_ops.h) + add_library(XGL STATIC loader.c dirent_on_windows.c dispatch.c table_ops.h) set_target_properties(XGL PROPERTIES SOVERSION 0) target_link_libraries(XGL) endif() -- 2.7.4