16 [[nodiscard]] Portal::Graphics::ShaderSpec field_spec(
const Kinesis::FieldSource& field)
18 if (!field.valid() || field.parameter_count() > 3) {
19 error<std::invalid_argument>(
22 std::source_location::current(),
23 "SDFFieldProcessor: the field did not parse into a function of "
24 "one to three parameters. It needs a trailing return type and a body.");
29 Portal::Graphics::ShaderSpec::Assemble assemble;
32 for (
const char*
name : {
"bounds_min_x",
"bounds_min_y",
"bounds_min_z",
"time",
"step_x",
"step_y",
"step_z" }) {
35 for (
const char*
name : {
"res_x",
"res_y",
"res_z" }) {
36 assemble.pc(
name, GpuDataFormat::UINT32);
38 for (
const char*
name : {
"p0",
"p1",
"p2",
"p3" }) {
42 assemble.workgroup(64)
43 .function(field.return_type, field.name, field.params, field.body);
46 body +=
" uint nx = res_x + 1u;\n";
47 body +=
" uint ny = res_y + 1u;\n";
48 body +=
" if (i >= nx * ny * (res_z + 1u)) { return; }\n";
49 body +=
" uint ix = i % nx;\n";
50 body +=
" uint iy = (i / nx) % ny;\n";
51 body +=
" uint iz = i / (nx * ny);\n";
52 body +=
" vec3 p = vec3(bounds_min_x + float(ix) * step_x,"
53 " bounds_min_y + float(iy) * step_y,"
54 " bounds_min_z + float(iz) * step_z);\n";
56 switch (field.parameter_count()) {
58 body +=
" sdf_grid[i] = " + field.name +
"(p);\n";
61 body +=
" sdf_grid[i] = " + field.name +
"(p, time);\n";
64 body +=
" vec4 params = vec4(p0, p1, p2, p3);\n";
65 body +=
" sdf_grid[i] = " + field.name +
"(p, time, params);\n";
69 assemble.kernel(Portal::Graphics::KernelSource { .body = std::move(body) });
70 return assemble.build();
76 std::shared_ptr<VKBuffer> grid_buf,
77 const glm::vec3& bounds_min,
78 const glm::vec3& bounds_max,
84 , m_grid_buf(
std::move(grid_buf))
85 , m_res_x(
std::
max(res_x, 1U))
86 , m_res_y(
std::
max(res_y, 1U))
87 , m_res_z(
std::
max(res_z, 1U))
94 const glm::vec3 extent = bounds_max - bounds_min;
96 extent.x /
static_cast<float>(
m_res_x),
97 extent.y /
static_cast<float>(
m_res_y),
98 extent.z /
static_cast<float>(
m_res_z),
110 std::shared_ptr<VKBuffer> grid_buf,
112 const glm::vec3& bounds_min,
113 const glm::vec3& bounds_max,
119 , m_grid_buf(
std::move(grid_buf))
120 , m_res_x(
std::
max(res_x, 1U))
121 , m_res_y(
std::
max(res_y, 1U))
122 , m_res_z(
std::
max(res_z, 1U))
139 const glm::vec3 extent = bounds_max - bounds_min;
141 extent.x /
static_cast<float>(
m_res_x),
142 extent.y /
static_cast<float>(
m_res_y),
143 extent.z /
static_cast<float>(
m_res_z),
162 const std::shared_ptr<VKBuffer>& )
std::shared_ptr< NetworkGeometryBuffer > buffer
virtual void on_attach(const std::shared_ptr< Buffer > &)
Called when this processor is attached to a buffer.
void set_dispatch_mode(ShaderDispatchConfig::DispatchMode mode)
Set dispatch mode.
void set_manual_dispatch(uint32_t x, uint32_t y=1, uint32_t z=1)
Set manual dispatch group counts.
Specialized ShaderProcessor for Compute Pipelines.
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Called before each process callback.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is attached to a buffer.
SDFFieldProcessor(std::shared_ptr< VKBuffer > grid_buf, const glm::vec3 &bounds_min, const glm::vec3 &bounds_max, uint32_t res_x, uint32_t res_y, uint32_t res_z, std::string shader="sdf_field_gyroid.comp.spv")
std::shared_ptr< VKBuffer > m_grid_buf
void set_bounds(const glm::vec3 &bounds_min, const glm::vec3 &bounds_max)
Replace the evaluation volume.
void set_push_constant_data(const T &data)
Update push constant data (type-safe)
void bind_buffer(const std::string &descriptor_name, const std::shared_ptr< VKBuffer > &buffer)
Bind a VKBuffer to a named shader descriptor.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
GpuDataFormat
GPU data formats with explicit precision levels.
Describes how a VKBuffer binds to a shader descriptor.
std::unordered_map< std::string, ShaderBinding > bindings
size_t push_constant_size
@ MANUAL
Use explicit group counts.
Parsed representation of a stringified field lambda.