aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorJaebaek Seo <duke.acacia@gmail.com>2019-02-19 23:29:08 +0900
committerdan sinclair <dj2@everburning.com>2019-02-19 09:29:08 -0500
commitb3a778d1a66f34025878576b0be5e6a5c18c8b94 (patch)
tree13338d962c0fdf4c7bbcc16614bab51f3b9a10af /samples
parent146a323c493ef0ec5705b66724f2a3636a4f1748 (diff)
downloadamber-b3a778d1a66f34025878576b0be5e6a5c18c8b94.tar.gz
Vulkan: support buffer dump (#269)
This CL adds support to dump the contents of compute buffers to a file. Fixes #36
Diffstat (limited to 'samples')
-rw-r--r--samples/amber.cc48
1 files changed, 35 insertions, 13 deletions
diff --git a/samples/amber.cc b/samples/amber.cc
index 6b5ceac..a1f0481 100644
--- a/samples/amber.cc
+++ b/samples/amber.cc
@@ -15,6 +15,7 @@
#include <cassert>
#include <cstdlib>
#include <fstream>
+#include <iomanip>
#include <iostream>
#include <set>
#include <utility>
@@ -34,7 +35,7 @@ struct Options {
std::string image_filename;
std::string buffer_filename;
- int64_t buffer_binding_index = 0;
+ std::vector<amber::BufferInfo> buffer_to_dump;
uint32_t engine_major = 1;
uint32_t engine_minor = 0;
bool parse_only = false;
@@ -55,7 +56,8 @@ const char kUsage[] = R"(Usage: amber [options] SCRIPT [SCRIPTS...]
-t <spirv_env> -- The target SPIR-V environment. Defaults to SPV_ENV_UNIVERSAL_1_0.
-i <filename> -- Write rendering to <filename> as a PPM image.
-b <filename> -- Write contents of a UBO or SSBO to <filename>.
- -B <buffer> -- Index of buffer to write. Defaults buffer 0.
+ -B [<desc set>:]<binding> -- Descriptor set and binding of buffer to write.
+ Default is [0:]0.
-e <engine> -- Specify graphics engine: vulkan, dawn. Default is vulkan.
-v <engine version> -- Engine version (eg, 1.1 for Vulkan). Default 1.0.
-V, --version -- Output version information for Amber and libraries.
@@ -87,14 +89,8 @@ bool ParseArgs(const std::vector<std::string>& args, Options* opts) {
std::cerr << "Missing value for -B argument." << std::endl;
return false;
}
- opts->buffer_binding_index =
- static_cast<int64_t>(strtol(args[i].c_str(), nullptr, 10));
-
- if (opts->buffer_binding_index < 0U) {
- std::cerr << "Invalid value for -B, must be 0 or greater." << std::endl;
- return false;
- }
-
+ opts->buffer_to_dump.emplace_back();
+ opts->buffer_to_dump.back().buffer_name = args[i];
} else if (arg == "-e") {
++i;
if (i >= args.size()) {
@@ -297,9 +293,10 @@ int main(int argc, const char** argv) {
amber_options.config = config.get();
- if (!options.buffer_filename.empty()) {
- // TODO(dsinclair): Write buffer file
- assert(false);
+ if (!options.buffer_filename.empty() && !options.buffer_to_dump.empty()) {
+ amber_options.extractions.insert(amber_options.extractions.end(),
+ options.buffer_to_dump.begin(),
+ options.buffer_to_dump.end());
}
if (!options.image_filename.empty()) {
@@ -343,6 +340,31 @@ int main(int argc, const char** argv) {
image_file << image;
image_file.close();
}
+
+ if (!options.buffer_filename.empty()) {
+ std::ofstream buffer_file;
+ buffer_file.open(options.buffer_filename, std::ios::out);
+ if (!buffer_file.is_open()) {
+ std::cerr << "Cannot open file for buffer dump: ";
+ std::cerr << options.buffer_filename << std::endl;
+ } else {
+ for (amber::BufferInfo buffer_info : amber_options.extractions) {
+ if (buffer_info.buffer_name == "framebuffer")
+ continue;
+
+ buffer_file << buffer_info.buffer_name << std::endl;
+ const auto& values = buffer_info.values;
+ for (size_t i = 0; i < values.size(); ++i) {
+ buffer_file << " " << std::setfill('0') << std::setw(2) << std::hex
+ << values[i].AsUint32();
+ if (i % 16 == 15)
+ buffer_file << std::endl;
+ }
+ buffer_file << std::endl;
+ }
+ buffer_file.close();
+ }
+ }
}
if (options.show_summary) {