aboutsummaryrefslogtreecommitdiff
path: root/src/cast_hash.h
diff options
context:
space:
mode:
authordan sinclair <dj2@everburning.com>2018-09-28 16:12:38 -0400
committerDavid Neto <dneto@google.com>2018-11-09 13:47:51 -0500
commit70d430c0fb3dd7832265815cde48866fada1eb3b (patch)
tree3e85912ed7eb1b30edb183c8d91b413fb421cf2a /src/cast_hash.h
downloadamber-70d430c0fb3dd7832265815cde48866fada1eb3b.tar.gz
Initial commit of Amber for open source
Amber is a multi-API shader test framework. Amber lets you capture and communicate shader bugs with the fluidity and ease of a scripting flow: * No graphics API programming is required. * WIP: Supports Vulkan and [Dawn][Dawn] graphics APIs. * A single text string (or file) maps to a single graphics API pipeline test case. The text includes: * Input data, including buffers and images. * Shaders. * Expectations for the result of running the pipeline. * Shaders can be expressed in binary form (as hex), in SPIR-V assembly, or in a higher level shader language. * After executing the pipeline, result buffers and images can be saved to output files. This is not an officially supported Google product.
Diffstat (limited to 'src/cast_hash.h')
-rw-r--r--src/cast_hash.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/cast_hash.h b/src/cast_hash.h
new file mode 100644
index 0000000..c7afbf0
--- /dev/null
+++ b/src/cast_hash.h
@@ -0,0 +1,33 @@
+// Copyright 2018 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 SRC_CAST_HASH_H_
+#define SRC_CAST_HASH_H_
+
+namespace amber {
+
+// A hash implementation for types that can trivially be up-cast to a size_t.
+// For example, use this as a hasher for an enum whose underlying type is
+// an integer no wider than size_t.
+//
+// The need for this was a defect in the C++11 library, and has been fixed
+// in C++14. http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148
+template <typename T>
+struct CastHash {
+ size_t operator()(const T& value) const { return static_cast<size_t>(value); }
+};
+
+} // namespace amber
+
+#endif // SRC_CAST_HASH_H_