From f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 29 Oct 2024 14:49:26 +0800 Subject: format * format * Minor test fixes * enable checking cpp format in ci --- examples/hello-world/main.cpp | 46 ++++++++++++++++++++++++++----------- examples/hello-world/vulkan-api.cpp | 30 ++++++++++++++---------- examples/hello-world/vulkan-api.h | 12 +++++----- 3 files changed, 56 insertions(+), 32 deletions(-) (limited to 'examples/hello-world') diff --git a/examples/hello-world/main.cpp b/examples/hello-world/main.cpp index 87d440901..e9585bde9 100644 --- a/examples/hello-world/main.cpp +++ b/examples/hello-world/main.cpp @@ -7,13 +7,12 @@ // The goal is to demonstrate how to use the Slang API to cross compile // shader code. // -#include "slang.h" -#include "slang-com-ptr.h" - -#include "vulkan-api.h" #include "examples/example-base/example-base.h" #include "examples/example-base/test-base.h" +#include "slang-com-ptr.h" +#include "slang.h" #include "source/core/slang-string-util.h" +#include "vulkan-api.h" using Slang::ComPtr; @@ -65,7 +64,6 @@ struct HelloWorldExample : public TestBase int run(); ~HelloWorldExample(); - }; int main(int argc, char* argv[]) @@ -102,8 +100,7 @@ int HelloWorldExample::initVulkanInstanceAndDevice() poolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; poolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; poolCreateInfo.queueFamilyIndex = vkAPI.queueFamilyIndex; - RETURN_ON_FAIL(vkAPI.vkCreateCommandPool( - vkAPI.device, &poolCreateInfo, nullptr, &commandPool)); + RETURN_ON_FAIL(vkAPI.vkCreateCommandPool(vkAPI.device, &poolCreateInfo, nullptr, &commandPool)); vkAPI.vkGetDeviceQueue(vkAPI.device, vkAPI.queueFamilyIndex, 0, &queue); return 0; @@ -204,7 +201,10 @@ int HelloWorldExample::createComputePipelineFromShader() { ComPtr diagnosticsBlob; SlangResult result = composedProgram->getEntryPointCode( - 0, 0, spirvCode.writeRef(), diagnosticsBlob.writeRef()); + 0, + 0, + spirvCode.writeRef(), + diagnosticsBlob.writeRef()); diagnoseIfNeeded(diagnosticsBlob); RETURN_ON_FAIL(result); @@ -238,13 +238,19 @@ int HelloWorldExample::createComputePipelineFromShader() } descSetLayoutCreateInfo.pBindings = bindings; RETURN_ON_FAIL(vkAPI.vkCreateDescriptorSetLayout( - vkAPI.device, &descSetLayoutCreateInfo, nullptr, &descriptorSetLayout)); + vkAPI.device, + &descSetLayoutCreateInfo, + nullptr, + &descriptorSetLayout)); VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; pipelineLayoutCreateInfo.setLayoutCount = 1; pipelineLayoutCreateInfo.pSetLayouts = &descriptorSetLayout; RETURN_ON_FAIL(vkAPI.vkCreatePipelineLayout( - vkAPI.device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayout)); + vkAPI.device, + &pipelineLayoutCreateInfo, + nullptr, + &pipelineLayout)); // Next we create a shader module from the compiled SPIRV code. VkShaderModuleCreateInfo shaderCreateInfo = {VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; @@ -263,7 +269,12 @@ int HelloWorldExample::createComputePipelineFromShader() pipelineCreateInfo.stage.pName = "main"; pipelineCreateInfo.layout = pipelineLayout; RETURN_ON_FAIL(vkAPI.vkCreateComputePipelines( - vkAPI.device, VK_NULL_HANDLE, 1, &pipelineCreateInfo, nullptr, &pipeline)); + vkAPI.device, + VK_NULL_HANDLE, + 1, + &pipelineCreateInfo, + nullptr, + &pipeline)); // We can destroy shader module now since it will no longer be used. vkAPI.vkDestroyShaderModule(vkAPI.device, vkShaderModule, nullptr); @@ -287,7 +298,8 @@ int HelloWorldExample::createInOutBuffers() vkAPI.vkGetBufferMemoryRequirements(vkAPI.device, inOutBuffers[i], &memoryReqs); int memoryTypeIndex = vkAPI.findMemoryTypeIndex( - memoryReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + memoryReqs.memoryTypeBits, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); assert(memoryTypeIndex >= 0); VkMemoryPropertyFlags actualMemoryProperites = @@ -347,7 +359,10 @@ int HelloWorldExample::createInOutBuffers() commandBufferAllocInfo.commandBufferCount = 1; commandBufferAllocInfo.commandPool = commandPool; commandBufferAllocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - RETURN_ON_FAIL(vkAPI.vkAllocateCommandBuffers(vkAPI.device, &commandBufferAllocInfo, &uploadCommandBuffer)); + RETURN_ON_FAIL(vkAPI.vkAllocateCommandBuffers( + vkAPI.device, + &commandBufferAllocInfo, + &uploadCommandBuffer)); VkCommandBufferBeginInfo beginInfo = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; vkAPI.vkBeginCommandBuffer(uploadCommandBuffer, &beginInfo); @@ -378,7 +393,10 @@ int HelloWorldExample::dispatchCompute() descriptorPoolCreateInfo.flags = 0; VkDescriptorPool descriptorPool = VK_NULL_HANDLE; RETURN_ON_FAIL(vkAPI.vkCreateDescriptorPool( - vkAPI.device, &descriptorPoolCreateInfo, nullptr, &descriptorPool)); + vkAPI.device, + &descriptorPoolCreateInfo, + nullptr, + &descriptorPool)); // Allocate descriptor set. VkDescriptorSetAllocateInfo descSetAllocInfo = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO}; diff --git a/examples/hello-world/vulkan-api.cpp b/examples/hello-world/vulkan-api.cpp index 3581563d4..95c4a512e 100644 --- a/examples/hello-world/vulkan-api.cpp +++ b/examples/hello-world/vulkan-api.cpp @@ -1,16 +1,17 @@ #include "vulkan-api.h" + #include "slang.h" -#include -#include #include +#include +#include #include #include #if SLANG_WINDOWS_FAMILY -# include +#include #else -# include +#include #endif #if _DEBUG @@ -25,7 +26,8 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageCallback( int32_t /*msgCode*/, const char* pLayerPrefix, const char* pMsg, - void* /*pUserData*/) + void* /*pUserData*/ +) { printf("[%s]: %s\n", pLayerPrefix, pMsg); return 1; @@ -62,7 +64,7 @@ int initializeVulkanDevice(VulkanAPI& api) uint32_t propertyCount; if (api.vkEnumerateInstanceLayerProperties(&propertyCount, nullptr) != 0) return -1; - std::vector< VkLayerProperties> properties(propertyCount); + std::vector properties(propertyCount); if (api.vkEnumerateInstanceLayerProperties(&propertyCount, properties.data()) != 0) return -1; for (const auto& p : properties) @@ -119,17 +121,19 @@ int initializeVulkanDevice(VulkanAPI& api) debugCreateInfo.flags = debugFlags; RETURN_ON_FAIL(api.vkCreateDebugReportCallbackEXT( - api.instance, &debugCreateInfo, nullptr, &api.debugReportCallback)); + api.instance, + &debugCreateInfo, + nullptr, + &api.debugReportCallback)); } // Enumerate physical devices. uint32_t numPhysicalDevices = 0; - RETURN_ON_FAIL( - api.vkEnumeratePhysicalDevices(api.instance, &numPhysicalDevices, nullptr)); + RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices(api.instance, &numPhysicalDevices, nullptr)); std::vector physicalDevices; physicalDevices.resize(numPhysicalDevices); - RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices( - api.instance, &numPhysicalDevices, &physicalDevices[0])); + RETURN_ON_FAIL( + api.vkEnumeratePhysicalDevices(api.instance, &numPhysicalDevices, &physicalDevices[0])); // We will use device 0. api.initPhysicalDevice(physicalDevices[0]); @@ -145,7 +149,9 @@ int initializeVulkanDevice(VulkanAPI& api) std::vector queueFamilies; queueFamilies.resize(numQueueFamilies); api.vkGetPhysicalDeviceQueueFamilyProperties( - api.physicalDevice, &numQueueFamilies, &queueFamilies[0]); + api.physicalDevice, + &numQueueFamilies, + &queueFamilies[0]); // Find a queue that can service our needs. auto requiredQueueFlags = VK_QUEUE_COMPUTE_BIT; diff --git a/examples/hello-world/vulkan-api.h b/examples/hello-world/vulkan-api.h index 89ca9747d..ab0822569 100644 --- a/examples/hello-world/vulkan-api.h +++ b/examples/hello-world/vulkan-api.h @@ -121,12 +121,12 @@ struct VulkanAPI }; #define RETURN_ON_FAIL(x) \ - { \ - auto _res = x; \ - if (_res != 0) \ - { \ - return -1; \ - } \ + { \ + auto _res = x; \ + if (_res != 0) \ + { \ + return -1; \ + } \ } // Loads Vulkan library and creates a VkDevice. -- cgit v1.2.3