Skip to content

Commit

Permalink
Small batch mode fixes (#1036)
Browse files Browse the repository at this point in the history
fix %d

fix label

fix
  • Loading branch information
tomadamatkinson committed Jun 3, 2024
1 parent 3a6e27d commit 86067f1
Show file tree
Hide file tree
Showing 26 changed files with 194 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
- id: copyright-check
name: copyright-check
entry: ./scripts/copyright.py main --fix
language: script
language: python
types: [python]
pass_filenames: false
always_run: true
3 changes: 2 additions & 1 deletion app/plugins/batch_mode/batch_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void BatchMode::init(const vkb::CommandParser &parser)
properties.resizable = false;
platform->set_window_properties(properties);
platform->disable_input_processing();
platform->force_render(true);
request_app();
}

Expand Down Expand Up @@ -166,4 +167,4 @@ void BatchMode::load_next_app()
// App will be started before the next update loop
request_app();
}
} // namespace plugins
} // namespace plugins
5 changes: 3 additions & 2 deletions app/plugins/benchmark_mode/benchmark_mode.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2020-2021, Arm Limited and Contributors
/* Copyright (c) 2020-2024, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -39,6 +39,7 @@ void BenchmarkMode::init(const vkb::CommandParser &parser)
// Whilst in benchmark mode fix the fps so that separate runs are consistently simulated
// This will effect the graph outputs of framerate
platform->force_simulation_fps(60.0f);
platform->force_render(true);
}

void BenchmarkMode::on_update(float delta_time)
Expand All @@ -58,4 +59,4 @@ void BenchmarkMode::on_app_close(const std::string &app_id)
{
LOGI("Benchmark for {} completed in {} seconds (ran {} frames, averaged {} fps)", app_id, elapsed_time, total_frames, total_frames / elapsed_time);
}
} // namespace plugins
} // namespace plugins
6 changes: 6 additions & 0 deletions framework/common/vk_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ VkFormat choose_blendable_format(VkPhysicalDevice physical_device, const std::ve
VkFormatProperties properties;
vkGetPhysicalDeviceFormatProperties(physical_device, format, &properties);
if (properties.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT)
{
return format;
}
}

throw std::runtime_error("No suitable blendable format could be determined");
Expand All @@ -197,7 +199,9 @@ void make_filters_valid(VkPhysicalDevice physical_device, VkFormat format, VkFil
{
// Not all formats support linear filtering, so we need to adjust them if they don't
if (*filter == VK_FILTER_NEAREST && (mipmapMode == nullptr || *mipmapMode == VK_SAMPLER_MIPMAP_MODE_NEAREST))
{
return; // These must already be valid
}

VkFormatProperties properties;
vkGetPhysicalDeviceFormatProperties(physical_device, format, &properties);
Expand All @@ -206,7 +210,9 @@ void make_filters_valid(VkPhysicalDevice physical_device, VkFormat format, VkFil
{
*filter = VK_FILTER_NEAREST;
if (mipmapMode)
{
*mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion framework/drawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ bool Drawer::radio_button(const char *caption, int32_t *selectedOption, const in
{
bool res = ImGui::RadioButton(caption, selectedOption, elementOption);
if (res)
{
dirty = true;
}

return res;
}

bool Drawer::input_float(const char *caption, float *value, float step, const char* precision)
bool Drawer::input_float(const char *caption, float *value, float step, const char *precision)
{
bool res = ImGui::InputFloat(caption, value, step, step * 10.0f, precision);
if (res)
Expand Down
8 changes: 7 additions & 1 deletion framework/gltf_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ inline void prepare_meshlets(std::vector<Meshlet> &meshlets, std::unique_ptr<vkb
meshlet.indices[meshlet.index_count] = *(reinterpret_cast<uint32_t *>(index_data.data()) + i);

if (vertices.insert(meshlet.indices[meshlet.index_count]).second)
{
++meshlet.vertex_count;
}

meshlet.index_count++;
triangle_check = triangle_check < 3 ? ++triangle_check : 1;
Expand All @@ -356,7 +358,9 @@ inline void prepare_meshlets(std::vector<Meshlet> &meshlets, std::unique_ptr<vkb
if (meshlet.vertex_count == 64 || meshlet.index_count == 96 || i == submesh->vertex_indices - 1)
{
if (i == submesh->vertex_indices - 1)
{
assert(triangle_check == 3);
}

uint32_t counter = 0;
for (auto v : vertices)
Expand Down Expand Up @@ -661,7 +665,9 @@ sg::Scene GLTFLoader::load_scene(int scene_index)

scene.add_component(std::move(default_sampler_linear));
if (used_nearest_sampler)
{
scene.add_component(std::move(default_sampler_nearest));
}

// Load materials
bool has_textures = scene.has_component<sg::Texture>();
Expand Down Expand Up @@ -1237,7 +1243,7 @@ std::unique_ptr<sg::SubMesh> GLTFLoader::load_model(uint32_t index, bool storage
prepare_meshlets(meshlets, submesh, index_data);

// vertex_indices and index_buffer are used for meshlets now
submesh->vertex_indices = (uint32_t) meshlets.size();
submesh->vertex_indices = static_cast<uint32_t>(meshlets.size());

core::Buffer stage_buffer = vkb::core::Buffer::create_staging_buffer(device, meshlets);

Expand Down
118 changes: 59 additions & 59 deletions framework/platform/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
#include "platform/plugins/plugin.h"
#include "vulkan_sample.h"

namespace plugins
{
class BenchmarkMode;
}

namespace vkb
{
const uint32_t Platform::MIN_WINDOW_WIDTH = 420;
Expand Down Expand Up @@ -133,59 +128,59 @@ ExitCode Platform::initialize(const std::vector<Plugin *> &plugins)

ExitCode Platform::main_loop_frame()
{
if (!app_requested())
{
return ExitCode::NoSample;
}

if (!window->should_close() && !close_requested)
{
try
{
// Load the requested app
if (app_requested())
{
if (!start_app())
{
LOGE("Failed to load requested application");
return ExitCode::FatalError;
}

// Compensate for load times of the app by rendering the first frame pre-emptively
timer.tick<Timer::Seconds>();
active_app->update(0.01667f);
}

update();

if (active_app && active_app->should_close())
{
std::string id = active_app->get_name();
on_app_close(id);
active_app->finish();
}

window->process_events();
}
catch (std::exception &e)
{
LOGE("Error Message: {}", e.what());
LOGE("Failed when running application {}", active_app->get_name());

on_app_error(active_app->get_name());

if (app_requested())
{
LOGI("Attempting to load next application");
}
else
{
return ExitCode::FatalError;
}
}
}

return ExitCode::Success;
if (!app_requested())
{
return ExitCode::NoSample;
}

if (!window->should_close() && !close_requested)
{
try
{
// Load the requested app
if (app_requested())
{
if (!start_app())
{
LOGE("Failed to load requested application");
return ExitCode::FatalError;
}

// Compensate for load times of the app by rendering the first frame pre-emptively
timer.tick<Timer::Seconds>();
active_app->update(0.01667f);
}

update();

if (active_app && active_app->should_close())
{
std::string id = active_app->get_name();
on_app_close(id);
active_app->finish();
}

window->process_events();
}
catch (std::exception &e)
{
LOGE("Error Message: {}", e.what());
LOGE("Failed when running application {}", active_app->get_name());

on_app_error(active_app->get_name());

if (app_requested())
{
LOGI("Attempting to load next application");
}
else
{
return ExitCode::FatalError;
}
}
}

return ExitCode::Success;
}

ExitCode Platform::main_loop()
Expand Down Expand Up @@ -249,7 +244,7 @@ void Platform::update()
{
auto delta_time = static_cast<float>(timer.tick<Timer::Seconds>());

if (focused)
if (focused || always_render)
{
on_update(delta_time);

Expand Down Expand Up @@ -346,6 +341,11 @@ void Platform::force_simulation_fps(float fps)
simulation_frame_time = 1 / fps;
}

void Platform::force_render(bool should_always_render)
{
always_render = should_always_render;
}

void Platform::disable_input_processing()
{
process_input_events = false;
Expand Down
6 changes: 5 additions & 1 deletion framework/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Platform
* @return An exit code representing the outcome of the loop
*/
ExitCode main_loop();
ExitCode main_loop_frame();
ExitCode main_loop_frame();

/**
* @brief Runs the application for one frame
Expand Down Expand Up @@ -128,6 +128,9 @@ class Platform

void force_simulation_fps(float fps);

// Force the application to always render even if it is not in focus
void force_render(bool should_always_render);

void disable_input_processing();

void set_window_properties(const Window::OptionalProperties &properties);
Expand Down Expand Up @@ -166,6 +169,7 @@ class Platform

Window::Properties window_properties; /* Source of truth for window state */
bool fixed_simulation_fps{false}; /* Delta time should be fixed with a fabricated value */
bool always_render{false}; /* App should always render even if not in focus */
float simulation_frame_time = 0.016f; /* A fabricated delta time */
bool process_input_events{true}; /* App should continue processing input events */
bool focused{true}; /* App is currently in focus at an operating system level */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void HPPDynamicUniformBuffers::prepare_camera()
camera.set_rotation(glm::vec3(0.0f));

// Note: Using reversed depth-buffer for increased precision, so Znear and Zfar are flipped
camera.set_perspective(60.0f, (float) extent.width / (float) extent.height, 256.0f, 0.1f);
camera.set_perspective(60.0f, static_cast<float>(extent.width) / static_cast<float>(extent.height), 256.0f, 0.1f);
}

// Prepare and initialize uniform buffer containing shader uniforms
Expand Down
6 changes: 3 additions & 3 deletions samples/api/hpp_timestamp_queries/hpp_timestamp_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ void HPPTimestampQueries::on_update_ui_overlay(vkb::Drawer &drawer)
// The timestampPeriod property of the device tells how many nanoseconds such a timestep translates to on the selected device
float timestampFrequency = get_device().get_gpu().get_properties().limits.timestampPeriod;

drawer.text("Pass 1: Offscreen scene rendering: %.3f ms", float(time_stamps.values[1] - time_stamps.values[0]) * timestampFrequency / 1000000.0f);
drawer.text("Pass 2: %s %.3f ms", (bloom.enabled ? "First bloom pass" : "Scene display"), float(time_stamps.values[3] - time_stamps.values[2]) * timestampFrequency / 1000000.0f);
drawer.text("Pass 1: Offscreen scene rendering: %.3f ms", static_cast<float>(time_stamps.values[1] - time_stamps.values[0]) * timestampFrequency / 1000000.0f);
drawer.text("Pass 2: %s %.3f ms", (bloom.enabled ? "First bloom pass" : "Scene display"), static_cast<float>(time_stamps.values[3] - time_stamps.values[2]) * timestampFrequency / 1000000.0f);
if (bloom.enabled)
{
drawer.text("Pass 3: Second bloom pass %.3f ms", float(time_stamps.values[5] - time_stamps.values[4]) * timestampFrequency / 1000000.0f);
drawer.text("Pass 3: Second bloom pass %.3f ms", static_cast<float>(time_stamps.values[5] - time_stamps.values[4]) * timestampFrequency / 1000000.0f);
drawer.set_dirty(true);
}
}
Expand Down
10 changes: 10 additions & 0 deletions samples/api/swapchain_recreation/swapchain_recreation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,10 @@ VkPhysicalDevice SwapchainRecreation::get_gpu_handle()

VkDevice SwapchainRecreation::get_device_handle()
{
if (!has_device())
{
return VK_NULL_HANDLE;
}
return get_device().get_handle();
}

Expand All @@ -937,6 +941,12 @@ SwapchainRecreation::SwapchainRecreation()

SwapchainRecreation::~SwapchainRecreation()
{
if (get_device_handle() == VK_NULL_HANDLE)
{
// No device, VK_EXT_swapchain_maintenance1 may not be available. Resources will not be created.
return;
}

// Wait for device to be idle and clean up everything.
vkDeviceWaitIdle(get_device_handle());

Expand Down
2 changes: 1 addition & 1 deletion samples/api/swapchain_recreation/swapchain_recreation.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class SwapchainRecreation : public vkb::VulkanSample<vkb::BindingType::C>
public:
SwapchainRecreation();

~SwapchainRecreation() override;
virtual ~SwapchainRecreation() override;

void create_render_context() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,14 @@ bool CalibratedTimestamps::prepare(const vkb::ApplicationOptions &options)
void CalibratedTimestamps::render(float delta_time)
{
if (!prepared)
{
return;
}
draw();
if (camera.updated)
{
update_uniform_buffers();
}
}

void CalibratedTimestamps::get_time_domains()
Expand Down
4 changes: 2 additions & 2 deletions samples/extensions/debug_utils/debug_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ VkPipelineShaderStageCreateInfo DebugUtils::debug_load_shader(const std::string
if (debug_utils_supported)
{
// Name the shader (by file name)
set_object_name(VK_OBJECT_TYPE_SHADER_MODULE, (uint64_t) shader_stage.module, std::string("Shader " + file).c_str());
set_object_name(VK_OBJECT_TYPE_SHADER_MODULE, (uint64_t) shader_stage.module, static_cast<std::string>("Shader " + file).c_str());

std::vector<uint8_t> buffer = vkb::fs::read_shader_binary(file);
// Pass the source GLSL shader code via an object tag
Expand Down Expand Up @@ -1046,7 +1046,7 @@ void DebugUtils::update_uniform_buffers()

void DebugUtils::draw()
{
queue_begin_label(queue, std::string("Graphics queue command buffer " + std::to_string(current_buffer) + " submission").c_str(), {1.0f, 1.0f, 1.0f, 1.0f});
queue_begin_label(queue, static_cast<std::string>("Graphics queue command buffer " + std::to_string(current_buffer) + " submission").c_str(), {1.0f, 1.0f, 1.0f, 1.0f});
ApiVulkanSample::prepare_frame();
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &draw_cmd_buffers[current_buffer];
Expand Down
Loading

0 comments on commit 86067f1

Please sign in to comment.