From 4740f6b8efc014cbf7a4354ec33c8c29894762b6 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Sun, 12 Mar 2023 16:07:41 +0100 Subject: Fix some compilation warnings + release build Fix element by element copy of imgui vertices --- api-test/CMakeLists.txt | 4 ++++ api-test/main.cpp | 39 ++++++++++++++------------------------- api-test/vk-bindless.cpp | 12 ++++++------ api-test/vk-device.cpp | 4 +++- include/api-test/vk-bindless.hpp | 2 +- include/api-test/vk-utils.hpp | 2 +- shaders/api-test-ui.vert | 12 +++++++----- 7 files changed, 36 insertions(+), 39 deletions(-) diff --git a/api-test/CMakeLists.txt b/api-test/CMakeLists.txt index 3fcad92..dc92ee3 100644 --- a/api-test/CMakeLists.txt +++ b/api-test/CMakeLists.txt @@ -12,6 +12,10 @@ add_executable( target_compile_definitions(api-test PUBLIC WINDOWS VK_NO_PROTOTYPES VK_USE_PLATFORM_WIN32_KHR) +target_compile_options(api-test + PRIVATE -Wall -Wextra +) + target_include_directories(api-test SYSTEM PUBLIC ${Vulkan_INCLUDE_DIRS}) target_include_directories(api-test SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/thirdparty) target_include_directories(api-test PUBLIC ${CMAKE_SOURCE_DIR}/include) diff --git a/api-test/main.cpp b/api-test/main.cpp index 0a2ab71..ee09f69 100644 --- a/api-test/main.cpp +++ b/api-test/main.cpp @@ -16,7 +16,9 @@ struct device_texture; +#ifdef _DEBUG #define ENABLE_RENDERDOC +#endif // _DEBUG #ifdef ENABLE_RENDERDOC #include @@ -25,7 +27,10 @@ struct device_texture; #define RD_END_CAPTURE if(rdoc_api != nullptr) rdoc_api->EndFrameCapture(nullptr, nullptr) RENDERDOC_API_1_4_1 *rdoc_api = nullptr; -#endif +#else +#define RD_START_CAPTURE (0) +#define RD_END_CAPTURE (0) +#endif // ENABLE_RENDERDOC static constexpr size_t Kb = 1024U; static constexpr size_t Mb = 1024U * Kb; @@ -39,27 +44,14 @@ void ui() { } void update_buffers(ImDrawData* draw_data, const device_buffer& vertex_buffer, const device_buffer& index_buffer) { - struct vertex { - ImVec2 pos; - ImVec2 uv; - uint32_t color; - uint32_t padding; - }; - off_t vertex_offset = 0; off_t index_offset = 0; - for (auto index {0U} ; index < draw_data->CmdListsCount; index++) { + for (auto index {0} ; index < draw_data->CmdListsCount; index++) { auto* cmd_list = draw_data->CmdLists[index]; size_t vertex_bytes_size = sizeof(ImDrawVert) * cmd_list->VtxBuffer.size(); - auto* vtx_ptr = static_cast(vertex_buffer.mapped_ptr) + vertex_offset; - for (auto vtx_index{0}; vtx_index < cmd_list->VtxBuffer.size(); vtx_index++, vtx_ptr++) { - auto& vtx = cmd_list->VtxBuffer[vtx_index]; - vtx_ptr->pos = vtx.pos; - vtx_ptr->uv = vtx.uv; - vtx_ptr->color = vtx.col; - } - // memcpy(static_cast(vertex_buffer.mapped_ptr) + vertex_offset, cmd_list->VtxBuffer.Data, vertex_bytes_size); + auto* vtx_ptr = static_cast(vertex_buffer.mapped_ptr) + vertex_offset; + memcpy(vtx_ptr, cmd_list->VtxBuffer.Data, vertex_bytes_size); vertex_offset += static_cast(vertex_bytes_size); size_t index_bytes_size = sizeof(ImDrawIdx) * cmd_list->IdxBuffer.size(); @@ -72,11 +64,8 @@ int main() { #ifdef ENABLE_RENDERDOC if (HMODULE mod = GetModuleHandleA("renderdoc.dll")) { - auto RENDERDOC_GetAPI = - (pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI"); - int ret = - RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void **)&rdoc_api); - assert(ret == 1); + auto RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI"); + assert(RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void **)&rdoc_api) == 1); } #endif @@ -238,8 +227,8 @@ int main() { command_buffers[0].dispatch({ .pipeline = compute, - .group_size = { image_size, image_size, 1U }, - .local_group_size = { 8U, 8U, 1U }, + .group_size = { .vec = { image_size, image_size, 1U }}, + .local_group_size = { .vec = { 8U, 8U, 1U }}, .uniforms_offset = 0U, }); @@ -299,7 +288,7 @@ int main() { uint32_t draw_index = 0U; std::array draws; - for (auto index {0U} ; index < draw_data->CmdListsCount; index++) { + for (auto index {0} ; index < draw_data->CmdListsCount; index++) { auto* cmd_list = draw_data->CmdLists[index]; for (auto& draw_command : cmd_list->CmdBuffer) { diff --git a/api-test/vk-bindless.cpp b/api-test/vk-bindless.cpp index c27211f..66fd59c 100644 --- a/api-test/vk-bindless.cpp +++ b/api-test/vk-bindless.cpp @@ -151,14 +151,14 @@ void bindless_model::create_layout(VkDevice device) { { .binding = 1U, .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - .descriptorCount = set_descriptors_count[BindlessSetType::GLOBAL], + .descriptorCount = set_descriptors_count, .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, .pImmutableSamplers = nullptr, }, { .binding = 2U, .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, - .descriptorCount = set_descriptors_count[BindlessSetType::GLOBAL], + .descriptorCount = set_descriptors_count, .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, .pImmutableSamplers = nullptr, }, @@ -254,19 +254,19 @@ void bindless_model::create_descriptor_pool(VkDevice device) { VkDescriptorPoolSize pool_sizes[]{ { .type = VK_DESCRIPTOR_TYPE_SAMPLER, - .descriptorCount = set_descriptors_count[BindlessSetType::MAX], + .descriptorCount = set_descriptors_count, }, { .type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - .descriptorCount = set_descriptors_count[BindlessSetType::MAX], + .descriptorCount = set_descriptors_count, }, { .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, - .descriptorCount = set_descriptors_count[BindlessSetType::MAX], + .descriptorCount = set_descriptors_count, }, { .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, - .descriptorCount = set_descriptors_count[BindlessSetType::MAX], + .descriptorCount = set_descriptors_count, }, }; diff --git a/api-test/vk-device.cpp b/api-test/vk-device.cpp index 42f6269..2b9f7eb 100644 --- a/api-test/vk-device.cpp +++ b/api-test/vk-device.cpp @@ -826,6 +826,7 @@ bool vkdevice::device_support_features(VkPhysicalDevice physical_dev) { } void vkdevice::create_debug_layer_callback() { +#ifdef _DEBUG VkDebugUtilsMessengerCreateInfoEXT create_info{ .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT, .pNext = nullptr, @@ -840,6 +841,7 @@ void vkdevice::create_debug_layer_callback() { }; VKCHECK(vkCreateDebugUtilsMessengerEXT(instance, &create_info, nullptr, &debug_messenger)); +#endif // _DEBUG } @@ -996,7 +998,7 @@ void device_texture::create_views() { }, }; - for (auto mip_index{ 0 }; mip_index < mips; mip_index++) { + for (auto mip_index{ 0U }; mip_index < mips; mip_index++) { create_info.subresourceRange.baseMipLevel = mip_index; VKCHECK(vkCreateImageView(device, &create_info, nullptr, &mips_views[mip_index])); } diff --git a/include/api-test/vk-bindless.hpp b/include/api-test/vk-bindless.hpp index 80918fe..7b8eccc 100644 --- a/include/api-test/vk-bindless.hpp +++ b/include/api-test/vk-bindless.hpp @@ -39,7 +39,7 @@ private: handle draws_uniform_buffer_handle; static constexpr size_t descriptor_pool_allocable_sets_count = 64U; - static constexpr uint32_t set_descriptors_count[BindlessSetType::MAX]{ 1024U }; + static constexpr uint32_t set_descriptors_count = 1024U; void create_layout(VkDevice device); void create_descriptor_pool(VkDevice device); diff --git a/include/api-test/vk-utils.hpp b/include/api-test/vk-utils.hpp index a107d3b..205e103 100644 --- a/include/api-test/vk-utils.hpp +++ b/include/api-test/vk-utils.hpp @@ -7,7 +7,7 @@ #ifdef _DEBUG #define VKCHECK(result) assert((result) == VK_SUCCESS) #else -#define VKCHECK(result) (result) +#define VKCHECK(result) result #endif VKAPI_ATTR VkBool32 VKAPI_CALL debug_callback(VkDebugUtilsMessageSeverityFlagBitsEXT severity, diff --git a/shaders/api-test-ui.vert b/shaders/api-test-ui.vert index 92c1372..4824d23 100644 --- a/shaders/api-test-ui.vert +++ b/shaders/api-test-ui.vert @@ -1,10 +1,11 @@ #extension GL_EXT_buffer_reference : require struct vertex { - vec2 pos; - vec2 uv; + float pos_x; + float pos_y; + float uv_x; + float uv_y; uint color; - uint padding; }; layout(buffer_reference) readonly buffer vertices { @@ -32,7 +33,8 @@ void main() { vertex v = params.vertex_buffer.vertices[gl_VertexIndex]; Out.color = unpackUnorm4x8(v.color); - Out.uv = v.uv; + Out.uv = vec2(v.uv_x, v.uv_y); - gl_Position = vec4(v.pos * params.scale + params.translate, 0.0, 1.0); + vec2 pos = vec2(v.pos_x, v.pos_y); + gl_Position = vec4(pos * params.scale + params.translate, 0.0, 1.0); } -- cgit v1.3