Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests in CI #5

Merged
merged 25 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 60 additions & 8 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
run: |
git-clang-format --binary clang-format-15 --diff origin/main --extensions cpp,hpp > output.txt
cat output.txt
grep "no modified files to format" output.txt
grep -E "(no modified files to format|clang-format did not modify any files)" output.txt
build:
name: Build
name: Builds & Tests
needs: format
runs-on: ubuntu-22.04
steps:
Expand All @@ -33,22 +33,22 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install ninja-build libvulkan-dev clang-15
sudo apt-get install ninja-build libvulkan-dev clang-15 mesa-vulkan-drivers libxrandr-dev
- name: Build SPIRV-Tools
run: |
git clone --depth 1 --branch vksp https://github.com/rjodinchr/SPIRV-Tools.git third_party/spirv-tools
git clone --depth 1 --branch vksp https://github.com/rjodinchr/SPIRV-Headers.git third_party/spirv-tools/external/spirv-headers
mkdir install
cmake -B third_party/spirv-tools/build -S third_party/spirv-tools/ -G Ninja \
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_CXX_COMPILER="$(which clang++)"
cmake --build third_party/spirv-tools/build --target install
-DCMAKE_CXX_COMPILER="$(which clang++)" \
-DCMAKE_BUILD_TYPE=Release
cmake --build third_party/spirv-tools/build
cmake --install third_party/spirv-tools/build --prefix $(pwd)/install/
- name: Build Perfetto
run: |
git clone --depth 1 --branch v39.0 https://android.googlesource.com/platform/external/perfetto third_party/perfetto
$(pwd)/third_party/perfetto/tools/install-build-deps
$(pwd)/third_party/perfetto/tools/setup_all_configs.py
$(pwd)/third_party/perfetto/tools/ninja -C $(pwd)/third_party/perfetto/out/linux_clang_release libtrace_processor.a
$(pwd)/third_party/perfetto/tools/ninja -C $(pwd)/third_party/perfetto/out/linux_clang_release libtrace_processor.a perfetto traced
- name: Build debug
run: |
cmake -B build_debug -S . -G Ninja \
Expand Down Expand Up @@ -77,3 +77,55 @@ jobs:
-DCMAKE_CXX_COMPILER="$(which clang++)" \
-DCMAKE_BUILD_TYPE=Release
cmake --build build_release
- name: Build Vulkan-Headers
run: |
git clone --depth 1 --branch v1.3.240 https://github.com/KhronosGroup/Vulkan-Headers.git third_party/vulkan-headers
cmake -B third_party/vulkan-headers/build -S third_party/vulkan-headers -G Ninja \
-DCMAKE_CXX_COMPILER="$(which clang++)" \
-DCMAKE_C_COMPILER="$(which clang)" \
-DCMAKE_BUILD_TYPE=Release
cmake --build third_party/vulkan-headers/build
cmake --install third_party/vulkan-headers/build --prefix $(pwd)/install/
- name: Build Vulkan-Loader
run : |
git clone --depth 1 --branch v1.3.240 https://github.com/KhronosGroup/Vulkan-Loader.git third_party/vulkan-loader
cmake -B third_party/vulkan-loader/build -S third_party/vulkan-loader -G Ninja \
-DVulkanHeaders_DIR=$(pwd)/install/share/cmake/VulkanHeaders \
-DCMAKE_CXX_COMPILER="$(which clang++)" \
-DCMAKE_C_COMPILER="$(which clang)" \
-DCMAKE_BUILD_TYPE=Release
cmake --build third_party/vulkan-loader/build
- name: Build system
run: |
cmake -B build_system -S . -G Ninja \
-DPERFETTO_SDK_PATH="$(pwd)/third_party/perfetto/sdk" \
-DPERFETTO_INTERNAL_INCLUDE_PATH="$(pwd)/third_party/perfetto/include" \
-DPERFETTO_GEN_INCLUDE_PATH="$(pwd)/third_party/perfetto/out/linux_clang_release/gen/build_config" \
-DPERFETTO_TRACE_PROCESSOR_LIB="$(pwd)/third_party/perfetto/out/linux_clang_release/libtrace_processor.a" \
-DPERFETTO_CXX_CONFIG_INCLUDE_PATH="$(pwd)/third_party/perfetto/buildtools/libcxx_config" \
-DPERFETTO_CXX_SYSTEM_INCLUDE_PATH="$(pwd)/third_party/perfetto/buildtools/libcxx/include" \
-DEXTRACTOR_NOSTDINCXX=1 \
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH};$(pwd)/install/lib/cmake/SPIRV-Tools-opt;$(pwd)/install/lib/cmake/SPIRV-Tools" \
-DCMAKE_CXX_COMPILER="$(which clang++)" \
-DBACKEND=System \
-DCMAKE_BUILD_TYPE=Release
cmake --build build_system
- name: Tests
run: |
$(pwd)/build_system/runner/vulkan-shader-profiler-runner -i $(pwd)/tests/example.spvasm -v
$(pwd)/build_system/runner/vulkan-shader-profiler-runner -i $(pwd)/tests/example-counter.spvasm | grep "my_section"
$(pwd)/third_party/perfetto/out/linux_clang_release/traced &
$(pwd)/third_party/perfetto/out/linux_clang_release/perfetto -c $(pwd)/tests/perfetto_config --txt -o $(pwd)/trace &
sleep 1
VK_LOADER_DEBUG=all \
LD_LIBRARY_PATH=$(pwd)/build_system/layer/:$(pwd)/third_party/vulkan-loader/build/loader/:$LD_LIBRARY_PATH \
VK_LOADER_LAYERS_ENABLE="VK_LAYER_SHADER_PROFILER" \
VK_ADD_LAYER_PATH=$(pwd)/manifest/ \
VKSP_TRACE_DEST=$(pwd)/trace \
$(pwd)/build_system/runner/vulkan-shader-profiler-runner -i $(pwd)/tests/example.spvasm
sleep 1
pkill -x perfetto
while [[ -n $(pgrep -x perfetto) ]]; do sleep 0.2; done
$(pwd)/build_system/extractor/vulkan-shader-profiler-extractor -i $(pwd)/trace -o $(pwd)/trace.spvasm -d 0 -v
cat $(pwd)/tests/example-expectation.spvasm
diff $(pwd)/trace.spvasm $(pwd)/tests/example-expectation.spvasm
79 changes: 63 additions & 16 deletions runner/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ static spv_target_env gSpvTargetEnv = SPV_ENV_VULKAN_1_3;

static const uint32_t gNbGpuTimestamps = 3;

static VkInstance gInstance;
static VkCommandPool gCmdPool;
static std::vector<VkBuffer> gBuffers;
static std::vector<VkDeviceMemory> gMemories;
static std::vector<VkImage> gImages;
static std::vector<VkImageView> gImageViews;
static std::vector<VkSampler> gSamplers;
static VkDescriptorPool gDescPool;
static VkShaderModule gShaderModule;

static int get_device_queue_and_cmd_buffer(VkPhysicalDevice &pDevice, VkDevice &device, VkQueue &queue,
VkCommandBuffer &cmdBuffer, VkPhysicalDeviceMemoryProperties &memProperties, const char *enabledExtensionNames)
{
Expand All @@ -82,16 +92,15 @@ static int get_device_queue_and_cmd_buffer(VkPhysicalDevice &pDevice, VkDevice &
nullptr,
};

VkInstance instance;
res = vkCreateInstance(&info, nullptr, &instance);
res = vkCreateInstance(&info, nullptr, &gInstance);
CHECK_VK(res, "Could not create vulkan instance");

uint32_t nbDevices;
res = vkEnumeratePhysicalDevices(instance, &nbDevices, nullptr);
res = vkEnumeratePhysicalDevices(gInstance, &nbDevices, nullptr);
CHECK_VK(res, "Could not enumerate physical devices");

std::vector<VkPhysicalDevice> physicalDevices(nbDevices);
res = vkEnumeratePhysicalDevices(instance, &nbDevices, physicalDevices.data());
res = vkEnumeratePhysicalDevices(gInstance, &nbDevices, physicalDevices.data());
CHECK_VK(res, "Could not enumerate physical devices (second call)");
pDevice = physicalDevices.front();

Expand Down Expand Up @@ -157,14 +166,13 @@ static int get_device_queue_and_cmd_buffer(VkPhysicalDevice &pDevice, VkDevice &

vkGetDeviceQueue(device, queueFamilyIndex, 0, &queue);

VkCommandPool cmdPool;
const VkCommandPoolCreateInfo pCreateInfo
= { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, queueFamilyIndex };
res = vkCreateCommandPool(device, &pCreateInfo, nullptr, &cmdPool);
res = vkCreateCommandPool(device, &pCreateInfo, nullptr, &gCmdPool);
CHECK_VK(res, "Could not create command pool");

const VkCommandBufferAllocateInfo pAllocateInfo
= { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
= { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, gCmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
res = vkAllocateCommandBuffers(device, &pAllocateInfo, &cmdBuffer);
CHECK_VK(res, "Could not allocate command buffer");

Expand Down Expand Up @@ -253,6 +261,7 @@ static uint32_t handle_descriptor_set_buffer(spvtools::vksp_descriptor_set &ds,
ds.buffer.size, ds.buffer.usage, (VkSharingMode)ds.buffer.sharingMode, 0, nullptr };
res = vkCreateBuffer(device, &pCreateInfo, nullptr, &buffer);
CHECK_VK(res, "Could not create buffer");
gBuffers.push_back(buffer);

if (bCounter) {
VkMemoryRequirements memreqs;
Expand Down Expand Up @@ -283,6 +292,7 @@ static uint32_t handle_descriptor_set_buffer(spvtools::vksp_descriptor_set &ds,
VkDeviceMemory memory;
res = vkAllocateMemory(device, &pAllocateInfo, nullptr, &memory);
CHECK_VK(res, "Could not allocate memory for buffer");
gMemories.push_back(memory);

res = vkBindBufferMemory(device, buffer, memory, ds.buffer.bindOffset);
CHECK_VK(res, "Could not bind buffer and memory");
Expand Down Expand Up @@ -324,6 +334,7 @@ static uint32_t handle_descriptor_set_image(spvtools::vksp_descriptor_set &ds, V
(VkImageLayout)ds.image.initialLayout };
res = vkCreateImage(device, &pCreateInfo, nullptr, &image);
CHECK_VK(res, "Could not create image");
gImages.push_back(image);

const VkMemoryAllocateInfo pAllocateInfo = {
VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
Expand All @@ -335,6 +346,7 @@ static uint32_t handle_descriptor_set_image(spvtools::vksp_descriptor_set &ds, V
VkDeviceMemory memory;
res = vkAllocateMemory(device, &pAllocateInfo, nullptr, &memory);
CHECK_VK(res, "Could not allocate memory for image");
gMemories.push_back(memory);

res = vkBindImageMemory(device, image, memory, ds.image.bindOffset);
CHECK_VK(res, "Could not bind image and memory");
Expand All @@ -349,6 +361,7 @@ static uint32_t handle_descriptor_set_image(spvtools::vksp_descriptor_set &ds, V
image, (VkImageViewType)ds.image.viewType, (VkFormat)ds.image.viewFormat, components, subresourceRange };
res = vkCreateImageView(device, &pViewInfo, nullptr, &image_view);
CHECK_VK(res, "Could not create image view");
gImageViews.push_back(image_view);

const VkDescriptorImageInfo imageInfo = { VK_NULL_HANDLE, image_view, (VkImageLayout)ds.image.imageLayout };
const VkWriteDescriptorSet write = {
Expand Down Expand Up @@ -381,6 +394,7 @@ static uint32_t handle_descriptor_set_sampler(spvtools::vksp_descriptor_set &ds,
ds.sampler.fMaxLod, (VkBorderColor)ds.sampler.borderColor, ds.sampler.unnormalizedCoordinates };
res = vkCreateSampler(device, &pCreateInfo, nullptr, &sampler);
CHECK_VK(res, "Could not create sampler");
gSamplers.push_back(sampler);

const VkDescriptorImageInfo imageInfo = { sampler, VK_NULL_HANDLE, VK_IMAGE_LAYOUT_UNDEFINED };
const VkWriteDescriptorSet write = {
Expand Down Expand Up @@ -430,7 +444,7 @@ static uint32_t allocate_descriptor_set(VkDevice device, std::vector<VkDescripto
const VkDescriptorSetLayoutCreateInfo pCreateInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
nullptr, 0, (uint32_t)descSetLayoutBindings.size(), descSetLayoutBindings.data() };
res = vkCreateDescriptorSetLayout(device, &pCreateInfo, nullptr, &descSetLayout);
CHECK_VK(res, "Count not create descriptor set layout");
CHECK_VK(res, "Could not create descriptor set layout");

descSetLayoutVector.push_back(descSetLayout);
}
Expand All @@ -443,12 +457,11 @@ static uint32_t allocate_descriptor_set(VkDevice device, std::vector<VkDescripto
const VkDescriptorPoolCreateInfo pCreateInfo
= { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, nullptr, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
(uint32_t)descSet.size(), (uint32_t)descPoolSize.size(), descPoolSize.data() };
VkDescriptorPool descPool;
res = vkCreateDescriptorPool(device, &pCreateInfo, nullptr, &descPool);
res = vkCreateDescriptorPool(device, &pCreateInfo, nullptr, &gDescPool);
CHECK_VK(res, "Could not create descriptor pool");

const VkDescriptorSetAllocateInfo pAllocateInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, nullptr,
descPool, (uint32_t)descSetLayoutVector.size(), descSetLayoutVector.data() };
gDescPool, (uint32_t)descSetLayoutVector.size(), descSetLayoutVector.data() };
res = vkAllocateDescriptorSets(device, &pAllocateInfo, descSet.data());
CHECK_VK(res, "Could not allocate descriptor sets");

Expand Down Expand Up @@ -507,10 +520,9 @@ static uint32_t allocate_pipeline(std::vector<uint32_t> &shader, VkPipelineLayou
spvtools::vksp_configuration &config, VkPipeline &pipeline)
{
VkResult res;
VkShaderModule shaderModule;
const VkShaderModuleCreateInfo shaderModuleCreateInfo
= { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, nullptr, 0, shader.size() * sizeof(uint32_t), shader.data() };
res = vkCreateShaderModule(device, &shaderModuleCreateInfo, nullptr, &shaderModule);
res = vkCreateShaderModule(device, &shaderModuleCreateInfo, nullptr, &gShaderModule);
CHECK_VK(res, "Could not create shader module");

std::vector<VkSpecializationMapEntry> mapEntries;
Expand Down Expand Up @@ -539,7 +551,7 @@ static uint32_t allocate_pipeline(std::vector<uint32_t> &shader, VkPipelineLayou
};

const VkComputePipelineCreateInfo pCreateInfo = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, nullptr, 0,
{ VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, shaderModule,
{ VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, gShaderModule,
config.entryPoint, &specializationInfo },
pipelineLayout, VK_NULL_HANDLE, 0 };
res = vkCreateComputePipelines(device, VK_NULL_HANDLE, 1, &pCreateInfo, nullptr, &pipeline);
Expand Down Expand Up @@ -653,6 +665,8 @@ static uint32_t execute(VkDevice device, VkCommandBuffer cmdBuffer, VkQueue queu
gpu_timestamps, sizeof(gpu_timestamps[0]), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT);
CHECK_VK(res, "Could not get query pool results");

vkDestroyQueryPool(device, queryPool, nullptr);

return 0;
}

Expand Down Expand Up @@ -751,6 +765,38 @@ static uint32_t print_results(VkPhysicalDevice pDevice, VkDevice device, spvtool
return 0;
}

void clean_vk_objects(VkDevice device, VkCommandBuffer cmdBuffer, std::vector<VkDescriptorSet> &descSet,
std::vector<VkDescriptorSetLayout> &descSetLayoutVector, VkPipelineLayout pipelineLayout, VkPipeline pipeline)
{
vkDestroyShaderModule(device, gShaderModule, nullptr);
vkDestroyPipeline(device, pipeline, nullptr);
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
for (auto sampler : gSamplers) {
vkDestroySampler(device, sampler, nullptr);
}
for (auto imageView : gImageViews) {
vkDestroyImageView(device, imageView, nullptr);
}
for (auto image : gImages) {
vkDestroyImage(device, image, nullptr);
}
for (auto buffer : gBuffers) {
vkDestroyBuffer(device, buffer, nullptr);
}
for (auto memory : gMemories) {
vkFreeMemory(device, memory, nullptr);
}
vkFreeDescriptorSets(device, gDescPool, descSet.size(), descSet.data());
vkDestroyDescriptorPool(device, gDescPool, nullptr);
for (auto descSetLayout : descSetLayoutVector) {
vkDestroyDescriptorSetLayout(device, descSetLayout, nullptr);
}
vkFreeCommandBuffers(device, gCmdPool, 1, &cmdBuffer);
vkDestroyCommandPool(device, gCmdPool, nullptr);
vkDestroyDevice(device, nullptr);
vkDestroyInstance(gInstance, nullptr);
}

static void help()
{
printf("USAGE: vulkan-shader-profiler-runner [OPTIONS] -i <input>\n"
Expand All @@ -776,8 +822,7 @@ static bool parse_args(int argc, char **argv)
ERROR("Could not parse spv target env, using default: '%s'", spvTargetEnvDescription(gSpvTargetEnv));
}

}
break;
} break;
case 'n':
gHotRun = atoi(optarg);
break;
Expand Down Expand Up @@ -942,5 +987,7 @@ int main(int argc, char **argv)
CHECK(print_results(pDevice, device, config, counters, gpu_timestamps, host_timestamps) == 0,
"Could not print all results");

clean_vk_objects(device, cmdBuffer, descSet, descSetLayoutVector, pipelineLayout, pipeline);

return 0;
}
Loading