aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
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.
Diffstat (limited to 'src')
-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
5 files changed, 76 insertions, 66 deletions
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);