Multiple changes to get a triangle working with hacky usage of descriptor heaps
Test Compilation / Build evk (push) Has been cancelled

This commit is contained in:
2026-05-13 22:07:01 +03:00
parent 283c937b10
commit be3d1d21e7
16 changed files with 120 additions and 99 deletions
+41 -40
View File
@@ -62,7 +62,10 @@ int main(void)
evstr("VK_KHR_synchronization2"),
evstr("VK_KHR_buffer_device_address"),
evstr("VK_EXT_descriptor_indexing"),
evstr("VK_EXT_descriptor_buffer"),
evstr("VK_KHR_maintenance5"),
evstr("VK_EXT_descriptor_heap"),
evstr(VK_EXT_SHADER_OBJECT_EXTENSION_NAME),
evstr(VK_KHR_SHADER_UNTYPED_POINTERS_EXTENSION_NAME),
}),
});
@@ -121,8 +124,8 @@ int main(void)
evstring vertexShaderText = evstring_new(vertexShaderBytes);
evstring fragmentShaderText = evstring_new(fragmentShaderBytes);
evkShader vertShader = evkInitShaderFromString(device, compiler, evstr("heap_triangle.vert"),vertexShaderText);
evkShader fragShader = evkInitShaderFromString(device, compiler, evstr("heap_triangle.frag"), fragmentShaderText);
evkShader vertShader = evkInitShaderFromString(device, compiler, evstr("heap_triangle.vert"),vertexShaderText, VK_SHADER_STAGE_VERTEX_BIT);
evkShader fragShader = evkInitShaderFromString(device, compiler, evstr("heap_triangle.frag"), fragmentShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
evstring_free(vertexShaderText);
evstring_free(fragmentShaderText);
@@ -148,7 +151,7 @@ int main(void)
// );
// evkDescriptorSetLayout setLayout_0 = evkCreateDescriptorSetLayoutFromBindings(&device, vertShader.reflect.bindings);
evkDescriptorSetLayout setLayout_0 = evkCreateDescriptorSetLayoutFromShaders(&device, svec_init(evkShader, {vertShader, fragShader}));
// evkDescriptorSetLayout setLayout_0 = evkCreateDescriptorSetLayoutFromShaders(&device, svec_init(evkShader, {vertShader, fragShader}));
evkPipelineCreateInfo pipelineCreateInfo = EV_DEFAULT(evkPipelineCreateInfo,
dynamicStates = svec_init(VkDynamicState, {
@@ -170,35 +173,20 @@ int main(void)
}},
}),
setLayouts = svec_init(evkDescriptorSetLayout, {setLayout_0}),
// setLayouts = svec_init(evkDescriptorSetLayout, {setLayout_0}),
);
evkDescriptorSet set_0 = evkCreateDescriptorSet(&(evkDescriptorSetCreateInfo){
.device = &device,
.allocator = &allocator,
.layout = &setLayout_0
});
// // if stageflags is 0, it's all graphics
// // if descriptor count is 0, it's 1
// // if
// evkDescriptorSetLayout set_0 = evkCreateDescriptorSetLayout(&device, svec_init(evkDescriptorBinding, {
// { "positions", VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER },
// })
// );
evkBuffer vertBuf = evkCreateBuffer(&device, (evkBufferCreateInfo) {
.queueFamilyIndices = svec_init(u32, {device.queueFamilies[VK_QUEUE_GRAPHICS_BIT].familyIndex}),
.sizeInBytes = 6 * 4,
.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
.allocationCreateInfo = {
.allocationFlags = EVK_GPU_ALLOCATION_CREATE_MAPPED_BIT | EVK_GPU_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.allocator = allocator,
},
evkBuffer resourceDescriptorHeap = evkCreateBuffer(&device, (evkBufferCreateInfo) {
.sizeInBytes = 16 * 4, // bufferDescriptorSize is 16 on my current device
.usage = VK_BUFFER_USAGE_DESCRIPTOR_HEAP_BIT_EXT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
.exclusive = true,
.allocationCreateInfo = {
.allocationFlags = EVK_GPU_ALLOCATION_CREATE_MAPPED_BIT | EVK_GPU_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.allocator = allocator,
}
});
evkBuffer uniBuf = evkCreateBuffer(&device, (evkBufferCreateInfo) {
.sizeInBytes = 12 * 4,
.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
@@ -209,17 +197,25 @@ int main(void)
.exclusive = true,
});
float* vert_arr = (float*)vertBuf.allocData.allocationInfo.vma.pMappedData;
vert_arr[0] = 0.0f; vert_arr[1] = -0.5f;
vert_arr[2] = 0.5f; vert_arr[3] = 0.5f;
vert_arr[4] = -0.5f; vert_arr[5] = 0.5f;
float* uni_arr = (float*)uniBuf.allocData.allocationInfo.vma.pMappedData;
uni_arr[0] = 0.0f; uni_arr[1] = -0.5f; uni_arr[2] = 0.0f; uni_arr[3] = 1.0f;
uni_arr[4] = 0.5f; uni_arr[5] = 0.5f; uni_arr[6] = 0.0f; uni_arr[7] = 1.0f;
uni_arr[8] = -0.5f; uni_arr[9] = 0.5f; uni_arr[10] = 0.0f; uni_arr[11] = 1.0f;
evkSetDescriptor(&set_0, evstr("vertexData"), &uniBuf);
// evkSetDescriptor(&set_0, evstr("vertexData"), &uniBuf);
VkResourceDescriptorInfoEXT resource = {
.sType = VK_STRUCTURE_TYPE_RESOURCE_DESCRIPTOR_INFO_EXT,
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.data.pAddressRange = &uniBuf.addressRange
};
VkHostAddressRangeEXT descriptor = {
.address = resourceDescriptorHeap.allocData.allocationInfo.vma.pMappedData,
.size = 16
};
vkWriteResourceDescriptorsEXT(device.vk, 1, &resource, &descriptor);
VkViewport viewport = EV_DEFAULT(VkViewport, width=width, height=height);
VkRect2D scissor = EV_DEFAULT(VkRect2D,extent.width=width, extent.height=height);
@@ -268,14 +264,19 @@ int main(void)
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT
));
VkDeviceSize offset = 0;
vkCmdBindVertexBuffers(cmdbuf.vk, 0, 1, &vertBuf.vk, &offset);
// VkDeviceSize offset = 0;
// vkCmdBindVertexBuffers(cmdbuf.vk, 0, 1, &vertBuf.vk, &offset);
evkCmdBindDescriptorSets(&cmdbuf, &graphicsPipeline, svec_init(evkDescriptorSet, { set_0 }), svec_init(u32, { 0 }));
// evkCmdBindDescriptorSets(&cmdbuf, &graphicsPipeline, svec_init(evkDescriptorSet, { set_0 }), svec_init(u32, { 0 }));
vkCmdSetScissor(cmdbuf.vk, 0, 1, &scissor);
vkCmdSetViewport(cmdbuf.vk, 0, 1, &viewport);
vkCmdBindResourceHeapEXT(cmdbuf.vk, &(VkBindHeapInfoEXT) {
.sType = VK_STRUCTURE_TYPE_BIND_HEAP_INFO_EXT,
.heapRange = resourceDescriptorHeap.addressRange,
});
vkCmdBeginRenderingKHR(cmdbuf.vk, &renderingInfo);
evkCmdBindPipeline(&cmdbuf, &graphicsPipeline);
@@ -338,11 +339,11 @@ int main(void)
evkDestroyPipeline(graphicsPipeline);
evkDestroyBuffer(vertBuf);
// evkDestroyBuffer(vertBuf);
evkDestroyBuffer(uniBuf);
evkDestroyDescriptorSet(&device, &set_0);
evkDestroyDescriptorSetLayout(&device, &setLayout_0);
// evkDestroyDescriptorSet(&device, &set_0);
// evkDestroyDescriptorSetLayout(&device, &setLayout_0);
evkDestroyShader(device, vertShader);
evkDestroyShader(device, fragShader);
@@ -1,9 +1,10 @@
#version 450
#pragma shader_stage(fragment)
#extension GL_EXT_descriptor_heap: require
layout(location = 0) out vec4 outColor;
void main() {
outColor = vec4(0.f, 1.f, 0.f, 1.f);
}
}
@@ -1,16 +1,12 @@
#version 450
#pragma shader_stage(vertex)
in layout(location=0) vec2 position;
#extension GL_EXT_descriptor_heap: require
layout(set=0, binding=0) uniform data {
layout(descriptor_heap) uniform data {
vec4 positions[3];
} vertexData;
} vertexData[];
void main() {
// gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
// 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);
gl_Position = vertexData[0].positions[gl_VertexIndex];
}
+1 -1
View File
@@ -1,2 +1,2 @@
subdir('basic_triangle')
# subdir('basic_triangle')
subdir('descriptor_heap')