diff options
Diffstat (limited to 'video.cpp')
-rw-r--r-- | video.cpp | 63 |
1 files changed, 55 insertions, 8 deletions
@@ -2252,6 +2252,40 @@ void Context::copy(Texture_Id dst, Buffer_Id src) { ); } +void Context::copy( + Texture_Id dst, + Buffer_Id src, + int mip, + int x, + int y, + int w, + int h +) { + Context_Vk* ctx = (Context_Vk*)this; + Device_Vk* dev = ctx->dev; + Texture_Vk& a = *(Texture_Vk*)&dev->get_texture(dst); + Buffer_Vk& b = *(Buffer_Vk*)&dev->get_buffer(src); + VkBufferImageCopy c{}; + transition(dst, Resource_State::copy_dst); + c.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + c.imageSubresource.layerCount = 1; + c.imageSubresource.mipLevel = mip; + c.imageExtent.width = w; + c.imageExtent.height = h; + c.imageExtent.depth = 1; + c.imageOffset.x = x; + c.imageOffset.y = y; + ctx->check_end_rp(); + vkCmdCopyBufferToImage( + ctx->cb, + b.buf, + a.image, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + 1, + &c + ); +} + void Context::transition(Texture_Id id, Resource_State state) { Context_Vk* ctx = (Context_Vk*)this; Device_Vk* dev = ctx->dev; @@ -3946,13 +3980,15 @@ Asset* Texture_Loader::load( char magic[4]; int w, h; size_t size; - Texture_Format fmt; + Texture_Format fmt = texture_format_r8i; + int mips = 0; (void)a; (void)s; pack_read(f, magic, 4); pack_read(f, &w, 4); pack_read(f, &h, 4); - pack_read(f, &fmt, 4); + pack_read(f, &fmt, 2); + pack_read(f, &mips, 2); size = calc_size(fmt, w, h); { Buffer_Id buf = dev->create_buffer( @@ -3961,9 +3997,6 @@ Asset* Texture_Loader::load( Buffer_Flags::copy_src | Buffer_Flags::cpu_readwrite ); - void* mem = dev->map_buffer(buf, 0, size); - pack_read(f, mem, size); - dev->unmap_buffer(buf); Texture_Id tex = dev->create_texture( filename, fmt, @@ -3971,11 +4004,25 @@ Asset* Texture_Loader::load( w, h, 1, + mips, 1, - 1, - buf + 0 ); - dev->destroy_buffer(buf); + { + int i; + for (i = 0; i < mips; i++) { + size = calc_size(fmt, w, h); + void* mem = dev->map_buffer(buf, 0, size); + pack_read(f, mem, size); + dev->unmap_buffer(buf); + auto& ctx = dev->acquire(); + ctx.copy(tex, buf, i, 0, 0, w, h); + dev->submit(ctx); + w >>= 1; + h >>= 1; + } + } + dev->destroy_bufferi(buf); return &dev->get_texture(tex); } } |