diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml new file mode 100644 index 0000000..fc21342 --- /dev/null +++ b/.github/workflows/cmake.yml @@ -0,0 +1,58 @@ +name: CMake + +on: + [push, pull_request] + # push: + # branches: [ "main", "dev" ] + # pull_request: + # branches: [ "main" ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Debug + +jobs: + build: + timeout-minutes: 200 + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + + steps: + - uses: actions/checkout@v5 + - name: Install CMake + uses: jwlawson/actions-setup-cmake@v2 + with: + cmake-version: '4.1' # Specify the desired CMake version + - name: Fetch Vulkan SDK version spec + shell: bash + run: | + curl -o vulkan-sdk-config.json https://vulkan.lunarg.com/sdk/config/1.4.304.1/linux/config.json + + - name: Configure Vulkan SDK using the downloaded spec + uses: humbletim/setup-vulkan-sdk@v1.2.1 + with: + vulkan-config-file: vulkan-sdk-config.json + vulkan-components: Vulkan-Headers, Vulkan-Loader, Glslang, SPIRV-Cross, SPIRV-Tools, SPIRV-Header + vulkan-use-cache: true + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{github.workspace}}/build + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + -DCMAKE_CXX_STANDARD=23 + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + # - name: Test + # working-directory: ${{github.workspace}}/build + # # Execute tests defined by the CMake configuration. + # # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + # run: ctest -C ${{env.BUILD_TYPE}} -j diff --git a/CMakeLists.txt b/CMakeLists.txt index 62233f4..5dc5323 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ add_subdirectory(resource) include(CTest) if(BUILD_TESTING) - add_subdirectory(test) + add_subdirectory(test) endif() set(CPACK_PROJECT_NAME ${PROJECT_NAME}) diff --git a/lib/application.cxx b/lib/application.cxx index ef68931..e5e7d16 100644 --- a/lib/application.cxx +++ b/lib/application.cxx @@ -147,19 +147,19 @@ void OttApplication::initVulkan() VkPipelineVertexInputStateCreateInfo gridVertexInputInfo = appPipeline.initVertexInputInfo(0, VK_NULL_HANDLE, 0, VK_NULL_HANDLE); appPipeline.createPipelineLayout (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, &bindlessDescSetLayout); - appPipeline.createGraphicsPipeline ("resource/shaders/object.vert.spv", "resource/shaders/solid_shading.frag.spv", + appPipeline.createGraphicsPipeline ("build/shaders/object.vert.spv", "build/shaders/solid_shading.frag.spv", appPipeline.graphicsPipelines.solid, modelVertexInputInfo, VK_POLYGON_MODE_FILL, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST ); - appPipeline.createGraphicsPipeline ("resource/shaders/object.vert.spv", "resource/shaders/texture.frag.spv", + appPipeline.createGraphicsPipeline ("build/shaders/object.vert.spv", "build/shaders/texture.frag.spv", appPipeline.graphicsPipelines.texture, modelVertexInputInfo, VK_POLYGON_MODE_FILL, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST ); - appPipeline.createGraphicsPipeline ("resource/shaders/object.vert.spv", "resource/shaders/wireframe.frag.spv", + appPipeline.createGraphicsPipeline ("build/shaders/object.vert.spv", "build/shaders/wireframe.frag.spv", appPipeline.graphicsPipelines.wireframe, modelVertexInputInfo, VK_POLYGON_MODE_LINE, VK_PRIMITIVE_TOPOLOGY_LINE_LIST ); - appPipeline.createGraphicsPipeline ("resource/shaders/grid.vert.spv", "resource/shaders/grid.frag.spv", + appPipeline.createGraphicsPipeline ("build/shaders/grid.vert.spv", "build/shaders/grid.frag.spv", appPipeline.graphicsPipelines.grid, gridVertexInputInfo, VK_POLYGON_MODE_FILL, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST ); diff --git a/resource/CMakeLists.txt b/resource/CMakeLists.txt index 8661ec2..3157756 100644 --- a/resource/CMakeLists.txt +++ b/resource/CMakeLists.txt @@ -1,40 +1,33 @@ # https://stackoverflow.com/a/67044657/6692219 -find_package(Vulkan) find_package(Vulkan COMPONENTS glslc) -find_program(glslc_executable NAMES glslc HINTS Vulkan::glslc) set(SHADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/shaders) -file(GLOB shaders - ${SHADER_DIR}/*.vert - ${SHADER_DIR}/*.frag - # ${SHADER_DIR}/*.comp - # ${SHADER_DIR}/*.geom - # ${SHADER_DIR}/*.tesc - # ${SHADER_DIR}/*.tese - # ${SHADER_DIR}/*.mesh - # ${SHADER_DIR}/*.task - # ${SHADER_DIR}/*.rgen - # ${SHADER_DIR}/*.rchit - # ${SHADER_DIR}/*.rmiss +file( + GLOB shaders + ${SHADER_DIR}/*.vert + ${SHADER_DIR}/*.frag + ${SHADER_DIR}/*.comp + ${SHADER_DIR}/*.geom + ${SHADER_DIR}/*.tesc + ${SHADER_DIR}/*.tese + ${SHADER_DIR}/*.mesh + ${SHADER_DIR}/*.task + ${SHADER_DIR}/*.rgen + ${SHADER_DIR}/*.rchit + ${SHADER_DIR}/*.rmiss ) -foreach(shader IN LISTS shaders) - cmake_path(GET shader EXTENSION ext) - cmake_path(GET shader STEM basename) - if(ext STREQUAL ".vert") - set(spv_base "${basename}.vert") - elseif(ext STREQUAL ".frag") - set(spv_base "${basename}.frag") - else() - set(spv_base "${basename}") - endif() +foreach(shader_path IN LISTS shaders) + cmake_path(GET shader_path FILENAME shader) + set(out_path ${CMAKE_BINARY_DIR}/shaders/${shader}.spv) + add_custom_command( + OUTPUT ${out_path} + COMMAND ${Vulkan_GLSLC_EXECUTABLE} ${shader_path} -o ${out_path} + DEPENDS ${shader_path} + COMMENT "Compiling ${shader}" + ) - add_custom_command(OUTPUT ${SHADER_DIR}/${spv_base}.spv - COMMAND ${Vulkan_GLSLC_EXECUTABLE} ${shader} -o ${SHADER_DIR}/${spv_base}.spv - DEPENDS ${shader} - COMMENT "Compiling ${spv_base}") - - list(APPEND SPV_SHADERS ${SHADER_DIR}/${spv_base}.spv) -endForeach() + list(APPEND SPV_SHADERS ${out_path}) +endforeach() add_custom_target(shaders_compile ALL DEPENDS ${SPV_SHADERS})