aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Android.mk1
-rw-r--r--DEPS5
-rw-r--r--samples/Android.mk5
-rw-r--r--samples/CMakeLists.txt3
-rw-r--r--samples/amber.cc16
-rw-r--r--samples/png.cc76
-rw-r--r--samples/png.h36
-rw-r--r--samples/ppm.h2
-rw-r--r--third_party/Android.mk9
-rw-r--r--third_party/CMakeLists.txt389
11 files changed, 356 insertions, 187 deletions
diff --git a/.gitignore b/.gitignore
index 8aa284b..c81c3cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@ out
third_party/cpplint
third_party/glslang
third_party/googletest
+third_party/lodepng
third_party/shaderc
third_party/spirv-tools
third_party/spirv-headers
diff --git a/Android.mk b/Android.mk
index 3a3d5f5..eb31818 100644
--- a/Android.mk
+++ b/Android.mk
@@ -17,6 +17,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:=amber
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti \
+ -Wno-unknown-pragmas \
-DAMBER_ENABLE_SPIRV_TOOLS=1 \
-DAMBER_ENABLE_SHADERC=1 \
-DAMBER_ENGINE_VULKAN=1
diff --git a/DEPS b/DEPS
index e89bfe4..097c94f 100644
--- a/DEPS
+++ b/DEPS
@@ -3,10 +3,12 @@ use_relative_paths = True
vars = {
'google_git': 'https://github.com/google',
'khronos_git': 'https://github.com/KhronosGroup',
+ 'lvandeve_git': 'https://github.com/lvandeve',
'cpplint_revision': '9f41862c0efa7681e2147910d39629c73a2b2702',
'glslang_revision': 'f44b17ee135d5e153ce000e88b806b5377812b11',
'googletest_revision': 'd5932506d6eed73ac80b9bcc47ed723c8c74eb1e',
+ 'lodepng_revision': 'ba9fc1f084f03b5fbf8c9a5df9448173f27544b1',
'shaderc_revision': '53c776f776821bc037b31b8b3b79db2fa54b4ce7',
'spirv_headers_revision': '8bea0a266ac9b718aa0818d9e3a47c0b77c2cb23',
'spirv_tools_revision': '39bfb6b978e937487a9cedfd964d61a3ac4384b8',
@@ -22,6 +24,9 @@ deps = {
'third_party/glslang': vars['khronos_git'] + '/glslang.git@' +
vars['glslang_revision'],
+ 'third_party/lodepng': vars['lvandeve_git'] + '/lodepng.git@' +
+ vars['lodepng_revision'],
+
'third_party/shaderc': vars['google_git'] + '/shaderc.git@' +
vars['shaderc_revision'],
diff --git a/samples/Android.mk b/samples/Android.mk
index 9d8033e..06f5fe9 100644
--- a/samples/Android.mk
+++ b/samples/Android.mk
@@ -22,11 +22,12 @@ LOCAL_SRC_FILES:= \
config_helper.cc \
config_helper_vulkan.cc \
log.cc \
- ppm.cc
+ ppm.cc \
+ png.cc
LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. $(LOCAL_PATH)/../include
LOCAL_LDLIBS:=-landroid -lvulkan -llog
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -Werror -Wno-unknown-pragmas -DAMBER_ENGINE_VULKAN=1
-LOCAL_STATIC_LIBRARIES:=amber
+LOCAL_STATIC_LIBRARIES:=amber lodepng
include $(BUILD_EXECUTABLE)
include $(LOCAL_PATH)/../Android.mk
diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt
index c71291a..77e1da7 100644
--- a/samples/CMakeLists.txt
+++ b/samples/CMakeLists.txt
@@ -19,10 +19,11 @@ set(AMBER_SOURCES
config_helper.cc
log.cc
ppm.cc
+ png.cc
${CMAKE_BINARY_DIR}/src/build-versions.h.fake
)
-set(AMBER_EXTRA_LIBS "")
+set(AMBER_EXTRA_LIBS "lodepng")
if (${Vulkan_FOUND})
set(AMBER_SOURCES ${AMBER_SOURCES} config_helper_vulkan.cc)
diff --git a/samples/amber.cc b/samples/amber.cc
index 33fcf70..012f273 100644
--- a/samples/amber.cc
+++ b/samples/amber.cc
@@ -24,6 +24,7 @@
#include "amber/amber.h"
#include "amber/recipe.h"
#include "samples/config_helper.h"
+#include "samples/png.h"
#include "samples/ppm.h"
#include "src/build-versions.h"
#include "src/make_unique.h"
@@ -56,7 +57,7 @@ const char kUsage[] = R"(Usage: amber [options] SCRIPT [SCRIPTS...]
-s -- Print summary of pass/failure.
-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 PPM image.
+ -i <filename> -- Write rendering to <filename> as a PNG image if it ends with '.png', or as a PPM image otherwise.
-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.
@@ -330,10 +331,19 @@ int main(int argc, const char** argv) {
if (!options.image_filename.empty()) {
std::string image;
+
+ auto pos = options.image_filename.find_last_of('.');
+ bool usePNG = pos != std::string::npos &&
+ options.image_filename.substr(pos + 1) == "png";
for (amber::BufferInfo buffer_info : amber_options.extractions) {
if (buffer_info.buffer_name == "framebuffer") {
- std::tie(result, image) = ppm::ConvertToPPM(
- buffer_info.width, buffer_info.height, buffer_info.values);
+ if (usePNG) {
+ std::tie(result, image) = png::ConvertToPNG(
+ buffer_info.width, buffer_info.height, buffer_info.values);
+ } else {
+ std::tie(result, image) = ppm::ConvertToPPM(
+ buffer_info.width, buffer_info.height, buffer_info.values);
+ }
break;
}
}
diff --git a/samples/png.cc b/samples/png.cc
new file mode 100644
index 0000000..79c6983
--- /dev/null
+++ b/samples/png.cc
@@ -0,0 +1,76 @@
+// Copyright 2019 The Amber Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "samples/png.h"
+
+#include <cassert>
+
+#include "amber/result.h"
+#include "amber/value.h"
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wweak-vtables"
+#include "third_party/lodepng/lodepng.h"
+#pragma clang diagnostic pop
+
+namespace png {
+
+namespace {
+
+unsigned char byte0(uint32_t word) {
+ return static_cast<unsigned char>(word);
+}
+
+unsigned char byte1(uint32_t word) {
+ return static_cast<unsigned char>(word >> 8);
+}
+
+unsigned char byte2(uint32_t word) {
+ return static_cast<unsigned char>(word >> 16);
+}
+
+unsigned char byte3(uint32_t word) {
+ return static_cast<unsigned char>(word >> 24);
+}
+
+} // namespace
+
+std::pair<amber::Result, std::string> ConvertToPNG(
+ uint32_t width,
+ uint32_t height,
+ const std::vector<amber::Value>& values) {
+ assert(values.size() == width * height);
+
+ std::vector<unsigned char> data;
+
+ // Prepare data as lodepng expects it
+ for (amber::Value value : values) {
+ const uint32_t pixel = value.AsUint32();
+ data.push_back(byte2(pixel)); // R
+ data.push_back(byte1(pixel)); // G
+ data.push_back(byte0(pixel)); // B
+ data.push_back(byte3(pixel)); // A
+ }
+
+ std::vector<unsigned char> png;
+ unsigned error = lodepng::encode(png, data, width, height);
+ if (error) {
+ return std::make_pair(amber::Result("lodepng::encode() returned non-zero"),
+ nullptr);
+ }
+
+ return std::make_pair(amber::Result(), std::string(png.begin(), png.end()));
+}
+
+} // namespace png
diff --git a/samples/png.h b/samples/png.h
new file mode 100644
index 0000000..2008e9e
--- /dev/null
+++ b/samples/png.h
@@ -0,0 +1,36 @@
+// Copyright 2019 The Amber Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SAMPLES_PNG_H_
+#define SAMPLES_PNG_H_
+
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "amber/amber.h"
+
+namespace png {
+
+/// Converts the image of dimensions |width| and |height| and with pixels stored
+/// in row-major order in |values| with format B8G8R8A8 into PNG format,
+/// returning the PNG binary as a string.
+std::pair<amber::Result, std::string> ConvertToPNG(
+ uint32_t width,
+ uint32_t height,
+ const std::vector<amber::Value>& values);
+
+} // namespace png
+
+#endif // SAMPLES_PNG_H_
diff --git a/samples/ppm.h b/samples/ppm.h
index 0eb1f8e..9b237f3 100644
--- a/samples/ppm.h
+++ b/samples/ppm.h
@@ -24,7 +24,7 @@
namespace ppm {
/// Converts the image of dimensions |width| and |height| and with pixels stored
-/// in row-major order in |values| with format R8G8B8A8 into PPM format,
+/// in row-major order in |values| with format B8G8R8A8 into PPM format,
/// returning the PPM binary as a string.
std::pair<amber::Result, std::string> ConvertToPPM(
uint32_t width,
diff --git a/third_party/Android.mk b/third_party/Android.mk
index c490378..ac00d05 100644
--- a/third_party/Android.mk
+++ b/third_party/Android.mk
@@ -1,5 +1,14 @@
THIRD_PARTY_PATH := $(call my-dir)
+LOCAL_PATH := $(call my-dir)
+
+# Lodepng
+include $(CLEAR_VARS)
+LOCAL_MODULE:=lodepng
+LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti
+LOCAL_SRC_FILES:= lodepng/lodepng.cpp
+include $(BUILD_STATIC_LIBRARY)
+
ifeq ($(GLSLANG_LOCAL_PATH),)
GLSLANG_LOCAL_PATH:=$(THIRD_PARTY_PATH)/glslang
endif
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index 12dbffb..6e29dde 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -15,118 +15,132 @@
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Turn off warnings to make gtest happy
set(GTEST_BUILD_FIXES
- -Wno-covered-switch-default
- -Wno-deprecated
- -Wno-disabled-macro-expansion
- -Wno-exit-time-constructors
- -Wno-exit-time-destructors
- -Wno-extra-semi-stmt
- -Wno-global-constructors
- -Wno-missing-field-initializers
- -Wno-format-nonliteral
- -Wno-missing-noreturn
- -Wno-missing-prototypes
- -Wno-missing-variable-declarations
- -Wno-shift-sign-overflow
- -Wno-sign-conversion
- -Wno-undef
- -Wno-unused-member-function
- -Wno-used-but-marked-unused
- -Wno-weak-vtables
- -Wno-zero-as-null-pointer-constant)
+ -Wno-covered-switch-default
+ -Wno-deprecated
+ -Wno-disabled-macro-expansion
+ -Wno-exit-time-constructors
+ -Wno-exit-time-destructors
+ -Wno-extra-semi-stmt
+ -Wno-global-constructors
+ -Wno-missing-field-initializers
+ -Wno-format-nonliteral
+ -Wno-missing-noreturn
+ -Wno-missing-prototypes
+ -Wno-missing-variable-declarations
+ -Wno-shift-sign-overflow
+ -Wno-sign-conversion
+ -Wno-undef
+ -Wno-unused-member-function
+ -Wno-used-but-marked-unused
+ -Wno-weak-vtables
+ -Wno-zero-as-null-pointer-constant)
set(GLSLANG_BUILD_FIXES
- -Wno-conversion
- -Wno-covered-switch-default
- -Wno-date-time
- -Wno-deprecated
- -Wno-disabled-macro-expansion
- -Wno-double-promotion
- -Wno-error
- -Wno-exit-time-destructors
- -Wno-extra-semi
- -Wno-extra-semi-stmt
- -Wno-float-equal
- -Wno-format-nonliteral
- -Wno-format-pedantic
- -Wno-global-constructors
- -Wno-gnu-redeclared-enum
- -Wno-implicit-fallthrough
- -Wno-inconsistent-missing-destructor-override
- -Wno-missing-field-initializers
- -Wno-missing-noreturn
- -Wno-missing-prototypes
- -Wno-missing-variable-declarations
- -Wno-newline-eof
- -Wno-old-style-cast
- -Wno-reserved-id-macro
- -Wno-shadow
- -Wno-shadow-field
- -Wno-shadow-field-in-constructor
- -Wno-shift-sign-overflow
- -Wno-sign-conversion
- -Wno-signed-enum-bitfield
- -Wno-undef
- -Wno-undefined-func-template
- -Wno-undefined-reinterpret-cast
- -Wno-unreachable-code
- -Wno-unreachable-code-break
- -Wno-unreachable-code-return
- -Wno-unused-macros
- -Wno-unused-parameter
- -Wno-unused-variable
- -Wno-used-but-marked-unused
- -Wno-weak-vtables
- -Wno-zero-as-null-pointer-constant)
+ -Wno-conversion
+ -Wno-covered-switch-default
+ -Wno-date-time
+ -Wno-deprecated
+ -Wno-disabled-macro-expansion
+ -Wno-double-promotion
+ -Wno-error
+ -Wno-exit-time-destructors
+ -Wno-extra-semi
+ -Wno-extra-semi-stmt
+ -Wno-float-equal
+ -Wno-format-nonliteral
+ -Wno-format-pedantic
+ -Wno-global-constructors
+ -Wno-gnu-redeclared-enum
+ -Wno-implicit-fallthrough
+ -Wno-inconsistent-missing-destructor-override
+ -Wno-missing-field-initializers
+ -Wno-missing-noreturn
+ -Wno-missing-prototypes
+ -Wno-missing-variable-declarations
+ -Wno-newline-eof
+ -Wno-old-style-cast
+ -Wno-reserved-id-macro
+ -Wno-shadow
+ -Wno-shadow-field
+ -Wno-shadow-field-in-constructor
+ -Wno-shift-sign-overflow
+ -Wno-sign-conversion
+ -Wno-signed-enum-bitfield
+ -Wno-undef
+ -Wno-undefined-func-template
+ -Wno-undefined-reinterpret-cast
+ -Wno-unreachable-code
+ -Wno-unreachable-code-break
+ -Wno-unreachable-code-return
+ -Wno-unused-macros
+ -Wno-unused-parameter
+ -Wno-unused-variable
+ -Wno-used-but-marked-unused
+ -Wno-weak-vtables
+ -Wno-zero-as-null-pointer-constant)
+
+ set(LODEPNG_BUILD_FIXES
+ -Wno-cast-qual
+ -Wno-conversion
+ -Wno-covered-switch-default
+ -Wno-deprecated
+ -Wno-extra-semi-stmt
+ -Wno-implicit-int-conversion
+ -Wno-missing-prototypes
+ -Wno-old-style-cast
+ -Wno-shorten-64-to-32
+ -Wno-weak-vtables
+ -Wno-zero-as-null-pointer-constant)
set(SPIRV_TOOLS_BUILD_FIXES
- -Wno-conditional-uninitialized
- -Wno-covered-switch-default
- -Wno-deprecated
- -Wno-documentation
- -Wno-documentation-pedantic
- -Wno-double-promotion
- -Wno-extra-semi
- -Wno-extra-semi-stmt
- -Wno-float-equal
- -Wno-format-nonliteral
- -Wno-implicit-fallthrough
- -Wno-missing-prototypes
- -Wno-old-style-cast
- -Wno-range-loop-analysis
- -Wno-shift-sign-overflow
- -Wno-unreachable-code-break
- -Wno-unreachable-code-return
- -Wno-unused-member-function
- -Wno-weak-vtables
- -Wno-zero-as-null-pointer-constant)
+ -Wno-conditional-uninitialized
+ -Wno-covered-switch-default
+ -Wno-deprecated
+ -Wno-documentation
+ -Wno-documentation-pedantic
+ -Wno-double-promotion
+ -Wno-extra-semi
+ -Wno-extra-semi-stmt
+ -Wno-float-equal
+ -Wno-format-nonliteral
+ -Wno-implicit-fallthrough
+ -Wno-missing-prototypes
+ -Wno-old-style-cast
+ -Wno-range-loop-analysis
+ -Wno-shift-sign-overflow
+ -Wno-unreachable-code-break
+ -Wno-unreachable-code-return
+ -Wno-unused-member-function
+ -Wno-weak-vtables
+ -Wno-zero-as-null-pointer-constant)
set(SHADERC_BUILD_FIXES
- -Wno-comma
- -Wno-conversion
- -Wno-covered-switch
- -Wno-covered-switch-default
- -Wno-deprecated
- -Wno-disabled-macro-expansion
- -Wno-double-promotion
- -Wno-extra-semi
- -Wno-float-equal
- -Wno-global-constructors
- -Wno-inconsistent-missing-destructor-override
- -Wno-missing-field-initializers
- -Wno-missing-prototypes
- -Wno-newline-eof
- -Wno-old-style-cast
- -Wno-reserved-id-macro
- -Wno-shadow
- -Wno-shadow-uncaptured-local
- -Wno-shadow-field-in-constructor
- -Wno-sign-conversion
- -Wno-signed-enum-bitfield
- -Wno-undef
- -Wno-unreachable-code-return
- -Wno-weak-vtables
- -Wno-zero-as-null-pointer-constant
+ -Wno-comma
+ -Wno-conversion
+ -Wno-covered-switch
+ -Wno-covered-switch-default
+ -Wno-deprecated
+ -Wno-disabled-macro-expansion
+ -Wno-double-promotion
+ -Wno-extra-semi
+ -Wno-float-equal
+ -Wno-global-constructors
+ -Wno-inconsistent-missing-destructor-override
+ -Wno-missing-field-initializers
+ -Wno-missing-prototypes
+ -Wno-newline-eof
+ -Wno-old-style-cast
+ -Wno-reserved-id-macro
+ -Wno-shadow
+ -Wno-shadow-field
+ -Wno-shadow-field-in-constructor
+ -Wno-shadow-uncaptured-local
+ -Wno-sign-conversion
+ -Wno-signed-enum-bitfield
+ -Wno-undef
+ -Wno-unreachable-code-return
+ -Wno-weak-vtables
+ -Wno-zero-as-null-pointer-constant
)
endif()
@@ -134,14 +148,16 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(GTEST_BUILD_FIXES "")
set(GLSLANG_BUILD_FIXES
- -Wno-error
- -Wno-implicit-fallthrough
- -Wno-overflow
- -Wno-missing-field-initializers
- -Wno-pedantic
- -Wno-strict-aliasing
- -Wno-unused-parameter
- -Wno-unused-variable)
+ -Wno-error
+ -Wno-implicit-fallthrough
+ -Wno-overflow
+ -Wno-missing-field-initializers
+ -Wno-pedantic
+ -Wno-strict-aliasing
+ -Wno-unused-parameter
+ -Wno-unused-variable)
+
+ set(LODEPNG_BUILD_FIXES "")
set(SPIRV_TOOLS_BUILD_FIXES "")
@@ -152,78 +168,78 @@ endif()
if (MSVC)
set(GTEST_BUILD_FIXES
- /W3
- /wd4061
- /wd4365
- /wd4514
- /wd4571
- /wd4623
- /wd4625
- /wd4626
- /wd4668
- /wd4710
- /wd4774
- /wd4820
- /wd5026
- /wd5027
- /wd5039
- /wd5045
- )
+ /W3
+ /wd4061
+ /wd4365
+ /wd4514
+ /wd4571
+ /wd4623
+ /wd4625
+ /wd4626
+ /wd4668
+ /wd4710
+ /wd4774
+ /wd4820
+ /wd5026
+ /wd5027
+ /wd5039
+ /wd5045)
set(GLSLANG_BUILD_FIXES
- /W3
- /wd4242
- /wd4244
- /wd4571
- /wd4623
- /wd4625
- /wd4626
- /wd4702
- /wd4774
- /wd4820
- /wd4946
- /wd4996
- /wd5026
- /wd5027
- /wd5045
- )
+ /W3
+ /wd4242
+ /wd4244
+ /wd4571
+ /wd4623
+ /wd4625
+ /wd4626
+ /wd4702
+ /wd4774
+ /wd4820
+ /wd4946
+ /wd4996
+ /wd5026
+ /wd5027
+ /wd5045)
+
+ set(LODEPNG_BUILD_FIXES
+ /W3
+ /wd4267)
set(SPIRV_TOOLS_BUILD_FIXES
/W3
- /wd4365
- /wd4389
- /wd4571
- /wd4623
- /wd4625
- /wd4626
- /wd4702
- /wd4706
- /wd4710
- /wd4774
- /wd4820
- /wd4826
- /wd4868
- /wd5026
- /wd5027
- /wd5045
- )
+ /wd4365
+ /wd4389
+ /wd4571
+ /wd4623
+ /wd4625
+ /wd4626
+ /wd4702
+ /wd4706
+ /wd4710
+ /wd4774
+ /wd4820
+ /wd4826
+ /wd4868
+ /wd5026
+ /wd5027
+ /wd5045)
-set(SHADERC_BUILD_FIXES
- /W3
- /wd4365
- /wd4571
- /wd4623
- /wd4625
- /wd4626
- /wd4702
- /wd4774
- /wd4820
- /wd4996
- /wd5026
- /wd5027
- /wd5039
- /wd5045
- )
+ set(SHADERC_BUILD_FIXES
+ /W3
+ /wd4365
+ /wd4571
+ /wd4623
+ /wd4625
+ /wd4626
+ /wd4702
+ /wd4774
+ /wd4820
+ /wd4996
+ /wd5026
+ /wd5027
+ /wd5039
+ /wd5045)
endif()
if (${AMBER_ENABLE_TESTS})
@@ -268,3 +284,16 @@ if (${AMBER_ENABLE_SHADERC})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/shaderc)
set(CMAKE_CXX_FLAGS ${CXX_BACK})
endif()
+
+if (${AMBER_ENABLE_SAMPLES})
+ # Lodepng
+ set(LODEPNG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lodepng/lodepng.cpp)
+ STRING(REGEX REPLACE ";" " " LODEPNG_BUILD_FIXES "${LODEPNG_BUILD_FIXES}")
+
+ set_source_files_properties(
+ ${LODEPNG_SOURCES}
+ PROPERTIES
+ COMPILE_FLAGS "${LODEPNG_BUILD_FIXES}")
+
+ add_library(lodepng STATIC ${LODEPNG_SOURCES})
+endif()