MCPcopy Create free account
hub / github.com/Kitware/VTK / SendToWebGPUDevice

Method SendToWebGPUDevice

Rendering/WebGPU/vtkWebGPURenderTextureDeviceResource.cxx:208–278  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

206
207//------------------------------------------------------------------------------
208void vtkWebGPURenderTextureDeviceResource::SendToWebGPUDevice(std::vector<void*> dataPlanes,
209 vtkWebGPUConfiguration* wgpuConfiguration, bool cubeMap /*= false*/)
210{
211 vtkLog(TRACE, "Sending texture to WebGPU device: " << this->GetLabel());
212 // Assumptions made on inputs:
213 // - inputs.size() = 1 for 1D/2D/3D textures
214 // - inputs.size() = 6, and cubeMap = true for cube maps
215
216 const int dimension = this->GetDimension();
217 if (cubeMap && (dataPlanes.size() != 6 || dimension != DIMENSION_2D))
218 {
219 vtkErrorMacro("Cube maps require 6 data planes, each a 2D texture. There are "
220 << dataPlanes.size() << " data planes and dimension is " << static_cast<int>(dimension));
221 return;
222 }
223 // create texture.
224 this->TextureDescriptor = {};
225 this->TextureDescriptor.label = std::string_view(this->Label);
226 this->TextureDescriptor.dimension =
227 vtkWebGPUComputePassTextureStorageInternals::ComputeTextureDimensionToWebGPU(
228 this->GetDimension());
229 this->TextureDescriptor.size.width = this->GetWidth();
230 this->TextureDescriptor.size.height = this->GetHeight();
231 this->TextureDescriptor.size.depthOrArrayLayers = this->GetDepth();
232 this->TextureDescriptor.format =
233 vtkWebGPUComputePassTextureStorageInternals::ComputeTextureFormatToWebGPU(this->GetFormat());
234 this->TextureDescriptor.mipLevelCount = this->GetMipLevelCount();
235 this->TextureDescriptor.sampleCount = this->SampleCount;
236 this->TextureDescriptor.usage =
237 vtkWebGPUComputePassTextureStorageInternals::ComputeTextureModeToUsage(this->GetMode(),
238 this->TextureDescriptor.label.IsUndefined() ? std::string("Unnamed Texture")
239 : std::string(this->TextureDescriptor.label));
240 this->Texture = wgpuConfiguration->CreateTexture(this->TextureDescriptor);
241 // upload data
242 const auto bytesPerRow = this->GetWidth() * this->GetBytesPerPixel();
243 const auto sizeBytes = bytesPerRow * this->GetHeight() * this->GetDepth();
244 wgpu::Origin3D dstOrigin = { 0, 0, 0 };
245 std::uint32_t srcOffset = 0;
246 for (size_t i = 0; i < dataPlanes.size(); ++i)
247 {
248 vtkLog(TRACE,
249 " Uploading data plane " << i << " of size " << sizeBytes << " bytes"
250 << (cubeMap ? " for cube map face." : "."));
251 std::uint32_t dstMipLevel = 0;
252 if (cubeMap)
253 {
254 dstOrigin.z = static_cast<std::uint32_t>(i);
255 }
256 wgpuConfiguration->WriteTexture(this->Texture, bytesPerRow, sizeBytes, dataPlanes[i], srcOffset,
257 dstOrigin, dstMipLevel, cubeMap ? "Upload Cube Map Face" : "Upload Texture Data");
258 }
259 this->SamplerDescriptor = {};
260 this->SamplerDescriptor.addressModeU = this->GetWebGPUAddressMode(this->AddressModeU);
261 this->SamplerDescriptor.addressModeV = this->GetWebGPUAddressMode(this->AddressModeV);
262 this->SamplerDescriptor.addressModeW = this->GetWebGPUAddressMode(this->AddressModeW);
263 this->SamplerDescriptor.magFilter = this->GetWebGPUFilterMode(this->MagFilter);
264 this->SamplerDescriptor.minFilter = this->GetWebGPUFilterMode(this->MinFilter);
265 this->SamplerDescriptor.mipmapFilter = this->GetWGPUMipMapFilterMode(this->MipmapFilter);

Callers 1

LoadMethod · 0.80

Calls 15

GetWebGPUAddressModeMethod · 0.95
GetWebGPUFilterModeMethod · 0.95
GetModeMethod · 0.80
GetBytesPerPixelMethod · 0.80
CreateViewMethod · 0.80
stringClass · 0.50
GetLabelMethod · 0.45
GetDimensionMethod · 0.45
sizeMethod · 0.45
GetWidthMethod · 0.45

Tested by

no test coverage detected