| 354 | } |
| 355 | |
| 356 | static void WebGPURealizeTexture(WebGPUTexture* texture, WGPUTextureFormat format, uint8_t depth, uint32_t sampleCount, WGPUTextureUsage usage) |
| 357 | { |
| 358 | if (texture->m_Base.m_Depth > depth) |
| 359 | depth = texture->m_Base.m_Depth; |
| 360 | |
| 361 | assert(!texture->m_Texture && !texture->m_TextureView); |
| 362 | texture->m_Format = format; |
| 363 | |
| 364 | { |
| 365 | #if defined(DM_GRAPHICS_WEBGPU2) |
| 366 | WGPUTextureDescriptor desc = WGPU_TEXTURE_DESCRIPTOR_INIT; |
| 367 | #else |
| 368 | WGPUTextureDescriptor desc = {}; |
| 369 | #endif |
| 370 | uint32_t storage_width; |
| 371 | uint32_t storage_height; |
| 372 | WebGPUGetTextureStorageDimensions(texture->m_Base.m_Format, texture->m_Base.m_Width, texture->m_Base.m_Height, &storage_width, &storage_height); |
| 373 | |
| 374 | desc.usage = texture->m_UsageFlags | usage; |
| 375 | // Defold texture metadata keeps logical dimensions. WebGPU compressed |
| 376 | // texture descriptors must be block-aligned, so realize with the |
| 377 | // physical storage dimensions for these formats. |
| 378 | desc.size = { storage_width, storage_height, dmMath::Max(1u, (uint32_t)depth) }; |
| 379 | desc.sampleCount = sampleCount; |
| 380 | desc.format = texture->m_Format; |
| 381 | desc.mipLevelCount = texture->m_Base.m_MipMapCount; |
| 382 | switch (texture->m_Base.m_Type) |
| 383 | { |
| 384 | case TEXTURE_TYPE_3D: |
| 385 | case TEXTURE_TYPE_IMAGE_3D: |
| 386 | case TEXTURE_TYPE_TEXTURE_3D: |
| 387 | desc.dimension = WGPUTextureDimension_3D; |
| 388 | break; |
| 389 | case TEXTURE_TYPE_2D: |
| 390 | case TEXTURE_TYPE_IMAGE_2D: |
| 391 | case TEXTURE_TYPE_2D_ARRAY: |
| 392 | case TEXTURE_TYPE_TEXTURE_2D: |
| 393 | case TEXTURE_TYPE_TEXTURE_2D_ARRAY: |
| 394 | desc.dimension = WGPUTextureDimension_2D; |
| 395 | break; |
| 396 | case TEXTURE_TYPE_CUBE_MAP: |
| 397 | case TEXTURE_TYPE_TEXTURE_CUBE: |
| 398 | desc.dimension = WGPUTextureDimension_2D; |
| 399 | desc.size.depthOrArrayLayers = 6; |
| 400 | break; |
| 401 | case TEXTURE_TYPE_SAMPLER: |
| 402 | dmLogError("Unable to realize texture, unsupported type (%s).", GetTextureTypeLiteral(texture->m_Base.m_Type)); |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | texture->m_Texture = wgpuDeviceCreateTexture(g_WebGPUContext->m_Device, &desc); |
| 407 | } |
| 408 | { |
| 409 | #if defined(DM_GRAPHICS_WEBGPU2) |
| 410 | WGPUTextureViewDescriptor desc = WGPU_TEXTURE_VIEW_DESCRIPTOR_INIT; |
| 411 | #else |
| 412 | WGPUTextureViewDescriptor desc = {}; |
| 413 | #endif |
no test coverage detected