aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/scene.hpp25
-rw-r--r--shaders/compute.comp33
-rw-r--r--src/main.cpp25
-rw-r--r--src/scene.cpp4
-rw-r--r--src/vk-command-buffer.cpp6
5 files changed, 60 insertions, 33 deletions
diff --git a/include/scene.hpp b/include/scene.hpp
index 5cda832..0a5e82f 100644
--- a/include/scene.hpp
+++ b/include/scene.hpp
@@ -3,22 +3,27 @@
class Buffer;
+enum FEATURES_BIT_INDEX: u8 {
+ DOF,
+ BVH_DEBUG_VIEW,
+};
+
struct metadata {
camera cam;
- uint32_t max_bounce = 3;
- uint32_t min_bounce = 1;
+ u8 max_bounce = 3;
+ u8 min_bounce = 1;
+
+ u8 features = 0b0; // 0: dof, 1: bvh debug view
+ u8 downscale_factor = 1;
- uint32_t width;
- uint32_t height;
+ u16 width;
+ u16 height;
- uint32_t sample_index = 1;
+ u32 sample_index = 1;
- uint32_t enable_dof = (uint32_t)false;
- uint32_t debug_bvh = (uint32_t)false;
- int32_t downscale_factor = 1;
- metadata(const camera &cam, uint32_t width, uint32_t height);
+ metadata(const camera &cam, u16 width, u16 height);
};
class scene {
@@ -26,7 +31,7 @@ class scene {
gltf model;
public:
- scene(const camera& cam, uint32_t width, uint32_t height);
+ scene(const camera& cam, u16 width, u16 height);
void deinit();
metadata meta;
diff --git a/shaders/compute.comp b/shaders/compute.comp
index c361c43..b5fcc17 100644
--- a/shaders/compute.comp
+++ b/shaders/compute.comp
@@ -98,15 +98,9 @@ layout(descriptor_heap) uniform sampler samplers[];
layout(push_constant) uniform registers {
camera cam;
- uint max_bounce;
- uint min_bounce;
- uint width;
- uint height;
-
+ uint max_min_feat_downscale;
+ uint width_height;
uint sample_index;
- uint enable_dof;
- uint debug_bvh;
- int downscale_factor;
nodes_array bvh;
indices_array indices_arr;
@@ -125,7 +119,7 @@ vec3 ray_color(ray r, uint seed) {
vec3 radiance = vec3(0.0);
vec3 throughput = vec3(1.0);
- for (uint bounce = 0; bounce < regs.max_bounce; bounce++) {
+ for (uint bounce = 0; bounce < uint(regs.max_min_feat_downscale & 0xff); bounce++) {
if (!hit_node(r, info))
return throughput * vec3(1.0);
@@ -235,7 +229,7 @@ vec3 ray_color(ray r, uint seed) {
// Russian Roulette
// As the throughput gets smaller, the ray is more likely to get terminated early.
// Survivors have their value boosted to make up for fewer samples being in the average.
- if (bounce > regs.min_bounce) {
+ if (bounce > uint(regs.max_min_feat_downscale & 0xff00)) {
float probability = min(0.95f, luminance(throughput));
if (probability < rand(seed)) break;
throughput /= probability;
@@ -246,13 +240,16 @@ vec3 ray_color(ray r, uint seed) {
}
ray generate_camera_ray(ivec2 coords, uint seed) {
- vec2 scene_size = vec2(regs.width - 1, regs.height - 1);
+ uint width = uint(regs.width_height & 0xff);
+ uint height = uint(regs.width_height & 0xff00);
+ vec2 scene_size = vec2(width - 1, height - 1);
vec2 uv = vec2(coords.x / scene_size.x, 1.0 - coords.y / scene_size.y);
vec2 rand_disk = disk_vec(vec2(rand(seed), rand(seed)));
vec2 jittered_uvs = uv + vec2(rand(seed), rand(seed)) / scene_size;
vec2 lens_disk = vec2(0.0);
- if (regs.enable_dof == 1) {
+ uint features = uint(regs.max_min_feat_downscale & 0xff0000);
+ if ((features & 1) == 1) {
lens_disk = rand_disk * regs.cam.lens_radius;
}
@@ -263,16 +260,22 @@ ray generate_camera_ray(ivec2 coords, uint seed) {
}
void main() {
- if (any(greaterThanEqual(gl_GlobalInvocationID.xy, uvec2(regs.width, regs.height))))
+ uint width = uint(regs.width_height & 0xff);
+ uint height = uint(regs.width_height & 0xff00);
+
+ if (any(greaterThanEqual(gl_GlobalInvocationID.xy, uvec2(width, height))))
return;
+ return;
- ivec2 coords = ivec2(gl_GlobalInvocationID.xy) * regs.downscale_factor;
+ int downscale_factor = int(regs.max_min_feat_downscale & 0xff000000);
+ ivec2 coords = ivec2(gl_GlobalInvocationID.xy) * downscale_factor;
uint seed = uint(coords.x * uint(1973) + coords.y * uint(9277) + regs.sample_index * uint(26699)) | uint(1);
ray r = generate_camera_ray(coords, seed);
vec3 out_color = vec3(0.0);
- if (regs.debug_bvh == 1) {
+ uint features = uint(regs.max_min_feat_downscale & 0xff0000);
+ if ((features & 2) == 2) {
out_color = hit_aabbs(r) * vec3(0.001, 0.0, 0.0);
} else {
out_color = ray_color(r, seed);
diff --git a/src/main.cpp b/src/main.cpp
index a046c0a..34cc894 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -120,14 +120,28 @@ void ui(scene* scene, float frame_time) {
}
if (ImGui::CollapsingHeader("Scene")) {
- ImGui::SliderInt("Max bounce", reinterpret_cast<int*>(&scene->meta.max_bounce), 5, 100);
- ImGui::SliderInt("Min bounce", reinterpret_cast<int*>(&scene->meta.min_bounce), 1, 5);
+ int max_bounce = 0;
+ ImGui::SliderInt("Max bounce", &max_bounce, 5, 100);
+ scene->meta.max_bounce = (u8)max_bounce;
- ImGui::Checkbox("DOF", reinterpret_cast<bool*>(&scene->meta.enable_dof));
- ImGui::Checkbox("Debug BVH", reinterpret_cast<bool*>(&scene->meta.debug_bvh));
- if (ImGui::SliderInt("Scale facotr", reinterpret_cast<int*>(&scene->meta.downscale_factor), 1, 20)) {
+ int min_bounce = 0;
+ ImGui::SliderInt("Min bounce", &min_bounce, 1, 5);
+ scene->meta.min_bounce = (u8)min_bounce;
+
+ scene->meta.features = 0U;
+ bool enable_dof = false;
+ ImGui::Checkbox("DOF", &enable_dof);
+ scene->meta.features |= enable_dof << FEATURES_BIT_INDEX::DOF;
+
+ bool enable_bvh_debug_view = false;
+ ImGui::Checkbox("Debug BVH", &enable_bvh_debug_view);
+ scene->meta.features |= enable_bvh_debug_view << FEATURES_BIT_INDEX::BVH_DEBUG_VIEW;
+
+ int downscale_factor = 0;
+ if (ImGui::SliderInt("Scale factor", &downscale_factor, 1, 20)) {
scene->meta.sample_index = 1U;
}
+ scene->meta.downscale_factor = (u8)downscale_factor;
}
ImGui::End();
@@ -676,7 +690,6 @@ int main() {
}
{
- // TODO: Pack this fields
struct params {
struct metadata meta;
uintptr_t bvh_buffer;
diff --git a/src/scene.cpp b/src/scene.cpp
index ae009e7..12499b0 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -51,10 +51,10 @@
// }
-metadata::metadata(const camera &cam, uint32_t width, uint32_t height)
+metadata::metadata(const camera &cam, u16 width, u16 height)
: cam(cam), width(width), height(height) {}
-scene::scene(const camera& cam, uint32_t width, uint32_t height)
+scene::scene(const camera& cam, u16 width, u16 height)
// :model("../models/sponza/Sponza.gltf"), meta(cam, width, height) {
// :model("../models/BistroInterior/BistroInterior.gltf"), meta(cam, width, height) {
// :model("../models/BistroExterior/BistroExterior.gltf"), meta(cam, width, height) {
diff --git a/src/vk-command-buffer.cpp b/src/vk-command-buffer.cpp
index 00d60a1..aa87265 100644
--- a/src/vk-command-buffer.cpp
+++ b/src/vk-command-buffer.cpp
@@ -124,6 +124,8 @@ void command_buffer::copy(handle<device_buffer> buffer_handle, ::handle<device_t
}
void graphics_command_buffer::dispatch(const dispatch_params& params, const void* data, size_t size) const {
+ assert(size <= descriptor_heap_props.maxPushDataSize);
+
const device_pipeline* pipeline = vkdevice::get().get_pipeline(params.pipeline);
vkCmdBindPipeline(vk_command_buffer, pipeline->bind_point, pipeline->vk_pipeline);
@@ -204,6 +206,8 @@ void graphics_command_buffer::begin_renderpass(const renderpass_params& params)
}
void graphics_command_buffer::draw(const draw_params& params, const void* data, size_t size) const {
+ assert(size <= descriptor_heap_props.maxPushDataSize);
+
const device_pipeline* pipeline = vkdevice::get().get_pipeline(params.pipeline);
vkCmdBindPipeline(vk_command_buffer, pipeline->bind_point, pipeline->vk_pipeline);
@@ -222,6 +226,8 @@ void graphics_command_buffer::draw(const draw_params& params, const void* data,
}
void graphics_command_buffer::draw_indexed(const draw_indexed_params& params, const void* data, size_t size) const {
+ assert(size <= descriptor_heap_props.maxPushDataSize);
+
const device_pipeline* pipeline = vkdevice::get().get_pipeline(params.pipeline);
vkCmdBindPipeline(vk_command_buffer, pipeline->bind_point, pipeline->vk_pipeline);