Skip to content

Commit

Permalink
large refactor, moving to VK_EXT_mutable_descriptor_type
Browse files Browse the repository at this point in the history
  • Loading branch information
natevm committed Dec 28, 2024
1 parent 3a868a5 commit d307f0f
Show file tree
Hide file tree
Showing 8 changed files with 4,341 additions and 4,527 deletions.
8,637 changes: 4,135 additions & 4,502 deletions gprt/gprt.cpp

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions gprt/gprt.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@

#include "gprt_shared.h"

// [[vk::binding(0, 0)]] is reserved for global "uniform" descriptor data,
// for eg, uniform parameters to compute kernels.

// Descriptor binding, then set number.
// Currently, 0, N is used for textures
// Then, 1, N is used for record data passed
Expand All @@ -94,11 +97,11 @@
// Note, it's assumed that at address 0 into all these descriptors, we will have some "default"
[[vk::binding(0, 1)]]
SamplerState samplers[];
[[vk::binding(0, 2)]]
[[vk::binding(0, 1)]]
Texture1D texture1Ds[];
[[vk::binding(0, 3)]]
[[vk::binding(0, 1)]]
Texture2D texture2Ds[];
[[vk::binding(0, 4)]]
[[vk::binding(0, 1)]]
Texture3D texture3Ds[];

// Update, we now use buffer pointers for all buffer data. This helps avoid the need for
Expand Down Expand Up @@ -189,22 +192,22 @@ getNullAccelHandle() {

Texture1D
getTexture1DHandle(gprt::Texture texture) {
return texture1Ds[texture];
return texture1Ds[texture.index];
}

Texture2D
getTexture2DHandle(gprt::Texture texture) {
return texture2Ds[texture];
return texture2Ds[texture.index];
}

Texture3D
getTexture3DHandle(gprt::Texture texture) {
return texture3Ds[texture];
return texture3Ds[texture.index];
}

SamplerState
getSamplerHandle(gprt::Sampler sampler) {
return samplers[sampler];
return samplers[sampler.index];
}

SamplerState
Expand Down
10 changes: 10 additions & 0 deletions gprt/gprt_fallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ struct SphereParameters {
float4 *vertices;
uint32_t exitTest; // false: return entry hits, true: return exit hits
};

struct CellParameters {
uint32_t *indices;
float3* vertices;
uint32_t count;
// Todo... support the below...
// uint32_t offset; //
// uint32_t stride;
uint32_t type;
};
130 changes: 123 additions & 7 deletions gprt/gprt_fallbacks.slang
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ LoadAligned<int alignment, T>(T *ptr) {
};
}

[ForceInline]
float
flipsign(float v, bool flag) {
return (flag) ? -v : v;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// LINE SWEPT SPHERES
////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
* @brief Intersects a ray with a linearly swept sphere (LSS).
Expand Down Expand Up @@ -187,6 +185,9 @@ LSSBounds(uint3 DispatchThreadID: SV_DispatchThreadID, uniform LSSBoundsParamete
lss.aabbs[(offset * 2) + 2 * primID + 1] = aabbMax;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SPHERES
////////////////////////////////////////////////////////////////////////////////////////////////////////////
[shader("intersection")]
void
SphereIntersection(uniform uint32_t userData[64], uniform SphereParameters s) {
Expand All @@ -208,8 +209,7 @@ SphereIntersection(uniform uint32_t userData[64], uniform SphereParameters s) {

[shader("compute")]
[numthreads(256, 1, 1)]
void
SphereBounds(uint3 DispatchThreadID: SV_DispatchThreadID, uniform SphereBoundsParameters s) {
void SphereBounds(uint3 DispatchThreadID: SV_DispatchThreadID, uniform SphereBoundsParameters s) {
int primID = DispatchThreadID.x;
if (primID >= s.count)
return;
Expand All @@ -225,3 +225,119 @@ SphereBounds(uint3 DispatchThreadID: SV_DispatchThreadID, uniform SphereBoundsPa
s.aabbs[(offset * 2) + 2 * primID] = aabbMin;
s.aabbs[(offset * 2) + 2 * primID + 1] = aabbMax;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// LINEAR CELLS
////////////////////////////////////////////////////////////////////////////////////////////////////////////

#define GPRT_TETRA 10
#define GPRT_VOXEL 11
#define GPRT_HEXAHEDRON 12
#define GPRT_WEDGE 13
#define GPRT_PYRAMID 14
#define GPRT_PENTAGONAL_PRISM 15
#define GPRT_HEXAGONAL_PRISM 16

int getVertexCount(uint32_t cellType) {
switch (cellType) {
case GPRT_TETRA: return 4;
case GPRT_VOXEL: return 8;
case GPRT_HEXAHEDRON: return 8;
case GPRT_WEDGE: return 6;
case GPRT_PYRAMID: return 14;
case GPRT_PENTAGONAL_PRISM: return 10;
case GPRT_HEXAGONAL_PRISM: return 12;
default: return 0;
}
}

// Not particularly efficient at the moment, meant to be general and easy to maintain.
[shader("compute")]
[numthreads(256, 1, 1)]
void LinearCellBounds(uint3 DispatchThreadID: SV_DispatchThreadID, uniform CellParameters record) {
int primID = DispatchThreadID.x;
if (primID >= record.count)
return;

float3 *vertices = record.vertices;
uint32_t *indices = record.indices;

uint32_t numVertices = getVertexCount(record.count);
float3 aabbMin = +float3(FLT_MAX);
float3 aabbMax = -float3(FLT_MAX);

// TODO: Try to load indices by groups of four.
// TODO: Use aligned loads...
// TODO: Add some validation and report an error if indices are invalid.
for (int i = 0; i < numVertices; ++i) {
int index = indices[i];
float3 vert = vertices[index];
aabbMin = min(aabbMin, vert);
aabbMax = max(aabbMin, vert);
}
}

// Quadratic, isoparametric cells
// GPRT_QUADRATIC_EDGE = 21,
// GPRT_QUADRATIC_TRIANGLE = 22,
// GPRT_QUADRATIC_QUAD = 23,
// GPRT_QUADRATIC_POLYGON = 36,
// #define GPRT_QUADRATIC_TETRA 24
// #define GPRT_QUADRATIC_HEXAHEDRON 25
// #define GPRT_QUADRATIC_WEDGE 26
// #define GPRT_QUADRATIC_PYRAMID 27
// #define GPRT_BIQUADRATIC_QUAD 28
// #define GPRT_TRIQUADRATIC_HEXAHEDRON 29
// #define GPRT_TRIQUADRATIC_PYRAMID 37
// #define GPRT_QUADRATIC_LINEAR_QUAD 30
// #define GPRT_QUADRATIC_LINEAR_WEDGE 31
// #define GPRT_BIQUADRATIC_QUADRATIC_WEDGE 32
// #define GPRT_BIQUADRATIC_QUADRATIC_HEXAHEDRON 33
// #define GPRT_BIQUADRATIC_TRIANGLE 34

// // Cubic, isoparametric cell
// GPRT_CUBIC_LINE = 35,

// // Special class of cells formed by convex group of points
// GPRT_CONVEX_POINT_SET = 41,

// // Polyhedron cell (consisting of polygonal faces)
// GPRT_POLYHEDRON = 42,

// // Higher order cells in parametric form
// GPRT_PARAMETRIC_CURVE = 51,
// GPRT_PARAMETRIC_SURFACE = 52,
// GPRT_PARAMETRIC_TRI_SURFACE = 53,
// GPRT_PARAMETRIC_QUAD_SURFACE = 54,
// GPRT_PARAMETRIC_TETRA_REGION = 55,
// GPRT_PARAMETRIC_HEX_REGION = 56,

// // Higher order cells
// GPRT_HIGHER_ORDER_EDGE = 60,
// GPRT_HIGHER_ORDER_TRIANGLE = 61,
// GPRT_HIGHER_ORDER_QUAD = 62,
// GPRT_HIGHER_ORDER_POLYGON = 63,
// GPRT_HIGHER_ORDER_TETRAHEDRON = 64,
// GPRT_HIGHER_ORDER_WEDGE = 65,
// GPRT_HIGHER_ORDER_PYRAMID = 66,
// GPRT_HIGHER_ORDER_HEXAHEDRON = 67,

// // Arbitrary order Lagrange elements (formulated separated from generic higher order cells)
// GPRT_LAGRANGE_CURVE = 68,
// GPRT_LAGRANGE_TRIANGLE = 69,
// GPRT_LAGRANGE_QUADRILATERAL = 70,
// GPRT_LAGRANGE_TETRAHEDRON = 71,
// GPRT_LAGRANGE_HEXAHEDRON = 72,
// GPRT_LAGRANGE_WEDGE = 73,
// GPRT_LAGRANGE_PYRAMID = 74,

// // Arbitrary order Bezier elements (formulated separated from generic higher order cells)
// GPRT_BEZIER_CURVE = 75,
// GPRT_BEZIER_TRIANGLE = 76,
// GPRT_BEZIER_QUADRILATERAL = 77,
// GPRT_BEZIER_TETRAHEDRON = 78,
// GPRT_BEZIER_HEXAHEDRON = 79,
// GPRT_BEZIER_WEDGE = 80,
// GPRT_BEZIER_PYRAMID = 81,

// GPRT_NUMBER_OF_CELL_TYPES
48 changes: 47 additions & 1 deletion gprt/gprt_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,53 @@ typedef enum {
GPRT_MATRIX_FORMAT_ROW_MAJOR
} GPRTMatrixFormat;

typedef enum { GPRT_UNKNOWN, GPRT_AABBS, GPRT_TRIANGLES, GPRT_SPHERES, GPRT_LSS } GPRTGeomKind;
typedef enum { GPRT_UNKNOWN, GPRT_AABBS, GPRT_TRIANGLES, GPRT_SPHERES, GPRT_LSS, GPRT_CELLS } GPRTGeomKind;

// A subset of the cell types supported by VTK.
// Keep in sync with https://github.com/Kitware/VTK/blob/master/Common/DataModel/vtkCellType.h
typedef enum
{
// Linear cells
GPRT_TETRA = 10,
GPRT_VOXEL = 11,
GPRT_HEXAHEDRON = 12,
GPRT_WEDGE = 13,
GPRT_PYRAMID = 14,
GPRT_PENTAGONAL_PRISM = 15,
GPRT_HEXAGONAL_PRISM = 16,

// // Quadratic, isoparametric cells
// GPRT_QUADRATIC_TETRA = 24,
// GPRT_QUADRATIC_HEXAHEDRON = 25,
// GPRT_QUADRATIC_WEDGE = 26,
// GPRT_QUADRATIC_PYRAMID = 27,
// GPRT_TRIQUADRATIC_HEXAHEDRON = 29,
// GPRT_TRIQUADRATIC_PYRAMID = 37,
// GPRT_QUADRATIC_LINEAR_WEDGE = 31,
// GPRT_BIQUADRATIC_QUADRATIC_WEDGE = 32,
// GPRT_BIQUADRATIC_QUADRATIC_HEXAHEDRON = 33,

// // Polyhedron cell (consisting of polygonal faces)
// GPRT_POLYHEDRON = 42,

// // Higher order cells
// GPRT_HIGHER_ORDER_TETRAHEDRON = 64,
// GPRT_HIGHER_ORDER_WEDGE = 65,
// GPRT_HIGHER_ORDER_PYRAMID = 66,
// GPRT_HIGHER_ORDER_HEXAHEDRON = 67,

// // Arbitrary order Lagrange elements (formulated separated from generic higher order cells)
// GPRT_LAGRANGE_TETRAHEDRON = 71,
// GPRT_LAGRANGE_HEXAHEDRON = 72,
// GPRT_LAGRANGE_WEDGE = 73,
// GPRT_LAGRANGE_PYRAMID = 74,

// // Arbitrary order Bezier elements (formulated separated from generic higher order cells)
// GPRT_BEZIER_TETRAHEDRON = 78,
// GPRT_BEZIER_HEXAHEDRON = 79,
// GPRT_BEZIER_WEDGE = 80,
// GPRT_BEZIER_PYRAMID = 81,
} GPRTCellType;

typedef enum {
GPRT_BUILD_MODE_UNINITIALIZED,
Expand Down
10 changes: 8 additions & 2 deletions gprt/gprt_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@
// NOTE, struct must be synchronized with declaration in gprt_host.h
namespace gprt {

typedef uint32_t Texture;
typedef uint32_t Sampler;

struct Texture {
uint32_t index;
};

struct Sampler {
uint32_t index;
};

// Update: now, we simply use Slang's pointer type for buffers
// Shared between Slang and C++
Expand Down
8 changes: 4 additions & 4 deletions samples/s9-differentiable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@

embed_devicecode(
OUTPUT_TARGET
s13_deviceCode
s9_0_deviceCode
HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/sharedCode.h
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/deviceCode.slang
)

add_executable(s13_differentiable hostCode.cpp)
target_link_libraries(s13_differentiable
add_executable(s9_0_differentiable hostCode.cpp)
target_link_libraries(s9_0_differentiable
PRIVATE
s13_deviceCode
s9_0_deviceCode
gprt::gprt
generator
)
8 changes: 4 additions & 4 deletions samples/s9-differentiable/hostCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ using namespace generator;
std::cout << "#gprt.sample(main): " << message << std::endl; \
std::cout << GPRT_TERMINAL_DEFAULT;

extern GPRTProgram s13_deviceCode;
extern GPRTProgram s9_0_deviceCode;

// initial image resolution
const uint2 fbSize = {1400, 460};
// const uint2 fbSize = {1024, 1024};

// final image output
const char *outFileName = "s12-imgui.png";
const char *outFileName = "s9_0_differentiable.png";

// Initial camera parameters
float3 lookFrom = {0.f, -8.f, 0.0f};
Expand Down Expand Up @@ -147,9 +147,9 @@ main(int ac, char **av) {
LOG("building module, programs, and pipeline");

// create a context on the first device:
gprtRequestWindow(fbSize.x, fbSize.y, "S13 Differentiable");
gprtRequestWindow(fbSize.x, fbSize.y, "S9_0 Differentiable");
GPRTContext context = gprtContextCreate();
GPRTModule module = gprtModuleCreate(context, s13_deviceCode);
GPRTModule module = gprtModuleCreate(context, s9_0_deviceCode);

// ##################################################################
// set up all the GPU kernels we want to run
Expand Down

0 comments on commit d307f0f

Please sign in to comment.