Path: blob/master/thirdparty/glslang/SPIRV/SpvTools.h
9903 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 "spirv-tools/libspirv.h"47#endif4849#include "glslang/MachineIndependent/localintermediate.h"50#include "GlslangToSpv.h"51#include "Logger.h"5253namespace glslang {5455#if ENABLE_OPT5657// Translate glslang's view of target versioning to what SPIRV-Tools uses.58spv_target_env MapToSpirvToolsEnv(const SpvVersion& spvVersion, spv::SpvBuildLogger* logger);5960// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment.61void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv);6263// Use the SPIRV-Tools disassembler to print SPIR-V with a provided SPIR-V environment.64void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv,65spv_target_env requested_context);6667// Apply the SPIRV-Tools validator to generated SPIR-V.68void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,69spv::SpvBuildLogger*, bool prelegalization);7071// Apply the SPIRV-Tools optimizer to generated SPIR-V. HLSL SPIR-V is legalized in the process.72void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,73spv::SpvBuildLogger*, const SpvOptions*);7475// Apply the SPIRV-Tools EliminateDeadInputComponents pass to generated SPIR-V. Put result in |spirv|.76void SpirvToolsEliminateDeadInputComponents(spv_target_env target_env, std::vector<unsigned int>& spirv,77spv::SpvBuildLogger*);7879// Apply the SPIRV-Tools AnalyzeDeadOutputStores pass to generated SPIR-V. Put result in |live_locs|.80// Return true if the result is valid.81bool SpirvToolsAnalyzeDeadOutputStores(spv_target_env target_env, std::vector<unsigned int>& spirv,82std::unordered_set<uint32_t>* live_locs,83std::unordered_set<uint32_t>* live_builtins, spv::SpvBuildLogger*);8485// Apply the SPIRV-Tools EliminateDeadOutputStores and AggressiveDeadCodeElimination passes to generated SPIR-V using86// |live_locs|. Put result in |spirv|.87void SpirvToolsEliminateDeadOutputStores(spv_target_env target_env, std::vector<unsigned int>& spirv,88std::unordered_set<uint32_t>* live_locs,89std::unordered_set<uint32_t>* live_builtins, spv::SpvBuildLogger*);9091// Apply the SPIRV-Tools optimizer to strip debug info from SPIR-V. This is implicitly done by92// SpirvToolsTransform if spvOptions->stripDebugInfo is set, but can be called separately if93// optimization is disabled.94void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate,95std::vector<unsigned int>& spirv, spv::SpvBuildLogger*);9697#endif9899} // end namespace glslang100101#endif // GLSLANG_SPV_TOOLS_H102103104