return sm;
}
+static void
+create_vertex_descriptions(struct vk_ctx *ctx,
+ struct vk_geometry *geometry,
+ int num_bind_dsc,
+ VkVertexInputBindingDescription *bind_dsc,
+ int num_att_dsc,
+ VkVertexInputAttributeDescription *att_dsc)
+{
+ VkFormat format;
+ VkFormatProperties fmt_props;
+ uint32_t stride;
+
+ assert(num_bind_dsc == num_att_dsc);
+
+ memset(bind_dsc, 0, num_bind_dsc * sizeof bind_dsc[0]);
+ memset(att_dsc, 0, num_att_dsc * sizeof att_dsc[0]);
+
+ /* FIXME!!! format and stride!!
+ * We have 3D Vectors so we need an RGB format:
+ * R for x, G for y, B for z
+ * If we need to set the w we need an RGBA format!
+ * the stride (distance between 2 consecutive elements
+ * must be 8 as we use 32bits floats and 32bits = 8bytes
+ */
+ format = VK_FORMAT_R32G32B32_SFLOAT;
+ vkGetPhysicalDeviceFormatProperties(ctx->pdev, format, &fmt_props);
+ assert(fmt_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT);
+ stride = 8;
+
+ /* Assumming that:
+ * 0 = vertices
+ * 1 = indices
+ * 2 = normals
+ * 3 = tangets
+ */
+
+ if (geometry->vertices.num_vertices) {
+ att_dsc[0].location = VERTEX_LOC;
+ att_dsc[0].binding = VERTEX_BIND;
+ att_dsc[0].format = format;
+ att_dsc[0].offset = 0;
+
+ bind_dsc[0].binding = VERTEX_BIND;
+ bind_dsc[0].stride = stride;
+ bind_dsc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
+ }
+
+ if (geometry->indices.num_vertices) {
+ }
+
+ if (geometry->normals.num_vertices) {
+ }
+
+ if (geometry->tangents.num_vertices) {
+ }
+}
+
static bool
create_graphics_pipeline(struct vk_ctx *ctx,
uint32_t width,
bool enable_stencil,
struct vk_renderer *renderer)
{
- VkVertexInputBindingDescription vert_bind_dsc[1];
- VkVertexInputAttributeDescription vert_att_dsc[1];
+ VkVertexInputBindingDescription vert_bind_dsc[4];
+ VkVertexInputAttributeDescription vert_att_dsc[4];
VkPipelineColorBlendAttachmentState *cb_att_state;
VkPipelineVertexInputStateCreateInfo vert_input_info;
VkPipelineLayout pipeline_layout;
uint32_t stride;
+ /* FIXME */
/* format of vertex attributes:
* we have 2D vectors so we need a RG format:
* R for x, G for y
assert(fmt_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT);
stride = 8;
+ // create_vertex_descriptions(ctx, renderer->geometry, 1, vert_bind_dsc, 1, vert_att_dsc);
+ memset(vert_att_dsc, 0, 4 * sizeof vert_att_dsc[0]);
+ memset(vert_bind_dsc, 0, 4 * sizeof vert_bind_dsc[0]);
+
/* VkVertexInputAttributeDescription */
- memset(&vert_att_dsc, 0, sizeof vert_att_dsc);
vert_att_dsc[0].location = 0;
vert_att_dsc[0].binding = 0;
vert_att_dsc[0].format = format; /* see comment */
vert_att_dsc[0].offset = 0;
/* VkVertexInputBindingDescription */
- memset(&vert_bind_dsc, 0, sizeof vert_bind_dsc);
vert_bind_dsc[0].binding = 0;
vert_bind_dsc[0].stride = stride;
vert_bind_dsc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
/* If using vbo, we have setup vertex_info in the renderer. */
- bool use_vbo = renderer->vertex_info.num_verts > 0;
+ bool has_geometry = renderer->geometry;
/* VkPipelineVertexInputStateCreateInfo */
memset(&vert_input_info, 0, sizeof vert_input_info);
vert_input_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
- vert_input_info.vertexBindingDescriptionCount = use_vbo ? 1 : 0;
+ vert_input_info.vertexBindingDescriptionCount = renderer->geometry ? 1 : 0;
vert_input_info.pVertexBindingDescriptions = vert_bind_dsc;
- vert_input_info.vertexAttributeDescriptionCount = use_vbo ? 1 : 0;
+ vert_input_info.vertexAttributeDescriptionCount = renderer->geometry ? 1 : 0;
vert_input_info.pVertexAttributeDescriptions = vert_att_dsc;
/* VkPipelineInputAssemblyStateCreateInfo */
memset(&asm_info, 0, sizeof asm_info);
asm_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
- asm_info.topology = renderer->vertex_info.topology ?
- renderer->vertex_info.topology
+ asm_info.topology = has_geometry ?
+ renderer->geometry->topo
: VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
asm_info.primitiveRestartEnable = false;
int num_color_att,
struct vk_att_props *color_props,
struct vk_att_props *depth_props,
- struct vk_vertex_info *vert_info,
+ struct vk_geometry *geometry,
struct vk_renderer *renderer)
{
/* create image views for each attachment */
goto fail;
renderer->fs = fs;
- if (vert_info)
- renderer->vertex_info = *vert_info;
-
+ if (geometry)
+ renderer->geometry = geometry;
/* FIXME this is only for graphics atm */
if(!create_graphics_pipeline(ctx, w, h,
vk_record_cmd_buffer(struct vk_ctx *ctx,
VkCommandBuffer cmd_buf,
struct vk_renderer *renderer,
- struct vk_buf *vbo,
uint32_t vk_fb_color_count,
float *vk_fb_color,
VkFramebuffer fb,
VkRect2D rp_area;
VkClearValue *clear_values; int i;
VkDeviceSize offsets[] = {0};
- int num_vertices;
+ int num_vertices = 0;
struct vk_dims img_size;
bool create_cmd_buf = false;
+ bool has_geometry = renderer->geometry != 0;
assert(vk_fb_color_count == 4);
0, sizeof (struct vk_dims),
&img_size);
- if (vbo) {
- vkCmdBindVertexBuffers(cmd_buf, 0, 1, &vbo->buf, offsets);
+ if (has_geometry && renderer->geometry->vertices.num_vertices > 0) {
+ num_vertices = renderer->geometry->vertices.num_vertices;
+ vkCmdBindVertexBuffers(cmd_buf, 0, 1, &renderer->geometry->vertices.vbo, offsets);
}
vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS,
renderer->pipeline);
- num_vertices = vbo ? renderer->vertex_info.num_verts : 4;
+ /* FIXME: temporal hack because I hard code 4 vertices in the
+ * vertex shader until I properly support VBOs */
+ if (!num_vertices)
+ num_vertices = 4;
+
vkCmdDraw(cmd_buf, num_vertices, 1, 0, 0);
vkCmdEndRenderPass(cmd_buf);