4#ifndef vtkWebGPUComputePassInternals_h
5#define vtkWebGPUComputePassInternals_h
14#include <unordered_map>
15#include <unordered_set>
19VTK_ABI_NAMESPACE_BEGIN
78 wgpu::TextureViewDimension textureViewDimension);
109 const wgpu::Device& device,
const std::vector<wgpu::BindGroupLayoutEntry>& layoutEntries);
115 const std::vector<vtkWebGPUComputeBuffer*>& buffers);
291 void WebGPUDispatch(
unsigned int groupsX,
unsigned int groupsY,
unsigned int groupsZ);
326 bool Initialized =
false;
330 bool BindGroupOrLayoutsInvalidated =
true;
338 wgpu::ShaderModule ShaderModule;
340 std::vector<wgpu::BindGroup> BindGroups;
343 std::unordered_map<int, std::vector<wgpu::BindGroupEntry>> BindGroupEntries;
344 std::vector<wgpu::BindGroupLayout> BindGroupLayouts;
347 std::unordered_map<int, std::vector<wgpu::BindGroupLayoutEntry>> BindGroupLayoutEntries;
349 wgpu::ComputePipeline ComputePipeline;
a simple class to control print indentation
abstract base class for most VTK objects
Hold a reference to a vtkObjectBase instance.
a weak reference to a vtkObject.
This class manages the creation/deletion/recreation/resizing/updating of compute buffers used by a co...
Internals of the vtkWebGPUComputePass.
void RecreateRenderTexture(vtkSmartPointer< vtkWebGPUComputeRenderTexture > renderTexture)
Recreates a render texture given a new textureView and possibly new parameters as specified in the 'r...
void RegisterTextureToPipeline(vtkSmartPointer< vtkWebGPUComputeTexture > texture, wgpu::Texture wgpuTexture)
Registers a texture to the associated compute pipeline of this compute pass so that other compute pas...
bool GetRegisteredBufferFromPipeline(vtkSmartPointer< vtkWebGPUComputeBuffer > buffer, wgpu::Buffer &wgpuBuffer)
Checks whether the given compute buffer/texture has already been registered in the pipeline associate...
std::vector< wgpu::BindGroupEntry > CreateBindGroupEntries(const std::vector< vtkWebGPUComputeBuffer * > &buffers)
Creates the bind group entries given a list of buffers.
vtkWeakPointer< vtkWebGPUComputePipeline > GetAssociatedPipeline()
Get/set the compute pipeline to which this compute pass belongs to.
wgpu::BindGroupEntry CreateBindGroupEntry(wgpu::Buffer buffer, uint32_t binding, vtkWebGPUComputeBuffer::BufferMode mode, uint32_t offset)
Given a buffer, creates the associated bind group entry that will be used when creating the bind grou...
void CreateBindGroupsAndLayouts()
Creates all the bind groups and bind group layouts of this compute pass from the buffers that have be...
void SetupRenderBuffer(vtkSmartPointer< vtkWebGPUComputeRenderBuffer > renderBuffer)
Binds the buffer to the compute pass at the WebGPU level.
wgpu::Buffer GetWGPUBuffer(std::size_t bufferIndex)
Returns the wgpu::Buffer object for a buffer in this compute pass buffer storage given its index.
wgpu::PipelineLayout CreateWebGPUComputePipelineLayout()
Creates the compute pipeline layout associated with the bind group layouts of this compute pass.
wgpu::CommandEncoder CreateCommandEncoder()
Creates and returns a command encoder.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void UpdateComputeTextureAndViews(vtkSmartPointer< vtkWebGPUComputeTexture > texture, wgpu::Texture newWgpuTexture)
Makes sure that the compute texture given in parameter internally points to the given newWgpuTexture.
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...
vtkWeakPointer< vtkWebGPUComputePass > ParentPass
wgpu::BindGroupLayoutEntry CreateBindGroupLayoutEntry(uint32_t binding, vtkWebGPUComputeBuffer::BufferMode mode)
Given a buffer, creates the associated bind group layout entry that will be used when creating the bi...
~vtkWebGPUComputePassInternals() override
void CreateShaderModule()
Compiles the shader source given into a WGPU shader module.
void RecreateTexture(int textureIndex)
Destroys and recreates the texture with the given index.
void CreateWebGPUComputePipeline()
Creates the compute pipeline that will be used to dispatch the compute shader.
void RecreateTextureViews(int textureIndex)
Recreates all the texture views of a texture given its index.
bool CheckBufferCorrectness(vtkSmartPointer< vtkWebGPUComputeBuffer > buffer)
Returns true if the buffer is ready to be added to the compute pass or not.
bool CheckTextureIndex(int textureIndex, const std::string &callerFunctionName)
Checks if a given index correponds to a texture of this compute pass.
void RegisterBufferToPipeline(vtkSmartPointer< vtkWebGPUComputeBuffer > buffer, wgpu::Buffer wgpuBuffer)
Registers a buffer to the associated compute pipeline of this compute pass so that other compute pass...
void UpdateWebGPUBuffer(vtkSmartPointer< vtkWebGPUComputeBuffer > buffer, wgpu::Buffer wgpuBuffer)
Updates the wgpu::Buffer reference that a compute buffer is associated to.
void RecreateTextureBindGroup(int textureIndex)
After recreating a wgpu::Buffer, the bind group entry (and the bind group) will need to be updated.
vtkWebGPUComputePassInternals()=default
void ReleaseResources()
Releases the resources of this compute pass internals.
bool GetRegisteredTextureFromPipeline(vtkSmartPointer< vtkWebGPUComputeTexture > texture, wgpu::Texture &wgpuTexture)
Checks whether the given compute buffer/texture has already been registered in the pipeline associate...
void SubmitCommandEncoderToQueue(const wgpu::CommandEncoder &commandEncoder)
Finishes the encoding of a command encoder and submits the resulting command buffer to the queue.
void RecreateBufferBindGroup(int bufferIndex)
Recreates the bind group and bind group entry of a buffer (given by its index)
bool CheckTextureViewIndex(int textureViewIndex, const std::string &callerFunctionName)
Checks if a given index correponds to a texture texture view of this compute pass.
static wgpu::BindGroupLayout CreateBindGroupLayout(const wgpu::Device &device, const std::vector< wgpu::BindGroupLayoutEntry > &layoutEntries)
Creates the bind group layout of a given list of buffers (that must all belong to the same bind group...
void RecreateBuffer(int bufferIndex, vtkIdType newByteSize)
Destroys and recreates a buffer with the given newByteSize Only the wgpu::Buffer object is recreated ...
void SetWGPUConfiguration(vtkWebGPUConfiguration *config)
Get/set the device used by this compute pass (usually the device of the compute pipeline holding this...
bool CheckBufferIndex(int bufferIndex, const std::string &callerFunctionName)
Checks if a given index is suitable for indexing Buffers.
wgpu::BindGroupLayoutEntry CreateBindGroupLayoutEntry(uint32_t binding, vtkSmartPointer< vtkWebGPUComputeTexture > computeTexture, wgpu::TextureViewDimension textureViewDimension)
Overload mainly used for creating the layout entry of render textures where we don't have a vtkWebGPU...
static vtkWebGPUComputePassInternals * New()
wgpu::BindGroupLayoutEntry CreateBindGroupLayoutEntry(uint32_t binding, vtkSmartPointer< vtkWebGPUComputeTexture > computeTexture, vtkSmartPointer< vtkWebGPUComputeTextureView > textureView)
Given a texture and its view, creates the associated bind group layout entry and returns it.
void SetAssociatedPipeline(vtkWeakPointer< vtkWebGPUComputePipeline > associatedPipeline)
Get/set the compute pipeline to which this compute pass belongs to.
wgpu::BindGroupEntry CreateBindGroupEntry(uint32_t binding, wgpu::TextureView textureView)
Given a texture view, creates the associated bind group entry that will be used when creating the bin...
void WebGPUDispatch(unsigned int groupsX, unsigned int groupsY, unsigned int groupsZ)
Encodes the compute pass and dispatches the workgroups.
wgpu::ComputePassEncoder CreateComputePassEncoder(const wgpu::CommandEncoder &commandEncoder)
Creates a compute pass encoder from a command encoder.
void SetParentPass(vtkWeakPointer< vtkWebGPUComputePass > parentPass)
Sets the parent pass of this internals class.
This class manages the creation/deletion/recreation/ of compute textures used by a compute pass.
A compute pass is an abstraction for offloading computation from the CPU onto the GPU using WebGPU co...
A compute pipeline is the orchestrator of a collection of compute passes.
Create a webgpu device for use in rendering and compute pipelines.
Internal implementation details of vtkWebGPUPointCloudMapper.