summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Ekstrand <jason.ekstrand@intel.com>2017-05-16 16:14:07 -0700
committerJason Ekstrand <jason.ekstrand@intel.com>2017-05-16 16:40:38 -0700
commit5434da8a316d5432bb0ed54441c06e24d8880581 (patch)
tree5493eeeb79fe4a083a72860ad3aec355ecb5d6f9
parent4f60bf124e78c4c4843379cbf12f63096d834bac (diff)
Add a test that tests 4 vertex buffers in a row
-rw-r--r--Makefile.am2
-rw-r--r--src/tests/func/4-vertex-buffers.c164
2 files changed, 166 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index d7eda44..656ee22 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -77,6 +77,7 @@ bin_crucible_SOURCES = \
src/tests/example/messages.c \
src/tests/func/cmd-buffer/secondary.c \
src/tests/func/copy/copy-buffer.c \
+ src/tests/func/4-vertex-buffers.c \
src/tests/func/depthstencil/basic.c \
src/tests/func/depthstencil/arrayed-clear.c \
src/tests/func/depthstencil/stencil_triangles.c \
@@ -115,6 +116,7 @@ bin_crucible_SOURCES = \
BUILT_SOURCES = \
src/qonos/qonos_pipeline-spirv.h \
+ src/tests/func/4-vertex-buffers-spirv.h \
src/tests/func/depthstencil/basic-spirv.h \
src/tests/func/depthstencil/arrayed-clear-spirv.h \
src/tests/func/depthstencil/stencil_triangles-spirv.h \
diff --git a/src/tests/func/4-vertex-buffers.c b/src/tests/func/4-vertex-buffers.c
new file mode 100644
index 0000000..aab090a
--- /dev/null
+++ b/src/tests/func/4-vertex-buffers.c
@@ -0,0 +1,164 @@
+// Copyright 2015 Intel Corporation
+//
+// 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 "tapi/t.h"
+
+#include "4-vertex-buffers-spirv.h"
+
+static void
+test(void)
+{
+ float base_coords[4][2] = {
+ { 0.25, -0.25, },
+ { 0.25, 0.25, },
+ { -0.25, -0.25, },
+ { -0.25, 0.25, },
+ };
+
+ float colors[4][3] = {
+ { 1.0f, 0.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f },
+ { 0.0f, 0.0f, 1.0f },
+ { 1.0f, 1.0f, 1.0f },
+ };
+
+ float centers[4][2] = {
+ { -0.5, -0.5, },
+ { 0.5, -0.5, },
+ { -0.5, 0.5, },
+ { 0.5, 0.5, },
+ };
+
+ VkBuffer buffers[4];
+ for (unsigned i = 0; i < 4; i++) {
+ const size_t buffer_size = 4096;
+ buffers[i] = qoCreateBuffer(t_device, .size = buffer_size,
+ .usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
+
+ VkDeviceMemory mem = qoAllocBufferMemory(t_device, buffers[i],
+ .memoryTypeIndex = t_mem_type_index_for_mmap);
+
+ qoBindBufferMemory(t_device, buffers[i], mem, 0);
+
+ float *map = qoMapMemory(t_device, mem, 0, buffer_size, 0);
+
+ for (unsigned j = 0; j < 4; j++) {
+ map[j * 5 + 0] = base_coords[j][0] + centers[i][0];
+ map[j * 5 + 1] = base_coords[j][1] + centers[i][1];
+ map[j * 5 + 2] = colors[i][0];
+ map[j * 5 + 3] = colors[i][1];
+ map[j * 5 + 4] = colors[i][2];
+ }
+
+ map = NULL;
+ }
+
+ VkPipelineVertexInputStateCreateInfo vi_create_info = {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+ .vertexBindingDescriptionCount = 1,
+ .pVertexBindingDescriptions = (VkVertexInputBindingDescription[]) {
+ {
+ .binding = 0,
+ .stride = 5 * sizeof(float),
+ .inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
+ },
+ },
+ .vertexAttributeDescriptionCount = 2,
+ .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[]) {
+ {
+ .location = 0,
+ .binding = 0,
+ .format = VK_FORMAT_R32G32_SFLOAT,
+ .offset = 0,
+ },
+ {
+ .location = 1,
+ .binding = 0,
+ .format = VK_FORMAT_R32G32B32_SFLOAT,
+ .offset = 8,
+ },
+ },
+ };
+
+ 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,
+ },
+ },
+ }
+ });
+
+ VkPipeline pipeline = qoCreateGraphicsPipeline(t_device, t_pipeline_cache,
+ &(QoExtraGraphicsPipelineCreateInfo) {
+ QO_EXTRA_GRAPHICS_PIPELINE_CREATE_INFO_DEFAULTS,
+ .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
+ .pNext =
+ &(VkGraphicsPipelineCreateInfo) {
+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
+ .pVertexInputState = &vi_create_info,
+ .renderPass = pass,
+ .subpass = 0,
+ }});
+
+ vkCmdBeginRenderPass(t_cmd_buffer,
+ &(VkRenderPassBeginInfo) {
+ .renderPass = pass,
+ .framebuffer = t_framebuffer,
+ .renderArea = { { 0, 0 }, { t_width, t_height } },
+ .clearValueCount = 1,
+ .pClearValues = (VkClearValue[]) {
+ { .color = { .float32 = { 0.5f, 0.5f, 0.5f, 1.0f } } }
+ }
+ }, VK_SUBPASS_CONTENTS_INLINE);
+
+ vkCmdBindPipeline(t_cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
+
+ for (unsigned i = 0; i < 4; i++) {
+ VkDeviceSize vb_offset = 0;
+ vkCmdBindVertexBuffers(t_cmd_buffer, 0, 1, &buffers[i], &vb_offset);
+
+ vkCmdDraw(t_cmd_buffer, 4, 1, 0, 0);
+ }
+
+ vkCmdEndRenderPass(t_cmd_buffer);
+ qoEndCommandBuffer(t_cmd_buffer);
+ qoQueueSubmit(t_queue, 1, &t_cmd_buffer, VK_NULL_HANDLE);
+}
+
+test_define {
+ .name = "func.4-vertex-buffers",
+ .start = test,
+};