Skip to content

Commit

Permalink
Bug 1878930 - s/RawBuffer/Span/: UniformData. r=gfx-reviewers,lsalzman
Browse files Browse the repository at this point in the history
  • Loading branch information
kdashg committed Feb 20, 2024
1 parent 88b2980 commit c512530
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
5 changes: 2 additions & 3 deletions dom/canvas/ClientWebGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4856,9 +4856,8 @@ void ClientWebGLContext::UniformData(const GLenum funcElemType,
const auto begin =
reinterpret_cast<const webgl::UniformDataVal*>(bytes.begin().get()) +
elemOffset;
const auto range = Range{begin, availCount};
RunWithGCData<RPROC(UniformData)>(std::move(nogc), locId, transpose,
RawBuffer{range});
const auto range = Span{begin, availCount};
RunWithGCData<RPROC(UniformData)>(std::move(nogc), locId, transpose, range);
}

// -
Expand Down
4 changes: 2 additions & 2 deletions dom/canvas/HostWebGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ class HostWebGLContext final : public SupportsWeakPtr {
// ------------------------ Uniforms and attributes ------------------------

void UniformData(uint32_t loc, bool transpose,
const RawBuffer<webgl::UniformDataVal>& data) const {
mContext->UniformData(loc, transpose, data.Data());
const Span<const webgl::UniformDataVal>& data) const {
mContext->UniformData(loc, transpose, data);
}

void VertexAttrib4T(GLuint index, const webgl::TypedQuad& data) const {
Expand Down
4 changes: 4 additions & 0 deletions dom/canvas/QueueParamTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ template <>
struct BytesAlwaysValidT<webgl::UniformDataVal> {
static constexpr bool value = true;
};
template <>
struct BytesAlwaysValidT<const webgl::UniformDataVal> {
static constexpr bool value = true;
};

// -

Expand Down
2 changes: 1 addition & 1 deletion dom/canvas/WebGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ class WebGLContext : public VRefCounted, public SupportsWeakPtr {
//////////////////////////

void UniformData(uint32_t loc, bool transpose,
const Range<const webgl::UniformDataVal>& data) const;
const Span<const webgl::UniformDataVal>& data) const;

////////////////////////////////////

Expand Down
16 changes: 8 additions & 8 deletions dom/canvas/WebGLContextGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ void WebGLContext::StencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail,

void WebGLContext::UniformData(
const uint32_t loc, const bool transpose,
const Range<const webgl::UniformDataVal>& data) const {
const Span<const webgl::UniformDataVal>& data) const {
const FuncScope funcScope(*this, "uniform setter");

if (!IsWebGL2() && transpose) {
Expand All @@ -1306,13 +1306,13 @@ void WebGLContext::UniformData(

// -

const auto lengthInType = data.length();
const auto lengthInType = data.size();
const auto elemCount = lengthInType / channels;
if (elemCount > 1 && !validationInfo.isArray) {
GenerateError(
LOCAL_GL_INVALID_OPERATION,
"(uniform %s) `values` length (%u) must exactly match size of %s.",
activeInfo.name.c_str(), lengthInType,
activeInfo.name.c_str(), (uint32_t)lengthInType,
EnumString(activeInfo.elemType).c_str());
return;
}
Expand All @@ -1321,9 +1321,9 @@ void WebGLContext::UniformData(

const auto& samplerInfo = locInfo->samplerInfo;
if (samplerInfo) {
const auto idata = reinterpret_cast<const uint32_t*>(data.begin().get());
const auto idata = ReinterpretToSpan<const uint32_t>::From(data);
const auto maxTexUnits = GLMaxTextureUnits();
for (const auto& val : Range<const uint32_t>(idata, elemCount)) {
for (const auto& val : idata) {
if (val >= maxTexUnits) {
ErrorInvalidValue(
"This uniform location is a sampler, but %d"
Expand All @@ -1337,20 +1337,20 @@ void WebGLContext::UniformData(
// -

// This is a little galaxy-brain, sorry!
const auto ptr = static_cast<const void*>(data.begin().get());
const auto ptr = static_cast<const void*>(data.data());
(*pfn)(*gl, static_cast<GLint>(loc), elemCount, transpose, ptr);

// -

if (samplerInfo) {
auto& texUnits = samplerInfo->texUnits;

const auto srcBegin = reinterpret_cast<const uint32_t*>(data.begin().get());
const auto srcBegin = reinterpret_cast<const uint32_t*>(data.data());
auto destIndex = locInfo->indexIntoUniform;
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)) {
for (const auto& val : Span<const uint32_t>(srcBegin, destCount)) {
texUnits[destIndex] = AssertedCast<uint8_t>(val);
destIndex += 1;
}
Expand Down

0 comments on commit c512530

Please sign in to comment.