Bug 1800301 - Use Vector instead of custom inlining_vector. r=jgilbert

Differential Revision: https://phabricator.services.mozilla.com/D162083
This commit is contained in:
Lee Salzman 2022-11-15 08:05:09 +00:00
Родитель ccb8642bc9
Коммит 5e17cdc939
5 изменённых файлов: 13 добавлений и 49 удалений

Просмотреть файл

@ -83,7 +83,7 @@ ScopedResolveTexturesForDraw::ScopedResolveTexturesForDraw(
uint8_t texUnit;
const webgl::SamplerUniformInfo* sampler;
};
inlining_vector<SamplerByTexUnit, 8> samplerByTexUnit;
Vector<SamplerByTexUnit, 8> samplerByTexUnit;
MOZ_ASSERT(mWebGL->mActiveProgramLinkInfo);
const auto& samplerUniforms = mWebGL->mActiveProgramLinkInfo->samplerUniforms;
@ -104,8 +104,8 @@ ScopedResolveTexturesForDraw::ScopedResolveTexturesForDraw(
}
if (!prevSamplerForTexUnit) {
prevSamplerForTexUnit = &uniform;
samplerByTexUnit.push_back(
SamplerByTexUnit{texUnit, prevSamplerForTexUnit});
MOZ_RELEASE_ASSERT(samplerByTexUnit.append(
SamplerByTexUnit{texUnit, prevSamplerForTexUnit}));
}
if (MOZ_UNLIKELY(&uniform.texListForType !=

Просмотреть файл

@ -1353,10 +1353,13 @@ void WebGLContext::UniformData(
const auto srcBegin = reinterpret_cast<const uint32_t*>(data.begin().get());
auto destIndex = locInfo->indexIntoUniform;
for (const auto& val : Range<const uint32_t>(srcBegin, elemCount)) {
if (destIndex >= texUnits.size()) break;
texUnits.at(destIndex) = AssertedCast<uint8_t>(val);
destIndex += 1;
if (destIndex < texUnits.length()) {
// Only sample as many indexes as available tex units allow.
const auto destCount = std::min(elemCount, texUnits.length() - destIndex);
for (const auto& val : Range<const uint32_t>(srcBegin, destCount)) {
texUnits[destIndex] = AssertedCast<uint8_t>(val);
destIndex += 1;
}
}
}
}

Просмотреть файл

@ -490,7 +490,7 @@ RefPtr<const webgl::LinkedProgramInfo> QueryProgramInfo(WebGLProgram* prog,
auto curInfo = std::unique_ptr<webgl::SamplerUniformInfo>(
new webgl::SamplerUniformInfo{*texList, *baseType, isShadowSampler});
curInfo->texUnits.resize(uniform.elemCount);
MOZ_RELEASE_ASSERT(curInfo->texUnits.resize(uniform.elemCount));
samplerInfo = curInfo.get();
info->samplerUniforms.push_back(std::move(curInfo));
}

Просмотреть файл

@ -12,6 +12,7 @@
#include <vector>
#include "mozilla/RefPtr.h"
#include "mozilla/Vector.h"
#include "mozilla/WeakPtr.h"
#include "CacheInvalidator.h"
@ -78,7 +79,7 @@ struct SamplerUniformInfo final {
const decltype(WebGLContext::mBound2DTextures)& texListForType;
const webgl::TextureBaseType texBaseType;
const bool isShadowSampler;
inlining_vector<uint8_t, 8> texUnits;
Vector<uint8_t, 8> texUnits = decltype(texUnits)();
};
struct LocationInfo final {

Просмотреть файл

@ -6,7 +6,6 @@
#ifndef WEBGLTYPES_H_
#define WEBGLTYPES_H_
#include <array>
#include <limits>
#include <string>
#include <tuple>
@ -1201,45 +1200,6 @@ union UniformDataVal {
} // namespace webgl
// -
template <class T, size_t InlineCapacity>
struct InliningAllocator {
using value_type = T;
template <class U>
struct rebind {
typedef InliningAllocator<U, InlineCapacity> other;
};
private:
std::array<T, InlineCapacity> mInlined = {};
public:
InliningAllocator() = default;
InliningAllocator(const InliningAllocator&) = delete;
InliningAllocator(InliningAllocator&&) = delete;
InliningAllocator& operator=(const InliningAllocator&) = delete;
InliningAllocator& operator=(InliningAllocator&&) = delete;
T* allocate(const size_t n) {
T* p = nullptr;
if (n <= mInlined.size()) {
p = mInlined.data(); // You better be using memmove not memcpy!
} else {
p = new T[n];
}
return p;
}
void deallocate(T* const p, size_t) {
if (p != mInlined.data()) {
delete[] p;
}
}
};
template <class T, size_t N>
using inlining_vector = std::vector<T, InliningAllocator<T, N>>;
} // namespace mozilla
#endif