Commit 9418b511 by Antonio Maiorano

CMake: split out Vulkan sources into separate CMakeLists

Add CMakeLists.txt to the following folders under src that create the following targets: Device -> vk_device Pipeline -> vk_pipeline WSI -> vk_wsi System -> vk_system Vulkan -> vk_swiftshader Dependencies (by folder): System --> n/a Pipeline --> System Device* Vulkan* WSI --> System Pipeline Vulkan* Device --> System Pipeline Vulkan* Vulkan --> Device Pipeline WSI System * = dependency by include directory only (should fix this in the future) Also make system-unittests and system-benchmarks depend on vk_system rather than build part of System source files. Bug: b/145758253 Change-Id: I9cce59ca90d91601696f6195326b5fd7dde517d5 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43690 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent efca5651
# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(ROOT_PROJECT_COMPILE_OPTIONS
${SWIFTSHADER_COMPILE_OPTIONS}
${WARNINGS_AS_ERRORS}
)
set(DEVICE_SRC_FILES
ASTC_Decoder.cpp
ASTC_Decoder.hpp
BC_Decoder.cpp
BC_Decoder.hpp
Blitter.cpp
Blitter.hpp
Clipper.cpp
Clipper.hpp
Config.hpp
Context.cpp
Context.hpp
ETC_Decoder.cpp
ETC_Decoder.hpp
LRUCache.hpp
Memset.hpp
PixelProcessor.cpp
PixelProcessor.hpp
Polygon.hpp
Primitive.hpp
QuadRasterizer.cpp
QuadRasterizer.hpp
Rasterizer.hpp
Renderer.cpp
Renderer.hpp
RoutineCache.hpp
Sampler.hpp
SetupProcessor.cpp
SetupProcessor.hpp
Stream.hpp
Triangle.hpp
Vertex.hpp
VertexProcessor.cpp
VertexProcessor.hpp
)
add_library(vk_device EXCLUDE_FROM_ALL
${DEVICE_SRC_FILES}
)
set_target_properties(vk_device PROPERTIES
POSITION_INDEPENDENT_CODE 1
FOLDER "SwiftShader VK"
LINK_FLAGS "${SWIFTSHADER_LINK_FLAGS}"
)
target_include_directories(vk_device
PUBLIC
".."
"${CMAKE_SOURCE_DIR}/include"
)
target_compile_options(vk_device
PUBLIC
${ROOT_PROJECT_COMPILE_OPTIONS}
)
target_link_libraries(vk_device
PUBLIC
vk_pipeline
)
# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(ROOT_PROJECT_COMPILE_OPTIONS
${SWIFTSHADER_COMPILE_OPTIONS}
${WARNINGS_AS_ERRORS}
)
set(PIPELINE_SRC_FILES
ComputeProgram.cpp
ComputeProgram.hpp
Constants.cpp
Constants.hpp
PixelProgram.cpp
PixelProgram.hpp
PixelRoutine.cpp
PixelRoutine.hpp
SamplerCore.cpp
SamplerCore.hpp
SetupRoutine.cpp
SetupRoutine.hpp
ShaderCore.cpp
ShaderCore.hpp
SpirvID.hpp
SpirvShader.cpp
SpirvShader.hpp
SpirvShaderArithmetic.cpp
SpirvShaderControlFlow.cpp
SpirvShaderDebugger.cpp
SpirvShaderEnumNames.cpp
SpirvShaderGLSLstd450.cpp
SpirvShaderGroup.cpp
SpirvShaderImage.cpp
SpirvShaderInstructions.cpp
SpirvShaderMemory.cpp
SpirvShaderSampling.cpp
SpirvShaderSpec.cpp
VertexProgram.cpp
VertexProgram.hpp
VertexRoutine.cpp
VertexRoutine.hpp
)
add_library(vk_pipeline EXCLUDE_FROM_ALL
${PIPELINE_SRC_FILES}
)
# Add SPIRV-Tools dep
if (NOT TARGET SPIRV-Tools)
message(FATAL_ERROR "Missing required target: SPIRV-Tools")
endif()
set_target_properties(core_tables PROPERTIES FOLDER "SPIRV-Tools build")
set_target_properties(enum_string_mapping PROPERTIES FOLDER "SPIRV-Tools build")
set_target_properties(extinst_tables PROPERTIES FOLDER "SPIRV-Tools build")
set_target_properties(spirv-tools-pkg-config PROPERTIES FOLDER "SPIRV-Tools build")
set_target_properties(spirv-tools-shared-pkg-config PROPERTIES FOLDER "SPIRV-Tools build")
# Copy the OpenCLDebugInfo100.h header that's generated by SPIRV-Tools
# out to a separate directory that can be added to the include path.
# Ideally, this header would just be pre-built and part of SPIRV-Headers.
# See: https://github.com/KhronosGroup/SPIRV-Headers/issues/137
set(SPIRV_TOOLS_EXT_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/spirv-tools-ext/include)
add_custom_command(
OUTPUT "${SPIRV_TOOLS_EXT_INC_DIR}/spirv-tools/ext/OpenCLDebugInfo100.h"
DEPENDS spirv-tools-header-OpenCLDebugInfo100
COMMAND ${CMAKE_COMMAND} -E copy
"${spirv-tools_BINARY_DIR}/OpenCLDebugInfo100.h"
"${SPIRV_TOOLS_EXT_INC_DIR}/spirv-tools/ext/OpenCLDebugInfo100.h"
)
add_custom_target(spirv_tools_ext_includes
DEPENDS "${SPIRV_TOOLS_EXT_INC_DIR}/spirv-tools/ext/OpenCLDebugInfo100.h")
set_target_properties(spirv_tools_ext_includes PROPERTIES FOLDER "SPIRV-Tools build")
add_dependencies(vk_pipeline spirv_tools_ext_includes)
set_target_properties(vk_pipeline PROPERTIES
POSITION_INDEPENDENT_CODE 1
FOLDER "SwiftShader VK"
LINK_FLAGS "${SWIFTSHADER_LINK_FLAGS}"
)
target_include_directories(vk_pipeline
PUBLIC
".."
"${CMAKE_SOURCE_DIR}/include"
"${SPIRV-Headers_SOURCE_DIR}/include"
"${SPIRV_TOOLS_EXT_INC_DIR}"
)
target_compile_options(vk_pipeline
PUBLIC
${ROOT_PROJECT_COMPILE_OPTIONS}
)
target_link_libraries(vk_pipeline
PUBLIC
vk_base
vk_system
marl
SPIRV-Tools
SPIRV-Tools-opt
)
# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(ROOT_PROJECT_COMPILE_OPTIONS
${SWIFTSHADER_COMPILE_OPTIONS}
${WARNINGS_AS_ERRORS}
)
set(SYSTEM_SRC_FILES
Build.cpp
Build.hpp
Configurator.cpp
Configurator.hpp
CPUID.cpp
CPUID.hpp
Debug.cpp
Debug.hpp
Half.cpp
Half.hpp
Math.cpp
Math.hpp
Memory.cpp
Memory.hpp
SharedLibrary.hpp
Socket.cpp
Socket.hpp
Synchronization.hpp
Timer.cpp
Timer.hpp
Types.hpp
)
if(LINUX OR ANDROID)
list(APPEND SYSTEM_SRC_FILES
Linux/MemFd.cpp
Linux/MemFd.hpp
)
endif()
add_library(vk_system EXCLUDE_FROM_ALL
${SYSTEM_SRC_FILES}
)
set_target_properties(vk_system PROPERTIES
POSITION_INDEPENDENT_CODE 1
FOLDER "SwiftShader VK"
LINK_FLAGS "${SWIFTSHADER_LINK_FLAGS}"
)
target_include_directories(vk_system
PUBLIC
".."
)
target_compile_options(vk_system
PUBLIC
${ROOT_PROJECT_COMPILE_OPTIONS}
)
# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(ROOT_PROJECT_COMPILE_OPTIONS
${SWIFTSHADER_COMPILE_OPTIONS}
${WARNINGS_AS_ERRORS}
)
set(VULKAN_SRC_FILES
libVulkan.cpp
main.cpp
resource.h
Version.h
VkBuffer.cpp
VkBuffer.hpp
VkBufferView.cpp
VkBufferView.hpp
VkCommandBuffer.cpp
VkCommandBuffer.hpp
VkCommandPool.cpp
VkCommandPool.hpp
VkConfig.h
VkDescriptorPool.cpp
VkDescriptorPool.hpp
VkDescriptorSet.hpp
VkDescriptorSetLayout.cpp
VkDescriptorSetLayout.hpp
VkDescriptorUpdateTemplate.cpp
VkDescriptorUpdateTemplate.hpp
VkDestroy.h
VkDevice.cpp
VkDevice.hpp
VkDeviceMemory.cpp
VkDeviceMemory.hpp
VkDeviceMemoryExternalAndroid.hpp
VkDeviceMemoryExternalLinux.hpp
VkEvent.hpp
VkFence.hpp
VkFormat.cpp
VkFormat.h
VkFramebuffer.cpp
VkFramebuffer.hpp
VkGetProcAddress.cpp
VkGetProcAddress.h
VkImage.cpp
VkImage.hpp
VkImageView.cpp
VkImageView.hpp
VkInstance.cpp
VkInstance.hpp
VkMemory.cpp
VkMemory.h
VkObject.hpp
VkPhysicalDevice.cpp
VkPhysicalDevice.hpp
VkPipeline.cpp
VkPipeline.hpp
VkPipelineCache.cpp
VkPipelineCache.hpp
VkPipelineLayout.cpp
VkPipelineLayout.hpp
VkPromotedExtensions.cpp
VkQueryPool.cpp
VkQueryPool.hpp
VkQueue.cpp
VkQueue.hpp
VkRenderPass.cpp
VkRenderPass.hpp
VkSampler.cpp
VkSampler.hpp
VkSemaphore.cpp
VkSemaphore.hpp
VkSemaphoreExternalFuchsia.hpp
VkSemaphoreExternalLinux.hpp
VkShaderModule.cpp
VkShaderModule.hpp
VkStringify.cpp
VkStringify.hpp
VulkanPlatform.h
)
if(WIN32)
list(APPEND VULKAN_SRC_FILES
Vulkan.rc
)
endif()
if(SWIFTSHADER_ENABLE_VULKAN_DEBUGGER)
list(APPEND VULKAN_SRC_FILES
Context.cpp
Context.hpp
Debug.cpp
EventListener.hpp
File.cpp
File.hpp
ID.hpp
Location.hpp
Server.cpp
Server.hpp
Thread.cpp
Thread.hpp
Type.cpp
Type.hpp
Value.cpp
Value.hpp
Variable.hpp
WeakMap.hpp
)
endif()
set(VULKAN_COMPILE_OPTIONS "")
if(FUCHSIA)
# At the moment, the Fuchsia build uses unofficial VK_STRUCTURE_TYPE_XX
# constants that are defined as macros in <vulkan/fuchsia_extras.h>. When
# these appear in switch() cases, the compiler complains that the values
# are not part of the VkStructureType enum. Silence this warning, until
# the constants are upstreamed to the official Vulkan headers.
list(APPEND VULKAN_COMPILE_OPTIONS "-Wno-switch")
endif()
set(VULKAN_LINKER_FLAGS "")
if(FUCHSIA)
# On Fuchsia, the Vulkan ICD is loaded into a process sandbox that doesn't
# have system libraries available, so ensure it does not depend on libc++.so.
list(APPEND VULKAN_LINKER_FLAGS "-static-libstdc++")
endif()
# Convert list to space-delimited string for LINK_FLAGS
string(REPLACE ";" " " VULKAN_LINKER_FLAGS "${VULKAN_LINKER_FLAGS}")
add_library(vk_swiftshader SHARED
${VULKAN_SRC_FILES}
)
set_target_properties(vk_swiftshader PROPERTIES
POSITION_INDEPENDENT_CODE 1
FOLDER "SwiftShader VK"
LINK_FLAGS "${SWIFTSHADER_LINK_FLAGS} ${VULKAN_LINKER_FLAGS}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
target_include_directories(vk_swiftshader
PRIVATE
".."
# "${CMAKE_SOURCE_DIR}/include"
)
target_compile_options(vk_swiftshader
PRIVATE
${ROOT_PROJECT_COMPILE_OPTIONS}
${VULKAN_COMPILE_OPTIONS}
)
target_compile_definitions(vk_swiftshader
PRIVATE
"VK_EXPORT="
$<$<CONFIG:Debug>:"DEBUGGER_WAIT_DIALOG">
)
target_link_libraries(vk_swiftshader
PRIVATE
vk_system
vk_pipeline
vk_device
vk_wsi
${Reactor}
marl
${OS_LIBS}
${SWIFTSHADER_LIBS}
$<$<BOOL:${SWIFTSHADER_ENABLE_VULKAN_DEBUGGER}>:cppdap>
$<$<BOOL:${SWIFTSHADER_ENABLE_ASTC}>:astc-encoder>
)
set_shared_library_export_map(vk_swiftshader ${CMAKE_CURRENT_SOURCE_DIR})
if(WIN32)
set(VULKAN_API_LIBRARY_NAME "vulkan-1.dll")
elseif(LINUX)
set(VULKAN_API_LIBRARY_NAME "libvulkan.so.1")
elseif(APPLE)
set(VULKAN_API_LIBRARY_NAME "libvulkan.dylib")
elseif(FUCHSIA)
set(VULKAN_API_LIBRARY_NAME "libvulkan.so")
else()
message(FATAL_ERROR "Platform does not support Vulkan yet")
endif()
add_custom_command(
TARGET vk_swiftshader
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vk_swiftshader> ${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vk_swiftshader> ${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/${VULKAN_API_LIBRARY_NAME}
)
# The vk_swiftshader_icd.json manifest file will point to ICD_LIBRARY_PATH.
# Set ICD_LIBRARY_PATH to be a relative path similar to "./libvk_swiftshader.so", so both files can be moved.
# A relative path is relative to the manifest file.
set(ICD_LIBRARY_PATH "${CMAKE_SHARED_LIBRARY_PREFIX}vk_swiftshader${CMAKE_SHARED_LIBRARY_SUFFIX}")
if(WIN32)
# The path is output to a JSON file, which requires backslashes to be escaped.
set(ICD_LIBRARY_PATH ".\\\\${ICD_LIBRARY_PATH}")
else()
set(ICD_LIBRARY_PATH "./${ICD_LIBRARY_PATH}")
endif()
configure_file(
"vk_swiftshader_icd.json.tmpl"
"${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}/vk_swiftshader_icd.json"
)
# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(ROOT_PROJECT_COMPILE_OPTIONS
${SWIFTSHADER_COMPILE_OPTIONS}
${WARNINGS_AS_ERRORS}
)
set(WSI_SRC_FILES
VkSurfaceKHR.cpp
VkSurfaceKHR.hpp
VkSwapchainKHR.cpp
VkSwapchainKHR.hpp
)
if(WIN32)
list(APPEND WSI_SRC_FILES
Win32SurfaceKHR.cpp
Win32SurfaceKHR.hpp
)
elseif(LINUX)
if(X11)
list(APPEND WSI_SRC_FILES
XlibSurfaceKHR.cpp
XlibSurfaceKHR.hpp
libX11.cpp
libX11.hpp
)
endif()
if(XCB)
list(APPEND WSI_SRC_FILES
XcbSurfaceKHR.cpp
XcbSurfaceKHR.hpp
)
endif()
elseif(APPLE)
list(APPEND WSI_SRC_FILES
MetalSurface.mm
MetalSurface.h
)
endif()
add_library(vk_wsi EXCLUDE_FROM_ALL
${WSI_SRC_FILES}
)
set_target_properties(vk_wsi PROPERTIES
POSITION_INDEPENDENT_CODE 1
FOLDER "SwiftShader VK"
LINK_FLAGS "${SWIFTSHADER_LINK_FLAGS}"
)
target_include_directories(vk_wsi
PUBLIC
".."
"${CMAKE_SOURCE_DIR}/include"
)
target_compile_options(vk_wsi
PUBLIC
${ROOT_PROJECT_COMPILE_OPTIONS}
)
target_link_libraries(vk_wsi
PUBLIC
vk_pipeline
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment