Hash :
dadd1986
Author :
Date :
2020-04-21T01:50:00
Implement GL_APPLE_clip_distance - Built-in variable gl_ClipDistance has been added to compiler. - Desktop GL: gl_ClipDistance is supported since GL 3.0. Enable/Disable each gl_ClipDistances[i] works out of the box via glEnable(). - Vulkan/Metal: Use uniform variable to control writing to each gl_ClipDistance. One bit flag controls one element in the gl_ClipDistance array. The writing to the disabled element in vertex shader will be ignored, and turned into zero assignment instead. - Direct3D/Mobile GL: Not implemented yet. - Added ClipDistanceTest to gl_tests and compiler unittests. - GL_APPLE_clip_distance is a subset of GL_EXT_clip_cull_distance, so GL_EXT_clip_cull_distance could be implemented in future if needed. Bug: angleproject:4452 Change-Id: I571ac8b56826989808a680226a04bec4cf59988e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2084324 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
//
// Copyright 2017 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.
//
// IntermNode_util.cpp: High-level utilities for creating AST nodes and node hierarchies. Mostly
// meant to be used in AST transforms.
#include "compiler/translator/tree_util/IntermNode_util.h"
#include "compiler/translator/FunctionLookup.h"
#include "compiler/translator/SymbolTable.h"
namespace sh
{
namespace
{
const TFunction *LookUpBuiltInFunction(const char *name,
const TIntermSequence *arguments,
const TSymbolTable &symbolTable,
int shaderVersion)
{
const ImmutableString &mangledName = TFunctionLookup::GetMangledName(name, *arguments);
const TSymbol *symbol = symbolTable.findBuiltIn(mangledName, shaderVersion);
if (symbol)
{
ASSERT(symbol->isFunction());
return static_cast<const TFunction *>(symbol);
}
return nullptr;
}
} // anonymous namespace
TIntermFunctionPrototype *CreateInternalFunctionPrototypeNode(const TFunction &func)
{
return new TIntermFunctionPrototype(&func);
}
TIntermFunctionDefinition *CreateInternalFunctionDefinitionNode(const TFunction &func,
TIntermBlock *functionBody)
{
return new TIntermFunctionDefinition(new TIntermFunctionPrototype(&func), functionBody);
}
TIntermTyped *CreateZeroNode(const TType &type)
{
TType constType(type);
constType.setQualifier(EvqConst);
if (!type.isArray() && type.getBasicType() != EbtStruct)
{
size_t size = constType.getObjectSize();
TConstantUnion *u = new TConstantUnion[size];
for (size_t i = 0; i < size; ++i)
{
switch (type.getBasicType())
{
case EbtFloat:
u[i].setFConst(0.0f);
break;
case EbtInt:
u[i].setIConst(0);
break;
case EbtUInt:
u[i].setUConst(0u);
break;
case EbtBool:
u[i].setBConst(false);
break;
default:
// CreateZeroNode is called by ParseContext that keeps parsing even when an
// error occurs, so it is possible for CreateZeroNode to be called with
// non-basic types. This happens only on error condition but CreateZeroNode
// needs to return a value with the correct type to continue the typecheck.
// That's why we handle non-basic type by setting whatever value, we just need
// the type to be right.
u[i].setIConst(42);
break;
}
}
TIntermConstantUnion *node = new TIntermConstantUnion(u, constType);
return node;
}
TIntermSequence *arguments = new TIntermSequence();
if (type.isArray())
{
TType elementType(type);
elementType.toArrayElementType();
size_t arraySize = type.getOutermostArraySize();
for (size_t i = 0; i < arraySize; ++i)
{
arguments->push_back(CreateZeroNode(elementType));
}
}
else
{
ASSERT(type.getBasicType() == EbtStruct);
const TStructure *structure = type.getStruct();
for (const auto &field : structure->fields())
{
arguments->push_back(CreateZeroNode(*field->type()));
}
}
return TIntermAggregate::CreateConstructor(constType, arguments);
}
TIntermConstantUnion *CreateFloatNode(float value)
{
TConstantUnion *u = new TConstantUnion[1];
u[0].setFConst(value);
TType type(EbtFloat, EbpUndefined, EvqConst, 1);
return new TIntermConstantUnion(u, type);
}
TIntermConstantUnion *CreateIndexNode(int index)
{
TConstantUnion *u = new TConstantUnion[1];
u[0].setIConst(index);
TType type(EbtInt, EbpUndefined, EvqConst, 1);
return new TIntermConstantUnion(u, type);
}
TIntermConstantUnion *CreateUIntNode(unsigned int value)
{
TConstantUnion *u = new TConstantUnion[1];
u[0].setUConst(value);
TType type(EbtUInt, EbpUndefined, EvqConst, 1);
return new TIntermConstantUnion(u, type);
}
TIntermConstantUnion *CreateBoolNode(bool value)
{
TConstantUnion *u = new TConstantUnion[1];
u[0].setBConst(value);
TType type(EbtBool, EbpUndefined, EvqConst, 1);
return new TIntermConstantUnion(u, type);
}
TVariable *CreateTempVariable(TSymbolTable *symbolTable, const TType *type)
{
ASSERT(symbolTable != nullptr);
// TODO(oetuaho): Might be useful to sanitize layout qualifier etc. on the type of the created
// variable. This might need to be done in other places as well.
return new TVariable(symbolTable, kEmptyImmutableString, type, SymbolType::AngleInternal);
}
TVariable *CreateTempVariable(TSymbolTable *symbolTable, const TType *type, TQualifier qualifier)
{
ASSERT(symbolTable != nullptr);
if (type->getQualifier() == qualifier)
{
return CreateTempVariable(symbolTable, type);
}
TType *typeWithQualifier = new TType(*type);
typeWithQualifier->setQualifier(qualifier);
return CreateTempVariable(symbolTable, typeWithQualifier);
}
TIntermSymbol *CreateTempSymbolNode(const TVariable *tempVariable)
{
ASSERT(tempVariable->symbolType() == SymbolType::AngleInternal);
ASSERT(tempVariable->getType().getQualifier() == EvqTemporary ||
tempVariable->getType().getQualifier() == EvqConst ||
tempVariable->getType().getQualifier() == EvqGlobal);
return new TIntermSymbol(tempVariable);
}
TIntermDeclaration *CreateTempDeclarationNode(const TVariable *tempVariable)
{
TIntermDeclaration *tempDeclaration = new TIntermDeclaration();
tempDeclaration->appendDeclarator(CreateTempSymbolNode(tempVariable));
return tempDeclaration;
}
TIntermDeclaration *CreateTempInitDeclarationNode(const TVariable *tempVariable,
TIntermTyped *initializer)
{
ASSERT(initializer != nullptr);
TIntermSymbol *tempSymbol = CreateTempSymbolNode(tempVariable);
TIntermDeclaration *tempDeclaration = new TIntermDeclaration();
TIntermBinary *tempInit = new TIntermBinary(EOpInitialize, tempSymbol, initializer);
tempDeclaration->appendDeclarator(tempInit);
return tempDeclaration;
}
TIntermBinary *CreateTempAssignmentNode(const TVariable *tempVariable, TIntermTyped *rightNode)
{
ASSERT(rightNode != nullptr);
TIntermSymbol *tempSymbol = CreateTempSymbolNode(tempVariable);
return new TIntermBinary(EOpAssign, tempSymbol, rightNode);
}
TVariable *DeclareTempVariable(TSymbolTable *symbolTable,
const TType *type,
TQualifier qualifier,
TIntermDeclaration **declarationOut)
{
TVariable *variable = CreateTempVariable(symbolTable, type, qualifier);
*declarationOut = CreateTempDeclarationNode(variable);
return variable;
}
TVariable *DeclareTempVariable(TSymbolTable *symbolTable,
TIntermTyped *initializer,
TQualifier qualifier,
TIntermDeclaration **declarationOut)
{
TVariable *variable =
CreateTempVariable(symbolTable, new TType(initializer->getType()), qualifier);
*declarationOut = CreateTempInitDeclarationNode(variable, initializer);
return variable;
}
const TVariable *DeclareInterfaceBlock(TIntermBlock *root,
TSymbolTable *symbolTable,
TFieldList *fieldList,
TQualifier qualifier,
const TMemoryQualifier &memoryQualifier,
uint32_t arraySize,
const ImmutableString &blockTypeName,
const ImmutableString &blockVariableName)
{
// Define an interface block.
TLayoutQualifier layoutQualifier = TLayoutQualifier::Create();
TInterfaceBlock *interfaceBlock = new TInterfaceBlock(
symbolTable, blockTypeName, fieldList, layoutQualifier, SymbolType::AngleInternal);
// Turn the inteface block into a declaration.
TType *interfaceBlockType = new TType(interfaceBlock, qualifier, layoutQualifier);
interfaceBlockType->setMemoryQualifier(memoryQualifier);
if (arraySize > 0)
{
interfaceBlockType->makeArray(arraySize);
}
TIntermDeclaration *interfaceBlockDecl = new TIntermDeclaration;
TVariable *interfaceBlockVar = new TVariable(symbolTable, blockVariableName, interfaceBlockType,
SymbolType::AngleInternal);
TIntermSymbol *interfaceBlockDeclarator = new TIntermSymbol(interfaceBlockVar);
interfaceBlockDecl->appendDeclarator(interfaceBlockDeclarator);
// Insert the declarations before the first function.
TIntermSequence *insertSequence = new TIntermSequence;
insertSequence->push_back(interfaceBlockDecl);
size_t firstFunctionIndex = FindFirstFunctionDefinitionIndex(root);
root->insertChildNodes(firstFunctionIndex, *insertSequence);
return interfaceBlockVar;
}
TIntermBlock *EnsureBlock(TIntermNode *node)
{
if (node == nullptr)
return nullptr;
TIntermBlock *blockNode = node->getAsBlock();
if (blockNode != nullptr)
return blockNode;
blockNode = new TIntermBlock();
blockNode->setLine(node->getLine());
blockNode->appendStatement(node);
return blockNode;
}
TIntermSymbol *ReferenceGlobalVariable(const ImmutableString &name, const TSymbolTable &symbolTable)
{
const TVariable *var = static_cast<const TVariable *>(symbolTable.findGlobal(name));
ASSERT(var);
return new TIntermSymbol(var);
}
TIntermSymbol *ReferenceBuiltInVariable(const ImmutableString &name,
const TSymbolTable &symbolTable,
int shaderVersion)
{
const TVariable *var =
static_cast<const TVariable *>(symbolTable.findBuiltIn(name, shaderVersion));
ASSERT(var);
return new TIntermSymbol(var);
}
TIntermTyped *CreateBuiltInFunctionCallNode(const char *name,
TIntermSequence *arguments,
const TSymbolTable &symbolTable,
int shaderVersion)
{
const TFunction *fn = LookUpBuiltInFunction(name, arguments, symbolTable, shaderVersion);
ASSERT(fn);
TOperator op = fn->getBuiltInOp();
if (op != EOpCallBuiltInFunction && arguments->size() == 1)
{
return new TIntermUnary(op, arguments->at(0)->getAsTyped(), fn);
}
return TIntermAggregate::CreateBuiltInFunctionCall(*fn, arguments);
}
} // namespace sh