From: Bas Nieuwenhuizen <ba...@chromium.org> --- Makefile.am | 2 + .../vertex_attribute_divisor.c | 216 ++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 src/tests/func/vertex_attribute_divisor/vertex_attribute_divisor.c
diff --git a/Makefile.am b/Makefile.am index 7c4a52b..128a7e9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -106,6 +106,7 @@ bin_crucible_SOURCES = \ src/tests/func/ssbo/interleave.c \ src/tests/func/sync/semaphore-fd.c \ src/tests/func/renderpass/clear.c \ + src/tests/func/vertex_attribute_divisor/vertex_attribute_divisor.c \ src/tests/stress/lots-of-surface-state.c \ src/tests/stress/buffer_limit.c \ src/tests/self/concurrent-output.c \ @@ -151,6 +152,7 @@ BUILT_SOURCES = \ src/tests/func/shader_group_vote/ext_shader_subgroup_vote-spirv.h \ src/tests/func/ssbo/interleave-spirv.h \ src/tests/func/sync/semaphore-fd-spirv.h \ + src/tests/func/vertex_attribute_divisor/vertex_attribute_divisor-spirv.h \ src/tests/stress/lots-of-surface-state-spirv.h bin_crucible_LDADD = $(MESA_LDFLAGS) -lm -lvulkan -lpthread $(libpng_LIBS) \ diff --git a/src/tests/func/vertex_attribute_divisor/vertex_attribute_divisor.c b/src/tests/func/vertex_attribute_divisor/vertex_attribute_divisor.c new file mode 100644 index 0000000..42ddfd6 --- /dev/null +++ b/src/tests/func/vertex_attribute_divisor/vertex_attribute_divisor.c @@ -0,0 +1,216 @@ +// Copyright 2018 Google LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice (including the next +// paragraph) shall be included in all copies or substantial portions of the +// Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. + + +#include "util/simple_pipeline.h" +#include "tapi/t.h" +#include <math.h> + +#include "vertex_attribute_divisor-spirv.h" + +static void +vertex_attribute_divisor() +{ + t_require_ext("VK_EXT_vertex_attribute_divisor"); + + VkRenderPass pass = qoCreateRenderPass(t_device, + .attachmentCount = 1, + .pAttachments = (VkAttachmentDescription[]) { + { + QO_ATTACHMENT_DESCRIPTION_DEFAULTS, + .format = VK_FORMAT_R8G8B8A8_UNORM, + .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR, + }, + }, + .subpassCount = 1, + .pSubpasses = (VkSubpassDescription[]) { + { + QO_SUBPASS_DESCRIPTION_DEFAULTS, + .colorAttachmentCount = 1, + .pColorAttachments = (VkAttachmentReference[]) { + { + .attachment = 0, + .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + }, + }, + .preserveAttachmentCount = 1, + .pPreserveAttachments = (uint32_t[]) { 0 }, + } + }); + + VkShaderModule vs = qoCreateShaderModuleGLSL(t_device, VERTEX, + layout(location = 0) in vec4 a_position; + layout(location = 1) in uint attributes[7]; + layout(location = 0) out vec4 v_color; + void main() + { + gl_Position = vec4(a_position.x, -1.0 + float(gl_InstanceIndex) / 8.0 + (1.0 + a_position.y) / 16.0, + a_position.z, a_position.w); + bool correct = true; + if (attributes[0] != 0) + correct = false; + for (int i = 1; i < 7; ++i) + if (attributes[i] != gl_InstanceIndex / i) + correct = false; + v_color = correct ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0); + } + ); + + VkShaderModule fs = qoCreateShaderModuleGLSL(t_device, FRAGMENT, + layout(location = 0) in vec4 v_color; + layout(location = 0) out vec4 color; + void main() + { + color = v_color; + } + ); + + const VkVertexInputBindingDescription bindings[8] = { + {.binding = 0, .stride = 8, .inputRate = VK_VERTEX_INPUT_RATE_VERTEX}, + {.binding = 1, .stride = 4, .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE}, + {.binding = 2, .stride = 4, .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE}, + {.binding = 3, .stride = 4, .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE}, + {.binding = 4, .stride = 4, .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE}, + {.binding = 5, .stride = 4, .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE}, + {.binding = 6, .stride = 4, .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE}, + {.binding = 7, .stride = 4, .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE}, + }; + + const VkVertexInputAttributeDescription attributes[] = { + {.location = 0, .binding = 0, .offset = 0, .format = VK_FORMAT_R32G32_SFLOAT}, + {.location = 1, .binding = 1, .offset = 0, .format = VK_FORMAT_R32_UINT}, + {.location = 2, .binding = 2, .offset = 0, .format = VK_FORMAT_R32_UINT}, + {.location = 3, .binding = 3, .offset = 0, .format = VK_FORMAT_R32_UINT}, + {.location = 4, .binding = 4, .offset = 0, .format = VK_FORMAT_R32_UINT}, + {.location = 5, .binding = 5, .offset = 0, .format = VK_FORMAT_R32_UINT}, + {.location = 6, .binding = 6, .offset = 0, .format = VK_FORMAT_R32_UINT}, + {.location = 7, .binding = 7, .offset = 0, .format = VK_FORMAT_R32_UINT}, + }; + + const VkVertexInputBindingDivisorDescriptionEXT divisors[] = { + {.binding = 1, .divisor = 0}, + {.binding = 2, .divisor = 1}, + {.binding = 3, .divisor = 2}, + {.binding = 4, .divisor = 3}, + {.binding = 5, .divisor = 4}, + {.binding = 6, .divisor = 5}, + {.binding = 7, .divisor = 6}, + }; + + const VkPipelineVertexInputDivisorStateCreateInfoEXT divisor_desc = { + .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT, + .vertexBindingDivisorCount = 7, + .pVertexBindingDivisors = divisors + }; + + VkPipelineVertexInputStateCreateInfo vi_info = { + .pNext = &divisor_desc, + .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, + .vertexBindingDescriptionCount = 8, + .pVertexBindingDescriptions = bindings, + .vertexAttributeDescriptionCount = 8, + .pVertexAttributeDescriptions = attributes + }; + + VkPipelineLayout layout = VK_NULL_HANDLE; + layout = qoCreatePipelineLayout(t_device, + .pushConstantRangeCount = 0); + + VkPipeline pipeline = qoCreateGraphicsPipeline(t_device, t_pipeline_cache, + &(QoExtraGraphicsPipelineCreateInfo) { + QO_EXTRA_GRAPHICS_PIPELINE_CREATE_INFO_DEFAULTS, + .vertexShader = vs, + .fragmentShader = fs, + .pNext = + &(VkGraphicsPipelineCreateInfo) { + .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, + .pInputAssemblyState = &(VkPipelineInputAssemblyStateCreateInfo) { + QO_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO_DEFAULTS, + .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, + }, + .pColorBlendState = &(VkPipelineColorBlendStateCreateInfo) { + QO_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO_DEFAULTS + }, + .pVertexInputState = &vi_info, + .renderPass = pass, + .layout = layout, + .subpass = 0, + }}); + + const float vertices[] = { + -1.0, 1.0, + 1.0, 1.0, + -1.0, -1.0, + 1.0, -1.0 + }; + + uint32_t indices[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + + VkBuffer vb = qoCreateBuffer(t_device, .size = sizeof(vertices), + .usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT); + + VkDeviceMemory vb_mem = qoAllocBufferMemory(t_device, vb, + .properties = VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + qoBindBufferMemory(t_device, vb, vb_mem, 0); + + void *vb_map = qoMapMemory(t_device, vb_mem, 0, sizeof(vertices), 0); + + memcpy(vb_map, vertices, sizeof(vertices)); + + VkBuffer vb2 = qoCreateBuffer(t_device, .size = sizeof(indices), + .usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT); + + VkDeviceMemory vb2_mem = qoAllocBufferMemory(t_device, vb2, + .properties = VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + qoBindBufferMemory(t_device, vb2, vb2_mem, 0); + + void *vb2_map = qoMapMemory(t_device, vb2_mem, 0, sizeof(indices), 0); + memcpy(vb2_map, indices, sizeof(indices)); + + vkCmdBeginRenderPass(t_cmd_buffer, + &(VkRenderPassBeginInfo) { + .renderPass = pass, + .framebuffer = t_framebuffer, + .renderArea = { { 0, 0 }, { t_width, t_height } }, + .clearValueCount = 1, + .pClearValues = (VkClearValue[]) { + { .color = { .float32 = {1.0, 0.0, 0.0, 1.0} } }, + } + }, VK_SUBPASS_CONTENTS_INLINE); + + VkBuffer buffers[] = {vb, vb2, vb2, vb2, vb2, vb2, vb2, vb2}; + vkCmdBindVertexBuffers(t_cmd_buffer, 0, 8, buffers, + (VkDeviceSize[]) { 0, 0, 0, 0, 0, 0, 0, 0}); + + vkCmdBindPipeline(t_cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); + + vkCmdDraw(t_cmd_buffer, 4, 16, 0, 0); + + vkCmdEndRenderPass(t_cmd_buffer); + qoEndCommandBuffer(t_cmd_buffer); + qoQueueSubmit(t_queue, 1, &t_cmd_buffer, VK_NULL_HANDLE); +} + +test_define { + .name = "func.ext.vertex_attribute_divisor", + .start = vertex_attribute_divisor, + .image_filename = "32x32-green.ref.png", +}; -- 2.17.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev