Path: blob/master/thirdparty/glslang/SPIRV/SpvTools.h
21731 views
//1// Copyright (C) 2014-2016 LunarG, Inc.2// Copyright (C) 2018 Google, Inc.3//4// All rights reserved.5//6// Redistribution and use in source and binary forms, with or without7// modification, are permitted provided that the following conditions8// are met:9//10// Redistributions of source code must retain the above copyright11// notice, this list of conditions and the following disclaimer.12//13// Redistributions in binary form must reproduce the above14// copyright notice, this list of conditions and the following15// disclaimer in the documentation and/or other materials provided16// with the distribution.17//18// Neither the name of 3Dlabs Inc. Ltd. nor the names of its19// contributors may be used to endorse or promote products derived20// from this software without specific prior written permission.21//22// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS23// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT24// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS25// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE26// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,27// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,28// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;29// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER30// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN32// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE33// POSSIBILITY OF SUCH DAMAGE.3435//36// Call into SPIRV-Tools to disassemble, validate, and optimize.37//3839#pragma once40#ifndef GLSLANG_SPV_TOOLS_H41#define GLSLANG_SPV_TOOLS_H4243#if ENABLE_OPT44#include <vector>45#include <ostream>46#include <unordered_set>47#include "spirv-tools/libspirv.h"48#endif4950#include "glslang/MachineIndependent/Versions.h"51#include "glslang/Include/visibility.h"52#include "GlslangToSpv.h"53#include "Logger.h"5455namespace glslang {5657#if ENABLE_OPT5859class TIntermediate;6061// Translate glslang's view of target versioning to what SPIRV-Tools uses.62GLSLANG_EXPORT spv_target_env MapToSpirvToolsEnv(const SpvVersion& spvVersion, spv::SpvBuildLogger* logger);63GLSLANG_EXPORT spv_target_env MapToSpirvToolsEnv(const glslang::TIntermediate& intermediate, spv::SpvBuildLogger* logger);6465// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment.66GLSLANG_EXPORT void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv);6768// Use the SPIRV-Tools disassembler to print SPIR-V with a provided SPIR-V environment.69GLSLANG_EXPORT void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv,70spv_target_env requested_context);7172// Apply the SPIRV-Tools validator to generated SPIR-V.73GLSLANG_EXPORT void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,74spv::SpvBuildLogger*, bool prelegalization);7576// Apply the SPIRV-Tools optimizer to generated SPIR-V. HLSL SPIR-V is legalized in the process.77GLSLANG_EXPORT void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,78spv::SpvBuildLogger*, const SpvOptions*);7980// Apply the SPIRV-Tools EliminateDeadInputComponents pass to generated SPIR-V. Put result in |spirv|.81GLSLANG_EXPORT void SpirvToolsEliminateDeadInputComponents(spv_target_env target_env, std::vector<unsigned int>& spirv,82spv::SpvBuildLogger*);8384// Apply the SPIRV-Tools AnalyzeDeadOutputStores pass to generated SPIR-V. Put result in |live_locs|.85// Return true if the result is valid.86GLSLANG_EXPORT bool SpirvToolsAnalyzeDeadOutputStores(spv_target_env target_env, std::vector<unsigned int>& spirv,87std::unordered_set<uint32_t>* live_locs,88std::unordered_set<uint32_t>* live_builtins,89spv::SpvBuildLogger*);9091// Apply the SPIRV-Tools EliminateDeadOutputStores and AggressiveDeadCodeElimination passes to generated SPIR-V using92// |live_locs|. Put result in |spirv|.93GLSLANG_EXPORT void SpirvToolsEliminateDeadOutputStores(spv_target_env target_env, std::vector<unsigned int>& spirv,94std::unordered_set<uint32_t>* live_locs,95std::unordered_set<uint32_t>* live_builtins,96spv::SpvBuildLogger*);9798// Apply the SPIRV-Tools optimizer to strip debug info from SPIR-V. This is implicitly done by99// SpirvToolsTransform if spvOptions->stripDebugInfo is set, but can be called separately if100// optimization is disabled.101GLSLANG_EXPORT void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate,102std::vector<unsigned int>& spirv, spv::SpvBuildLogger*);103104#endif105106} // end namespace glslang107108#endif // GLSLANG_SPV_TOOLS_H109110111