[Piglit] [PATCH 2/3] Add a test with a large constant array in the shader
Jason Ekstrand
jason at jlekstrand.net
Sat Aug 25 23:41:59 UTC 2018
---
Makefile.am | 2 +
data/32x32-smile.ref.png | Bin 0 -> 315 bytes
src/tests/func/shader/constants.c | 245 ++++++++++++++++++++++++++++++
3 files changed, 247 insertions(+)
create mode 100644 data/32x32-smile.ref.png
create mode 100644 src/tests/func/shader/constants.c
diff --git a/Makefile.am b/Makefile.am
index 7c4a52b..a96da9d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -98,6 +98,7 @@ bin_crucible_SOURCES = \
src/tests/func/interleaved-cmd-buffers.c \
src/tests/func/miptree/miptree.c \
src/tests/func/push-constants/basic.c \
+ src/tests/func/shader/constants.c \
src/tests/func/shader/fragcoord.c \
src/tests/func/shader/pack_unpack.c \
src/tests/func/shader_ballot/ext_shader_ballot.c \
@@ -144,6 +145,7 @@ BUILT_SOURCES = \
src/tests/func/push-constants/basic-spirv.h \
src/tests/func/amd/gcn_shader-spirv.h \
src/tests/func/amd/shader_trinary_minmax-spirv.h \
+ src/tests/func/shader/constants-spirv.h \
src/tests/func/shader/fragcoord-spirv.h \
src/tests/func/shader/pack_unpack-spirv.h \
src/tests/func/shader_ballot/ext_shader_ballot-spirv.h \
diff --git a/data/32x32-smile.ref.png b/data/32x32-smile.ref.png
new file mode 100644
index 0000000000000000000000000000000000000000..80c5bf359361c378478a46e857f00109a26f699b
GIT binary patch
literal 315
zcmeAS at N?(olHy`uVBq!ia0vp^3LwnE1SJ1Ryj={WI14-?iy0X7ltGxWVyS%@P>{XE
z)7O>#5t}T#yr9InASIxXWQl7;iF1B#Zfaf$gL6 at 8Vo7R>LV0FMhJw4NZ$Nk>pEyv_
zR!<kl5Rc<;!=m{b6nL^bzwiI_$1w1qErX-)lgYZ;(KoG}48Ev5c+B8^qWjd|FU$fA
zE}SmE3_{MPy|CzEIuP(e#;r-^y8Hd2RF(yryBZDu%${edG0$Hvu6=^0a&nq_dC2{Q
zq>p=F`|8V;JvsN*eqD7(Z<>J4_P5jeUQOKD^+RIG<&$;t6Rxc&=ni|)c<Fqq)~eYi
z6Yto#2CaO&b!|#_)UG?CQU)d`YrMXsuhBKvjr%h_{{5P?30{^@9mF>RJ;31U>gTe~
HDWM4fB2#y|
literal 0
HcmV?d00001
diff --git a/src/tests/func/shader/constants.c b/src/tests/func/shader/constants.c
new file mode 100644
index 0000000..56b7194
--- /dev/null
+++ b/src/tests/func/shader/constants.c
@@ -0,0 +1,245 @@
+// Copyright 2018 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 "constants-spirv.h"
+
+static void
+test(void)
+{
+ VkShaderModule vs = qoCreateShaderModuleGLSL(t_device, VERTEX,
+ layout(location = 0) in vec4 a_position;
+ void main()
+ {
+ gl_Position = a_position;
+ }
+ );
+
+ VkShaderModule fs = qoCreateShaderModuleGLSL(t_device, FRAGMENT,
+ layout(set = 0, binding = 0) uniform block1 {
+ vec4 colors[3];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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
+ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
+ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
+ };
+
+ void main()
+ {
+ ivec2 pix = ivec2(gl_FragCoord.xy);
+ int index = table[pix.y][pix.x];
+ f_color = u.colors[index];
+ }
+ );
+
+ const float vertices[8] = {
+ -1.0, -1.0,
+ 1.0, -1.0,
+ -1.0, 1.0,
+ 1.0, 1.0,
+ };
+ const unsigned vertices_offset = 0;
+
+ const float colors[12] = {
+ 0.0, 0.0, 0.0, 1.0,
+ 0.0, 1.0, 0.0, 1.0,
+ 1.0, 1.0, 0.0, 1.0,
+ };
+ const unsigned colors_offset = vertices_offset + sizeof(vertices);
+
+ const unsigned buffer_size = sizeof(vertices) + sizeof(colors);
+
+ VkBuffer buffer = qoCreateBuffer(t_device, .size = buffer_size,
+ .usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
+ VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
+
+ VkDeviceMemory mem = qoAllocBufferMemory(t_device, buffer,
+ .properties = VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
+ qoBindBufferMemory(t_device, buffer, mem, 0);
+
+ void *map = qoMapMemory(t_device, mem, 0, buffer_size, 0);
+ memcpy(map + vertices_offset, vertices, sizeof(vertices));
+ memcpy(map + colors_offset, colors, sizeof(colors));
+
+ VkDescriptorSetLayout set_layout = qoCreateDescriptorSetLayout(t_device,
+ .bindingCount = 1,
+ .pBindings = (VkDescriptorSetLayoutBinding[]) {
+ {
+ .binding = 0,
+ .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+ .descriptorCount = 1,
+ .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
+ .pImmutableSamplers = NULL,
+ },
+ });
+
+ VkDescriptorSet set = qoAllocateDescriptorSet(t_device,
+ .descriptorPool = t_descriptor_pool,
+ .pSetLayouts = &set_layout);
+
+ vkUpdateDescriptorSets(t_device,
+ 1, /* writeCount */
+ &(VkWriteDescriptorSet) {
+ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
+ .dstSet = set,
+ .dstBinding = 0,
+ .dstArrayElement = 0,
+ .descriptorCount = 1,
+ .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+ .pBufferInfo = &(VkDescriptorBufferInfo) {
+ .buffer = buffer,
+ .offset = colors_offset,
+ .range = sizeof(colors),
+ },
+ }, 0, NULL);
+
+ VkPipelineLayout pipeline_layout = qoCreatePipelineLayout(t_device,
+ .setLayoutCount = 1,
+ .pSetLayouts = &set_layout);
+
+ VkPipelineVertexInputStateCreateInfo vi_create_info = {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+ .vertexBindingDescriptionCount = 1,
+ .pVertexBindingDescriptions = &(VkVertexInputBindingDescription) {
+ .binding = 0,
+ .stride = 2 * sizeof(float),
+ .inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
+ },
+ .vertexAttributeDescriptionCount = 1,
+ .pVertexAttributeDescriptions = &(VkVertexInputAttributeDescription) {
+ .location = 0,
+ .binding = 0,
+ .format = VK_FORMAT_R32G32_SFLOAT,
+ .offset = vertices_offset,
+ },
+ };
+
+ VkPipeline pipeline = qoCreateGraphicsPipeline(t_device, t_pipeline_cache,
+ &(QoExtraGraphicsPipelineCreateInfo) {
+ .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
+ .vertexShader = vs,
+ .fragmentShader = fs,
+ .pNext =
+ &(VkGraphicsPipelineCreateInfo) {
+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
+ .pVertexInputState = &vi_create_info,
+ .flags = 0,
+ .layout = pipeline_layout,
+ .renderPass = t_render_pass,
+ .subpass = 0,
+ }});
+
+ vkCmdBeginRenderPass(t_cmd_buffer,
+ &(VkRenderPassBeginInfo) {
+ .renderPass = t_render_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);
+
+ vkCmdBindVertexBuffers(t_cmd_buffer, 0, 1,
+ (VkBuffer[]) { buffer },
+ (VkDeviceSize[]) { vertices_offset });
+ vkCmdBindPipeline(t_cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
+ vkCmdBindDescriptorSets(t_cmd_buffer,
+ VK_PIPELINE_BIND_POINT_GRAPHICS,
+ pipeline_layout, 0, 1, &set, 0, NULL);
+ vkCmdDraw(t_cmd_buffer, /*vertexCount*/ 4, /*instanceCount*/ 1,
+ /*firstVertex*/ 0, /*firstInstance*/ 0);
+ vkCmdEndRenderPass(t_cmd_buffer);
+ qoEndCommandBuffer(t_cmd_buffer);
+ qoQueueSubmit(t_queue, 1, &t_cmd_buffer, VK_NULL_HANDLE);
+}
+
+test_define {
+ .name = "func.shader.constants",
+ .start = test,
+ .image_filename = "32x32-smile.ref.png",
+};
--
2.17.1
More information about the Piglit
mailing list