Code Monkey home page Code Monkey logo

cudaplayground's Introduction

CUDA Playground

This project provides basic templates of a cuda programs that can be modified and executed at runtime by saving the cuda kernel file (with ctrl+s). It's meant to help with developing algorithms by providing a near-instant feedback loop.

Several example programs are provided, one using the console and others using OpenGL interop to draw an image with CUDA and display the resulting image with OpenGL.

VR Voxel Painter

Main: main_rasterize_triangles.cpp
Kernel: rasterize.cu

A virtual reality voxel painter that entirely runs in a single CUDA kernel, including game logic, meshing via marching cubes and triangle rasterization. A more detailed documentation is found in ./docs/voxelpainter.md.

CUDA Triangle Rasterizer

Main: main_rasterize_triangles.cpp
Kernel: rasterize.cu

Rasterizes 25 instances of the spot model.

  • First allocates bytes for an interleaved depth&color buffer
  • Clears it with all launched threads
  • Generates and draws a ground plane, colored by triangle index
  • Then draws the spot model with rasterizeTriangles()
    • Each cuda block grabs a triangle
    • Block projects it to screen
    • Block computes the screen-space bounding box
    • Iterates through all fragments, utilizing one block-thread per fragment
    • Each thread stores the fragment via a 64bit atomicMin that encodes depth and color
  • If colored by normalized time, computes the max time.
  • Finally transfers the results from our custom buffer to an OpenGL texture

jpeg

Random Numbers

Kernel: randomNumbers.cu

Generates a list of random numbers and then computes the average value. Results are printed directly by the CUDA kernel. Cooperative groups, specifically grid.sync(), are used to sync all GPU threads between different passes.

gif

CUDA Rasterizer

Kernel: rasterize.cu

Draws a parametric plane and sphere into a custom cuda framebuffer, and then transfers the result into an OpenGL texture. At each frame, the kernel

  • allocates a framebuffer from a byte buffer
  • clears it with infinite depth and a background value
  • samples points on the surface, projects them to pixels
  • stores the closest samples by using atomicMin with a 64 bit value that contains both, depth and color.
  • Then extracts the color values from the interleaved depth&color buffer, and stores the result in an OpenGL texture,

jpeg

CUDA Seascape

Kernel: seascape.cu

A CUDA port of the shadertoy demo "Seascape" (from Alexander Alekseev aka TDM). Instead of projecting points to pixels as the rasterizer does, this demo traces rays from pixels to compute a randering of an ocean.

jpeg

Getting Started

  • Open build/CudaPlayground.sln in Visual Studio 2022
  • Specify your desired startup project by right clicking and selecting "Set as startup project".
  • Press ctrl+f5 to compile and run the project
  • Open the respective cuda file (randomNumbers.cu, rasterize.cu, seascape.cu) and try to change some code. Changes are instantly applied by saving the file.

Notes

  • "--gpu-architecture=compute_75" is hardcoded in CudaModularProgram.h. You may want to change this to access newer features.

Citing

This project extracts a minimal viable cuda framework from our research on software rasterization of point clouds (see github project compute_rasterizer).

@article{SCHUETZ-2022-PCC,
  title =      "Software Rasterization of 2 Billion Points in Real Time",
  author =     "Markus Sch\"{u}tz and Bernhard Kerbl and Michael Wimmer",
  year =       "2022",
  month =      jul,
  journal =    "Proc. ACM Comput. Graph. Interact. Tech.",
  volume =     "5",
  pages =      "1--16",
  URL =        "https://www.cg.tuwien.ac.at/research/publications/2022/SCHUETZ-2022-PCC/",
}

@article{SCHUETZ-2021-PCC,
  title =      "Rendering Point Clouds with Compute Shaders and Vertex Order Optimization",
  author =     "Markus Sch\"{u}tz and Bernhard Kerbl and Michael Wimmer",
  year =       "2021",
  month =      jul,
  doi =        "10.1111/cgf.14345",
  journal =    "Computer Graphics Forum",
  number =     "4",
  volume =     "40",
  pages =      "115--126",
  keywords =   "point-based rendering, compute shader, real-time rendering",
  URL =        "https://www.cg.tuwien.ac.at/research/publications/2021/SCHUETZ-2021-PCC/",
}

cudaplayground's People

Contributors

m-schuetz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.