aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordan sinclair <dj2@everburning.com>2019-03-07 15:44:31 -0500
committerGitHub <noreply@github.com>2019-03-07 15:44:31 -0500
commit0d744484eba498e30ad02cfb91b35426df470ece (patch)
tree15e738f15a7c5e4f33a37b538700831bdadcdaa5
parent6d37d69d4cde35d95f8420e879d1fa6543e4ff1c (diff)
downloadamber-0d744484eba498e30ad02cfb91b35426df470ece.tar.gz
Build with local vulkan data if requested (#319)
This CL adds a flag AMBER_USE_LOCAL_VULKAN which if set when running cmake will have amber use the vulkan header and loaders out of the third_party directory. This should let amber try to build on a system without vulkan so the build can be tested on the bots.
-rw-r--r--.gitignore1
-rw-r--r--CMakeLists.txt7
-rw-r--r--DEPS8
-rw-r--r--kokoro/scripts/linux/build.sh2
-rw-r--r--kokoro/scripts/macos/build.sh2
-rw-r--r--kokoro/scripts/windows/build.bat130
-rw-r--r--samples/config_helper_vulkan.cc37
-rw-r--r--samples/config_helper_vulkan.h6
-rw-r--r--src/vulkan/device.cc3
-rw-r--r--src/vulkan/engine_vulkan.cc2
-rw-r--r--src/vulkan/find_vulkan.cmake61
-rw-r--r--src/vulkan/vertex_buffer.cc45
-rw-r--r--src/vulkan/vertex_buffer_test.cc31
-rw-r--r--third_party/CMakeLists.txt22
14 files changed, 206 insertions, 151 deletions
diff --git a/.gitignore b/.gitignore
index 6398fa9..850a919 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@ third_party/shaderc
third_party/spirv-tools
third_party/spirv-headers
third_party/vulkan-headers
+third_party/vulkan-loader
.vs
# Vim swap files
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 71439b5..109a3d0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,7 @@ option(AMBER_SKIP_SHADERC
"Skip building Shaderc into the library" ${AMBER_SKIP_SHADERC})
option(AMBER_SKIP_SAMPLES
"Skip building sample application" ${AMBER_SKIP_SAMPLES})
+option(AMBER_USE_LOCAL_VULKAN "Build with vulkan in third_party" OFF)
if (${AMBER_SKIP_SPIRV_TOOLS})
set(AMBER_ENABLE_SPIRV_TOOLS FALSE)
@@ -65,6 +66,12 @@ else()
set(AMBER_ENABLE_SAMPLES TRUE)
endif()
+if (${AMBER_USE_LOCAL_VULKAN})
+ message(STATUS "Using python3")
+ # vulkan-loaders requires python 3
+ find_package(PythonInterp 3 REQUIRED)
+endif()
+
message(STATUS "Amber enable SPIRV-Tools: ${AMBER_ENABLE_SPIRV_TOOLS}")
message(STATUS "Amber enable Shaderc: ${AMBER_ENABLE_SHADERC}")
message(STATUS "Amber enable tests: ${AMBER_ENABLE_TESTS}")
diff --git a/DEPS b/DEPS
index 026dbae..8db61b2 100644
--- a/DEPS
+++ b/DEPS
@@ -10,9 +10,10 @@ vars = {
'googletest_revision': 'd5932506d6eed73ac80b9bcc47ed723c8c74eb1e',
'lodepng_revision': 'ba9fc1f084f03b5fbf8c9a5df9448173f27544b1',
'shaderc_revision': '53c776f776821bc037b31b8b3b79db2fa54b4ce7',
- 'spirv_headers_revision': '8bea0a266ac9b718aa0818d9e3a47c0b77c2cb23',
- 'spirv_tools_revision': '39bfb6b978e937487a9cedfd964d61a3ac4384b8',
+ 'spirv_headers_revision': '03a081524afabdde274d885880c2fef213e46a59',
+ 'spirv_tools_revision': '07f80c4df1b0619ee484c38e79a7ad71f672ca14',
'vulkan_headers_revision': '8e2c4cd554b644592a6d904f2c8000ebbd4aa77f',
+ 'vulkan_loader_revision': '15fa85d92454f7823febeb68b56038d427e2a7a4',
}
deps = {
@@ -39,4 +40,7 @@ deps = {
'third_party/vulkan-headers': vars['khronos_git'] + '/Vulkan-Headers.git@' +
vars['vulkan_headers_revision'],
+
+ 'third_party/vulkan-loader': vars['khronos_git'] + '/Vulkan-Loader.git@' +
+ vars['vulkan_loader_revision'],
}
diff --git a/kokoro/scripts/linux/build.sh b/kokoro/scripts/linux/build.sh
index a178631..7b625fd 100644
--- a/kokoro/scripts/linux/build.sh
+++ b/kokoro/scripts/linux/build.sh
@@ -52,7 +52,7 @@ mkdir build && cd $SRC/build
# Invoke the build.
BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
echo $(date): Starting build...
-cmake -GNinja -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_C_CXX_COMPILER ..
+cmake -GNinja -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_C_CXX_COMPILER -DAMBER_USE_LOCAL_VULKAN=1 ..
echo $(date): Build everything...
ninja
diff --git a/kokoro/scripts/macos/build.sh b/kokoro/scripts/macos/build.sh
index 793dd1f..acbb76b 100644
--- a/kokoro/scripts/macos/build.sh
+++ b/kokoro/scripts/macos/build.sh
@@ -36,7 +36,7 @@ CMAKE_C_CXX_COMPILER="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++"
# Invoke the build.
BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
echo $(date): Starting build...
-cmake -GNinja -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_C_CXX_COMPILER ..
+cmake -GNinja -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_C_CXX_COMPILER -DAMBER_USE_LOCAL_VULKAN=1 ..
echo $(date): Build everything...
ninja
diff --git a/kokoro/scripts/windows/build.bat b/kokoro/scripts/windows/build.bat
index b39d072..1c5d2ff 100644
--- a/kokoro/scripts/windows/build.bat
+++ b/kokoro/scripts/windows/build.bat
@@ -1,64 +1,66 @@
-:: Copyright The Amber Authors.
-::
-:: 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.
-
-@echo on
-
-set BUILD_ROOT=%cd%
-set SRC=%cd%\github\amber
-set BUILD_TYPE=%1
-
-:: Force usage of python 2.7 rather than 3.6
-set PATH=C:\python27;%PATH%
-
-cd %SRC%
-python tools\git-sync-deps
-
-:: #########################################
-:: set up msvc build env
-:: #########################################
-call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
-echo "Using VS 2017..."
-
-cd %SRC%
-mkdir build
-cd build
-
-:: #########################################
-:: Start building.
-:: #########################################
-echo "Starting build... %DATE% %TIME%"
-if "%KOKORO_GITHUB_COMMIT%." == "." (
- set BUILD_SHA=%KOKORO_GITHUB_PULL_REQUEST_COMMIT%
-) else (
- set BUILD_SHA=%KOKORO_GITHUB_COMMIT%
-)
-
-cmake -GNinja -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe ..
-
-if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%
-
-echo "Build everything... %DATE% %TIME%"
-ninja
-if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%
-echo "Build Completed %DATE% %TIME%"
-
-:: ################################################
-:: Run the tests (We no longer run tests on VS2013)
-:: ################################################
-echo "Running Tests... %DATE% %TIME%"
-amber_unittests
-if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%
-echo "Tests Completed %DATE% %TIME%"
-
-exit /b %ERRORLEVEL%
+:: Copyright The Amber Authors.
+::
+:: 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.
+
+@echo on
+
+set BUILD_ROOT=%cd%
+set SRC=%cd%\github\amber
+set BUILD_TYPE=%1
+
+set PATH=C:\python27;%PATH%
+
+cd %SRC%
+python tools\git-sync-deps
+
+:: Force usage of python 3.6
+:: Change this after the git-sync-deps as that requires python2 ...
+set PATH=C:\python36;%PATH%
+
+:: #########################################
+:: set up msvc build env
+:: #########################################
+call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
+echo "Using VS 2017..."
+
+cd %SRC%
+mkdir build
+cd build
+
+:: #########################################
+:: Start building.
+:: #########################################
+echo "Starting build... %DATE% %TIME%"
+if "%KOKORO_GITHUB_COMMIT%." == "." (
+ set BUILD_SHA=%KOKORO_GITHUB_PULL_REQUEST_COMMIT%
+) else (
+ set BUILD_SHA=%KOKORO_GITHUB_COMMIT%
+)
+
+cmake -GNinja -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DAMBER_USE_LOCAL_VULKAN=1 ..
+if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%
+
+echo "Build everything... %DATE% %TIME%"
+ninja
+if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%
+echo "Build Completed %DATE% %TIME%"
+
+:: ################################################
+:: Run the tests (We no longer run tests on VS2013)
+:: ################################################
+echo "Running Tests... %DATE% %TIME%"
+amber_unittests
+if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%
+echo "Tests Completed %DATE% %TIME%"
+
+exit /b %ERRORLEVEL%
diff --git a/samples/config_helper_vulkan.cc b/samples/config_helper_vulkan.cc
index b6de67f..0bf0ef5 100644
--- a/samples/config_helper_vulkan.cc
+++ b/samples/config_helper_vulkan.cc
@@ -592,7 +592,11 @@ std::string deviceTypeToName(VkPhysicalDeviceType type) {
} // namespace
-ConfigHelperVulkan::ConfigHelperVulkan() = default;
+ConfigHelperVulkan::ConfigHelperVulkan()
+ : available_features_(VkPhysicalDeviceFeatures()),
+ available_features2_(VkPhysicalDeviceFeatures2KHR()),
+ variable_pointers_feature_(VkPhysicalDeviceVariablePointerFeaturesKHR()) {
+}
ConfigHelperVulkan::~ConfigHelperVulkan() = default;
@@ -601,11 +605,11 @@ amber::Result ConfigHelperVulkan::CreateVulkanInstance(
uint32_t engine_minor,
std::vector<std::string> required_extensions,
bool disable_validation_layer) {
- VkApplicationInfo app_info = {};
+ VkApplicationInfo app_info = VkApplicationInfo();
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
app_info.apiVersion = VK_MAKE_VERSION(engine_major, engine_minor, 0);
- VkInstanceCreateInfo instance_info = {};
+ VkInstanceCreateInfo instance_info = VkInstanceCreateInfo();
instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instance_info.pApplicationInfo = &app_info;
@@ -655,7 +659,8 @@ amber::Result ConfigHelperVulkan::CreateVulkanInstance(
}
amber::Result ConfigHelperVulkan::CreateDebugReportCallback() {
- VkDebugReportCallbackCreateInfoEXT info = {};
+ VkDebugReportCallbackCreateInfoEXT info =
+ VkDebugReportCallbackCreateInfoEXT();
info.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
info.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
info.pfnCallback = debugCallback;
@@ -691,15 +696,17 @@ amber::Result ConfigHelperVulkan::ChooseVulkanPhysicalDevice(
return amber::Result("Unable to enumerate physical devices");
}
- VkPhysicalDeviceFeatures required_vulkan_features = {};
+ VkPhysicalDeviceFeatures required_vulkan_features =
+ VkPhysicalDeviceFeatures();
for (uint32_t i = 0; i < count; ++i) {
if (use_physical_device_features2_) {
- VkPhysicalDeviceVariablePointerFeaturesKHR var_ptrs = {};
+ VkPhysicalDeviceVariablePointerFeaturesKHR var_ptrs =
+ VkPhysicalDeviceVariablePointerFeaturesKHR();
var_ptrs.sType =
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR;
var_ptrs.pNext = nullptr;
- VkPhysicalDeviceFeatures2KHR features2 = {};
+ VkPhysicalDeviceFeatures2KHR features2 = VkPhysicalDeviceFeatures2KHR();
features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
features2.pNext = &var_ptrs;
@@ -767,7 +774,7 @@ amber::Result ConfigHelperVulkan::ChooseVulkanPhysicalDevice(
amber::Result ConfigHelperVulkan::CreateVulkanDevice(
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions) {
- VkDeviceQueueCreateInfo queue_info = {};
+ VkDeviceQueueCreateInfo queue_info = VkDeviceQueueCreateInfo();
const float priorities[] = {1.0f};
queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
@@ -781,7 +788,7 @@ amber::Result ConfigHelperVulkan::CreateVulkanDevice(
std::back_inserter(required_extensions_in_char),
[](const std::string& ext) -> const char* { return ext.c_str(); });
- VkDeviceCreateInfo info = {};
+ VkDeviceCreateInfo info = VkDeviceCreateInfo();
info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
info.pQueueCreateInfos = &queue_info;
info.queueCreateInfoCount = 1;
@@ -797,7 +804,8 @@ amber::Result ConfigHelperVulkan::CreateVulkanDevice(
amber::Result ConfigHelperVulkan::CreateDeviceWithFeatures1(
const std::vector<std::string>& required_features,
VkDeviceCreateInfo* info) {
- VkPhysicalDeviceFeatures required_vulkan_features = {};
+ VkPhysicalDeviceFeatures required_vulkan_features =
+ VkPhysicalDeviceFeatures();
amber::Result r =
NamesToVulkanFeatures(required_features, &required_vulkan_features);
if (!r.IsSuccess())
@@ -831,7 +839,8 @@ amber::Result ConfigHelperVulkan::CreateDeviceWithFeatures2(
variable_pointers_feature_.variablePointersStorageBuffer = VK_TRUE;
}
- VkPhysicalDeviceFeatures required_vulkan_features = {};
+ VkPhysicalDeviceFeatures required_vulkan_features =
+ VkPhysicalDeviceFeatures();
amber::Result r =
NamesToVulkanFeatures(feature1_names, &required_vulkan_features);
if (!r.IsSuccess())
@@ -860,9 +869,9 @@ void ConfigHelperVulkan::DumpPhysicalDeviceInfo() {
std::cout << std::endl;
std::cout << "Physical device properties:" << std::endl;
- std::cout << " apiVersion: " << VK_VERSION_MAJOR(api_version) << "."
- << VK_VERSION_MINOR(api_version) << "."
- << VK_VERSION_PATCH(api_version) << std::endl;
+ std::cout << " apiVersion: " << static_cast<uint32_t>(api_version >> 22)
+ << "." << static_cast<uint32_t>((api_version >> 12) & 0x3ff) << "."
+ << static_cast<uint32_t>(api_version & 0xfff) << std::endl;
std::cout << " driverVersion: " << props.driverVersion << std::endl;
std::cout << " vendorID: " << props.vendorID << std::endl;
std::cout << " deviceID: " << props.deviceID << std::endl;
diff --git a/samples/config_helper_vulkan.h b/samples/config_helper_vulkan.h
index 10e66d2..bf956fb 100644
--- a/samples/config_helper_vulkan.h
+++ b/samples/config_helper_vulkan.h
@@ -103,9 +103,9 @@ class ConfigHelperVulkan : public ConfigHelperImpl {
VkDevice vulkan_device_ = VK_NULL_HANDLE;
bool use_physical_device_features2_ = false;
- VkPhysicalDeviceFeatures available_features_ = {};
- VkPhysicalDeviceFeatures2KHR available_features2_ = {};
- VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointers_feature_ = {};
+ VkPhysicalDeviceFeatures available_features_;
+ VkPhysicalDeviceFeatures2KHR available_features2_;
+ VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointers_feature_;
};
} // namespace sample
diff --git a/src/vulkan/device.cc b/src/vulkan/device.cc
index 89d1948..5af9ae6 100644
--- a/src/vulkan/device.cc
+++ b/src/vulkan/device.cc
@@ -379,7 +379,8 @@ Result Device::Initialize(
}
}
- VkPhysicalDeviceFeatures available_vulkan_features = {};
+ VkPhysicalDeviceFeatures available_vulkan_features =
+ VkPhysicalDeviceFeatures();
if (use_physical_device_features_2) {
available_vulkan_features = available_features2.features;
diff --git a/src/vulkan/engine_vulkan.cc b/src/vulkan/engine_vulkan.cc
index e15ed30..1321e31 100644
--- a/src/vulkan/engine_vulkan.cc
+++ b/src/vulkan/engine_vulkan.cc
@@ -155,7 +155,7 @@ bool EngineVulkan::VerifyFormatAvailable(const Format& format,
Result EngineVulkan::CreatePipeline(amber::Pipeline* pipeline) {
// Create the pipeline data early so we can access them as needed.
- pipeline_map_[pipeline] = {};
+ pipeline_map_[pipeline] = PipelineInfo();
auto& info = pipeline_map_[pipeline];
// Set VK_FORMAT_B8G8R8A8_UNORM for color frame buffer by default.
diff --git a/src/vulkan/find_vulkan.cmake b/src/vulkan/find_vulkan.cmake
index 98a221f..42e45bd 100644
--- a/src/vulkan/find_vulkan.cmake
+++ b/src/vulkan/find_vulkan.cmake
@@ -19,34 +19,49 @@ set(Vulkan_FOUND FALSE)
set(VULKAN_CTS_HEADER FALSE)
set(VULKAN_LIB "")
-# Our first choice is to pick up the Vulkan headers from an enclosing project.
-# And if that's the case, then use Vulkan libraries as specified by
-# Vulkan_LIBRARIES, with a default library of "vulkan".
-set(X "${Vulkan-Headers_SOURCE_DIR}/include")
-if (IS_DIRECTORY "${X}")
- message(STATUS "Amber: Using Vulkan header dir ${X}")
- list(APPEND CMAKE_REQUIRED_INCLUDES "${X}")
+if (${AMBER_USE_LOCAL_VULKAN})
+ set(Vulkan_FOUND TRUE)
+ set(VulkanHeaders_INCLUDE_DIR
+ ${PROJECT_SOURCE_DIR}/third_party/vulkan-headers/include
+ CACHE PATH "vk headers dir" FORCE)
+ set(VulkanRegistry_DIR
+ ${PROJECT_SOURCE_DIR}/third_party/vulkan-headers/registry
+ CACHE PATH "vk_registry_dir" FORCE)
+ include_directories(BEFORE "${VulkanHeaders_INCLUDE_DIR}")
+ set(VULKAN_LIB vulkan)
+ message(STATUS "Amber: using local vulkan")
+endif()
- # Add the directory to the list of include paths, before any others.
- include_directories(BEFORE "${X}")
- CHECK_INCLUDE_FILE(vulkan/vulkan.h HAVE_VULKAN_HEADER)
+if (NOT ${Vulkan_FOUND})
+ # Our first choice is to pick up the Vulkan headers from an enclosing project.
+ # And if that's the case, then use Vulkan libraries as specified by
+ # Vulkan_LIBRARIES, with a default library of "vulkan".
+ set(X "${Vulkan-Headers_SOURCE_DIR}/include")
+ if (IS_DIRECTORY "${X}")
+ message(STATUS "Amber: Using Vulkan header dir ${X}")
+ list(APPEND CMAKE_REQUIRED_INCLUDES "${X}")
- if (${HAVE_VULKAN_HEADER})
- if ("${Vulkan_LIBRARIES}" STREQUAL "")
- message(STATUS "Amber: Defaulting to Vulkan library: vulkan")
- set(VULKAN_LIB vulkan)
- else()
- message(STATUS "Amber: Using specified Vulkan libraries: ${Vulkan_LIBRARIES}")
- set(VULKAN_LIB "${Vulkan_LIBRARIES}")
- endif()
+ # Add the directory to the list of include paths, before any others.
+ include_directories(BEFORE "${X}")
+ CHECK_INCLUDE_FILE(vulkan/vulkan.h HAVE_VULKAN_HEADER)
+
+ if (${HAVE_VULKAN_HEADER})
+ if ("${Vulkan_LIBRARIES}" STREQUAL "")
+ message(STATUS "Amber: Defaulting to Vulkan library: vulkan")
+ set(VULKAN_LIB vulkan)
+ else()
+ message(STATUS "Amber: Using specified Vulkan libraries: ${Vulkan_LIBRARIES}")
+ set(VULKAN_LIB "${Vulkan_LIBRARIES}")
+ endif()
- # For now assume we have Vulkan. We have its header, but we haven't checked
- # for the library.
- # TODO(dneto): Actually check for the libraries.
- set(Vulkan_FOUND TRUE)
+ # For now assume we have Vulkan. We have its header, but we haven't checked
+ # for the library.
+ # TODO(dneto): Actually check for the libraries.
+ set(Vulkan_FOUND TRUE)
+ endif()
endif()
+ unset(X)
endif()
-unset(X)
# Check if we're in the CTS
if (NOT ${Vulkan_FOUND})
diff --git a/src/vulkan/vertex_buffer.cc b/src/vulkan/vertex_buffer.cc
index babfe85..c0333f0 100644
--- a/src/vulkan/vertex_buffer.cc
+++ b/src/vulkan/vertex_buffer.cc
@@ -105,14 +105,7 @@ uint16_t FloatToHexFloat(float value, uint8_t bits) {
return 0;
}
-// Copy [0, bits) bits of |src| to
-// [dst_bit_offset, dst_bit_offset + bits) of |dst|. If |bits| is
-// less than 32 and the type is float, this method uses
-// FloatToHexFloat() to convert it into small bits float.
-Result CopyBitsOfValueToBuffer(uint8_t* dst,
- const Value& src,
- uint8_t dst_bit_offset,
- uint8_t bits) {
+Result ValueToUint64(const Value& src, uint8_t bits, uint64_t* out) {
uint64_t data = 0;
if (src.IsInteger()) {
switch (bits) {
@@ -147,17 +140,16 @@ Result CopyBitsOfValueToBuffer(uint8_t* dst,
} else {
switch (bits) {
case 32: {
- float* float_ptr = nullptr;
- float_ptr = reinterpret_cast<float*>(&data);
+ float* float_ptr = reinterpret_cast<float*>(&data);
*float_ptr = src.AsFloat();
break;
}
case 16:
case 11:
case 10: {
- uint16_t* uint16_ptr = nullptr;
- uint16_ptr = reinterpret_cast<uint16_t*>(&data);
- *uint16_ptr = FloatToHexFloat(src.AsFloat(), bits);
+ uint16_t* uint16_ptr = reinterpret_cast<uint16_t*>(&data);
+ *uint16_ptr =
+ static_cast<uint16_t>(FloatToHexFloat(src.AsFloat(), bits));
break;
}
default: {
@@ -167,10 +159,27 @@ Result CopyBitsOfValueToBuffer(uint8_t* dst,
}
}
}
+ *out = data;
+ return {};
+}
+
+// Copy [0, bits) bits of |src| to
+// [dst_bit_offset, dst_bit_offset + bits) of |dst|. If |bits| is
+// less than 32 and the type is float, this method uses
+// FloatToHexFloat() to convert it into small bits float.
+Result CopyBitsOfValueToBuffer(uint8_t* dst,
+ const Value& src,
+ uint32_t dst_bit_offset,
+ uint8_t bits) {
+ uint64_t data = 0;
+ Result r = ValueToUint64(src, bits, &data);
+ if (!r.IsSuccess())
+ return r;
+ // Shift memory pointer to the start of the byte to write into.
while (dst_bit_offset > 7) {
++dst;
- dst_bit_offset = static_cast<uint8_t>(dst_bit_offset - 8);
+ dst_bit_offset -= 8;
}
// No overflow will happen. |dst_bit_offset| is based on VkFormat
@@ -232,7 +241,7 @@ Result VertexBuffer::FillVertexBufferWithData(CommandBuffer* command) {
}
const auto& components = formats_[j].GetComponents();
- uint8_t bit_offset = 0;
+ uint32_t bit_offset = 0;
for (uint32_t k = 0; k < components.size(); ++k) {
uint8_t bits = components[k].num_bits;
@@ -241,14 +250,12 @@ Result VertexBuffer::FillVertexBufferWithData(CommandBuffer* command) {
if (!r.IsSuccess())
return r;
- if ((k != components.size() - 1) &&
- (static_cast<uint32_t>(bit_offset) + static_cast<uint32_t>(bits) >=
- 256)) {
+ if ((k != components.size() - 1) && (bit_offset + bits >= 256)) {
return Result(
"Vulkan: VertexBuffer::FillVertexBufferWithData bit_offset "
"overflow");
}
- bit_offset = static_cast<uint8_t>(bit_offset + bits);
+ bit_offset += bits;
}
ptr += formats_[j].GetByteSize();
diff --git a/src/vulkan/vertex_buffer_test.cc b/src/vulkan/vertex_buffer_test.cc
index 0d01ef2..e575535 100644
--- a/src/vulkan/vertex_buffer_test.cc
+++ b/src/vulkan/vertex_buffer_test.cc
@@ -90,7 +90,6 @@ TEST_F(VertexBufferTest, R8G8B8A8_UINT) {
values[3].SetIntValue(255);
Format format;
- format.SetFormatType(FormatType::kR8G8B8A8_UINT);
format.AddComponent(FormatComponentType::kR, FormatMode::kUInt, 8);
format.AddComponent(FormatComponentType::kG, FormatMode::kUInt, 8);
format.AddComponent(FormatComponentType::kB, FormatMode::kUInt, 8);
@@ -112,7 +111,6 @@ TEST_F(VertexBufferTest, R16G16B16A16_UINT) {
values[3].SetIntValue(255);
Format format;
- format.SetFormatType(FormatType::kR16G16B16A16_UINT);
format.AddComponent(FormatComponentType::kR, FormatMode::kUInt, 16);
format.AddComponent(FormatComponentType::kG, FormatMode::kUInt, 16);
format.AddComponent(FormatComponentType::kB, FormatMode::kUInt, 16);
@@ -134,7 +132,6 @@ TEST_F(VertexBufferTest, R32G32B32A32_UINT) {
values[3].SetIntValue(255);
Format format;
- format.SetFormatType(FormatType::kR32G32B32A32_UINT);
format.AddComponent(FormatComponentType::kR, FormatMode::kUInt, 32);
format.AddComponent(FormatComponentType::kG, FormatMode::kUInt, 32);
format.AddComponent(FormatComponentType::kB, FormatMode::kUInt, 32);
@@ -156,7 +153,6 @@ TEST_F(VertexBufferTest, R64G64B64A64_UINT) {
values[3].SetIntValue(255);
Format format;
- format.SetFormatType(FormatType::kR64G64B64A64_UINT);
format.AddComponent(FormatComponentType::kR, FormatMode::kUInt, 64);
format.AddComponent(FormatComponentType::kG, FormatMode::kUInt, 64);
format.AddComponent(FormatComponentType::kB, FormatMode::kUInt, 64);
@@ -178,7 +174,6 @@ TEST_F(VertexBufferTest, R8G8B8A8_SNORM) {
values[3].SetIntValue(127);
Format format;
- format.SetFormatType(FormatType::kR8G8B8A8_SNORM);
format.AddComponent(FormatComponentType::kR, FormatMode::kSNorm, 8);
format.AddComponent(FormatComponentType::kG, FormatMode::kSNorm, 8);
format.AddComponent(FormatComponentType::kB, FormatMode::kSNorm, 8);
@@ -200,7 +195,6 @@ TEST_F(VertexBufferTest, R16G16B16A16_SNORM) {
values[3].SetIntValue(255);
Format format;
- format.SetFormatType(FormatType::kR16G16B16A16_SNORM);
format.AddComponent(FormatComponentType::kR, FormatMode::kSNorm, 16);
format.AddComponent(FormatComponentType::kG, FormatMode::kSNorm, 16);
format.AddComponent(FormatComponentType::kB, FormatMode::kSNorm, 16);
@@ -222,7 +216,6 @@ TEST_F(VertexBufferTest, R32G32B32A32_SINT) {
values[3].SetIntValue(255);
Format format;
- format.SetFormatType(FormatType::kR32G32B32A32_SINT);
format.AddComponent(FormatComponentType::kR, FormatMode::kSInt, 32);
format.AddComponent(FormatComponentType::kG, FormatMode::kSInt, 32);
format.AddComponent(FormatComponentType::kB, FormatMode::kSInt, 32);
@@ -244,7 +237,6 @@ TEST_F(VertexBufferTest, R64G64B64A64_SINT) {
values[3].SetIntValue(255);
Format format;
- format.SetFormatType(FormatType::kR64G64B64A64_SINT);
format.AddComponent(FormatComponentType::kR, FormatMode::kSInt, 64);
format.AddComponent(FormatComponentType::kG, FormatMode::kSInt, 64);
format.AddComponent(FormatComponentType::kB, FormatMode::kSInt, 64);
@@ -264,24 +256,23 @@ TEST_F(VertexBufferTest, R16G11B10_SFLOAT) {
// 16 bits float to float
// Sig / Exp / Mantissa Sig / Exp / Mantissa
// 1 / 17 / 512 --> 1 / 129 / 4194304 = -1.1(2) * 2^2 = -6
- uint64_t expected = 50688UL;
+ uint64_t expected = 50688ULL;
values[0].SetDoubleValue(-6.0);
// 11 bits float to float
// Sig / Exp / Mantissa Sig / Exp / Mantissa
// 0 / 18 / 48 --> 0 / 130 / 12582912 = 1.11(2) * 2^3 = 14
- expected |= 1200UL << 16UL;
+ expected |= 1200ULL << 16ULL;
values[1].SetDoubleValue(14.0);
// 10 bits float to float
// Sig / Exp / Mantissa Sig / Exp / Mantissa
// 0 / 11 / 28 --> 1 / 123 / 14680064 = 1.111(2) * 2^-4
// = 0.1171875
- expected |= 380UL << (16UL + 11UL);
+ expected |= 380ULL << (16ULL + 11ULL);
values[2].SetDoubleValue(0.1171875);
Format format;
- format.SetFormatType(FormatType::kR8G8B8_UNORM);
format.AddComponent(FormatComponentType::kR, FormatMode::kSFloat, 16);
format.AddComponent(FormatComponentType::kG, FormatMode::kSFloat, 11);
format.AddComponent(FormatComponentType::kB, FormatMode::kSFloat, 10);
@@ -298,23 +289,22 @@ TEST_F(VertexBufferTest, R10G16B11_SFLOAT) {
// Sig / Exp / Mantissa Sig / Exp / Mantissa
// 0 / 11 / 28 --> 1 / 123 / 14680064 = 1.111(2) * 2^-4
// = 0.1171875
- uint64_t expected = 380UL;
+ uint64_t expected = 380ULL;
values[0].SetDoubleValue(0.1171875);
// 16 bits float to float
// Sig / Exp / Mantissa Sig / Exp / Mantissa
// 1 / 17 / 512 --> 1 / 129 / 4194304 = -1.1(2) * 2^2 = -6
- expected |= 50688UL << 10UL;
+ expected |= 50688ULL << 10ULL;
values[1].SetDoubleValue(-6.0);
// 11 bits float to float
// Sig / Exp / Mantissa Sig / Exp / Mantissa
// 0 / 18 / 48 --> 0 / 130 / 12582912 = 1.11(2) * 2^3 = 14
- expected |= 1200UL << (16UL + 10UL);
+ expected |= 1200ULL << (16ULL + 10ULL);
values[2].SetDoubleValue(14.0);
Format format;
- format.SetFormatType(FormatType::kR8G8B8_UNORM);
format.AddComponent(FormatComponentType::kR, FormatMode::kSFloat, 10);
format.AddComponent(FormatComponentType::kG, FormatMode::kSFloat, 16);
format.AddComponent(FormatComponentType::kB, FormatMode::kSFloat, 11);
@@ -330,24 +320,23 @@ TEST_F(VertexBufferTest, R11G16B10_SFLOAT) {
// 11 bits float to float
// Sig / Exp / Mantissa Sig / Exp / Mantissa
// 0 / 18 / 48 --> 0 / 130 / 12582912 = 1.11(2) * 2^3 = 14
- uint64_t expected = 1200UL;
+ uint64_t expected = 1200ULL;
values[0].SetDoubleValue(14.0);
// 16 bits float to float
// Sig / Exp / Mantissa Sig / Exp / Mantissa
// 1 / 17 / 512 --> 1 / 129 / 4194304 = -1.1(2) * 2^2 = -6
- expected |= 50688UL << 11UL;
+ expected |= 50688ULL << 11ULL;
values[1].SetDoubleValue(-6.0);
// 10 bits float to float
// Sig / Exp / Mantissa Sig / Exp / Mantissa
// 0 / 11 / 28 --> 1 / 123 / 14680064 = 1.111(2) * 2^-4
// = 0.1171875
- expected |= 380UL << (16UL + 11UL);
+ expected |= 380ULL << (16ULL + 11ULL);
values[2].SetDoubleValue(0.1171875);
Format format;
- format.SetFormatType(FormatType::kR8G8B8_UNORM);
format.AddComponent(FormatComponentType::kR, FormatMode::kSFloat, 11);
format.AddComponent(FormatComponentType::kG, FormatMode::kSFloat, 16);
format.AddComponent(FormatComponentType::kB, FormatMode::kSFloat, 10);
@@ -364,7 +353,6 @@ TEST_F(VertexBufferTest, R32G32B32_SFLOAT) {
values[2].SetDoubleValue(0.1171875);
Format format;
- format.SetFormatType(FormatType::kR32G32B32A32_SFLOAT);
format.AddComponent(FormatComponentType::kR, FormatMode::kSFloat, 32);
format.AddComponent(FormatComponentType::kG, FormatMode::kSFloat, 32);
format.AddComponent(FormatComponentType::kB, FormatMode::kSFloat, 32);
@@ -383,7 +371,6 @@ TEST_F(VertexBufferTest, R64G64B64_SFLOAT) {
values[2].SetDoubleValue(0.1171875);
Format format;
- format.SetFormatType(FormatType::kR64G64B64A64_SFLOAT);
format.AddComponent(FormatComponentType::kR, FormatMode::kSFloat, 64);
format.AddComponent(FormatComponentType::kG, FormatMode::kSFloat, 64);
format.AddComponent(FormatComponentType::kB, FormatMode::kSFloat, 64);
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index 6e29dde..7020678 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -142,6 +142,10 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
-Wno-weak-vtables
-Wno-zero-as-null-pointer-constant
)
+
+ set(VULKAN_LOADER_BUILD_FIXES
+ -Wno-unknown-warning-option
+ )
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
@@ -164,6 +168,8 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(SHADERC_BUILD_FIXES
-Wno-missing-field-initializers
-Wno-pedantic)
+
+ set(VULKAN_LOADER_BUILD_FIXES "")
endif()
if (MSVC)
@@ -240,6 +246,10 @@ if (MSVC)
/wd5027
/wd5039
/wd5045)
+
+ set(VULKAN_LOADER_BUILD_FIXES
+ /W3
+ )
endif()
if (${AMBER_ENABLE_TESTS})
@@ -297,3 +307,15 @@ if (${AMBER_ENABLE_SAMPLES})
add_library(lodepng STATIC ${LODEPNG_SOURCES})
endif()
+
+if (${AMBER_USE_LOCAL_VULKAN})
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-headers)
+
+ set(CXX_BACK ${CMAKE_CXX_FLAGS})
+ SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "${VULKAN_LOADER_BUILD_FIXES}")
+ STRING(REGEX REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ set(BUILD_TESTS FALSE)
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-loader)
+ set(CMAKE_CXX_FLAGS ${CXX_BACK})
+endif()
+