Commit d1434c04 by Jamie Madill Committed by Commit Bot

Revert "Use ImmutableString for HLSL texture references"

This reverts commit c13bda86. Reason for revert: May have broken LibFuzzer and AFL builds: https://ci.chromium.org/buildbot/chromium.fyi/Afl%20Upload%20Linux%20ASan/7718 https://build.chromium.org/deprecated/chromium.fyi/builders/Libfuzzer%20Upload%20Linux%20ASan/builds/8691 In file included from ../../third_party/angle/src/compiler/translator/TextureFunctionHLSL.cpp:12: In file included from ../../third_party/angle/src/compiler/translator/TextureFunctionHLSL.h:19: ../../third_party/angle/src/compiler/translator/InfoSink.h:40:16: error: call to function 'operator<<' that is neither visible in the template definition nor found by argument-dependent lookup stream << t; ^ ../../third_party/angle/src/compiler/translator/TextureFunctionHLSL.cpp:111:9: note: in instantiation of function template specialization 'sh::TInfoSinkBase::operator<<<sh::ImmutableString>' requested here out << textureReference; ^ ../../third_party/angle/src/compiler/translator/ImmutableString.h:76:15: note: 'operator<<' should be declared prior to the call site or in namespace 'sh' std::ostream &operator<<(std::ostream &os, const sh::ImmutableString &str); ^ 1 error generated. Bug: chromium:806619 Original change's description: > Use ImmutableString for HLSL texture references > > This also adds ImmutableStringBuilder class, which can be used to > build ImmutableStrings in place without extra allocations if the > maximum length is known in advance. > > BUG=angleproject:2267 > TEST=angle_unittests > > Change-Id: I4dfb78adeb0cffcfad0d25753fb8063466012c92 > Reviewed-on: https://chromium-review.googlesource.com/886362 > Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> > Reviewed-by: Jamie Madill <jmadill@chromium.org> TBR=jmadill@chromium.org,cwallez@chromium.org,oetuaho@nvidia.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: angleproject:2267 Change-Id: I445f5a786f8b16c3f40f28df09d45fcb215a9c88 Reviewed-on: https://chromium-review.googlesource.com/890542Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent e7624004
...@@ -71,10 +71,7 @@ ...@@ -71,10 +71,7 @@
'compiler/translator/FoldExpressions.h', 'compiler/translator/FoldExpressions.h',
'compiler/translator/HashNames.cpp', 'compiler/translator/HashNames.cpp',
'compiler/translator/HashNames.h', 'compiler/translator/HashNames.h',
'compiler/translator/ImmutableString.cpp',
'compiler/translator/ImmutableString.h', 'compiler/translator/ImmutableString.h',
'compiler/translator/ImmutableStringBuilder.cpp',
'compiler/translator/ImmutableStringBuilder.h',
'compiler/translator/InfoSink.cpp', 'compiler/translator/InfoSink.cpp',
'compiler/translator/InfoSink.h', 'compiler/translator/InfoSink.h',
'compiler/translator/Initialize.cpp', 'compiler/translator/Initialize.cpp',
......
//
// Copyright (c) 2018 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.
//
// ImmutableString.cpp: Wrapper for static or pool allocated char arrays, that are guaranteed to be
// valid and unchanged for the duration of the compilation.
//
#include "compiler/translator/ImmutableString.h"
std::ostream &operator<<(std::ostream &os, const sh::ImmutableString &str)
{
return os.write(str.data(), str.length());
}
...@@ -45,13 +45,10 @@ class ImmutableString ...@@ -45,13 +45,10 @@ class ImmutableString
{ {
} }
constexpr ImmutableString(const char *data, size_t length) : mData(data), mLength(length) {}
ImmutableString(const ImmutableString &) = default; ImmutableString(const ImmutableString &) = default;
ImmutableString &operator=(const ImmutableString &) = default; ImmutableString &operator=(const ImmutableString &) = default;
const char *data() const { return mData ? mData : ""; } const char *data() const { return mData ? mData : ""; }
size_t length() const { return mLength; }
bool operator<(const ImmutableString &b) const bool operator<(const ImmutableString &b) const
{ {
...@@ -67,12 +64,10 @@ class ImmutableString ...@@ -67,12 +64,10 @@ class ImmutableString
} }
private: private:
const char *mData; const char *const mData;
size_t mLength; const size_t mLength;
}; };
} // namespace sh } // namespace sh
std::ostream &operator<<(std::ostream &os, const sh::ImmutableString &str);
#endif // COMPILER_TRANSLATOR_IMMUTABLESTRING_H_ #endif // COMPILER_TRANSLATOR_IMMUTABLESTRING_H_
//
// Copyright (c) 2018 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.
//
// ImmutableStringBuilder.cpp: Stringstream-like utility for building pool allocated strings where
// the maximum length is known in advance.
//
#include "compiler/translator/ImmutableStringBuilder.h"
namespace sh
{
ImmutableStringBuilder &ImmutableStringBuilder::operator<<(const ImmutableString &str)
{
ASSERT(mData != nullptr);
ASSERT(mPos + str.length() <= mMaxLength);
memcpy(mData + mPos, str.data(), str.length());
mPos += str.length();
return *this;
}
ImmutableStringBuilder &ImmutableStringBuilder::operator<<(const char *str)
{
ASSERT(mData != nullptr);
size_t len = strlen(str);
ASSERT(mPos + len <= mMaxLength);
memcpy(mData + mPos, str, len);
mPos += len;
return *this;
}
ImmutableStringBuilder &ImmutableStringBuilder::operator<<(const char &c)
{
ASSERT(mData != nullptr);
ASSERT(mPos + 1 <= mMaxLength);
mData[mPos++] = c;
return *this;
}
ImmutableStringBuilder::operator ImmutableString()
{
mData[mPos] = '\0';
ImmutableString str(static_cast<const char *>(mData), mPos);
#if defined(ANGLE_ENABLE_ASSERTS)
// Make sure that nothing is added to the string after it is finalized.
mData = nullptr;
#endif
return str;
}
} // namespace sh
//
// Copyright (c) 2018 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.
//
// ImmutableStringBuilder.h: Stringstream-like utility for building pool allocated strings where the
// maximum length is known in advance.
//
#ifndef COMPILER_TRANSLATOR_IMMUTABLESTRINGBUILDER_H_
#define COMPILER_TRANSLATOR_IMMUTABLESTRINGBUILDER_H_
#include "compiler/translator/ImmutableString.h"
namespace sh
{
class ImmutableStringBuilder
{
public:
ImmutableStringBuilder(size_t maxLength)
: mPos(0u), mMaxLength(maxLength), mData(AllocateEmptyPoolCharArray(maxLength))
{
}
ImmutableStringBuilder &operator<<(const ImmutableString &str);
ImmutableStringBuilder &operator<<(const char *str);
ImmutableStringBuilder &operator<<(const char &c);
// This invalidates the ImmutableStringBuilder, so it should only be called once.
operator ImmutableString();
private:
inline static char *AllocateEmptyPoolCharArray(size_t strLength)
{
size_t requiredSize = strLength + 1u;
return reinterpret_cast<char *>(GetGlobalPoolAllocator()->allocate(requiredSize));
}
size_t mPos;
size_t mMaxLength;
char *mData;
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_IMMUTABLESTRINGBUILDER_H_
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "compiler/translator/TextureFunctionHLSL.h" #include "compiler/translator/TextureFunctionHLSL.h"
#include "compiler/translator/ImmutableStringBuilder.h"
#include "compiler/translator/UtilsHLSL.h" #include "compiler/translator/UtilsHLSL.h"
namespace sh namespace sh
...@@ -105,8 +104,8 @@ void OutputIntTexCoordWraps(TInfoSinkBase &out, ...@@ -105,8 +104,8 @@ void OutputIntTexCoordWraps(TInfoSinkBase &out,
void OutputHLSL4SampleFunctionPrefix(TInfoSinkBase &out, void OutputHLSL4SampleFunctionPrefix(TInfoSinkBase &out,
const TextureFunctionHLSL::TextureFunction &textureFunction, const TextureFunctionHLSL::TextureFunction &textureFunction,
const ImmutableString &textureReference, const TString &textureReference,
const ImmutableString &samplerReference) const TString &samplerReference)
{ {
out << textureReference; out << textureReference;
if (IsIntegerSampler(textureFunction.sampler) || if (IsIntegerSampler(textureFunction.sampler) ||
...@@ -451,56 +450,37 @@ void OutputTextureFunctionArgumentList(TInfoSinkBase &out, ...@@ -451,56 +450,37 @@ void OutputTextureFunctionArgumentList(TInfoSinkBase &out,
void GetTextureReference(TInfoSinkBase &out, void GetTextureReference(TInfoSinkBase &out,
const TextureFunctionHLSL::TextureFunction &textureFunction, const TextureFunctionHLSL::TextureFunction &textureFunction,
const ShShaderOutput outputType, const ShShaderOutput outputType,
ImmutableString *textureReference, TString *textureReference,
ImmutableString *samplerReference) TString *samplerReference)
{ {
if (outputType == SH_HLSL_4_1_OUTPUT) if (outputType == SH_HLSL_4_1_OUTPUT)
{ {
static const ImmutableString kTexturesStr("textures"); TString suffix = TextureGroupSuffix(textureFunction.sampler);
static const ImmutableString kSamplersStr("samplers");
static const ImmutableString kSamplerIndexStr("[samplerIndex]");
static const ImmutableString kTextureIndexStr("[textureIndex]");
static const ImmutableString kSamplerArrayIndexStr("[samplerArrayIndex]");
ImmutableString suffix(TextureGroupSuffix(textureFunction.sampler));
if (TextureGroup(textureFunction.sampler) == HLSL_TEXTURE_2D) if (TextureGroup(textureFunction.sampler) == HLSL_TEXTURE_2D)
{ {
ImmutableStringBuilder textureRefBuilder(kTexturesStr.length() + suffix.length() + *textureReference = TString("textures") + suffix + "[samplerIndex]";
kSamplerIndexStr.length()); *samplerReference = TString("samplers") + suffix + "[samplerIndex]";
textureRefBuilder << kTexturesStr << suffix << kSamplerIndexStr;
*textureReference = textureRefBuilder;
ImmutableStringBuilder samplerRefBuilder(kSamplersStr.length() + suffix.length() +
kSamplerIndexStr.length());
samplerRefBuilder << kSamplersStr << suffix << kSamplerIndexStr;
*samplerReference = samplerRefBuilder;
} }
else else
{ {
out << " const uint textureIndex = samplerIndex - textureIndexOffset" out << " const uint textureIndex = samplerIndex - textureIndexOffset" << suffix
<< suffix.data() << ";\n"; << ";\n";
ImmutableStringBuilder textureRefBuilder(kTexturesStr.length() + suffix.length() + *textureReference = TString("textures") + suffix + "[textureIndex]";
kTextureIndexStr.length()); out << " const uint samplerArrayIndex = samplerIndex - samplerIndexOffset" << suffix
textureRefBuilder << kTexturesStr << suffix << kTextureIndexStr; << ";\n";
*textureReference = textureRefBuilder; *samplerReference = TString("samplers") + suffix + "[samplerArrayIndex]";
out << " const uint samplerArrayIndex = samplerIndex - samplerIndexOffset"
<< suffix.data() << ";\n";
ImmutableStringBuilder samplerRefBuilder(kSamplersStr.length() + suffix.length() +
kSamplerArrayIndexStr.length());
samplerRefBuilder << kSamplersStr << suffix << kSamplerArrayIndexStr;
*samplerReference = samplerRefBuilder;
} }
} }
else else
{ {
*textureReference = ImmutableString("x"); *textureReference = "x";
*samplerReference = ImmutableString("s"); *samplerReference = "s";
} }
} }
void OutputTextureSizeFunctionBody(TInfoSinkBase &out, void OutputTextureSizeFunctionBody(TInfoSinkBase &out,
const TextureFunctionHLSL::TextureFunction &textureFunction, const TextureFunctionHLSL::TextureFunction &textureFunction,
const ImmutableString &textureReference, const TString &textureReference,
bool getDimensionsIgnoresBaseLevel) bool getDimensionsIgnoresBaseLevel)
{ {
if (IsSampler2DMS(textureFunction.sampler)) if (IsSampler2DMS(textureFunction.sampler))
...@@ -585,7 +565,7 @@ void OutputIntegerTextureSampleFunctionComputations( ...@@ -585,7 +565,7 @@ void OutputIntegerTextureSampleFunctionComputations(
TInfoSinkBase &out, TInfoSinkBase &out,
const TextureFunctionHLSL::TextureFunction &textureFunction, const TextureFunctionHLSL::TextureFunction &textureFunction,
const ShShaderOutput outputType, const ShShaderOutput outputType,
const ImmutableString &textureReference, const TString &textureReference,
TString *texCoordX, TString *texCoordX,
TString *texCoordY, TString *texCoordY,
TString *texCoordZ) TString *texCoordZ)
...@@ -831,8 +811,8 @@ void OutputTextureSampleFunctionReturnStatement( ...@@ -831,8 +811,8 @@ void OutputTextureSampleFunctionReturnStatement(
TInfoSinkBase &out, TInfoSinkBase &out,
const TextureFunctionHLSL::TextureFunction &textureFunction, const TextureFunctionHLSL::TextureFunction &textureFunction,
const ShShaderOutput outputType, const ShShaderOutput outputType,
const ImmutableString &textureReference, const TString &textureReference,
const ImmutableString &samplerReference, const TString &samplerReference,
const TString &texCoordX, const TString &texCoordX,
const TString &texCoordY, const TString &texCoordY,
const TString &texCoordZ) const TString &texCoordZ)
...@@ -1311,8 +1291,8 @@ void TextureFunctionHLSL::textureFunctionHeader(TInfoSinkBase &out, ...@@ -1311,8 +1291,8 @@ void TextureFunctionHLSL::textureFunctionHeader(TInfoSinkBase &out,
// sampling we need to call the function directly on references to the texture and sampler // sampling we need to call the function directly on references to the texture and sampler
// arrays. The bug was found using dEQP-GLES3.functional.shaders.discard*loop_texture* // arrays. The bug was found using dEQP-GLES3.functional.shaders.discard*loop_texture*
// tests. // tests.
ImmutableString textureReference(""); TString textureReference;
ImmutableString samplerReference(""); TString samplerReference;
GetTextureReference(out, textureFunction, outputType, &textureReference, &samplerReference); GetTextureReference(out, textureFunction, outputType, &textureReference, &samplerReference);
if (textureFunction.method == TextureFunction::SIZE) if (textureFunction.method == TextureFunction::SIZE)
......
...@@ -218,7 +218,7 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat ...@@ -218,7 +218,7 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat
return HLSL_TEXTURE_UNKNOWN; return HLSL_TEXTURE_UNKNOWN;
} }
const char *TextureString(const HLSLTextureGroup textureGroup) TString TextureString(const HLSLTextureGroup textureGroup)
{ {
switch (textureGroup) switch (textureGroup)
{ {
...@@ -277,12 +277,12 @@ const char *TextureString(const HLSLTextureGroup textureGroup) ...@@ -277,12 +277,12 @@ const char *TextureString(const HLSLTextureGroup textureGroup)
return "<unknown read texture type>"; return "<unknown read texture type>";
} }
const char *TextureString(const TBasicType type, TLayoutImageInternalFormat imageInternalFormat) TString TextureString(const TBasicType type, TLayoutImageInternalFormat imageInternalFormat)
{ {
return TextureString(TextureGroup(type, imageInternalFormat)); return TextureString(TextureGroup(type, imageInternalFormat));
} }
const char *TextureGroupSuffix(const HLSLTextureGroup type) TString TextureGroupSuffix(const HLSLTextureGroup type)
{ {
switch (type) switch (type)
{ {
...@@ -341,8 +341,7 @@ const char *TextureGroupSuffix(const HLSLTextureGroup type) ...@@ -341,8 +341,7 @@ const char *TextureGroupSuffix(const HLSLTextureGroup type)
return "<unknown texture type>"; return "<unknown texture type>";
} }
const char *TextureGroupSuffix(const TBasicType type, TString TextureGroupSuffix(const TBasicType type, TLayoutImageInternalFormat imageInternalFormat)
TLayoutImageInternalFormat imageInternalFormat)
{ {
return TextureGroupSuffix(TextureGroup(type, imageInternalFormat)); return TextureGroupSuffix(TextureGroup(type, imageInternalFormat));
} }
......
...@@ -87,12 +87,12 @@ enum HLSLRWTextureGroup ...@@ -87,12 +87,12 @@ enum HLSLRWTextureGroup
HLSLTextureGroup TextureGroup(const TBasicType type, HLSLTextureGroup TextureGroup(const TBasicType type,
TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified); TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified);
const char *TextureString(const HLSLTextureGroup textureGroup); TString TextureString(const HLSLTextureGroup textureGroup);
const char *TextureString(const TBasicType type, TString TextureString(const TBasicType type,
TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified); TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified);
const char *TextureGroupSuffix(const HLSLTextureGroup type); TString TextureGroupSuffix(const HLSLTextureGroup type);
const char *TextureGroupSuffix(const TBasicType type, TString TextureGroupSuffix(const TBasicType type,
TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified); TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified);
TString TextureTypeSuffix(const TBasicType type, TString TextureTypeSuffix(const TBasicType type,
TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified); TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified);
HLSLRWTextureGroup RWTextureGroup(const TBasicType type, HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
......
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