diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c index 442cbf70b27..ca215af274a 100644 --- a/src/broadcom/vulkan/v3dv_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c @@ -1560,8 +1560,8 @@ cmd_buffer_emit_graphics_pipeline(struct v3dv_cmd_buffer *cmd_buffer) shader.vertex_shader_uniforms_address = vs_uniforms; shader.fragment_shader_uniforms_address = fs_uniforms; - /* FIXME: pending */ - /* shader.address_of_default_attribute_values = */ + shader.address_of_default_attribute_values = + v3dv_cl_address(pipeline->default_attribute_values, 0); } /* Upload vertex element attributes (SHADER_STATE_ATTRIBUTE_RECORD) */ diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index 98bb6c554dc..43b66eea0b7 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -104,6 +104,11 @@ v3dv_DestroyPipeline(VkDevice _device, destroy_pipeline_stage(device, pipeline->vs_bin, pAllocator); destroy_pipeline_stage(device, pipeline->fs, pAllocator); + if (pipeline->default_attribute_values) { + v3dv_bo_free(device, pipeline->default_attribute_values); + pipeline->default_attribute_values = NULL; + } + vk_free2(&device->alloc, pAllocator, pipeline); } @@ -1034,6 +1039,44 @@ get_attr_type(const struct util_format_description *desc) return attr_type; } +static void +create_default_attribute_values(struct v3dv_pipeline *pipeline, + const VkPipelineVertexInputStateCreateInfo *vi_info) +{ + uint32_t size = MAX_VERTEX_ATTRIBS * sizeof(float) * 4; + + if (pipeline->default_attribute_values == NULL) { + pipeline->default_attribute_values = v3dv_bo_alloc(pipeline->device, size); + + if (!pipeline->default_attribute_values) { + fprintf(stderr, "failed to allocate memory for the default " + "attribute values\n"); + } + } + + bool ok = v3dv_bo_map(pipeline->device, + pipeline->default_attribute_values, size); + if (!ok) { + fprintf(stderr, "failed to map default attribute values buffer\n"); + abort(); + } + + uint32_t *attrs = pipeline->default_attribute_values->map; + + for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) { + attrs[i * 4 + 0] = 0; + attrs[i * 4 + 1] = 0; + attrs[i * 4 + 2] = 0; + if (i < pipeline->va_count && vk_format_is_int(pipeline->va[i].vk_format)) { + attrs[i * 4 + 3] = 1; + } else { + attrs[i * 4 + 3] = fui(1.0); + } + } + + v3dv_bo_unmap(pipeline->device, pipeline->default_attribute_values); +} + static void pack_shader_state_attribute_record(struct v3dv_pipeline *pipeline, uint32_t index, @@ -1137,12 +1180,14 @@ pipeline_init(struct v3dv_pipeline *pipeline, pipeline->va[pipeline->va_count].offset = desc->offset; pipeline->va[pipeline->va_count].binding = desc->binding; pipeline->va[pipeline->va_count].driver_location = driver_location; + pipeline->va[pipeline->va_count].vk_format = desc->format; pack_shader_state_attribute_record(pipeline, pipeline->va_count, desc); pipeline->va_count++; } } + create_default_attribute_values(pipeline, vi_info); return result; } diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index 7c66b4bb51e..4d8495fce3b 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -668,9 +668,15 @@ struct v3dv_pipeline { * are indexed by driver_location */ uint32_t driver_location; + VkFormat vk_format; } va[MAX_VERTEX_ATTRIBS]; uint32_t va_count; + /* FIXME: this bo is another candidate to data to be uploaded using a + * resource manager, instead of a individual bo + */ + struct v3dv_bo *default_attribute_values; + struct vpm_config vpm_cfg; struct vpm_config vpm_cfg_bin; /* Packets prepacked during pipeline creation diff --git a/src/broadcom/vulkan/vk_format_info.h b/src/broadcom/vulkan/vk_format_info.h index 0969c025d54..fee432d9a85 100644 --- a/src/broadcom/vulkan/vk_format_info.h +++ b/src/broadcom/vulkan/vk_format_info.h @@ -88,6 +88,13 @@ vk_format_is_color(VkFormat format) return vk_format_aspects(format) == VK_IMAGE_ASPECT_COLOR_BIT; } +/* FIXME: from freedreno vk_format.h, common place?*/ +static inline bool +vk_format_is_int(VkFormat format) +{ + return util_format_is_pure_integer(vk_format_to_pipe_format(format)); +} + static inline bool vk_format_is_depth_or_stencil(VkFormat format) {