Commit 926f1caa by Yi Xu Committed by Commit Bot

Add support for GCC Compilers

Add support for GCC Compilers, so it can be build on Ubuntu. BUG=angleproject:3392 Change-Id: I2f5ac7355a40f52123bd465f86b1e966c59c943d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1592062Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Yi Xu <yiyix@chromium.org>
parent 69f72b41
...@@ -248,7 +248,7 @@ std::ostream &FmtHex(std::ostream &os, T value) ...@@ -248,7 +248,7 @@ std::ostream &FmtHex(std::ostream &os, T value)
# define EVENT(message, ...) (void(0)) # define EVENT(message, ...) (void(0))
#endif #endif
#if defined(COMPILER_GCC) || defined(__clang__) #if defined(__GNUC__)
# define ANGLE_CRASH() __builtin_trap() # define ANGLE_CRASH() __builtin_trap()
#else #else
# define ANGLE_CRASH() ((void)(*(volatile char *)0 = 0)), __assume(0) # define ANGLE_CRASH() ((void)(*(volatile char *)0 = 0)), __assume(0)
...@@ -336,7 +336,7 @@ std::ostream &FmtHex(std::ostream &os, T value) ...@@ -336,7 +336,7 @@ std::ostream &FmtHex(std::ostream &os, T value)
# define ANGLE_ENABLE_STRUCT_PADDING_WARNINGS \ # define ANGLE_ENABLE_STRUCT_PADDING_WARNINGS \
_Pragma("clang diagnostic push") _Pragma("clang diagnostic error \"-Wpadded\"") _Pragma("clang diagnostic push") _Pragma("clang diagnostic error \"-Wpadded\"")
# define ANGLE_DISABLE_STRUCT_PADDING_WARNINGS _Pragma("clang diagnostic pop") # define ANGLE_DISABLE_STRUCT_PADDING_WARNINGS _Pragma("clang diagnostic pop")
#elif defined(COMPILER_GCC) #elif defined(__GNUC__)
# define ANGLE_ENABLE_STRUCT_PADDING_WARNINGS \ # define ANGLE_ENABLE_STRUCT_PADDING_WARNINGS \
_Pragma("GCC diagnostic push") _Pragma("GCC diagnostic error \"-Wpadded\"") _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic error \"-Wpadded\"")
# define ANGLE_DISABLE_STRUCT_PADDING_WARNINGS _Pragma("GCC diagnostic pop") # define ANGLE_DISABLE_STRUCT_PADDING_WARNINGS _Pragma("GCC diagnostic pop")
......
...@@ -209,7 +209,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMissingBugId) ...@@ -209,7 +209,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMissingBugId)
EXPECT_FALSE(parser.loadTestExpectations(config, line)); EXPECT_FALSE(parser.loadTestExpectations(config, line));
EXPECT_EQ(parser.getErrorMessages().size(), 1u); EXPECT_EQ(parser.getErrorMessages().size(), 1u);
if (parser.getErrorMessages().size() >= 1) if (parser.getErrorMessages().size() >= 1)
{
EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format"); EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format");
}
// Default behavior is to let missing tests pass // Default behavior is to let missing tests pass
EXPECT_EQ( EXPECT_EQ(
parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"), parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"),
...@@ -227,7 +229,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMissingBugIdWithCon ...@@ -227,7 +229,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMissingBugIdWithCon
EXPECT_FALSE(parser.loadTestExpectations(config, line)); EXPECT_FALSE(parser.loadTestExpectations(config, line));
EXPECT_EQ(parser.getErrorMessages().size(), 1u); EXPECT_EQ(parser.getErrorMessages().size(), 1u);
if (parser.getErrorMessages().size() >= 1) if (parser.getErrorMessages().size() >= 1)
{
EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format"); EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format");
}
// Default behavior is to let missing tests pass // Default behavior is to let missing tests pass
EXPECT_EQ( EXPECT_EQ(
parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"), parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"),
...@@ -243,7 +247,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMissingColon) ...@@ -243,7 +247,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMissingColon)
EXPECT_FALSE(parser.loadTestExpectations(config, line)); EXPECT_FALSE(parser.loadTestExpectations(config, line));
EXPECT_EQ(parser.getErrorMessages().size(), 1u); EXPECT_EQ(parser.getErrorMessages().size(), 1u);
if (parser.getErrorMessages().size() >= 1) if (parser.getErrorMessages().size() >= 1)
{
EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format"); EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format");
}
// Default behavior is to let missing tests pass // Default behavior is to let missing tests pass
EXPECT_EQ( EXPECT_EQ(
parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"), parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"),
...@@ -278,7 +284,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMissingEquals) ...@@ -278,7 +284,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMissingEquals)
EXPECT_FALSE(parser.loadTestExpectations(config, line)); EXPECT_FALSE(parser.loadTestExpectations(config, line));
EXPECT_EQ(parser.getErrorMessages().size(), 1u); EXPECT_EQ(parser.getErrorMessages().size(), 1u);
if (parser.getErrorMessages().size() >= 1) if (parser.getErrorMessages().size() >= 1)
{
EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format"); EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format");
}
// Default behavior is to let missing tests pass // Default behavior is to let missing tests pass
EXPECT_EQ( EXPECT_EQ(
parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"), parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"),
...@@ -294,7 +302,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMissingExpectation) ...@@ -294,7 +302,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMissingExpectation)
EXPECT_FALSE(parser.loadTestExpectations(config, line)); EXPECT_FALSE(parser.loadTestExpectations(config, line));
EXPECT_EQ(parser.getErrorMessages().size(), 1u); EXPECT_EQ(parser.getErrorMessages().size(), 1u);
if (parser.getErrorMessages().size() >= 1) if (parser.getErrorMessages().size() >= 1)
{
EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format"); EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format");
}
// Default behavior is to let missing tests pass // Default behavior is to let missing tests pass
EXPECT_EQ( EXPECT_EQ(
parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"), parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"),
...@@ -311,7 +321,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserInvalidExpectation) ...@@ -311,7 +321,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserInvalidExpectation)
EXPECT_FALSE(parser.loadTestExpectations(config, line)); EXPECT_FALSE(parser.loadTestExpectations(config, line));
EXPECT_EQ(parser.getErrorMessages().size(), 1u); EXPECT_EQ(parser.getErrorMessages().size(), 1u);
if (parser.getErrorMessages().size() >= 1) if (parser.getErrorMessages().size() >= 1)
{
EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format"); EXPECT_EQ(parser.getErrorMessages()[0], "Line 1 : entry with wrong format");
}
// Default behavior is to let missing tests pass // Default behavior is to let missing tests pass
EXPECT_EQ( EXPECT_EQ(
parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"), parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"),
...@@ -330,8 +342,10 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserUnimplementedCondit ...@@ -330,8 +342,10 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserUnimplementedCondit
EXPECT_FALSE(parser.loadTestExpectations(config, line)); EXPECT_FALSE(parser.loadTestExpectations(config, line));
EXPECT_EQ(parser.getErrorMessages().size(), 1u); EXPECT_EQ(parser.getErrorMessages().size(), 1u);
if (parser.getErrorMessages().size() >= 1) if (parser.getErrorMessages().size() >= 1)
{
EXPECT_EQ(parser.getErrorMessages()[0], EXPECT_EQ(parser.getErrorMessages()[0],
"Line 1 : entry invalid, likely unimplemented modifiers"); "Line 1 : entry invalid, likely unimplemented modifiers");
}
// Default behavior is to let missing tests pass // Default behavior is to let missing tests pass
EXPECT_EQ( EXPECT_EQ(
parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"), parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.ubo.vertex_binding_max"),
...@@ -368,7 +382,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMisspelledExpectati ...@@ -368,7 +382,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserMisspelledExpectati
GPUTestExpectationsParser::kGpuTestPass); GPUTestExpectationsParser::kGpuTestPass);
EXPECT_EQ(parser.getUnusedExpectationsMessages().size(), 1u); EXPECT_EQ(parser.getUnusedExpectationsMessages().size(), 1u);
if (parser.getUnusedExpectationsMessages().size() >= 1) if (parser.getUnusedExpectationsMessages().size() >= 1)
{
EXPECT_EQ(parser.getUnusedExpectationsMessages()[0], "Line 1: expectation was unused."); EXPECT_EQ(parser.getUnusedExpectationsMessages()[0], "Line 1: expectation was unused.");
}
} }
// Wild characters that match groups of expectations can be overridden with more specific lines. // Wild characters that match groups of expectations can be overridden with more specific lines.
...@@ -389,7 +405,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserOverrideExpectation ...@@ -389,7 +405,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserOverrideExpectation
// The FAIL expectation was unused because it was overridden. // The FAIL expectation was unused because it was overridden.
EXPECT_EQ(parser.getUnusedExpectationsMessages().size(), 1u); EXPECT_EQ(parser.getUnusedExpectationsMessages().size(), 1u);
if (parser.getUnusedExpectationsMessages().size() >= 1) if (parser.getUnusedExpectationsMessages().size() >= 1)
{
EXPECT_EQ(parser.getUnusedExpectationsMessages()[0], "Line 1: expectation was unused."); EXPECT_EQ(parser.getUnusedExpectationsMessages()[0], "Line 1: expectation was unused.");
}
// Now try a test that doesn't match the override criteria // Now try a test that doesn't match the override criteria
EXPECT_EQ(parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.image.test"), EXPECT_EQ(parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.image.test"),
GPUTestExpectationsParser::kGpuTestFail); GPUTestExpectationsParser::kGpuTestFail);
...@@ -414,7 +432,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserOverrideExpectation ...@@ -414,7 +432,9 @@ TEST(GPUTestExpectationsParserTest, GPUTestExpectationsParserOverrideExpectation
// The FAIL expectation was unused because it was overridden. // The FAIL expectation was unused because it was overridden.
EXPECT_EQ(parser.getUnusedExpectationsMessages().size(), 1u); EXPECT_EQ(parser.getUnusedExpectationsMessages().size(), 1u);
if (parser.getUnusedExpectationsMessages().size() >= 1) if (parser.getUnusedExpectationsMessages().size() >= 1)
{
EXPECT_EQ(parser.getUnusedExpectationsMessages()[0], "Line 2: expectation was unused."); EXPECT_EQ(parser.getUnusedExpectationsMessages()[0], "Line 2: expectation was unused.");
}
// Now try a test that doesn't match the override criteria // Now try a test that doesn't match the override criteria
EXPECT_EQ(parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.image.test"), EXPECT_EQ(parser.getTestExpectation("dEQP-GLES31.functional.layout_binding.image.test"),
GPUTestExpectationsParser::kGpuTestFail); GPUTestExpectationsParser::kGpuTestFail);
......
...@@ -244,7 +244,7 @@ VkResult init_instance(struct sample_info &info, char const *const app_short_nam ...@@ -244,7 +244,7 @@ VkResult init_instance(struct sample_info &info, char const *const app_short_nam
inst_info.ppEnabledExtensionNames = info.instance_extension_names.data(); inst_info.ppEnabledExtensionNames = info.instance_extension_names.data();
VkResult res = vkCreateInstance(&inst_info, NULL, &info.inst); VkResult res = vkCreateInstance(&inst_info, NULL, &info.inst);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
return res; return res;
} }
...@@ -257,19 +257,19 @@ void init_device_extension_names(struct sample_info &info) ...@@ -257,19 +257,19 @@ void init_device_extension_names(struct sample_info &info)
VkResult init_enumerate_device(struct sample_info &info, uint32_t gpu_count) VkResult init_enumerate_device(struct sample_info &info, uint32_t gpu_count)
{ {
VkResult res = vkEnumeratePhysicalDevices(info.inst, &gpu_count, NULL); VkResult res = vkEnumeratePhysicalDevices(info.inst, &gpu_count, NULL);
assert(gpu_count); ASSERT(gpu_count);
info.gpus.resize(gpu_count); info.gpus.resize(gpu_count);
res = vkEnumeratePhysicalDevices(info.inst, &gpu_count, info.gpus.data()); res = vkEnumeratePhysicalDevices(info.inst, &gpu_count, info.gpus.data());
assert(!res); ASSERT(!res);
vkGetPhysicalDeviceQueueFamilyProperties(info.gpus[0], &info.queue_family_count, NULL); vkGetPhysicalDeviceQueueFamilyProperties(info.gpus[0], &info.queue_family_count, NULL);
assert(info.queue_family_count >= 1); ASSERT(info.queue_family_count >= 1);
info.queue_props.resize(info.queue_family_count); info.queue_props.resize(info.queue_family_count);
vkGetPhysicalDeviceQueueFamilyProperties(info.gpus[0], &info.queue_family_count, vkGetPhysicalDeviceQueueFamilyProperties(info.gpus[0], &info.queue_family_count,
info.queue_props.data()); info.queue_props.data());
assert(info.queue_family_count >= 1); ASSERT(info.queue_family_count >= 1);
/* This is as good a place as any to do this */ /* This is as good a place as any to do this */
vkGetPhysicalDeviceMemoryProperties(info.gpus[0], &info.memory_properties); vkGetPhysicalDeviceMemoryProperties(info.gpus[0], &info.memory_properties);
...@@ -393,8 +393,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ...@@ -393,8 +393,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
void init_window(struct sample_info &info) void init_window(struct sample_info &info)
{ {
WNDCLASSEXA win_class; WNDCLASSEXA win_class;
assert(info.width > 0); ASSERT(info.width > 0);
assert(info.height > 0); ASSERT(info.height > 0);
info.connection = GetModuleHandle(NULL); info.connection = GetModuleHandle(NULL);
sprintf(info.name, "Sample"); sprintf(info.name, "Sample");
...@@ -465,8 +465,8 @@ void destroy_window(struct sample_info &info) ...@@ -465,8 +465,8 @@ void destroy_window(struct sample_info &info)
void init_window(struct sample_info &info) void init_window(struct sample_info &info)
{ {
assert(info.width > 0); ASSERT(info.width > 0);
assert(info.height > 0); ASSERT(info.height > 0);
info.window = wl_compositor_create_surface(info.compositor); info.window = wl_compositor_create_surface(info.compositor);
if (!info.window) if (!info.window)
...@@ -502,8 +502,8 @@ void destroy_window(struct sample_info &info) ...@@ -502,8 +502,8 @@ void destroy_window(struct sample_info &info)
void init_window(struct sample_info &info) void init_window(struct sample_info &info)
{ {
assert(info.width > 0); ASSERT(info.width > 0);
assert(info.height > 0); ASSERT(info.height > 0);
uint32_t value_mask, value_list[32]; uint32_t value_mask, value_list[32];
...@@ -558,7 +558,7 @@ void init_window_size(struct sample_info &info, int32_t default_width, int32_t d ...@@ -558,7 +558,7 @@ void init_window_size(struct sample_info &info, int32_t default_width, int32_t d
{ {
#ifdef __ANDROID__ #ifdef __ANDROID__
info.mOSWindow = OSWindow::New(); info.mOSWindow = OSWindow::New();
assert(info.mOSWindow != nullptr); ASSERT(info.mOSWindow != nullptr);
info.mOSWindow->initialize("VulkanTest", default_width, default_height); info.mOSWindow->initialize("VulkanTest", default_width, default_height);
#endif #endif
info.width = default_width; info.width = default_width;
...@@ -602,7 +602,7 @@ void init_swapchain_extension(struct sample_info &info) ...@@ -602,7 +602,7 @@ void init_swapchain_extension(struct sample_info &info)
createInfo.window = info.window; createInfo.window = info.window;
res = vkCreateXcbSurfaceKHR(info.inst, &createInfo, NULL, &info.surface); res = vkCreateXcbSurfaceKHR(info.inst, &createInfo, NULL, &info.surface);
#endif // __ANDROID__ && _WIN32 #endif // __ANDROID__ && _WIN32
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
// Iterate over each queue to learn whether it supports presenting: // Iterate over each queue to learn whether it supports presenting:
VkBool32 *pSupportsPresent = (VkBool32 *)malloc(info.queue_family_count * sizeof(VkBool32)); VkBool32 *pSupportsPresent = (VkBool32 *)malloc(info.queue_family_count * sizeof(VkBool32));
...@@ -656,12 +656,12 @@ void init_swapchain_extension(struct sample_info &info) ...@@ -656,12 +656,12 @@ void init_swapchain_extension(struct sample_info &info)
// Get the list of VkFormats that are supported: // Get the list of VkFormats that are supported:
uint32_t formatCount; uint32_t formatCount;
res = vkGetPhysicalDeviceSurfaceFormatsKHR(info.gpus[0], info.surface, &formatCount, NULL); res = vkGetPhysicalDeviceSurfaceFormatsKHR(info.gpus[0], info.surface, &formatCount, NULL);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
VkSurfaceFormatKHR *surfFormats = VkSurfaceFormatKHR *surfFormats =
(VkSurfaceFormatKHR *)malloc(formatCount * sizeof(VkSurfaceFormatKHR)); (VkSurfaceFormatKHR *)malloc(formatCount * sizeof(VkSurfaceFormatKHR));
res = res =
vkGetPhysicalDeviceSurfaceFormatsKHR(info.gpus[0], info.surface, &formatCount, surfFormats); vkGetPhysicalDeviceSurfaceFormatsKHR(info.gpus[0], info.surface, &formatCount, surfFormats);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
// If the format list includes just one entry of VK_FORMAT_UNDEFINED, // If the format list includes just one entry of VK_FORMAT_UNDEFINED,
// the surface has no preferred format. Otherwise, at least one // the surface has no preferred format. Otherwise, at least one
// supported format will be returned. // supported format will be returned.
...@@ -671,7 +671,7 @@ void init_swapchain_extension(struct sample_info &info) ...@@ -671,7 +671,7 @@ void init_swapchain_extension(struct sample_info &info)
} }
else else
{ {
assert(formatCount >= 1); ASSERT(formatCount >= 1);
info.format = surfFormats[0].format; info.format = surfFormats[0].format;
} }
free(surfFormats); free(surfFormats);
...@@ -700,7 +700,7 @@ VkResult init_device(struct sample_info &info) ...@@ -700,7 +700,7 @@ VkResult init_device(struct sample_info &info)
device_info.pEnabledFeatures = NULL; device_info.pEnabledFeatures = NULL;
res = vkCreateDevice(info.gpus[0], &device_info, NULL, &info.device); res = vkCreateDevice(info.gpus[0], &device_info, NULL, &info.device);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
return res; return res;
} }
...@@ -717,7 +717,7 @@ void init_command_pool(struct sample_info &info, VkCommandPoolCreateFlags cmd_po ...@@ -717,7 +717,7 @@ void init_command_pool(struct sample_info &info, VkCommandPoolCreateFlags cmd_po
cmd_pool_info.flags = cmd_pool_create_flags; cmd_pool_info.flags = cmd_pool_create_flags;
res = vkCreateCommandPool(info.device, &cmd_pool_info, NULL, &info.cmd_pool); res = vkCreateCommandPool(info.device, &cmd_pool_info, NULL, &info.cmd_pool);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
void init_command_buffer(struct sample_info &info) void init_command_buffer(struct sample_info &info)
...@@ -733,7 +733,7 @@ void init_command_buffer(struct sample_info &info) ...@@ -733,7 +733,7 @@ void init_command_buffer(struct sample_info &info)
cmd.commandBufferCount = 1; cmd.commandBufferCount = 1;
res = vkAllocateCommandBuffers(info.device, &cmd, &info.cmd); res = vkAllocateCommandBuffers(info.device, &cmd, &info.cmd);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
void init_command_buffer_array(struct sample_info &info, int numBuffers) void init_command_buffer_array(struct sample_info &info, int numBuffers)
...@@ -741,7 +741,7 @@ void init_command_buffer_array(struct sample_info &info, int numBuffers) ...@@ -741,7 +741,7 @@ void init_command_buffer_array(struct sample_info &info, int numBuffers)
/* DEPENDS on init_swapchain_extension() and init_command_pool() */ /* DEPENDS on init_swapchain_extension() and init_command_pool() */
VkResult res; VkResult res;
info.cmds.resize(numBuffers); info.cmds.resize(numBuffers);
assert(info.cmds.data() != NULL); ASSERT(info.cmds.data() != NULL);
VkCommandBufferAllocateInfo cmd = {}; VkCommandBufferAllocateInfo cmd = {};
cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
...@@ -751,7 +751,7 @@ void init_command_buffer_array(struct sample_info &info, int numBuffers) ...@@ -751,7 +751,7 @@ void init_command_buffer_array(struct sample_info &info, int numBuffers)
cmd.commandBufferCount = numBuffers; cmd.commandBufferCount = numBuffers;
res = vkAllocateCommandBuffers(info.device, &cmd, info.cmds.data()); res = vkAllocateCommandBuffers(info.device, &cmd, info.cmds.data());
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
void init_command_buffer2_array(struct sample_info &info, int numBuffers) void init_command_buffer2_array(struct sample_info &info, int numBuffers)
...@@ -767,7 +767,7 @@ void init_command_buffer2_array(struct sample_info &info, int numBuffers) ...@@ -767,7 +767,7 @@ void init_command_buffer2_array(struct sample_info &info, int numBuffers)
cmd.commandBufferCount = numBuffers; cmd.commandBufferCount = numBuffers;
res = vkAllocateCommandBuffers(info.device, &cmd, info.cmd2s.data()); res = vkAllocateCommandBuffers(info.device, &cmd, info.cmd2s.data());
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
void init_device_queue(struct sample_info &info) void init_device_queue(struct sample_info &info)
...@@ -793,18 +793,18 @@ void init_swap_chain(struct sample_info &info, VkImageUsageFlags usageFlags) ...@@ -793,18 +793,18 @@ void init_swap_chain(struct sample_info &info, VkImageUsageFlags usageFlags)
VkSurfaceCapabilitiesKHR surfCapabilities; VkSurfaceCapabilitiesKHR surfCapabilities;
res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(info.gpus[0], info.surface, &surfCapabilities); res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(info.gpus[0], info.surface, &surfCapabilities);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
uint32_t presentModeCount; uint32_t presentModeCount;
res = vkGetPhysicalDeviceSurfacePresentModesKHR(info.gpus[0], info.surface, &presentModeCount, res = vkGetPhysicalDeviceSurfacePresentModesKHR(info.gpus[0], info.surface, &presentModeCount,
NULL); NULL);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
VkPresentModeKHR *presentModes = VkPresentModeKHR *presentModes =
(VkPresentModeKHR *)malloc(presentModeCount * sizeof(VkPresentModeKHR)); (VkPresentModeKHR *)malloc(presentModeCount * sizeof(VkPresentModeKHR));
assert(presentModes); ASSERT(presentModes);
res = vkGetPhysicalDeviceSurfacePresentModesKHR(info.gpus[0], info.surface, &presentModeCount, res = vkGetPhysicalDeviceSurfacePresentModesKHR(info.gpus[0], info.surface, &presentModeCount,
presentModes); presentModes);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
VkExtent2D swapchainExtent; VkExtent2D swapchainExtent;
// width and height are either both 0xFFFFFFFF, or both not 0xFFFFFFFF. // width and height are either both 0xFFFFFFFF, or both not 0xFFFFFFFF.
...@@ -922,16 +922,16 @@ void init_swap_chain(struct sample_info &info, VkImageUsageFlags usageFlags) ...@@ -922,16 +922,16 @@ void init_swap_chain(struct sample_info &info, VkImageUsageFlags usageFlags)
} }
res = vkCreateSwapchainKHR(info.device, &swapchain_ci, NULL, &info.swap_chain); res = vkCreateSwapchainKHR(info.device, &swapchain_ci, NULL, &info.swap_chain);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
res = vkGetSwapchainImagesKHR(info.device, info.swap_chain, &info.swapchainImageCount, NULL); res = vkGetSwapchainImagesKHR(info.device, info.swap_chain, &info.swapchainImageCount, NULL);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
VkImage *swapchainImages = (VkImage *)malloc(info.swapchainImageCount * sizeof(VkImage)); VkImage *swapchainImages = (VkImage *)malloc(info.swapchainImageCount * sizeof(VkImage));
assert(swapchainImages); ASSERT(swapchainImages);
res = vkGetSwapchainImagesKHR(info.device, info.swap_chain, &info.swapchainImageCount, res = vkGetSwapchainImagesKHR(info.device, info.swap_chain, &info.swapchainImageCount,
swapchainImages); swapchainImages);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
for (uint32_t i = 0; i < info.swapchainImageCount; i++) for (uint32_t i = 0; i < info.swapchainImageCount; i++)
{ {
...@@ -959,7 +959,7 @@ void init_swap_chain(struct sample_info &info, VkImageUsageFlags usageFlags) ...@@ -959,7 +959,7 @@ void init_swap_chain(struct sample_info &info, VkImageUsageFlags usageFlags)
res = vkCreateImageView(info.device, &color_image_view, NULL, &sc_buffer.view); res = vkCreateImageView(info.device, &color_image_view, NULL, &sc_buffer.view);
info.buffers.push_back(sc_buffer); info.buffers.push_back(sc_buffer);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
free(swapchainImages); free(swapchainImages);
info.current_buffer = 0; info.current_buffer = 0;
...@@ -1077,7 +1077,7 @@ void init_depth_buffer(struct sample_info &info) ...@@ -1077,7 +1077,7 @@ void init_depth_buffer(struct sample_info &info)
/* Create image */ /* Create image */
res = vkCreateImage(info.device, &image_info, NULL, &info.depth.image); res = vkCreateImage(info.device, &image_info, NULL, &info.depth.image);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
vkGetImageMemoryRequirements(info.device, info.depth.image, &mem_reqs); vkGetImageMemoryRequirements(info.device, info.depth.image, &mem_reqs);
...@@ -1086,20 +1086,20 @@ void init_depth_buffer(struct sample_info &info) ...@@ -1086,20 +1086,20 @@ void init_depth_buffer(struct sample_info &info)
pass = memory_type_from_properties(info, mem_reqs.memoryTypeBits, pass = memory_type_from_properties(info, mem_reqs.memoryTypeBits,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
&mem_alloc.memoryTypeIndex); &mem_alloc.memoryTypeIndex);
assert(pass); ASSERT(pass);
/* Allocate memory */ /* Allocate memory */
res = vkAllocateMemory(info.device, &mem_alloc, NULL, &info.depth.mem); res = vkAllocateMemory(info.device, &mem_alloc, NULL, &info.depth.mem);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
/* Bind memory */ /* Bind memory */
res = vkBindImageMemory(info.device, info.depth.image, info.depth.mem, 0); res = vkBindImageMemory(info.device, info.depth.image, info.depth.mem, 0);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
/* Create image view */ /* Create image view */
view_info.image = info.depth.image; view_info.image = info.depth.image;
res = vkCreateImageView(info.device, &view_info, NULL, &info.depth.view); res = vkCreateImageView(info.device, &view_info, NULL, &info.depth.view);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
void init_uniform_buffer(struct sample_info &info) void init_uniform_buffer(struct sample_info &info)
...@@ -1121,7 +1121,7 @@ void init_uniform_buffer(struct sample_info &info) ...@@ -1121,7 +1121,7 @@ void init_uniform_buffer(struct sample_info &info)
buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
buf_info.flags = 0; buf_info.flags = 0;
res = vkCreateBuffer(info.device, &buf_info, NULL, &info.uniform_data.buf); res = vkCreateBuffer(info.device, &buf_info, NULL, &info.uniform_data.buf);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
VkMemoryRequirements mem_reqs; VkMemoryRequirements mem_reqs;
vkGetBufferMemoryRequirements(info.device, info.uniform_data.buf, &mem_reqs); vkGetBufferMemoryRequirements(info.device, info.uniform_data.buf, &mem_reqs);
...@@ -1136,21 +1136,21 @@ void init_uniform_buffer(struct sample_info &info) ...@@ -1136,21 +1136,21 @@ void init_uniform_buffer(struct sample_info &info)
info, mem_reqs.memoryTypeBits, info, mem_reqs.memoryTypeBits,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
&alloc_info.memoryTypeIndex); &alloc_info.memoryTypeIndex);
assert(pass && "No mappable, coherent memory"); ASSERT(pass && "No mappable, coherent memory");
res = vkAllocateMemory(info.device, &alloc_info, NULL, &(info.uniform_data.mem)); res = vkAllocateMemory(info.device, &alloc_info, NULL, &(info.uniform_data.mem));
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
uint8_t *pData; uint8_t *pData;
res = vkMapMemory(info.device, info.uniform_data.mem, 0, mem_reqs.size, 0, (void **)&pData); res = vkMapMemory(info.device, info.uniform_data.mem, 0, mem_reqs.size, 0, (void **)&pData);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
memcpy(pData, info.MVP.data(), sizeof(float) * 16); // info.MVP.data() size memcpy(pData, info.MVP.data(), sizeof(float) * 16); // info.MVP.data() size
vkUnmapMemory(info.device, info.uniform_data.mem); vkUnmapMemory(info.device, info.uniform_data.mem);
res = vkBindBufferMemory(info.device, info.uniform_data.buf, info.uniform_data.mem, 0); res = vkBindBufferMemory(info.device, info.uniform_data.buf, info.uniform_data.mem, 0);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
info.uniform_data.buffer_info.buffer = info.uniform_data.buf; info.uniform_data.buffer_info.buffer = info.uniform_data.buf;
info.uniform_data.buffer_info.offset = 0; info.uniform_data.buffer_info.offset = 0;
...@@ -1191,7 +1191,7 @@ void init_descriptor_and_pipeline_layouts(struct sample_info &info, ...@@ -1191,7 +1191,7 @@ void init_descriptor_and_pipeline_layouts(struct sample_info &info,
info.desc_layout.resize(NUM_DESCRIPTOR_SETS); info.desc_layout.resize(NUM_DESCRIPTOR_SETS);
res = res =
vkCreateDescriptorSetLayout(info.device, &descriptor_layout, NULL, info.desc_layout.data()); vkCreateDescriptorSetLayout(info.device, &descriptor_layout, NULL, info.desc_layout.data());
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
/* Now use the descriptor layout to create a pipeline layout */ /* Now use the descriptor layout to create a pipeline layout */
VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo = {}; VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo = {};
...@@ -1204,7 +1204,7 @@ void init_descriptor_and_pipeline_layouts(struct sample_info &info, ...@@ -1204,7 +1204,7 @@ void init_descriptor_and_pipeline_layouts(struct sample_info &info,
res = vkCreatePipelineLayout(info.device, &pPipelineLayoutCreateInfo, NULL, res = vkCreatePipelineLayout(info.device, &pPipelineLayoutCreateInfo, NULL,
&info.pipeline_layout); &info.pipeline_layout);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
void init_renderpass(struct sample_info &info, void init_renderpass(struct sample_info &info,
...@@ -1271,7 +1271,7 @@ void init_renderpass(struct sample_info &info, ...@@ -1271,7 +1271,7 @@ void init_renderpass(struct sample_info &info,
rp_info.pDependencies = NULL; rp_info.pDependencies = NULL;
res = vkCreateRenderPass(info.device, &rp_info, NULL, &info.render_pass); res = vkCreateRenderPass(info.device, &rp_info, NULL, &info.render_pass);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
void init_framebuffers(struct sample_info &info, bool include_depth) void init_framebuffers(struct sample_info &info, bool include_depth)
...@@ -1301,7 +1301,7 @@ void init_framebuffers(struct sample_info &info, bool include_depth) ...@@ -1301,7 +1301,7 @@ void init_framebuffers(struct sample_info &info, bool include_depth)
{ {
attachments[0] = info.buffers[i].view; attachments[0] = info.buffers[i].view;
res = vkCreateFramebuffer(info.device, &fb_info, NULL, &info.framebuffers[i]); res = vkCreateFramebuffer(info.device, &fb_info, NULL, &info.framebuffers[i]);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
} }
...@@ -1324,7 +1324,7 @@ void init_vertex_buffer(struct sample_info &info, ...@@ -1324,7 +1324,7 @@ void init_vertex_buffer(struct sample_info &info,
buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
buf_info.flags = 0; buf_info.flags = 0;
res = vkCreateBuffer(info.device, &buf_info, NULL, &info.vertex_buffer.buf); res = vkCreateBuffer(info.device, &buf_info, NULL, &info.vertex_buffer.buf);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
VkMemoryRequirements mem_reqs; VkMemoryRequirements mem_reqs;
vkGetBufferMemoryRequirements(info.device, info.vertex_buffer.buf, &mem_reqs); vkGetBufferMemoryRequirements(info.device, info.vertex_buffer.buf, &mem_reqs);
...@@ -1339,23 +1339,23 @@ void init_vertex_buffer(struct sample_info &info, ...@@ -1339,23 +1339,23 @@ void init_vertex_buffer(struct sample_info &info,
info, mem_reqs.memoryTypeBits, info, mem_reqs.memoryTypeBits,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
&alloc_info.memoryTypeIndex); &alloc_info.memoryTypeIndex);
assert(pass && "No mappable, coherent memory"); ASSERT(pass && "No mappable, coherent memory");
res = vkAllocateMemory(info.device, &alloc_info, NULL, &(info.vertex_buffer.mem)); res = vkAllocateMemory(info.device, &alloc_info, NULL, &(info.vertex_buffer.mem));
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
info.vertex_buffer.buffer_info.range = mem_reqs.size; info.vertex_buffer.buffer_info.range = mem_reqs.size;
info.vertex_buffer.buffer_info.offset = 0; info.vertex_buffer.buffer_info.offset = 0;
uint8_t *pData; uint8_t *pData;
res = vkMapMemory(info.device, info.vertex_buffer.mem, 0, mem_reqs.size, 0, (void **)&pData); res = vkMapMemory(info.device, info.vertex_buffer.mem, 0, mem_reqs.size, 0, (void **)&pData);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
memcpy(pData, vertexData, dataSize); memcpy(pData, vertexData, dataSize);
vkUnmapMemory(info.device, info.vertex_buffer.mem); vkUnmapMemory(info.device, info.vertex_buffer.mem);
res = vkBindBufferMemory(info.device, info.vertex_buffer.buf, info.vertex_buffer.mem, 0); res = vkBindBufferMemory(info.device, info.vertex_buffer.buf, info.vertex_buffer.mem, 0);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
info.vi_binding.binding = 0; info.vi_binding.binding = 0;
info.vi_binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; info.vi_binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
...@@ -1395,7 +1395,7 @@ void init_descriptor_pool(struct sample_info &info, bool use_texture) ...@@ -1395,7 +1395,7 @@ void init_descriptor_pool(struct sample_info &info, bool use_texture)
descriptor_pool.pPoolSizes = type_count; descriptor_pool.pPoolSizes = type_count;
res = vkCreateDescriptorPool(info.device, &descriptor_pool, NULL, &info.desc_pool); res = vkCreateDescriptorPool(info.device, &descriptor_pool, NULL, &info.desc_pool);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
void init_descriptor_set(struct sample_info &info) void init_descriptor_set(struct sample_info &info)
...@@ -1413,7 +1413,7 @@ void init_descriptor_set(struct sample_info &info) ...@@ -1413,7 +1413,7 @@ void init_descriptor_set(struct sample_info &info)
info.desc_set.resize(NUM_DESCRIPTOR_SETS); info.desc_set.resize(NUM_DESCRIPTOR_SETS);
res = vkAllocateDescriptorSets(info.device, alloc_info, info.desc_set.data()); res = vkAllocateDescriptorSets(info.device, alloc_info, info.desc_set.data());
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
VkWriteDescriptorSet writes[2]; VkWriteDescriptorSet writes[2];
...@@ -1495,7 +1495,7 @@ void init_shaders(struct sample_info &info, const char *vertShaderText, const ch ...@@ -1495,7 +1495,7 @@ void init_shaders(struct sample_info &info, const char *vertShaderText, const ch
info.shaderStages[0].pName = "main"; info.shaderStages[0].pName = "main";
retVal = GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vertShaderText, vtx_spv); retVal = GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vertShaderText, vtx_spv);
assert(retVal); ASSERT(retVal);
moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
moduleCreateInfo.pNext = NULL; moduleCreateInfo.pNext = NULL;
...@@ -1504,7 +1504,7 @@ void init_shaders(struct sample_info &info, const char *vertShaderText, const ch ...@@ -1504,7 +1504,7 @@ void init_shaders(struct sample_info &info, const char *vertShaderText, const ch
moduleCreateInfo.pCode = vtx_spv.data(); moduleCreateInfo.pCode = vtx_spv.data();
res = vkCreateShaderModule(info.device, &moduleCreateInfo, NULL, res = vkCreateShaderModule(info.device, &moduleCreateInfo, NULL,
&info.shaderStages[0].module); &info.shaderStages[0].module);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
if (fragShaderText) if (fragShaderText)
...@@ -1518,7 +1518,7 @@ void init_shaders(struct sample_info &info, const char *vertShaderText, const ch ...@@ -1518,7 +1518,7 @@ void init_shaders(struct sample_info &info, const char *vertShaderText, const ch
info.shaderStages[1].pName = "main"; info.shaderStages[1].pName = "main";
retVal = GLSLtoSPV(VK_SHADER_STAGE_FRAGMENT_BIT, fragShaderText, frag_spv); retVal = GLSLtoSPV(VK_SHADER_STAGE_FRAGMENT_BIT, fragShaderText, frag_spv);
assert(retVal); ASSERT(retVal);
moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
moduleCreateInfo.pNext = NULL; moduleCreateInfo.pNext = NULL;
...@@ -1527,7 +1527,7 @@ void init_shaders(struct sample_info &info, const char *vertShaderText, const ch ...@@ -1527,7 +1527,7 @@ void init_shaders(struct sample_info &info, const char *vertShaderText, const ch
moduleCreateInfo.pCode = frag_spv.data(); moduleCreateInfo.pCode = frag_spv.data();
res = vkCreateShaderModule(info.device, &moduleCreateInfo, NULL, res = vkCreateShaderModule(info.device, &moduleCreateInfo, NULL,
&info.shaderStages[1].module); &info.shaderStages[1].module);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
glslang::FinalizeProcess(); glslang::FinalizeProcess();
...@@ -1544,7 +1544,7 @@ void init_pipeline_cache(struct sample_info &info) ...@@ -1544,7 +1544,7 @@ void init_pipeline_cache(struct sample_info &info)
pipelineCache.pInitialData = NULL; pipelineCache.pInitialData = NULL;
pipelineCache.flags = 0; pipelineCache.flags = 0;
res = vkCreatePipelineCache(info.device, &pipelineCache, NULL, &info.pipelineCache); res = vkCreatePipelineCache(info.device, &pipelineCache, NULL, &info.pipelineCache);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
void init_pipeline(struct sample_info &info, VkBool32 include_depth, VkBool32 include_vi) void init_pipeline(struct sample_info &info, VkBool32 include_depth, VkBool32 include_vi)
...@@ -1701,7 +1701,7 @@ void init_pipeline(struct sample_info &info, VkBool32 include_depth, VkBool32 in ...@@ -1701,7 +1701,7 @@ void init_pipeline(struct sample_info &info, VkBool32 include_depth, VkBool32 in
res = vkCreateGraphicsPipelines(info.device, info.pipelineCache, 1, &pipeline, NULL, res = vkCreateGraphicsPipelines(info.device, info.pipelineCache, 1, &pipeline, NULL,
&info.pipeline); &info.pipeline);
assert(res == VK_SUCCESS); ASSERT(res == VK_SUCCESS);
} }
void init_viewports(struct sample_info &info) void init_viewports(struct sample_info &info)
......
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