diff options
author | dan sinclair <dsinclair@google.com> | 2019-05-13 13:17:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-13 13:17:46 -0400 |
commit | 7991d429236d41d4701788a633452e62e755a05f (patch) | |
tree | 19cc6eee62b67e1ed410592b8bd9483fd765ce96 | |
parent | 0bb996460399eeced77a63cf9875c5708864de12 (diff) | |
download | amber-7991d429236d41d4701788a633452e62e755a05f.tar.gz |
Allow setting name of framebuffer to extract. (#507)
Currently the framebuffer must be named 'framebuffer' for the image
extraction to work correctly. This CL adds a -I option to the sample app
and changes the BufferInfo structure to record if it is an image that is
being extracted.
Fixes #505
-rw-r--r-- | include/amber/amber.h | 2 | ||||
-rw-r--r-- | samples/amber.cc | 17 | ||||
-rw-r--r-- | src/amber.cc | 4 |
3 files changed, 18 insertions, 5 deletions
diff --git a/include/amber/amber.h b/include/amber/amber.h index 6360f37..2b14475 100644 --- a/include/amber/amber.h +++ b/include/amber/amber.h @@ -51,6 +51,8 @@ struct BufferInfo { BufferInfo& operator=(const BufferInfo&); + /// Determines if this is an image buffer. + bool is_image_buffer; /// Holds the buffer name std::string buffer_name; /// Holds the buffer width diff --git a/samples/amber.cc b/samples/amber.cc index 48e6771..8d185d0 100644 --- a/samples/amber.cc +++ b/samples/amber.cc @@ -40,6 +40,7 @@ struct Options { std::string image_filename; std::string buffer_filename; + std::string fb_name = kGeneratedColorBuffer; std::vector<amber::BufferInfo> buffer_to_dump; uint32_t engine_major = 1; uint32_t engine_minor = 0; @@ -65,6 +66,7 @@ const char kUsage[] = R"(Usage: amber [options] SCRIPT [SCRIPTS...] -d -- Disable validation layers. -t <spirv_env> -- The target SPIR-V environment. Defaults to SPV_ENV_UNIVERSAL_1_0. -i <filename> -- Write rendering to <filename> as a PNG image if it ends with '.png', or as a PPM image otherwise. + -I <buffername> -- Name of framebuffer to dump. Defaults to 'framebuffer'. -b <filename> -- Write contents of a UBO or SSBO to <filename>. -B [<desc set>:]<binding> -- Descriptor set and binding of buffer to write. Default is [0:]0. @@ -88,6 +90,14 @@ bool ParseArgs(const std::vector<std::string>& args, Options* opts) { } opts->image_filename = args[i]; + } else if (arg == "-I") { + ++i; + if (i >= args.size()) { + std::cerr << "Missing value for -I argument." << std::endl; + return false; + } + opts->fb_name = args[i]; + } else if (arg == "-b") { ++i; if (i >= args.size()) { @@ -386,7 +396,8 @@ int main(int argc, const char** argv) { if (!options.image_filename.empty()) { amber::BufferInfo buffer_info; - buffer_info.buffer_name = kGeneratedColorBuffer; + buffer_info.buffer_name = options.fb_name; + buffer_info.is_image_buffer = true; amber_options.extractions.push_back(buffer_info); } @@ -410,7 +421,7 @@ int main(int argc, const char** argv) { bool usePNG = pos != std::string::npos && options.image_filename.substr(pos + 1) == "png"; for (const amber::BufferInfo& buffer_info : amber_options.extractions) { - if (buffer_info.buffer_name == kGeneratedColorBuffer) { + if (buffer_info.buffer_name == options.fb_name) { if (usePNG) { result = png::ConvertToPNG(buffer_info.width, buffer_info.height, buffer_info.values, &out_buf); @@ -446,7 +457,7 @@ int main(int argc, const char** argv) { std::cerr << options.buffer_filename << std::endl; } else { for (const amber::BufferInfo& buffer_info : amber_options.extractions) { - if (buffer_info.buffer_name == kGeneratedColorBuffer) + if (buffer_info.buffer_name == options.fb_name) continue; buffer_file << buffer_info.buffer_name << std::endl; diff --git a/src/amber.cc b/src/amber.cc index b8f41d2..183ebac 100644 --- a/src/amber.cc +++ b/src/amber.cc @@ -72,7 +72,7 @@ Options::Options() Options::~Options() = default; -BufferInfo::BufferInfo() : width(0), height(0) {} +BufferInfo::BufferInfo() : is_image_buffer(false), width(0), height(0) {} BufferInfo::BufferInfo(const BufferInfo&) = default; @@ -189,7 +189,7 @@ amber::Result Amber::ExecuteWithShaderData(const amber::Recipe* recipe, // extractor fails before running the pipeline that will trigger the dumps // to almost always fail. for (BufferInfo& buffer_info : opts->extractions) { - if (buffer_info.buffer_name == Pipeline::kGeneratedColorBuffer) { + if (buffer_info.is_image_buffer) { auto* buffer = script->GetBuffer(buffer_info.buffer_name); if (!buffer) break; |