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:
@@ -79,8 +79,6 @@ static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mu
|
|||||||
static int globalLockInitialized = 0;
|
static int globalLockInitialized = 0;
|
||||||
static loader_platform_thread_mutex globalLock;
|
static loader_platform_thread_mutex globalLock;
|
||||||
|
|
||||||
uint32_t MAX_PATH_SIZE = 512;
|
|
||||||
|
|
||||||
/* Mapped from VkInstace/VkPhysicalDevice */
|
/* Mapped from VkInstace/VkPhysicalDevice */
|
||||||
struct instance_data {
|
struct instance_data {
|
||||||
struct vk_instance_dispatch_table vtable;
|
struct vk_instance_dispatch_table vtable;
|
||||||
@@ -739,7 +737,7 @@ struct ThreadSaveData {
|
|||||||
void *writePNG(void *data) {
|
void *writePNG(void *data) {
|
||||||
struct ThreadSaveData *threadData = (struct ThreadSaveData*)data;
|
struct ThreadSaveData *threadData = (struct ThreadSaveData*)data;
|
||||||
FILE *file;
|
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";
|
const char *tmpStr = ".tmp";
|
||||||
char *filename = (char *)malloc(length);
|
char *filename = (char *)malloc(length);
|
||||||
char *tmpFilename = (char *)malloc(length + 4); // Allow for ".tmp"
|
char *tmpFilename = (char *)malloc(length + 4); // Allow for ".tmp"
|
||||||
@@ -1193,8 +1191,8 @@ static VkResult screenshot_QueuePresentKHR(
|
|||||||
uint32_t path_size_used = 0;
|
uint32_t path_size_used = 0;
|
||||||
const char *SUFFIX = ".png";
|
const char *SUFFIX = ".png";
|
||||||
const char *TEMP_DIR = "/tmp/";
|
const char *TEMP_DIR = "/tmp/";
|
||||||
char full_path[MAX_PATH_SIZE]; // Let's increase to 512 to account for large files/paths
|
char full_path[LARGE_BUFFER_SIZE+STANDARD_BUFFER_SIZE] = "";
|
||||||
char filename[256] = "";
|
char filename[STANDARD_BUFFER_SIZE] = "";
|
||||||
char frame_counter_str[11];
|
char frame_counter_str[11];
|
||||||
bool rename_file = true;
|
bool rename_file = true;
|
||||||
itoa(frame_counter, frame_counter_str);
|
itoa(frame_counter, frame_counter_str);
|
||||||
@@ -1222,7 +1220,7 @@ static VkResult screenshot_QueuePresentKHR(
|
|||||||
strcat(filename, SUFFIX);
|
strcat(filename, SUFFIX);
|
||||||
}
|
}
|
||||||
path_size_used += strlen(filename);
|
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);
|
strcat(full_path, filename);
|
||||||
pSemaphoreWaitBeforePresent = pPresentInfo->pWaitSemaphores;
|
pSemaphoreWaitBeforePresent = pPresentInfo->pWaitSemaphores;
|
||||||
semaphoreWaitBeforePresentCount = pPresentInfo->waitSemaphoreCount;
|
semaphoreWaitBeforePresentCount = pPresentInfo->waitSemaphoreCount;
|
||||||
@@ -1241,7 +1239,7 @@ static VkResult screenshot_QueuePresentKHR(
|
|||||||
present_info.waitSemaphoreCount = 1;
|
present_info.waitSemaphoreCount = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -182,7 +182,7 @@ parse_frames(const char *str)
|
|||||||
uint32_t range_delimit_count = 0;
|
uint32_t range_delimit_count = 0;
|
||||||
range_interval = 1;
|
range_interval = 1;
|
||||||
char *prev_delim = NULL;
|
char *prev_delim = NULL;
|
||||||
char str_buf[256] = {0};
|
char str_buf[STANDARD_BUFFER_SIZE] = {0};
|
||||||
char *str_buf_ptr;
|
char *str_buf_ptr;
|
||||||
str_buf_ptr = str_buf;
|
str_buf_ptr = str_buf;
|
||||||
struct frame_list *list = (struct frame_list*)malloc(sizeof(struct frame_list));
|
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 *
|
static const char *
|
||||||
parse_output_dir(const char *str)
|
parse_output_dir(const char *str)
|
||||||
{
|
{
|
||||||
static char output_dir[256];
|
static char output_dir[LARGE_BUFFER_SIZE];
|
||||||
strcpy(output_dir, str);
|
strcpy(output_dir, str);
|
||||||
uint32_t last_char_index = strlen(str)-1;
|
uint32_t last_char_index = strlen(str)-1;
|
||||||
// Ensure we're in bounds and the last character is '/'
|
// Ensure we're in bounds and the last character is '/'
|
||||||
if (last_char_index > 0 &&
|
if (last_char_index > 0 &&
|
||||||
str[last_char_index] != '/' &&
|
str[last_char_index] != '/' &&
|
||||||
last_char_index < 254) {
|
last_char_index < LARGE_BUFFER_SIZE-1) {
|
||||||
output_dir[last_char_index+1] = '/';
|
output_dir[last_char_index+1] = '/';
|
||||||
}
|
}
|
||||||
DIR *dir = opendir(output_dir);
|
DIR *dir = opendir(output_dir);
|
||||||
@@ -370,7 +370,7 @@ parse_screenshot_env(struct screenshot_params *params,
|
|||||||
|
|
||||||
uint32_t num;
|
uint32_t num;
|
||||||
const char *itr = env;
|
const char *itr = env;
|
||||||
char key[256], value[256];
|
char key[STANDARD_BUFFER_SIZE], value[LARGE_BUFFER_SIZE];
|
||||||
|
|
||||||
memset(params, 0, sizeof(*params));
|
memset(params, 0, sizeof(*params));
|
||||||
|
|
||||||
|
@@ -40,6 +40,9 @@ extern "C" {
|
|||||||
SCREENSHOT_PARAM_CUSTOM(output_dir) \
|
SCREENSHOT_PARAM_CUSTOM(output_dir) \
|
||||||
SCREENSHOT_PARAM_CUSTOM(help)
|
SCREENSHOT_PARAM_CUSTOM(help)
|
||||||
|
|
||||||
|
#define LARGE_BUFFER_SIZE 16384 // 16 KB for large input strings
|
||||||
|
#define STANDARD_BUFFER_SIZE 256
|
||||||
|
|
||||||
enum screenshot_param_enabled {
|
enum screenshot_param_enabled {
|
||||||
#define SCREENSHOT_PARAM_BOOL(name) SCREENSHOT_PARAM_ENABLED_##name,
|
#define SCREENSHOT_PARAM_BOOL(name) SCREENSHOT_PARAM_ENABLED_##name,
|
||||||
#define SCREENSHOT_PARAM_CUSTOM(name)
|
#define SCREENSHOT_PARAM_CUSTOM(name)
|
||||||
|
Reference in New Issue
Block a user