Skip to content

Commit 9812308

Browse files
committed
Merge branch 'main' of https://github.com/TheNumbat/rvk
2 parents f871ef6 + fe2653c commit 9812308

18 files changed

+171
-65
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ If you're already using [rpp](https://github.com/TheNumbat/rpp), also set the fo
4040
set(RVK_HAS_RPP TRUE)
4141
```
4242

43-
Alternatively, to start an rvk project from scratch, you can fork [rpp_example_project/rvk](https://github.com/TheNumbat/rpp_example_project/tree/rvk).
44-
4543
## Examples
4644

4745
### Main Loop
@@ -103,8 +101,8 @@ i32 main() {
103101

104102
rvk::Shader_Loader loader = rvk::make_shader_loader();
105103

106-
auto vertex = loader.load("shader.vert.spv"_v);
107-
auto fragment = loader.load("shader.frag.spv"_v);
104+
auto vertex = loader.compile("shader.vert.spv"_v);
105+
auto fragment = loader.compile("shader.frag.spv"_v);
108106

109107
loader.on_reload(Slice{{vertex, fragment}}, [&](Shader_Loader&) {
110108
// Recreate your pipeline...

deps/rpp

rvk/acceleration.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "acceleration.h"
55
#include "commands.h"
6+
#include "rvk.h"
67

78
namespace rvk::impl {
89

@@ -31,7 +32,7 @@ TLAS& TLAS::operator=(TLAS&& src) {
3132
return *this;
3233
}
3334

34-
Opt<TLAS::Staged> TLAS::make(Arc<Device_Memory, Alloc> memory, Buffer& instances, u32 n_instances) {
35+
Opt<TLAS::Staged> TLAS::make(Arc<Device_Memory, Alloc> memory, Buffer instances, u32 n_instances) {
3536

3637
assert(instances.length());
3738

@@ -73,14 +74,13 @@ Opt<TLAS::Staged> TLAS::make(Arc<Device_Memory, Alloc> memory, Buffer& instances
7374
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
7475
if(!scratch) return {};
7576

76-
return Opt<Staged>{Staged{move(*structure_buf), move(*scratch), instances, n_instances,
77+
return Opt<Staged>{Staged{move(*structure_buf), move(*scratch), move(instances), n_instances,
7778
build_sizes.accelerationStructureSize, move(memory)}};
7879
}
7980

8081
TLAS TLAS::build(Commands& cmds, Staged buffers) {
8182

8283
// Create acceleration structure
83-
assert(buffers.instances);
8484

8585
VkAccelerationStructureKHR acceleration_structure = null;
8686

@@ -103,7 +103,7 @@ TLAS TLAS::build(Commands& cmds, Staged buffers) {
103103
geom.geometry.instances.sType =
104104
VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR;
105105
geom.geometry.instances.arrayOfPointers = VK_FALSE;
106-
geom.geometry.instances.data.deviceAddress = buffers.instances->gpu_address();
106+
geom.geometry.instances.data.deviceAddress = buffers.instances.gpu_address();
107107

108108
VkAccelerationStructureBuildGeometryInfoKHR build_info = {};
109109
build_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR;
@@ -116,6 +116,7 @@ TLAS TLAS::build(Commands& cmds, Staged buffers) {
116116
build_info.dstAccelerationStructure = acceleration_structure;
117117

118118
cmds.attach(move(buffers.scratch));
119+
cmds.attach(move(buffers.instances));
119120

120121
VkAccelerationStructureBuildRangeInfoKHR offset = {};
121122
offset.primitiveCount = buffers.n_instances;
@@ -189,6 +190,8 @@ Opt<BLAS::Staged> BLAS::make(Arc<Device_Memory, Alloc> memory, Buffer data,
189190
geom.geometry.triangles.indexData.deviceAddress = base_data + offset.index;
190191
if(offset.transform) {
191192
geom.geometry.triangles.transformData.deviceAddress = base_data + *offset.transform;
193+
} else {
194+
geom.geometry.triangles.transformData.deviceAddress = 0;
192195
}
193196
geom.geometry.triangles.maxVertex = static_cast<u32>(offset.n_vertices);
194197

@@ -231,6 +234,8 @@ Opt<BLAS::Staged> BLAS::make(Arc<Device_Memory, Alloc> memory, Buffer data,
231234

232235
BLAS BLAS::build(Commands& cmds, Staged buffers) {
233236

237+
if(!buffers.geometry.length()) return {};
238+
234239
// Create acceleration structure
235240

236241
VkAccelerationStructureKHR acceleration_structure = null;

rvk/acceleration.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ struct TLAS {
2727
Staged& operator=(Staged&& src) = default;
2828

2929
private:
30-
explicit Staged(Buffer result, Buffer scratch, Buffer& instances, u32 n_instances,
30+
explicit Staged(Buffer result, Buffer scratch, Buffer instances, u32 n_instances,
3131
u64 result_size, Arc<Device_Memory, Alloc> memory)
32-
: result(move(result)), scratch(move(scratch)), instances(instances),
32+
: result(move(result)), scratch(move(scratch)), instances(move(instances)),
3333
n_instances(n_instances), result_size(result_size), memory(move(memory)) {
3434
}
3535

3636
Buffer result;
3737
Buffer scratch;
38-
Ref<Buffer> instances;
38+
Buffer instances;
3939
u32 n_instances = 0;
4040
u64 result_size = 0;
4141
Arc<Device_Memory, Alloc> memory;
@@ -63,7 +63,7 @@ struct TLAS {
6363
VkAccelerationStructureKHR accel);
6464
friend struct Vk;
6565

66-
static Opt<Staged> make(Arc<Device_Memory, Alloc> memory, Buffer& instances, u32 n_instances);
66+
static Opt<Staged> make(Arc<Device_Memory, Alloc> memory, Buffer instances, u32 n_instances);
6767

6868
Arc<Device_Memory, Alloc> memory;
6969

rvk/commands.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ void Commands::reset() {
147147

148148
RVK_CHECK(vkResetCommandBuffer(buffer, 0));
149149

150+
transient_buffers.clear();
151+
150152
VkCommandBufferBeginInfo begin_info = {};
151153
begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
152154
begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
@@ -245,7 +247,7 @@ void Command_Pool_Manager<F>::begin_thread() {
245247
VkCommandPool pool = null;
246248
RVK_CHECK(vkCreateCommandPool(*device, &create_info, null, &pool));
247249

248-
this_thread.pool = Box<Command_Pool, Alloc>::make(device.dup(), F, pool);
250+
this_thread.pool = Arc<Command_Pool, Alloc>::make(device.dup(), F, pool);
249251

250252
Profile::Time_Point end = Profile::timestamp();
251253
info("[rvk] Allocated new % command pool for thread % in %ms.", F, id,

rvk/commands.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ struct Command_Pool {
114114

115115
private:
116116
explicit Command_Pool(Arc<Device, Alloc> device, Queue_Family family, VkCommandPool pool);
117-
friend struct Box<Command_Pool, Alloc>;
117+
friend struct Arc<Command_Pool, Alloc>;
118118

119119
Commands make();
120120
void release(VkCommandBuffer commands);
@@ -141,8 +141,8 @@ struct Command_Pool_Manager {
141141
Command_Pool_Manager& operator=(Command_Pool_Manager&&) = delete;
142142

143143
// When allocating a command buffer, you _MUST_ get it from your current
144-
// thread's pool, and it _MUST_ be recorded in that thread _ONLY_. Once recording
145-
// is complete, it _MAY_ then be passed to another thread (e.g. the main thread)
144+
// thread's pool, and it _MUST_ be recorded in that thread _ONLY_. Once the buffer
145+
// is ended, it _MAY_ then be passed to another thread (e.g. the main thread)
146146
// for submission and deletion. Deletion is OK on another thread because
147147
// all it does is push it onto the buffer free list, which is protected by the mutex.
148148
//
@@ -162,15 +162,15 @@ struct Command_Pool_Manager {
162162
~This_Thread() {
163163
if(pool_manager) pool_manager->end_thread();
164164
}
165-
Box<Command_Pool, Alloc> pool;
165+
Arc<Command_Pool, Alloc> pool;
166166
Ref<Command_Pool_Manager> pool_manager;
167167
};
168168

169169
static inline thread_local This_Thread this_thread;
170170

171171
Arc<Device, Alloc> device;
172172

173-
Vec<Box<Command_Pool, Alloc>, Alloc> free_list;
173+
Vec<Arc<Command_Pool, Alloc>, Alloc> free_list;
174174
Map<Thread::Id, Empty<>, Alloc> active_threads;
175175
Thread::Mutex mutex;
176176
};

rvk/device.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,6 @@ u32 Device::queue_index(Queue_Family family) {
606606

607607
void Device::submit(Commands& cmds, u32 index) {
608608

609-
cmds.end();
610-
611609
VkCommandBufferSubmitInfo cmd_info = {};
612610
cmd_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO;
613611
cmd_info.commandBuffer = cmds;
@@ -625,8 +623,6 @@ void Device::submit(Commands& cmds, u32 index) {
625623

626624
void Device::submit(Commands& cmds, u32 index, Fence& fence) {
627625

628-
cmds.end();
629-
630626
VkCommandBufferSubmitInfo cmd_info = {};
631627
cmd_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO;
632628
cmd_info.commandBuffer = cmds;
@@ -645,8 +641,6 @@ void Device::submit(Commands& cmds, u32 index, Fence& fence) {
645641

646642
void Device::submit(Commands& cmds, u32 index, Slice<Sem_Ref> signal, Slice<Sem_Ref> wait) {
647643

648-
cmds.end();
649-
650644
Region(R) {
651645

652646
Vec<VkSemaphoreSubmitInfo, Mregion<R>> vk_signal(signal.length());
@@ -690,8 +684,6 @@ void Device::submit(Commands& cmds, u32 index, Slice<Sem_Ref> signal, Slice<Sem_
690684
void Device::submit(Commands& cmds, u32 index, Slice<Sem_Ref> signal, Slice<Sem_Ref> wait,
691685
Fence& fence) {
692686

693-
cmds.end();
694-
695687
Region(R) {
696688

697689
Vec<VkSemaphoreSubmitInfo, Mregion<R>> vk_signal(signal.length());

rvk/execute.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace rvk {
1010

1111
namespace impl {
1212
Arc<Device, Alloc> get_device();
13-
}
13+
bool validation_enabled();
14+
} // namespace impl
1415

1516
using namespace rpp;
1617

@@ -39,10 +40,12 @@ auto sync(F&& f, Queue_Family family, u32 index) -> Invoke_Result<F, Commands&>
3940
auto cmds = make_commands(family);
4041
if constexpr(Same<Invoke_Result<F, Commands&>, void>) {
4142
f(cmds);
43+
cmds.end();
4244
submit(cmds, index, fence);
4345
fence.wait();
4446
} else {
4547
auto result = f(cmds);
48+
cmds.end();
4649
submit(cmds, index, fence);
4750
fence.wait();
4851
return result;
@@ -53,17 +56,27 @@ template<typename F>
5356
requires Invocable<F, Commands&>
5457
auto async(Async::Pool<>& pool, F&& f, Queue_Family family, u32 index)
5558
-> Async::Task<Invoke_Result<F, Commands&>> {
56-
co_await pool.suspend();
5759
auto fence = make_fence();
5860
auto cmds = make_commands(family);
5961
if constexpr(Same<Invoke_Result<F, Commands&>, void>) {
6062
forward<F>(f)(cmds);
63+
cmds.end();
6164
submit(cmds, index, fence);
62-
co_await pool.event(fence.event());
65+
if(impl::validation_enabled()) {
66+
fence.wait();
67+
} else {
68+
co_await pool.event(fence.event());
69+
}
70+
co_return;
6371
} else {
6472
auto ret = forward<F>(f)(cmds);
73+
cmds.end();
6574
submit(cmds, index, fence);
66-
co_await pool.event(fence.event());
75+
if(impl::validation_enabled()) {
76+
fence.wait();
77+
} else {
78+
co_await pool.event(fence.event());
79+
}
6780
co_return ret;
6881
}
6982
}

rvk/fwd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ struct Command_Pool;
4848
template<Queue_Family F>
4949
struct Command_Pool_Manager;
5050
struct Pipeline;
51-
template<VkShaderStageFlagBits stages, typename... Ts>
51+
template<u32 stages, typename... Ts>
5252
struct Push_Constants;
53+
struct Binding_Table;
5354
struct Shader;
5455
struct Sampler;
5556
struct Swapchain;
@@ -63,6 +64,7 @@ void check(VkResult result);
6364

6465
} // namespace impl
6566

67+
using impl::Binding_Table;
6668
using impl::BLAS;
6769
using impl::Buffer;
6870
using impl::Commands;

rvk/memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ Buffer& Buffer::operator=(Buffer&& src) {
340340
return *this;
341341
}
342342

343-
u64 Buffer::gpu_address() {
343+
u64 Buffer::gpu_address() const {
344344
if(!buffer) return 0;
345345
VkBufferDeviceAddressInfo info = {};
346346
info.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO;

0 commit comments

Comments
 (0)