Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ganesh] Apply buffer binding restriction #170

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/gpu/ganesh/gl/GrGLBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,37 @@ inline static GrGLenum gr_to_gl_access_pattern(GrGpuBufferType bufferType,
return usageType(bufferType, accessPattern);
}

#ifdef SK_DEBUG
bool GrGLBuffer::validBindingTarget(GrGLenum target) const {
if (!this->glCaps().bufferBindingRestriction()) {
return true;
}
/* This restriction implies that a given buffer object may contain
* either indices or other data, but not both.
*/
if (GR_GL_ELEMENT_ARRAY_BUFFER == target) {
switch (fBindingCategory) {
case BindingCategory::kUndefined:
fBindingCategory = BindingCategory::kIndexBuffer;
[[fallthrough]];
case BindingCategory::kIndexBuffer:
return true;
default:
return false;
}
}
switch (fBindingCategory) {
case BindingCategory::kUndefined:
fBindingCategory = BindingCategory::kOtherData;
[[fallthrough]];
case BindingCategory::kOtherData:
return true;
default:
return false;
}
}
#endif // SK_DEBUG

GrGLBuffer::GrGLBuffer(GrGLGpu* gpu,
size_t size,
GrGpuBufferType intendedType,
Expand Down
13 changes: 13 additions & 0 deletions src/gpu/ganesh/gl/GrGLBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class GrGLBuffer : public GrGpuBuffer {
void setHasAttachedToTexture() { fHasAttachedToTexture = true; }
bool hasAttachedToTexture() const { return fHasAttachedToTexture; }

#ifdef SK_DEBUG
bool validBindingTarget(GrGLenum target) const;
#endif // SK_DEBUG

protected:
GrGLBuffer(GrGLGpu*,
size_t size,
Expand Down Expand Up @@ -59,6 +63,15 @@ class GrGLBuffer : public GrGpuBuffer {
GrGLenum fUsage;
bool fHasAttachedToTexture;

#ifdef SK_DEBUG
enum class BindingCategory {
kUndefined,
kIndexBuffer,
kOtherData,
};
mutable BindingCategory fBindingCategory = BindingCategory::kUndefined;
#endif // SK_DEBUG

using INHERITED = GrGpuBuffer;
};

Expand Down
2 changes: 2 additions & 0 deletions src/gpu/ganesh/gl/GrGLCaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ void GrGLCaps::init(const GrContextOptions& contextOptions,
fClientCanDisableMultisample = false;
}

fBufferBindingRestriction = GR_IS_GR_WEBGL(standard);

if (GR_IS_GR_GL(standard)) {
// 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
// instanced arrays, but we could make this more granular if we wanted
Expand Down
4 changes: 4 additions & 0 deletions src/gpu/ganesh/gl/GrGLCaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ class GrGLCaps : public GrCaps {

bool clientCanDisableMultisample() const { return fClientCanDisableMultisample; }

/* https://registry.khronos.org/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING */
bool bufferBindingRestriction() const { return fBufferBindingRestriction; }

GrBackendFormat getBackendFormatFromCompressionType(SkTextureCompressionType) const override;

skgpu::Swizzle getWriteSwizzle(const GrBackendFormat&, GrColorType) const override;
Expand Down Expand Up @@ -630,6 +633,7 @@ class GrGLCaps : public GrCaps {
bool fSRGBWriteControl : 1;
bool fSkipErrorChecks : 1;
bool fClientCanDisableMultisample : 1;
bool fBufferBindingRestriction: 1;

// Driver workarounds
bool fDoManualMipmapping : 1;
Expand Down
1 change: 1 addition & 0 deletions src/gpu/ganesh/gl/GrGLGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,7 @@ GrGLenum GrGLGpu::bindBuffer(GrGpuBufferType type, const GrBuffer* buffer) {
} else if (static_cast<const GrGpuBuffer*>(buffer)->uniqueID() !=
bufferState->fBoundBufferUniqueID) {
const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(buffer);
SkASSERT(glBuffer->validBindingTarget(bufferState->fGLTarget));
GL_CALL(BindBuffer(bufferState->fGLTarget, glBuffer->bufferID()));
bufferState->fBufferZeroKnownBound = false;
bufferState->fBoundBufferUniqueID = glBuffer->uniqueID();
Expand Down