summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-29 23:28:00 +1100
committerquou <quou@disroot.org>2024-12-29 23:28:00 +1100
commite25b20717523e579bb6f1e0d17b635c71bad6fab (patch)
treedd7839c247b81554d0ea2f5207df0f52f0484637
parent39fc0b5af67aa2dc0763394b0727e919840f9f57 (diff)
resource names
-rw-r--r--asset.cpp2
-rw-r--r--asset.hpp7
-rw-r--r--c2.cpp13
-rw-r--r--model.cpp12
-rw-r--r--model.hpp7
-rw-r--r--ui.cpp6
-rw-r--r--video.cpp88
-rw-r--r--video.hpp12
8 files changed, 127 insertions, 20 deletions
diff --git a/asset.cpp b/asset.cpp
index 10ddd04..8a5a1cc 100644
--- a/asset.cpp
+++ b/asset.cpp
@@ -123,7 +123,7 @@ Asset* Asset_Arena::load(const char* name) {
pack_seek(f, 0, seek_rel_start);
Asset_Loader& loader = manager.get_loader(magic);
clear_arena(s);
- Asset* asset = loader.load(a, s, f);
+ Asset* asset = loader.load(a, s, name, f);
if (asset) {
asset->loader = &loader;
assets[b].name = dup_string(a, name);
diff --git a/asset.hpp b/asset.hpp
index c149e0a..63ea047 100644
--- a/asset.hpp
+++ b/asset.hpp
@@ -11,7 +11,12 @@ struct Asset {
};
struct Asset_Loader {
- virtual Asset* load(Arena* a, Arena* s, Pack_File* f) = 0;
+ virtual Asset* load(
+ Arena* a,
+ Arena* s,
+ const char* filename,
+ Pack_File* f
+ ) = 0;
virtual void unload(Asset* a) = 0;
};
diff --git a/c2.cpp b/c2.cpp
index 936638d..e88f12d 100644
--- a/c2.cpp
+++ b/c2.cpp
@@ -29,11 +29,13 @@ struct C2 : public App {
static Buffer_Id upload_verts(Device* dev) {
Buffer_Id stage = dev->create_buffer(
+ "temp",
sizeof verts,
Buffer_Flags::copy_src |
Buffer_Flags::cpu_readwrite
);
Buffer_Id vbo = dev->create_buffer(
+ "autism triangle vbo",
sizeof verts,
Buffer_Flags::vertex_buffer |
Buffer_Flags::copy_dst
@@ -59,7 +61,7 @@ static Sampler_Id create_clamped_linear(Device* dev) {
s.mag = Filter_Mode::linear;
s.address_u = Address_Mode::repeat;
s.address_v = Address_Mode::repeat;
- return dev->create_sampler(s);
+ return dev->create_sampler("repeated linear", s);
}
struct Config_Buffer {
@@ -80,7 +82,7 @@ extern "C" int entrypoint() {
Texture* texture;
Texture* texture2;
Model* monkey;
- Buffer_Id vbo, cbuf, cbuf2;
+ Buffer_Id vbo, cbuf;
Sampler_Id clamped_linear;
UI* ui;
C2* app = App::create<C2>("c2");
@@ -113,15 +115,11 @@ extern "C" int entrypoint() {
texture = (Texture*)assets.load("22.tex");
texture2 = (Texture*)assets.load("kita.tex");
cbuf = dev->create_buffer(
+ "config buffer",
sizeof(Config_Buffer),
Buffer_Flags::constant_buffer |
Buffer_Flags::cpu_readwrite
);
- cbuf2 = dev->create_buffer(
- sizeof(Config_Buffer2),
- Buffer_Flags::constant_buffer |
- Buffer_Flags::cpu_readwrite
- );
per_frame = heap_alloc(
dev->heap,
per_frame_memory_size
@@ -251,7 +249,6 @@ extern "C" int entrypoint() {
dev->destroy_sampler(clamped_linear);
dev->destroy_buffer(vbo);
dev->destroy_buffer(cbuf);
- dev->destroy_buffer(cbuf2);
dev->destroy();
app->destroy();
return 0;
diff --git a/model.cpp b/model.cpp
index f102a07..dd14085 100644
--- a/model.cpp
+++ b/model.cpp
@@ -19,7 +19,12 @@ void Model_Loader::init(Device* device, Asset_Arena* shader_arena) {
shaders = shader_arena;
}
-Asset* Model_Loader::load(Arena* a, Arena* s, Pack_File* f) {
+Asset* Model_Loader::load(
+ Arena* a,
+ Arena* s,
+ const char* filename,
+ Pack_File* f
+) {
char magic[4];
int vbo_size, ibo_size, node_count, i, coff, icoff, vcoff;
uint8_t* verts;
@@ -46,11 +51,13 @@ Asset* Model_Loader::load(Arena* a, Arena* s, Pack_File* f) {
r->mesh_count = node_count;
meshes = r->get_meshes();
stage_verts = dev->create_buffer(
+ "model vertex buffer stage",
vbo_size,
Buffer_Flags::copy_src |
Buffer_Flags::cpu_readwrite
);
stage_indices = dev->create_buffer(
+ "model index buffer stage",
ibo_size,
Buffer_Flags::copy_src |
Buffer_Flags::cpu_readwrite
@@ -96,16 +103,19 @@ Asset* Model_Loader::load(Arena* a, Arena* s, Pack_File* f) {
dev->unmap_buffer(stage_verts);
dev->unmap_buffer(stage_indices);
r->vbo = dev->create_buffer(
+ filename,
vbo_size,
Buffer_Flags::copy_dst |
Buffer_Flags::vertex_buffer
);
r->ibo = dev->create_buffer(
+ filename,
ibo_size,
Buffer_Flags::copy_dst |
Buffer_Flags::index_buffer
);
r->mvp = dev->create_buffer(
+ filename,
sizeof(MVP_Cbuffer) * node_count,
Buffer_Flags::constant_buffer |
Buffer_Flags::cpu_readwrite
diff --git a/model.hpp b/model.hpp
index 0242cd0..7130024 100644
--- a/model.hpp
+++ b/model.hpp
@@ -40,7 +40,12 @@ struct Model_Loader : public Asset_Loader {
Device* dev;
Asset_Arena* shaders;
void init(Device* device, Asset_Arena* shader_arena);
- Asset* load(Arena* a, Arena* s, Pack_File* f) override;
+ Asset* load(
+ Arena* a,
+ Arena* s,
+ const char* filename,
+ Pack_File* f
+ ) override;
void unload(Asset* a);
};
diff --git a/ui.cpp b/ui.cpp
index f6caedd..bd7a90d 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -78,6 +78,7 @@ static Texture_Id create_atlas(Device* d, Arena* a) {
int x, y;
int size = 10 * font_w;
Buffer_Id buf = d->create_buffer(
+ "font atlas stage",
size,
Buffer_Flags::copy_src |
Buffer_Flags::cpu_readwrite
@@ -94,6 +95,7 @@ static Texture_Id create_atlas(Device* d, Arena* a) {
}
d->unmap_buffer(buf);
tex = d->create_texture(
+ "font atlas",
texture_format_r8i,
Texture_Flags::sampleable | Texture_Flags::copy_dst,
font_w,
@@ -111,7 +113,7 @@ static Sampler_Id create_clamped_point(Device* dev) {
s.mag = Filter_Mode::point;
s.address_u = Address_Mode::clamp;
s.address_v = Address_Mode::clamp;
- return dev->create_sampler(s);
+ return dev->create_sampler("clamped point", s);
}
UI* UI::create(Device* dev, Arena* a, Shader_Id sh) {
@@ -140,11 +142,13 @@ void UI::init(Device* dev, Arena* a, Texture_Id at, Shader_Id sh) {
atlas = at;
shader = sh;
mesh = device->create_buffer(
+ "UI Mesh",
mesh_size,
Buffer_Flags::vertex_buffer |
Buffer_Flags::cpu_readwrite
);
config_buf = device->create_buffer(
+ "UI Cbuffer",
sizeof(UI_CBuffer),
Buffer_Flags::constant_buffer |
Buffer_Flags::cpu_readwrite
diff --git a/video.cpp b/video.cpp
index 165dd9b..f95fcaa 100644
--- a/video.cpp
+++ b/video.cpp
@@ -602,6 +602,7 @@ struct Texture_Vk : public Texture, public Late_Terminated {
Resource_State state;
void destroy(Device_Vk*) override;
+ void set_name(Device_Vk* dev, const char* name);
};
struct Buffer_Vk : public Buffer, public Late_Terminated {
@@ -612,6 +613,7 @@ struct Buffer_Vk : public Buffer, public Late_Terminated {
void init(Device_Vk* dev, int flags, VkDeviceSize size);
void destroy(Device_Vk* dev) override;
+ void set_name(Device_Vk* dev, const char* name);
static VkBufferUsageFlags get_usage(int flags) {
VkBufferUsageFlags r = 0;
@@ -816,6 +818,7 @@ struct Sampler_Vk : public Late_Terminated {
void init(Device_Vk* dev, const Sampler_State& s);
void destroy(Device_Vk* dev) override;
+ void set_name(Device_Vk* dev, const char* name);
static VkFilter get_filter(Filter_Mode mode);
static VkSamplerMipmapMode get_mipmap_mode(Filter_Mode mode);
@@ -899,7 +902,12 @@ struct Hash_Function<Sampler_Id> {
struct Shader_Loader : public Asset_Loader {
Device_Vk* dev;
void init(Device_Vk* d);
- Asset* load(Arena* a, Arena* s, Pack_File* f) override;
+ Asset* load(
+ Arena* a,
+ Arena* s,
+ const char* filename,
+ Pack_File* f
+ ) override;
void unload(Asset* a) override;
};
@@ -907,7 +915,12 @@ struct Texture_Loader : public Asset_Loader {
Device_Vk* dev;
static size_t calc_size(Texture_Format fmt, int w, int h);
void init(Device_Vk* d);
- Asset* load(Arena* a, Arena* s, Pack_File* f) override;
+ Asset* load(
+ Arena* a,
+ Arena* s,
+ const char* filename,
+ Pack_File* f
+ ) override;
void unload(Asset* a) override;
Buffer_Id upload(void* buf, size_t size);
@@ -1390,6 +1403,7 @@ void Device_Vk::create_depth(int w, int h) {
if (depth)
destroy_texture(depth);
depth = create_texture(
+ "default depth",
texture_format_d24s8,
Texture_Flags::sampleable | Texture_Flags::depth_stencil_target,
w,
@@ -3230,11 +3244,30 @@ void Buffer_Vk::destroy(Device_Vk* dev) {
dev->buffers.remove(id);
}
-Buffer_Id Device::create_buffer(size_t size, int flags) {
+void Buffer_Vk::set_name(Device_Vk* dev, const char* name) {
+#ifdef DEBUG
+ VkDebugUtilsObjectNameInfoEXT i{};
+ i.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
+ i.pObjectName = name;
+ i.objectType = VK_OBJECT_TYPE_BUFFER;
+ i.objectHandle = (uint64_t)buf;
+ vkSetDebugUtilsObjectNameEXT(dev->dev, &i);
+#else
+ (void)dev;
+ (void)name;
+#endif
+}
+
+Buffer_Id Device::create_buffer(
+ const char* name,
+ size_t size,
+ int flags
+) {
Device_Vk* dev = (Device_Vk*)this;
Buffer_Id id = dev->alloc_buffer();
Buffer_Vk& buf = *(Buffer_Vk*)&get_buffer(id);
buf.init(dev, flags, (VkDeviceSize)size);
+ buf.set_name(dev, name);
return id;
}
@@ -3275,6 +3308,7 @@ Buffer& Device::get_buffer(Buffer_Id id) {
}
Texture_Id Device::create_texture(
+ const char* name,
Texture_Format fmt,
int flags,
int w,
@@ -3344,9 +3378,26 @@ Texture_Id Device::create_texture(
ctx.transition(id, Resource_State::shader_read);
dev->submit(ctx);
}
+ tex.set_name(dev, name);
return id;
}
+void Texture_Vk::set_name(Device_Vk* dev, const char* name) {
+#ifdef DEBUG
+ VkDebugUtilsObjectNameInfoEXT i{};
+ i.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
+ i.pObjectName = name;
+ i.objectType = VK_OBJECT_TYPE_IMAGE;
+ i.objectHandle = (uint64_t)image;
+ vkSetDebugUtilsObjectNameEXT(dev->dev, &i);
+ i.objectType = VK_OBJECT_TYPE_IMAGE_VIEW;
+ i.objectHandle = (uint64_t)view;
+ vkSetDebugUtilsObjectNameEXT(dev->dev, &i);
+#else
+ (void)dev;
+ (void)name;
+#endif
+}
Shader& Device::get_shader(Shader_Id id) {
Device_Vk* dev = (Device_Vk*)this;
@@ -3355,11 +3406,15 @@ Shader& Device::get_shader(Shader_Id id) {
return dev->shaders[id];
}
-Sampler_Id Device::create_sampler(const Sampler_State& state) {
+Sampler_Id Device::create_sampler(
+ const char* name,
+ const Sampler_State& state
+) {
Device_Vk* dev = (Device_Vk*)this;
Sampler_Id id = dev->alloc_sampler();
Sampler_Vk& s = dev->samplers[id];
s.init(dev, state);
+ s.set_name(dev, name);
return id;
}
@@ -3382,12 +3437,14 @@ void Shader_Loader::init(Device_Vk* d) {
Asset* Shader_Loader::load(
Arena* a,
Arena* s,
+ const char* filename,
Pack_File* f
) {
Shader_Vk* shader;
Shader_Id id;
(void)s;
(void)a;
+ (void)filename;
id = dev->alloc_shader();
shader = (Shader_Vk*)&dev->get_shader(id);
if (!shader->init(dev, f)) {
@@ -3523,6 +3580,7 @@ size_t Texture_Loader::calc_size(
Buffer_Id Texture_Loader::upload(void* buf, size_t size) {
void* mem;
Buffer_Id id = dev->create_buffer(
+ "texture stage",
size,
Buffer_Flags::copy_src |
Buffer_Flags::cpu_readwrite
@@ -3533,7 +3591,12 @@ Buffer_Id Texture_Loader::upload(void* buf, size_t size) {
return id;
}
-Asset* Texture_Loader::load(Arena* a, Arena* s, Pack_File* f) {
+Asset* Texture_Loader::load(
+ Arena* a,
+ Arena* s,
+ const char* filename,
+ Pack_File* f
+) {
char magic[4];
void* data;
int w, h;
@@ -3550,6 +3613,7 @@ Asset* Texture_Loader::load(Arena* a, Arena* s, Pack_File* f) {
{
Buffer_Id buf = upload(data, size);
Texture_Id tex = dev->create_texture(
+ filename,
fmt,
Texture_Flags::sampleable | Texture_Flags::copy_dst,
w,
@@ -3647,6 +3711,20 @@ void Sampler_Vk::destroy(Device_Vk* dev) {
dev->samplers.remove(id);
}
+void Sampler_Vk::set_name(Device_Vk* dev, const char* name) {
+#ifdef DEBUG
+ VkDebugUtilsObjectNameInfoEXT i{};
+ i.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
+ i.pObjectName = name;
+ i.objectType = VK_OBJECT_TYPE_SAMPLER;
+ i.objectHandle = (uint64_t)sampler;
+ vkSetDebugUtilsObjectNameEXT(dev->dev, &i);
+#else
+ (void)dev;
+ (void)name;
+#endif
+}
+
void Vram_Allocator::Page::init(
Device_Vk* dev,
VkDeviceSize s,
diff --git a/video.hpp b/video.hpp
index c89c60a..aa196a7 100644
--- a/video.hpp
+++ b/video.hpp
@@ -419,6 +419,7 @@ struct Device {
Context& get_ctx();
Texture_Id create_texture(
+ const char* name,
Texture_Format fmt,
int flags,
int w,
@@ -431,7 +432,11 @@ struct Device {
void destroy_texture(Texture_Id id);
void destroy_texturei(Texture_Id id);
- Buffer_Id create_buffer(size_t size, int flags);
+ Buffer_Id create_buffer(
+ const char* name,
+ size_t size,
+ int flags
+ );
void* map_buffer(Buffer_Id id, size_t offset, size_t size);
void unmap_buffer(Buffer_Id id);
Buffer& get_buffer(Buffer_Id id);
@@ -445,7 +450,10 @@ struct Device {
Shader& get_shader(Shader_Id id);
- Sampler_Id create_sampler(const Sampler_State& state);
+ Sampler_Id create_sampler(
+ const char* name,
+ const Sampler_State& state
+ );
void destroy_sampler(Sampler_Id id);
void destroy_sampleri(Sampler_Id id);
};