VTK  9.7.20261123
vtkWebGPUVolumeBrickPool.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
23
24#ifndef vtkWebGPUVolumeBrickPool_h
25#define vtkWebGPUVolumeBrickPool_h
26
27#include "Private/vtkWebGPUHandle.h" // for the reference counted handle wrappers
28
29#include "vtkABINamespace.h"
30
31#include "vtk_wgpu.h"
32
33#include <cstdint>
34#include <map>
35#include <vector>
36
37VTK_ABI_NAMESPACE_BEGIN
38
40
42{
43public:
45 static constexpr std::uint32_t InvalidSlot = 0xFFFFFFFFu;
46
49 enum class Kind
50 {
51 Byte = 0,
52 Float = 1,
57 Mask = 4,
59 };
60
62 struct Key
63 {
64 const void* Owner = nullptr;
65 std::uint32_t Brick = 0;
66
67 bool operator<(const Key& other) const
68 {
69 return this->Owner != other.Owner ? this->Owner < other.Owner : this->Brick < other.Brick;
70 }
71 };
72
79 void Configure(vtkWebGPURenderWindow* window, int brickSize, std::size_t budgetBytes,
80 std::size_t wantedSlots, std::uint32_t bytesPerVoxel);
81
84 void BeginFrame();
85
87
92 std::uint32_t Lookup(const Key& key);
93 std::uint32_t Allocate(const Key& key);
95
100 void Upload(Kind kind, std::uint32_t slot, const void* voxels);
101
103 void Release(const Key& key);
104
106 void Forget(const void* owner);
107
109
112 int GetBrickSize() const { return this->BrickSize; }
113 int GetSlotSize() const { return this->BrickSize + 2; }
114 const std::uint32_t* GetSlotGrid() const { return this->SlotGrid; }
115 std::uint32_t GetCapacity() const { return this->Capacity; }
117
119 WGPUTextureView GetView(Kind kind);
120
122 bool IsUsed(Kind kind) const { return this->Textures[static_cast<int>(kind)] != nullptr; }
123
124private:
125 void EnsureTexture(Kind kind);
126 void SlotOrigin(std::uint32_t slot, std::uint32_t origin[3]) const;
127
128 vtkWebGPURenderWindow* Window = nullptr;
129
130 int BrickSize = 0;
131 std::uint32_t SlotGrid[3] = { 0, 0, 0 };
132 std::uint32_t Capacity = 0;
133
134 struct SlotState
135 {
136 Key Owner;
137 std::uint64_t LastUsed = 0;
138 bool Occupied = false;
139 };
140 std::vector<SlotState> Slots;
141 std::map<Key, std::uint32_t> Residency;
142 std::uint64_t Frame = 0;
144 std::uint32_t NextVictim = 0;
145
146 static constexpr int KindCount = static_cast<int>(Kind::Count);
147 vtkWebGPU::Texture Textures[KindCount];
148 vtkWebGPU::TextureView Views[KindCount];
149 vtkWebGPU::Texture Placeholders[KindCount];
150 vtkWebGPU::TextureView PlaceholderViews[KindCount];
151};
152
153VTK_ABI_NAMESPACE_END
154#endif
155// VTK-HeaderTest-Exclude: vtkWebGPUVolumeBrickPool.h
WebGPU rendering window.
Fixed size 3D texture that holds the resident bricks of every volume in a pass.
WGPUTextureView GetView(Kind kind)
Views of the pool textures. A kind that no volume has used yet is a one voxel placeholder.
void BeginFrame()
Start gathering a frame.
std::uint32_t Allocate(const Key &key)
Look up a brick, or make room for one.
void Release(const Key &key)
Give a slot back, for when the brick it was allocated for could not be fetched after all.
std::uint32_t Lookup(const Key &key)
Look up a brick, or make room for one.
static constexpr std::uint32_t InvalidSlot
A page whose slot is this is not resident and must not be sampled.
void Configure(vtkWebGPURenderWindow *window, int brickSize, std::size_t budgetBytes, std::size_t wantedSlots, std::uint32_t bytesPerVoxel)
Make room for wantedSlots bricks of brickSize voxels a side within budgetBytes.
const std::uint32_t * GetSlotGrid() const
bool IsUsed(Kind kind) const
Whether kind has been asked for since the pool was configured.
void Forget(const void *owner)
Let go of every slot that owner holds.
Kind
How a volume's scalars are stored.
@ Mask
Two bytes per voxel: whether it is hidden, by a ghost, blanking or a binary mask, and its label for a...
void Upload(Kind kind, std::uint32_t slot, const void *voxels)
Fill a slot.
Identifies one brick of one volume for as long as the volume keeps offering itself.
bool operator<(const Key &other) const
Reference-counted ownership for WebGPU C API handles.