Skip to content

Commit

Permalink
Add RTPSO support to external replayer.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKristian-Work committed Sep 14, 2021
1 parent 4a670d4 commit b9aedc2
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 2 deletions.
17 changes: 16 additions & 1 deletion fossilize_external_replayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void ExternalReplayer::compute_condensed_progress(const Progress &progress, unsi
// Due to all these quirks, it is somewhat complicated to provide an accurate metric on completion.
unsigned total_actions = 2 * progress.total_graphics_pipeline_blobs +
2 * progress.total_compute_pipeline_blobs +
2 * progress.total_raytracing_pipeline_blobs +
progress.total_modules;

// If we have crashes or other unexpected behavior, these values might increase beyond the expected value.
Expand All @@ -86,12 +87,16 @@ void ExternalReplayer::compute_condensed_progress(const Progress &progress, unsi
// but UI can always report something here when we know we're not done yet.
unsigned parsed_graphics = (std::min)(progress.graphics.parsed + progress.graphics.parsed_fail + progress.graphics.cached, progress.total_graphics_pipeline_blobs);
unsigned parsed_compute = (std::min)(progress.compute.parsed + progress.compute.parsed_fail + progress.compute.cached, progress.total_compute_pipeline_blobs);
unsigned parsed_raytracing = (std::min)(progress.raytracing.parsed + progress.raytracing.parsed_fail + progress.raytracing.cached, progress.total_raytracing_pipeline_blobs);
unsigned compiled_graphics = (std::min)(progress.graphics.completed + progress.graphics.skipped + progress.graphics.cached, progress.total_graphics_pipeline_blobs);
unsigned compiled_compute = (std::min)(progress.compute.completed + progress.compute.skipped + progress.compute.cached, progress.total_compute_pipeline_blobs);
unsigned compiled_raytracing = (std::min)(progress.raytracing.completed + progress.raytracing.skipped + progress.raytracing.cached, progress.total_raytracing_pipeline_blobs);
unsigned decompressed_modules = (std::min)(progress.completed_modules + progress.module_validation_failures +
progress.banned_modules + progress.missing_modules, progress.total_modules);

completed = parsed_graphics + parsed_compute + compiled_graphics + compiled_compute + decompressed_modules;
completed = parsed_graphics + parsed_compute + parsed_raytracing +
compiled_graphics + compiled_compute + compiled_raytracing +
decompressed_modules;
total = total_actions;
}

Expand All @@ -115,6 +120,11 @@ bool ExternalReplayer::get_faulty_compute_pipelines(size_t *num_hashes, unsigned
return impl->get_faulty_compute_pipelines(num_hashes, indices, hashes);
}

bool ExternalReplayer::get_faulty_raytracing_pipelines(size_t *num_hashes, unsigned *indices, Hash *hashes) const
{
return impl->get_faulty_raytracing_pipelines(num_hashes, indices, hashes);
}

bool ExternalReplayer::get_graphics_failed_validation(size_t *num_hashes, Hash *hashes) const
{
return impl->get_graphics_failed_validation(num_hashes, hashes);
Expand All @@ -125,6 +135,11 @@ bool ExternalReplayer::get_compute_failed_validation(size_t *num_hashes, Hash *h
return impl->get_compute_failed_validation(num_hashes, hashes);
}

bool ExternalReplayer::get_raytracing_failed_validation(size_t *num_hashes, Hash *hashes) const
{
return impl->get_raytracing_failed_validation(num_hashes, hashes);
}

bool ExternalReplayer::poll_memory_usage(uint32_t *num_processes, ProcessStats *stats) const
{
return impl->poll_memory_usage(num_processes, stats);
Expand Down
6 changes: 6 additions & 0 deletions fossilize_external_replayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class ExternalReplayer
unsigned end_graphics_index;
unsigned start_compute_index;
unsigned end_compute_index;
unsigned start_raytracing_index;
unsigned end_raytracing_index;
bool use_pipeline_range;

// Redirect stdout and stderr to /dev/null or NUL.
Expand Down Expand Up @@ -182,10 +184,12 @@ class ExternalReplayer
// with a given pipeline range.
bool get_faulty_graphics_pipelines(size_t *num_pipelines, unsigned *indices, Hash *hashes) const;
bool get_faulty_compute_pipelines(size_t *num_pipelines, unsigned *indices, Hash *hashes) const;
bool get_faulty_raytracing_pipelines(size_t *num_pipelines, unsigned *indices, Hash *hashes) const;

// If validation is enabled, gets a list of all pipelines which failed validation.
bool get_graphics_failed_validation(size_t *num_hashes, Hash *hashes) const;
bool get_compute_failed_validation(size_t *num_hashes, Hash *hashes) const;
bool get_raytracing_failed_validation(size_t *num_hashes, Hash *hashes) const;

enum class PollResult : unsigned
{
Expand All @@ -211,6 +215,7 @@ class ExternalReplayer
{
TypeProgress compute;
TypeProgress graphics;
TypeProgress raytracing;

uint32_t completed_modules;
uint32_t missing_modules;
Expand All @@ -224,6 +229,7 @@ class ExternalReplayer
// These values are static and represents the total amount pipelines in the archive that we expect to replay.
uint32_t total_graphics_pipeline_blobs;
uint32_t total_compute_pipeline_blobs;
uint32_t total_raytracing_pipeline_blobs;
};

PollResult poll_progress(Progress &progress);
Expand Down
9 changes: 8 additions & 1 deletion fossilize_external_replayer_control_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static_assert(sizeof(std::atomic<uint32_t>) == sizeof(uint32_t), "Atomic size mi
namespace Fossilize
{
enum { ControlBlockMessageSize = 64 };
enum { ControlBlockMagic = 0x19bcde1b };
enum { ControlBlockMagic = 0x19bcde1c };
enum { MaxProcessStats = 256 };

struct SharedControlBlock
Expand All @@ -46,19 +46,25 @@ struct SharedControlBlock
std::atomic<uint32_t> successful_modules;
std::atomic<uint32_t> successful_graphics;
std::atomic<uint32_t> successful_compute;
std::atomic<uint32_t> successful_raytracing;
std::atomic<uint32_t> skipped_graphics;
std::atomic<uint32_t> skipped_compute;
std::atomic<uint32_t> skipped_raytracing;
std::atomic<uint32_t> cached_graphics;
std::atomic<uint32_t> cached_compute;
std::atomic<uint32_t> cached_raytracing;
std::atomic<uint32_t> clean_process_deaths;
std::atomic<uint32_t> dirty_process_deaths;
std::atomic<uint32_t> parsed_graphics;
std::atomic<uint32_t> parsed_compute;
std::atomic<uint32_t> parsed_raytracing;
std::atomic<uint32_t> parsed_graphics_failures;
std::atomic<uint32_t> parsed_compute_failures;
std::atomic<uint32_t> parsed_raytracing_failures;
std::atomic<uint32_t> parsed_module_failures;
std::atomic<uint32_t> total_graphics;
std::atomic<uint32_t> total_compute;
std::atomic<uint32_t> total_raytracing;
std::atomic<uint32_t> total_modules;
std::atomic<uint32_t> banned_modules;
std::atomic<uint32_t> module_validation_failures;
Expand All @@ -67,6 +73,7 @@ struct SharedControlBlock

std::atomic<uint32_t> static_total_count_graphics;
std::atomic<uint32_t> static_total_count_compute;
std::atomic<uint32_t> static_total_count_raytracing;

std::atomic<uint32_t> num_running_processes;
std::atomic<uint32_t> num_processes_memory_stats;
Expand Down
46 changes: 46 additions & 0 deletions fossilize_external_replayer_linux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ struct ExternalReplayer::Impl
std::unordered_set<Hash> faulty_spirv_modules;
std::vector<std::pair<unsigned, Hash>> faulty_graphics_pipelines;
std::vector<std::pair<unsigned, Hash>> faulty_compute_pipelines;
std::vector<std::pair<unsigned, Hash>> faulty_raytracing_pipelines;
std::unordered_set<Hash> graphics_failed_validation;
std::unordered_set<Hash> compute_failed_validation;
std::unordered_set<Hash> raytracing_failed_validation;

bool start(const ExternalReplayer::Options &options);
void start_replayer_process(const ExternalReplayer::Options &options, int ctl_fd);
Expand All @@ -129,8 +131,10 @@ struct ExternalReplayer::Impl
bool get_faulty_spirv_modules(size_t *count, Hash *hashes) const;
bool get_faulty_graphics_pipelines(size_t *count, unsigned *indices, Hash *hashes) const;
bool get_faulty_compute_pipelines(size_t *count, unsigned *indices, Hash *hashes) const;
bool get_faulty_raytracing_pipelines(size_t *count, unsigned *indices, Hash *hashes) const;
bool get_graphics_failed_validation(size_t *count, Hash *hashes) const;
bool get_compute_failed_validation(size_t *count, Hash *hashes) const;
bool get_raytracing_failed_validation(size_t *count, Hash *hashes) const;
bool get_failed(const std::unordered_set<Hash> &failed, size_t *count, Hash *hashes) const;
bool get_failed(const std::vector<std::pair<unsigned, Hash>> &failed, size_t *count,
unsigned *indices, Hash *hashes) const;
Expand Down Expand Up @@ -252,12 +256,21 @@ ExternalReplayer::PollResult ExternalReplayer::Impl::poll_progress(ExternalRepla
progress.compute.skipped = shm_block->skipped_compute.load(std::memory_order_relaxed);
progress.compute.cached = shm_block->cached_compute.load(std::memory_order_relaxed);
progress.compute.completed = shm_block->successful_compute.load(std::memory_order_relaxed);

progress.graphics.total = shm_block->total_graphics.load(std::memory_order_relaxed);
progress.graphics.parsed = shm_block->parsed_graphics.load(std::memory_order_relaxed);
progress.graphics.parsed_fail = shm_block->parsed_graphics_failures.load(std::memory_order_relaxed);
progress.graphics.skipped = shm_block->skipped_graphics.load(std::memory_order_relaxed);
progress.graphics.cached = shm_block->cached_graphics.load(std::memory_order_relaxed);
progress.graphics.completed = shm_block->successful_graphics.load(std::memory_order_relaxed);

progress.raytracing.total = shm_block->total_raytracing.load(std::memory_order_relaxed);
progress.raytracing.parsed = shm_block->parsed_raytracing.load(std::memory_order_relaxed);
progress.raytracing.parsed_fail = shm_block->parsed_raytracing.load(std::memory_order_relaxed);
progress.raytracing.skipped = shm_block->skipped_raytracing.load(std::memory_order_relaxed);
progress.raytracing.cached = shm_block->cached_raytracing.load(std::memory_order_relaxed);
progress.raytracing.completed = shm_block->successful_raytracing.load(std::memory_order_relaxed);

progress.completed_modules = shm_block->successful_modules.load(std::memory_order_relaxed);
progress.missing_modules = shm_block->parsed_module_failures.load(std::memory_order_relaxed);
progress.total_modules = shm_block->total_modules.load(std::memory_order_relaxed);
Expand All @@ -268,6 +281,7 @@ ExternalReplayer::PollResult ExternalReplayer::Impl::poll_progress(ExternalRepla

progress.total_graphics_pipeline_blobs = shm_block->static_total_count_graphics.load(std::memory_order_relaxed);
progress.total_compute_pipeline_blobs = shm_block->static_total_count_compute.load(std::memory_order_relaxed);
progress.total_raytracing_pipeline_blobs = shm_block->static_total_count_raytracing.load(std::memory_order_relaxed);

futex_wrapper_lock(&shm_block->futex_lock);
size_t read_avail = shared_control_block_read_avail(shm_block);
Expand Down Expand Up @@ -310,6 +324,11 @@ void ExternalReplayer::Impl::parse_message(const char *msg)
auto hash = strtoull(msg + 12, nullptr, 16);
compute_failed_validation.insert(hash);
}
else if (strncmp(msg, "RAYTRACE_VERR", 13) == 0)
{
auto hash = strtoull(msg + 13, nullptr, 16);
raytracing_failed_validation.insert(hash);
}
else if (strncmp(msg, "GRAPHICS", 8) == 0)
{
char *end = nullptr;
Expand All @@ -320,6 +339,16 @@ void ExternalReplayer::Impl::parse_message(const char *msg)
faulty_graphics_pipelines.push_back({ unsigned(index), graphics_pipeline });
}
}
else if (strncmp(msg, "RAYTRACE", 8) == 0)
{
char *end = nullptr;
int index = int(strtol(msg + 8, &end, 0));
if (index >= 0 && end)
{
Hash raytrace_pipeline = strtoull(end, nullptr, 16);
faulty_raytracing_pipelines.push_back({ unsigned(index), raytrace_pipeline });
}
}
else if (strncmp(msg, "COMPUTE", 7) == 0)
{
char *end = nullptr;
Expand Down Expand Up @@ -479,6 +508,11 @@ bool ExternalReplayer::Impl::get_faulty_compute_pipelines(size_t *count, unsigne
return get_failed(faulty_compute_pipelines, count, indices, hashes);
}

bool ExternalReplayer::Impl::get_faulty_raytracing_pipelines(size_t *count, unsigned int *indices, Hash *hashes) const
{
return get_failed(faulty_raytracing_pipelines, count, indices, hashes);
}

bool ExternalReplayer::Impl::get_graphics_failed_validation(size_t *count, Hash *hashes) const
{
return get_failed(graphics_failed_validation, count, hashes);
Expand All @@ -489,6 +523,11 @@ bool ExternalReplayer::Impl::get_compute_failed_validation(size_t *count, Hash *
return get_failed(compute_failed_validation, count, hashes);
}

bool ExternalReplayer::Impl::get_raytracing_failed_validation(size_t *count, Hash *hashes) const
{
return get_failed(raytracing_failed_validation, count, hashes);
}

void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Options &options, int ctl_fd)
{
char fd_name[16], control_fd_name[16];
Expand Down Expand Up @@ -597,6 +636,7 @@ void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Opti

char graphics_range_start[16], graphics_range_end[16];
char compute_range_start[16], compute_range_end[16];
char raytracing_range_start[16], raytracing_range_end[16];

if (options.use_pipeline_range)
{
Expand All @@ -611,6 +651,12 @@ void ExternalReplayer::Impl::start_replayer_process(const ExternalReplayer::Opti
sprintf(compute_range_end, "%u", options.end_compute_index);
argv.push_back(compute_range_start);
argv.push_back(compute_range_end);

argv.push_back("--raytracing-pipeline-range");
sprintf(raytracing_range_start, "%u", options.start_raytracing_index);
sprintf(raytracing_range_end, "%u", options.end_raytracing_index);
argv.push_back(raytracing_range_start);
argv.push_back(raytracing_range_end);
}

if (options.pipeline_stats_path)
Expand Down
44 changes: 44 additions & 0 deletions fossilize_external_replayer_windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ struct ExternalReplayer::Impl
std::unordered_set<Hash> faulty_spirv_modules;
std::vector<std::pair<unsigned, Hash>> faulty_graphics_pipelines;
std::vector<std::pair<unsigned, Hash>> faulty_compute_pipelines;
std::vector<std::pair<unsigned, Hash>> faulty_raytracing_pipelines;
std::unordered_set<Hash> graphics_failed_validation;
std::unordered_set<Hash> compute_failed_validation;
std::unordered_set<Hash> raytracing_failed_validation;

bool start(const ExternalReplayer::Options &options);
ExternalReplayer::PollResult poll_progress(Progress &progress);
Expand All @@ -66,8 +68,10 @@ struct ExternalReplayer::Impl
bool get_faulty_spirv_modules(size_t *count, Hash *hashes) const;
bool get_faulty_graphics_pipelines(size_t *count, unsigned *indices, Hash *hashes) const;
bool get_faulty_compute_pipelines(size_t *count, unsigned *indices, Hash *hashes) const;
bool get_faulty_raytracing_pipelines(size_t *count, unsigned *indices, Hash *hashes) const;
bool get_graphics_failed_validation(size_t *count, Hash *hashes) const;
bool get_compute_failed_validation(size_t *count, Hash *hashes) const;
bool get_raytracing_failed_validation(size_t *count, Hash *hashes) const;
bool get_failed(const std::unordered_set<Hash> &failed, size_t *count, Hash *hashes) const;
bool get_failed(const std::vector<std::pair<unsigned, Hash>> &failed, size_t *count,
unsigned *indices, Hash *hashes) const;
Expand Down Expand Up @@ -121,12 +125,21 @@ ExternalReplayer::PollResult ExternalReplayer::Impl::poll_progress(ExternalRepla
progress.compute.skipped = shm_block->skipped_compute.load(std::memory_order_relaxed);
progress.compute.cached = shm_block->cached_compute.load(std::memory_order_relaxed);
progress.compute.completed = shm_block->successful_compute.load(std::memory_order_relaxed);

progress.graphics.total = shm_block->total_graphics.load(std::memory_order_relaxed);
progress.graphics.parsed = shm_block->parsed_graphics.load(std::memory_order_relaxed);
progress.graphics.parsed_fail = shm_block->parsed_graphics_failures.load(std::memory_order_relaxed);
progress.graphics.skipped = shm_block->skipped_graphics.load(std::memory_order_relaxed);
progress.graphics.cached = shm_block->cached_graphics.load(std::memory_order_relaxed);
progress.graphics.completed = shm_block->successful_graphics.load(std::memory_order_relaxed);

progress.raytracing.total = shm_block->total_raytracing.load(std::memory_order_relaxed);
progress.raytracing.parsed = shm_block->parsed_raytracing.load(std::memory_order_relaxed);
progress.raytracing.parsed_fail = shm_block->parsed_raytracing.load(std::memory_order_relaxed);
progress.raytracing.skipped = shm_block->skipped_raytracing.load(std::memory_order_relaxed);
progress.raytracing.cached = shm_block->cached_raytracing.load(std::memory_order_relaxed);
progress.raytracing.completed = shm_block->successful_raytracing.load(std::memory_order_relaxed);

progress.completed_modules = shm_block->successful_modules.load(std::memory_order_relaxed);
progress.missing_modules = shm_block->parsed_module_failures.load(std::memory_order_relaxed);
progress.total_modules = shm_block->total_modules.load(std::memory_order_relaxed);
Expand All @@ -137,6 +150,7 @@ ExternalReplayer::PollResult ExternalReplayer::Impl::poll_progress(ExternalRepla

progress.total_graphics_pipeline_blobs = shm_block->static_total_count_graphics.load(std::memory_order_relaxed);
progress.total_compute_pipeline_blobs = shm_block->static_total_count_compute.load(std::memory_order_relaxed);
progress.total_raytracing_pipeline_blobs = shm_block->static_total_count_raytracing.load(std::memory_order_relaxed);

if (WaitForSingleObject(mutex, INFINITE) == WAIT_OBJECT_0)
{
Expand Down Expand Up @@ -169,6 +183,11 @@ void ExternalReplayer::Impl::parse_message(const char *msg)
auto hash = strtoull(msg + 12, nullptr, 16);
compute_failed_validation.insert(hash);
}
else if (strncmp(msg, "RAYTRACE_VERR", 13) == 0)
{
auto hash = strtoull(msg + 13, nullptr, 16);
raytracing_failed_validation.insert(hash);
}
else if (strncmp(msg, "GRAPHICS", 8) == 0)
{
char *end = nullptr;
Expand All @@ -179,6 +198,16 @@ void ExternalReplayer::Impl::parse_message(const char *msg)
faulty_graphics_pipelines.push_back({ unsigned(index), graphics_pipeline });
}
}
else if (strncmp(msg, "RAYTRACE", 8) == 0)
{
char *end = nullptr;
int index = int(strtol(msg + 8, &end, 0));
if (index >= 0 && end)
{
Hash raytrace_pipeline = strtoull(end, nullptr, 16);
faulty_raytracing_pipelines.push_back({ unsigned(index), raytrace_pipeline });
}
}
else if (strncmp(msg, "COMPUTE", 7) == 0)
{
char *end = nullptr;
Expand Down Expand Up @@ -306,6 +335,11 @@ bool ExternalReplayer::Impl::get_faulty_compute_pipelines(size_t *count, unsigne
return get_failed(faulty_compute_pipelines, count, indices, hashes);
}

bool ExternalReplayer::Impl::get_faulty_raytracing_pipelines(size_t *count, unsigned int *indices, Hash *hashes) const
{
return get_failed(faulty_raytracing_pipelines, count, indices, hashes);
}

bool ExternalReplayer::Impl::get_graphics_failed_validation(size_t *count, Hash *hashes) const
{
return get_failed(graphics_failed_validation, count, hashes);
Expand All @@ -316,6 +350,11 @@ bool ExternalReplayer::Impl::get_compute_failed_validation(size_t *count, Hash *
return get_failed(compute_failed_validation, count, hashes);
}

bool ExternalReplayer::Impl::get_raytracing_failed_validation(size_t *count, Hash *hashes) const
{
return get_failed(raytracing_failed_validation, count, hashes);
}

static char *create_modified_environment(unsigned num_environment_variables, const ExternalReplayer::Environment *environment_variables)
{
if (!num_environment_variables)
Expand Down Expand Up @@ -551,6 +590,11 @@ bool ExternalReplayer::Impl::start(const ExternalReplayer::Options &options)
cmdline += std::to_string(options.start_compute_index);
cmdline += " ";
cmdline += std::to_string(options.end_compute_index);

cmdline += " --raytracing-pipeline-range ";
cmdline += std::to_string(options.start_raytracing_index);
cmdline += " ";
cmdline += std::to_string(options.end_raytracing_index);
}

if (options.pipeline_stats_path)
Expand Down

0 comments on commit b9aedc2

Please sign in to comment.