Path: blob/master/thirdparty/glslang/SPIRV/spvUtil.h
21733 views
//1// Copyright (C) 2025 Jan Kelemen2//3// All rights reserved.4//5// Redistribution and use in source and binary forms, with or without6// modification, are permitted provided that the following conditions7// are met:8//9// Redistributions of source code must retain the above copyright10// notice, this list of conditions and the following disclaimer.11//12// Redistributions in binary form must reproduce the above13// copyright notice, this list of conditions and the following14// disclaimer in the documentation and/or other materials provided15// with the distribution.16//17// Neither the name of 3Dlabs Inc. Ltd. nor the names of its18// contributors may be used to endorse or promote products derived19// from this software without specific prior written permission.20//21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS22// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT23// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS24// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE25// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,26// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,27// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;28// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER29// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN31// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE32// POSSIBILITY OF SUCH DAMAGE.33//34#pragma once35#ifndef spvUtil_H36#define spvUtil_H3738#include <cstdint>39#include <type_traits>4041#include "spirv.hpp11"4243namespace spv {44__inline uint32_t operator&(uint32_t value, spv::MemoryAccessMask mask) { return value & (unsigned)mask; }4546__inline bool operator==(uint32_t word, spv::FPEncoding encoding) { return word == (unsigned)encoding; }47__inline bool operator!=(uint32_t word, spv::FPEncoding encoding) { return !(word == encoding); }4849__inline bool operator==(uint32_t word, spv::Decoration decoration) { return word == (unsigned)decoration; }50__inline bool operator!=(uint32_t word, spv::Decoration decoration) { return !(word == decoration); }5152__inline bool operator==(uint32_t word, spv::Op op) { return word == (unsigned)op; }53__inline bool operator!=(uint32_t word, spv::Op op) { return !(word == op); }5455__inline bool operator==(uint32_t word, spv::StorageClass storage) { return word == (unsigned)storage; }56__inline bool operator!=(uint32_t word, spv::StorageClass storage) { return !(word == storage); }5758__inline bool anySet(spv::MemoryAccessMask value, spv::MemoryAccessMask mask)59{60return (value & mask) != spv::MemoryAccessMask::MaskNone;61}6263__inline bool anySet(spv::ImageOperandsMask value, spv::ImageOperandsMask mask)64{65return (value & mask) != spv::ImageOperandsMask::MaskNone;66}6768__inline bool anySet(spv::MemorySemanticsMask value, spv::MemorySemanticsMask mask)69{70return (value & mask) != spv::MemorySemanticsMask::MaskNone;71}7273__inline void addMask(uint32_t& word, spv::TensorAddressingOperandsMask mask) { word |= (unsigned)mask; }7475__inline void addMask(spv::CooperativeMatrixOperandsMask& word, spv::CooperativeMatrixOperandsMask mask)76{77word = word | mask;78}7980template<typename Enum, typename To = std::underlying_type_t<Enum>>81__inline To enumCast(Enum value)82{83return static_cast<To>(value);84}85}8687#endif // spvUtil_H888990