blob: 2bc433fb2db7c2154e209cd54cd64dc8d901c84e [file] [log] [blame]
* GLSLToSPIRVConverter.h
* Copyright (c) 2014-2019 The Brenwill Workshop Ltd. (
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
#ifndef __GLSLToSPIRVConverter_h_
#define __GLSLToSPIRVConverter_h_ 1
#include "GLSLConversion.h"
#include <string>
#include <vector>
namespace mvk {
#pragma mark -
#pragma mark GLSLToSPIRVConverter
/** Converts GLSL code to SPIR-V code. */
class GLSLToSPIRVConverter {
/** Sets the GLSL source code that is to be converted to the specified string. */
void setGLSL(const std::string& glslSrc) { _glsl = glslSrc; }
* Sets the GLSL source code that is to be converted from the first length characters
* of the buffer, and ensuring the resulting string is null-terminated.
void setGLSL(const char* glslSrc, size_t length) { _glsl.assign(glslSrc, length); }
/** Returns the GLSL source code that was set using the setGLSL() function. */
const std::string& getGLSL() { return _glsl; }
/** Returns whether the SPIR-V code has been set. */
bool hasGLSL() { return !_glsl.empty(); }
* Converts GLSL code, set with setGLSL(), to SPIR-V code, which can be retrieved using getSPIRV().
* The boolean flags indicate whether the original GLSL code and resulting SPIR-V code should
* be logged to the result log of this converter. This can be useful during shader debugging.
bool convert(MVKGLSLConversionShaderStage shaderStage, bool shouldLogGLSL, bool shouldLogSPIRV);
* Returns whether the most recent conversion was successful.
* The initial value of this property is NO. It is set to YES upon successful conversion.
bool wasConverted() { return _wasConverted; }
/** Returns the SPIRV code most recently converted by the convert() function. */
const std::vector<uint32_t>& getSPIRV() { return _spirv; }
* Returns a human-readable log of the most recent conversion activity.
* This may be empty if the conversion was successful.
const std::string& getResultLog() { return _resultLog; }
void logMsg(const char* logMsg);
bool logError(const char* errMsg);
void logGLSL(const char* opDesc);
void logSPIRV(const char* opDesc);
bool validateSPIRV();
void initGLSLCompilerResources();
std::string _glsl;
std::vector<uint32_t> _spirv;
std::string _resultLog;
bool _wasConverted = false;