aboutsummaryrefslogtreecommitdiff
path: root/layers/shader_checker.cpp
diff options
context:
space:
mode:
authorChris Forbes <chrisforbes@google.com>2015-11-24 11:13:29 +1300
committerMark Lobodzinski <mark@lunarg.com>2015-11-26 13:56:36 -0700
commitddfc92598f491f069e89c7e53dc55b580640b210 (patch)
treedb3da29bef0596be8d4a770477109773cdd9e1ff /layers/shader_checker.cpp
parent4fa8629a758d4fc8cb1c6398a3fdbc6ef38c475c (diff)
downloadusermoji-ddfc92598f491f069e89c7e53dc55b580640b210.tar.xz
layers/SC: LX187: compute size of array and matrix types
This fixes spurious warnings previously emitted by SC when using larger-than-vec4 types across the VI->VS interface.
Diffstat (limited to 'layers/shader_checker.cpp')
-rw-r--r--layers/shader_checker.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/layers/shader_checker.cpp b/layers/shader_checker.cpp
index 7bd5d265..617eac6b 100644
--- a/layers/shader_checker.cpp
+++ b/layers/shader_checker.cpp
@@ -477,11 +477,30 @@ value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id,
static unsigned
get_locations_consumed_by_type(shader_module const *src, unsigned type)
{
- /* Returns the number of vec4 locations consumed by a variable of type `type`
- * appearing on a shader interface.
- */
- /* TODO: implement this properly */
- return 1;
+ auto type_def_it = src->type_def_index.find(type);
+
+ if (type_def_it == src->type_def_index.end()) {
+ return 1; /* This is actually broken SPIR-V... */
+ }
+
+ unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
+ unsigned opcode = code[0] & 0x0ffffu;
+ switch (opcode) {
+ case spv::OpTypePointer:
+ /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
+ * we're never actually passing pointers around. */
+ return get_locations_consumed_by_type(src, code[3]);
+ case spv::OpTypeArray:
+ case spv::OpTypeMatrix:
+ /* num locations is the array dimension * element size */
+ return code[3] * get_locations_consumed_by_type(src, code[2]);
+ default:
+ /* everything else is just 1. */
+ return 1;
+
+ /* TODO: extend to handle 64bit scalar types, whose vectors may need
+ * multiple locations. */
+ }
}