Hash :
abe96578
Author :
Date :
2020-11-30T14:09:11
Vulkan: I/O blocks: Support unsized arrays Geometry shader inputs have an extra array dimension, which can be unsized as it can be derived from the primitive type. This change fixes the grammar to support such arrays. Additionally, it enables EXT_shader_io_blocks automatically with EXT_geometry_shader and EXT_tessellation_shader per spec. Bug: angleproject:3580 Change-Id: Ia7eb3e8be28c2eef2072dbe2a546fa34973104ab Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2568242 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Mohan Maiya <m.maiya@samsung.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
//
// Copyright 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/translator/DirectiveHandler.h"
#include <sstream>
#include "angle_gl.h"
#include "common/debug.h"
#include "compiler/translator/Common.h"
#include "compiler/translator/Diagnostics.h"
namespace sh
{
static TBehavior getBehavior(const std::string &str)
{
const char kRequire[] = "require";
const char kEnable[] = "enable";
const char kDisable[] = "disable";
const char kWarn[] = "warn";
if (str == kRequire)
return EBhRequire;
else if (str == kEnable)
return EBhEnable;
else if (str == kDisable)
return EBhDisable;
else if (str == kWarn)
return EBhWarn;
return EBhUndefined;
}
TDirectiveHandler::TDirectiveHandler(TExtensionBehavior &extBehavior,
TDiagnostics &diagnostics,
int &shaderVersion,
sh::GLenum shaderType,
bool debugShaderPrecisionSupported)
: mExtensionBehavior(extBehavior),
mDiagnostics(diagnostics),
mShaderVersion(shaderVersion),
mShaderType(shaderType),
mDebugShaderPrecisionSupported(debugShaderPrecisionSupported)
{}
TDirectiveHandler::~TDirectiveHandler() {}
void TDirectiveHandler::handleError(const angle::pp::SourceLocation &loc, const std::string &msg)
{
mDiagnostics.error(loc, msg.c_str(), "");
}
void TDirectiveHandler::handlePragma(const angle::pp::SourceLocation &loc,
const std::string &name,
const std::string &value,
bool stdgl)
{
if (stdgl)
{
const char kInvariant[] = "invariant";
const char kAll[] = "all";
if (name == kInvariant && value == kAll)
{
if (mShaderVersion == 300 && mShaderType == GL_FRAGMENT_SHADER)
{
// ESSL 3.00.4 section 4.6.1
mDiagnostics.error(
loc, "#pragma STDGL invariant(all) can not be used in fragment shader",
name.c_str());
}
mPragma.stdgl.invariantAll = true;
}
// The STDGL pragma is used to reserve pragmas for use by future
// revisions of GLSL. Do not generate an error on unexpected
// name and value.
return;
}
else
{
const char kOptimize[] = "optimize";
const char kDebug[] = "debug";
const char kDebugShaderPrecision[] = "webgl_debug_shader_precision";
const char kOn[] = "on";
const char kOff[] = "off";
bool invalidValue = false;
if (name == kOptimize)
{
if (value == kOn)
mPragma.optimize = true;
else if (value == kOff)
mPragma.optimize = false;
else
invalidValue = true;
}
else if (name == kDebug)
{
if (value == kOn)
mPragma.debug = true;
else if (value == kOff)
mPragma.debug = false;
else
invalidValue = true;
}
else if (name == kDebugShaderPrecision && mDebugShaderPrecisionSupported)
{
if (value == kOn)
mPragma.debugShaderPrecision = true;
else if (value == kOff)
mPragma.debugShaderPrecision = false;
else
invalidValue = true;
}
else
{
mDiagnostics.report(angle::pp::Diagnostics::PP_UNRECOGNIZED_PRAGMA, loc, name);
return;
}
if (invalidValue)
{
mDiagnostics.error(loc, "invalid pragma value - 'on' or 'off' expected", value.c_str());
}
}
}
void TDirectiveHandler::handleExtension(const angle::pp::SourceLocation &loc,
const std::string &name,
const std::string &behavior)
{
const char kExtAll[] = "all";
TBehavior behaviorVal = getBehavior(behavior);
if (behaviorVal == EBhUndefined)
{
mDiagnostics.error(loc, "behavior invalid", name.c_str());
return;
}
if (name == kExtAll)
{
if (behaviorVal == EBhRequire)
{
mDiagnostics.error(loc, "extension cannot have 'require' behavior", name.c_str());
}
else if (behaviorVal == EBhEnable)
{
mDiagnostics.error(loc, "extension cannot have 'enable' behavior", name.c_str());
}
else
{
for (TExtensionBehavior::iterator iter = mExtensionBehavior.begin();
iter != mExtensionBehavior.end(); ++iter)
iter->second = behaviorVal;
}
return;
}
TExtensionBehavior::iterator iter = mExtensionBehavior.find(GetExtensionByName(name.c_str()));
if (iter != mExtensionBehavior.end())
{
iter->second = behaviorVal;
// OVR_multiview is implicitly enabled when OVR_multiview2 is enabled
if (name == "GL_OVR_multiview2")
{
constexpr char kMultiviewExtName[] = "GL_OVR_multiview";
iter = mExtensionBehavior.find(GetExtensionByName(kMultiviewExtName));
if (iter != mExtensionBehavior.end())
{
iter->second = behaviorVal;
}
}
// EXT_shader_io_blocks is implicitly enabled when EXT_geometry_shader or
// EXT_tessellation_shader is enabled.
if (name == "GL_EXT_geometry_shader" || name == "GL_EXT_tessellation_shader")
{
constexpr char kIOBlocksExtName[] = "GL_EXT_shader_io_blocks";
iter = mExtensionBehavior.find(GetExtensionByName(kIOBlocksExtName));
if (iter != mExtensionBehavior.end())
{
iter->second = behaviorVal;
}
}
return;
}
switch (behaviorVal)
{
case EBhRequire:
mDiagnostics.error(loc, "extension is not supported", name.c_str());
break;
case EBhEnable:
case EBhWarn:
case EBhDisable:
mDiagnostics.warning(loc, "extension is not supported", name.c_str());
break;
default:
UNREACHABLE();
break;
}
}
void TDirectiveHandler::handleVersion(const angle::pp::SourceLocation &loc,
int version,
ShShaderSpec spec)
{
if (((version == 100 || version == 300 || version == 310 || version == 320) &&
!IsDesktopGLSpec(spec)) ||
IsDesktopGLSpec(spec))
{
mShaderVersion = version;
}
else
{
std::stringstream stream = sh::InitializeStream<std::stringstream>();
stream << version;
std::string str = stream.str();
mDiagnostics.error(loc, "client/version number not supported", str.c_str());
}
}
} // namespace sh