Hash :
a825eb70
Author :
Date :
2019-11-21T11:37:17
Implement BaseVertex draw calls for Vulkan, OpenGL, NULL contexts. This adds support for the following functions: - glDrawElementsBaseVertex - glDrawRangeElementsBaseVertex - glDrawElementsInstancedBaseVertex Bug: angleproject:3582 Bug: angleproject:3402 Bug: angleproject:4166 Change-Id: I83770f62e3a918c0965fd4ca8c7d9e598b8b4154 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1929083 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// validationESEXT.cpp: Validation functions for OpenGL ES extension entry points.
#include "libANGLE/validationESEXT_autogen.h"
#include "libANGLE/Context.h"
#include "libANGLE/ErrorStrings.h"
#include "libANGLE/validationES.h"
namespace gl
{
using namespace err;
namespace
{
template <typename ObjectT>
bool ValidateGetImageFormatAndType(Context *context, ObjectT *obj, GLenum format, GLenum type)
{
GLenum implFormat = obj->getImplementationColorReadFormat(context);
if (!ValidES3Format(format) && (format != implFormat || format == GL_NONE))
{
context->validationError(GL_INVALID_ENUM, kInvalidFormat);
return false;
}
GLenum implType = obj->getImplementationColorReadType(context);
if (!ValidES3Type(type) && (type != implType || type == GL_NONE))
{
context->validationError(GL_INVALID_ENUM, kInvalidType);
return false;
}
// Format/type combinations are not yet validated.
return true;
}
} // namespace
bool ValidateGetTexImageANGLE(Context *context,
TextureTarget target,
GLint level,
GLenum format,
GLenum type,
void *pixels)
{
if (!context->getExtensions().getImageANGLE)
{
context->validationError(GL_INVALID_OPERATION, kGetImageExtensionNotEnabled);
return false;
}
if (!ValidTexture2DDestinationTarget(context, target) &&
!ValidTexture3DDestinationTarget(context, target))
{
context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
return false;
}
if (level < 0)
{
context->validationError(GL_INVALID_VALUE, kNegativeLevel);
return false;
}
TextureType textureType = TextureTargetToType(target);
if (!ValidMipLevel(context, textureType, level))
{
context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
return false;
}
Texture *texture = context->getTextureByTarget(target);
if (!ValidateGetImageFormatAndType(context, texture, format, type))
{
return false;
}
GLsizei width = static_cast<GLsizei>(texture->getWidth(target, level));
GLsizei height = static_cast<GLsizei>(texture->getHeight(target, level));
if (!ValidatePixelPack(context, format, type, 0, 0, width, height, -1, nullptr, pixels))
{
return false;
}
return true;
}
bool ValidateGetRenderbufferImageANGLE(Context *context,
GLenum target,
GLenum format,
GLenum type,
void *pixels)
{
if (!context->getExtensions().getImageANGLE)
{
context->validationError(GL_INVALID_OPERATION, kGetImageExtensionNotEnabled);
return false;
}
if (target != GL_RENDERBUFFER)
{
context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
return false;
}
Renderbuffer *renderbuffer = context->getState().getCurrentRenderbuffer();
if (!ValidateGetImageFormatAndType(context, renderbuffer, format, type))
{
return false;
}
GLsizei width = renderbuffer->getWidth();
GLsizei height = renderbuffer->getHeight();
if (!ValidatePixelPack(context, format, type, 0, 0, width, height, -1, nullptr, pixels))
{
return false;
}
return true;
}
bool ValidateDrawElementsBaseVertexEXT(Context *context,
PrimitiveMode mode,
GLsizei count,
DrawElementsType type,
const void *indices,
GLint basevertex)
{
if (!context->getExtensions().drawElementsBaseVertexAny())
{
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
return false;
}
return ValidateDrawElementsCommon(context, mode, count, type, indices, 1);
}
bool ValidateDrawElementsInstancedBaseVertexEXT(Context *context,
PrimitiveMode mode,
GLsizei count,
DrawElementsType type,
const void *indices,
GLsizei instancecount,
GLint basevertex)
{
if (!context->getExtensions().drawElementsBaseVertexAny())
{
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
return false;
}
return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, instancecount);
}
bool ValidateDrawRangeElementsBaseVertexEXT(Context *context,
PrimitiveMode mode,
GLuint start,
GLuint end,
GLsizei count,
DrawElementsType type,
const void *indices,
GLint basevertex)
{
if (!context->getExtensions().drawElementsBaseVertexAny())
{
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
return false;
}
if (end < start)
{
context->validationError(GL_INVALID_VALUE, kInvalidElementRange);
return false;
}
if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0))
{
return false;
}
// Skip range checks for no-op calls.
if (count <= 0)
{
return true;
}
// Note that resolving the index range is a bit slow. We should probably optimize this.
IndexRange indexRange;
ANGLE_VALIDATION_TRY(context->getState().getVertexArray()->getIndexRange(context, type, count,
indices, &indexRange));
if (indexRange.end > end || indexRange.start < start)
{
// GL spec says that behavior in this case is undefined - generating an error is fine.
context->validationError(GL_INVALID_OPERATION, kExceedsElementRange);
return false;
}
return true;
}
bool ValidateMultiDrawElementsBaseVertexEXT(Context *context,
PrimitiveMode mode,
const GLsizei *count,
DrawElementsType type,
const void *const *indices,
GLsizei drawcount,
const GLint *basevertex)
{
return true;
}
bool ValidateDrawElementsBaseVertexOES(Context *context,
PrimitiveMode mode,
GLsizei count,
DrawElementsType type,
const void *indices,
GLint basevertex)
{
if (!context->getExtensions().drawElementsBaseVertexAny())
{
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
return false;
}
return ValidateDrawElementsCommon(context, mode, count, type, indices, 1);
}
bool ValidateDrawElementsInstancedBaseVertexOES(Context *context,
PrimitiveMode mode,
GLsizei count,
DrawElementsType type,
const void *indices,
GLsizei instancecount,
GLint basevertex)
{
if (!context->getExtensions().drawElementsBaseVertexAny())
{
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
return false;
}
return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, instancecount);
}
bool ValidateDrawRangeElementsBaseVertexOES(Context *context,
PrimitiveMode mode,
GLuint start,
GLuint end,
GLsizei count,
DrawElementsType type,
const void *indices,
GLint basevertex)
{
if (!context->getExtensions().drawElementsBaseVertexAny())
{
context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled);
return false;
}
if (end < start)
{
context->validationError(GL_INVALID_VALUE, kInvalidElementRange);
return false;
}
if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0))
{
return false;
}
// Skip range checks for no-op calls.
if (count <= 0)
{
return true;
}
// Note that resolving the index range is a bit slow. We should probably optimize this.
IndexRange indexRange;
ANGLE_VALIDATION_TRY(context->getState().getVertexArray()->getIndexRange(context, type, count,
indices, &indexRange));
if (indexRange.end > end || indexRange.start < start)
{
// GL spec says that behavior in this case is undefined - generating an error is fine.
context->validationError(GL_INVALID_OPERATION, kExceedsElementRange);
return false;
}
return true;
}
} // namespace gl