vulkan/screenshot-layer: Increase buffer sizes

This allows larger buffer sizes when using the env config as well
as filepath for the output directory.

This will allow, for example, using a large number of singular frames:
frames=1/2/3/4/5/6/7/8/.../300

Also fixed an issue with filepaths sometimes being appended with garbage
characters due to not being initialized.

Signed-off-by: Casey Bowman <casey.g.bowman@intel.com>
Reviewed-by: Felix DeGrood <felix.j.degrood@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31793>
This commit is contained in:
Casey Bowman
2024-10-19 22:21:10 -07:00
committed by Marge Bot
parent 461e1f985f
commit 1438cb5c25
3 changed files with 12 additions and 11 deletions

View File

@@ -79,8 +79,6 @@ static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mu
static int globalLockInitialized = 0;
static loader_platform_thread_mutex globalLock;
uint32_t MAX_PATH_SIZE = 512;
/* Mapped from VkInstace/VkPhysicalDevice */
struct instance_data {
struct vk_instance_dispatch_table vtable;
@@ -739,7 +737,7 @@ struct ThreadSaveData {
void *writePNG(void *data) {
struct ThreadSaveData *threadData = (struct ThreadSaveData*)data;
FILE *file;
size_t length = sizeof(char[MAX_PATH_SIZE]);
size_t length = sizeof(char[LARGE_BUFFER_SIZE+STANDARD_BUFFER_SIZE]);
const char *tmpStr = ".tmp";
char *filename = (char *)malloc(length);
char *tmpFilename = (char *)malloc(length + 4); // Allow for ".tmp"
@@ -1193,8 +1191,8 @@ static VkResult screenshot_QueuePresentKHR(
uint32_t path_size_used = 0;
const char *SUFFIX = ".png";
const char *TEMP_DIR = "/tmp/";
char full_path[MAX_PATH_SIZE]; // Let's increase to 512 to account for large files/paths
char filename[256] = "";
char full_path[LARGE_BUFFER_SIZE+STANDARD_BUFFER_SIZE] = "";
char filename[STANDARD_BUFFER_SIZE] = "";
char frame_counter_str[11];
bool rename_file = true;
itoa(frame_counter, frame_counter_str);
@@ -1222,7 +1220,7 @@ static VkResult screenshot_QueuePresentKHR(
strcat(filename, SUFFIX);
}
path_size_used += strlen(filename);
if(path_size_used <= MAX_PATH_SIZE) {
if(path_size_used <= LARGE_BUFFER_SIZE+STANDARD_BUFFER_SIZE) {
strcat(full_path, filename);
pSemaphoreWaitBeforePresent = pPresentInfo->pWaitSemaphores;
semaphoreWaitBeforePresentCount = pPresentInfo->waitSemaphoreCount;
@@ -1241,7 +1239,7 @@ static VkResult screenshot_QueuePresentKHR(
present_info.waitSemaphoreCount = 1;
}
} else {
LOG(DEBUG, "Cancelling screenshot due to excessive filepath size (max %u characters)\n", MAX_PATH_SIZE);
LOG(DEBUG, "Cancelling screenshot due to excessive filepath size (max %u characters)\n", LARGE_BUFFER_SIZE);
}
}
}

View File

@@ -182,7 +182,7 @@ parse_frames(const char *str)
uint32_t range_delimit_count = 0;
range_interval = 1;
char *prev_delim = NULL;
char str_buf[256] = {0};
char str_buf[STANDARD_BUFFER_SIZE] = {0};
char *str_buf_ptr;
str_buf_ptr = str_buf;
struct frame_list *list = (struct frame_list*)malloc(sizeof(struct frame_list));
@@ -300,13 +300,13 @@ parse_log_type(const char *str)
static const char *
parse_output_dir(const char *str)
{
static char output_dir[256];
static char output_dir[LARGE_BUFFER_SIZE];
strcpy(output_dir, str);
uint32_t last_char_index = strlen(str)-1;
// Ensure we're in bounds and the last character is '/'
if (last_char_index > 0 &&
str[last_char_index] != '/' &&
last_char_index < 254) {
last_char_index < LARGE_BUFFER_SIZE-1) {
output_dir[last_char_index+1] = '/';
}
DIR *dir = opendir(output_dir);
@@ -370,7 +370,7 @@ parse_screenshot_env(struct screenshot_params *params,
uint32_t num;
const char *itr = env;
char key[256], value[256];
char key[STANDARD_BUFFER_SIZE], value[LARGE_BUFFER_SIZE];
memset(params, 0, sizeof(*params));

View File

@@ -40,6 +40,9 @@ extern "C" {
SCREENSHOT_PARAM_CUSTOM(output_dir) \
SCREENSHOT_PARAM_CUSTOM(help)
#define LARGE_BUFFER_SIZE 16384 // 16 KB for large input strings
#define STANDARD_BUFFER_SIZE 256
enum screenshot_param_enabled {
#define SCREENSHOT_PARAM_BOOL(name) SCREENSHOT_PARAM_ENABLED_##name,
#define SCREENSHOT_PARAM_CUSTOM(name)