Instance index attempt
This commit is contained in:
1 parent
9a168facec
commit
6c6dd5626c
3 files changed
+194
-71
No files matched your search
+25
-2
@@ -7,9 +7,9 @@
|
||||
#include "../../window/window_inc.h"
|
||||
#include "../../wapp/wapp.h"
|
||||
#include "../../cglm/struct.h"
|
||||
#include <stdio.h>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "../../stb_image/stb_image.h"
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef USE_SDL_WINDOW_BACKEND
|
||||
@@ -315,6 +315,7 @@ wp_intern VkAttachmentStoreOp vkAttachmentStoreOpFromGpuAttachmentStore
|
||||
wp_intern GpuAttachmentStoreOp gpuAttachmentStoreOpFromVkAttachmentStoreOp(VkAttachmentStoreOp op);
|
||||
wp_intern VkResolveModeFlagBits vkResolveModeFlagsFromGpuResolveModeFlags(GpuResolveModeFlags flags);
|
||||
wp_intern GpuResolveModeFlags gpuResolveModeFlagsFromVkResolveModeFlags(VkResolveModeFlags flags);
|
||||
wp_intern u32 calcMaxMipLevelsForSize(ivec3s size);
|
||||
|
||||
GpuInstance *gpuInit(const WpAllocator *allocator, GpuInitRequest request) {
|
||||
assertWithLogger(volkInitialize() == VK_SUCCESS, &logger, "Failed to initialise volk");
|
||||
@@ -869,6 +870,7 @@ GpuImage *gpuCreateImage(const WpAllocator *allocator, GpuImageCreateRequest req
|
||||
GpuImage *output = wpMemAllocatorAlloc(allocator, sizeof(GpuImage));
|
||||
assertWithLogger(output != NULL, &logger, "Failed to allocate image");
|
||||
|
||||
u32 mip_levels = min(calcMaxMipLevelsForSize(request.size), request.subresource.level_count);
|
||||
VkFormat format = vkFormatFromGpuFormat(request.format);
|
||||
VkImageCreateInfo image_create_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
||||
@@ -877,7 +879,7 @@ GpuImage *gpuCreateImage(const WpAllocator *allocator, GpuImageCreateRequest req
|
||||
.extent = (VkExtent3D){ .width = request.size.x,
|
||||
.height = request.size.y,
|
||||
.depth = request.size.z },
|
||||
.mipLevels = request.subresource.level_count,
|
||||
.mipLevels = mip_levels,
|
||||
.arrayLayers = request.subresource.layer_count,
|
||||
.samples = vkSampleCountFromGpuSampleCount(request.samples),
|
||||
.tiling = vkImageTilingFromGpuImageTiling(request.tiling),
|
||||
@@ -954,8 +956,24 @@ GpuImage *gpuLoadImageFromFile(const WpAllocator *allocator, const WpAllocator *
|
||||
};
|
||||
GpuImage *output = gpuCreateImage(allocator, img_request);
|
||||
|
||||
u64 data_size = width * height * channels * sizeof(u8);
|
||||
GpuBufferCreateRequest temp_buf_request = {
|
||||
.device = request.command_pool->device,
|
||||
.size = data_size,
|
||||
.usage = GPU_BUFFER_USAGE_TRANSFER_SRC,
|
||||
};
|
||||
GpuBuffer temp_storage = gpuCreateBuffer(allocator, temp_buf_request);
|
||||
memcpy(temp_storage.cpu_mapping, data, data_size);
|
||||
|
||||
stbi_image_free((void *)data);
|
||||
|
||||
GpuCommandBufferAllocateRequest cb_request = {
|
||||
.pool = request.command_pool,
|
||||
.buffer_count = 1,
|
||||
};
|
||||
GpuCommandBufferPtrArray cbs = gpuAllocateCommandBuffers(allocator, temp, cb_request);
|
||||
GpuCommandBuffer *cb = cbs[0];
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -3555,3 +3573,8 @@ wp_intern GpuResolveModeFlags gpuResolveModeFlagsFromVkResolveModeFlags(VkResolv
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
wp_intern u32 calcMaxMipLevelsForSize(ivec3s size) {
|
||||
f32 max_dim = max(max(size.x, size.y), size.z);
|
||||
return (u32)(floorf(log2f(max_dim)) + 1.0f);
|
||||
}
|
||||
Reference in new issue
Block a user