Skip to content

Commit

Permalink
Working better on integrated GPU"
Browse files Browse the repository at this point in the history
  • Loading branch information
Honeybunch committed Nov 14, 2023
1 parent ef8a041 commit 158155f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/rendersystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ VkResult tb_rnd_sys_alloc_gpu_buffer(RenderSystem *self,
const char *name, TbBuffer *buffer);
VkResult tb_rnd_sys_alloc_gpu_image(RenderSystem *self,
const VkImageCreateInfo *create_info,
VmaAllocationCreateFlags vma_flags,
const char *name, TbImage *image);

VkResult tb_rnd_sys_tmp_buffer_copy(RenderSystem *self, uint64_t size,
Expand Down
2 changes: 1 addition & 1 deletion include/rendertargetsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#define RenderTargetSystemId 0xB0BABABE

#define TB_SHADOW_MAP_DIM 4096
#define TB_SHADOW_MAP_DIM 2048

typedef uint32_t TbRenderTargetId;
static const TbRenderTargetId InvalidRenderTargetId = SDL_MAX_UINT32;
Expand Down
13 changes: 5 additions & 8 deletions source/rendersystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,12 @@ VkResult tb_rnd_sys_alloc_gpu_buffer(RenderSystem *self,

VkResult tb_rnd_sys_alloc_gpu_image(RenderSystem *self,
const VkImageCreateInfo *create_info,
VmaAllocationCreateFlags vma_flags,
const char *name, TbImage *image) {
VmaAllocator vma_alloc = self->vma_alloc;
VmaAllocationCreateInfo alloc_create_info = {
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT,
.flags = vma_flags,
};
VkResult err = vmaCreateImage(vma_alloc, create_info, &alloc_create_info,
&image->image, &image->alloc, &image->info);
Expand Down Expand Up @@ -571,7 +570,7 @@ VkResult tb_rnd_sys_create_gpu_image(RenderSystem *self, const void *data,
const VkImageCreateInfo *create_info,
const char *name, TbImage *image,
TbHostBuffer *host) {
VkResult err = tb_rnd_sys_alloc_gpu_image(self, create_info, name, image);
VkResult err = tb_rnd_sys_alloc_gpu_image(self, create_info, 0, name, image);
TB_VK_CHECK_RET(err, "Failed to allocate gpu image for texture", err);

void *ptr = NULL;
Expand All @@ -597,14 +596,12 @@ VkResult tb_rnd_sys_create_gpu_image(RenderSystem *self, const void *data,
return err;
}

// Copy the given data to the temp buffer and schedule an upload to the
// dedicated gpu image
// Or if this is a UMA platform just directly create the image
// Copy the given data to the temp buffer and move it into a dedicated GPU image
VkResult tb_rnd_sys_create_gpu_image_tmp(RenderSystem *self, const void *data,
uint64_t data_size, uint32_t alignment,
const VkImageCreateInfo *create_info,
const char *name, TbImage *image) {
VkResult err = tb_rnd_sys_alloc_gpu_image(self, create_info, name, image);
VkResult err = tb_rnd_sys_alloc_gpu_image(self, create_info, 0, name, image);
TB_VK_CHECK_RET(err, "Failed to allocate gpu image for texture", err);

void *ptr = NULL;
Expand Down
4 changes: 3 additions & 1 deletion source/rendertargetsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ bool create_render_target(RenderTargetSystem *self, RenderTarget *rt,
.samples = VK_SAMPLE_COUNT_1_BIT,
.usage = usage | VK_IMAGE_USAGE_SAMPLED_BIT,
};
err = tb_rnd_sys_alloc_gpu_image(self->render_system, &create_info,
VmaAllocationCreateFlags flags =
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
err = tb_rnd_sys_alloc_gpu_image(self->render_system, &create_info, flags,
desc->name, &rt->images[i]);
TB_VK_CHECK_RET(err, "Failed to allocate image for render target", false);

Expand Down
2 changes: 1 addition & 1 deletion source/texturesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ TbTextureId tb_tex_system_alloc_texture(TextureSystem *self, const char *name,
const VkFormat format = create_info->format;
// Allocate image
{
err = tb_rnd_sys_alloc_gpu_image(rnd_sys, create_info, name,
err = tb_rnd_sys_alloc_gpu_image(rnd_sys, create_info, 0, name,
&texture->gpu_image);
TB_VK_CHECK_RET(err, "Failed to allocate gpu image for texture",
InvalidTextureId);
Expand Down

0 comments on commit 158155f

Please sign in to comment.