diff --git a/gapis/api/gles/api/asynchronous_queries.api b/gapis/api/gles/api/asynchronous_queries.api index 5c41c215b8..f4dcc233b7 100644 --- a/gapis/api/gles/api/asynchronous_queries.api +++ b/gapis/api/gles/api/asynchronous_queries.api @@ -61,7 +61,7 @@ cmd void glDeleteQueries(GLsizei count, const QueryId* queries) { } sub void DeleteQueries(GLsizei count, const QueryId* queries) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) q := queries[0:count] ctx := GetContext() for i in (0 .. count) { @@ -103,7 +103,7 @@ cmd void glGenQueries(GLsizei count, QueryId* queries) { } sub void GenQueries(GLsizei count, QueryId* queries) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) q := queries[0:count] ctx := GetContext() for i in (0 .. count) { diff --git a/gapis/api/gles/api/buffer_objects.api b/gapis/api/gles/api/buffer_objects.api index 51d97eefd8..79e52c9371 100644 --- a/gapis/api/gles/api/buffer_objects.api +++ b/gapis/api/gles/api/buffer_objects.api @@ -265,7 +265,7 @@ cmd void glBufferData(GLenum target, GLsizeiptr size, BufferDataPointer data, GL glErrorInvalidEnum(usage) } } - CheckNonNegative!GLsizeiptr(size) + CheckSizeGE!GLsizeiptr(size, 0) b.Data = switch (data != null) { case true: clone(as!u8*(data)[0:size]) @@ -282,8 +282,9 @@ cmd void glBufferData(GLenum target, GLsizeiptr size, BufferDataPointer data, GL @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glBufferSubData.xhtml", Version.GLES32) cmd void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, BufferDataPointer data) { b := GetBoundBufferOrError(target) - if (offset < 0) || (size < 0) { glErrorInvalidValue() } - if (as!GLsizeiptr(offset) + size) > b.Size { glErrorInvalidValue() } + CheckGE!GLintptr(offset, 0) + CheckSizeGE!GLsizeiptr(size, 0) + CheckLE!GLsizeiptr((as!GLsizeiptr(offset) + size), b.Size) copy(b.Data[offset:as!GLsizeiptr(offset) + size], as!u8*(data)[0:size]) } @@ -313,7 +314,7 @@ sub void CopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readO @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glDeleteBuffers.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glDeleteBuffers.xhtml", Version.GLES32) cmd void glDeleteBuffers(GLsizei count, const BufferId* buffers) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) b := buffers[0:count] ctx := GetContext() for i in (0 .. count) { @@ -331,7 +332,7 @@ cmd void glDeleteBuffers(GLsizei count, const BufferId* buffers) { @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glGenBuffers.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGenBuffers.xhtml", Version.GLES32) cmd void glGenBuffers(GLsizei count, BufferId* buffers) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) b := buffers[0:count] ctx := GetContext() for i in (0 .. count) { @@ -466,9 +467,11 @@ cmd void* glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GL return ptr } -sub void MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access, u8* ptr) { +sub void MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr size, GLbitfield access, u8* ptr) { b := GetBoundBufferOrError(target) - if (offset < 0) || (length < 0) || ((as!GLsizeiptr(offset) + length) > b.Size) { glErrorInvalidValue() } + CheckGE!GLintptr(offset, 0) + CheckSizeGE!GLsizeiptr(size, 0) + CheckLE!GLsizeiptr((as!GLsizeiptr(offset) + size), b.Size) supportsBits(access, GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_READ_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_WRITE_BIT) if b.Mapped == GL_TRUE { glErrorInvalidOperation() } @@ -476,11 +479,11 @@ sub void MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbit b.AccessFlags = access b.MapPointer = ptr b.MapOffset = offset - b.MapLength = length - mapMemory(ptr[0:length]) + b.MapLength = size + mapMemory(ptr[0:size]) if GL_MAP_READ_BIT in access { - copy(ptr[0:length], b.Data[offset:offset + as!GLintptr(length)]) + copy(ptr[0:size], b.Data[offset:offset + as!GLintptr(size)]) } } @@ -516,11 +519,13 @@ cmd void glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr len FlushMappedBufferRange(target, offset, length) } -sub void FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length) { +sub void FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr size) { b := GetBoundBufferOrError(target) if b.Mapped == GL_FALSE { glErrorInvalidOperation() } if !(GL_MAP_FLUSH_EXPLICIT_BIT in b.AccessFlags) { glErrorInvalidOperation() } - if (offset < 0) || (length < 0) || ((as!GLsizeiptr(offset) + length) > b.MapLength) { glErrorInvalidValue() } + CheckGE!GLintptr(offset, 0) + CheckSizeGE!GLsizeiptr(size, 0) + CheckLE!GLsizeiptr((as!GLsizeiptr(offset) + size), b.MapLength) dstOffset := b.MapOffset + offset - copy(b.Data[dstOffset:dstOffset + as!GLintptr(length)], b.MapPointer[offset:offset + as!GLintptr(length)]) + copy(b.Data[dstOffset:dstOffset + as!GLintptr(size)], b.MapPointer[offset:offset + as!GLintptr(size)]) } diff --git a/gapis/api/gles/api/debug.api b/gapis/api/gles/api/debug.api index c77daae26d..622d6dc1f2 100644 --- a/gapis/api/gles/api/debug.api +++ b/gapis/api/gles/api/debug.api @@ -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: { diff --git a/gapis/api/gles/api/draw_commands.api b/gapis/api/gles/api/draw_commands.api index 2f83e0ce0c..ffc1568465 100644 --- a/gapis/api/gles/api/draw_commands.api +++ b/gapis/api/gles/api/draw_commands.api @@ -62,8 +62,8 @@ sub bool isTransformFeedback() { @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glDrawArrays.xhtml", Version.GLES32) cmd void glDrawArrays(GLenum draw_mode, GLint first_index, GLsizei indices_count) { checkPrimitiveType(draw_mode) - CheckNonNegative!GLint(first_index) // "Recommended behaviour" - CheckNonNegative!GLsizei(indices_count) + CheckGE!GLint(first_index, 0) // "Recommended behaviour" + CheckCountGE!GLsizei(indices_count, 0) ctx := GetContext() ReadVertexArrays(ctx, as!u32(first_index), as!u32(indices_count), 1) WriteGPUFramebufferData(ctx) @@ -77,10 +77,10 @@ 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: if as!u64(indirect) % 4 != 0 { glErrorInvalidValue() } + // TODO: CheckEQ(as!u64(indirect) % 4, 0) WriteGPUFramebufferData(ctx) } @@ -96,9 +96,9 @@ cmd void glDrawArraysInstanced(GLenum draw_mode, GLint first_index, GLsizei indi sub void DrawArraysInstanced(GLenum draw_mode, GLint first_index, GLsizei indices_count, GLsizei instance_count) { checkPrimitiveType(draw_mode) - CheckNonNegative!GLint(first_index) // "Recommended behaviour" - CheckNonNegative!GLsizei(indices_count) - CheckNonNegative!GLsizei(instance_count) + CheckGE!GLint(first_index, 0) // "Recommended behaviour" + CheckCountGE!GLsizei(indices_count, 0) + CheckCountGE!GLsizei(instance_count, 0) ctx := GetContext() ReadVertexArrays(ctx, as!u32(first_index), as!u32(indices_count), as!u32(instance_count)) WriteGPUFramebufferData(ctx) @@ -112,9 +112,9 @@ sub void DrawElements(ref!Context ctx, GLsizei instance_count, GLint base_vertex) { checkPrimitiveType(draw_mode) - CheckNonNegative!GLsizei(indices_count) // SPEC: missing in pdf + CheckCountGE!GLsizei(indices_count, 0) // SPEC: missing in pdf checkIndicesType(indices_type) - CheckNonNegative!GLsizei(instance_count) // SPEC: missing in pdf + CheckCountGE!GLsizei(instance_count, 0) // SPEC: missing in pdf if indices_count > 0 { count := as!u32(indices_count) index_buffer := ctx.Bound.VertexArray.ElementArrayBuffer @@ -189,11 +189,11 @@ 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. - // TODO: if as!u64(indirect) % 4 != 0 { glErrorInvalidValue() } + // TODO: CheckEQ(as!u64(indirect) % 4, 0) WriteGPUFramebufferData(ctx) } @@ -246,7 +246,7 @@ cmd void glDrawRangeElements(GLenum draw_mode, GLsizei indices_count, GLenum indices_type, IndicesPointer indices) { - if end < start { glErrorInvalidValue() } + CheckGE!GLuint(end, start) ctx := GetContext() DrawElements(ctx, draw_mode, indices_count, indices_type, indices, 1, 0) } @@ -266,7 +266,7 @@ cmd void glDrawRangeElementsBaseVertex(GLenum draw_mode, } sub void DrawRangeElementsBaseVertex(GLenum draw_mode, GLuint start, GLuint end, GLsizei indices_count, GLenum indices_type, IndicesPointer indices, GLint base_vertex) { - if end < start { glErrorInvalidValue() } + CheckGE!GLuint(end, start) ctx := GetContext() DrawElements(ctx, draw_mode, indices_count, indices_type, indices, 1, base_vertex) } diff --git a/gapis/api/gles/api/errors.api b/gapis/api/gles/api/errors.api new file mode 100644 index 0000000000..a2329a16d1 --- /dev/null +++ b/gapis/api/gles/api/errors.api @@ -0,0 +1,111 @@ +// Copyright (C) 2017 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +extern void onGlError(GLenum v) + +sub void supportsBits(GLbitfield seenBits, GLbitfield validBits) { + CheckEQ!GLbitfield((seenBits & validBits), seenBits) +} + +sub void glErrorInvalidEnum(GLenum value) { + glErrorInvalidEnumMsg(new!ERR_INVALID_ENUM(value: as!u32(value))) +} + +sub void glErrorInvalidEnumMsg(message m) { + onGlError(GL_INVALID_ENUM) + _ = newMsg(SEVERITY_ERROR, m) + abort +} + +sub void glErrorInvalidValue!T(T value) { + glErrorInvalidValueMsg(new!ERR_INVALID_VALUE(value: as!s64(value))) +} + +sub void glErrorInvalidObjectName!T(T value) { + glErrorInvalidValueMsg(new!ERR_INVALID_OBJECT_NAME(value: as!s64(value))) +} + +sub void glErrorInvalidValueMsg(message m) { + onGlError(GL_INVALID_VALUE) + _ = newMsg(SEVERITY_ERROR, m) + abort +} + +sub void glErrorInvalidOperation() { + glErrorInvalidOperationMsg(new!ERR_INVALID_OPERATION()) +} + +sub void glErrorInvalidOperationMsg(message m) { + onGlError(GL_INVALID_OPERATION) + _ = newMsg(SEVERITY_ERROR, m) + abort +} + +sub void CheckEQ!T(T value, T constraint) { + if !(as!s64(value) == as!s64(constraint)) { + glErrorInvalidValueMsg(new!ERR_INVALID_VALUE_CHECK_EQ(value: as!s64(value), constraint: as!s64(constraint))) + } +} + +sub void CheckNE!T(T value, T constraint) { + if !(as!s64(value) != as!s64(constraint)) { + glErrorInvalidValueMsg(new!ERR_INVALID_VALUE_CHECK_NE(value: as!s64(value), constraint: as!s64(constraint))) + } +} + +sub void CheckGE!T(T value, T constraint) { + if !(as!s64(value) >= as!s64(constraint)) { + glErrorInvalidValueMsg(new!ERR_INVALID_VALUE_CHECK_GE(value: as!s64(value), constraint: as!s64(constraint))) + } +} + +sub void CheckGT!T(T value, T constraint) { + if !(as!s64(value) > as!s64(constraint)) { + glErrorInvalidValueMsg(new!ERR_INVALID_VALUE_CHECK_GT(value: as!s64(value), constraint: as!s64(constraint))) + } +} + +sub void CheckLE!T(T value, T constraint) { + if !(as!s64(value) <= as!s64(constraint)) { + glErrorInvalidValueMsg(new!ERR_INVALID_VALUE_CHECK_LE(value: as!s64(value), constraint: as!s64(constraint))) + } +} + +sub void CheckLT!T(T value, T constraint) { + if !(as!s64(value) < as!s64(constraint)) { + glErrorInvalidValueMsg(new!ERR_INVALID_VALUE_CHECK_LT(value: as!s64(value), constraint: as!s64(constraint))) + } +} + +sub void CheckLocationLT!T(T value, T constraint) { + if !(as!s64(value) < as!s64(constraint)) { + glErrorInvalidValueMsg(new!ERR_INVALID_VALUE_CHECK_LOCATION_LT(value: as!s64(value), constraint: as!s64(constraint))) + } +} + +sub void CheckCountGE!T(T value, T constraint) { + if !(as!s64(value) >= as!s64(constraint)) { + glErrorInvalidValueMsg(new!ERR_INVALID_VALUE_CHECK_COUNT_GE(value: as!s64(value), constraint: as!s64(constraint))) + } +} + +sub void CheckSizeGE!T(T value, T constraint) { + if !(as!s64(value) >= as!s64(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))) +} diff --git a/gapis/api/gles/api/extensions.api b/gapis/api/gles/api/extensions.api index b0dc79b767..9423af429b 100644 --- a/gapis/api/gles/api/extensions.api +++ b/gapis/api/gles/api/extensions.api @@ -881,7 +881,7 @@ sub void FramebufferTextureMultiviewOVR(GLenum target, ctx := GetContext() attachment_info := FramebufferAttachment() if (texture != 0) { - if !(texture in ctx.Objects.Shared.Textures) { glErrorInvalidValue() } + if !(texture in ctx.Objects.Shared.Textures) { glErrorInvalidObjectName!TextureId(texture) } attachment_info.Type = GL_TEXTURE attachment_info.Texture = ctx.Objects.Shared.Textures[texture] attachment_info.TextureLevel = level @@ -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: { diff --git a/gapis/api/gles/api/fragment_operations.api b/gapis/api/gles/api/fragment_operations.api index 435a553041..0766f2cb0b 100644 --- a/gapis/api/gles/api/fragment_operations.api +++ b/gapis/api/gles/api/fragment_operations.api @@ -292,7 +292,8 @@ cmd void glSampleMaski(GLuint maskNumber, GLbitfield mask) { @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glScissor.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glScissor.xhtml", Version.GLES32) cmd void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) { - if (width < 0) || (height < 0) { glErrorInvalidValue() } + CheckSizeGE!GLsizei(width, 0) + CheckSizeGE!GLsizei(height, 0) ctx := GetContext() ctx.Pixel.Scissor.Box = Rect(x, y, width, height) } diff --git a/gapis/api/gles/api/framebuffer.api b/gapis/api/gles/api/framebuffer.api index f744e6e25d..8acd82bfd3 100644 --- a/gapis/api/gles/api/framebuffer.api +++ b/gapis/api/gles/api/framebuffer.api @@ -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] @@ -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 @@ -318,7 +325,7 @@ cmd void glClear(GLbitfield mask) { cmd void glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) { switch (buffer) { case GL_DEPTH_STENCIL: { - if drawbuffer != 0 { glErrorInvalidValue() } + CheckEQ!GLint(drawbuffer, 0) } default: { glErrorInvalidEnum(buffer) @@ -335,11 +342,11 @@ cmd void glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value) switch (buffer) { case GL_COLOR: { ctx := GetContext() - if drawbuffer >= ctx.Constants.MaxDrawBuffers { glErrorInvalidValue() } + CheckLT!GLint(drawbuffer, ctx.Constants.MaxDrawBuffers) read(value[0:4]) } case GL_DEPTH: { - if drawbuffer != 0 { glErrorInvalidValue() } + CheckEQ!GLint(drawbuffer, 0) read(value[0:1]) } default: { @@ -357,11 +364,11 @@ cmd void glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value) { switch (buffer) { case GL_COLOR: { ctx := GetContext() - if drawbuffer >= ctx.Constants.MaxDrawBuffers { glErrorInvalidValue() } + CheckLT!GLint(drawbuffer, ctx.Constants.MaxDrawBuffers) read(value[0:4]) } case GL_STENCIL: { - if drawbuffer != 0 { glErrorInvalidValue() } + CheckEQ!GLint(drawbuffer, 0) read(value[0:1]) } default: { @@ -379,7 +386,7 @@ cmd void glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value) switch (buffer) { case GL_COLOR: { ctx := GetContext() - if drawbuffer >= ctx.Constants.MaxDrawBuffers { glErrorInvalidValue() } + CheckLT!GLint(drawbuffer, ctx.Constants.MaxDrawBuffers) read(value[0:4]) } default: { @@ -450,7 +457,7 @@ sub void ColorMaski(DrawBufferIndex index, GLboolean r, GLboolean g, GLboolean b @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glDeleteFramebuffers.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glDeleteFramebuffers.xhtml", Version.GLES32) cmd void glDeleteFramebuffers(GLsizei count, const FramebufferId* framebuffers) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) f := framebuffers[0:count] ctx := GetContext() @@ -460,7 +467,7 @@ cmd void glDeleteFramebuffers(GLsizei count, const FramebufferId* framebuffers) // TODO: This is not really an error according to the spec. // However, we need to ensure the command is removed, // or else the invalid ID breaks remapping in replay. - if !(id in ctx.Objects.Framebuffers) { glErrorInvalidValue() } + if !(id in ctx.Objects.Framebuffers) { glErrorInvalidValue!FramebufferId(id) } delete(ctx.Objects.Framebuffers, id) delete(ctx.Objects.GeneratedNames.Framebuffers, id) if id == ctx.Bound.ReadFramebuffer.ID { @@ -479,7 +486,7 @@ cmd void glDeleteFramebuffers(GLsizei count, const FramebufferId* framebuffers) @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glDeleteRenderbuffers.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glDeleteRenderbuffers.xhtml", Version.GLES32) cmd void glDeleteRenderbuffers(GLsizei count, const RenderbufferId* renderbuffers) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) r := renderbuffers[0:count] ctx := GetContext() @@ -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) @@ -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) { @@ -584,7 +593,7 @@ sub void FramebufferTexture(GLenum target, GLenum attachment, TextureId texture, ctx := GetContext() attachment_info := FramebufferAttachment() if (texture != 0) { - if !(texture in ctx.Objects.Shared.Textures) { glErrorInvalidValue() } + if !(texture in ctx.Objects.Shared.Textures) { glErrorInvalidValue!TextureId(texture) } attachment_info.Type = GL_TEXTURE attachment_info.Texture = ctx.Objects.Shared.Textures[texture] attachment_info.TextureLevel = level @@ -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 @@ -665,7 +676,7 @@ cmd void glFramebufferTextureLayer(GLenum target, ctx := GetContext() attachment_info := FramebufferAttachment() if (texture != 0) { - if !(texture in ctx.Objects.Shared.Textures) { glErrorInvalidValue() } + if !(texture in ctx.Objects.Shared.Textures) { glErrorInvalidValue!TextureId(texture) } attachment_info.Type = GL_TEXTURE attachment_info.Texture = ctx.Objects.Shared.Textures[texture] attachment_info.TextureLevel = level @@ -680,7 +691,7 @@ cmd void glFramebufferTextureLayer(GLenum target, @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glGenFramebuffers.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGenFramebuffers.xhtml", Version.GLES32) cmd void glGenFramebuffers(GLsizei count, FramebufferId* framebuffers) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) f := framebuffers[0:count] ctx := GetContext() for i in (0 .. count) { @@ -697,7 +708,7 @@ cmd void glGenFramebuffers(GLsizei count, FramebufferId* framebuffers) { @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glGenRenderbuffers.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGenRenderbuffers.xhtml", Version.GLES32) cmd void glGenRenderbuffers(GLsizei count, RenderbufferId* renderbuffers) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) r := renderbuffers[0:count] ctx := GetContext() for i in (0 .. count) { @@ -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 @@ -984,7 +995,8 @@ sub void checkReadPixels(GLsizei width, glErrorInvalidEnum(type) } } - if (width < 0) || (height < 0) { glErrorInvalidValue() } + CheckSizeGE!GLsizei(width, 0) + CheckSizeGE!GLsizei(height, 0) } @if(Version.GLES10) @@ -1071,13 +1083,12 @@ sub void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum i if sizedFormatInfo.Compression != Uncompressed { glErrorInvalidEnum(internalformat) } - if (width < 0) || (height < 0) { glErrorInvalidValue() } + CheckSizeGE!GLsizei(width, 0) + CheckSizeGE!GLsizei(height, 0) ctx := GetContext() - if (width > as!GLsizei(ctx.Constants.MaxRenderbufferSize)) || - (height > as!GLsizei(ctx.Constants.MaxRenderbufferSize)) { - glErrorInvalidValue() - } + CheckLE!GLsizei(width, as!GLsizei(ctx.Constants.MaxRenderbufferSize)) + CheckLE!GLsizei(height, as!GLsizei(ctx.Constants.MaxRenderbufferSize)) rb := ctx.Bound.Renderbuffer if rb == null { glErrorInvalidOperation() } diff --git a/gapis/api/gles/api/other.api b/gapis/api/gles/api/other.api index 33c8385bbc..54e3e3cee7 100644 --- a/gapis/api/gles/api/other.api +++ b/gapis/api/gles/api/other.api @@ -119,20 +119,20 @@ sub GLboolean GetCapability(GLenum capability, GLuint index) { GL_SAMPLE_COVERAGE, GL_SCISSOR_TEST, GL_STENCIL_TEST: { - if index > 0 { glErrorInvalidValue() } + CheckEQ!GLuint(index, 0) } @if(Version.GLES30) case GL_PRIMITIVE_RESTART_FIXED_INDEX, GL_RASTERIZER_DISCARD: { - if index > 0 { glErrorInvalidValue() } + CheckEQ!GLuint(index, 0) } @if(Version.GLES31) case GL_SAMPLE_MASK: { - if index > 0 { glErrorInvalidValue() } + CheckEQ!GLuint(index, 0) } @if(Version.GLES32) case GL_DEBUG_OUTPUT, GL_DEBUG_OUTPUT_SYNCHRONOUS: { - if index > 0 { glErrorInvalidValue() } + CheckEQ!GLuint(index, 0) } default: { // glErrorInvalidEnum(capability) diff --git a/gapis/api/gles/api/programs_and_shaders.api b/gapis/api/gles/api/programs_and_shaders.api index c1aca201c2..aa1bda33bb 100644 --- a/gapis/api/gles/api/programs_and_shaders.api +++ b/gapis/api/gles/api/programs_and_shaders.api @@ -269,11 +269,8 @@ sub ref!Shader GetShaderOrError(ShaderId shader) { ctx := GetContext() s := ctx.Objects.Shared.Shaders[shader] if s == null { - if (!as!ProgramId(shader) in ctx.Objects.Shared.Programs) { - glErrorInvalidValue() - } else { - glErrorInvalidOperation() - } + if !(as!ProgramId(shader) in ctx.Objects.Shared.Programs) { glErrorInvalidObjectName!ShaderId(shader) } + glErrorInvalidOperation() } return s } @@ -282,11 +279,8 @@ sub ref!Program GetProgramOrError(ProgramId program) { ctx := GetContext() p := ctx.Objects.Shared.Programs[program] if p == null { - if (!as!ShaderId(program) in ctx.Objects.Shared.Shaders) { - glErrorInvalidValue() - } else { - glErrorInvalidOperation() - } + if !(as!ShaderId(program) in ctx.Objects.Shared.Shaders) { glErrorInvalidValue!ProgramId(program) } + glErrorInvalidOperation() } return p } @@ -371,7 +365,7 @@ cmd void glBindAttribLocation(ProgramId program, AttributeLocation location, str if (len(n) > 2) && (as!string(n[0:3]) == "gl_") { glErrorInvalidOperation() } ctx := GetContext() _ = GetProgramOrError(program) - if location >= as!AttributeLocation(ctx.Constants.MaxVertexAttribs) { glErrorInvalidValue() } + CheckAttributeLocation(location) p := ctx.Objects.Shared.Programs[program] p.AttributeBindings[name] = location } @@ -478,7 +472,7 @@ cmd void glDeleteProgramPipelines(GLsizei n, const PipelineId* pipelines) { } sub void DeleteProgramPipelines(GLsizei count, const PipelineId* pipelines) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) ids := pipelines[0:count] ctx := GetContext() for i in (0 .. count) { @@ -540,7 +534,7 @@ cmd void glGenProgramPipelines(GLsizei count, PipelineId* pipelines) { } sub void GenProgramPipelines(GLsizei count, PipelineId* pipelines) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) t := pipelines[0:count] ctx := GetContext() for i in (0 .. count) { @@ -564,12 +558,12 @@ cmd void glGetActiveAttrib(ProgramId program, GLenum* type, GLchar* name) { - CheckNonNegative!GLsizei(buffer_size) + CheckSizeGE!GLsizei(buffer_size, 0) ctx := GetContext() _ = GetProgramOrError(program) p := ctx.Objects.Shared.Programs[program] - if !(index in p.ActiveAttributes) { glErrorInvalidValue() } + if !(index in p.ActiveAttributes) { glErrorInvalidValue!AttributeIndex(index) } writeString(buffer_size, buffer_bytes_written, name) @@ -592,9 +586,9 @@ cmd void glGetActiveUniform(ProgramId program, ctx := GetContext() _ = GetProgramOrError(program) - CheckNonNegative!GLsizei(buffer_size) + CheckSizeGE!GLsizei(buffer_size, 0) p := ctx.Objects.Shared.Programs[program] - if !(index in p.ActiveUniforms) { glErrorInvalidValue() } + if !(index in p.ActiveUniforms) { glErrorInvalidValue!UniformIndex(index) } writeString(buffer_size, buffer_bytes_written, name) @@ -674,7 +668,7 @@ cmd void glGetAttachedShaders(ProgramId program, ctx := GetContext() _ = GetProgramOrError(program) - CheckNonNegative!GLsizei(buffer_length) + CheckGE!GLsizei(buffer_length, 0) p := ctx.Objects.Shared.Programs[program] l := min!s32(as!s32(buffer_length), len(p.Shaders)) if shaders_length_written != null { @@ -743,7 +737,7 @@ cmd void glGetProgramInfoLog(ProgramId program, GLsizei* string_length_written, GLchar* info) { _ = GetProgramOrError(program) - CheckNonNegative!GLsizei(buffer_length) + CheckGE!GLsizei(buffer_length, 0) writeString(buffer_length, string_length_written, info) } @@ -945,7 +939,7 @@ cmd void glGetShaderInfoLog(ShaderId shader, GLsizei* string_length_written, GLchar* info) { _ = GetShaderOrError(shader) - CheckNonNegative!GLsizei(buffer_length) + CheckGE!GLsizei(buffer_length, 0) writeString(buffer_length, string_length_written, info) } @@ -989,7 +983,7 @@ cmd void glGetShaderSource(ShaderId shader, GLsizei* string_length_written, GLchar* source) { _ = GetShaderOrError(shader) - CheckNonNegative!GLsizei(buffer_length) + CheckGE!GLsizei(buffer_length, 0) // TODO: Handle properly. Mind the null-terminator. writeString(buffer_length, string_length_written, source) } @@ -1867,7 +1861,7 @@ cmd void glShaderSource(ShaderId shader, GLsizei count, const GLchar* const* source, const GLint* length) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) sources := source[0:count] ctx := GetContext() diff --git a/gapis/api/gles/api/rasterization.api b/gapis/api/gles/api/rasterization.api index 17ce79d1c4..e5ea6b7b6e 100644 --- a/gapis/api/gles/api/rasterization.api +++ b/gapis/api/gles/api/rasterization.api @@ -117,7 +117,7 @@ cmd void glGetMultisamplefv(GLenum pname, GLuint index, GLfloat* val) { @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glLineWidth.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glLineWidth.xhtml", Version.GLES32) cmd void glLineWidth(GLfloat width) { - if (width <= 0.0) { glErrorInvalidValue() } + if width <= 0.0 { glErrorInvalidValue!GLfloat(width) } ctx := GetContext() ctx.Rasterization.LineWidth = width } @@ -151,7 +151,8 @@ cmd void glPolygonOffset(GLfloat scale_factor, GLfloat units) { @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glViewport.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glViewport.xhtml", Version.GLES32) cmd void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { - if (width < 0) || (height < 0) { glErrorInvalidValue() } + CheckSizeGE!GLsizei(width, 0) + CheckSizeGE!GLsizei(height, 0) ctx := GetContext() ctx.Rasterization.Viewport = Rect(x, y, width, height) } diff --git a/gapis/api/gles/api/synchronization.api b/gapis/api/gles/api/synchronization.api index 8102146424..7f0f8b7666 100644 --- a/gapis/api/gles/api/synchronization.api +++ b/gapis/api/gles/api/synchronization.api @@ -34,7 +34,7 @@ cmd GLenum glClientWaitSync(GLsync sync, GLbitfield syncFlags, GLuint64 timeout) sub void ClientWaitSync(GLsync sync, GLbitfield syncFlags, GLuint64 timeout) { supportsBits(syncFlags, GL_SYNC_FLUSH_COMMANDS_BIT) ctx := GetContext() - if !(sync in ctx.Objects.Shared.SyncObjects) { glErrorInvalidValue() } + if !(sync in ctx.Objects.Shared.SyncObjects) { glErrorInvalidObjectName!GLsync(sync) } if (GL_SYNC_FLUSH_COMMANDS_BIT in syncFlags) { } _ = timeout // TODO @@ -51,7 +51,7 @@ cmd void glDeleteSync(GLsync sync) { sub void DeleteSync(GLsync sync) { if sync != null { ctx := GetContext() - if !(sync in ctx.Objects.Shared.SyncObjects) { glErrorInvalidValue() } + if !(sync in ctx.Objects.Shared.SyncObjects) { glErrorInvalidValue!GLsync(sync) } delete(ctx.Objects.Shared.SyncObjects, sync) } } @@ -68,7 +68,7 @@ cmd GLsync glFenceSync(GLenum condition, GLbitfield syncFlags) { sub void FenceSync(GLenum condition, GLbitfield syncFlags, GLsync sync) { if condition != GL_SYNC_GPU_COMMANDS_COMPLETE { glErrorInvalidEnum(condition) } - if syncFlags != as!GLbitfield(0) { glErrorInvalidValue() } + CheckEQ!GLbitfield(syncFlags, as!GLbitfield(0)) ctx := GetContext() if (sync != null) { ctx.Objects.Shared.SyncObjects[sync] = new!SyncObject() @@ -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 timeout != 0xFFFFFFFFFFFFFFFF { glErrorInvalidValue() } // GL_TIMEOUT_IGNORED - if syncFlags != as!GLbitfield(0) { glErrorInvalidValue() } + if !(sync in ctx.Objects.Shared.SyncObjects) { + glErrorInvalidOperation_ObjectDoesNotExist!GLsync(sync) + } + CheckEQ!GLuint64(timeout, 0xFFFFFFFFFFFFFFFF) // GL_TIMEOUT_IGNORED + CheckEQ!GLbitfield(syncFlags, as!GLbitfield(0)) } diff --git a/gapis/api/gles/api/textures_and_samplers.api b/gapis/api/gles/api/textures_and_samplers.api index 5742cdf7ae..546192a0d8 100644 --- a/gapis/api/gles/api/textures_and_samplers.api +++ b/gapis/api/gles/api/textures_and_samplers.api @@ -252,7 +252,7 @@ sub SizedFormatInfo GetSizedFormatInfoOrEnumError(GLenum internalformat) { sub SizedFormatInfo GetSizedFormatInfoOrValueError(GLint internalformat) { info := GetSizedFormatInfo(as!GLenum(internalformat)) if info.UnsizedFormat == GL_NONE { - glErrorInvalidValue() + glErrorInvalidValue!GLint(internalformat) } return info } @@ -336,19 +336,19 @@ sub void TexImage(TexImageFlags flags, t := GetBoundTextureOrErrorInvalidEnum(target) // Check offsets and sizes - CheckNonNegative!GLint(loffset) - CheckNonNegative!GLint(xoffset) - CheckNonNegative!GLint(yoffset) - CheckNonNegative!GLint(zoffset) - if levels < 1 { glErrorInvalidValue() } - CheckNonNegative!GLsizei(width) - CheckNonNegative!GLsizei(height) - CheckNonNegative!GLsizei(depth) - if border != 0 { glErrorInvalidValue() } - CheckNonNegative!GLsizei(data_size) + CheckGE!GLint(loffset, 0) + CheckGE!GLint(xoffset, 0) + CheckGE!GLint(yoffset, 0) + CheckGE!GLint(zoffset, 0) + CheckGE!GLsizei(levels, 1) + CheckSizeGE!GLsizei(width, 0) + CheckSizeGE!GLsizei(height, 0) + CheckSizeGE!GLsizei(depth, 0) + CheckEQ!GLint(border, 0) + CheckGE!GLsizei(data_size, 0) switch target { case GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_CUBE_MAP, GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: { - if width != height { glErrorInvalidValue() } + CheckEQ!GLsizei(width, height) } default: { } } @@ -384,8 +384,8 @@ sub void TexImage(TexImageFlags flags, if hasSubModifier { i := t.Levels[loffset + l].Layers[zoffset + z + cubemap_layer] if (i == null) { glErrorInvalidOperation() } - if (as!GLsizei(xoffset) + width) > i.Width { glErrorInvalidValue() } - if (as!GLsizei(yoffset) + height) > i.Height { glErrorInvalidValue() } + CheckLE!GLsizei((as!GLsizei(xoffset) + width), i.Width) + CheckLE!GLsizei((as!GLsizei(yoffset) + height), i.Height) } } } @@ -550,7 +550,7 @@ cmd void glBindImageTexture(GLuint unit, cmd void glBindSampler(GLuint index, SamplerId sampler) { ctx := GetContext() tu := ctx.Objects.TextureUnits[as!TextureUnitId(index)] - if tu == null { glErrorInvalidValue() } + if tu == null { glErrorInvalidObjectName!SamplerId(sampler) } tu.SamplerBinding = GetOrCreateSampler(sampler) } @@ -854,7 +854,7 @@ sub void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoff @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glDeleteSamplers.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glDeleteSamplers.xhtml", Version.GLES32) cmd void glDeleteSamplers(GLsizei count, const SamplerId* samplers) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) s := samplers[0:count] ctx := GetContext() for i in (0 .. count) { @@ -872,7 +872,7 @@ cmd void glDeleteSamplers(GLsizei count, const SamplerId* samplers) { @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glDeleteTextures.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glDeleteTextures.xhtml", Version.GLES32) cmd void glDeleteTextures(GLsizei count, const TextureId* textures) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) t := textures[0:count] ctx := GetContext() for i in (0 .. count) { @@ -890,7 +890,7 @@ cmd void glDeleteTextures(GLsizei count, const TextureId* textures) { @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glGenSamplers.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGenSamplers.xhtml", Version.GLES32) cmd void glGenSamplers(GLsizei count, SamplerId* samplers) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) s := samplers[0:count] ctx := GetContext() for i in (0 .. count) { @@ -907,7 +907,7 @@ cmd void glGenSamplers(GLsizei count, SamplerId* samplers) { @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glGenTextures.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGenTextures.xhtml", Version.GLES32) cmd void glGenTextures(GLsizei count, TextureId* textures) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) t := textures[0:count] ctx := GetContext() for i in (0 .. count) { @@ -1265,12 +1265,12 @@ cmd GLboolean glIsTexture(TextureId texture) { @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glPixelStorei.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glPixelStorei.xhtml", Version.GLES32) cmd void glPixelStorei(GLenum parameter, GLint value) { - CheckNonNegative!GLint(value) + CheckGE!GLint(value, 0) ctx := GetContext() switch (parameter) { @if(Version.GLES20) case GL_PACK_ALIGNMENT: { - if (value != 1) && (value != 2) && (value != 4) && (value != 8) { glErrorInvalidValue() } + if (value != 1) && (value != 2) && (value != 4) && (value != 8) { glErrorInvalidValue!GLint(value) } ctx.Other.Pack.Alignment = value } @if(Version.GLES30) @@ -1295,7 +1295,7 @@ cmd void glPixelStorei(GLenum parameter, GLint value) { } @if(Version.GLES20) case GL_UNPACK_ALIGNMENT: { - if (value != 1) && (value != 2) && (value != 4) && (value != 8) { glErrorInvalidValue() } + if (value != 1) && (value != 2) && (value != 4) && (value != 8) { glErrorInvalidValue!GLint(value) } ctx.Other.Unpack.Alignment = value } @if(Version.GLES30) @@ -1586,7 +1586,7 @@ sub void TexParameterv!T(GLenum target, GLenum pname, T params) { @if(Version.GLES30) case GL_TEXTURE_BASE_LEVEL: { baseLevel := as!GLint(params[0]) - CheckNonNegative!GLint(baseLevel) + CheckGE!GLint(baseLevel, 0) t.BaseLevel = baseLevel } @if(Version.GLES30 || Extension.GL_EXT_shadow_samplers) @@ -1600,7 +1600,7 @@ sub void TexParameterv!T(GLenum target, GLenum pname, T params) { @if(Version.GLES30) case GL_TEXTURE_MAX_LEVEL: { maxLevel := as!GLint(params[0]) - CheckNonNegative!GLint(maxLevel) + CheckGE!GLint(maxLevel, 0) t.MaxLevel = maxLevel } @if(Version.GLES30) diff --git a/gapis/api/gles/api/transform_feedback.api b/gapis/api/gles/api/transform_feedback.api index 353f0db6df..a3bd7b9f0f 100644 --- a/gapis/api/gles/api/transform_feedback.api +++ b/gapis/api/gles/api/transform_feedback.api @@ -70,11 +70,11 @@ sub ref!TransformFeedback GetOrCreateTransformFeedback(TransformFeedbackId id) { @doc("https://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteTransformFeedbacks.xhtml", Version.GLES30) @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glDeleteTransformFeedbacks.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glDeleteTransformFeedbacks.xhtml", Version.GLES32) -cmd void glDeleteTransformFeedbacks(GLsizei n, const TransformFeedbackId* ids) { - CheckNonNegative!GLsizei(n) - tfs := ids[0:n] +cmd void glDeleteTransformFeedbacks(GLsizei count, const TransformFeedbackId* ids) { + CheckCountGE!GLsizei(count, 0) + tfs := ids[0:count] ctx := GetContext() - for i in (0 .. n) { + for i in (0 .. count) { id := tfs[i] if id != 0 { delete(ctx.Objects.TransformFeedbacks, id) @@ -97,11 +97,11 @@ cmd void glEndTransformFeedback() { @doc("https://www.khronos.org/opengles/sdk/docs/man3/html/glGenTransformFeedbacks.xhtml", Version.GLES30) @doc("https://www.khronos.org/opengles/sdk/docs/man31/html/glGenTransformFeedbacks.xhtml", Version.GLES31) @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGenTransformFeedbacks.xhtml", Version.GLES32) -cmd void glGenTransformFeedbacks(GLsizei n, TransformFeedbackId* ids) { - CheckNonNegative!GLsizei(n) - tfs := ids[0:n] +cmd void glGenTransformFeedbacks(GLsizei count, TransformFeedbackId* ids) { + CheckCountGE!GLsizei(count, 0) + tfs := ids[0:count] ctx := GetContext() - for i in (0 .. n) { + for i in (0 .. count) { id := as!TransformFeedbackId(?) assert(id != 0) ctx.Objects.GeneratedNames.TransformFeedbacks[id] = true diff --git a/gapis/api/gles/api/util.api b/gapis/api/gles/api/util.api index 0758c17f05..7dfb155c0f 100644 --- a/gapis/api/gles/api/util.api +++ b/gapis/api/gles/api/util.api @@ -37,3 +37,10 @@ sub T min!T(T a, T b) { case false: b } } + +sub T max!T(T a, T b) { + return switch a > b { + case true: a + case false: b + } +} diff --git a/gapis/api/gles/api/vertex_arrays.api b/gapis/api/gles/api/vertex_arrays.api index 14acea2069..8a7a349947 100644 --- a/gapis/api/gles/api/vertex_arrays.api +++ b/gapis/api/gles/api/vertex_arrays.api @@ -60,6 +60,18 @@ class VertexAttributeValue { @unused u8[] Value // Used if VertexAttributeArray is disabled. } +sub void CheckAttributeLocation(AttributeLocation location) { + ctx := GetContext() + 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 @@ -186,18 +198,11 @@ sub void BindVertexArray(VertexArrayId array) { } sub void BindVertexBuffer(ref!Context ctx, VertexBufferBindingIndex binding_index, BufferId buffer, GLintptr offset, GLsizei stride) { - if offset < 0 { glErrorInvalidValueMsg(new!ERR_VALUE_NEG("offset", as!s64(offset))) } - if stride < 0 { glErrorInvalidValueMsg(new!ERR_VALUE_NEG("stride", as!s64(stride))) } + CheckGE!GLintptr(offset, 0) + CheckGE!GLsizei(stride, 0) if VersionGreaterOrEqual(ctx, 3, 1) { - if as!s64(binding_index) >= as!s64(ctx.Constants.MaxVertexAttribBindings) { - glErrorInvalidValueMsg(new!ERR_VALUE_GE_LIMIT( - "binding index", "GL_MAX_VERTEX_ATTRIB_BINDINGS", - as!s64(binding_index), as!s64(ctx.Constants.MaxVertexAttribBindings))) - } - if as!s64(stride) >= as!s64(ctx.Constants.MaxVertexAttribStride) { - glErrorInvalidValueMsg(new!ERR_VALUE_GE_LIMIT( "stride", "GL_MAX_VERTEX_ATTRIB_STRIDE", - as!s64(stride), as!s64(ctx.Constants.MaxVertexAttribStride))) - } + CheckLT!VertexBufferBindingIndex(binding_index, as!VertexBufferBindingIndex(ctx.Constants.MaxVertexAttribBindings)) + CheckLT!GLsizei(stride, as!GLsizei(ctx.Constants.MaxVertexAttribStride)) } _ = GetOrCreateBuffer(buffer) vao := ctx.Bound.VertexArray @@ -212,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) } @@ -225,7 +230,7 @@ cmd void glDeleteVertexArrays(GLsizei count, const VertexArrayId* arrays) { } sub void DeleteVertexArrays(GLsizei count, const VertexArrayId* arrays) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) ctx := GetContext() a := arrays[0:count] for i in (0 .. count) { @@ -250,7 +255,7 @@ sub void DeleteVertexArrays(GLsizei count, const VertexArrayId* arrays) { @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glEnableVertexAttribArray.xhtml", Version.GLES32) cmd void glDisableVertexAttribArray(AttributeLocation location) { ctx := GetContext() - if location >= as!AttributeLocation(ctx.Constants.MaxVertexAttribs) { glErrorInvalidValue() } + CheckAttributeLocation(location) vao := ctx.Bound.VertexArray vao.VertexAttributeArrays[location].Enabled = GL_FALSE } @@ -262,7 +267,7 @@ cmd void glDisableVertexAttribArray(AttributeLocation location) { @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glEnableVertexAttribArray.xhtml", Version.GLES32) cmd void glEnableVertexAttribArray(AttributeLocation location) { ctx := GetContext() - if location >= as!AttributeLocation(ctx.Constants.MaxVertexAttribs) { glErrorInvalidValue() } + CheckAttributeLocation(location) vao := ctx.Bound.VertexArray vao.VertexAttributeArrays[location].Enabled = GL_TRUE } @@ -276,7 +281,7 @@ cmd void glGenVertexArrays(GLsizei count, VertexArrayId* arrays) { } sub void GenVertexArrays(GLsizei count, VertexArrayId* arrays) { - CheckNonNegative!GLsizei(count) + CheckCountGE!GLsizei(count, 0) ctx := GetContext() a := arrays[0:count] for i in (0 .. count) { @@ -293,7 +298,7 @@ sub void GenVertexArrays(GLsizei count, VertexArrayId* arrays) { @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGetVertexAttrib.xhtml", Version.GLES32) cmd void glGetVertexAttribIiv(AttributeLocation index, GLenum pname, GLint* params) { ctx := GetContext() - if index >= as!AttributeLocation(ctx.Constants.MaxVertexAttribs) { glErrorInvalidValue() } + CheckAttributeLocation(index) if pname == GL_CURRENT_VERTEX_ATTRIB { // attr := ctx.Vertex.Attributes[index] // TODO: params[0:4] = as!GLint[](attr.Value)[0:4] @@ -309,7 +314,7 @@ cmd void glGetVertexAttribIiv(AttributeLocation index, GLenum pname, GLint* para @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGetVertexAttrib.xhtml", Version.GLES32) cmd void glGetVertexAttribIuiv(AttributeLocation index, GLenum pname, GLuint* params) { ctx := GetContext() - if index >= as!AttributeLocation(ctx.Constants.MaxVertexAttribs) { glErrorInvalidValue() } + CheckAttributeLocation(index) if pname == GL_CURRENT_VERTEX_ATTRIB { // attr := ctx.Vertex.Attributes[index] // TODO: params[0:4] = as!GLuint[](attr.Value)[0:4] @@ -326,7 +331,7 @@ cmd void glGetVertexAttribIuiv(AttributeLocation index, GLenum pname, GLuint* pa @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGetVertexAttribPointerv.xhtml", Version.GLES32) cmd void glGetVertexAttribPointerv(AttributeLocation index, GLenum pname, void** pointer) { ctx := GetContext() - if index >= as!AttributeLocation(ctx.Constants.MaxVertexAttribs) { glErrorInvalidValue() } + CheckAttributeLocation(index) if pname != GL_VERTEX_ATTRIB_ARRAY_POINTER { glErrorInvalidEnum(pname) } vao := ctx.Bound.VertexArray pointer[0] = as!void*(vao.VertexAttributeArrays[index].Pointer) @@ -339,7 +344,7 @@ cmd void glGetVertexAttribPointerv(AttributeLocation index, GLenum pname, void** @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGetVertexAttrib.xhtml", Version.GLES32) cmd void glGetVertexAttribfv(AttributeLocation index, GLenum pname, GLfloat* params) { ctx := GetContext() - if index >= as!AttributeLocation(ctx.Constants.MaxVertexAttribs) { glErrorInvalidValue() } + CheckAttributeLocation(index) if pname == GL_CURRENT_VERTEX_ATTRIB { // TODO: params[0:4] = as!GLfloat[](attr.Value)[0:4] // attr := ctx.Vertex.Attributes[index] @@ -356,7 +361,7 @@ cmd void glGetVertexAttribfv(AttributeLocation index, GLenum pname, GLfloat* par @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glGetVertexAttrib.xhtml", Version.GLES32) cmd void glGetVertexAttribiv(AttributeLocation index, GLenum pname, GLint* params) { ctx := GetContext() - if index >= as!AttributeLocation(ctx.Constants.MaxVertexAttribs) { glErrorInvalidValue() } + CheckAttributeLocation(index) if pname == GL_CURRENT_VERTEX_ATTRIB { // TODO: params[0:4] = as!GLint[](attr.Value)[0:4] // attr := ctx.Vertex.Attributes[index] @@ -381,7 +386,7 @@ sub GLboolean IsVertexArray(VertexArrayId array) { sub void VertexAttribF(AttributeLocation location, Vec4f value) { ctx := GetContext() - if location >= as!AttributeLocation(ctx.Constants.MaxVertexAttribs) { glErrorInvalidValue() } + CheckAttributeLocation(location) vals := make!Vec4f(1) vals[0] = value ctx.Vertex.Attributes[location] = VertexAttributeValue(Value: as!u8[](vals)) @@ -476,16 +481,8 @@ cmd void glVertexAttrib4fv(AttributeLocation location, const GLfloat* value) { sub void VertexAttribBinding(ref!Context ctx, AttributeLocation index, VertexBufferBindingIndex binding_index) { if VersionGreaterOrEqual(ctx, 3, 1) { - if as!s64(index) > as!s64(ctx.Constants.MaxVertexAttribs) { - glErrorInvalidValueMsg(new!ERR_VALUE_GE_LIMIT( - "index", "GL_MAX_VERTEX_ATTRIBS", - as!s64(index), as!s64(ctx.Constants.MaxVertexAttribs))) - } - if as!s64(binding_index) > as!s64(ctx.Constants.MaxVertexAttribBindings) { - glErrorInvalidValueMsg(new!ERR_VALUE_GE_LIMIT( - "binding_index", "GL_MAX_VERTEX_ATTRIB_BINDINGS", - as!s64(binding_index), as!s64(ctx.Constants.MaxVertexAttribBindings))) - } + CheckAttributeLocation(index) + CheckLT!VertexBufferBindingIndex(binding_index, as!VertexBufferBindingIndex(ctx.Constants.MaxVertexAttribBindings)) } // NB: Some callers may use the default VertexArray and some may not. // Therefore the caller should do the check if it is needed. @@ -498,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) } @@ -525,12 +522,8 @@ sub void VertexAttribFormat(ref!Context ctx, GLboolean normalized, GLuint relativeOffset, bool integer) { - if as!s64(index) >= as!s64(ctx.Constants.MaxVertexAttribs) { - glErrorInvalidValueMsg(new!ERR_VALUE_GE_LIMIT( - "index", "GL_MAX_VERTEX_ATTRIBS", - as!s64(index), as!s64(ctx.Constants.MaxVertexAttribs))) - } - if !((1 <= size) && (size <= 4)) { glErrorInvalidValue() } + CheckAttributeLocation(index) + if !((1 <= size) && (size <= 4)) { glErrorInvalidValue!GLint(size) } if (integer) { switch (type) { @if(Version.GLES30) @@ -563,7 +556,7 @@ sub void VertexAttribFormat(ref!Context ctx, // NB: Some callers may use the default VertexArray and some may not. // Therefore the caller should do the check if it is needed. if VersionGreaterOrEqual(ctx, 3, 1) { - if relativeOffset > as!GLuint(ctx.Constants.MaxVertexAttribRelativeOffset) { glErrorInvalidValue() } + CheckLE!GLuint(relativeOffset, as!GLuint(ctx.Constants.MaxVertexAttribRelativeOffset)) } vao := ctx.Bound.VertexArray format := vao.VertexAttributeArrays[index] @@ -585,13 +578,13 @@ cmd void glVertexAttribFormat(AttributeLocation index, GLboolean normalized, GLuint relativeoffset) { ctx := GetContext() - if IsDefaultVertexArrayBound() { glErrorInvalidOperation() } + CheckNonDefaultVertexArrayBound() VertexAttribFormat(ctx, index, size, type, normalized, relativeoffset, false) } sub void VertexAttribI(AttributeLocation location, Vec4i value) { ctx := GetContext() - if location >= as!AttributeLocation(ctx.Constants.MaxVertexAttribs) { glErrorInvalidValue() } + CheckAttributeLocation(location) vals := make!Vec4i(1) vals[0] = value ctx.Vertex.Attributes[location] = VertexAttributeValue(Value: as!u8[](vals)) @@ -638,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) } @@ -710,8 +703,8 @@ cmd void glVertexAttribPointer(AttributeLocation location, @doc("https://www.khronos.org/opengles/sdk/docs/man32/html/glVertexBindingDivisor.xhtml", Version.GLES32) cmd void glVertexBindingDivisor(VertexBufferBindingIndex binding_index, GLuint divisor) { ctx := GetContext() - if binding_index >= as!VertexBufferBindingIndex(ctx.Constants.MaxVertexAttribBindings) { glErrorInvalidValue() } - if IsDefaultVertexArrayBound() { glErrorInvalidOperation() } + CheckLT!VertexBufferBindingIndex(binding_index, as!VertexBufferBindingIndex(ctx.Constants.MaxVertexAttribBindings)) + CheckNonDefaultVertexArrayBound() vao := ctx.Bound.VertexArray vao.VertexBufferBindings[binding_index].Divisor = divisor } diff --git a/gapis/api/gles/gles.api b/gapis/api/gles/gles.api index 080f9aff90..095f560943 100644 --- a/gapis/api/gles/gles.api +++ b/gapis/api/gles/gles.api @@ -21,6 +21,7 @@ import "api/buffer_objects.api" import "api/constants.api" import "api/egl.api" import "api/eglenum.api" +import "api/errors.api" import "api/debug.api" import "api/draw_commands.api" import "api/extensions.api" @@ -48,55 +49,6 @@ import "../../messages/messages.api" extern void mapMemory(u8[] slice) extern void unmapMemory(u8[] slice) -extern void onGlError(GLenum v) - -sub void supportsBits(GLbitfield seenBits, GLbitfield validBits) { - if (seenBits & validBits) != seenBits { glErrorInvalidValue() } -} - -sub void glErrorInvalidEnum(GLenum value) { - glErrorInvalidEnumMsg(new!ERR_INVALID_ENUM(value: as!u32(value))) -} - -sub void glErrorInvalidEnumMsg(message m) { - onGlError(GL_INVALID_ENUM) - _ = newMsg(SEVERITY_ERROR, m) - abort -} - -sub void glErrorInvalidValue() { - glErrorInvalidValueMsg(new!ERR_INVALID_VALUE()) -} - -sub void glErrorInvalidValueMsg(message m) { - onGlError(GL_INVALID_VALUE) - _ = newMsg(SEVERITY_ERROR, m) - abort -} - -sub void glErrorInvalidOperation() { - glErrorInvalidOperationMsg(new!ERR_INVALID_OPERATION()) -} - -sub void glErrorInvalidOperationMsg(message m) { - onGlError(GL_INVALID_OPERATION) - _ = newMsg(SEVERITY_ERROR, m) - abort -} - -sub void CheckNonNegative!T(T param) { - if param < 0 { - glErrorInvalidValueMsg(new!ERR_INVALID_VALUE_NEGATIVE(value: as!s64(param))) - } -} - -sub T max!T(T a, T b) { - return switch a > b { - case true: a - case false: b - } -} - // Flags which are set if the context supports given GLES version @internal class Versions { diff --git a/gapis/messages/en-us.stb.md b/gapis/messages/en-us.stb.md index 881295adbb..99aa48a218 100644 --- a/gapis/messages/en-us.stb.md +++ b/gapis/messages/en-us.stb.md @@ -25,11 +25,47 @@ The slice {{from_value}}:{{to_value}} for {{from_variable}}:{{to_variable}} is o # ERR_INVALID_VALUE -Invalid value. +Invalid value {{value:s64}}. -# ERR_INVALID_VALUE_NEGATIVE +# ERR_INVALID_OBJECT_NAME -Invalid value {{value:s64}}: The value must be positive or zero. +Invalid value {{value:s64}}. Object with this name does not exist. + +# ERR_INVALID_VALUE_CHECK_EQ + +Invalid value {{value:s64}}. It must be {{constraint:s64}}. + +# ERR_INVALID_VALUE_CHECK_NE + +Invalid value {{value:s64}}. It must not be {{constraint:s64}}. + +# ERR_INVALID_VALUE_CHECK_GE + +Invalid value {{value:s64}}. It must be greater than or equal to {{constraint:s64}}. + +# ERR_INVALID_VALUE_CHECK_GT + +Invalid value {{value:s64}}. It must be greater than {{constraint:s64}}. + +# ERR_INVALID_VALUE_CHECK_LE + +Invalid value {{value:s64}}. It must be less than or equal to {{constraint:s64}}. + +# ERR_INVALID_VALUE_CHECK_LT + +Invalid value {{value:s64}}. It must be less than {{constraint:s64}}. + +# ERR_INVALID_VALUE_CHECK_LOCATION_LT + +Invalid value {{value:s64}}. Location must be less than {{constraint:s64}}. + +# ERR_INVALID_VALUE_CHECK_COUNT_GE + +Invalid value {{value:s64}}. Count must be greater than or equal to {{constraint:s64}}. + +# ERR_INVALID_VALUE_CHECK_SIZE_GE + +Invalid value {{value:s64}}. Size must be greater than or equal to {{constraint:s64}}. # ERR_INVALID_ENUM @@ -39,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.