Skip to content

Commit

Permalink
Add custom messages for most common invalid operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrbecky committed Oct 3, 2017
1 parent 237470f commit 4edbf78
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 35 deletions.
44 changes: 33 additions & 11 deletions gapis/api/gles/api/debug.api
Original file line number Diff line number Diff line change
Expand Up @@ -242,47 +242,69 @@ sub void ObjectLabel(GLenum identifier, GLuint name, GLsizei length, const GLcha
ctx := GetContext()
switch (identifier) {
case GL_TEXTURE: {
if !(as!TextureId(name) in ctx.Objects.Shared.Textures) { glErrorInvalidOperation() }
if !(as!TextureId(name) in ctx.Objects.Shared.Textures) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.Shared.Textures[as!TextureId(name)].Label = str
}
case GL_FRAMEBUFFER: {
if !(as!FramebufferId(name) in ctx.Objects.Framebuffers) { glErrorInvalidOperation() }
if !(as!FramebufferId(name) in ctx.Objects.Framebuffers) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.Framebuffers[as!FramebufferId(name)].Label = str
}
case GL_RENDERBUFFER: {
if !(as!RenderbufferId(name) in ctx.Objects.Shared.Renderbuffers) { glErrorInvalidOperation() }
if !(as!RenderbufferId(name) in ctx.Objects.Shared.Renderbuffers) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.Shared.Renderbuffers[as!RenderbufferId(name)].Label = str
}
case GL_BUFFER: {
if !(as!BufferId(name) in ctx.Objects.Shared.Buffers) { glErrorInvalidOperation() }
if !(as!BufferId(name) in ctx.Objects.Shared.Buffers) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.Shared.Buffers[as!BufferId(name)].Label = str
}
case GL_SHADER: {
if !(as!ShaderId(name) in ctx.Objects.Shared.Shaders) { glErrorInvalidOperation() }
if !(as!ShaderId(name) in ctx.Objects.Shared.Shaders) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.Shared.Shaders[as!ShaderId(name)].Label = str
}
case GL_PROGRAM: {
if !(as!ProgramId(name) in ctx.Objects.Shared.Programs) { glErrorInvalidOperation() }
if !(as!ProgramId(name) in ctx.Objects.Shared.Programs) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.Shared.Programs[as!ProgramId(name)].Label = str
}
case GL_VERTEX_ARRAY: {
if !(as!VertexArrayId(name) in ctx.Objects.VertexArrays) { glErrorInvalidOperation() }
if !(as!VertexArrayId(name) in ctx.Objects.VertexArrays) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.VertexArrays[as!VertexArrayId(name)].Label = str
}
case GL_QUERY: {
if !(as!QueryId(name) in ctx.Objects.Queries) { glErrorInvalidOperation() }
if !(as!QueryId(name) in ctx.Objects.Queries) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.Queries[as!QueryId(name)].Label = str
}
case GL_SAMPLER: {
if !(as!SamplerId(name) in ctx.Objects.Shared.Samplers) { glErrorInvalidOperation() }
if !(as!SamplerId(name) in ctx.Objects.Shared.Samplers) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.Shared.Samplers[as!SamplerId(name)].Label = str
}
case GL_TRANSFORM_FEEDBACK: {
if !(as!TransformFeedbackId(name) in ctx.Objects.TransformFeedbacks) { glErrorInvalidOperation() }
if !(as!TransformFeedbackId(name) in ctx.Objects.TransformFeedbacks) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.TransformFeedbacks[as!TransformFeedbackId(name)].Label = str
}
case GL_PROGRAM_PIPELINE: {
if !(as!PipelineId(name) in ctx.Objects.Pipelines) { glErrorInvalidOperation() }
if !(as!PipelineId(name) in ctx.Objects.Pipelines) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(name)
}
ctx.Objects.Pipelines[as!PipelineId(name)].Label = str
}
default: {
Expand Down
4 changes: 2 additions & 2 deletions gapis/api/gles/api/draw_commands.api
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cmd void glDrawArrays(GLenum draw_mode, GLint first_index, GLsizei indices_count
cmd void glDrawArraysIndirect(GLenum draw_mode, const void* indirect) {
checkPrimitiveType(draw_mode)
ctx := GetContext()
if IsDefaultVertexArrayBound() { glErrorInvalidOperation() }
CheckNonDefaultVertexArrayBound()
if ctx.Bound.DrawIndirectBuffer == null { glErrorInvalidOperation() }
// TODO: INVALID_OPERATION error if the command would source data beyond the end of the buffer object.
// TODO: CheckEQ(as!u64(indirect) % 4, 0)
Expand Down Expand Up @@ -189,7 +189,7 @@ cmd void glDrawElementsIndirect(GLenum draw_mode, GLenum indices_type, const voi
checkIndicesType(indices_type)

ctx := GetContext()
if IsDefaultVertexArrayBound() { glErrorInvalidOperation() }
CheckNonDefaultVertexArrayBound()
// TODO: Error if enabled array is not bound or is mapped.
if ctx.Bound.DrawIndirectBuffer == null { glErrorInvalidOperation() }
// TODO: INVALID_OPERATION error if the command would source data beyond the end of the buffer object.
Expand Down
4 changes: 4 additions & 0 deletions gapis/api/gles/api/errors.api
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ sub void CheckSizeGE!T(T value, T constraint) {
glErrorInvalidValueMsg(new!ERR_INVALID_VALUE_CHECK_SIZE_GE(value: as!s64(value), constraint: as!s64(constraint)))
}
}

sub void glErrorInvalidOperation_ObjectDoesNotExist!T(T id) {
glErrorInvalidOperationMsg(new!ERR_INVALID_OPERATION_OBJECT_DOES_NOT_EXIST(id: as!u64(id)))
}
44 changes: 33 additions & 11 deletions gapis/api/gles/api/extensions.api
Original file line number Diff line number Diff line change
Expand Up @@ -1540,47 +1540,69 @@ cmd void glLabelObjectEXT(GLenum type, GLuint object, GLsizei length, const GLch
ctx := GetContext()
switch (type) {
case GL_TEXTURE: {
if !(as!TextureId(object) in ctx.Objects.Shared.Textures) { glErrorInvalidOperation() }
if !(as!TextureId(object) in ctx.Objects.Shared.Textures) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.Shared.Textures[as!TextureId(object)].Label = str
}
case GL_FRAMEBUFFER: {
if !(as!FramebufferId(object) in ctx.Objects.Framebuffers) { glErrorInvalidOperation() }
if !(as!FramebufferId(object) in ctx.Objects.Framebuffers) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.Framebuffers[as!FramebufferId(object)].Label = str
}
case GL_RENDERBUFFER: {
if !(as!RenderbufferId(object) in ctx.Objects.Shared.Renderbuffers) { glErrorInvalidOperation() }
if !(as!RenderbufferId(object) in ctx.Objects.Shared.Renderbuffers) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.Shared.Renderbuffers[as!RenderbufferId(object)].Label = str
}
case GL_BUFFER_OBJECT_EXT: {
if !(as!BufferId(object) in ctx.Objects.Shared.Buffers) { glErrorInvalidOperation() }
if !(as!BufferId(object) in ctx.Objects.Shared.Buffers) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.Shared.Buffers[as!BufferId(object)].Label = str
}
case GL_SHADER_OBJECT_EXT: {
if !(as!ShaderId(object) in ctx.Objects.Shared.Shaders) { glErrorInvalidOperation() }
if !(as!ShaderId(object) in ctx.Objects.Shared.Shaders) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.Shared.Shaders[as!ShaderId(object)].Label = str
}
case GL_PROGRAM_OBJECT_EXT: {
if !(as!ProgramId(object) in ctx.Objects.Shared.Programs) { glErrorInvalidOperation() }
if !(as!ProgramId(object) in ctx.Objects.Shared.Programs) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.Shared.Programs[as!ProgramId(object)].Label = str
}
case GL_VERTEX_ARRAY_OBJECT_EXT: {
if !(as!VertexArrayId(object) in ctx.Objects.VertexArrays) { glErrorInvalidOperation() }
if !(as!VertexArrayId(object) in ctx.Objects.VertexArrays) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.VertexArrays[as!VertexArrayId(object)].Label = str
}
case GL_QUERY_OBJECT_EXT: {
if !(as!QueryId(object) in ctx.Objects.Queries) { glErrorInvalidOperation() }
if !(as!QueryId(object) in ctx.Objects.Queries) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.Queries[as!QueryId(object)].Label = str
}
case GL_SAMPLER: {
if !(as!SamplerId(object) in ctx.Objects.Shared.Samplers) { glErrorInvalidOperation() }
if !(as!SamplerId(object) in ctx.Objects.Shared.Samplers) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.Shared.Samplers[as!SamplerId(object)].Label = str
}
case GL_TRANSFORM_FEEDBACK: {
if !(as!TransformFeedbackId(object) in ctx.Objects.TransformFeedbacks) { glErrorInvalidOperation() }
if !(as!TransformFeedbackId(object) in ctx.Objects.TransformFeedbacks) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.TransformFeedbacks[as!TransformFeedbackId(object)].Label = str
}
case GL_PROGRAM_PIPELINE_OBJECT_EXT: {
if !(as!PipelineId(object) in ctx.Objects.Pipelines) { glErrorInvalidOperation() }
if !(as!PipelineId(object) in ctx.Objects.Pipelines) {
glErrorInvalidOperation_ObjectDoesNotExist!GLuint(object)
}
ctx.Objects.Pipelines[as!PipelineId(object)].Label = str
}
default: {
Expand Down
21 changes: 16 additions & 5 deletions gapis/api/gles/api/framebuffer.api
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ sub ref!Framebuffer GetBoundFramebufferOrErrorInvalidEnum(GLenum framebuffer_tar
}
}

sub void CheckNonDefaultFramebuffer(ref!Framebuffer framebuffer) {
ctx := GetContext()
if framebuffer == ctx.Objects.Framebuffers[0] {
glErrorInvalidOperationMsg(new!ERR_INVALID_OPERATION_DEFAULT_FRAMEBUFFER_BOUND())
}
}

sub bool IsDefaultFramebuffer(ref!Framebuffer framebuffer) {
ctx := GetContext()
return framebuffer == ctx.Objects.Framebuffers[0]
Expand All @@ -132,7 +139,7 @@ sub void SetFramebufferAttachment(GLenum framebuffer_target,
FramebufferAttachment attachment) {
ctx := GetContext()
framebuffer := GetBoundFramebufferOrErrorInvalidEnum(framebuffer_target)
if IsDefaultFramebuffer(framebuffer) { glErrorInvalidOperation() }
CheckNonDefaultFramebuffer(framebuffer)
switch (framebuffer_attachment) {
case GL_COLOR_ATTACHMENT0:
framebuffer.ColorAttachments[0] = attachment
Expand Down Expand Up @@ -528,7 +535,7 @@ sub void DrawBuffers(GLsizei n, const GLenum* buffers) {
@doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glFramebufferParameteri.xhtml", Version.GLES32)
cmd void glFramebufferParameteri(GLenum target, GLenum pname, GLint param) {
framebuffer := GetBoundFramebufferOrErrorInvalidEnum(target)
if IsDefaultFramebuffer(framebuffer) { glErrorInvalidOperation() }
CheckNonDefaultFramebuffer(framebuffer)
switch (pname) {
case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: {
framebuffer.DefaultFixedSampleLocations = as!GLboolean(param)
Expand Down Expand Up @@ -564,7 +571,9 @@ cmd void glFramebufferRenderbuffer(GLenum framebuffer_target,
ctx := GetContext()
if renderbuffer_target != GL_RENDERBUFFER { glErrorInvalidEnum(renderbuffer_target) }
// SPEC: Only PDF spec mentions this:
if (renderbuffer != 0) && !(renderbuffer in ctx.Objects.Shared.Renderbuffers) { glErrorInvalidOperation() }
if (renderbuffer != 0) && !(renderbuffer in ctx.Objects.Shared.Renderbuffers) {
glErrorInvalidOperation_ObjectDoesNotExist!RenderbufferId(renderbuffer)
}

attachment := FramebufferAttachment()
if (renderbuffer != 0) {
Expand Down Expand Up @@ -630,7 +639,9 @@ sub void FramebufferTexture2D(GLenum framebuffer_target,
ctx := GetContext()
attachment := FramebufferAttachment()
if (texture != 0) {
if !(texture in ctx.Objects.Shared.Textures) { glErrorInvalidOperation() }
if !(texture in ctx.Objects.Shared.Textures) {
glErrorInvalidOperation_ObjectDoesNotExist!TextureId(texture)
}
kind := switch (texture_target) {
case GL_TEXTURE_2D:
GL_TEXTURE_2D
Expand Down Expand Up @@ -790,7 +801,7 @@ cmd void glGetFramebufferParameteriv(GLenum target, GLenum pname, GLint* params)
}

framebuffer := GetBoundFramebufferOrErrorInvalidEnum(target)
if IsDefaultFramebuffer(framebuffer) { glErrorInvalidOperation() }
CheckNonDefaultFramebuffer(framebuffer)
params[0] = switch (pname) {
case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: as!GLint(framebuffer.DefaultFixedSampleLocations)
case GL_FRAMEBUFFER_DEFAULT_HEIGHT: framebuffer.DefaultHeight
Expand Down
4 changes: 3 additions & 1 deletion gapis/api/gles/api/synchronization.api
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ cmd void glWaitSync(GLsync sync, GLbitfield syncFlags, GLuint64 timeout) {

sub void WaitSync(GLsync sync, GLbitfield syncFlags, GLuint64 timeout) {
ctx := GetContext()
if !(sync in ctx.Objects.Shared.SyncObjects) { glErrorInvalidOperation() }
if !(sync in ctx.Objects.Shared.SyncObjects) {
glErrorInvalidOperation_ObjectDoesNotExist!GLsync(sync)
}
CheckEQ!GLuint64(timeout, 0xFFFFFFFFFFFFFFFF) // GL_TIMEOUT_IGNORED
CheckEQ!GLbitfield(syncFlags, as!GLbitfield(0))
}
17 changes: 12 additions & 5 deletions gapis/api/gles/api/vertex_arrays.api
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ sub void CheckAttributeLocation(AttributeLocation location) {
CheckLocationLT!AttributeLocation(location, as!AttributeLocation(ctx.Constants.MaxVertexAttribs))
}

sub void CheckNonDefaultVertexArrayBound() {
ctx := GetContext()
if ctx.Bound.VertexArray.ID == 0 {
glErrorInvalidOperationMsg(new!ERR_INVALID_OPERATION_DEFAULT_VERTEX_ARRAY_BOUND())
}
}

sub bool IsDefaultVertexArrayBound() {
ctx := GetContext()
return ctx.Bound.VertexArray.ID == 0
Expand Down Expand Up @@ -210,7 +217,7 @@ sub void BindVertexBuffer(ref!Context ctx, VertexBufferBindingIndex binding_inde
@doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glBindVertexBuffer.xhtml", Version.GLES32)
cmd void glBindVertexBuffer(VertexBufferBindingIndex binding_index, BufferId buffer, GLintptr offset, GLsizei stride) {
ctx := GetContext()
if IsDefaultVertexArrayBound() { glErrorInvalidOperation() }
CheckNonDefaultVertexArrayBound()
BindVertexBuffer(ctx, binding_index, buffer, offset, stride)
}

Expand Down Expand Up @@ -488,7 +495,7 @@ sub void VertexAttribBinding(ref!Context ctx, AttributeLocation index, VertexBuf
@doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glVertexAttribBinding.xhtml", Version.GLES32)
cmd void glVertexAttribBinding(AttributeLocation index, VertexBufferBindingIndex binding_index) {
ctx := GetContext()
if IsDefaultVertexArrayBound() { glErrorInvalidOperation() }
CheckNonDefaultVertexArrayBound()
VertexAttribBinding(ctx, index, binding_index)
}

Expand Down Expand Up @@ -571,7 +578,7 @@ cmd void glVertexAttribFormat(AttributeLocation index,
GLboolean normalized,
GLuint relativeoffset) {
ctx := GetContext()
if IsDefaultVertexArrayBound() { glErrorInvalidOperation() }
CheckNonDefaultVertexArrayBound()
VertexAttribFormat(ctx, index, size, type, normalized, relativeoffset, false)
}

Expand Down Expand Up @@ -624,7 +631,7 @@ cmd void glVertexAttribI4uiv(AttributeLocation index, const GLuint* values) {
@doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glVertexAttribFormat.xhtml", Version.GLES32)
cmd void glVertexAttribIFormat(AttributeLocation index, GLint size, GLenum type, GLuint relativeoffset) {
ctx := GetContext()
if IsDefaultVertexArrayBound() { glErrorInvalidOperation() }
CheckNonDefaultVertexArrayBound()
VertexAttribFormat(ctx, index, size, type, as!GLboolean(0), relativeoffset, true)
}

Expand Down Expand Up @@ -697,7 +704,7 @@ cmd void glVertexAttribPointer(AttributeLocation location,
cmd void glVertexBindingDivisor(VertexBufferBindingIndex binding_index, GLuint divisor) {
ctx := GetContext()
CheckLT!VertexBufferBindingIndex(binding_index, as!VertexBufferBindingIndex(ctx.Constants.MaxVertexAttribBindings))
if IsDefaultVertexArrayBound() { glErrorInvalidOperation() }
CheckNonDefaultVertexArrayBound()
vao := ctx.Bound.VertexArray
vao.VertexBufferBindings[binding_index].Divisor = divisor
}
12 changes: 12 additions & 0 deletions gapis/messages/en-us.stb.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ Invalid enum {{value:u32}}.

Invalid operation.

# ERR_INVALID_OPERATION_DEFAULT_FRAMEBUFFER_BOUND

Invalid operation. Default framebuffer object is bound.

# ERR_INVALID_OPERATION_DEFAULT_VERTEX_ARRAY_BOUND

Invalid operation. Default vertex array object is bound.

# ERR_INVALID_OPERATION_OBJECT_DOES_NOT_EXIST

Invalid operation. Object {{id:u64}} does not exist.

# ERR_CONTEXT_DOES_NOT_EXIST

No context with id {{id:u64}} exists.
Expand Down

0 comments on commit 4edbf78

Please sign in to comment.