2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-10-05 00:35:54 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-11-21 01:38:20 +04:00
|
|
|
#include "WebGLBuffer.h"
|
2014-03-17 18:52:56 +04:00
|
|
|
|
2013-09-04 16:14:52 +04:00
|
|
|
#include "GLContext.h"
|
2012-10-05 00:35:54 +04:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
2014-03-17 18:52:56 +04:00
|
|
|
#include "WebGLContext.h"
|
2012-10-05 00:35:54 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2012-10-05 00:35:54 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::WebGLBuffer(WebGLContext* webgl, GLuint buf)
|
2020-01-09 01:19:16 +03:00
|
|
|
: WebGLContextBoundObject(webgl), mGLName(buf) {}
|
|
|
|
|
|
|
|
WebGLBuffer::~WebGLBuffer() {
|
|
|
|
mByteLength = 0;
|
|
|
|
mFetchInvalidator.InvalidateCaches();
|
|
|
|
|
|
|
|
mIndexCache = nullptr;
|
|
|
|
mIndexRanges.clear();
|
2012-11-21 01:38:20 +04:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
if (!mContext) return;
|
|
|
|
mContext->gl->fDeleteBuffers(1, &mGLName);
|
|
|
|
}
|
2012-11-21 01:38:20 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
void WebGLBuffer::SetContentAfterBind(GLenum target) {
|
|
|
|
if (mContent != Kind::Undefined) return;
|
|
|
|
|
2015-05-21 02:59:14 +03:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
|
|
|
|
mContent = Kind::ElementArray;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_ARRAY_BUFFER:
|
|
|
|
case LOCAL_GL_PIXEL_PACK_BUFFER:
|
|
|
|
case LOCAL_GL_PIXEL_UNPACK_BUFFER:
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER:
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
|
|
|
|
case LOCAL_GL_COPY_READ_BUFFER:
|
|
|
|
case LOCAL_GL_COPY_WRITE_BUFFER:
|
2016-09-10 07:02:54 +03:00
|
|
|
mContent = Kind::OtherData;
|
2015-05-21 02:59:14 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: invalid target");
|
2015-05-21 02:59:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
static bool ValidateBufferUsageEnum(WebGLContext* webgl, GLenum usage) {
|
2016-09-10 07:02:54 +03:00
|
|
|
switch (usage) {
|
|
|
|
case LOCAL_GL_STREAM_DRAW:
|
|
|
|
case LOCAL_GL_STATIC_DRAW:
|
|
|
|
case LOCAL_GL_DYNAMIC_DRAW:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LOCAL_GL_DYNAMIC_COPY:
|
|
|
|
case LOCAL_GL_DYNAMIC_READ:
|
|
|
|
case LOCAL_GL_STATIC_COPY:
|
|
|
|
case LOCAL_GL_STATIC_READ:
|
|
|
|
case LOCAL_GL_STREAM_COPY:
|
|
|
|
case LOCAL_GL_STREAM_READ:
|
|
|
|
if (MOZ_LIKELY(webgl->IsWebGL2())) return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
webgl->ErrorInvalidEnumInfo("usage", usage);
|
2016-09-10 07:02:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-23 19:07:13 +03:00
|
|
|
void WebGLBuffer::BufferData(const GLenum target, const uint64_t size,
|
|
|
|
const void* const maybeData, const GLenum usage) {
|
|
|
|
// The driver knows only GLsizeiptr, which is int32_t on 32bit!
|
|
|
|
bool sizeValid = CheckedInt<GLsizeiptr>(size).isValid();
|
2016-09-10 07:02:54 +03:00
|
|
|
|
2020-01-23 19:07:13 +03:00
|
|
|
if (mContext->gl->WorkAroundDriverBugs()) {
|
|
|
|
// Bug 790879
|
2019-04-28 15:19:18 +03:00
|
|
|
#if defined(XP_MACOSX) || defined(MOZ_WIDGET_GTK)
|
2020-01-23 19:07:13 +03:00
|
|
|
sizeValid &= CheckedInt<int32_t>(size).isValid();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Bug 1610383
|
|
|
|
if (mContext->gl->IsANGLE()) {
|
|
|
|
// While ANGLE seems to support up to `unsigned int`, UINT32_MAX-4 causes
|
|
|
|
// GL_OUT_OF_MEMORY in glFlush??
|
|
|
|
sizeValid &= CheckedInt<int32_t>(size).isValid();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sizeValid) {
|
|
|
|
mContext->ErrorOutOfMemory("Size not valid for platform: %" PRIu64, size);
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-23 19:07:13 +03:00
|
|
|
// -
|
|
|
|
|
|
|
|
if (!ValidateBufferUsageEnum(mContext, usage)) return;
|
|
|
|
|
|
|
|
const void* uploadData = maybeData;
|
2020-01-09 01:19:16 +03:00
|
|
|
UniqueBuffer maybeCalloc;
|
2020-01-23 19:07:13 +03:00
|
|
|
if (!uploadData) {
|
2020-01-09 01:19:16 +03:00
|
|
|
maybeCalloc = calloc(1, AssertedCast<size_t>(size));
|
|
|
|
if (!maybeCalloc) {
|
|
|
|
mContext->ErrorOutOfMemory("Failed to alloc zeros.");
|
|
|
|
return;
|
|
|
|
}
|
2020-01-23 19:07:13 +03:00
|
|
|
uploadData = maybeCalloc.get();
|
2020-01-09 01:19:16 +03:00
|
|
|
}
|
2020-01-23 19:07:13 +03:00
|
|
|
MOZ_ASSERT(uploadData);
|
2017-02-10 07:32:58 +03:00
|
|
|
|
|
|
|
UniqueBuffer newIndexCache;
|
2016-09-10 07:02:54 +03:00
|
|
|
if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER &&
|
2017-02-10 07:32:58 +03:00
|
|
|
mContext->mNeedsIndexValidation) {
|
2019-03-07 02:52:05 +03:00
|
|
|
newIndexCache = malloc(AssertedCast<size_t>(size));
|
2017-02-10 07:32:58 +03:00
|
|
|
if (!newIndexCache) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorOutOfMemory("Failed to alloc index cache.");
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-08-05 09:26:56 +03:00
|
|
|
// memcpy out of SharedArrayBuffers can be racey, and should generally use
|
|
|
|
// memcpySafeWhenRacy. But it's safe here:
|
|
|
|
// * We only memcpy in one place.
|
|
|
|
// * We only read out of the single copy, and only after copying.
|
|
|
|
// * If we get data value corruption from racing read-during-write, that's
|
|
|
|
// fine.
|
2020-01-23 19:07:13 +03:00
|
|
|
memcpy(newIndexCache.get(), uploadData, size);
|
2017-06-22 21:32:00 +03:00
|
|
|
uploadData = newIndexCache.get();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-06-22 21:32:00 +03:00
|
|
|
const auto& gl = mContext->gl;
|
2016-09-28 00:03:48 +03:00
|
|
|
const ScopedLazyBind lazyBind(gl, target, this);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const bool sizeChanges = (size != ByteLength());
|
2017-08-03 13:01:38 +03:00
|
|
|
if (sizeChanges) {
|
2017-02-10 07:32:58 +03:00
|
|
|
gl::GLContext::LocalErrorScope errorScope(*gl);
|
|
|
|
gl->fBufferData(target, size, uploadData, usage);
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto error = errorScope.GetError();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
if (error) {
|
2016-09-10 07:02:54 +03:00
|
|
|
MOZ_ASSERT(error == LOCAL_GL_OUT_OF_MEMORY);
|
2017-02-10 07:32:58 +03:00
|
|
|
mContext->ErrorOutOfMemory("Error from driver: 0x%04x", error);
|
2019-06-14 06:26:18 +03:00
|
|
|
|
|
|
|
// Truncate
|
|
|
|
mByteLength = 0;
|
|
|
|
mFetchInvalidator.InvalidateCaches();
|
|
|
|
mIndexCache = nullptr;
|
2017-02-10 07:32:58 +03:00
|
|
|
return;
|
2016-09-10 07:02:54 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-02-10 07:32:58 +03:00
|
|
|
gl->fBufferData(target, size, uploadData, usage);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->OnDataAllocCall();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-28 00:03:48 +03:00
|
|
|
mUsage = usage;
|
2017-02-10 07:32:58 +03:00
|
|
|
mByteLength = size;
|
2017-10-21 01:40:12 +03:00
|
|
|
mFetchInvalidator.InvalidateCaches();
|
2018-05-30 22:15:35 +03:00
|
|
|
mIndexCache = std::move(newIndexCache);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
if (mIndexCache) {
|
|
|
|
if (!mIndexRanges.empty()) {
|
|
|
|
mContext->GeneratePerfWarning("[%p] Invalidating %u ranges.", this,
|
|
|
|
uint32_t(mIndexRanges.size()));
|
|
|
|
mIndexRanges.clear();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2017-12-21 03:31:58 +03:00
|
|
|
|
|
|
|
ResetLastUpdateFenceId();
|
2016-09-10 07:02:54 +03:00
|
|
|
}
|
|
|
|
|
2019-03-07 02:52:05 +03:00
|
|
|
void WebGLBuffer::BufferSubData(GLenum target, uint64_t dstByteOffset,
|
|
|
|
uint64_t dataLen, const void* data) const {
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateRange(dstByteOffset, dataLen)) return;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
2019-03-07 02:52:05 +03:00
|
|
|
if (!CheckedInt<GLintptr>(dstByteOffset).isValid() ||
|
|
|
|
!CheckedInt<GLsizeiptr>(dataLen).isValid())
|
|
|
|
return mContext->ErrorOutOfMemory("offset or size too large for platform.");
|
2017-02-10 07:32:58 +03:00
|
|
|
|
|
|
|
////
|
|
|
|
|
2020-02-07 06:17:26 +03:00
|
|
|
if (!dataLen) return; // With validation successful, nothing else to do.
|
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
const void* uploadData = data;
|
|
|
|
if (mIndexCache) {
|
|
|
|
const auto cachedDataBegin = (uint8_t*)mIndexCache.get() + dstByteOffset;
|
|
|
|
memcpy(cachedDataBegin, data, dataLen);
|
|
|
|
uploadData = cachedDataBegin;
|
|
|
|
|
|
|
|
InvalidateCacheRange(dstByteOffset, dataLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
const auto& gl = mContext->gl;
|
|
|
|
const ScopedLazyBind lazyBind(gl, target, this);
|
|
|
|
|
|
|
|
gl->fBufferSubData(target, dstByteOffset, dataLen, uploadData);
|
2017-12-21 03:31:58 +03:00
|
|
|
|
|
|
|
ResetLastUpdateFenceId();
|
2017-02-10 07:32:58 +03:00
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
bool WebGLBuffer::ValidateRange(size_t byteOffset, size_t byteLen) const {
|
2016-10-12 03:37:29 +03:00
|
|
|
auto availLength = mByteLength;
|
|
|
|
if (byteOffset > availLength) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidValue("Offset passes the end of the buffer.");
|
2016-10-12 03:37:29 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
availLength -= byteOffset;
|
|
|
|
|
|
|
|
if (byteLen > availLength) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidValue("Offset+size passes the end of the buffer.");
|
2016-10-12 03:37:29 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
static uint8_t IndexByteSizeByType(GLenum type) {
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
return 1;
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
|
|
|
return 2;
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2012-11-21 01:38:20 +04:00
|
|
|
}
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
void WebGLBuffer::InvalidateCacheRange(uint64_t byteOffset,
|
|
|
|
uint64_t byteLength) const {
|
2017-02-10 07:32:58 +03:00
|
|
|
MOZ_ASSERT(mIndexCache);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
std::vector<IndexRange> invalids;
|
2017-10-21 01:40:12 +03:00
|
|
|
const uint64_t updateBegin = byteOffset;
|
|
|
|
const uint64_t updateEnd = updateBegin + byteLength;
|
2017-02-10 07:32:58 +03:00
|
|
|
for (const auto& cur : mIndexRanges) {
|
|
|
|
const auto& range = cur.first;
|
|
|
|
const auto& indexByteSize = IndexByteSizeByType(range.type);
|
2017-10-21 01:40:12 +03:00
|
|
|
const auto rangeBegin = range.byteOffset * indexByteSize;
|
|
|
|
const auto rangeEnd =
|
|
|
|
rangeBegin + uint64_t(range.indexCount) * indexByteSize;
|
2017-02-10 07:32:58 +03:00
|
|
|
if (rangeBegin >= updateEnd || rangeEnd <= updateBegin) continue;
|
|
|
|
invalids.push_back(range);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-03 13:01:38 +03:00
|
|
|
if (!invalids.empty()) {
|
2017-02-10 07:32:58 +03:00
|
|
|
mContext->GeneratePerfWarning("[%p] Invalidating %u/%u ranges.", this,
|
|
|
|
uint32_t(invalids.size()),
|
|
|
|
uint32_t(mIndexRanges.size()));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
for (const auto& cur : invalids) {
|
|
|
|
mIndexRanges.erase(cur);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-11-21 01:38:20 +04:00
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
size_t WebGLBuffer::SizeOfIncludingThis(
|
|
|
|
mozilla::MallocSizeOf mallocSizeOf) const {
|
2017-02-10 07:32:58 +03:00
|
|
|
size_t size = mallocSizeOf(this);
|
|
|
|
if (mIndexCache) {
|
|
|
|
size += mByteLength;
|
|
|
|
}
|
|
|
|
return size;
|
2014-03-17 18:52:56 +04:00
|
|
|
}
|
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
template <typename T>
|
2017-10-21 01:40:12 +03:00
|
|
|
static Maybe<uint32_t> MaxForRange(const void* const start,
|
|
|
|
const uint32_t count,
|
|
|
|
const Maybe<uint32_t>& untypedIgnoredVal) {
|
|
|
|
const Maybe<T> ignoredVal =
|
|
|
|
(untypedIgnoredVal ? Some(T(untypedIgnoredVal.value())) : Nothing());
|
|
|
|
Maybe<uint32_t> maxVal;
|
2016-12-21 05:44:28 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
auto itr = (const T*)start;
|
2017-02-10 07:32:58 +03:00
|
|
|
const auto end = itr + count;
|
|
|
|
|
|
|
|
for (; itr != end; ++itr) {
|
|
|
|
const auto& val = *itr;
|
2017-10-21 01:40:12 +03:00
|
|
|
if (ignoredVal && val == ignoredVal.value()) continue;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
if (maxVal && val <= maxVal.value()) continue;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
maxVal = Some(val);
|
2017-02-10 07:32:58 +03:00
|
|
|
}
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
return maxVal;
|
2014-03-17 18:52:56 +04:00
|
|
|
}
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
static const uint32_t kMaxIndexRanges = 256;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
Maybe<uint32_t> WebGLBuffer::GetIndexedFetchMaxVert(
|
|
|
|
const GLenum type, const uint64_t byteOffset,
|
|
|
|
const uint32_t indexCount) const {
|
2017-02-10 07:32:58 +03:00
|
|
|
if (!mIndexCache) return Nothing();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
const IndexRange range = {type, byteOffset, indexCount};
|
|
|
|
auto res = mIndexRanges.insert({range, Nothing()});
|
2017-02-10 07:32:58 +03:00
|
|
|
if (mIndexRanges.size() > kMaxIndexRanges) {
|
|
|
|
mContext->GeneratePerfWarning(
|
|
|
|
"[%p] Clearing mIndexRanges after exceeding %u.", this,
|
|
|
|
kMaxIndexRanges);
|
|
|
|
mIndexRanges.clear();
|
2017-10-21 01:40:12 +03:00
|
|
|
res = mIndexRanges.insert({range, Nothing()});
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
const auto& itr = res.first;
|
2017-02-10 07:32:58 +03:00
|
|
|
const auto& didInsert = res.second;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
auto& maxFetchIndex = itr->second;
|
2017-10-21 01:40:12 +03:00
|
|
|
if (didInsert) {
|
2017-02-10 07:32:58 +03:00
|
|
|
const auto& data = mIndexCache.get();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
const auto start = (const uint8_t*)data + byteOffset;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
Maybe<uint32_t> ignoredVal;
|
|
|
|
if (mContext->IsWebGL2()) {
|
|
|
|
ignoredVal = Some(UINT32_MAX);
|
2017-02-10 07:32:58 +03:00
|
|
|
}
|
2016-12-21 05:44:28 +03:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
2017-10-21 01:40:12 +03:00
|
|
|
maxFetchIndex = MaxForRange<uint8_t>(start, indexCount, ignoredVal);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2017-02-10 07:32:58 +03:00
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
2017-10-21 01:40:12 +03:00
|
|
|
maxFetchIndex = MaxForRange<uint16_t>(start, indexCount, ignoredVal);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2017-02-10 07:32:58 +03:00
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
2017-10-21 01:40:12 +03:00
|
|
|
maxFetchIndex = MaxForRange<uint32_t>(start, indexCount, ignoredVal);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
default:
|
2017-02-10 07:32:58 +03:00
|
|
|
MOZ_CRASH();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-10-21 01:40:12 +03:00
|
|
|
const auto displayMaxVertIndex =
|
|
|
|
maxFetchIndex ? int64_t(maxFetchIndex.value()) : -1;
|
|
|
|
mContext->GeneratePerfWarning("[%p] New range #%u: (0x%04x, %" PRIu64
|
2018-11-30 13:46:48 +03:00
|
|
|
", %u):"
|
2017-10-21 01:40:12 +03:00
|
|
|
" %" PRIi64,
|
|
|
|
this, uint32_t(mIndexRanges.size()),
|
|
|
|
range.type, range.byteOffset,
|
|
|
|
range.indexCount, displayMaxVertIndex);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
return maxFetchIndex;
|
2014-06-03 00:30:00 +04:00
|
|
|
}
|
2014-03-17 18:52:56 +04:00
|
|
|
|
2016-12-21 05:44:28 +03:00
|
|
|
////
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
bool WebGLBuffer::ValidateCanBindToTarget(GLenum target) {
|
2016-09-18 02:44:56 +03:00
|
|
|
/* https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.1
|
|
|
|
*
|
|
|
|
* In the WebGL 2 API, buffers have their WebGL buffer type
|
|
|
|
* initially set to undefined. Calling bindBuffer, bindBufferRange
|
|
|
|
* or bindBufferBase with the target argument set to any buffer
|
|
|
|
* binding point except COPY_READ_BUFFER or COPY_WRITE_BUFFER will
|
|
|
|
* then set the WebGL buffer type of the buffer being bound
|
|
|
|
* according to the table above.
|
|
|
|
*
|
|
|
|
* Any call to one of these functions which attempts to bind a
|
|
|
|
* WebGLBuffer that has the element array WebGL buffer type to a
|
|
|
|
* binding point that falls under other data, or bind a
|
|
|
|
* WebGLBuffer which has the other data WebGL buffer type to
|
|
|
|
* ELEMENT_ARRAY_BUFFER will generate an INVALID_OPERATION error,
|
|
|
|
* and the state of the binding point will remain untouched.
|
|
|
|
*/
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-18 02:44:56 +03:00
|
|
|
if (mContent == WebGLBuffer::Kind::Undefined) return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-18 02:44:56 +03:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_COPY_READ_BUFFER:
|
|
|
|
case LOCAL_GL_COPY_WRITE_BUFFER:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
|
|
|
|
if (mContent == WebGLBuffer::Kind::ElementArray) return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_ARRAY_BUFFER:
|
|
|
|
case LOCAL_GL_PIXEL_PACK_BUFFER:
|
|
|
|
case LOCAL_GL_PIXEL_UNPACK_BUFFER:
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER:
|
|
|
|
if (mContent == WebGLBuffer::Kind::OtherData) return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto dataType =
|
|
|
|
(mContent == WebGLBuffer::Kind::OtherData) ? "other" : "element";
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation("Buffer already contains %s data.", dataType);
|
2016-09-18 02:44:56 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-21 03:31:58 +03:00
|
|
|
void WebGLBuffer::ResetLastUpdateFenceId() const {
|
|
|
|
mLastUpdateFenceId = mContext->mNextFenceId;
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
} // namespace mozilla
|