Skip to content

Commit

Permalink
Add force_fifo_present_mode optional setting (#1687)
Browse files Browse the repository at this point in the history
If presentMode is forced to VK_PRESENT_MODE_FIFO_KHR in vkCreateSwapchainKHR,
the application will crash if it does not use VK_PRESENT_MODE_FIFO_KHR when capturing.
  • Loading branch information
zongdu-arm authored Sep 16, 2024
1 parent 247ff67 commit fa95511
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions USAGE_android.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ option values.
| Page guard unblock SIGSEGV | debug.gfxrecon.page_guard_unblock_sigsegv | BOOL | When the `page_guard` memory tracking mode is enabled and in the case that SIGSEGV has been marked as blocked in thread's signal mask, setting this enviroment variable to `true` will forcibly re-enable the signal in the thread's signal mask. Default is `false` |
| Page guard signal handler watcher | debug.gfxrecon.page_guard_signal_handler_watcher | BOOL | When the `page_guard` memory tracking mode is enabled, setting this enviroment variable to `true` will spawn a thread which will periodically reinstall the `SIGSEGV` handler if it has been replaced by the application being traced. Default is `false` |
| Page guard signal handler watcher max restores | debug.gfxrecon.page_guard_signal_handler_watcher_max_restores | INTEGER | Sets the number of times the watcher will attempt to restore the signal handler. Setting it to a negative value will make the watcher thread run indefinitely. Default is `1` |
| Force FIFO present mode | debug.gfxrecon.force_fifo_present_mode | BOOL | When the `force_fifo_present_mode` is enabled, force all present modes in vkGetPhysicalDeviceSurfacePresentModesKHR to VK_PRESENT_MODE_FIFO_KHR, app present mode is set in vkCreateSwapchain to VK_PRESENT_MODE_FIFO_KHR. Otherwise the original present mode will be used. Default is: `true` |

#### Settings File

Expand Down
6 changes: 6 additions & 0 deletions framework/encode/capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ bool CommonCaptureManager::Initialize(format::ApiFamilyId api_
force_command_serialization_ = trace_settings.force_command_serialization;
queue_zero_only_ = trace_settings.queue_zero_only;
allow_pipeline_compile_required_ = trace_settings.allow_pipeline_compile_required;
force_fifo_present_mode_ = trace_settings.force_fifo_present_mode;

rv_annotation_info_.gpuva_mask = trace_settings.rv_anotation_info.gpuva_mask;
rv_annotation_info_.descriptor_mask = trace_settings.rv_anotation_info.descriptor_mask;
Expand Down Expand Up @@ -1404,6 +1405,11 @@ void CommonCaptureManager::WriteCaptureOptions(std::string& operation_annotation
buffer += "\n \"queue-zero-only\": ";
buffer += queue_zero_only_ ? "true," : "false,";
}
if (force_fifo_present_mode_ != default_settings.force_fifo_present_mode)
{
buffer += "\n \"force-fifo-present-mode\": ";
buffer += force_fifo_present_mode_ ? "true," : "false,";
}

if (buffer.empty())
{
Expand Down
2 changes: 2 additions & 0 deletions framework/encode/capture_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class CommonCaptureManager
bool GetDebugDeviceLostSetting() const { return debug_device_lost_; }
bool GetDisableDxrSetting() const { return disable_dxr_; }
auto GetAccelStructPaddingSetting() const { return accel_struct_padding_; }
bool GetForceFifoPresentModeSetting() const { return force_fifo_present_mode_; }

util::Compressor* GetCompressor() { return compressor_.get(); }
std::mutex& GetMappedMemoryLock() { return mapped_memory_lock_; }
Expand Down Expand Up @@ -380,6 +381,7 @@ class CommonCaptureManager
bool queue_zero_only_;
bool allow_pipeline_compile_required_;
bool quit_after_frame_ranges_;
bool force_fifo_present_mode_;

struct
{
Expand Down
8 changes: 8 additions & 0 deletions framework/encode/capture_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ GFXRECON_BEGIN_NAMESPACE(encode)
#define RV_ANNOTATION_GPUVA_UPPER "RV_ANNOTATION_GPUVA"
#define RV_ANNOTATION_DESCRIPTOR_LOWER "rv_annotation_descriptor"
#define RV_ANNOTATION_DESCRIPTOR_UPPER "RV_ANNOTATION_DESCRIPTOR"
#define FORCE_FIFO_PRESENT_MODE_LOWER "force_fifo_present_mode"
#define FORCE_FIFO_PRESENT_MODE_UPPER "FORCE_FIFO_PRESENT_MODE"

#if defined(__ANDROID__)
// Android Properties
Expand Down Expand Up @@ -187,6 +189,7 @@ const char kAnnotationExperimentalEnvVar[] = GFXRECON_ENV_VAR_
const char kAnnotationRandEnvVar[] = GFXRECON_ENV_VAR_PREFIX RV_ANNOTATION_RAND_LOWER;
const char kAnnotationGPUVAEnvVar[] = GFXRECON_ENV_VAR_PREFIX RV_ANNOTATION_GPUVA_LOWER;
const char kAnnotationDescriptorEnvVar[] = GFXRECON_ENV_VAR_PREFIX RV_ANNOTATION_DESCRIPTOR_LOWER;
const char kForceFifoPresentModeEnvVar[] = GFXRECON_ENV_VAR_PREFIX FORCE_FIFO_PRESENT_MODE_LOWER;

#else
// Desktop environment settings
Expand Down Expand Up @@ -239,6 +242,7 @@ const char kAnnotationExperimentalEnvVar[] = GFXRECON_ENV_VAR_
const char kAnnotationRandEnvVar[] = GFXRECON_ENV_VAR_PREFIX RV_ANNOTATION_RAND_UPPER;
const char kAnnotationGPUVAEnvVar[] = GFXRECON_ENV_VAR_PREFIX RV_ANNOTATION_GPUVA_UPPER;
const char kAnnotationDescriptorEnvVar[] = GFXRECON_ENV_VAR_PREFIX RV_ANNOTATION_DESCRIPTOR_UPPER;
const char kForceFifoPresentModeEnvVar[] = GFXRECON_ENV_VAR_PREFIX FORCE_FIFO_PRESENT_MODE_UPPER;

#endif

Expand Down Expand Up @@ -290,6 +294,7 @@ const std::string kOptionKeyAnnotationExperimental = std::stri
const std::string kOptionKeyAnnotationRand = std::string(kSettingsFilter) + std::string(RV_ANNOTATION_RAND_LOWER);
const std::string kOptionKeyAnnotationGPUVA = std::string(kSettingsFilter) + std::string(RV_ANNOTATION_GPUVA_LOWER);
const std::string kOptionKeyAnnotationDescriptor = std::string(kSettingsFilter) + std::string(RV_ANNOTATION_DESCRIPTOR_LOWER);
const std::string kOptionForceFifoPresentModeEnvVar = std::string(kSettingsFilter) + std::string(FORCE_FIFO_PRESENT_MODE_LOWER);

#if defined(GFXRECON_ENABLE_LZ4_COMPRESSION)
const format::CompressionType kDefaultCompressionType = format::CompressionType::kLz4;
Expand Down Expand Up @@ -445,6 +450,7 @@ void CaptureSettings::LoadOptionsEnvVar(OptionsMap* options)
LoadSingleOptionEnvVar(options, kAnnotationRandEnvVar, kOptionKeyAnnotationRand);
LoadSingleOptionEnvVar(options, kAnnotationGPUVAEnvVar, kOptionKeyAnnotationGPUVA);
LoadSingleOptionEnvVar(options, kAnnotationDescriptorEnvVar, kOptionKeyAnnotationDescriptor);
LoadSingleOptionEnvVar(options, kForceFifoPresentModeEnvVar, kOptionForceFifoPresentModeEnvVar);
}

void CaptureSettings::LoadOptionsFile(OptionsMap* options)
Expand Down Expand Up @@ -616,6 +622,8 @@ void CaptureSettings::ProcessOptions(OptionsMap* options, CaptureSettings* setti
settings->trace_settings_.rv_anotation_info.descriptor_mask =
ParseUnsignedInteger16String(FindOption(options, kOptionKeyAnnotationDescriptor),
settings->trace_settings_.rv_anotation_info.descriptor_mask);
settings->trace_settings_.force_fifo_present_mode = ParseBoolString(
FindOption(options, kOptionForceFifoPresentModeEnvVar), settings->trace_settings_.force_fifo_present_mode);
}

void CaptureSettings::ProcessLogOptions(OptionsMap* options, CaptureSettings* settings)
Expand Down
1 change: 1 addition & 0 deletions framework/encode/capture_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class CaptureSettings
bool queue_zero_only{ false };
bool allow_pipeline_compile_required{ false };
bool quit_after_frame_ranges{ false };
bool force_fifo_present_mode{ true };

// An optimization for the page_guard memory tracking mode that eliminates the need for shadow memory by
// overriding vkAllocateMemory so that all host visible allocations use the external memory extension with a
Expand Down
12 changes: 10 additions & 2 deletions framework/encode/vulkan_capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2682,9 +2682,17 @@ void VulkanCaptureManager::OverrideGetPhysicalDeviceSurfacePresentModesKHR(uint3
{
assert((pPresentModeCount != nullptr) && (pPresentModes != nullptr));

for (uint32_t i = 0; i < (*pPresentModeCount); ++i)
if (common_manager_->GetForceFifoPresentModeSetting())
{
pPresentModes[i] = VK_PRESENT_MODE_FIFO_KHR;
GFXRECON_LOG_WARNING_ONCE(
"Force all present modes in vkGetPhysicalDeviceSurfacePresentModesKHR to VK_PRESENT_MODE_FIFO_KHR. "
"The application will use VK_PRESENT_MODE_FIFO_KHR present mode in vkCreateSwapchainKHR, which may "
"cause an unknown crash if the application does not use VK_PRESENT_MODE_FIFO_KHR present mode");

for (uint32_t i = 0; i < (*pPresentModeCount); ++i)
{
pPresentModes[i] = VK_PRESENT_MODE_FIFO_KHR;
}
}
}
#endif
Expand Down

0 comments on commit fa95511

Please sign in to comment.