Skip to content

Commit 9aa8bcf

Browse files
committed
add uint8 render target
1. use render buffers instead of textured for deferred rendering 2. add the ability to change rendering ratio and use OpenGL for blitting
1 parent 217d323 commit 9aa8bcf

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

fast_gauss/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self,
2929
init_buffer_size: int = 32768,
3030
init_texture_size: List[int] = [512, 512],
3131
dtype=torch.float,
32-
tex_dtype=torch.half):
32+
tex_dtype=torch.uint8):
3333
super().__init__()
3434
self.raster_settings = raster_settings
3535

fast_gauss/console_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,19 @@ def dumps(self, obj: Union[dict, dotdict]):
114114
if 'easyvolcap.utils.console_utils' in sys.modules:
115115
console = sys.modules['easyvolcap.utils.console_utils'].console
116116
do_nothing_console = sys.modules['easyvolcap.utils.console_utils'].do_nothing_console
117+
progress = sys.modules['easyvolcap.utils.console_utils'].progress
118+
live = sys.modules['easyvolcap.utils.console_utils'].live
119+
log = sys.modules['easyvolcap.utils.console_utils'].log
120+
bold = sys.modules['easyvolcap.utils.console_utils'].bold
121+
green = sys.modules['easyvolcap.utils.console_utils'].green
122+
log(green('[FAST GAUSS] Reusing console from easyvolcap.utils.console_utils'))
117123
else:
118124
do_nothing_console = Console(file=StringIO(), stderr=StringIO())
119125
console = Console(soft_wrap=True, tab_size=4, log_time_format=slim_time_format, width=slim_width, log_time=slim_log_time, log_path=slim_log_path)
126+
progress = Progress(console=console, expand=True) # destroyed
127+
live = Live(console=console, refresh_per_second=10) # destroyed
120128
# fmt: on
121129

122-
progress = Progress(console=console, expand=True) # destroyed
123-
live = Live(console=console, refresh_per_second=10) # destroyed
124130
traceback.install(console=console, width=slim_width) # for colorful tracebacks
125131
pretty.install(console=console)
126132

@@ -293,7 +299,6 @@ def color_slim(string: str, color: str): return f'[{color}]{string}[/]'
293299
def slim(string: str): return f'{string}'
294300

295301

296-
297302
def markup_to_ansi(string: str) -> str:
298303
"""
299304
Convert rich-style markup to ANSI sequences for command-line formatting.

fast_gauss/gsplat_utils.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ def __init__(self,
4040
init_buffer_size: int = 32768,
4141
init_texture_size: List[int] = [512, 512],
4242
dtype: str = torch.float, # +5-10 fps on 3060, not working too well with flame_salmon
43-
tex_dtype: str = torch.half, # +5-10 fps on 3060, not working too well with flame_salmon
43+
tex_dtype: str = torch.uint8, # +5-10 fps on 3060, not working too well with flame_salmon
4444

4545
# DEBUG: whether to write back to cuda in offline rendering mode, only used for speed tests
4646
offline_writeback: bool = True,
4747
):
4848
self.attr_sizes = [3, 3, 3, 4] # verts, cov6, rgba4
4949
self.dtype = getattr(torch, dtype) if isinstance(dtype, str) else dtype
5050
self.tex_dtype = getattr(torch, tex_dtype) if isinstance(tex_dtype, str) else tex_dtype
51-
self.gl_tex_dtype = gl.GL_RGBA16F if self.tex_dtype == torch.half else gl.GL_RGBA32F
51+
self.gl_tex_dtype = gl.GL_RGBA16F if self.tex_dtype == torch.half else gl.GL_RGBA32F if self.tex_dtype == torch.float else gl.GL_RGBA8
5252
self.gl_attr_dtypes = [gl.GL_FLOAT if self.dtype == torch.float else gl.GL_HALF_FLOAT] * len(self.attr_sizes)
5353
self.uniforms = dotdict() # uniform values
5454

@@ -63,7 +63,7 @@ def __init__(self,
6363
self.resize_buffers(init_buffer_size)
6464
self.resize_textures(*init_texture_size)
6565

66-
log(bold(f'[FAST GAUSS] GSplatContextManager initialized with attribute dtype: {self.dtype}, texture dtype: {self.tex_dtype}, offline rendering: {self.offline_rendering}, buffer size: {init_buffer_size}, texture size: {init_texture_size}'))
66+
log(bold(f'[FAST GAUSS] GSplatContextManager initialized with attribute dtype: {self.dtype}, texture dtype: {self.tex_dtype}, offline rendering: {self.offline_rendering}, vertex buffer size: {init_buffer_size}, render buffer size: {init_texture_size}'))
6767

6868
if not self.offline_rendering:
6969
log(bold('[FAST GAUSS] Using online rendering mode, in this mode, calling the rendering function of fast_gauss will write directly to the currently bound framebuffer'))
@@ -199,7 +199,7 @@ def init_textures(self, H: int, W: int):
199199
# Init the texture (call the resizing function), will simply allocate empty memory
200200
# The internal format describes how the texture shall be stored in the GPU. The format describes how the format of your pixel data in client memory (together with the type parameter).
201201
gl.glBindRenderbuffer(gl.GL_RENDERBUFFER, self.rbo_rgba)
202-
gl.glRenderbufferStorage(gl.GL_RENDERBUFFER, gl.GL_RGBA8, W, H)
202+
gl.glRenderbufferStorage(gl.GL_RENDERBUFFER, self.gl_tex_dtype, W, H) # faster if using rgba8
203203
gl.glBindRenderbuffer(gl.GL_RENDERBUFFER, self.rbo_atth)
204204
gl.glRenderbufferStorage(gl.GL_RENDERBUFFER, gl.GL_DEPTH_COMPONENT, W, H)
205205

@@ -228,15 +228,15 @@ def resize_textures(self, H: int, W: int): # analogy to update_gl_buffers
228228
if H > self.max_H or W > self.max_W: # max got updated
229229
if H > self.max_H: self.max_H = int(H * 1.05)
230230
if W > self.max_W: self.max_W = int(W * 1.05)
231-
if not init: log(bold('[FAST GAUSS] Resizing textures to:'), int(H), int(W))
231+
if not init: log(bold('[FAST GAUSS] Resizing render buffers to:'), int(H), int(W))
232232
self.init_textures(self.max_H, self.max_W)
233233

234234
def resize_buffers(self, v: int = 0):
235235
init = False
236236
if not hasattr(self, 'max_verts'): self.max_verts = 0; init = True
237237
if v > self.max_verts:
238238
if v > self.max_verts: self.max_verts = int(v * 1.05)
239-
if not init: log(bold('[FAST GAUSS] Resizing buffers to:'), int(v))
239+
if not init: log(bold('[FAST GAUSS] Resizing vertex buffers to:'), int(v))
240240
self.init_gl_buffers(self.max_verts)
241241

242242
@torch.no_grad()
@@ -353,8 +353,12 @@ def render(self, xyz3: torch.Tensor, cov6: torch.Tensor, rgb3: torch.Tensor, occ
353353
CHECK_CUDART_ERROR(cudart.cudaGraphicsUnmapResources(1, cu_tex, stream))
354354

355355
if rgba_map.dtype != xyz3.dtype:
356-
warn_once(yellow(f'Using texture dtype {rgba_map.dtype}, expected {xyz3.dtype} for the output, will cast to {xyz3.dtype}'))
357-
rgba_map = rgba_map.to(xyz3.dtype)
356+
warn_once(yellow(f'[FAST GAUSS] Using render buffer dtype {rgba_map.dtype}, expected {xyz3.dtype} for the output, will cast to {xyz3.dtype}'))
357+
if not torch.is_floating_point(rgba_map):
358+
warn_once(yellow(f'[FAST GAUSS] Using a non-floating-point render buffer dtype: {rgba_map.dtype}, this might cause some precision loss'))
359+
rgba_map = rgba_map / torch.iinfo(rgba_map.dtype).max # should be 255 for uint8
360+
else:
361+
rgba_map = rgba_map.to(xyz3.dtype)
358362

359363
return rgba_map # H, W, 4
360364
else:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "fast_gauss"
7-
version = "0.0.8"
7+
version = "0.0.9"
88
description = "A geometry-shader-based, global CUDA sorted high-performance 3D Gaussian Splatting rasterizer. Can achieve a 5-10x speedup in rendering compared to the vanialla diff-gaussian-rasterization."
99
readme = "readme.md"
1010
license = { file = "license" }

0 commit comments

Comments
 (0)