#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 VkPipelineColorBlendStateCreateInfo *cb_state,
+ 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 };
- VkShader vs_h;
- ANV_CALL(CreateShader)(device_h,
- &(VkShaderCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO,
- .module = anv_shader_module_to_handle(&vs_m),
- .pName = "main",
- },
- &vs_h);
-
- VkShader fs_h;
- ANV_CALL(CreateShader)(device_h,
- &(VkShaderCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO,
- .module = anv_shader_module_to_handle(&fs_m),
- .pName = "main",
- },
- &fs_h);
-
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,
.pStages = (VkPipelineShaderStageCreateInfo[]) {
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
- .stage = VK_SHADER_STAGE_VERTEX,
- .shader = vs_h,
+ .stage = VK_SHADER_STAGE_VERTEX_BIT,
+ .module = anv_shader_module_to_handle(&vs_m),
+ .pName = "main",
},
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
- .stage = VK_SHADER_STAGE_FRAGMENT,
- .shader = fs_h,
+ .stage = VK_SHADER_STAGE_FRAGMENT_BIT,
+ .module = anv_shader_module_to_handle(&fs_m),
+ .pName = "main",
},
},
.pVertexInputState = vi_state,
.scissorCount = 1,
.pScissors = NULL, /* dynamic */
},
- .pRasterState = &(VkPipelineRasterStateCreateInfo) {
- .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO,
- .depthClipEnable = false,
+ .pRasterizationState = &(VkPipelineRasterizationStateCreateInfo) {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
.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,
- .rasterSamples = 1, /* FINISHME: Multisampling */
+ .rasterizationSamples = 1, /* FINISHME: Multisampling */
.sampleShadingEnable = false,
.pSampleMask = (VkSampleMask[]) { UINT32_MAX },
.alphaToCoverageEnable = false,
.disable_vs = true,
.use_rectlist = true
},
+ alloc,
&pipeline_h);
- ANV_CALL(DestroyShader)(device_h, vs_h);
- ANV_CALL(DestroyShader)(device_h, fs_h);
-
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;
.pAttachments = (VkPipelineColorBlendAttachmentState []) {
{
.blendEnable = false,
- .channelWriteMask = VK_CHANNEL_A_BIT |
- VK_CHANNEL_R_BIT |
- VK_CHANNEL_G_BIT |
- VK_CHANNEL_B_BIT,
+ .colorWriteMask = VK_COLOR_COMPONENT_A_BIT |
+ VK_COLOR_COMPONENT_R_BIT |
+ VK_COLOR_COMPONENT_G_BIT |
+ VK_COLOR_COMPONENT_B_BIT,
},
},
};
- device->meta_state.clear.color_pipeline =
+ return
create_pipeline(device, vs_nir, fs_nir, &vi_state, &ds_state,
- &cb_state);
+ &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,
ANV_CALL(CmdSetViewport)(cmd_buffer_h, 1,
(VkViewport[]) {
{
- .originX = 0,
- .originY = 0,
+ .x = 0,
+ .y = 0,
.width = fb->width,
.height = fb->height,
.minDepth = 0.0,
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);
+ &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(CmdSetViewport)(cmd_buffer_h, 1,
(VkViewport[]) {
{
- .originX = 0,
- .originY = 0,
+ .x = 0,
+ .y = 0,
.width = fb->width,
.height = fb->height,
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
VkDevice device_h = anv_device_to_handle(device);
ANV_CALL(DestroyPipeline)(device_h,
- anv_pipeline_to_handle(device->meta_state.clear.color_pipeline));
+ anv_pipeline_to_handle(device->meta_state.clear.color_pipeline),
+ NULL);
ANV_CALL(DestroyPipeline)(device_h,
- anv_pipeline_to_handle(device->meta_state.clear.depth_only_pipeline));
+ anv_pipeline_to_handle(device->meta_state.clear.depth_only_pipeline),
+ NULL);
ANV_CALL(DestroyPipeline)(device_h,
- anv_pipeline_to_handle(device->meta_state.clear.stencil_only_pipeline));
+ anv_pipeline_to_handle(device->meta_state.clear.stencil_only_pipeline),
+ NULL);
ANV_CALL(DestroyPipeline)(device_h,
- anv_pipeline_to_handle(device->meta_state.clear.depthstencil_pipeline));
+ anv_pipeline_to_handle(device->meta_state.clear.depthstencil_pipeline),
+ NULL);
}
void
meta_clear_begin(&saved_state, cmd_buffer);
for (uint32_t r = 0; r < rangeCount; r++) {
- for (uint32_t l = 0; l < pRanges[r].mipLevels; l++) {
- for (uint32_t s = 0; s < pRanges[r].arraySize; s++) {
+ for (uint32_t l = 0; l < pRanges[r].levelCount; l++) {
+ for (uint32_t s = 0; s < pRanges[r].layerCount; s++) {
struct anv_image_view iview;
anv_image_view_init(&iview, cmd_buffer->device,
&(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,
- .mipLevels = 1,
+ .levelCount = 1,
.baseArrayLayer = pRanges[r].baseArrayLayer + s,
- .arraySize = 1
+ .layerCount = 1
},
},
cmd_buffer);
.width = iview.extent.width,
.height = iview.extent.height,
.layers = 1
- }, &fb);
+ }, &cmd_buffer->pool->alloc, &fb);
VkRenderPass pass;
anv_CreateRenderPass(anv_device_to_handle(cmd_buffer->device),
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
.attachmentCount = 1,
.pAttachments = &(VkAttachmentDescription) {
- .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION,
- .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,
},
.subpassCount = 1,
.pSubpasses = &(VkSubpassDescription) {
- .sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION,
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
- .inputCount = 0,
- .colorCount = 1,
+ .inputAttachmentCount = 0,
+ .colorAttachmentCount = 1,
.pColorAttachments = &(VkAttachmentReference) {
.attachment = 0,
.layout = VK_IMAGE_LAYOUT_GENERAL,
},
.pResolveAttachments = NULL,
- .depthStencilAttachment = (VkAttachmentReference) {
+ .pDepthStencilAttachment = &(VkAttachmentReference) {
.attachment = VK_ATTACHMENT_UNUSED,
.layout = VK_IMAGE_LAYOUT_GENERAL,
},
- .preserveCount = 1,
+ .preserveAttachmentCount = 1,
.pPreserveAttachments = &(VkAttachmentReference) {
.attachment = 0,
.layout = VK_IMAGE_LAYOUT_GENERAL,
},
},
.dependencyCount = 0,
- }, &pass);
+ }, &cmd_buffer->pool->alloc, &pass);
ANV_CALL(CmdBeginRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer),
&(VkRenderPassBeginInfo) {
}, VK_SUBPASS_CONTENTS_INLINE);
ANV_CALL(CmdEndRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer));
+
+ /* XXX: We're leaking the render pass and framebuffer */
}
}
}