Hash :
4e6fe5e0
Author :
Date :
2024-02-29T15:01:06
Vulkan: Cache ImageLoadContext in context This avoids the need to requery this from the display every time. Bug: angleproject:8564 Change-Id: Ied650e7789741f59b7662c0f97c55132b105778d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5332074 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Charlie Lao <cclao@google.com> 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 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 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
//
// 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.
//
// Context9:
// D3D9-specific functionality associated with a GL Context.
//
#include "libANGLE/renderer/d3d/d3d9/Context9.h"
#include "common/entry_points_enum_autogen.h"
#include "common/string_utils.h"
#include "image_util/loadimage.h"
#include "libANGLE/renderer/OverlayImpl.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h"
#include "libANGLE/renderer/d3d/ProgramExecutableD3D.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/d3d9/Buffer9.h"
#include "libANGLE/renderer/d3d/d3d9/Fence9.h"
#include "libANGLE/renderer/d3d/d3d9/Framebuffer9.h"
#include "libANGLE/renderer/d3d/d3d9/Query9.h"
#include "libANGLE/renderer/d3d/d3d9/Renderer9.h"
#include "libANGLE/renderer/d3d/d3d9/StateManager9.h"
#include "libANGLE/renderer/d3d/d3d9/VertexArray9.h"
namespace rx
{
Context9::Context9(const gl::State &state, gl::ErrorSet *errorSet, Renderer9 *renderer)
: ContextD3D(state, errorSet), mRenderer(renderer)
{}
Context9::~Context9() {}
angle::Result Context9::initialize(const angle::ImageLoadContext &imageLoadContext)
{
mImageLoadContext = imageLoadContext;
return angle::Result::Continue;
}
void Context9::onDestroy(const gl::Context *context)
{
mIncompleteTextures.onDestroy(context);
mImageLoadContext = {};
}
CompilerImpl *Context9::createCompiler()
{
return new CompilerD3D(SH_HLSL_3_0_OUTPUT);
}
ShaderImpl *Context9::createShader(const gl::ShaderState &data)
{
return new ShaderD3D(data, mRenderer);
}
ProgramImpl *Context9::createProgram(const gl::ProgramState &data)
{
return new ProgramD3D(data, mRenderer);
}
ProgramExecutableImpl *Context9::createProgramExecutable(const gl::ProgramExecutable *executable)
{
return new ProgramExecutableD3D(executable);
}
FramebufferImpl *Context9::createFramebuffer(const gl::FramebufferState &data)
{
return new Framebuffer9(data, mRenderer);
}
TextureImpl *Context9::createTexture(const gl::TextureState &state)
{
switch (state.getType())
{
case gl::TextureType::_2D:
// GL_TEXTURE_VIDEO_IMAGE_WEBGL maps to 2D texture on Windows platform.
case gl::TextureType::VideoImage:
return new TextureD3D_2D(state, mRenderer);
case gl::TextureType::CubeMap:
return new TextureD3D_Cube(state, mRenderer);
case gl::TextureType::External:
return new TextureD3D_External(state, mRenderer);
default:
UNREACHABLE();
}
return nullptr;
}
RenderbufferImpl *Context9::createRenderbuffer(const gl::RenderbufferState &state)
{
return new RenderbufferD3D(state, mRenderer);
}
BufferImpl *Context9::createBuffer(const gl::BufferState &state)
{
return new Buffer9(state, mRenderer);
}
VertexArrayImpl *Context9::createVertexArray(const gl::VertexArrayState &data)
{
return new VertexArray9(data);
}
QueryImpl *Context9::createQuery(gl::QueryType type)
{
return new Query9(mRenderer, type);
}
FenceNVImpl *Context9::createFenceNV()
{
return new FenceNV9(mRenderer);
}
SyncImpl *Context9::createSync()
{
// D3D9 doesn't support ES 3.0 and its sync objects.
UNREACHABLE();
return nullptr;
}
TransformFeedbackImpl *Context9::createTransformFeedback(const gl::TransformFeedbackState &state)
{
UNREACHABLE();
return nullptr;
}
SamplerImpl *Context9::createSampler(const gl::SamplerState &state)
{
return new SamplerD3D(state);
}
ProgramPipelineImpl *Context9::createProgramPipeline(const gl::ProgramPipelineState &data)
{
UNREACHABLE();
return nullptr;
}
MemoryObjectImpl *Context9::createMemoryObject()
{
UNREACHABLE();
return nullptr;
}
SemaphoreImpl *Context9::createSemaphore()
{
UNREACHABLE();
return nullptr;
}
OverlayImpl *Context9::createOverlay(const gl::OverlayState &state)
{
// Not implemented.
return new OverlayImpl(state);
}
angle::Result Context9::flush(const gl::Context *context)
{
return mRenderer->flush(context);
}
angle::Result Context9::finish(const gl::Context *context)
{
return mRenderer->finish(context);
}
angle::Result Context9::drawArrays(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count)
{
return mRenderer->genericDrawArrays(context, mode, first, count, 0);
}
angle::Result Context9::drawArraysInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
return mRenderer->genericDrawArrays(context, mode, first, count, instanceCount);
}
angle::Result Context9::drawArraysInstancedBaseInstance(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count,
GLsizei instanceCount,
GLuint baseInstance)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Continue;
}
angle::Result Context9::drawElements(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices)
{
return mRenderer->genericDrawElements(context, mode, count, type, indices, 0);
}
angle::Result Context9::drawElementsBaseVertex(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLint baseVertex)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Continue;
}
angle::Result Context9::drawElementsInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLsizei instances)
{
return mRenderer->genericDrawElements(context, mode, count, type, indices, instances);
}
angle::Result Context9::drawElementsInstancedBaseVertex(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLsizei instances,
GLint baseVertex)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Continue;
}
angle::Result Context9::drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLsizei instances,
GLint baseVertex,
GLuint baseInstance)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Continue;
}
angle::Result Context9::drawRangeElements(const gl::Context *context,
gl::PrimitiveMode mode,
GLuint start,
GLuint end,
GLsizei count,
gl::DrawElementsType type,
const void *indices)
{
return mRenderer->genericDrawElements(context, mode, count, type, indices, 0);
}
angle::Result Context9::drawRangeElementsBaseVertex(const gl::Context *context,
gl::PrimitiveMode mode,
GLuint start,
GLuint end,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLint baseVertex)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Continue;
}
angle::Result Context9::drawArraysIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
const void *indirect)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Stop;
}
angle::Result Context9::drawElementsIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
gl::DrawElementsType type,
const void *indirect)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Stop;
}
angle::Result Context9::multiDrawArrays(const gl::Context *context,
gl::PrimitiveMode mode,
const GLint *firsts,
const GLsizei *counts,
GLsizei drawcount)
{
return rx::MultiDrawArraysGeneral(this, context, mode, firsts, counts, drawcount);
}
angle::Result Context9::multiDrawArraysInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
const GLint *firsts,
const GLsizei *counts,
const GLsizei *instanceCounts,
GLsizei drawcount)
{
return rx::MultiDrawArraysInstancedGeneral(this, context, mode, firsts, counts, instanceCounts,
drawcount);
}
angle::Result Context9::multiDrawArraysIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
const void *indirect,
GLsizei drawcount,
GLsizei stride)
{
UNREACHABLE();
return angle::Result::Stop;
}
angle::Result Context9::multiDrawElements(const gl::Context *context,
gl::PrimitiveMode mode,
const GLsizei *counts,
gl::DrawElementsType type,
const GLvoid *const *indices,
GLsizei drawcount)
{
return rx::MultiDrawElementsGeneral(this, context, mode, counts, type, indices, drawcount);
}
angle::Result Context9::multiDrawElementsInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
const GLsizei *counts,
gl::DrawElementsType type,
const GLvoid *const *indices,
const GLsizei *instanceCounts,
GLsizei drawcount)
{
return rx::MultiDrawElementsInstancedGeneral(this, context, mode, counts, type, indices,
instanceCounts, drawcount);
}
angle::Result Context9::multiDrawElementsIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
gl::DrawElementsType type,
const void *indirect,
GLsizei drawcount,
GLsizei stride)
{
UNREACHABLE();
return angle::Result::Stop;
}
angle::Result Context9::multiDrawArraysInstancedBaseInstance(const gl::Context *context,
gl::PrimitiveMode mode,
const GLint *firsts,
const GLsizei *counts,
const GLsizei *instanceCounts,
const GLuint *baseInstances,
GLsizei drawcount)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Stop;
}
angle::Result Context9::multiDrawElementsInstancedBaseVertexBaseInstance(
const gl::Context *context,
gl::PrimitiveMode mode,
const GLsizei *counts,
gl::DrawElementsType type,
const GLvoid *const *indices,
const GLsizei *instanceCounts,
const GLint *baseVertices,
const GLuint *baseInstances,
GLsizei drawcount)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Stop;
}
gl::GraphicsResetStatus Context9::getResetStatus()
{
return mRenderer->getResetStatus();
}
angle::Result Context9::insertEventMarker(GLsizei length, const char *marker)
{
mRenderer->getAnnotator()->setMarker(/*context=*/nullptr, marker);
return angle::Result::Continue;
}
angle::Result Context9::pushGroupMarker(GLsizei length, const char *marker)
{
mRenderer->getAnnotator()->beginEvent(nullptr, angle::EntryPoint::GLPushGroupMarkerEXT, marker,
marker);
mMarkerStack.push(std::string(marker));
return angle::Result::Continue;
}
angle::Result Context9::popGroupMarker()
{
const char *marker = nullptr;
if (!mMarkerStack.empty())
{
marker = mMarkerStack.top().c_str();
mMarkerStack.pop();
mRenderer->getAnnotator()->endEvent(nullptr, marker,
angle::EntryPoint::GLPopGroupMarkerEXT);
}
return angle::Result::Continue;
}
angle::Result Context9::pushDebugGroup(const gl::Context *context,
GLenum source,
GLuint id,
const std::string &message)
{
// Fall through to the EXT_debug_marker functions
return pushGroupMarker(static_cast<GLsizei>(message.size()), message.c_str());
}
angle::Result Context9::popDebugGroup(const gl::Context *context)
{
// Fall through to the EXT_debug_marker functions
return popGroupMarker();
}
angle::Result Context9::syncState(const gl::Context *context,
const gl::state::DirtyBits dirtyBits,
const gl::state::DirtyBits bitMask,
const gl::state::ExtendedDirtyBits extendedDirtyBits,
const gl::state::ExtendedDirtyBits extendedBitMask,
gl::Command command)
{
mRenderer->getStateManager()->syncState(mState, dirtyBits, extendedDirtyBits);
return angle::Result::Continue;
}
GLint Context9::getGPUDisjoint()
{
// Disjoint timer queries are not supported.
return false;
}
GLint64 Context9::getTimestamp()
{
return mRenderer->getTimestamp();
}
angle::Result Context9::onMakeCurrent(const gl::Context *context)
{
mRenderer->getStateManager()->setAllDirtyBits();
return mRenderer->ensureVertexDataManagerInitialized(context);
}
gl::Caps Context9::getNativeCaps() const
{
return mRenderer->getNativeCaps();
}
const gl::TextureCapsMap &Context9::getNativeTextureCaps() const
{
return mRenderer->getNativeTextureCaps();
}
const gl::Extensions &Context9::getNativeExtensions() const
{
return mRenderer->getNativeExtensions();
}
const gl::Limitations &Context9::getNativeLimitations() const
{
return mRenderer->getNativeLimitations();
}
const ShPixelLocalStorageOptions &Context9::getNativePixelLocalStorageOptions() const
{
return mRenderer->getNativePixelLocalStorageOptions();
}
angle::Result Context9::dispatchCompute(const gl::Context *context,
GLuint numGroupsX,
GLuint numGroupsY,
GLuint numGroupsZ)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Stop;
}
angle::Result Context9::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Stop;
}
angle::Result Context9::memoryBarrier(const gl::Context *context, GLbitfield barriers)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Stop;
}
angle::Result Context9::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
{
ANGLE_HR_UNREACHABLE(this);
return angle::Result::Stop;
}
angle::Result Context9::getIncompleteTexture(const gl::Context *context,
gl::TextureType type,
gl::Texture **textureOut)
{
return mIncompleteTextures.getIncompleteTexture(context, type, gl::SamplerFormat::Float,
nullptr, textureOut);
}
void Context9::handleResult(HRESULT hr,
const char *message,
const char *file,
const char *function,
unsigned int line)
{
ASSERT(FAILED(hr));
if (d3d9::isDeviceLostError(hr))
{
mRenderer->notifyDeviceLost();
}
GLenum glErrorCode = DefaultGLErrorCode(hr);
std::stringstream errorStream;
errorStream << "Internal D3D9 error: " << gl::FmtHR(hr) << ": " << message;
mErrors->handleError(glErrorCode, errorStream.str().c_str(), file, function, line);
}
} // namespace rx