Hash :
d779f6a9
Author :
Date :
2018-03-23T01:44:33
D3D11: Refactor draw call functions. This allow for better code reuse for the Indirect draw calls. It also cleans up the InputLayoutCache to be only responsible for caching input layouts, and moves the logic for maintaining state into StateManager11. Bug: angleproject:2389 Change-Id: I84aae164bf1b94a394743cf58650adfdcfc2c17a Reviewed-on: https://chromium-review.googlesource.com/948796 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
//
// Copyright 2017 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.
//
// params:
// Parameter wrapper structs for OpenGL ES. These helpers cache re-used values
// in entry point routines.
#ifndef LIBANGLE_PARAMS_H_
#define LIBANGLE_PARAMS_H_
#include "angle_gl.h"
#include "common/Optional.h"
#include "common/angleutils.h"
#include "common/mathutil.h"
#include "libANGLE/Error.h"
#include "libANGLE/entry_points_enum_autogen.h"
namespace gl
{
class Context;
template <EntryPoint EP>
struct EntryPointParam;
template <EntryPoint EP>
using EntryPointParamType = typename EntryPointParam<EP>::Type;
class ParamTypeInfo
{
public:
constexpr ParamTypeInfo(const char *selfClass, const ParamTypeInfo *parentType)
: mSelfClass(selfClass), mParentTypeInfo(parentType)
{
}
constexpr bool hasDynamicType(const ParamTypeInfo &typeInfo) const
{
return mSelfClass == typeInfo.mSelfClass ||
(mParentTypeInfo && mParentTypeInfo->hasDynamicType(typeInfo));
}
constexpr bool isValid() const { return mSelfClass != nullptr; }
private:
const char *mSelfClass;
const ParamTypeInfo *mParentTypeInfo;
};
#define ANGLE_PARAM_TYPE_INFO(NAME, BASENAME) \
static constexpr ParamTypeInfo TypeInfo = {#NAME, &BASENAME::TypeInfo}
class ParamsBase : angle::NonCopyable
{
public:
ParamsBase(Context *context, ...){};
template <EntryPoint EP, typename... ArgsT>
static void Factory(EntryPointParamType<EP> *objBuffer, ArgsT... args);
static constexpr ParamTypeInfo TypeInfo = {nullptr, nullptr};
};
// static
template <EntryPoint EP, typename... ArgsT>
ANGLE_INLINE void ParamsBase::Factory(EntryPointParamType<EP> *objBuffer, ArgsT... args)
{
new (objBuffer) EntryPointParamType<EP>(args...);
}
// Helper class that encompasses draw call parameters. It uses the HasIndexRange
// helper class to only pull index range info lazily to prevent unnecessary readback.
// It is also used when syncing state for the VertexArray implementation, since the
// vertex and index buffer updates depend on draw call parameters.
class DrawCallParams final : angle::NonCopyable
{
public:
// Called by DrawArrays.
DrawCallParams(GLenum mode, GLint firstVertex, GLsizei vertexCount, GLsizei instances);
// Called by DrawElements.
DrawCallParams(GLenum mode,
GLint indexCount,
GLenum type,
const void *indices,
GLint baseVertex,
GLsizei instances);
// Called by DrawArraysIndirect.
DrawCallParams(GLenum mode, const void *indirect);
// Called by DrawElementsIndirect.
DrawCallParams(GLenum mode, GLenum type, const void *indirect);
GLenum mode() const;
// This value is the sum of 'baseVertex' and the first indexed vertex for DrawElements calls.
GLint firstVertex() const;
GLsizei vertexCount() const;
GLsizei indexCount() const;
GLint baseVertex() const;
GLenum type() const;
const void *indices() const;
GLsizei instances() const;
const void *indirect() const;
Error ensureIndexRangeResolved(const Context *context) const;
bool isDrawElements() const;
bool isDrawIndirect() const;
// ensureIndexRangeResolved must be called first.
const IndexRange &getIndexRange() const;
template <EntryPoint EP, typename... ArgsT>
static void Factory(DrawCallParams *objBuffer, ArgsT... args);
ANGLE_PARAM_TYPE_INFO(DrawCallParams, ParamsBase);
private:
GLenum mMode;
mutable Optional<IndexRange> mIndexRange;
mutable GLint mFirstVertex;
mutable GLsizei mVertexCount;
GLint mIndexCount;
GLint mBaseVertex;
GLenum mType;
const void *mIndices;
GLsizei mInstances;
const void *mIndirect;
};
// Entry point funcs essentially re-map different entry point parameter arrays into
// the format the parameter type class expects. For example, for HasIndexRange, for the
// various indexed draw calls, they drop parameters that aren't useful and re-arrange
// the rest.
#define ANGLE_ENTRY_POINT_FUNC(NAME, CLASS, ...) \
\
template<> struct EntryPointParam<EntryPoint::NAME> \
{ \
using Type = CLASS; \
}; \
\
template<> inline void CLASS::Factory<EntryPoint::NAME>(__VA_ARGS__)
ANGLE_ENTRY_POINT_FUNC(DrawArrays,
DrawCallParams,
DrawCallParams *objBuffer,
Context *context,
GLenum mode,
GLint first,
GLsizei count)
{
return ParamsBase::Factory<EntryPoint::DrawArrays>(objBuffer, mode, first, count, 0);
}
ANGLE_ENTRY_POINT_FUNC(DrawArraysInstanced,
DrawCallParams,
DrawCallParams *objBuffer,
Context *context,
GLenum mode,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
return ParamsBase::Factory<EntryPoint::DrawArraysInstanced>(objBuffer, mode, first, count,
instanceCount);
}
ANGLE_ENTRY_POINT_FUNC(DrawArraysInstancedANGLE,
DrawCallParams,
DrawCallParams *objBuffer,
Context *context,
GLenum mode,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
return ParamsBase::Factory<EntryPoint::DrawArraysInstancedANGLE>(objBuffer, mode, first, count,
instanceCount);
}
ANGLE_ENTRY_POINT_FUNC(DrawArraysIndirect,
DrawCallParams,
DrawCallParams *objBuffer,
Context *context,
GLenum mode,
const void *indirect)
{
return ParamsBase::Factory<EntryPoint::DrawArraysIndirect>(objBuffer, mode, indirect);
}
ANGLE_ENTRY_POINT_FUNC(DrawElementsIndirect,
DrawCallParams,
DrawCallParams *objBuffer,
Context *context,
GLenum mode,
GLenum type,
const void *indirect)
{
return ParamsBase::Factory<EntryPoint::DrawElementsIndirect>(objBuffer, mode, type, indirect);
}
ANGLE_ENTRY_POINT_FUNC(DrawElements,
DrawCallParams,
DrawCallParams *objBuffer,
Context *context,
GLenum mode,
GLsizei count,
GLenum type,
const void *indices)
{
return ParamsBase::Factory<EntryPoint::DrawElements>(objBuffer, mode, count, type, indices, 0,
0);
}
ANGLE_ENTRY_POINT_FUNC(DrawElementsInstanced,
DrawCallParams,
DrawCallParams *objBuffer,
Context *context,
GLenum mode,
GLsizei count,
GLenum type,
const void *indices,
GLsizei instanceCount)
{
return ParamsBase::Factory<EntryPoint::DrawElementsInstanced>(objBuffer, mode, count, type,
indices, 0, instanceCount);
}
ANGLE_ENTRY_POINT_FUNC(DrawElementsInstancedANGLE,
DrawCallParams,
DrawCallParams *objBuffer,
Context *context,
GLenum mode,
GLsizei count,
GLenum type,
const void *indices,
GLsizei instanceCount)
{
return ParamsBase::Factory<EntryPoint::DrawElementsInstancedANGLE>(objBuffer, mode, count, type,
indices, 0, instanceCount);
}
ANGLE_ENTRY_POINT_FUNC(DrawRangeElements,
DrawCallParams,
DrawCallParams *objBuffer,
Context *context,
GLenum mode,
GLuint /*start*/,
GLuint /*end*/,
GLsizei count,
GLenum type,
const void *indices)
{
return ParamsBase::Factory<EntryPoint::DrawRangeElements>(objBuffer, mode, count, type, indices,
0, 0);
}
#undef ANGLE_ENTRY_POINT_FUNC
template <EntryPoint EP>
struct EntryPointParam
{
using Type = ParamsBase;
};
// A template struct for determining the default value to return for each entry point.
template <EntryPoint EP, typename ReturnType>
struct DefaultReturnValue;
// Default return values for each basic return type.
template <EntryPoint EP>
struct DefaultReturnValue<EP, GLint>
{
static constexpr GLint kValue = -1;
};
// This doubles as the GLenum return value.
template <EntryPoint EP>
struct DefaultReturnValue<EP, GLuint>
{
static constexpr GLuint kValue = 0;
};
template <EntryPoint EP>
struct DefaultReturnValue<EP, GLboolean>
{
static constexpr GLboolean kValue = GL_FALSE;
};
// Catch-all rules for pointer types.
template <EntryPoint EP, typename PointerType>
struct DefaultReturnValue<EP, const PointerType *>
{
static constexpr const PointerType *kValue = nullptr;
};
template <EntryPoint EP, typename PointerType>
struct DefaultReturnValue<EP, PointerType *>
{
static constexpr PointerType *kValue = nullptr;
};
// Overloaded to return invalid index
template <>
struct DefaultReturnValue<EntryPoint::GetUniformBlockIndex, GLuint>
{
static constexpr GLuint kValue = GL_INVALID_INDEX;
};
// Specialized enum error value.
template <>
struct DefaultReturnValue<EntryPoint::ClientWaitSync, GLenum>
{
static constexpr GLenum kValue = GL_WAIT_FAILED;
};
// glTestFenceNV should still return TRUE for an invalid fence.
template <>
struct DefaultReturnValue<EntryPoint::TestFenceNV, GLboolean>
{
static constexpr GLboolean kValue = GL_TRUE;
};
template <EntryPoint EP, typename ReturnType>
constexpr ANGLE_INLINE ReturnType GetDefaultReturnValue()
{
return DefaultReturnValue<EP, ReturnType>::kValue;
}
} // namespace gl
#endif // LIBANGLE_PARAMS_H_