1 // Copyright (c) 2015-2016 The Khronos Group Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a 4 // copy of this software and/or associated documentation files (the 5 // "Materials"), to deal in the Materials without restriction, including 6 // without limitation the rights to use, copy, modify, merge, publish, 7 // distribute, sublicense, and/or sell copies of the Materials, and to 8 // permit persons to whom the Materials are furnished to do so, subject to 9 // the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included 12 // in all copies or substantial portions of the Materials. 13 // 14 // MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS 15 // KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS 16 // SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT 17 // https://www.khronos.org/registry/ 18 // 19 // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 // MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 26 27 #ifndef LIBSPIRV_SPIRV_DEFINITION_H_ 28 #define LIBSPIRV_SPIRV_DEFINITION_H_ 29 30 #include <cstdint> 31 32 #include "spirv-tools/libspirv.h" 33 34 #define spvIsInBitfield(value, bitfield) ((value) == ((value)&bitfield)) 35 36 // A bit mask representing a set of capabilities. 37 // Currently there are 60 distinct capabilities, so 64 bits 38 // should be enough. 39 typedef uint64_t spv_capability_mask_t; 40 41 // Transforms spv::Capability into a mask for use in bitfields. Should really 42 // be a constexpr inline function, but some important versions of MSVC don't 43 // support that yet. Different from SPV_BIT, which doesn't guarantee 64-bit 44 // values. 45 #define SPV_CAPABILITY_AS_MASK(capability) \ 46 (spv_capability_mask_t(1) << (capability)) 47 48 // Applies f to every capability present in a mask. 49 namespace libspirv { 50 template <typename Functor> 51 inline void ForEach(spv_capability_mask_t capabilities, Functor f) { 52 for (int c = 0; capabilities; ++c, capabilities >>= 1) 53 if (capabilities & 1) f(static_cast<SpvCapability>(c)); 54 } 55 } // end namespace libspirv 56 57 typedef struct spv_header_t { 58 uint32_t magic; 59 uint32_t version; 60 uint32_t generator; 61 uint32_t bound; 62 uint32_t schema; // NOTE: Reserved 63 const uint32_t* instructions; // NOTE: Unfixed pointer to instruciton stream 64 } spv_header_t; 65 66 #endif // LIBSPIRV_SPIRV_DEFINITION_H_ 67