Skip to content

Commit 81c2ee1

Browse files
committed
Fix some non-deterministic samples when in benchmark mode
I'm using --benchmark and --hideui to build some automatic testing capabilities locally using our driver's CRC mechanism. Most samples behave deterministically when --benchmark is used, as it fixes the frame-rate for example, but some samples weren't quite right. Note: some still aren't entirely deterministic for other reasons (multiple queues in use, some other random generators being used etc), but this fixes up some of the issues at least.
1 parent be52510 commit 81c2ee1

File tree

7 files changed

+15
-21
lines changed

7 files changed

+15
-21
lines changed

framework/platform/platform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019-2025, Arm Limited and Contributors
1+
/* Copyright (c) 2019-2026, Arm Limited and Contributors
22
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
@@ -477,7 +477,7 @@ bool Platform::start_app()
477477
auto sample_info = static_cast<const apps::SampleInfo *>(requested_app_info);
478478
active_app->set_name(sample_info->name);
479479

480-
if (!active_app->prepare({false, window.get()}))
480+
if (!active_app->prepare({fixed_simulation_fps, window.get()}))
481481
{
482482
LOGE("Failed to prepare vulkan app.");
483483
return false;

samples/extensions/synchronization_2/synchronization_2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021-2025, Sascha Willems
1+
/* Copyright (c) 2021-2026, Sascha Willems
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -264,7 +264,7 @@ void Synchronization2::prepare_storage_buffers()
264264
// Initial particle positions
265265
std::vector<Particle> particle_buffer(num_particles);
266266

267-
std::default_random_engine rnd_engine(window->get_window_mode() == vkb::Window::Mode::Headless ? 0 : static_cast<unsigned>(time(nullptr)));
267+
std::default_random_engine rnd_engine((lock_simulation_speed || window->get_window_mode() == vkb::Window::Mode::Headless) ? 0 : static_cast<unsigned>(time(nullptr)));
268268
std::normal_distribution<float> rnd_distribution(0.0f, 1.0f);
269269

270270
for (uint32_t i = 0; i < static_cast<uint32_t>(attractors.size()); i++)

samples/performance/afbc/afbc.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ bool AFBCSample::prepare(const vkb::ApplicationOptions &options)
7373

7474
create_gui(*window, &get_stats());
7575

76-
// Store the start time to calculate rotation
77-
start_time = std::chrono::system_clock::now();
78-
7976
return true;
8077
}
8178

@@ -91,7 +88,8 @@ void AFBCSample::update(float delta_time)
9188
/* Pan the camera back and forth. */
9289
auto &camera_transform = camera->get_node()->get_component<vkb::sg::Transform>();
9390

94-
float rotation_factor = std::chrono::duration<float>(std::chrono::system_clock::now() - start_time).count();
91+
elapsed_time += delta_time;
92+
float rotation_factor = elapsed_time;
9593

9694
glm::quat qy = glm::angleAxis(0.003f * sin(rotation_factor * 0.7f), glm::vec3(0.0f, 1.0f, 0.0f));
9795
glm::quat orientation = glm::normalize(qy * camera_transform.get_rotation() * glm::angleAxis(0.0f, glm::vec3(1.0f, 0.0f, 0.0f)));

samples/performance/afbc/afbc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019-2024, Arm Limited and Contributors
1+
/* Copyright (c) 2019-2026, Arm Limited and Contributors
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -47,7 +47,7 @@ class AFBCSample : public vkb::VulkanSampleC
4747

4848
bool afbc_enabled{false};
4949

50-
std::chrono::system_clock::time_point start_time;
50+
float elapsed_time{0.0f};
5151
};
5252

5353
std::unique_ptr<vkb::VulkanSampleC> create_afbc();

samples/performance/async_compute/async_compute.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,6 @@ bool AsyncComputeSample::prepare(const vkb::ApplicationOptions &options)
305305

306306
create_gui(*window, &get_stats());
307307

308-
// Store the start time to calculate rotation
309-
start_time = std::chrono::system_clock::now();
310-
311308
auto &threshold_module = get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT,
312309
vkb::ShaderSource("async_compute/threshold.comp.spv"));
313310
auto &blur_up_module = get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT,
@@ -752,7 +749,8 @@ void AsyncComputeSample::update(float delta_time)
752749

753750
composite_subpass->set_texture(&get_current_forward_render_target().get_views()[0], blur_chain_views[1].get(), linear_sampler.get()); // blur_chain[1] and color_targets[0] will be used by the present queue
754751

755-
float rotation_factor = std::chrono::duration<float>(std::chrono::system_clock::now() - start_time).count();
752+
elapsed_time += delta_time;
753+
float rotation_factor = elapsed_time;
756754

757755
glm::quat orientation;
758756

samples/performance/async_compute/async_compute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class AsyncComputeSample : public vkb::VulkanSampleC
4747

4848
virtual void draw_gui() override;
4949

50-
std::chrono::system_clock::time_point start_time;
50+
float elapsed_time{0.0f};
5151

5252
void render_shadow_pass();
5353
VkSemaphore render_forward_offscreen_pass(VkSemaphore hdr_wait_semaphore);

samples/tooling/profiles/profiles.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* Copyright (c) 2022-2025, Sascha Willems
2-
* Copyright (c) 2024-2025, Arm Limited and Contributors
1+
/* Copyright (c) 2022-2026, Sascha Willems
2+
* Copyright (c) 2024-2026, Arm Limited and Contributors
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -253,8 +253,7 @@ void Profiles::generate_textures()
253253
VK_CHECK(vkCreateImageView(get_device().get_handle(), &image_view, nullptr, &textures[i].image_view));
254254

255255
// Generate a random texture
256-
std::random_device rnd_device;
257-
std::default_random_engine rnd_engine(rnd_device());
256+
std::default_random_engine rnd_engine(lock_simulation_speed ? static_cast<unsigned>(i) : std::random_device{}());
258257
std::uniform_int_distribution<short> rnd_dist(0, 255);
259258
const size_t buffer_size = dim * dim * 4;
260259
uint8_t *buffer = staging_buffer.map();
@@ -311,8 +310,7 @@ void Profiles::generate_cubes()
311310
std::vector<uint32_t> indices;
312311

313312
// Generate random per-face texture indices
314-
std::random_device rndDevice;
315-
std::default_random_engine rndEngine(rndDevice());
313+
std::default_random_engine rndEngine(lock_simulation_speed ? 0u : std::random_device{}());
316314
std::uniform_int_distribution<int32_t> rndDist(0, static_cast<uint32_t>(textures.size()) - 1);
317315

318316
// Generate cubes with random per-face texture indices

0 commit comments

Comments
 (0)