Hash :
17ac6943
Author :
Date :
2023-01-20T12:09:44
Move d3d11 BCX textures to the "UNREACHABLE" section for clears BCX textures can't be rendered to or cleared. Bug: angleproject:7855 Change-Id: Id2564e92db692aeae9a0da47d55a8ef18b66c4d0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4184938 Commit-Queue: Chris Dalton <chris@rive.app> Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.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 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
//
// 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.
//
// ResourceManager11:
// Centralized point of allocation for all D3D11 Resources.
#include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h"
#include "common/debug.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
namespace rx
{
namespace
{
constexpr uint8_t kDebugInitTextureDataValue = 0x48;
constexpr FLOAT kDebugColorInitClearValue[4] = {0.3f, 0.5f, 0.7f, 0.5f};
constexpr FLOAT kDebugDepthInitValue = 0.2f;
constexpr UINT8 kDebugStencilInitValue = 3;
// A hard limit on buffer size. This works around a problem in the NVIDIA drivers where buffer sizes
// close to MAX_UINT would give undefined results. The limit of MAX_UINT/2 should be generous enough
// for almost any demanding application.
constexpr UINT kMaximumBufferSizeHardLimit = std::numeric_limits<UINT>::max() >> 1;
uint64_t ComputeMippedMemoryUsage(unsigned int width,
unsigned int height,
unsigned int depth,
uint64_t pixelSize,
unsigned int mipLevels)
{
uint64_t sizeSum = 0;
for (unsigned int level = 0; level < mipLevels; ++level)
{
unsigned int mipWidth = std::max(width >> level, 1u);
unsigned int mipHeight = std::max(height >> level, 1u);
unsigned int mipDepth = std::max(depth >> level, 1u);
sizeSum += static_cast<uint64_t>(mipWidth * mipHeight * mipDepth) * pixelSize;
}
return sizeSum;
}
uint64_t ComputeMemoryUsage(const D3D11_TEXTURE2D_DESC *desc)
{
ASSERT(desc);
uint64_t pixelBytes =
static_cast<uint64_t>(d3d11::GetDXGIFormatSizeInfo(desc->Format).pixelBytes);
return ComputeMippedMemoryUsage(desc->Width, desc->Height, 1, pixelBytes, desc->MipLevels);
}
uint64_t ComputeMemoryUsage(const D3D11_TEXTURE3D_DESC *desc)
{
ASSERT(desc);
uint64_t pixelBytes =
static_cast<uint64_t>(d3d11::GetDXGIFormatSizeInfo(desc->Format).pixelBytes);
return ComputeMippedMemoryUsage(desc->Width, desc->Height, desc->Depth, pixelBytes,
desc->MipLevels);
}
uint64_t ComputeMemoryUsage(const D3D11_BUFFER_DESC *desc)
{
ASSERT(desc);
return static_cast<uint64_t>(desc->ByteWidth);
}
template <typename T>
uint64_t ComputeMemoryUsage(const T *desc)
{
return 0;
}
template <ResourceType ResourceT>
uint64_t ComputeGenericMemoryUsage(ID3D11DeviceChild *genericResource)
{
auto *typedResource = static_cast<GetD3D11Type<ResourceT> *>(genericResource);
GetDescType<ResourceT> desc;
typedResource->GetDesc(&desc);
return ComputeMemoryUsage(&desc);
}
uint64_t ComputeGenericMemoryUsage(ResourceType resourceType, ID3D11DeviceChild *resource)
{
switch (resourceType)
{
case ResourceType::Texture2D:
return ComputeGenericMemoryUsage<ResourceType::Texture2D>(resource);
case ResourceType::Texture3D:
return ComputeGenericMemoryUsage<ResourceType::Texture3D>(resource);
case ResourceType::Buffer:
return ComputeGenericMemoryUsage<ResourceType::Buffer>(resource);
default:
return 0;
}
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_BLEND_DESC *desc,
void * /*initData*/,
ID3D11BlendState **blendState)
{
return device->CreateBlendState(desc, blendState);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_BUFFER_DESC *desc,
const D3D11_SUBRESOURCE_DATA *initData,
ID3D11Buffer **buffer)
{
// Force buffers to be limited to a fixed max size.
if (desc->ByteWidth > kMaximumBufferSizeHardLimit)
{
return E_OUTOFMEMORY;
}
return device->CreateBuffer(desc, initData, buffer);
}
HRESULT CreateResource(ID3D11Device *device,
const ShaderData *desc,
void * /*initData*/,
ID3D11ComputeShader **resourceOut)
{
return device->CreateComputeShader(desc->get(), desc->size(), nullptr, resourceOut);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_DEPTH_STENCIL_DESC *desc,
void * /*initData*/,
ID3D11DepthStencilState **resourceOut)
{
return device->CreateDepthStencilState(desc, resourceOut);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
ID3D11Resource *resource,
ID3D11DepthStencilView **resourceOut)
{
return device->CreateDepthStencilView(resource, desc, resourceOut);
}
HRESULT CreateResource(ID3D11Device *device,
const ShaderData *desc,
const std::vector<D3D11_SO_DECLARATION_ENTRY> *initData,
ID3D11GeometryShader **resourceOut)
{
if (initData)
{
return device->CreateGeometryShaderWithStreamOutput(
desc->get(), desc->size(), initData->data(), static_cast<UINT>(initData->size()),
nullptr, 0, 0, nullptr, resourceOut);
}
else
{
return device->CreateGeometryShader(desc->get(), desc->size(), nullptr, resourceOut);
}
}
HRESULT CreateResource(ID3D11Device *device,
const InputElementArray *desc,
const ShaderData *initData,
ID3D11InputLayout **resourceOut)
{
return device->CreateInputLayout(desc->get(), static_cast<UINT>(desc->size()), initData->get(),
initData->size(), resourceOut);
}
HRESULT CreateResource(ID3D11Device *device,
const ShaderData *desc,
void * /*initData*/,
ID3D11PixelShader **resourceOut)
{
return device->CreatePixelShader(desc->get(), desc->size(), nullptr, resourceOut);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_QUERY_DESC *desc,
void * /*initData*/,
ID3D11Query **resourceOut)
{
return device->CreateQuery(desc, resourceOut);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_RASTERIZER_DESC *desc,
void * /*initData*/,
ID3D11RasterizerState **rasterizerState)
{
return device->CreateRasterizerState(desc, rasterizerState);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_RENDER_TARGET_VIEW_DESC *desc,
ID3D11Resource *resource,
ID3D11RenderTargetView **renderTargetView)
{
return device->CreateRenderTargetView(resource, desc, renderTargetView);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_SAMPLER_DESC *desc,
void * /*initData*/,
ID3D11SamplerState **resourceOut)
{
return device->CreateSamplerState(desc, resourceOut);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
ID3D11Resource *resource,
ID3D11ShaderResourceView **resourceOut)
{
return device->CreateShaderResourceView(resource, desc, resourceOut);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
ID3D11Resource *resource,
ID3D11UnorderedAccessView **resourceOut)
{
return device->CreateUnorderedAccessView(resource, desc, resourceOut);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_TEXTURE2D_DESC *desc,
const D3D11_SUBRESOURCE_DATA *initData,
ID3D11Texture2D **texture)
{
return device->CreateTexture2D(desc, initData, texture);
}
HRESULT CreateResource(ID3D11Device *device,
const D3D11_TEXTURE3D_DESC *desc,
const D3D11_SUBRESOURCE_DATA *initData,
ID3D11Texture3D **texture)
{
return device->CreateTexture3D(desc, initData, texture);
}
HRESULT CreateResource(ID3D11Device *device,
const ShaderData *desc,
void * /*initData*/,
ID3D11VertexShader **resourceOut)
{
return device->CreateVertexShader(desc->get(), desc->size(), nullptr, resourceOut);
}
DXGI_FORMAT GetTypedDepthStencilFormat(DXGI_FORMAT dxgiFormat)
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R16_TYPELESS:
return DXGI_FORMAT_D16_UNORM;
case DXGI_FORMAT_R24G8_TYPELESS:
return DXGI_FORMAT_D24_UNORM_S8_UINT;
case DXGI_FORMAT_R32_TYPELESS:
return DXGI_FORMAT_D32_FLOAT;
case DXGI_FORMAT_R32G8X24_TYPELESS:
return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
default:
return dxgiFormat;
}
}
DXGI_FORMAT GetTypedColorFormatForClearing(DXGI_FORMAT dxgiFormat)
{
switch (dxgiFormat)
{
case DXGI_FORMAT_R32G32B32A32_TYPELESS:
return DXGI_FORMAT_R32G32B32A32_FLOAT;
case DXGI_FORMAT_R32G32B32_TYPELESS:
return DXGI_FORMAT_R32G32B32_FLOAT;
case DXGI_FORMAT_R16G16B16A16_TYPELESS:
return DXGI_FORMAT_R16G16B16A16_FLOAT;
case DXGI_FORMAT_R32G32_TYPELESS:
return DXGI_FORMAT_R32G32_FLOAT;
case DXGI_FORMAT_R10G10B10A2_TYPELESS:
return DXGI_FORMAT_R10G10B10A2_UNORM;
case DXGI_FORMAT_R8G8B8A8_TYPELESS:
return DXGI_FORMAT_R8G8B8A8_UNORM;
case DXGI_FORMAT_R16G16_TYPELESS:
return DXGI_FORMAT_R16G16_FLOAT;
case DXGI_FORMAT_R32_TYPELESS:
return DXGI_FORMAT_R32_FLOAT;
case DXGI_FORMAT_R8G8_TYPELESS:
return DXGI_FORMAT_R8G8_UNORM;
case DXGI_FORMAT_R16_TYPELESS:
return DXGI_FORMAT_R16_FLOAT;
case DXGI_FORMAT_R8_TYPELESS:
return DXGI_FORMAT_R8_UNORM;
case DXGI_FORMAT_B8G8R8A8_TYPELESS:
return DXGI_FORMAT_B8G8R8A8_UNORM;
case DXGI_FORMAT_B8G8R8X8_TYPELESS:
return DXGI_FORMAT_B8G8R8X8_UNORM;
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC2_TYPELESS:
case DXGI_FORMAT_BC3_TYPELESS:
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC5_TYPELESS:
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC7_TYPELESS:
case DXGI_FORMAT_R32G8X24_TYPELESS:
case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
case DXGI_FORMAT_R24G8_TYPELESS:
case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
UNREACHABLE();
[[fallthrough]];
default:
return dxgiFormat;
}
}
template <typename DescT, typename ResourceT>
angle::Result ClearResource(d3d::Context *context,
Renderer11 *renderer,
const DescT *desc,
ResourceT *texture)
{
// No-op.
return angle::Result::Continue;
}
template <>
angle::Result ClearResource(d3d::Context *context,
Renderer11 *renderer,
const D3D11_TEXTURE2D_DESC *desc,
ID3D11Texture2D *texture)
{
ID3D11DeviceContext *deviceContext = renderer->getDeviceContext();
if ((desc->BindFlags & D3D11_BIND_DEPTH_STENCIL) != 0)
{
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Flags = 0;
dsvDesc.Format = GetTypedDepthStencilFormat(desc->Format);
const auto &format = d3d11_angle::GetFormat(dsvDesc.Format);
UINT clearFlags = (format.depthBits > 0 ? D3D11_CLEAR_DEPTH : 0) |
(format.stencilBits > 0 ? D3D11_CLEAR_STENCIL : 0);
// Must process each mip level individually.
for (UINT mipLevel = 0; mipLevel < desc->MipLevels; ++mipLevel)
{
if (desc->SampleDesc.Count == 0)
{
dsvDesc.Texture2D.MipSlice = mipLevel;
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
}
else
{
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
}
d3d11::DepthStencilView dsv;
ANGLE_TRY(renderer->allocateResource(context, dsvDesc, texture, &dsv));
deviceContext->ClearDepthStencilView(dsv.get(), clearFlags, kDebugDepthInitValue,
kDebugStencilInitValue);
}
}
else
{
ASSERT((desc->BindFlags & D3D11_BIND_RENDER_TARGET) != 0);
DXGI_FORMAT formatForClearing = GetTypedColorFormatForClearing(desc->Format);
if (formatForClearing != desc->Format || desc->MipLevels > 1)
{
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = formatForClearing;
if (desc->SampleDesc.Count <= 1)
{
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
}
else
{
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
ASSERT(desc->MipLevels == 1);
}
for (UINT mipLevel = 0; mipLevel < desc->MipLevels; ++mipLevel)
{
d3d11::RenderTargetView rtv;
if (rtvDesc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
{
rtvDesc.Texture2D.MipSlice = mipLevel;
}
ANGLE_TRY(renderer->allocateResource(context, rtvDesc, texture, &rtv));
deviceContext->ClearRenderTargetView(rtv.get(), kDebugColorInitClearValue);
}
}
else
{
d3d11::RenderTargetView rtv;
ANGLE_TRY(renderer->allocateResourceNoDesc(context, texture, &rtv));
deviceContext->ClearRenderTargetView(rtv.get(), kDebugColorInitClearValue);
}
}
return angle::Result::Continue;
}
template <>
angle::Result ClearResource(d3d::Context *context,
Renderer11 *renderer,
const D3D11_TEXTURE3D_DESC *desc,
ID3D11Texture3D *texture)
{
ID3D11DeviceContext *deviceContext = renderer->getDeviceContext();
ASSERT((desc->BindFlags & D3D11_BIND_DEPTH_STENCIL) == 0);
ASSERT((desc->BindFlags & D3D11_BIND_RENDER_TARGET) != 0);
DXGI_FORMAT formatForClearing = GetTypedColorFormatForClearing(desc->Format);
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = formatForClearing;
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
rtvDesc.Texture3D.WSize = 1;
UINT depth = desc->Depth;
for (UINT mipLevel = 0; mipLevel < desc->MipLevels; ++mipLevel)
{
rtvDesc.Texture3D.MipSlice = mipLevel;
for (UINT w = 0; w < depth; ++w)
{
rtvDesc.Texture3D.FirstWSlice = w;
d3d11::RenderTargetView rtv;
ANGLE_TRY(renderer->allocateResource(context, rtvDesc, texture, &rtv));
deviceContext->ClearRenderTargetView(rtv.get(), kDebugColorInitClearValue);
}
depth /= 2;
}
return angle::Result::Continue;
}
#define ANGLE_RESOURCE_STRINGIFY_OP(NAME, RESTYPE, D3D11TYPE, DESCTYPE, INITDATATYPE) \
"Error allocating " #RESTYPE,
constexpr std::array<const char *, NumResourceTypes> kResourceTypeErrors = {
{ANGLE_RESOURCE_TYPE_OP(Stringify, ANGLE_RESOURCE_STRINGIFY_OP)}};
static_assert(kResourceTypeErrors[NumResourceTypes - 1] != nullptr,
"All members must be initialized.");
} // anonymous namespace
// ResourceManager11 Implementation.
ResourceManager11::ResourceManager11() : mInitializeAllocations(false)
{
for (auto &count : mAllocatedResourceCounts)
{
count = 0;
}
for (auto &memorySize : mAllocatedResourceDeviceMemory)
{
memorySize = 0;
}
}
ResourceManager11::~ResourceManager11()
{
for (size_t count : mAllocatedResourceCounts)
{
ASSERT(count == 0);
}
for (uint64_t memorySize : mAllocatedResourceDeviceMemory)
{
ASSERT(memorySize == 0);
}
}
template <typename T>
angle::Result ResourceManager11::allocate(d3d::Context *context,
Renderer11 *renderer,
const GetDescFromD3D11<T> *desc,
GetInitDataFromD3D11<T> *initData,
Resource11<T> *resourceOut)
{
ID3D11Device *device = renderer->getDevice();
T *resource = nullptr;
GetInitDataFromD3D11<T> *shadowInitData = initData;
if (!shadowInitData && mInitializeAllocations)
{
shadowInitData = createInitDataIfNeeded<T>(desc);
}
HRESULT hr = CreateResource(device, desc, shadowInitData, &resource);
ANGLE_TRY_HR(context, hr, kResourceTypeErrors[ResourceTypeIndex<T>()]);
if (!shadowInitData && mInitializeAllocations)
{
ANGLE_TRY(ClearResource(context, renderer, desc, resource));
}
ASSERT(resource);
incrResource(GetResourceTypeFromD3D11<T>(), ComputeMemoryUsage(desc));
*resourceOut = std::move(Resource11<T>(resource, this));
return angle::Result::Continue;
}
void ResourceManager11::incrResource(ResourceType resourceType, uint64_t memorySize)
{
size_t typeIndex = ResourceTypeIndex(resourceType);
mAllocatedResourceCounts[typeIndex]++;
mAllocatedResourceDeviceMemory[typeIndex] += memorySize;
// This checks for integer overflow.
ASSERT(mAllocatedResourceCounts[typeIndex] > 0);
ASSERT(mAllocatedResourceDeviceMemory[typeIndex] >= memorySize);
}
void ResourceManager11::decrResource(ResourceType resourceType, uint64_t memorySize)
{
size_t typeIndex = ResourceTypeIndex(resourceType);
ASSERT(mAllocatedResourceCounts[typeIndex] > 0);
mAllocatedResourceCounts[typeIndex]--;
ASSERT(mAllocatedResourceDeviceMemory[typeIndex] >= memorySize);
mAllocatedResourceDeviceMemory[typeIndex] -= memorySize;
}
void ResourceManager11::onReleaseGeneric(ResourceType resourceType, ID3D11DeviceChild *resource)
{
ASSERT(resource);
decrResource(resourceType, ComputeGenericMemoryUsage(resourceType, resource));
}
template <>
const D3D11_SUBRESOURCE_DATA *ResourceManager11::createInitDataIfNeeded<ID3D11Texture2D>(
const D3D11_TEXTURE2D_DESC *desc)
{
ASSERT(desc);
if ((desc->BindFlags & (D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_RENDER_TARGET)) != 0)
{
// This will be done using ClearView methods.
return nullptr;
}
size_t requiredSize = static_cast<size_t>(ComputeMemoryUsage(desc));
if (mZeroMemory.size() < requiredSize)
{
if (!mZeroMemory.resize(requiredSize))
{
ERR() << "Failed to allocate D3D texture initialization data.";
return nullptr;
}
mZeroMemory.fill(kDebugInitTextureDataValue);
}
const auto &formatSizeInfo = d3d11::GetDXGIFormatSizeInfo(desc->Format);
UINT subresourceCount = desc->MipLevels * desc->ArraySize;
if (mShadowInitData.size() < subresourceCount)
{
mShadowInitData.resize(subresourceCount);
}
for (UINT mipLevel = 0; mipLevel < desc->MipLevels; ++mipLevel)
{
for (UINT arrayIndex = 0; arrayIndex < desc->ArraySize; ++arrayIndex)
{
UINT subresourceIndex = D3D11CalcSubresource(mipLevel, arrayIndex, desc->MipLevels);
D3D11_SUBRESOURCE_DATA *data = &mShadowInitData[subresourceIndex];
UINT levelWidth = std::max(desc->Width >> mipLevel, 1u);
UINT levelHeight = std::max(desc->Height >> mipLevel, 1u);
data->SysMemPitch = levelWidth * formatSizeInfo.pixelBytes;
data->SysMemSlicePitch = data->SysMemPitch * levelHeight;
data->pSysMem = mZeroMemory.data();
}
}
return mShadowInitData.data();
}
template <>
const D3D11_SUBRESOURCE_DATA *ResourceManager11::createInitDataIfNeeded<ID3D11Texture3D>(
const D3D11_TEXTURE3D_DESC *desc)
{
ASSERT(desc);
if ((desc->BindFlags & D3D11_BIND_RENDER_TARGET) != 0)
{
// This will be done using ClearView methods.
return nullptr;
}
size_t requiredSize = static_cast<size_t>(ComputeMemoryUsage(desc));
if (mZeroMemory.size() < requiredSize)
{
if (!mZeroMemory.resize(requiredSize))
{
ERR() << "Failed to allocate D3D texture initialization data.";
return nullptr;
}
mZeroMemory.fill(kDebugInitTextureDataValue);
}
const auto &formatSizeInfo = d3d11::GetDXGIFormatSizeInfo(desc->Format);
UINT subresourceCount = desc->MipLevels;
if (mShadowInitData.size() < subresourceCount)
{
mShadowInitData.resize(subresourceCount);
}
for (UINT mipLevel = 0; mipLevel < desc->MipLevels; ++mipLevel)
{
UINT subresourceIndex = D3D11CalcSubresource(mipLevel, 0, desc->MipLevels);
D3D11_SUBRESOURCE_DATA *data = &mShadowInitData[subresourceIndex];
UINT levelWidth = std::max(desc->Width >> mipLevel, 1u);
UINT levelHeight = std::max(desc->Height >> mipLevel, 1u);
data->SysMemPitch = levelWidth * formatSizeInfo.pixelBytes;
data->SysMemSlicePitch = data->SysMemPitch * levelHeight;
data->pSysMem = mZeroMemory.data();
}
return mShadowInitData.data();
}
template <typename T>
GetInitDataFromD3D11<T> *ResourceManager11::createInitDataIfNeeded(const GetDescFromD3D11<T> *desc)
{
// No-op.
return nullptr;
}
void ResourceManager11::setAllocationsInitialized(bool initialize)
{
mInitializeAllocations = initialize;
}
#define ANGLE_INSTANTIATE_OP(NAME, RESTYPE, D3D11TYPE, DESCTYPE, INITDATATYPE) \
\
template angle::Result ResourceManager11::allocate( \
d3d::Context *, Renderer11 *, const DESCTYPE *, INITDATATYPE *, Resource11<D3D11TYPE> *);
ANGLE_RESOURCE_TYPE_OP(Instantitate, ANGLE_INSTANTIATE_OP)
} // namespace rx