Multiple changes + fixes
This commit is contained in:
+6
-6
@@ -88,9 +88,9 @@ static inline const char* VkResultStrings(VkResult res) {
|
||||
}
|
||||
};
|
||||
|
||||
#define EVK_ASSERT(fn) do { \
|
||||
VkResult __vk_assert_result_internal = fn; \
|
||||
if(__vk_assert_result_internal != VK_SUCCESS) { \
|
||||
ev_log_error("[VulkanError] `%s` returned error code %d ('%s')", EV_STRINGIZE(fn), __vk_assert_result_internal, VkResultStrings(__vk_assert_result_internal));\
|
||||
} \
|
||||
} while (0)
|
||||
static VkResult __evk_check_result_internal;
|
||||
#define EVK_CHECK(fn) ( \
|
||||
__evk_check_result_internal = fn, \
|
||||
__evk_check_result_internal != VK_SUCCESS? \
|
||||
ev_log_error("[VulkanError] `%s` returned error code %d ('%s')", EV_STRINGIZE(fn), __evk_check_result_internal, VkResultStrings(__evk_check_result_internal)):0, \
|
||||
__evk_check_result_internal)
|
||||
+4
-4
@@ -71,7 +71,7 @@ evkDevice evkCreateDevice(evkDeviceCreateInfo createInfo)
|
||||
device._physicalDevice = evkDetectPhysicalDevice(createInfo.instance, createInfo.physicalDeviceType);
|
||||
device._instance = createInfo.instance;
|
||||
|
||||
VkPhysicalDeviceProperties2 physicalDeviceProperties = {
|
||||
VkPhysicalDeviceProperties2 physicalDeviceProperties = {
|
||||
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
|
||||
};
|
||||
|
||||
@@ -200,7 +200,7 @@ evkDevice evkCreateDevice(evkDeviceCreateInfo createInfo)
|
||||
}
|
||||
|
||||
// Allowing the retrieval of non-requested, but allocated, queues is possible.
|
||||
// Example: Allocating COMPUTE | GRAPHICS then requesting GRAPHICS should
|
||||
// Example: Allocating COMPUTE | GRAPHICS then requesting GRAPHICS should
|
||||
// return the already allocated queue
|
||||
for (i32 i = MAX_QUEUE_FAMILIES - 1; i >= 0; i--) {
|
||||
for (i32 j = i - 1; j >= 0; j--) {
|
||||
@@ -210,7 +210,7 @@ evkDevice evkCreateDevice(evkDeviceCreateInfo createInfo)
|
||||
}
|
||||
}
|
||||
|
||||
EVK_ASSERT(vkCreateDevice(device._physicalDevice, &vkDeviceCreateInfo, evkGetAllocationCallbacks(), &device.vk));
|
||||
EVK_CHECK(vkCreateDevice(device._physicalDevice, &vkDeviceCreateInfo, evkGetAllocationCallbacks(), &device.vk));
|
||||
|
||||
vec_fini(&queueCreateInfoList);
|
||||
vec_fini(&priorities);
|
||||
@@ -221,4 +221,4 @@ evkDevice evkCreateDevice(evkDeviceCreateInfo createInfo)
|
||||
void evkDestroyDevice(evkDevice device)
|
||||
{
|
||||
vkDestroyDevice(device.vk, evkGetAllocationCallbacks());
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -56,6 +56,7 @@ evkImage evkGPUCreateImage(evkGPUAllocationCreateInfo allocationCreateInfo, VkIm
|
||||
.flags = allocationCreateInfo.allocationFlags,
|
||||
.pool = allocationCreateInfo.pool.vma,
|
||||
};
|
||||
img.allocData.allocator = allocationCreateInfo.allocator;
|
||||
|
||||
vmaCreateImage(allocationCreateInfo.allocator.vma, imageCreateInfo, &vmaAllocCreateInfo, &img.vk, &img.allocData.allocation.vma, &img.allocData.allocationInfo.vma);
|
||||
|
||||
@@ -79,6 +80,7 @@ evkBuffer evkGPUCreateBuffer(evkGPUAllocationCreateInfo allocationCreateInfo, Vk
|
||||
|
||||
vmaCreateBuffer(allocationCreateInfo.allocator.vma, bufferCreateInfo, &vmaAllocCreateInfo, &buf.vk, &buf.allocData.allocation.vma, &buf.allocData.allocationInfo.vma);
|
||||
buf.usage = bufferCreateInfo->usage;
|
||||
buf.allocData.allocator = allocationCreateInfo.allocator;
|
||||
|
||||
return buf;
|
||||
}
|
||||
@@ -86,4 +88,4 @@ evkBuffer evkGPUCreateBuffer(evkGPUAllocationCreateInfo allocationCreateInfo, Vk
|
||||
void evkGPUDestroyBuffer(evkBuffer buf)
|
||||
{
|
||||
vmaDestroyBuffer(buf.allocData.allocator.vma, buf.vk, buf.allocData.allocation.vma);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -183,7 +183,7 @@ evkPipeline evkCreateGraphicsPipeline(evkDevice device, evkPipelineCreateInfo cr
|
||||
|
||||
if(createInfo.setLayouts != NULL)
|
||||
{
|
||||
res.layout = evkCreatePipelineLayout(device,
|
||||
res.layout = evkCreatePipelineLayout(device,
|
||||
EV_DEFAULT(evkPipelineLayoutCreateInfo,
|
||||
setLayouts = createInfo.setLayouts,
|
||||
)
|
||||
@@ -210,7 +210,7 @@ evkPipeline evkCreateGraphicsPipeline(evkDevice device, evkPipelineCreateInfo cr
|
||||
.layout = res.layout.vk,
|
||||
};
|
||||
|
||||
EVK_ASSERT(vkCreateGraphicsPipelines(device.vk, VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, NULL, &res.vk));
|
||||
EVK_CHECK(vkCreateGraphicsPipelines(device.vk, VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, NULL, &res.vk));
|
||||
|
||||
res._device = device;
|
||||
|
||||
@@ -243,4 +243,4 @@ void evkCmdBindPipeline(evkCommandBuffer* cmdbuf, evkPipeline* pipeline)
|
||||
void evkCmdImageBarrier(evkCommandBuffer* cmdbuf, VkImageMemoryBarrier barrier)
|
||||
{
|
||||
vkCmdPipelineBarrier(cmdbuf->vk, 0, 0, 0, 0, NULL, 0, NULL, 1, &barrier);
|
||||
}
|
||||
}
|
||||
+10
-11
@@ -107,27 +107,26 @@ void evkDestroyShaderCompiler(evkShaderCompiler compiler)
|
||||
shaderc_compiler_release(compiler.sc);
|
||||
}
|
||||
|
||||
evkShader evkInitShaderFromFile(evkDevice device, evkShaderCompiler compiler, evstring shaderPath)
|
||||
evkShader evkInitShaderFromString(evkDevice device, evkShaderCompiler compiler,evstring shaderName, evstring shaderText)
|
||||
{
|
||||
evstring shaderText = evstring_readFile(shaderPath);
|
||||
|
||||
shaderc_compilation_result_t compilation_result = shaderc_compile_into_spv(compiler.sc, shaderText, evstring_getLength(shaderText), shaderc_glsl_infer_from_source, shaderPath, "main", compiler.scopt);
|
||||
shaderc_compilation_result_t compilation_result = shaderc_compile_into_spv(compiler.sc, shaderText, evstring_getLength(shaderText), shaderc_glsl_infer_from_source, shaderName, "main", compiler.scopt);
|
||||
|
||||
shaderc_compilation_status status = shaderc_result_get_compilation_status(compilation_result);
|
||||
|
||||
u32 errorCount = shaderc_result_get_num_errors(compilation_result);
|
||||
u32 warnCount = shaderc_result_get_num_warnings(compilation_result);
|
||||
ev_log_info("[[evkShader]] %s Compilation Status: %d ( %d Errors, %d Warnings )", shaderPath, status, errorCount, warnCount);
|
||||
ev_log_info("[[evkShader]] %s Compilation Status: %d ( %d Errors, %d Warnings )", shaderName, status, errorCount, warnCount);
|
||||
if(errorCount + warnCount > 0)
|
||||
{
|
||||
ev_log_error("Errors:\n%s", shaderc_result_get_error_message(compilation_result));
|
||||
}
|
||||
|
||||
evkShader shader = evkInitShaderFromBytes(device, (u8*)shaderc_result_get_bytes(compilation_result), shaderc_result_get_length(compilation_result));
|
||||
|
||||
evstring_free(shaderText);
|
||||
|
||||
return shader;
|
||||
return evkInitShaderFromBytes(device, (u8*)shaderc_result_get_bytes(compilation_result), shaderc_result_get_length(compilation_result));
|
||||
}
|
||||
evkShader evkInitShaderFromFile(evkDevice device, evkShaderCompiler compiler, evstring shaderPath)
|
||||
{
|
||||
evstring shaderText = evstring_readFile(shaderPath);
|
||||
return evkInitShaderFromString(device, compiler, shaderPath, shaderText);
|
||||
}
|
||||
|
||||
VkPipelineShaderStageCreateInfo evkGetShaderStageCreateInfo(evkShader shader)
|
||||
@@ -138,4 +137,4 @@ VkPipelineShaderStageCreateInfo evkGetShaderStageCreateInfo(evkShader shader)
|
||||
.module = shader.vk,
|
||||
.pName = "main",
|
||||
};
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -4,6 +4,9 @@
|
||||
|
||||
[[nodiscard("Leaking VkShaderModule")]]
|
||||
evkShader evkInitShaderFromBytes(evkDevice device, const u8* shaderBytes, u32 shaderLen);
|
||||
[[nodiscard("Leaking VkShaderModule")]]
|
||||
evkShader evkInitShaderFromString(evkDevice device, evkShaderCompiler compiler, evstring shaderName, evstring shaderText);
|
||||
[[nodiscard("Leaking VkShaderModule")]]
|
||||
evkShader evkInitShaderFromFile(evkDevice device, evkShaderCompiler compiler, evstring shaderPath);
|
||||
void evkDestroyShader(evkDevice device, evkShader shader);
|
||||
|
||||
@@ -15,4 +18,4 @@ VkPipelineShaderStageCreateInfo evkGetShaderStageCreateInfo(evkShader shader);
|
||||
|
||||
[[nodiscard("Leaking Shader Reflection Data")]]
|
||||
evkShaderReflectionData evkGenerateShaderReflectionData(const u8* shaderBytes, u32 shaderLen);
|
||||
void evkDestroyShaderReflectionData(evkShaderReflectionData data);
|
||||
void evkDestroyShaderReflectionData(evkShaderReflectionData data);
|
||||
+7
-7
@@ -9,7 +9,7 @@ evkSwapChain evkCreateSwapChain(evkSwapChainCreateInfo createInfo)
|
||||
VkSurfaceCapabilitiesKHR surfaceCaps;
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(createInfo.device._physicalDevice, createInfo.surface, &surfaceCaps);
|
||||
|
||||
if(surfaceCaps.maxImageCount == 0)
|
||||
if(surfaceCaps.maxImageCount == 0)
|
||||
surfaceCaps.maxImageCount = UInt32.MAX;
|
||||
|
||||
VkCompositeAlphaFlagBitsKHR compositeAlpha =
|
||||
@@ -27,7 +27,7 @@ evkSwapChain evkCreateSwapChain(evkSwapChainCreateInfo createInfo)
|
||||
VkSurfaceFormatKHR surfaceFormats[surfaceFormatCount];
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(createInfo.device._physicalDevice, createInfo.surface, &surfaceFormatCount, surfaceFormats);
|
||||
|
||||
// TODO Add format picking logic
|
||||
// TODO Add format picking logic
|
||||
swapChain.surfaceFormat = surfaceFormats[0];
|
||||
|
||||
u32 buffering = min(max(createInfo.imageCount, surfaceCaps.minImageCount), surfaceCaps.maxImageCount);
|
||||
@@ -56,7 +56,7 @@ evkSwapChain evkCreateSwapChain(evkSwapChainCreateInfo createInfo)
|
||||
.oldSwapchain = VK_NULL_HANDLE,
|
||||
};
|
||||
|
||||
EVK_ASSERT(vkCreateSwapchainKHR(createInfo.device.vk, &swapChainCreateInfo, NULL, &swapChain.vk));
|
||||
EVK_CHECK(vkCreateSwapchainKHR(createInfo.device.vk, &swapChainCreateInfo, NULL, &swapChain.vk));
|
||||
|
||||
vkGetSwapchainImagesKHR(createInfo.device.vk, swapChain.vk, &buffering, NULL);
|
||||
VkImage swapChainVkImages[buffering];
|
||||
@@ -69,9 +69,9 @@ evkSwapChain evkCreateSwapChain(evkSwapChainCreateInfo createInfo)
|
||||
for(u32 i = 0; i < buffering; i++)
|
||||
{
|
||||
swapChain.images[i] = (evkImage) {
|
||||
.vk = swapChainVkImages[i],
|
||||
.width = imageExtent.width,
|
||||
.height = imageExtent.height,
|
||||
.vk = swapChainVkImages[i],
|
||||
.width = imageExtent.width,
|
||||
.height = imageExtent.height,
|
||||
.format = swapChain.surfaceFormat.format
|
||||
};
|
||||
swapChain.imageViews[i] = evkCreateImageView(createInfo.device, swapChain.images[i],
|
||||
@@ -94,4 +94,4 @@ void evkDestroySwapChain(evkDevice device, evkSwapChain swapChain)
|
||||
vec_fini(&swapChain.imageViews);
|
||||
vec_fini(&swapChain.images);
|
||||
vkDestroySwapchainKHR(device.vk, swapChain.vk, NULL);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,16 @@
|
||||
|
||||
evstring PROJECT_NAME = evstr("basic_triangle");
|
||||
|
||||
int main(void)
|
||||
char vertexShaderBytes[] = {
|
||||
#embed "shaders/basic_triangle.vert"
|
||||
,'\0'
|
||||
};
|
||||
char fragmentShaderBytes[] = {
|
||||
#embed "shaders/basic_triangle.frag"
|
||||
,'\0'
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
u32 width = 1280;
|
||||
u32 height = 800;
|
||||
@@ -82,7 +91,7 @@ int main(void)
|
||||
}
|
||||
|
||||
VkSurfaceKHR surface;
|
||||
VkResult err = glfwCreateWindowSurface(instance.vk, window, NULL, &surface);
|
||||
VkResult err = EVK_CHECK(glfwCreateWindowSurface(instance.vk, window, NULL, &surface));
|
||||
if (err)
|
||||
{
|
||||
ev_log_error("Surface creation failed.");
|
||||
@@ -99,8 +108,8 @@ int main(void)
|
||||
.imageCount = 3,
|
||||
});
|
||||
|
||||
evkCommandPool commandPool = evkCreateCommandPool((evkCommandPoolCreateInfo) {
|
||||
.device = device,
|
||||
evkCommandPool commandPool = evkCreateCommandPool((evkCommandPoolCreateInfo) {
|
||||
.device = device,
|
||||
.queueFlags = VK_QUEUE_GRAPHICS_BIT,
|
||||
.poolFlags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT
|
||||
});
|
||||
@@ -109,9 +118,15 @@ int main(void)
|
||||
|
||||
evkShaderCompiler compiler = evkCreateShaderCompiler();
|
||||
|
||||
evkShader vertShader = evkInitShaderFromFile(device, compiler, "shaders/basic_triangle.vert");
|
||||
evkShader fragShader = evkInitShaderFromFile(device, compiler, "shaders/basic_triangle.frag");
|
||||
|
||||
evstring vertexShaderText = evstring_new(vertexShaderBytes);
|
||||
evstring fragmentShaderText = evstring_new(fragmentShaderBytes);
|
||||
|
||||
evkShader vertShader = evkInitShaderFromString(device, compiler, evstr("basic_triangle.vert"),vertexShaderText);
|
||||
evkShader fragShader = evkInitShaderFromString(device, compiler, evstr("basic_triangle.frag"), fragmentShaderText);
|
||||
|
||||
evstring_free(vertexShaderText);
|
||||
evstring_free(fragmentShaderText);
|
||||
|
||||
evkDestroyShaderCompiler(compiler);
|
||||
|
||||
evkColorAttachment colorAttachment0 = {
|
||||
@@ -122,25 +137,26 @@ int main(void)
|
||||
// TODO Get this from shader reflection data
|
||||
// evkDescriptorSetLayout setLayout_0 = evkCreateDescriptorSetLayout(
|
||||
// &device, svec_init(evkDescriptorBinding, {
|
||||
// {
|
||||
// .name = evstr("positions"),
|
||||
// .binding = 0,
|
||||
// .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
// .descriptorCount = 1,
|
||||
// .stageFlags = VK_SHADER_STAGE_ALL_GRAPHICS,
|
||||
// {
|
||||
// .name = evstr("positions"),
|
||||
// .binding = 0,
|
||||
// .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
// .descriptorCount = 1,
|
||||
// .stageFlags = VK_SHADER_STAGE_ALL_GRAPHICS,
|
||||
// },
|
||||
// })
|
||||
// );
|
||||
// evkDescriptorSetLayout setLayout_0 = evkCreateDescriptorSetLayoutFromBindings(&device, vertShader.reflect.bindings);
|
||||
|
||||
evkDescriptorSetLayout setLayout_0 = evkCreateDescriptorSetLayoutFromShaders(&device, svec_init(evkShader, {vertShader, fragShader}));
|
||||
|
||||
evkPipelineCreateInfo pipelineCreateInfo = EV_DEFAULT(evkPipelineCreateInfo,
|
||||
dynamicStates = svec_init(VkDynamicState, {
|
||||
VK_DYNAMIC_STATE_VIEWPORT,
|
||||
dynamicStates = svec_init(VkDynamicState, {
|
||||
VK_DYNAMIC_STATE_VIEWPORT,
|
||||
VK_DYNAMIC_STATE_SCISSOR,
|
||||
}),
|
||||
shaderStages = svec_init(evkShader, {
|
||||
vertShader,
|
||||
vertShader,
|
||||
fragShader,
|
||||
}),
|
||||
colorAttachments = svec_init(evkColorAttachment, {
|
||||
@@ -158,8 +174,8 @@ int main(void)
|
||||
);
|
||||
|
||||
evkDescriptorSet set_0 = evkCreateDescriptorSet(&(evkDescriptorSetCreateInfo){
|
||||
.device = &device,
|
||||
.allocator = &allocator,
|
||||
.device = &device,
|
||||
.allocator = &allocator,
|
||||
.layout = &setLayout_0
|
||||
});
|
||||
|
||||
@@ -228,7 +244,7 @@ int main(void)
|
||||
{
|
||||
imageIdx = (imageIdx + 1) % imageCount;
|
||||
u32 swapChainImageIdx;
|
||||
EVK_ASSERT(vkAcquireNextImageKHR(device.vk, swapChain.vk, UInt64.MAX, imageAcquiredSemaphores[imageIdx], VK_NULL_HANDLE, &swapChainImageIdx));
|
||||
EVK_CHECK(vkAcquireNextImageKHR(device.vk, swapChain.vk, UInt64.MAX, imageAcquiredSemaphores[imageIdx], VK_NULL_HANDLE, &swapChainImageIdx));
|
||||
|
||||
evkCommandBuffer cmdbuf = commandBuffers[imageIdx];
|
||||
|
||||
@@ -269,6 +285,7 @@ int main(void)
|
||||
|
||||
evkCmdImageBarrier(&cmdbuf, EV_DEFAULT(VkImageMemoryBarrier,
|
||||
image = swapChain.images[swapChainImageIdx].vk,
|
||||
oldLayout = VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR,
|
||||
newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT
|
||||
));
|
||||
@@ -321,6 +338,9 @@ int main(void)
|
||||
|
||||
evkDestroyPipeline(graphicsPipeline);
|
||||
|
||||
evkDestroyBuffer(vertBuf);
|
||||
evkDestroyBuffer(uniBuf);
|
||||
|
||||
evkDestroyDescriptorSet(&device, &set_0);
|
||||
evkDestroyDescriptorSetLayout(&device, &setLayout_0);
|
||||
|
||||
@@ -330,6 +350,8 @@ int main(void)
|
||||
evkFreeCommandBuffers(device, commandPool, commandBuffers);
|
||||
evkDestroyCommandPool(device, commandPool);
|
||||
|
||||
evkGPUDestroyAllocator(allocator);
|
||||
|
||||
evkDestroySwapChain(device, swapChain);
|
||||
|
||||
// SwapchainCreationFailed:
|
||||
@@ -346,4 +368,4 @@ DeviceCreationFailed:
|
||||
evkDestroyInstance(instance);
|
||||
InstanceCreationFailed:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#version 450
|
||||
#pragma shader_stage(vertex)
|
||||
|
||||
// in layout(location=0) vec2 position;
|
||||
in layout(location=0) vec2 position;
|
||||
|
||||
layout(set=0, binding=0) uniform data {
|
||||
vec4 positions[3];
|
||||
@@ -12,4 +12,5 @@ void main() {
|
||||
// gl_Position = vec4(position, 0.0, 1.0);
|
||||
// gl_Position = vec4(inputData.positions[gl_VertexIndex], 0.0, 1.0);
|
||||
gl_Position = vertexData.positions[gl_VertexIndex];
|
||||
}
|
||||
// gl_Position = vec4(position, 0.0, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user