#include "anv_meta.h"
#include "anv_meta_clear.h"
-#include "anv_nir_builder.h"
#include "anv_private.h"
+#include "glsl/nir/nir_builder.h"
/** Vertex attributes for color clears. */
struct color_clear_vattrs {
nir_builder vs_b;
nir_builder fs_b;
- nir_builder_init_simple_shader(&vs_b, MESA_SHADER_VERTEX);
- nir_builder_init_simple_shader(&fs_b, MESA_SHADER_FRAGMENT);
+ nir_builder_init_simple_shader(&vs_b, NULL, MESA_SHADER_VERTEX, NULL);
+ nir_builder_init_simple_shader(&fs_b, NULL, MESA_SHADER_FRAGMENT, NULL);
const struct glsl_type *position_type = glsl_vec4_type();
const struct glsl_type *color_type = glsl_vec4_type();
*out_fs = fs_b.shader;
}
-static struct anv_pipeline *
+static VkResult
create_pipeline(struct anv_device *device,
struct nir_shader *vs_nir,
struct nir_shader *fs_nir,
const VkPipelineVertexInputStateCreateInfo *vi_state,
const VkPipelineDepthStencilStateCreateInfo *ds_state,
const VkPipelineColorBlendStateCreateInfo *cb_state,
- const VkAllocationCallbacks *alloc)
+ const VkAllocationCallbacks *alloc,
+ struct anv_pipeline **pipeline)
{
VkDevice device_h = anv_device_to_handle(device);
+ VkResult result;
struct anv_shader_module vs_m = { .nir = vs_nir };
struct anv_shader_module fs_m = { .nir = fs_nir };
VkPipeline pipeline_h;
- anv_graphics_pipeline_create(device_h,
+ result = anv_graphics_pipeline_create(device_h,
+ VK_NULL_HANDLE,
&(VkGraphicsPipelineCreateInfo) {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.stageCount = 2,
},
.pRasterizationState = &(VkPipelineRasterizationStateCreateInfo) {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
- .depthClipEnable = false,
.rasterizerDiscardEnable = false,
.polygonMode = VK_POLYGON_MODE_FILL,
.cullMode = VK_CULL_MODE_NONE,
.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
.depthBiasEnable = false,
- .depthClipEnable = false,
},
.pMultisampleState = &(VkPipelineMultisampleStateCreateInfo) {
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
ralloc_free(vs_nir);
ralloc_free(fs_nir);
- return anv_pipeline_from_handle(pipeline_h);
+ *pipeline = anv_pipeline_from_handle(pipeline_h);
+
+ return result;
}
-static void
+static VkResult
init_color_pipeline(struct anv_device *device)
{
struct nir_shader *vs_nir;
},
};
- device->meta_state.clear.color_pipeline =
+ return
create_pipeline(device, vs_nir, fs_nir, &vi_state, &ds_state,
- &cb_state, NULL);
+ &cb_state, NULL,
+ &device->meta_state.clear.color_pipeline);
}
static void
};
struct anv_state state =
- anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, sizeof(vertex_data), 16);
- memcpy(state.map, vertex_data, sizeof(vertex_data));
+ anv_cmd_buffer_emit_dynamic(cmd_buffer, vertex_data, sizeof(vertex_data), 16);
struct anv_buffer vertex_buffer = {
.device = device,
nir_builder vs_b;
nir_builder fs_b;
- nir_builder_init_simple_shader(&vs_b, MESA_SHADER_VERTEX);
- nir_builder_init_simple_shader(&fs_b, MESA_SHADER_FRAGMENT);
+ nir_builder_init_simple_shader(&vs_b, NULL, MESA_SHADER_VERTEX, NULL);
+ nir_builder_init_simple_shader(&fs_b, NULL, MESA_SHADER_FRAGMENT, NULL);
const struct glsl_type *position_type = glsl_vec4_type();
*out_fs = fs_b.shader;
}
-static struct anv_pipeline *
+static VkResult
create_depthstencil_pipeline(struct anv_device *device,
- VkImageAspectFlags aspects)
+ VkImageAspectFlags aspects,
+ struct anv_pipeline **pipeline)
{
struct nir_shader *vs_nir;
struct nir_shader *fs_nir;
};
return create_pipeline(device, vs_nir, fs_nir, &vi_state, &ds_state,
- &cb_state, NULL);
+ &cb_state, NULL, pipeline);
}
static void
};
struct anv_state state =
- anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, sizeof(vertex_data), 16);
- memcpy(state.map, vertex_data, sizeof(vertex_data));
+ anv_cmd_buffer_emit_dynamic(cmd_buffer, vertex_data, sizeof(vertex_data), 16);
struct anv_buffer vertex_buffer = {
.device = device,
ANV_CALL(CmdDraw)(cmd_buffer_h, 3, 1, 0, 0);
}
-static void
+static VkResult
init_depthstencil_pipelines(struct anv_device *device)
{
- device->meta_state.clear.depth_only_pipeline =
- create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_DEPTH_BIT);
-
- device->meta_state.clear.stencil_only_pipeline =
- create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_STENCIL_BIT);
-
- device->meta_state.clear.depthstencil_pipeline =
- create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_DEPTH_BIT |
- VK_IMAGE_ASPECT_STENCIL_BIT);
+ VkResult result;
+ struct anv_meta_state *state = &device->meta_state;
+
+ result =
+ create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_DEPTH_BIT,
+ &state->clear.depth_only_pipeline);
+ if (result != VK_SUCCESS)
+ goto fail;
+
+ result =
+ create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_STENCIL_BIT,
+ &state->clear.stencil_only_pipeline);
+ if (result != VK_SUCCESS)
+ goto fail_depth_only;
+
+ result =
+ create_depthstencil_pipeline(device,
+ VK_IMAGE_ASPECT_DEPTH_BIT |
+ VK_IMAGE_ASPECT_STENCIL_BIT,
+ &state->clear.depthstencil_pipeline);
+ if (result != VK_SUCCESS)
+ goto fail_stencil_only;
+
+ return result;
+
+ fail_stencil_only:
+ anv_DestroyPipeline(anv_device_to_handle(device),
+ anv_pipeline_to_handle(state->clear.stencil_only_pipeline),
+ NULL);
+ fail_depth_only:
+ anv_DestroyPipeline(anv_device_to_handle(device),
+ anv_pipeline_to_handle(state->clear.depth_only_pipeline),
+ NULL);
+ fail:
+ return result;
}
-void
+VkResult
anv_device_init_meta_clear_state(struct anv_device *device)
{
- init_color_pipeline(device);
- init_depthstencil_pipelines(device);
+ VkResult result;
+
+ result = init_color_pipeline(device);
+ if (result != VK_SUCCESS)
+ goto fail;
+
+ result = init_depthstencil_pipelines(device);
+ if (result != VK_SUCCESS)
+ goto fail_color_pipeline;
+
+ return VK_SUCCESS;
+
+ fail_color_pipeline:
+ anv_DestroyPipeline(anv_device_to_handle(device),
+ anv_pipeline_to_handle(device->meta_state.clear.color_pipeline),
+ NULL);
+ fail:
+ return result;
}
void
&(VkImageViewCreateInfo) {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.image = _image,
- .viewType = VK_IMAGE_VIEW_TYPE_2D,
- .format = image->format->vk_format,
+ .viewType = anv_meta_get_view_type(image),
+ .format = image->vk_format,
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.baseMipLevel = pRanges[r].baseMipLevel + l,
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
.attachmentCount = 1,
.pAttachments = &(VkAttachmentDescription) {
- .format = iview.format->vk_format,
+ .format = iview.vk_format,
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
.initialLayout = VK_IMAGE_LAYOUT_GENERAL,