Commit 2aa7f3a6 by John Kessenich

SPV compression: Remove file/path manipulation stuff, setting up for that to be…

SPV compression: Remove file/path manipulation stuff, setting up for that to be a separate tool. Added copyright messages as well. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@31201 e7fa87d3-cd2b-0410-9028-fcbf551c1848
parent ccc7acc9
//
//Copyright (C) 2015 LunarG, Inc.
//
//All rights reserved.
//
//Redistribution and use in source and binary forms, with or without
//modification, are permitted provided that the following conditions
//are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//POSSIBILITY OF SUCH DAMAGE.
//
#ifndef SPIRVREMAPPER_H #ifndef SPIRVREMAPPER_H
#define SPIRVREMAPPER_H #define SPIRVREMAPPER_H
...@@ -34,16 +68,6 @@ public: ...@@ -34,16 +68,6 @@ public:
ALL_BUT_STRIP = (MAP_ALL | DCE_ALL | OPT_ALL), ALL_BUT_STRIP = (MAP_ALL | DCE_ALL | OPT_ALL),
DO_EVERYTHING = (STRIP | ALL_BUT_STRIP) DO_EVERYTHING = (STRIP | ALL_BUT_STRIP)
}; };
// OS dependent path separator (avoiding boost::filesystem dependency)
#if defined(_WIN32)
static const char path_sep_char() { return '\\'; }
#else
static const char path_sep_char() { return '/'; }
#endif
// Poor man's basename, to avoid external dependencies
static const std::string basename(const std::string& filename);
}; };
} // namespace SPV } // namespace SPV
...@@ -52,7 +76,6 @@ public: ...@@ -52,7 +76,6 @@ public:
#include <stdio.h> #include <stdio.h>
namespace spv { namespace spv {
class spirvbin_t : public spirvbin_base_t class spirvbin_t : public spirvbin_base_t
{ {
public: public:
...@@ -62,11 +85,6 @@ public: ...@@ -62,11 +85,6 @@ public:
{ {
printf("Tool not compiled for C++11, which is required for SPIR-V remapping.\n"); printf("Tool not compiled for C++11, which is required for SPIR-V remapping.\n");
} }
void remap(const std::string& filename, const std::string& outputDir, unsigned int opts = 0)
{
printf("Tool not compiled for C++11, which is required for SPIR-V remapping.\n");
}
}; };
} // namespace SPV } // namespace SPV
...@@ -95,10 +113,6 @@ public: ...@@ -95,10 +113,6 @@ public:
// remap on an existing binary in memory // remap on an existing binary in memory
void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = Options::DO_EVERYTHING); void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = Options::DO_EVERYTHING);
// load binary from disk file, and remap that.
void remap(const std::string& filename, const std::string& outputDir,
std::uint32_t opts = Options::DO_EVERYTHING);
// Type for error/log handler functions // Type for error/log handler functions
typedef std::function<void(const std::string&)> errorfn_t; typedef std::function<void(const std::string&)> errorfn_t;
typedef std::function<void(const std::string&)> logfn_t; typedef std::function<void(const std::string&)> logfn_t;
...@@ -112,14 +126,10 @@ protected: ...@@ -112,14 +126,10 @@ protected:
virtual void msg(int minVerbosity, int indent, const std::string& txt) const; virtual void msg(int minVerbosity, int indent, const std::string& txt) const;
private: private:
// write SPV to given directory using filename passed to remap(filename...)
void write(const std::string& outputDir) const;
// Local to global, or global to local ID map // Local to global, or global to local ID map
typedef std::unordered_map<spv::Id, spv::Id> idmap_t; typedef std::unordered_map<spv::Id, spv::Id> idmap_t;
typedef std::unordered_set<spv::Id> idset_t; typedef std::unordered_set<spv::Id> idset_t;
void read(const std::string& filename); // read SPV from disk file
void remap(std::uint32_t opts = Options::DO_EVERYTHING); void remap(std::uint32_t opts = Options::DO_EVERYTHING);
// Map of names to IDs // Map of names to IDs
...@@ -148,10 +158,6 @@ private: ...@@ -148,10 +158,6 @@ private:
// handle error // handle error
void error(const std::string& txt) const { errorHandler(txt); } void error(const std::string& txt) const { errorHandler(txt); }
// handle error with our filename appended to the string
void ferror(const std::string& txt) const {
error(std::string("\nERROR processing file ") + filename + ":\n" + txt);
}
bool isConstOp(spv::Op opCode) const; bool isConstOp(spv::Op opCode) const;
bool isTypeOp(spv::Op opCode) const; bool isTypeOp(spv::Op opCode) const;
...@@ -229,7 +235,6 @@ private: ...@@ -229,7 +235,6 @@ private:
void strip(); // remove debug symbols void strip(); // remove debug symbols
std::vector<spirword_t> spv; // SPIR words std::vector<spirword_t> spv; // SPIR words
std::string filename; // the file this came from
namemap_t nameMap; // ID names from OpName namemap_t nameMap; // ID names from OpName
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include "../SPIRV/GLSL450Lib.h" #include "../SPIRV/GLSL450Lib.h"
#include "../SPIRV/doc.h" #include "../SPIRV/doc.h"
#include "../SPIRV/disassemble.h" #include "../SPIRV/disassemble.h"
#include "../SPIRV/SPVRemapper.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
...@@ -72,8 +71,6 @@ enum TOptions { ...@@ -72,8 +71,6 @@ enum TOptions {
EOptionSpv = 0x0800, EOptionSpv = 0x0800,
EOptionHumanReadableSpv = 0x1000, EOptionHumanReadableSpv = 0x1000,
EOptionDefaultDesktop = 0x2000, EOptionDefaultDesktop = 0x2000,
EOptionCanonicalizeSpv = 0x4000,
EOptionStripSpv = 0x8000,
}; };
// //
...@@ -484,17 +481,11 @@ bool ProcessArguments(int argc, char* argv[]) ...@@ -484,17 +481,11 @@ bool ProcessArguments(int argc, char* argv[])
for (; argc >= 1; argc--, argv++) { for (; argc >= 1; argc--, argv++) {
Work[argc] = 0; Work[argc] = 0;
if (argv[0][0] == '-') { if (argv[0][0] == '-') {
const char optLetter = argv[0][1]; switch (argv[0][1]) {
case 'H':
switch (optLetter) { Options |= EOptionHumanReadableSpv;
case 'S': // fall through to -V // fall through to -V
case 'C': // fall through to -V
case 'H': // fall through to -V
case 'V': case 'V':
if (optLetter == 'H') Options |= EOptionHumanReadableSpv;
if (optLetter == 'S') Options |= EOptionStripSpv;
if (optLetter == 'C') Options |= EOptionCanonicalizeSpv;
Options |= EOptionSpv; Options |= EOptionSpv;
Options |= EOptionLinkProgram; Options |= EOptionLinkProgram;
break; break;
...@@ -669,17 +660,7 @@ void CompileAndLinkShaders() ...@@ -669,17 +660,7 @@ void CompileAndLinkShaders()
case EShLangCompute: name = "comp"; break; case EShLangCompute: name = "comp"; break;
default: name = "unknown"; break; default: name = "unknown"; break;
} }
if (Options & (EOptionCanonicalizeSpv | EOptionStripSpv)) {
const unsigned int remapOpts =
((Options & EOptionCanonicalizeSpv) ? (spv::spirvbin_t::ALL_BUT_STRIP) : 0) |
((Options & EOptionStripSpv) ? (spv::spirvbin_t::STRIP) : 0);
spv::Parameterize();
spv::spirvbin_t().remap(spirv, remapOpts);
}
glslang::OutputSpv(spirv, name); glslang::OutputSpv(spirv, name);
if (Options & EOptionHumanReadableSpv) { if (Options & EOptionHumanReadableSpv) {
spv::Parameterize(); spv::Parameterize();
GLSL_STD_450::GetDebugNames(GlslStd450DebugNames); GLSL_STD_450::GetDebugNames(GlslStd450DebugNames);
...@@ -886,8 +867,6 @@ void usage() ...@@ -886,8 +867,6 @@ void usage()
"To get other information, use one of the following options:\n" "To get other information, use one of the following options:\n"
"(Each option must be specified separately, but can go anywhere in the command line.)\n" "(Each option must be specified separately, but can go anywhere in the command line.)\n"
" -V create SPIR-V in file <stage>.spv\n" " -V create SPIR-V in file <stage>.spv\n"
" -C canonicalize generated SPIR-V: turns on -V\n"
" -S debug-strip SPIR-V: turns on -V\n"
" -H print human readable form of SPIR-V; turns on -V\n" " -H print human readable form of SPIR-V; turns on -V\n"
" -c configuration dump; use to create default configuration file (redirect to a .conf file)\n" " -c configuration dump; use to create default configuration file (redirect to a .conf file)\n"
" -d default to desktop (#version 110) when there is no version in the shader (default is ES version 100)\n" " -d default to desktop (#version 110) when there is no version in the shader (default is ES version 100)\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment