4#ifndef vtkWebGPUComputePassInternals_h
5#define vtkWebGPUComputePassInternals_h
15#include <unordered_map>
16#include <unordered_set>
20VTK_ABI_NAMESPACE_BEGIN
79 WGPUTextureViewDimension textureViewDimension);
110 const WGPUDevice& device,
const std::vector<WGPUBindGroupLayoutEntry>& layoutEntries);
116 const std::vector<vtkWebGPUComputeBuffer*>& buffers);
293 void WebGPUDispatch(
unsigned int groupsX,
unsigned int groupsY,
unsigned int groupsZ);
328 bool Initialized =
false;
332 bool BindGroupOrLayoutsInvalidated =
true;
340 vtkWebGPU::ShaderModule ShaderModule;
342 std::vector<vtkWebGPU::BindGroup> BindGroups;
345 std::unordered_map<int, std::vector<WGPUBindGroupEntry>> BindGroupEntries;
346 std::vector<vtkWebGPU::BindGroupLayout> BindGroupLayouts;
349 std::unordered_map<int, std::vector<WGPUBindGroupLayoutEntry>> BindGroupLayoutEntries;
351 vtkWebGPU::ComputePipeline ComputePipeline;
a simple class to control print indentation
Hold a reference to a vtkObjectBase instance.
a weak reference to a vtkObject.
void RecreateRenderTexture(vtkSmartPointer< vtkWebGPUComputeRenderTexture > renderTexture)
Recreates a render texture given a new textureView and possibly new parameters as specified in the 'r...
friend class vtkWebGPUComputePassBufferStorageInternals
bool GetRegisteredBufferFromPipeline(vtkSmartPointer< vtkWebGPUComputeBuffer > buffer, vtkWebGPU::Buffer &wgpuBuffer)
Checks whether the given compute buffer/texture has already been registered in the pipeline associate...
void UpdateWebGPUBuffer(vtkSmartPointer< vtkWebGPUComputeBuffer > buffer, vtkWebGPU::Buffer wgpuBuffer)
Updates the vtkWebGPU::Buffer reference that a compute buffer is associated to.
vtkWeakPointer< vtkWebGPUComputePipeline > GetAssociatedPipeline()
Get/set the compute pipeline to which this compute pass belongs to.
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.
friend class vtkWebGPUComputePassTextureStorageInternals
friend class vtkWebGPUPointCloudMapperInternals
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool GetRegisteredTextureFromPipeline(vtkSmartPointer< vtkWebGPUComputeTexture > texture, vtkWebGPU::Texture &wgpuTexture)
Checks whether the given compute buffer/texture has already been registered in the pipeline associate...
vtkWeakPointer< vtkWebGPUComputePass > ParentPass
vtkWebGPU::Buffer GetWGPUBuffer(std::size_t bufferIndex)
Returns the vtkWebGPU::Buffer object for a buffer in this compute pass buffer storage given its index...
~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.
WGPUBindGroupLayoutEntry 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...
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 corresponds to a texture of this compute pass.
void UpdateComputeTextureAndViews(vtkSmartPointer< vtkWebGPUComputeTexture > texture, vtkWebGPU::Texture newWgpuTexture)
Makes sure that the compute texture given in parameter internally points to the given newWgpuTexture.
void RegisterBufferToPipeline(vtkSmartPointer< vtkWebGPUComputeBuffer > buffer, vtkWebGPU::Buffer wgpuBuffer)
Registers a buffer to the associated compute pipeline of this compute pass so that other compute pass...
vtkWebGPU::TextureView CreateWebGPUTextureView(vtkSmartPointer< vtkWebGPUComputeTextureView > textureView, vtkWebGPU::Texture wgpuTexture)
Utilitary method to create a vtkWebGPU::TextureView from a ComputeTextureView and the texture this vt...
void RecreateTextureBindGroup(int textureIndex)
After recreating a vtkWebGPU::Buffer, the bind group entry (and the bind group) will need to be updat...
static vtkWebGPU::BindGroupLayout CreateBindGroupLayout(const WGPUDevice &device, const std::vector< WGPUBindGroupLayoutEntry > &layoutEntries)
Creates the bind group layout of a given list of buffers (that must all belong to the same bind group...
WGPUCommandEncoder CreateCommandEncoder()
Creates and returns a command encoder.
vtkWebGPUComputePassInternals()=default
WGPUBindGroupLayoutEntry CreateBindGroupLayoutEntry(uint32_t binding, vtkSmartPointer< vtkWebGPUComputeTexture > computeTexture, WGPUTextureViewDimension textureViewDimension)
Overload mainly used for creating the layout entry of render textures where we don't have a vtkWebGPU...
WGPUBindGroupEntry CreateBindGroupEntry(WGPUBuffer 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 ReleaseResources()
Releases the resources of this compute pass internals.
void RecreateBufferBindGroup(int bufferIndex)
Recreates the bind group and bind group entry of a buffer (given by its index).
friend class vtkWebGPUComputePass
bool CheckTextureViewIndex(int textureViewIndex, const std::string &callerFunctionName)
Checks if a given index corresponds to a texture texture view of this compute pass.
void RecreateBuffer(int bufferIndex, vtkIdType newByteSize)
Destroys and recreates a buffer with the given newByteSize Only the vtkWebGPU::Buffer object is recre...
friend class vtkWebGPUComputePipeline
WGPUBindGroupLayoutEntry 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 SetWGPUConfiguration(vtkWebGPUConfiguration *config)
Get/set the device used by this compute pass (usually the device of the compute pipeline holding this...
vtkWebGPU::PipelineLayout CreateWebGPUComputePipelineLayout()
Creates the compute pipeline layout associated with the bind group layouts of this compute pass.
void RegisterTextureToPipeline(vtkSmartPointer< vtkWebGPUComputeTexture > texture, vtkWebGPU::Texture wgpuTexture)
Registers a texture to the associated compute pipeline of this compute pass so that other compute pas...
bool CheckBufferIndex(int bufferIndex, const std::string &callerFunctionName)
Checks if a given index is suitable for indexing Buffers.
static vtkWebGPUComputePassInternals * New()
void SetAssociatedPipeline(vtkWeakPointer< vtkWebGPUComputePipeline > associatedPipeline)
Get/set the compute pipeline to which this compute pass belongs to.
WGPUComputePassEncoder CreateComputePassEncoder(const WGPUCommandEncoder &commandEncoder)
Creates a compute pass encoder from a command encoder.
void WebGPUDispatch(unsigned int groupsX, unsigned int groupsY, unsigned int groupsZ)
Encodes the compute pass and dispatches the workgroups.
std::vector< WGPUBindGroupEntry > CreateBindGroupEntries(const std::vector< vtkWebGPUComputeBuffer * > &buffers)
Creates the bind group entries given a list of buffers.
void SetParentPass(vtkWeakPointer< vtkWebGPUComputePass > parentPass)
Sets the parent pass of this internals class.
void SubmitCommandEncoderToQueue(const WGPUCommandEncoder &commandEncoder)
Finishes the encoding of a command encoder and submits the resulting command buffer to the queue.
WGPUBindGroupEntry CreateBindGroupEntry(uint32_t binding, WGPUTextureView textureView)
Given a texture view, creates the associated bind group entry that will be used when creating the bin...
A compute pipeline is the orchestrator of a collection of compute passes.
Create a webgpu device for use in rendering and compute pipelines.
Reference-counted ownership for WebGPU C API handles.