Hash :
62fcf62a
Author :
Date :
2017-11-30T16:16:12
ES31: Add DispatchComputeIndirect suport for OpenGL backend BUG=angleproject:2270 TEST=dEQP-GLES31.functional.compute.indirect_dispatch.* Change-Id: Id062a80188b2a37f28833aaae8e6d31bac382276 Reviewed-on: https://chromium-review.googlesource.com/802763 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 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 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
//
// Copyright 2016 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.
//
// Context11:
// D3D11-specific functionality associated with a GL Context.
//
#include "libANGLE/renderer/d3d/d3d11/Context11.h"
#include "common/string_utils.h"
#include "libANGLE/Context.h"
#include "libANGLE/MemoryProgramCache.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h"
#include "libANGLE/renderer/d3d/RenderbufferD3D.h"
#include "libANGLE/renderer/d3d/SamplerD3D.h"
#include "libANGLE/renderer/d3d/ShaderD3D.h"
#include "libANGLE/renderer/d3d/TextureD3D.h"
#include "libANGLE/renderer/d3d/d3d11/Buffer11.h"
#include "libANGLE/renderer/d3d/d3d11/Fence11.h"
#include "libANGLE/renderer/d3d/d3d11/Framebuffer11.h"
#include "libANGLE/renderer/d3d/d3d11/ProgramPipeline11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/StateManager11.h"
#include "libANGLE/renderer/d3d/d3d11/TransformFeedback11.h"
#include "libANGLE/renderer/d3d/d3d11/VertexArray11.h"
namespace rx
{
Context11::Context11(const gl::ContextState &state, Renderer11 *renderer)
: ContextImpl(state), mRenderer(renderer)
{
}
Context11::~Context11()
{
}
gl::Error Context11::initialize()
{
return gl::NoError();
}
CompilerImpl *Context11::createCompiler()
{
if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3)
{
return new CompilerD3D(SH_HLSL_4_0_FL9_3_OUTPUT);
}
else
{
return new CompilerD3D(SH_HLSL_4_1_OUTPUT);
}
}
ShaderImpl *Context11::createShader(const gl::ShaderState &data)
{
return new ShaderD3D(data, mRenderer->getWorkarounds(), mRenderer->getNativeExtensions());
}
ProgramImpl *Context11::createProgram(const gl::ProgramState &data)
{
return new ProgramD3D(data, mRenderer);
}
FramebufferImpl *Context11::createFramebuffer(const gl::FramebufferState &data)
{
return new Framebuffer11(data, mRenderer);
}
TextureImpl *Context11::createTexture(const gl::TextureState &state)
{
switch (state.getTarget())
{
case GL_TEXTURE_2D:
return new TextureD3D_2D(state, mRenderer);
case GL_TEXTURE_CUBE_MAP:
return new TextureD3D_Cube(state, mRenderer);
case GL_TEXTURE_3D:
return new TextureD3D_3D(state, mRenderer);
case GL_TEXTURE_2D_ARRAY:
return new TextureD3D_2DArray(state, mRenderer);
case GL_TEXTURE_EXTERNAL_OES:
return new TextureD3D_External(state, mRenderer);
case GL_TEXTURE_2D_MULTISAMPLE:
return new TextureD3D_2DMultisample(state, mRenderer);
break;
default:
UNREACHABLE();
}
return nullptr;
}
RenderbufferImpl *Context11::createRenderbuffer()
{
return new RenderbufferD3D(mRenderer);
}
BufferImpl *Context11::createBuffer(const gl::BufferState &state)
{
Buffer11 *buffer = new Buffer11(state, mRenderer);
mRenderer->onBufferCreate(buffer);
return buffer;
}
VertexArrayImpl *Context11::createVertexArray(const gl::VertexArrayState &data)
{
return new VertexArray11(data);
}
QueryImpl *Context11::createQuery(GLenum type)
{
return new Query11(mRenderer, type);
}
FenceNVImpl *Context11::createFenceNV()
{
return new FenceNV11(mRenderer);
}
SyncImpl *Context11::createSync()
{
return new Sync11(mRenderer);
}
TransformFeedbackImpl *Context11::createTransformFeedback(const gl::TransformFeedbackState &state)
{
return new TransformFeedback11(state, mRenderer);
}
SamplerImpl *Context11::createSampler(const gl::SamplerState &state)
{
return new SamplerD3D(state);
}
ProgramPipelineImpl *Context11::createProgramPipeline(const gl::ProgramPipelineState &data)
{
return new ProgramPipeline11(data);
}
std::vector<PathImpl *> Context11::createPaths(GLsizei)
{
return std::vector<PathImpl *>();
}
gl::Error Context11::flush(const gl::Context *context)
{
return mRenderer->flush();
}
gl::Error Context11::finish(const gl::Context *context)
{
return mRenderer->finish();
}
gl::Error Context11::drawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count)
{
ANGLE_TRY(prepareForDrawCall(context, mode));
return mRenderer->drawArrays(context, mode, first, count, 0);
}
gl::Error Context11::drawArraysInstanced(const gl::Context *context,
GLenum mode,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
ANGLE_TRY(prepareForDrawCall(context, mode));
return mRenderer->drawArrays(context, mode, first, count, instanceCount);
}
gl::Error Context11::drawElements(const gl::Context *context,
GLenum mode,
GLsizei count,
GLenum type,
const void *indices)
{
ANGLE_TRY(prepareForDrawCall(context, mode));
return mRenderer->drawElements(context, mode, count, type, indices, 0);
}
gl::Error Context11::drawElementsInstanced(const gl::Context *context,
GLenum mode,
GLsizei count,
GLenum type,
const void *indices,
GLsizei instances)
{
ANGLE_TRY(prepareForDrawCall(context, mode));
return mRenderer->drawElements(context, mode, count, type, indices, instances);
}
gl::Error Context11::drawRangeElements(const gl::Context *context,
GLenum mode,
GLuint start,
GLuint end,
GLsizei count,
GLenum type,
const void *indices)
{
ANGLE_TRY(prepareForDrawCall(context, mode));
return mRenderer->drawElements(context, mode, count, type, indices, 0);
}
gl::Error Context11::drawArraysIndirect(const gl::Context *context,
GLenum mode,
const void *indirect)
{
ANGLE_TRY(prepareForDrawCall(context, mode));
return mRenderer->drawArraysIndirect(context, mode, indirect);
}
gl::Error Context11::drawElementsIndirect(const gl::Context *context,
GLenum mode,
GLenum type,
const void *indirect)
{
ANGLE_TRY(prepareForDrawCall(context, mode));
return mRenderer->drawElementsIndirect(context, mode, type, indirect);
}
GLenum Context11::getResetStatus()
{
return mRenderer->getResetStatus();
}
std::string Context11::getVendorString() const
{
return mRenderer->getVendorString();
}
std::string Context11::getRendererDescription() const
{
return mRenderer->getRendererDescription();
}
void Context11::insertEventMarker(GLsizei length, const char *marker)
{
auto optionalString = angle::WidenString(static_cast<size_t>(length), marker);
if (optionalString.valid())
{
mRenderer->getAnnotator()->setMarker(optionalString.value().data());
}
}
void Context11::pushGroupMarker(GLsizei length, const char *marker)
{
auto optionalString = angle::WidenString(static_cast<size_t>(length), marker);
if (optionalString.valid())
{
mRenderer->getAnnotator()->beginEvent(optionalString.value().data());
}
}
void Context11::popGroupMarker()
{
mRenderer->getAnnotator()->endEvent();
}
void Context11::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message)
{
// Fall through to the EXT_debug_marker functions
pushGroupMarker(length, message);
}
void Context11::popDebugGroup()
{
// Fall through to the EXT_debug_marker functions
popGroupMarker();
}
void Context11::syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits)
{
mRenderer->getStateManager()->syncState(context, dirtyBits);
}
GLint Context11::getGPUDisjoint()
{
return mRenderer->getGPUDisjoint();
}
GLint64 Context11::getTimestamp()
{
return mRenderer->getTimestamp();
}
void Context11::onMakeCurrent(const gl::Context *context)
{
ANGLE_SWALLOW_ERR(mRenderer->getStateManager()->onMakeCurrent(context));
}
const gl::Caps &Context11::getNativeCaps() const
{
return mRenderer->getNativeCaps();
}
const gl::TextureCapsMap &Context11::getNativeTextureCaps() const
{
return mRenderer->getNativeTextureCaps();
}
const gl::Extensions &Context11::getNativeExtensions() const
{
return mRenderer->getNativeExtensions();
}
const gl::Limitations &Context11::getNativeLimitations() const
{
return mRenderer->getNativeLimitations();
}
gl::Error Context11::dispatchCompute(const gl::Context *context,
GLuint numGroupsX,
GLuint numGroupsY,
GLuint numGroupsZ)
{
return mRenderer->dispatchCompute(context, numGroupsX, numGroupsY, numGroupsZ);
}
gl::Error Context11::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
{
UNIMPLEMENTED();
return gl::InternalError();
}
gl::Error Context11::triggerDrawCallProgramRecompilation(const gl::Context *context,
GLenum drawMode)
{
const auto &glState = context->getGLState();
const auto *va11 = GetImplAs<VertexArray11>(glState.getVertexArray());
const auto *drawFBO = glState.getDrawFramebuffer();
gl::Program *program = glState.getProgram();
ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program);
programD3D->updateCachedInputLayout(va11->getCurrentStateSerial(), glState);
programD3D->updateCachedOutputLayout(context, drawFBO);
bool recompileVS = !programD3D->hasVertexExecutableForCachedInputLayout();
bool recompileGS = !programD3D->hasGeometryExecutableForPrimitiveType(drawMode);
bool recompilePS = !programD3D->hasPixelExecutableForCachedOutputLayout();
if (!recompileVS && !recompileGS && !recompilePS)
{
return gl::NoError();
}
// Load the compiler if necessary and recompile the programs.
ANGLE_TRY(mRenderer->ensureHLSLCompilerInitialized());
gl::InfoLog infoLog;
if (recompileVS)
{
ShaderExecutableD3D *vertexExe = nullptr;
ANGLE_TRY(programD3D->getVertexExecutableForCachedInputLayout(&vertexExe, &infoLog));
if (!programD3D->hasVertexExecutableForCachedInputLayout())
{
ASSERT(infoLog.getLength() > 0);
ERR() << "Dynamic recompilation error log: " << infoLog.str();
return gl::InternalError()
<< "Error compiling dynamic vertex executable:" << infoLog.str();
}
}
if (recompileGS)
{
ShaderExecutableD3D *geometryExe = nullptr;
ANGLE_TRY(programD3D->getGeometryExecutableForPrimitiveType(context, drawMode, &geometryExe,
&infoLog));
if (!programD3D->hasGeometryExecutableForPrimitiveType(drawMode))
{
ASSERT(infoLog.getLength() > 0);
ERR() << "Dynamic recompilation error log: " << infoLog.str();
return gl::InternalError()
<< "Error compiling dynamic geometry executable:" << infoLog.str();
}
}
if (recompilePS)
{
ShaderExecutableD3D *pixelExe = nullptr;
ANGLE_TRY(programD3D->getPixelExecutableForCachedOutputLayout(&pixelExe, &infoLog));
if (!programD3D->hasPixelExecutableForCachedOutputLayout())
{
ASSERT(infoLog.getLength() > 0);
ERR() << "Dynamic recompilation error log: " << infoLog.str();
return gl::InternalError()
<< "Error compiling dynamic pixel executable:" << infoLog.str();
}
}
// Refresh the program cache entry.
if (mMemoryProgramCache)
{
mMemoryProgramCache->updateProgram(context, program);
}
return gl::NoError();
}
gl::Error Context11::prepareForDrawCall(const gl::Context *context, GLenum drawMode)
{
ANGLE_TRY(mRenderer->getStateManager()->updateState(context, drawMode));
return gl::NoError();
}
gl::Error Context11::memoryBarrier(const gl::Context *context, GLbitfield barriers)
{
UNIMPLEMENTED();
return gl::NoError();
}
gl::Error Context11::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
{
UNIMPLEMENTED();
return gl::NoError();
}
} // namespace rx