-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
249 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
#include "fwd.h" | ||
|
||
namespace rvk::impl { | ||
|
||
void check(VkResult result) { | ||
RVK_CHECK(result); | ||
} | ||
|
||
String_View describe(VkResult result) { | ||
switch(result) { | ||
#define STR(r) \ | ||
case VK_##r: return #r##_v | ||
STR(SUCCESS); | ||
STR(NOT_READY); | ||
STR(TIMEOUT); | ||
STR(EVENT_SET); | ||
STR(EVENT_RESET); | ||
STR(INCOMPLETE); | ||
STR(ERROR_OUT_OF_HOST_MEMORY); | ||
STR(ERROR_OUT_OF_DEVICE_MEMORY); | ||
STR(ERROR_INITIALIZATION_FAILED); | ||
STR(ERROR_DEVICE_LOST); | ||
STR(ERROR_MEMORY_MAP_FAILED); | ||
STR(ERROR_LAYER_NOT_PRESENT); | ||
STR(ERROR_EXTENSION_NOT_PRESENT); | ||
STR(ERROR_FEATURE_NOT_PRESENT); | ||
STR(ERROR_INCOMPATIBLE_DRIVER); | ||
STR(ERROR_TOO_MANY_OBJECTS); | ||
STR(ERROR_FORMAT_NOT_SUPPORTED); | ||
STR(ERROR_SURFACE_LOST_KHR); | ||
STR(ERROR_NATIVE_WINDOW_IN_USE_KHR); | ||
STR(SUBOPTIMAL_KHR); | ||
STR(ERROR_OUT_OF_DATE_KHR); | ||
STR(ERROR_INCOMPATIBLE_DISPLAY_KHR); | ||
STR(ERROR_VALIDATION_FAILED_EXT); | ||
STR(ERROR_INVALID_SHADER_NV); | ||
#undef STR | ||
default: return "UNKNOWN_ERROR"_v; | ||
} | ||
} | ||
|
||
[[nodiscard]] String_View describe(VkObjectType type) { | ||
switch(type) { | ||
#define STR(r) \ | ||
case VK_OBJECT_TYPE_##r: return #r##_v | ||
STR(UNKNOWN); | ||
STR(INSTANCE); | ||
STR(PHYSICAL_DEVICE); | ||
STR(DEVICE); | ||
STR(QUEUE); | ||
STR(SEMAPHORE); | ||
STR(COMMAND_BUFFER); | ||
STR(FENCE); | ||
STR(DEVICE_MEMORY); | ||
STR(BUFFER); | ||
STR(IMAGE); | ||
STR(EVENT); | ||
STR(QUERY_POOL); | ||
STR(BUFFER_VIEW); | ||
STR(IMAGE_VIEW); | ||
STR(SHADER_MODULE); | ||
STR(PIPELINE_CACHE); | ||
STR(PIPELINE_LAYOUT); | ||
STR(RENDER_PASS); | ||
STR(PIPELINE); | ||
STR(DESCRIPTOR_SET_LAYOUT); | ||
STR(SAMPLER); | ||
STR(DESCRIPTOR_POOL); | ||
STR(DESCRIPTOR_SET); | ||
STR(FRAMEBUFFER); | ||
STR(COMMAND_POOL); | ||
STR(SAMPLER_YCBCR_CONVERSION); | ||
STR(DESCRIPTOR_UPDATE_TEMPLATE); | ||
STR(SURFACE_KHR); | ||
STR(SWAPCHAIN_KHR); | ||
STR(DISPLAY_KHR); | ||
STR(DISPLAY_MODE_KHR); | ||
STR(DEBUG_REPORT_CALLBACK_EXT); | ||
STR(DEBUG_UTILS_MESSENGER_EXT); | ||
STR(VALIDATION_CACHE_EXT); | ||
#undef STR | ||
default: return "UNKNOWN_OBJECT"_v; | ||
} | ||
} | ||
|
||
} // namespace rvk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
#include "shader_loader.h" | ||
|
||
#include <rpp/asyncio.h> | ||
|
||
namespace rvk { | ||
|
||
impl::Shader& Shader_Loader::get(Token token) { | ||
return shaders.get(token).first; | ||
} | ||
|
||
Shader_Loader::Token Shader_Loader::compile(String_View path) { | ||
|
||
if(Opt<Vec<u8, Files::Alloc>> data = Files::read(path)) { | ||
|
||
Shader shader{device.dup(), data->slice()}; | ||
Files::Write_Watcher watcher{path}; | ||
|
||
Token token = next_token.incr(); | ||
{ | ||
Thread::Lock lock{mutex}; | ||
shaders.insert(token, Pair{move(shader), move(watcher)}); | ||
} | ||
|
||
return token; | ||
} | ||
|
||
die("[rvk] Failed to read shader from %!", path); | ||
} | ||
|
||
Async::Task<Shader_Loader::Token> Shader_Loader::compile_async(Async::Pool<>& pool, | ||
String_View path) { | ||
|
||
if(Opt<Vec<u8, Files::Alloc>> data = co_await Async::read(pool, path)) { | ||
|
||
// Will compile on another thread | ||
Shader shader{device.dup(), data->slice()}; | ||
Files::Write_Watcher watcher{path}; | ||
|
||
Token token = next_token.incr(); | ||
{ | ||
Thread::Lock lock{mutex}; | ||
shaders.insert(token, Pair{move(shader), move(watcher)}); | ||
} | ||
|
||
co_return token; | ||
} | ||
|
||
die("[rvk] Failed to read shader from %!", path); | ||
} | ||
|
||
void Shader_Loader::try_reload() { | ||
Thread::Lock lock{mutex}; | ||
|
||
Region(R) { | ||
Map<Reload_Token, Empty<>, Mregion<R>> callbacks_to_run; | ||
|
||
for(auto& [token, shader] : shaders) { | ||
if(shader.second.poll()) { | ||
if(Opt<Vec<u8, Files::Alloc>> data = shader.second.read()) { | ||
shader.first = Shader{device.dup(), data->slice()}; | ||
callbacks_to_run.insert(reloads.get(token), {}); | ||
} | ||
} | ||
} | ||
|
||
for(auto [token, _] : callbacks_to_run) { | ||
static_cast<void>(_); | ||
callbacks.get(token)(*this); | ||
} | ||
} | ||
} | ||
|
||
void Shader_Loader::on_reload(Slice<Shader_Loader::Token> tokens, | ||
Function<void(Shader_Loader&)> callback) { | ||
Thread::Lock lock{mutex}; | ||
|
||
Reload_Token reload_token = next_reload_token++; | ||
callbacks.insert(reload_token, move(callback)); | ||
|
||
for(auto token : tokens) { | ||
reloads.insert(token, reload_token); | ||
} | ||
} | ||
|
||
} // namespace rvk |
Oops, something went wrong.