4#ifndef vtkWebGPUComputePassTextureStorageInternals_h
5#define vtkWebGPUComputePassTextureStorageInternals_h
18#include <unordered_map>
19#include <unordered_set>
21VTK_ABI_NAMESPACE_BEGIN
225 void WriteTexture(std::size_t textureIndex,
const void* bytes, std::size_t numBytes)
232 wgpu::Texture wgpuTexture;
234 wgpuTexture = this->WebGPUTextures[textureIndex];
235 texture = this->Textures[textureIndex];
237 if (numBytes >
static_cast<std::size_t
>(texture->GetByteSize()))
240 "The given data is larger than what the texture \""
241 << texture->GetLabel() <<
"\" with byte size: " << texture->GetByteSize());
246 wgpu::Extent3D textureExtents = { texture->GetWidth(), texture->GetHeight(),
247 texture->GetDepth() };
249 wgpu::ImageCopyTexture copyTexture;
250 copyTexture.aspect = wgpu::TextureAspect::All;
251 copyTexture.mipLevel = 0;
252 copyTexture.origin = { 0, 0, 0 };
253 copyTexture.texture = wgpuTexture;
255 wgpu::TextureDataLayout textureDataLayout;
256 textureDataLayout.nextInChain =
nullptr;
257 textureDataLayout.bytesPerRow = texture->GetBytesPerPixel() * textureExtents.width;
258 textureDataLayout.offset = 0;
259 textureDataLayout.rowsPerImage = textureExtents.height;
262 this->ParentPassWGPUConfiguration->
GetDevice().GetQueue().WriteTexture(
263 ©Texture, bytes, numBytes, &textureDataLayout, &textureExtents);
349 std::vector<vtkSmartPointer<vtkWebGPUComputeTexture>> Textures;
351 std::vector<vtkSmartPointer<vtkWebGPUComputeRenderTexture>> RenderTextures;
353 std::unordered_map<vtkSmartPointer<vtkWebGPUComputeRenderTexture>, wgpu::Texture>
354 RenderTexturesToWebGPUTexture;
356 std::vector<wgpu::Texture> WebGPUTextures;
360 std::unordered_map<vtkSmartPointer<vtkWebGPUComputeTexture>,
361 std::unordered_set<vtkSmartPointer<vtkWebGPUComputeTextureView>>>
362 ComputeTextureToViews;
365 std::vector<vtkSmartPointer<vtkWebGPUComputeTextureView>> TextureViews;
367 std::unordered_map<vtkSmartPointer<vtkWebGPUComputeTextureView>, wgpu::TextureView>
368 TextureViewsToWebGPUTextureViews;
abstract base class for most VTK objects
Hold a reference to a vtkObjectBase instance.
a weak reference to a vtkObject.
Internals of the vtkWebGPUComputePass.
This class manages the creation/deletion/recreation/ of compute textures used by a compute pass.
vtkSetSmartPointerMacro(ParentPassWGPUConfiguration, vtkWebGPUConfiguration)
Sets the device that will be used by this texture storage when creating textures / texture views.
bool CheckTextureViewCorrectness(vtkWebGPUComputeTextureView *textureView)
Makes sure the texture view is correct with regards to its properties (binding, group,...
vtkSmartPointer< vtkWebGPUComputeTextureView > GetTextureView(std::size_t textureViewIndex)
Retrieves the texture view associated with the given texture view index.
static wgpu::TextureFormat ComputeTextureFormatToWebGPU(vtkWebGPUComputeTexture::TextureFormat format)
Internal method used to convert the user friendly TextureFormat enum to its wgpu::TextureFormat equiv...
int AddTextureView(vtkSmartPointer< vtkWebGPUComputeTextureView > textureView)
Adds a texture view to the compute pass and returns its index.
void ReadTextureFromGPU(std::size_t textureIndex, int mipLevel, vtkWebGPUComputePass::TextureMapAsyncCallback callback, void *userdata)
static wgpu::StorageTextureAccess ComputeTextureViewModeToShaderStorage(vtkWebGPUComputeTextureView::TextureViewMode mode, const std::string &textureViewLabel)
Internal method used to get the StorageTextureAccess mode associated with a TextureViewMode.
void RecreateTextureViews(std::size_t textureIndex)
Recreates all the texture views of a texture given its index.
vtkSmartPointer< vtkWebGPUComputeTexture > GetComputeTexture(std::size_t textureIndex)
Retrieves the compute texture associated with the given texture index.
static vtkWebGPUComputePassTextureStorageInternals * New()
wgpu::TextureView CreateWebGPUTextureView(vtkSmartPointer< vtkWebGPUComputeTextureView > textureView, wgpu::Texture wgpuTexture)
Utilitary method to create a wgpu::TextureView from a ComputeTextureView and the texture this wgpu::T...
static wgpu::TextureUsage ComputeTextureModeToUsage(vtkWebGPUComputeTexture::TextureMode mode, const std::string &textureLabel)
Internal method used to convert the user friendly TextureMode enum to its wgpu::TextureUsage equivale...
void ReleaseResources()
Releases the textures & resources held by this texture storage.
void RebindTextureView(std::size_t group, uint32_t binding, std::size_t textureViewIndex)
This function allows the usage of multiple texture views on a single binding point (group / binding c...
void WriteTexture(std::size_t textureIndex, const void *bytes, std::size_t numBytes)
Uploads the given data to the texture starting at pixel (0, 0)
static wgpu::TextureViewDimension ComputeTextureDimensionToViewDimension(vtkWebGPUComputeTexture::TextureDimension dimension)
This function does a simple mapping between the dimension of the texture (vtkWebGPUComputeTexture::Te...
static wgpu::StorageTextureAccess ComputeTextureModeToShaderStorage(vtkWebGPUComputeTexture::TextureMode mode, const std::string &textureLabel)
Internal method used to get the StorageTextureAccess mode associated with a TextureMode.
int AddRenderTexture(vtkSmartPointer< vtkWebGPUComputeRenderTexture > renderTexture)
Adds a render texture to the storage.
~vtkWebGPUComputePassTextureStorageInternals() override
bool CheckTextureCorrectness(vtkWebGPUComputeTexture *texture)
Makes sure the texture is correct with regards to its properties (size, ...)
void DeleteTextureViews(std::size_t textureIndex)
Deletes all the texture views of a given texture (given by its index)
void SetComputePass(vtkWeakPointer< vtkWebGPUComputePass > parentComputePass)
Sets the compute pass that uses the textures and texture views used by this storage.
void RecreateRenderTexture(vtkSmartPointer< vtkWebGPUComputeRenderTexture > renderTexture)
Recreates a render texture given a new textureView and possibly new parameters as specified in the 'r...
static wgpu::TextureSampleType ComputeTextureSampleTypeToWebGPU(vtkWebGPUComputeTexture::TextureSampleType sampleType)
Internal method used to convert the user friendly TextureSampleType enum to its wgpu::TextureSampleTy...
bool CheckTextureIndex(std::size_t textureIndex, const std::string &callerFunctionName)
Checks if a given index is suitable for indexing this->Textures.
static wgpu::TextureAspect ComputeTextureViewAspectToWebGPU(vtkWebGPUComputeTextureView::TextureViewAspect aspect)
Internal method used to convert the user friendly TextureAspect enum to its wgpu::TextureAspect equiv...
vtkWebGPUComputePassTextureStorageInternals()=default
void UpdateComputeTextureAndViews(vtkSmartPointer< vtkWebGPUComputeTexture > texture, wgpu::Texture newWgpuTexture)
Makes sure that the compute texture given in parameter internally points to the given newWgpuTexture.
int AddTexture(vtkSmartPointer< vtkWebGPUComputeTexture > texture)
Adds a texture to the storage and upload its data to the device.
void RecreateTextureView(std::size_t textureViewIndex)
Recreates a compute texture view.
void RecreateComputeTexture(std::size_t textureIndex)
Recreates a compute texture.
static wgpu::TextureDimension ComputeTextureDimensionToWebGPU(vtkWebGPUComputeTexture::TextureDimension dimension)
Internal method used to convert the user friendly Dimension enum to its wgpu::TextureDimension equiva...
void RecreateTexture(std::size_t textureIndex)
Destroys and recreates the texture with the given index.
bool CheckTextureViewIndex(std::size_t textureViewIndex, const std::string &callerFunctionName)
Checks if a given index is suitable for indexing this->TextureViews.
vtkSmartPointer< vtkWebGPUComputeTextureView > CreateTextureView(std::size_t textureIndex)
Returns a new texture view on the given texture (given by the index) that can be configured and then ...
bool CheckParentComputePass(const std::string &callerFunctionName)
Checks whether or not the associated ParentComputePass and ParentPassDevice are non-null.
A compute pass is an abstraction for offloading computation from the CPU onto the GPU using WebGPU co...
std::function< void(const void *, int, void *)> TextureMapAsyncCallback
Represents the set of parameters that will be used to create a compute shader texture on the device w...
Create a webgpu device for use in rendering and compute pipelines.
wgpu::Device GetDevice()
Get handles of the WGPU adapter/device/instance.
TextureViewAspect
What will the shader sample from the texture when calling a sampling function.
TextureViewMode
The mode of the texture view to define what operations will be doable on the texture in the shader.
TextureMode
How will the texture be used by the shader.
TextureDimension
How the texture data is arranged.
TextureSampleType
Determines what kind of value is returned when reading from the texture in the compute shader.
TextureFormat
RGBA8_UNORM: Uses RGB + alpha.
#define vtkLog(verbosity_name, x)
Add to log given the verbosity level.