| 127 | } |
| 128 | |
| 129 | bool GPUTextureWebGPU::OnInit() |
| 130 | { |
| 131 | // Create texture |
| 132 | WGPUTextureDescriptor textureDesc = WGPU_TEXTURE_DESCRIPTOR_INIT; |
| 133 | #if GPU_ENABLE_RESOURCE_NAMING |
| 134 | _name.Set(_namePtr, _nameSize); |
| 135 | textureDesc.label = { _name.Get(), (size_t)_name.Length() }; |
| 136 | #endif |
| 137 | if (!IsDepthStencil()) |
| 138 | textureDesc.usage |= WGPUTextureUsage_CopyDst; |
| 139 | if (IsStaging()) |
| 140 | textureDesc.usage |= WGPUTextureUsage_CopySrc | WGPUTextureUsage_CopyDst; |
| 141 | if (IsShaderResource()) |
| 142 | textureDesc.usage |= WGPUTextureUsage_TextureBinding; |
| 143 | if (IsUnorderedAccess()) |
| 144 | textureDesc.usage |= WGPUTextureUsage_StorageBinding; |
| 145 | if (IsRenderTarget() || IsDepthStencil()) |
| 146 | textureDesc.usage |= WGPUTextureUsage_RenderAttachment; |
| 147 | textureDesc.size.width = _desc.Width; |
| 148 | textureDesc.size.height = _desc.Height; |
| 149 | switch (_desc.Dimensions) |
| 150 | { |
| 151 | case TextureDimensions::Texture: |
| 152 | _viewDimension = IsArray() ? WGPUTextureViewDimension_2DArray : WGPUTextureViewDimension_2D; |
| 153 | textureDesc.dimension = WGPUTextureDimension_2D; |
| 154 | textureDesc.size.depthOrArrayLayers = _desc.ArraySize; |
| 155 | break; |
| 156 | case TextureDimensions::VolumeTexture: |
| 157 | _viewDimension = WGPUTextureViewDimension_3D; |
| 158 | textureDesc.dimension = WGPUTextureDimension_3D; |
| 159 | textureDesc.size.depthOrArrayLayers = _desc.Depth; |
| 160 | break; |
| 161 | case TextureDimensions::CubeTexture: |
| 162 | _viewDimension = _desc.ArraySize > 6 ? WGPUTextureViewDimension_CubeArray : WGPUTextureViewDimension_Cube; |
| 163 | textureDesc.dimension = WGPUTextureDimension_2D; |
| 164 | textureDesc.size.depthOrArrayLayers = _desc.ArraySize; |
| 165 | break; |
| 166 | } |
| 167 | textureDesc.format = RenderToolsWebGPU::ToTextureFormat(Format()); |
| 168 | textureDesc.mipLevelCount = _desc.MipLevels; |
| 169 | textureDesc.sampleCount = (uint32_t)_desc.MultiSampleLevel; |
| 170 | textureDesc.viewFormats = &textureDesc.format; |
| 171 | textureDesc.viewFormatCount = 1; |
| 172 | _format = textureDesc.format; |
| 173 | Usage = textureDesc.usage; |
| 174 | Texture = wgpuDeviceCreateTexture(_device->Device, &textureDesc); |
| 175 | if (!Texture) |
| 176 | return true; |
| 177 | _version = _device->GetObjectVersion(); |
| 178 | |
| 179 | // Update memory usage |
| 180 | _memoryUsage = calculateMemoryUsage(); |
| 181 | |
| 182 | // Initialize handles to the resource |
| 183 | if (IsRegularTexture()) |
| 184 | { |
| 185 | // 'Regular' texture is using only one handle (texture/cubemap) |
| 186 | _handlesPerSlice.Resize(1, false); |
nothing calls this directly
no test coverage detected