| 353 | } |
| 354 | |
| 355 | bool GPUTexture::Init(const GPUTextureDescription& desc) |
| 356 | { |
| 357 | PROFILE_CPU(); |
| 358 | PROFILE_MEM(GraphicsTextures); |
| 359 | |
| 360 | // Validate description |
| 361 | const auto device = GPUDevice::Instance; |
| 362 | if (desc.Usage == GPUResourceUsage::Dynamic) |
| 363 | { |
| 364 | LOG(Warning, "Cannot create texture. Dynamic textures are not supported. Description: {0}", desc.ToString()); |
| 365 | return true; |
| 366 | } |
| 367 | if (desc.MipLevels < 0 || desc.MipLevels > GPU_MAX_TEXTURE_MIP_LEVELS) |
| 368 | { |
| 369 | LOG(Warning, "Cannot create texture. Invalid amount of mip levels. Description: {0}", desc.ToString()); |
| 370 | return true; |
| 371 | } |
| 372 | if (desc.IsDepthStencil()) |
| 373 | { |
| 374 | if (desc.MipLevels > 1) |
| 375 | { |
| 376 | LOG(Warning, "Cannot create texture. Depth Stencil texture cannot have mip maps. Description: {0}", desc.ToString()); |
| 377 | return true; |
| 378 | } |
| 379 | if (desc.IsRenderTarget()) |
| 380 | { |
| 381 | LOG(Warning, "Cannot create texture. Depth Stencil texture cannot be used as a Render Target. Description: {0}", desc.ToString()); |
| 382 | return true; |
| 383 | } |
| 384 | if (EnumHasAnyFlags(desc.Flags, GPUTextureFlags::ReadOnlyDepthView) && !device->Limits.HasReadOnlyDepth) |
| 385 | { |
| 386 | LOG(Warning, "Cannot create texture. The current graphics platform does not support read-only Depth Stencil texture. Description: {0}", desc.ToString()); |
| 387 | return true; |
| 388 | } |
| 389 | } |
| 390 | else |
| 391 | { |
| 392 | if (EnumHasAnyFlags(desc.Flags, GPUTextureFlags::ReadOnlyDepthView)) |
| 393 | { |
| 394 | LOG(Warning, "Cannot create texture. Cannot create read-only Depth Stencil texture that is not a Depth Stencil texture. Add DepthStencil flag. Description: {0}", desc.ToString()); |
| 395 | return true; |
| 396 | } |
| 397 | } |
| 398 | if (desc.HasPerMipViews() && !(desc.IsShaderResource() || desc.IsRenderTarget())) |
| 399 | { |
| 400 | LOG(Warning, "Cannot create texture. Depth Stencil texture cannot have mip maps. Description: {0}", desc.ToString()); |
| 401 | return true; |
| 402 | } |
| 403 | auto formatFeatures = device->GetFormatFeatures(desc.Format); |
| 404 | switch (desc.Dimensions) |
| 405 | { |
| 406 | case TextureDimensions::Texture: |
| 407 | { |
| 408 | if (desc.HasPerSliceViews()) |
| 409 | { |
| 410 | LOG(Warning, "Cannot create texture. Texture cannot have per slice views. Description: {0}", desc.ToString()); |
| 411 | return true; |
| 412 | } |
no test coverage detected