Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 1 | // Copyright 2005, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | // VK tests |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 32 | // |
| 33 | // Copyright (C) 2014 LunarG, Inc. |
| 34 | // |
| 35 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 36 | // copy of this software and associated documentation files (the "Software"), |
| 37 | // to deal in the Software without restriction, including without limitation |
| 38 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 39 | // and/or sell copies of the Software, and to permit persons to whom the |
| 40 | // Software is furnished to do so, subject to the following conditions: |
| 41 | // |
| 42 | // The above copyright notice and this permission notice shall be included |
| 43 | // in all copies or substantial portions of the Software. |
| 44 | // |
| 45 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 46 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 47 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 48 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 49 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 50 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 51 | // DEALINGS IN THE SOFTWARE. |
| 52 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 53 | // Basic rendering tests |
| 54 | |
| 55 | #include <stdlib.h> |
| 56 | #include <stdio.h> |
| 57 | #include <stdbool.h> |
| 58 | #include <string.h> |
Courtney Goeltzenleuchter | da91b95 | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 59 | #include <iostream> |
| 60 | #include <fstream> |
| 61 | using namespace std; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 62 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 63 | #include <vulkan.h> |
Tobin Ehlis | 11e5213 | 2014-11-28 11:17:19 -0700 | [diff] [blame] | 64 | #ifdef DUMP_STATE_DOT |
| 65 | #include "../layers/draw_state.h" |
| 66 | #endif |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 67 | #ifdef PRINT_OBJECTS |
| 68 | #include "../layers/object_track.h" |
| 69 | #endif |
Tobin Ehlis | 6663f49 | 2014-11-10 12:29:12 -0700 | [diff] [blame] | 70 | #ifdef DEBUG_CALLBACK |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 71 | #include <vkDbg.h> |
Tobin Ehlis | 6663f49 | 2014-11-10 12:29:12 -0700 | [diff] [blame] | 72 | #endif |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 73 | #include "gtest-1.7.0/include/gtest/gtest.h" |
| 74 | |
Cody Northrop | 054a470 | 2015-03-17 14:54:35 -0600 | [diff] [blame] | 75 | #include "icd-spv.h" |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 76 | |
Courtney Goeltzenleuchter | fdcfb9f | 2014-10-10 18:04:39 -0600 | [diff] [blame] | 77 | #define GLM_FORCE_RADIANS |
| 78 | #include "glm/glm.hpp" |
| 79 | #include <glm/gtc/matrix_transform.hpp> |
| 80 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 81 | #include "vkrenderframework.h" |
Tobin Ehlis | 6663f49 | 2014-11-10 12:29:12 -0700 | [diff] [blame] | 82 | #ifdef DEBUG_CALLBACK |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 83 | void VKAPI myDbgFunc( |
| 84 | VK_DBG_MSG_TYPE msgType, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 85 | VkValidationLevel validationLevel, |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 86 | VkObject srcObject, |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 87 | size_t location, |
| 88 | int32_t msgCode, |
| 89 | const char* pMsg, |
| 90 | void* pUserData) |
Tobin Ehlis | 6663f49 | 2014-11-10 12:29:12 -0700 | [diff] [blame] | 91 | { |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 92 | switch (msgType) |
| 93 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 94 | case VK_DBG_MSG_WARNING: |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 95 | printf("CALLBACK WARNING : %s\n", pMsg); |
| 96 | break; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 97 | case VK_DBG_MSG_ERROR: |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 98 | printf("CALLBACK ERROR : %s\n", pMsg); |
| 99 | break; |
| 100 | default: |
| 101 | printf("EATING Msg of type %u\n", msgType); |
| 102 | break; |
| 103 | } |
Tobin Ehlis | 6663f49 | 2014-11-10 12:29:12 -0700 | [diff] [blame] | 104 | } |
| 105 | #endif |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 106 | |
| 107 | |
| 108 | #undef ASSERT_NO_FATAL_FAILURE |
| 109 | #define ASSERT_NO_FATAL_FAILURE(x) x |
| 110 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 111 | //-------------------------------------------------------------------------------------- |
| 112 | // Mesh and VertexFormat Data |
| 113 | //-------------------------------------------------------------------------------------- |
| 114 | struct Vertex |
| 115 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 116 | float posX, posY, posZ, posW; // Position data |
| 117 | float r, g, b, a; // Color |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
| 121 | |
| 122 | static const Vertex g_vbData[] = |
| 123 | { |
| 124 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 125 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 126 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 127 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 128 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 129 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 130 | |
| 131 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 132 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 133 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 134 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 135 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 136 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 137 | |
| 138 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 139 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 140 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 141 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 142 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 143 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 144 | |
| 145 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 146 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 147 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 148 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 149 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 150 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 151 | |
| 152 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 153 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 154 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 155 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 156 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 157 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 158 | |
| 159 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 160 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 161 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 162 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 163 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 164 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 165 | }; |
| 166 | |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 167 | static const Vertex g_vb_solid_face_colors_Data[] = |
| 168 | { |
| 169 | { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 170 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 171 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 172 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 173 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 174 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 175 | |
| 176 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 177 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 178 | { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 179 | { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 180 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 181 | { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 182 | |
| 183 | { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 184 | { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 185 | { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 186 | { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 187 | { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 188 | { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 189 | |
| 190 | { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 191 | { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 192 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 193 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 194 | { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 195 | { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 196 | |
| 197 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 198 | { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 199 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 200 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 201 | { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 202 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 203 | |
| 204 | { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 205 | { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 206 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 207 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 208 | { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 209 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 210 | }; |
| 211 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 212 | class VkRenderTest : public VkRenderFramework |
Courtney Goeltzenleuchter | 54119a3 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 213 | { |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 214 | public: |
Cody Northrop | 7ad4aaf | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 215 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 216 | void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model, |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 217 | VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer); |
| 218 | void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet); |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 219 | void InitDepthStencil(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 220 | void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 221 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 222 | VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer); |
| 223 | VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer); |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 224 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 225 | protected: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 226 | VkImage m_texture; |
| 227 | VkImageView m_textureView; |
| 228 | VkImageViewAttachInfo m_textureViewInfo; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 229 | VkDeviceMemory m_textureMem; |
Cody Northrop | 7d2035d | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 230 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 231 | VkSampler m_sampler; |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 232 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 233 | |
| 234 | virtual void SetUp() { |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 235 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 236 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 237 | this->app_info.pNext = NULL; |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 238 | this->app_info.pAppName = "render_tests"; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 239 | this->app_info.appVersion = 1; |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 240 | this->app_info.pEngineName = "unittest"; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 241 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 242 | this->app_info.apiVersion = VK_API_VERSION; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 243 | |
Cody Northrop | 7d2035d | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 244 | memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 245 | m_textureViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
Cody Northrop | 7d2035d | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 246 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 247 | InitFramework(); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | virtual void TearDown() { |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 251 | // Clean up resources before we reset |
| 252 | ShutdownFramework(); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 253 | } |
| 254 | }; |
| 255 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 256 | VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer) |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 257 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 258 | VkResult result; |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 259 | |
| 260 | result = cmdBuffer.BeginCommandBuffer(); |
| 261 | |
| 262 | /* |
| 263 | * For render test all drawing happens in a single render pass |
| 264 | * on a single command buffer. |
| 265 | */ |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 266 | if (VK_SUCCESS == result) { |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 267 | cmdBuffer.BeginRenderPass(renderPass(), framebuffer()); |
| 268 | } |
| 269 | |
| 270 | return result; |
| 271 | } |
| 272 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 273 | VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer) |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 274 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 275 | VkResult result; |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 276 | |
| 277 | cmdBuffer.EndRenderPass(renderPass()); |
| 278 | |
| 279 | result = cmdBuffer.EndCommandBuffer(); |
| 280 | |
| 281 | return result; |
| 282 | } |
| 283 | |
| 284 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 285 | void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet) |
Tony Barbour | 22e32a1 | 2015-01-08 17:08:28 -0700 | [diff] [blame] | 286 | { |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 287 | if (m_depthStencil->Initialized()) { |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 288 | cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil); |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 289 | } else { |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 290 | cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 291 | } |
| 292 | |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 293 | cmdBuffer->PrepareAttachments(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 294 | cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster); |
| 295 | cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport); |
| 296 | cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend); |
| 297 | cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 298 | descriptorSet.CreateVKDescriptorSet(cmdBuffer); |
| 299 | pipelineobj.CreateVKPipeline(descriptorSet); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 300 | cmdBuffer->BindPipeline(pipelineobj); |
Chia-I Wu | 53f07d7 | 2015-03-28 15:23:55 +0800 | [diff] [blame] | 301 | cmdBuffer->BindDescriptorSet(descriptorSet); |
Tony Barbour | 22e32a1 | 2015-01-08 17:08:28 -0700 | [diff] [blame] | 302 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 303 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 304 | void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model, |
| 305 | VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer) |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 306 | { |
| 307 | int i; |
| 308 | glm::mat4 MVP; |
| 309 | int matrixSize = sizeof(MVP); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 310 | VkResult err; |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 311 | |
| 312 | for (i = 0; i < 8; i++) { |
| 313 | void *pData = constantBuffer->map(); |
| 314 | |
| 315 | Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f)); |
| 316 | MVP = Projection * View * Model; |
| 317 | memcpy(pData, (const void*) &MVP[0][0], matrixSize); |
| 318 | |
| 319 | constantBuffer->unmap(); |
| 320 | |
| 321 | // submit the command buffer to the universal queue |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 322 | cmdBuffer->QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 323 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 324 | err = vkQueueWaitIdle( m_device->m_queue ); |
| 325 | ASSERT_VK_SUCCESS( err ); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 326 | |
| 327 | // Wait for work to finish before cleaning up. |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 328 | vkDeviceWaitIdle(m_device->device()); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 329 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 330 | assert(m_renderTargets.size() == 1); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 331 | RecordImage(m_renderTargets[0]); |
| 332 | } |
| 333 | } |
Courtney Goeltzenleuchter | c55471f | 2014-10-13 13:03:31 -0600 | [diff] [blame] | 334 | |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 335 | void dumpMatrix(const char *note, glm::mat4 MVP) |
| 336 | { |
Chia-I Wu | 6f18429 | 2014-12-15 23:57:34 +0800 | [diff] [blame] | 337 | int i; |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 338 | |
| 339 | printf("%s: \n", note); |
| 340 | for (i=0; i<4; i++) { |
| 341 | printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]); |
| 342 | } |
| 343 | printf("\n"); |
| 344 | fflush(stdout); |
| 345 | } |
| 346 | |
| 347 | void dumpVec4(const char *note, glm::vec4 vector) |
| 348 | { |
| 349 | printf("%s: \n", note); |
| 350 | printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]); |
| 351 | printf("\n"); |
| 352 | fflush(stdout); |
| 353 | } |
| 354 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 355 | struct vktriangle_vs_uniform { |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 356 | // Must start with MVP |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 357 | float mvp[4][4]; |
| 358 | float position[3][4]; |
| 359 | float color[3][4]; |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 360 | }; |
| 361 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 362 | void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate) |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 363 | { |
Tobin Ehlis | 6663f49 | 2014-11-10 12:29:12 -0700 | [diff] [blame] | 364 | #ifdef DEBUG_CALLBACK |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 365 | vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL); |
Tobin Ehlis | 6663f49 | 2014-11-10 12:29:12 -0700 | [diff] [blame] | 366 | #endif |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 367 | // Create identity matrix |
| 368 | int i; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 369 | struct vktriangle_vs_uniform data; |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 370 | |
| 371 | glm::mat4 Projection = glm::mat4(1.0f); |
| 372 | glm::mat4 View = glm::mat4(1.0f); |
| 373 | glm::mat4 Model = glm::mat4(1.0f); |
| 374 | glm::mat4 MVP = Projection * View * Model; |
| 375 | const int matrixSize = sizeof(MVP); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 376 | const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float); |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 377 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 378 | |
| 379 | static const Vertex tri_data[] = |
| 380 | { |
| 381 | { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 382 | { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 383 | { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 384 | }; |
| 385 | |
| 386 | for (i=0; i<3; i++) { |
| 387 | data.position[i][0] = tri_data[i].posX; |
| 388 | data.position[i][1] = tri_data[i].posY; |
| 389 | data.position[i][2] = tri_data[i].posZ; |
| 390 | data.position[i][3] = tri_data[i].posW; |
| 391 | data.color[i][0] = tri_data[i].r; |
| 392 | data.color[i][1] = tri_data[i].g; |
| 393 | data.color[i][2] = tri_data[i].b; |
| 394 | data.color[i][3] = tri_data[i].a; |
| 395 | } |
| 396 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 397 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 398 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 399 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 400 | VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 401 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 402 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 403 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 404 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 405 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 406 | pipelineobj.AddShader(&vs); |
| 407 | pipelineobj.AddShader(&ps); |
| 408 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 409 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 410 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 411 | |
Tony Barbour | d726a17 | 2015-01-09 16:12:35 -0700 | [diff] [blame] | 412 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 413 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | d726a17 | 2015-01-09 16:12:35 -0700 | [diff] [blame] | 414 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 415 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 416 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | d726a17 | 2015-01-09 16:12:35 -0700 | [diff] [blame] | 417 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 418 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | d726a17 | 2015-01-09 16:12:35 -0700 | [diff] [blame] | 419 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 420 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | d726a17 | 2015-01-09 16:12:35 -0700 | [diff] [blame] | 421 | pDSDumpDot((char*)"triTest2.dot"); |
| 422 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 423 | |
Tony Barbour | d726a17 | 2015-01-09 16:12:35 -0700 | [diff] [blame] | 424 | // render triangle |
| 425 | cmdBuffer.Draw(0, 3, 0, 1); |
| 426 | |
| 427 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 428 | EndCommandBuffer(cmdBuffer); |
| 429 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 430 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | d726a17 | 2015-01-09 16:12:35 -0700 | [diff] [blame] | 431 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 432 | RecordImages(m_renderTargets); |
Tony Barbour | d726a17 | 2015-01-09 16:12:35 -0700 | [diff] [blame] | 433 | |
| 434 | if (rotate) |
Tobin Ehlis | 976fc16 | 2015-03-26 08:23:25 -0600 | [diff] [blame] | 435 | RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer); |
Tony Barbour | d726a17 | 2015-01-09 16:12:35 -0700 | [diff] [blame] | 436 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 437 | #ifdef PRINT_OBJECTS |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 438 | //uint64_t objTrackGetObjectCount(VK_OBJECT_TYPE type) |
| 439 | OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectCount"); |
| 440 | uint64_t numObjects = pObjTrackGetObjectCount(VK_OBJECT_TYPE_ANY); |
| 441 | //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects"); |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 442 | printf("DEBUG : Number of Objects : %lu\n", numObjects); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 443 | OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects"); |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 444 | OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 445 | pObjTrackGetObjs(VK_OBJECT_TYPE_ANY, numObjects, pObjNodeArray); |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 446 | for (i=0; i < numObjects; i++) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 447 | printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_VK_OBJECT_TYPE(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses); |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 448 | } |
| 449 | free(pObjNodeArray); |
| 450 | #endif |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 451 | |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 452 | } |
| 453 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 454 | TEST_F(VkRenderTest, VKTriangle_FragColor) |
Courtney Goeltzenleuchter | 71d1f87 | 2014-10-27 13:08:55 -0600 | [diff] [blame] | 455 | { |
| 456 | static const char *vertShaderText = |
| 457 | "#version 140\n" |
| 458 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 459 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 460 | "\n" |
| 461 | "layout(binding = 0) uniform buf {\n" |
| 462 | " mat4 MVP;\n" |
| 463 | " vec4 position[3];\n" |
| 464 | " vec4 color[3];\n" |
| 465 | "} ubuf;\n" |
| 466 | "\n" |
| 467 | "layout (location = 0) out vec4 outColor;\n" |
| 468 | "\n" |
| 469 | "void main() \n" |
| 470 | "{\n" |
| 471 | " outColor = ubuf.color[gl_VertexID];\n" |
| 472 | " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n" |
| 473 | "}\n"; |
| 474 | |
| 475 | static const char *fragShaderText = |
| 476 | "#version 140\n" |
| 477 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 478 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 479 | "\n" |
| 480 | "layout (location = 0) in vec4 inColor;\n" |
| 481 | "\n" |
| 482 | "void main()\n" |
| 483 | "{\n" |
| 484 | " gl_FragColor = inColor;\n" |
| 485 | "}\n"; |
| 486 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 487 | TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor"); |
| 488 | VKTriangleTest(vertShaderText, fragShaderText, true); |
Courtney Goeltzenleuchter | 71d1f87 | 2014-10-27 13:08:55 -0600 | [diff] [blame] | 489 | } |
| 490 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 491 | TEST_F(VkRenderTest, VKTriangle_OutputLocation) |
Courtney Goeltzenleuchter | 71d1f87 | 2014-10-27 13:08:55 -0600 | [diff] [blame] | 492 | { |
| 493 | static const char *vertShaderText = |
| 494 | "#version 140\n" |
| 495 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 496 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 497 | "\n" |
| 498 | "layout(binding = 0) uniform buf {\n" |
| 499 | " mat4 MVP;\n" |
| 500 | " vec4 position[3];\n" |
| 501 | " vec4 color[3];\n" |
| 502 | "} ubuf;\n" |
| 503 | "\n" |
| 504 | "layout (location = 0) out vec4 outColor;\n" |
| 505 | "\n" |
| 506 | "void main() \n" |
| 507 | "{\n" |
| 508 | " outColor = ubuf.color[gl_VertexID];\n" |
| 509 | " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n" |
| 510 | "}\n"; |
| 511 | |
| 512 | static const char *fragShaderText = |
| 513 | "#version 140\n" |
| 514 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 515 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 516 | "\n" |
| 517 | "layout (location = 0) in vec4 inColor;\n" |
| 518 | "layout (location = 0) out vec4 outColor;\n" |
| 519 | "\n" |
| 520 | "void main()\n" |
| 521 | "{\n" |
| 522 | " outColor = inColor;\n" |
| 523 | "}\n"; |
| 524 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 525 | TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor"); |
Courtney Goeltzenleuchter | 71d1f87 | 2014-10-27 13:08:55 -0600 | [diff] [blame] | 526 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 527 | VKTriangleTest(vertShaderText, fragShaderText, true); |
Courtney Goeltzenleuchter | 71d1f87 | 2014-10-27 13:08:55 -0600 | [diff] [blame] | 528 | } |
Tony Barbour | 0dd968a | 2015-04-02 15:48:24 -0600 | [diff] [blame] | 529 | #ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 530 | TEST_F(VkRenderTest, SPV_VKTriangle) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 531 | { |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 532 | bool saved_use_spv = VkTestFramework::m_use_spv; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 533 | |
| 534 | static const char *vertShaderText = |
| 535 | "#version 140\n" |
| 536 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 537 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 538 | "\n" |
| 539 | "layout(binding = 0) uniform buf {\n" |
| 540 | " mat4 MVP;\n" |
| 541 | " vec4 position[3];\n" |
| 542 | " vec4 color[3];\n" |
| 543 | "} ubuf;\n" |
| 544 | "\n" |
| 545 | "layout (location = 0) out vec4 outColor;\n" |
| 546 | "\n" |
| 547 | "void main() \n" |
| 548 | "{\n" |
| 549 | " outColor = ubuf.color[gl_VertexID];\n" |
| 550 | " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n" |
| 551 | "}\n"; |
| 552 | |
| 553 | static const char *fragShaderText = |
| 554 | "#version 140\n" |
| 555 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 556 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 557 | "\n" |
| 558 | "layout (location = 0) in vec4 inColor;\n" |
| 559 | "\n" |
| 560 | "void main()\n" |
| 561 | "{\n" |
| 562 | " gl_FragColor = inColor;\n" |
| 563 | "}\n"; |
| 564 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 565 | TEST_DESCRIPTION("VK-style shaders, but force test framework to compile shader to SPV and pass SPV to driver."); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 566 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 567 | VkTestFramework::m_use_spv = true; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 568 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 569 | VKTriangleTest(vertShaderText, fragShaderText, true); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 570 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 571 | VkTestFramework::m_use_spv = saved_use_spv; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 572 | } |
Tony Barbour | 0dd968a | 2015-04-02 15:48:24 -0600 | [diff] [blame] | 573 | #endif |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 574 | TEST_F(VkRenderTest, GreenTriangle) |
Cody Northrop | d1a256b | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 575 | { |
| 576 | static const char *vertShaderText = |
| 577 | "#version 130\n" |
| 578 | "vec2 vertices[3];\n" |
| 579 | "void main() {\n" |
| 580 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 581 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 582 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 583 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 584 | "}\n"; |
Courtney Goeltzenleuchter | 538062a | 2014-10-09 15:40:19 -0600 | [diff] [blame] | 585 | |
Cody Northrop | d1a256b | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 586 | static const char *fragShaderText = |
| 587 | "#version 130\n" |
Cody Northrop | d1a256b | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 588 | "void main() {\n" |
Steve K | c53f863 | 2014-10-10 08:54:29 -0600 | [diff] [blame] | 589 | " gl_FragColor = vec4(0,1,0,1);\n" |
Cody Northrop | d1a256b | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 590 | "}\n"; |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 591 | |
Courtney Goeltzenleuchter | 9fb6249 | 2014-10-27 13:09:23 -0600 | [diff] [blame] | 592 | TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader."); |
| 593 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 594 | VKTriangleTest(vertShaderText, fragShaderText, false); |
Cody Northrop | d1a256b | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 595 | } |
Tony Barbour | 0dd968a | 2015-04-02 15:48:24 -0600 | [diff] [blame] | 596 | #ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 597 | TEST_F(VkRenderTest, SPV_GreenTriangle) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 598 | { |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 599 | bool saved_use_spv = VkTestFramework::m_use_spv; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 600 | |
| 601 | static const char *vertShaderText = |
| 602 | "#version 130\n" |
| 603 | "vec2 vertices[3];\n" |
| 604 | "void main() {\n" |
| 605 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 606 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 607 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 608 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 609 | "}\n"; |
| 610 | |
| 611 | static const char *fragShaderText = |
| 612 | "#version 130\n" |
| 613 | "void main() {\n" |
| 614 | " gl_FragColor = vec4(0,1,0,1);\n" |
| 615 | "}\n"; |
| 616 | |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 617 | TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver."); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 618 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 619 | VkTestFramework::m_use_spv = true; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 620 | VKTriangleTest(vertShaderText, fragShaderText, false); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 621 | VkTestFramework::m_use_spv = saved_use_spv; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 622 | } |
Tony Barbour | 0dd968a | 2015-04-02 15:48:24 -0600 | [diff] [blame] | 623 | #endif |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 624 | TEST_F(VkRenderTest, YellowTriangle) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 625 | { |
| 626 | static const char *vertShaderText = |
| 627 | "#version 130\n" |
| 628 | "void main() {\n" |
| 629 | " vec2 vertices[3];" |
| 630 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 631 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 632 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 633 | " vec4 colors[3];\n" |
| 634 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 635 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 636 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 637 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 638 | "}\n"; |
| 639 | |
| 640 | static const char *fragShaderText = |
| 641 | "#version 130\n" |
| 642 | "void main() {\n" |
| 643 | " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n" |
| 644 | "}\n"; |
| 645 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 646 | VKTriangleTest(vertShaderText, fragShaderText, false); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 649 | TEST_F(VkRenderTest, QuadWithVertexFetch) |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 650 | { |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 651 | static const char *vertShaderText = |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 652 | "#version 140\n" |
| 653 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 654 | "#extension GL_ARB_shading_language_420pack : enable\n" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 655 | //XYZ1( -1, -1, -1 ) |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 656 | "layout (location = 0) in vec4 pos;\n" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 657 | //XYZ1( 0.f, 0.f, 0.f ) |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 658 | "layout (location = 1) in vec4 inColor;\n" |
| 659 | "layout (location = 0) out vec4 outColor;\n" |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 660 | "void main() {\n" |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 661 | " outColor = inColor;\n" |
Cody Northrop | 7ad4aaf | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 662 | " gl_Position = pos;\n" |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 663 | "}\n"; |
| 664 | |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 665 | |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 666 | static const char *fragShaderText = |
Cody Northrop | d43c52e | 2014-12-05 15:44:14 -0700 | [diff] [blame] | 667 | "#version 140\n" |
| 668 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 669 | "#extension GL_ARB_shading_language_420pack : enable\n" |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 670 | "layout (location = 0) in vec4 color;\n" |
Cody Northrop | d43c52e | 2014-12-05 15:44:14 -0700 | [diff] [blame] | 671 | "layout (location = 0) out vec4 outColor;\n" |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 672 | "void main() {\n" |
Cody Northrop | d43c52e | 2014-12-05 15:44:14 -0700 | [diff] [blame] | 673 | " outColor = color;\n" |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 674 | "}\n"; |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 675 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 676 | |
| 677 | |
| 678 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 679 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 680 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 681 | VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 682 | meshBuffer.BufferMemoryBarrier(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 683 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 684 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 685 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 686 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 687 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 688 | pipelineobj.AddShader(&vs); |
| 689 | pipelineobj.AddShader(&ps); |
| 690 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 691 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 692 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer); |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 693 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 694 | #define MESH_BIND_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 695 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 696 | MESH_BIND_ID, // binding ID |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 697 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 698 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 699 | }; |
| 700 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 701 | VkVertexInputAttributeDescription vi_attribs[2]; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 702 | vi_attribs[0].binding = MESH_BIND_ID; // Binding ID |
| 703 | vi_attribs[0].location = 0; // location, position |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 704 | vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 705 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 706 | vi_attribs[1].binding = MESH_BIND_ID; // Binding ID |
| 707 | vi_attribs[1].location = 1; // location, color |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 708 | vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 709 | vi_attribs[1].offsetInBytes = 1*sizeof(float)*4; // Offset of first element in bytes from base of vertex |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 710 | |
| 711 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 712 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 713 | pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 714 | |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 715 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 716 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 717 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 718 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 719 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 720 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 721 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 722 | |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 723 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 724 | |
| 725 | // render two triangles |
| 726 | cmdBuffer.Draw(0, 6, 0, 1); |
| 727 | |
| 728 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 729 | EndCommandBuffer(cmdBuffer); |
| 730 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 731 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 732 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 733 | RecordImages(m_renderTargets); |
Tobin Ehlis | d806c8e | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 734 | } |
| 735 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 736 | TEST_F(VkRenderTest, TriangleMRT) |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 737 | { |
| 738 | static const char *vertShaderText = |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 739 | "#version 140\n" |
| 740 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 741 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 742 | "layout (location = 0) in vec4 pos;\n" |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 743 | "void main() {\n" |
| 744 | " gl_Position = pos;\n" |
| 745 | "}\n"; |
| 746 | |
| 747 | static const char *fragShaderText = |
| 748 | "#version 130\n" |
| 749 | "void main() {\n" |
| 750 | " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 751 | " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 752 | "}\n"; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 753 | const float vb_data[][2] = { |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 754 | { -1.0f, -1.0f }, |
| 755 | { 1.0f, -1.0f }, |
| 756 | { -1.0f, 1.0f } |
| 757 | }; |
| 758 | |
| 759 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 760 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 761 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 762 | VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 763 | meshBuffer.BufferMemoryBarrier(); |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 764 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 765 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 766 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 767 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 768 | VkPipelineObj pipelineobj(m_device); |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 769 | pipelineobj.AddShader(&vs); |
| 770 | pipelineobj.AddShader(&ps); |
| 771 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 772 | #define MESH_BUF_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 773 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 774 | MESH_BUF_ID, // Binding ID |
| 775 | sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 776 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 777 | }; |
| 778 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 779 | VkVertexInputAttributeDescription vi_attrib; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 780 | vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions |
| 781 | vi_attrib.location = 0; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 782 | vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 783 | vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 784 | |
| 785 | pipelineobj.AddVertexInputAttribs(&vi_attrib, 1); |
| 786 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 787 | pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID); |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 788 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 789 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 790 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer); |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 791 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 792 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2)); |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 793 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 794 | VkPipelineCbAttachmentState att = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 795 | att.blendEnable = VK_FALSE; |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 796 | att.format = m_render_target_fmt; |
| 797 | att.channelWriteMask = 0xf; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 798 | pipelineobj.AddColorAttachment(1, &att); |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 799 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 800 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 801 | |
Tony Barbour | 304ec8b | 2015-01-07 14:31:52 -0700 | [diff] [blame] | 802 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 803 | cmdBuffer.AddRenderTarget(m_renderTargets[1]); |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 804 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 805 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 304ec8b | 2015-01-07 14:31:52 -0700 | [diff] [blame] | 806 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 807 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 808 | |
Tony Barbour | 304ec8b | 2015-01-07 14:31:52 -0700 | [diff] [blame] | 809 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
Tony Barbour | 304ec8b | 2015-01-07 14:31:52 -0700 | [diff] [blame] | 810 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 811 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 304ec8b | 2015-01-07 14:31:52 -0700 | [diff] [blame] | 812 | pDSDumpDot((char*)"triTest2.dot"); |
| 813 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 814 | |
Tony Barbour | 304ec8b | 2015-01-07 14:31:52 -0700 | [diff] [blame] | 815 | // render triangle |
| 816 | cmdBuffer.Draw(0, 3, 0, 1); |
| 817 | |
| 818 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 819 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 820 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 304ec8b | 2015-01-07 14:31:52 -0700 | [diff] [blame] | 821 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 822 | RecordImages(m_renderTargets); |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 823 | } |
| 824 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 825 | TEST_F(VkRenderTest, QuadWithIndexedVertexFetch) |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 826 | { |
| 827 | static const char *vertShaderText = |
| 828 | "#version 140\n" |
| 829 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 830 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 831 | "layout(location = 0) in vec4 pos;\n" |
| 832 | "layout(location = 1) in vec4 inColor;\n" |
| 833 | "layout(location = 0) out vec4 outColor;\n" |
| 834 | "void main() {\n" |
| 835 | " outColor = inColor;\n" |
| 836 | " gl_Position = pos;\n" |
| 837 | "}\n"; |
| 838 | |
| 839 | |
| 840 | static const char *fragShaderText = |
| 841 | "#version 140\n" |
| 842 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 843 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 844 | "layout(location = 0) in vec4 color;\n" |
| 845 | "void main() {\n" |
| 846 | " gl_FragColor = color;\n" |
| 847 | "}\n"; |
| 848 | |
| 849 | const Vertex g_vbData[] = |
| 850 | { |
| 851 | // first tri |
| 852 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black |
| 853 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red |
| 854 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green |
| 855 | |
| 856 | // second tri |
| 857 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green |
| 858 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red |
| 859 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow |
| 860 | }; |
| 861 | |
| 862 | const uint16_t g_idxData[6] = { |
| 863 | 0, 1, 2, |
| 864 | 3, 4, 5, |
| 865 | }; |
| 866 | |
| 867 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 868 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 869 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 870 | VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 871 | meshBuffer.BufferMemoryBarrier(); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 872 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 873 | VkIndexBufferObj indexBuffer(m_device); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 874 | indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData); |
Mark Lobodzinski | 49a6b4b | 2015-02-16 14:24:23 -0600 | [diff] [blame] | 875 | indexBuffer.BufferMemoryBarrier(); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 876 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 877 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 878 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 879 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 880 | VkPipelineObj pipelineobj(m_device); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 881 | pipelineobj.AddShader(&vs); |
| 882 | pipelineobj.AddShader(&ps); |
| 883 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 884 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 885 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer); |
| 886 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer); |
Tony Barbour | 831062d | 2015-04-02 15:43:15 -0600 | [diff] [blame] | 887 | |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 888 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 889 | #define MESH_BIND_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 890 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 891 | MESH_BIND_ID, // binding ID |
| 892 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 893 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 894 | }; |
| 895 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 896 | VkVertexInputAttributeDescription vi_attribs[2]; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 897 | vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute |
| 898 | vi_attribs[0].location = 0; // layout location of vertex attribute |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 899 | vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 900 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 901 | vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute |
| 902 | vi_attribs[1].location = 1; // layout location of vertex attribute |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 903 | vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 904 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 905 | |
| 906 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 907 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 908 | |
| 909 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 910 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | ad8f154 | 2014-12-17 11:16:05 -0700 | [diff] [blame] | 911 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 912 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 913 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 914 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 915 | |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 916 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 917 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tobin Ehlis | f27eba7 | 2014-12-16 17:34:50 -0700 | [diff] [blame] | 918 | pDSDumpDot((char*)"triTest2.dot"); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 919 | #endif |
Tony Barbour | 22e32a1 | 2015-01-08 17:08:28 -0700 | [diff] [blame] | 920 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 921 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 922 | cmdBuffer.BindIndexBuffer(&indexBuffer, 0); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 923 | |
| 924 | // render two triangles |
Tony Barbour | ad8f154 | 2014-12-17 11:16:05 -0700 | [diff] [blame] | 925 | cmdBuffer.DrawIndexed(0, 6, 0, 0, 1); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 926 | |
| 927 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 928 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 929 | cmdBuffer.QueueCommandBuffer(); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 930 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 931 | RecordImages(m_renderTargets); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 934 | TEST_F(VkRenderTest, GreyandRedCirclesonBlue) |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 935 | { |
| 936 | // This tests gl_FragCoord |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 937 | |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 938 | static const char *vertShaderText = |
| 939 | "#version 140\n" |
| 940 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 941 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 942 | "layout (location = 0) in vec4 pos;\n" |
| 943 | "layout (location = 0) out vec4 outColor;\n" |
| 944 | "layout (location = 1) out vec4 outColor2;\n" |
| 945 | "void main() {\n" |
| 946 | " gl_Position = pos;\n" |
| 947 | " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n" |
| 948 | " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n" |
| 949 | "}\n"; |
| 950 | |
| 951 | static const char *fragShaderText = |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 952 | "#version 330\n" |
| 953 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 954 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 955 | //"#extension GL_ARB_fragment_coord_conventions : enable\n" |
| 956 | //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n" |
| 957 | "layout (location = 0) in vec4 color;\n" |
| 958 | "layout (location = 1) in vec4 color2;\n" |
| 959 | "void main() {\n" |
| 960 | " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n" |
| 961 | " float dist_squared = dot(pos, pos);\n" |
| 962 | " gl_FragColor = (dist_squared < 400.0)\n" |
| 963 | " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n" |
| 964 | " : color2;\n" |
| 965 | "}\n"; |
| 966 | |
| 967 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 968 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 969 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 970 | VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 971 | meshBuffer.BufferMemoryBarrier(); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 972 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 973 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 974 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 975 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 976 | VkPipelineObj pipelineobj(m_device); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 977 | pipelineobj.AddShader(&vs); |
| 978 | pipelineobj.AddShader(&ps); |
| 979 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 980 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 981 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer); |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 982 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 983 | #define MESH_BIND_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 984 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 985 | MESH_BIND_ID, // binding ID |
| 986 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 987 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 988 | }; |
| 989 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 990 | VkVertexInputAttributeDescription vi_attribs[1]; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 991 | vi_attribs[0].binding = MESH_BIND_ID; // binding ID |
| 992 | vi_attribs[0].location = 0; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 993 | vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 994 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 995 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 996 | pipelineobj.AddVertexInputAttribs(vi_attribs,1); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 997 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 998 | pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 999 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1000 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1001 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1002 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 1003 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1004 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1005 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1006 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1007 | |
| 1008 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 1009 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1010 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1011 | pDSDumpDot((char*)"triTest2.dot"); |
| 1012 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1013 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1014 | // render triangle |
| 1015 | cmdBuffer.Draw(0, 6, 0, 1); |
| 1016 | |
| 1017 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1018 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1019 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1020 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1021 | RecordImages(m_renderTargets); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1024 | TEST_F(VkRenderTest, RedCirclesonBlue) |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1025 | { |
| 1026 | // This tests that we correctly handle unread fragment inputs |
| 1027 | |
| 1028 | static const char *vertShaderText = |
| 1029 | "#version 140\n" |
| 1030 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1031 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1032 | "layout (location = 0) in vec4 pos;\n" |
| 1033 | "layout (location = 0) out vec4 outColor;\n" |
| 1034 | "layout (location = 1) out vec4 outColor2;\n" |
| 1035 | "void main() {\n" |
| 1036 | " gl_Position = pos;\n" |
| 1037 | " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n" |
| 1038 | " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n" |
| 1039 | "}\n"; |
| 1040 | |
| 1041 | static const char *fragShaderText = |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1042 | "#version 330\n" |
| 1043 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1044 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1045 | //"#extension GL_ARB_fragment_coord_conventions : enable\n" |
| 1046 | //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n" |
| 1047 | "layout (location = 0) in vec4 color;\n" |
| 1048 | "layout (location = 1) in vec4 color2;\n" |
| 1049 | "void main() {\n" |
| 1050 | " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n" |
| 1051 | " float dist_squared = dot(pos, pos);\n" |
| 1052 | " gl_FragColor = (dist_squared < 400.0)\n" |
| 1053 | " ? vec4(1.0, 0.0, 0.0, 1.0)\n" |
| 1054 | " : color2;\n" |
| 1055 | "}\n"; |
| 1056 | |
| 1057 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1058 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1059 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1060 | VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1061 | meshBuffer.BufferMemoryBarrier(); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1062 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1063 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1064 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1065 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1066 | VkPipelineObj pipelineobj(m_device); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1067 | pipelineobj.AddShader(&vs); |
| 1068 | pipelineobj.AddShader(&ps); |
| 1069 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1070 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1071 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer); |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 1072 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1073 | #define MESH_BIND_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1074 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1075 | MESH_BIND_ID, // binding ID |
| 1076 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1077 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1078 | }; |
| 1079 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1080 | VkVertexInputAttributeDescription vi_attribs[1]; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1081 | vi_attribs[0].binding = MESH_BIND_ID; // binding ID |
| 1082 | vi_attribs[0].location = 0; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1083 | vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1084 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1085 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1086 | pipelineobj.AddVertexInputAttribs(vi_attribs,1); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1087 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1088 | pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1089 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1090 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1091 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1092 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 1093 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1094 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1095 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1096 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1097 | |
| 1098 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 1099 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1100 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1101 | pDSDumpDot((char*)"triTest2.dot"); |
| 1102 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1103 | // render two triangles |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1104 | cmdBuffer.Draw(0, 6, 0, 1); |
| 1105 | |
| 1106 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1107 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1108 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1109 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1110 | RecordImages(m_renderTargets); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1113 | TEST_F(VkRenderTest, GreyCirclesonBlueFade) |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1114 | { |
| 1115 | // This tests reading gl_ClipDistance from FS |
| 1116 | |
| 1117 | static const char *vertShaderText = |
| 1118 | "#version 330\n" |
| 1119 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1120 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1121 | "out gl_PerVertex {\n" |
| 1122 | " vec4 gl_Position;\n" |
| 1123 | " float gl_ClipDistance[1];\n" |
| 1124 | "};\n" |
| 1125 | "layout (location = 0) in vec4 pos;\n" |
| 1126 | "layout (location = 0) out vec4 outColor;\n" |
| 1127 | "layout (location = 1) out vec4 outColor2;\n" |
| 1128 | "void main() {\n" |
| 1129 | " gl_Position = pos;\n" |
| 1130 | " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n" |
| 1131 | " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n" |
| 1132 | " float dists[3];\n" |
| 1133 | " dists[0] = 0.0;\n" |
| 1134 | " dists[1] = 1.0;\n" |
| 1135 | " dists[2] = 1.0;\n" |
| 1136 | " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n" |
| 1137 | "}\n"; |
| 1138 | |
| 1139 | |
| 1140 | static const char *fragShaderText = |
| 1141 | //"#version 140\n" |
| 1142 | "#version 330\n" |
| 1143 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1144 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1145 | //"#extension GL_ARB_fragment_coord_conventions : enable\n" |
| 1146 | //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n" |
| 1147 | "layout (location = 0) in vec4 color;\n" |
| 1148 | "layout (location = 1) in vec4 color2;\n" |
| 1149 | "void main() {\n" |
| 1150 | " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n" |
| 1151 | " float dist_squared = dot(pos, pos);\n" |
| 1152 | " gl_FragColor = (dist_squared < 400.0)\n" |
| 1153 | " ? color * gl_ClipDistance[0]\n" |
| 1154 | " : color2;\n" |
| 1155 | "}\n"; |
| 1156 | |
| 1157 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1158 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1159 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1160 | VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1161 | meshBuffer.BufferMemoryBarrier(); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1162 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1163 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1164 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1165 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1166 | VkPipelineObj pipelineobj(m_device); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1167 | pipelineobj.AddShader(&vs); |
| 1168 | pipelineobj.AddShader(&ps); |
| 1169 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1170 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1171 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer); |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 1172 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1173 | #define MESH_BIND_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1174 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1175 | MESH_BIND_ID, // binding ID |
| 1176 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1177 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1178 | }; |
| 1179 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1180 | VkVertexInputAttributeDescription vi_attribs[1]; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1181 | vi_attribs[0].binding = MESH_BIND_ID; // binding ID |
| 1182 | vi_attribs[0].location = 0; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1183 | vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1184 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1185 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1186 | pipelineobj.AddVertexInputAttribs(vi_attribs,1); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1187 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1188 | pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1189 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1190 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1191 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1192 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1193 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1194 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1195 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1196 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1197 | |
| 1198 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 1199 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1200 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1201 | pDSDumpDot((char*)"triTest2.dot"); |
| 1202 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1203 | |
| 1204 | // render two triangles |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1205 | cmdBuffer.Draw(0, 6, 0, 1); |
| 1206 | |
| 1207 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1208 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1209 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1210 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1211 | RecordImages(m_renderTargets); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1212 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1213 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1214 | TEST_F(VkRenderTest, GreyCirclesonBlueDiscard) |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1215 | { |
| 1216 | static const char *vertShaderText = |
| 1217 | "#version 140\n" |
| 1218 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1219 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1220 | "layout (location = 0) in vec4 pos;\n" |
| 1221 | "layout (location = 0) out vec4 outColor;\n" |
| 1222 | "layout (location = 1) out vec4 outColor2;\n" |
| 1223 | "void main() {\n" |
| 1224 | " gl_Position = pos;\n" |
| 1225 | " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n" |
| 1226 | " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n" |
| 1227 | "}\n"; |
| 1228 | |
| 1229 | |
| 1230 | static const char *fragShaderText = |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1231 | "#version 330\n" |
| 1232 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1233 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1234 | //"#extension GL_ARB_fragment_coord_conventions : enable\n" |
| 1235 | //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n" |
| 1236 | "layout (location = 0) in vec4 color;\n" |
| 1237 | "layout (location = 1) in vec4 color2;\n" |
| 1238 | "void main() {\n" |
| 1239 | " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n" |
| 1240 | " float dist_squared = dot(pos, pos);\n" |
| 1241 | " if (dist_squared < 100.0)\n" |
| 1242 | " discard;\n" |
| 1243 | " gl_FragColor = (dist_squared < 400.0)\n" |
| 1244 | " ? color\n" |
| 1245 | " : color2;\n" |
| 1246 | "}\n"; |
| 1247 | |
| 1248 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1249 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1250 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1251 | VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1252 | meshBuffer.BufferMemoryBarrier(); |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1253 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1254 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1255 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1256 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1257 | VkPipelineObj pipelineobj(m_device); |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1258 | pipelineobj.AddShader(&vs); |
| 1259 | pipelineobj.AddShader(&ps); |
| 1260 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1261 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1262 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer); |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 1263 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1264 | #define MESH_BIND_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1265 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1266 | MESH_BIND_ID, // binding ID |
| 1267 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1268 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1269 | }; |
| 1270 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1271 | VkVertexInputAttributeDescription vi_attribs[1]; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1272 | vi_attribs[0].binding = MESH_BIND_ID; // binding ID |
| 1273 | vi_attribs[0].location = 0; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1274 | vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1275 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1276 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1277 | pipelineobj.AddVertexInputAttribs(vi_attribs,1); |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1278 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1279 | pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID); |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1280 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1281 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1282 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1283 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 1284 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1285 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1286 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1287 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1288 | |
| 1289 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 1290 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1291 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1292 | pDSDumpDot((char*)"triTest2.dot"); |
| 1293 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1294 | |
| 1295 | // render two triangles |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1296 | cmdBuffer.Draw(0, 6, 0, 1); |
| 1297 | |
| 1298 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1299 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1300 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1301 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1302 | RecordImages(m_renderTargets); |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1306 | TEST_F(VkRenderTest, TriangleVSUniform) |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1307 | { |
| 1308 | static const char *vertShaderText = |
Courtney Goeltzenleuchter | 8285704 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1309 | "#version 140\n" |
| 1310 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1311 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1312 | "\n" |
| 1313 | "layout(binding = 0) uniform buf {\n" |
| 1314 | " mat4 MVP;\n" |
| 1315 | "} ubuf;\n" |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1316 | "void main() {\n" |
| 1317 | " vec2 vertices[3];" |
| 1318 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1319 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1320 | " vertices[2] = vec2( 0.5, 0.5);\n" |
Courtney Goeltzenleuchter | 8285704 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1321 | " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1322 | "}\n"; |
| 1323 | |
| 1324 | static const char *fragShaderText = |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1325 | "#version 130\n" |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1326 | "void main() {\n" |
Cody Northrop | bb38ad3 | 2014-10-10 15:45:00 -0600 | [diff] [blame] | 1327 | " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1328 | "}\n"; |
| 1329 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1330 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1331 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1332 | |
Courtney Goeltzenleuchter | fdcfb9f | 2014-10-10 18:04:39 -0600 | [diff] [blame] | 1333 | // Create identity matrix |
Courtney Goeltzenleuchter | 8285704 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1334 | glm::mat4 Projection = glm::mat4(1.0f); |
| 1335 | glm::mat4 View = glm::mat4(1.0f); |
| 1336 | glm::mat4 Model = glm::mat4(1.0f); |
| 1337 | glm::mat4 MVP = Projection * View * Model; |
| 1338 | const int matrixSize = sizeof(MVP) / sizeof(MVP[0]); |
| 1339 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1340 | VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]); |
| 1341 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1342 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Courtney Goeltzenleuchter | 8285704 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1343 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1344 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1345 | pipelineobj.AddShader(&vs); |
| 1346 | pipelineobj.AddShader(&ps); |
| 1347 | |
| 1348 | // Create descriptor set and attach the constant buffer to it |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1349 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1350 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1351 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1352 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1353 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1354 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1355 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1356 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1357 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1358 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1359 | |
| 1360 | // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 1361 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1362 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1363 | pDSDumpDot((char*)"triTest2.dot"); |
| 1364 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1365 | |
| 1366 | // render two triangles |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1367 | cmdBuffer.Draw(0, 6, 0, 1); |
| 1368 | |
| 1369 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1370 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1371 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1372 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1373 | RecordImages(m_renderTargets); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1374 | |
| 1375 | RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer); |
Courtney Goeltzenleuchter | 8285704 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1376 | } |
| 1377 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1378 | TEST_F(VkRenderTest, MixTriangle) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1379 | { |
| 1380 | // This tests location applied to varyings. Notice that we have switched foo |
| 1381 | // and bar in the FS. The triangle should be blended with red, green and blue |
| 1382 | // corners. |
| 1383 | static const char *vertShaderText = |
| 1384 | "#version 140\n" |
| 1385 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1386 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1387 | "layout (location=0) out vec4 bar;\n" |
| 1388 | "layout (location=1) out vec4 foo;\n" |
| 1389 | "layout (location=2) out float scale;\n" |
| 1390 | "vec2 vertices[3];\n" |
| 1391 | "void main() {\n" |
| 1392 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 1393 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 1394 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 1395 | "vec4 colors[3];\n" |
| 1396 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 1397 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 1398 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 1399 | " foo = colors[gl_VertexID % 3];\n" |
| 1400 | " bar = vec4(1.0, 1.0, 1.0, 1.0);\n" |
| 1401 | " scale = 1.0;\n" |
| 1402 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1403 | "}\n"; |
| 1404 | |
| 1405 | static const char *fragShaderText = |
| 1406 | "#version 140\n" |
| 1407 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1408 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1409 | "layout (location = 1) in vec4 bar;\n" |
| 1410 | "layout (location = 0) in vec4 foo;\n" |
| 1411 | "layout (location = 2) in float scale;\n" |
| 1412 | "void main() {\n" |
| 1413 | " gl_FragColor = bar * scale + foo * (1.0-scale);\n" |
| 1414 | "}\n"; |
| 1415 | |
| 1416 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1417 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1418 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1419 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1420 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1421 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1422 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1423 | pipelineobj.AddShader(&vs); |
| 1424 | pipelineobj.AddShader(&ps); |
| 1425 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1426 | VkDescriptorSetObj descriptorSet(m_device); |
Tony Barbour | 831062d | 2015-04-02 15:43:15 -0600 | [diff] [blame] | 1427 | descriptorSet.AppendDummy(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1428 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1429 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1430 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1431 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 1432 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1433 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1434 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1435 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1436 | |
| 1437 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1438 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1439 | pDSDumpDot((char*)"triTest2.dot"); |
| 1440 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1441 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1442 | // render triangle |
| 1443 | cmdBuffer.Draw(0, 3, 0, 1); |
| 1444 | |
| 1445 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1446 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1447 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1448 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1449 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1452 | TEST_F(VkRenderTest, QuadVertFetchAndVertID) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1453 | { |
| 1454 | // This tests that attributes work in the presence of gl_VertexID |
| 1455 | |
| 1456 | static const char *vertShaderText = |
| 1457 | "#version 140\n" |
| 1458 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1459 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1460 | //XYZ1( -1, -1, -1 ) |
| 1461 | "layout (location = 0) in vec4 pos;\n" |
| 1462 | //XYZ1( 0.f, 0.f, 0.f ) |
| 1463 | "layout (location = 1) in vec4 inColor;\n" |
| 1464 | "layout (location = 0) out vec4 outColor;\n" |
| 1465 | "void main() {\n" |
| 1466 | " outColor = inColor;\n" |
| 1467 | " vec4 vertices[3];" |
| 1468 | " vertices[gl_VertexID % 3] = pos;\n" |
| 1469 | " gl_Position = vertices[(gl_VertexID + 3) % 3];\n" |
| 1470 | "}\n"; |
| 1471 | |
| 1472 | |
| 1473 | static const char *fragShaderText = |
| 1474 | "#version 140\n" |
| 1475 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1476 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1477 | "layout (location = 0) in vec4 color;\n" |
| 1478 | "void main() {\n" |
| 1479 | " gl_FragColor = color;\n" |
| 1480 | "}\n"; |
| 1481 | |
| 1482 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1483 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1484 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1485 | VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1486 | meshBuffer.BufferMemoryBarrier(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1487 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1488 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1489 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1490 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1491 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1492 | pipelineobj.AddShader(&vs); |
| 1493 | pipelineobj.AddShader(&ps); |
| 1494 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1495 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1496 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer); |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 1497 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1498 | #define MESH_BUF_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1499 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1500 | MESH_BUF_ID, // Binding ID |
| 1501 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1502 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1503 | }; |
| 1504 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1505 | VkVertexInputAttributeDescription vi_attribs[2]; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1506 | vi_attribs[0].binding = MESH_BUF_ID; // binding ID |
| 1507 | vi_attribs[0].location = 0; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1508 | vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1509 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1510 | vi_attribs[1].binding = MESH_BUF_ID; // binding ID |
| 1511 | vi_attribs[1].location = 1; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1512 | vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1513 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1514 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1515 | pipelineobj.AddVertexInputAttribs(vi_attribs, 2); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1516 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1517 | pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1518 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1519 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1520 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1521 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 1522 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1523 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1524 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1525 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1526 | |
| 1527 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 1528 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1529 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1530 | pDSDumpDot((char*)"triTest2.dot"); |
| 1531 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1532 | |
| 1533 | // render two triangles |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1534 | cmdBuffer.Draw(0, 6, 0, 1); |
| 1535 | |
| 1536 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1537 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1538 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1539 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1540 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1543 | TEST_F(VkRenderTest, QuadSparseVertFetch) |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1544 | { |
| 1545 | // This tests that attributes work in the presence of gl_VertexID |
| 1546 | |
| 1547 | static const char *vertShaderText = |
| 1548 | "#version 140\n" |
| 1549 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1550 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1551 | //XYZ1( -1, -1, -1 ) |
| 1552 | "layout (location = 1) in vec4 pos;\n" |
| 1553 | "layout (location = 4) in vec4 inColor;\n" |
| 1554 | //XYZ1( 0.f, 0.f, 0.f ) |
| 1555 | "layout (location = 0) out vec4 outColor;\n" |
| 1556 | "void main() {\n" |
| 1557 | " outColor = inColor;\n" |
| 1558 | " gl_Position = pos;\n" |
| 1559 | "}\n"; |
| 1560 | |
| 1561 | |
| 1562 | static const char *fragShaderText = |
| 1563 | "#version 140\n" |
| 1564 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1565 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1566 | "layout (location = 0) in vec4 color;\n" |
| 1567 | "void main() {\n" |
| 1568 | " gl_FragColor = color;\n" |
| 1569 | "}\n"; |
| 1570 | |
| 1571 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1572 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1573 | |
| 1574 | struct VDATA |
| 1575 | { |
| 1576 | float t1, t2, t3, t4; // filler data |
| 1577 | float posX, posY, posZ, posW; // Position data |
| 1578 | float r, g, b, a; // Color |
| 1579 | }; |
| 1580 | const struct VDATA vData[] = |
| 1581 | { |
| 1582 | { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 1583 | { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 1584 | { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 1585 | { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 1586 | { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 1587 | { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 1588 | }; |
| 1589 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1590 | VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData); |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1591 | meshBuffer.BufferMemoryBarrier(); |
| 1592 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1593 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1594 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1595 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1596 | VkPipelineObj pipelineobj(m_device); |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1597 | pipelineobj.AddShader(&vs); |
| 1598 | pipelineobj.AddShader(&ps); |
| 1599 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1600 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1601 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer); |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1602 | |
| 1603 | #define MESH_BUF_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1604 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1605 | MESH_BUF_ID, // Binding ID |
| 1606 | sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1607 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1608 | }; |
| 1609 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1610 | VkVertexInputAttributeDescription vi_attribs[2]; |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1611 | vi_attribs[0].binding = MESH_BUF_ID; // binding ID |
| 1612 | vi_attribs[0].location = 4; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1613 | vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1614 | vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex |
| 1615 | vi_attribs[1].binding = MESH_BUF_ID; // binding ID |
| 1616 | vi_attribs[1].location = 1; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1617 | vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1618 | vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex |
| 1619 | |
| 1620 | pipelineobj.AddVertexInputAttribs(vi_attribs, 2); |
| 1621 | pipelineobj.AddVertexInputBindings(&vi_binding, 1); |
| 1622 | pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID); |
| 1623 | |
| 1624 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1625 | VkCommandBufferObj cmdBuffer(m_device); |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1626 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 1627 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1628 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1629 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1630 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1631 | |
| 1632 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID); |
| 1633 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1634 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1635 | pDSDumpDot((char*)"triTest2.dot"); |
| 1636 | #endif |
| 1637 | |
| 1638 | // render two triangles |
| 1639 | cmdBuffer.Draw(0, 6, 0, 1); |
| 1640 | |
| 1641 | // finalize recording of the command buffer |
| 1642 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1643 | cmdBuffer.QueueCommandBuffer(); |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1644 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1645 | RecordImages(m_renderTargets); |
Courtney Goeltzenleuchter | f35a514 | 2015-03-31 16:39:32 -0600 | [diff] [blame] | 1646 | } |
| 1647 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1648 | TEST_F(VkRenderTest, TriVertFetchDeadAttr) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1649 | { |
| 1650 | // This tests that attributes work in the presence of gl_VertexID |
| 1651 | // and a dead attribute in position 0. Draws a triangle with yellow, |
| 1652 | // red and green corners, starting at top and going clockwise. |
| 1653 | |
| 1654 | static const char *vertShaderText = |
| 1655 | "#version 140\n" |
| 1656 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1657 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1658 | //XYZ1( -1, -1, -1 ) |
| 1659 | "layout (location = 0) in vec4 pos;\n" |
| 1660 | //XYZ1( 0.f, 0.f, 0.f ) |
| 1661 | "layout (location = 1) in vec4 inColor;\n" |
| 1662 | "layout (location = 0) out vec4 outColor;\n" |
| 1663 | "void main() {\n" |
| 1664 | " outColor = inColor;\n" |
| 1665 | " vec2 vertices[3];" |
| 1666 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 1667 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 1668 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 1669 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1670 | "}\n"; |
| 1671 | |
| 1672 | |
| 1673 | static const char *fragShaderText = |
| 1674 | "#version 140\n" |
| 1675 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1676 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1677 | "layout (location = 0) in vec4 color;\n" |
| 1678 | "void main() {\n" |
| 1679 | " gl_FragColor = color;\n" |
| 1680 | "}\n"; |
| 1681 | |
| 1682 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1683 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1684 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1685 | VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1686 | meshBuffer.BufferMemoryBarrier(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1687 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1688 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1689 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1690 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1691 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1692 | pipelineobj.AddShader(&vs); |
| 1693 | pipelineobj.AddShader(&ps); |
| 1694 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1695 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1696 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer); |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 1697 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1698 | #define MESH_BUF_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1699 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1700 | MESH_BUF_ID, // Binding ID |
| 1701 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1702 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1703 | }; |
| 1704 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1705 | VkVertexInputAttributeDescription vi_attribs[2]; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1706 | vi_attribs[0].binding = MESH_BUF_ID; // binding ID |
| 1707 | vi_attribs[0].location = 0; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1708 | vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1709 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1710 | vi_attribs[1].binding = MESH_BUF_ID; // binding ID |
| 1711 | vi_attribs[1].location = 1; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1712 | vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1713 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1714 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1715 | pipelineobj.AddVertexInputAttribs(vi_attribs, 2); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1716 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1717 | pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1718 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1719 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1720 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1721 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1722 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1723 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1724 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1725 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1726 | |
| 1727 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 1728 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1729 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1730 | pDSDumpDot((char*)"triTest2.dot"); |
| 1731 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1732 | |
| 1733 | // render two triangles |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1734 | cmdBuffer.Draw(0, 6, 0, 1); |
| 1735 | |
| 1736 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1737 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1738 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1739 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1740 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1743 | TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP) |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1744 | { |
| 1745 | static const char *vertShaderText = |
| 1746 | "#version 140\n" |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1747 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1748 | "#extension GL_ARB_shading_language_420pack : enable\n" |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1749 | "layout (std140) uniform bufferVals {\n" |
| 1750 | " mat4 mvp;\n" |
| 1751 | "} myBufferVals;\n" |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1752 | "layout (location = 0) in vec4 pos;\n" |
| 1753 | "layout (location = 1) in vec4 inColor;\n" |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1754 | "out vec4 outColor;\n" |
| 1755 | "void main() {\n" |
| 1756 | " outColor = inColor;\n" |
| 1757 | " gl_Position = myBufferVals.mvp * pos;\n" |
| 1758 | "}\n"; |
| 1759 | |
| 1760 | static const char *fragShaderText = |
| 1761 | "#version 130\n" |
| 1762 | "in vec4 color;\n" |
| 1763 | "void main() {\n" |
| 1764 | " gl_FragColor = color;\n" |
| 1765 | "}\n"; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1766 | glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f); |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1767 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1768 | glm::mat4 View = glm::lookAt( |
| 1769 | glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space |
| 1770 | glm::vec3(0,0,0), // and looks at the origin |
| 1771 | glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down) |
| 1772 | ); |
| 1773 | |
| 1774 | glm::mat4 Model = glm::mat4(1.0f); |
| 1775 | |
| 1776 | glm::mat4 MVP = Projection * View * Model; |
| 1777 | |
| 1778 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1779 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1780 | m_depthStencil->Init(m_device, m_width, m_height); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1781 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1782 | VkConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]), |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1783 | sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data); |
| 1784 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1785 | const int buf_size = sizeof(MVP) / sizeof(float); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1786 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1787 | VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]); |
| 1788 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1789 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1790 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1791 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1792 | pipelineobj.AddShader(&vs); |
| 1793 | pipelineobj.AddShader(&ps); |
| 1794 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1795 | VkPipelineDsStateCreateInfo ds_state; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1796 | ds_state.depthTestEnable = VK_TRUE; |
| 1797 | ds_state.depthWriteEnable = VK_TRUE; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1798 | ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1799 | ds_state.depthBoundsEnable = VK_FALSE; |
| 1800 | ds_state.stencilTestEnable = VK_FALSE; |
| 1801 | ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP; |
| 1802 | ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP; |
| 1803 | ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1804 | ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS; |
| 1805 | ds_state.format = VK_FORMAT_D32_SFLOAT; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1806 | ds_state.front = ds_state.back; |
| 1807 | pipelineobj.SetDepthStencil(&ds_state); |
| 1808 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1809 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1810 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1811 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1812 | #define MESH_BUF_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1813 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1814 | MESH_BUF_ID, // Binding ID |
| 1815 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1816 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1817 | }; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1818 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1819 | VkVertexInputAttributeDescription vi_attribs[2]; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1820 | vi_attribs[0].binding = MESH_BUF_ID; // binding ID |
| 1821 | vi_attribs[0].location = 0; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1822 | vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1823 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1824 | vi_attribs[1].binding = MESH_BUF_ID; // binding ID |
| 1825 | vi_attribs[1].location = 1; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1826 | vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1827 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1828 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1829 | pipelineobj.AddVertexInputAttribs(vi_attribs, 2); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1830 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 1831 | pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1832 | |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1833 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo())); |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1834 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1835 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 1836 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1837 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1838 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1839 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1840 | |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 1841 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 1842 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1843 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 1844 | pDSDumpDot((char*)"triTest2.dot"); |
| 1845 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1846 | |
| 1847 | // render triangles |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 1848 | cmdBuffer.Draw(0, 36, 0, 1); |
| 1849 | |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1850 | |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 1851 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1852 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1853 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 1fde694 | 2015-01-09 10:06:53 -0700 | [diff] [blame] | 1854 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1855 | RecordImages(m_renderTargets); |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1856 | } |
| 1857 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1858 | TEST_F(VkRenderTest, VSTexture) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1859 | { |
| 1860 | // The expected result from this test is a green and red triangle; |
| 1861 | // one red vertex on the left, two green vertices on the right. |
| 1862 | static const char *vertShaderText = |
| 1863 | "#version 130\n" |
| 1864 | "out vec4 texColor;\n" |
| 1865 | "uniform sampler2D surface;\n" |
| 1866 | "void main() {\n" |
| 1867 | " vec2 vertices[3];" |
| 1868 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1869 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1870 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 1871 | " vec2 positions[3];" |
| 1872 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 1873 | " positions[1] = vec2( 0.25, 0.1);\n" |
| 1874 | " positions[2] = vec2( 0.1, 0.25);\n" |
| 1875 | " vec2 samplePos = positions[gl_VertexID % 3];\n" |
| 1876 | " texColor = textureLod(surface, samplePos, 0.0);\n" |
| 1877 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1878 | "}\n"; |
| 1879 | |
| 1880 | static const char *fragShaderText = |
| 1881 | "#version 130\n" |
| 1882 | "in vec4 texColor;\n" |
| 1883 | "void main() {\n" |
| 1884 | " gl_FragColor = texColor;\n" |
| 1885 | "}\n"; |
| 1886 | |
| 1887 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1888 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1889 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1890 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1891 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
| 1892 | VkSamplerObj sampler(m_device); |
| 1893 | VkTextureObj texture(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1894 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1895 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1896 | pipelineobj.AddShader(&vs); |
| 1897 | pipelineobj.AddShader(&ps); |
| 1898 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1899 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1900 | descriptorSet.AppendSamplerTexture(&sampler, &texture); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1901 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1902 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1903 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1904 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1905 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1906 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1907 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1908 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1909 | |
| 1910 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1911 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1912 | pDSDumpDot((char*)"triTest2.dot"); |
| 1913 | #endif |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1914 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1915 | // render triangle |
| 1916 | cmdBuffer.Draw(0, 3, 0, 1); |
| 1917 | |
| 1918 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1919 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1920 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1921 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1922 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1923 | } |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1924 | TEST_F(VkRenderTest, TexturedTriangle) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1925 | { |
| 1926 | // The expected result from this test is a red and green checkered triangle |
| 1927 | static const char *vertShaderText = |
| 1928 | "#version 140\n" |
| 1929 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1930 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1931 | "layout (location = 0) out vec2 samplePos;\n" |
| 1932 | "void main() {\n" |
| 1933 | " vec2 vertices[3];" |
| 1934 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1935 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1936 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 1937 | " vec2 positions[3];" |
| 1938 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 1939 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 1940 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 1941 | " samplePos = positions[gl_VertexID % 3];\n" |
| 1942 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1943 | "}\n"; |
| 1944 | |
| 1945 | static const char *fragShaderText = |
| 1946 | "#version 140\n" |
| 1947 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1948 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1949 | "layout (location = 0) in vec2 samplePos;\n" |
| 1950 | "layout (binding = 0) uniform sampler2D surface;\n" |
| 1951 | "layout (location=0) out vec4 outColor;\n" |
| 1952 | "void main() {\n" |
| 1953 | " vec4 texColor = textureLod(surface, samplePos, 0.0);\n" |
| 1954 | " outColor = texColor;\n" |
| 1955 | "}\n"; |
| 1956 | |
| 1957 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1958 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1959 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1960 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 1961 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
| 1962 | VkSamplerObj sampler(m_device); |
| 1963 | VkTextureObj texture(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1964 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1965 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1966 | pipelineobj.AddShader(&vs); |
| 1967 | pipelineobj.AddShader(&ps); |
| 1968 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1969 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1970 | descriptorSet.AppendSamplerTexture(&sampler, &texture); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1971 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1972 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1973 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1974 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 1975 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1976 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1977 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1978 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1979 | |
| 1980 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1981 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1982 | pDSDumpDot((char*)"triTest2.dot"); |
| 1983 | #endif |
| 1984 | // render triangle |
| 1985 | cmdBuffer.Draw(0, 3, 0, 1); |
| 1986 | |
| 1987 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1988 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1989 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 1990 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 1991 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1992 | } |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1993 | TEST_F(VkRenderTest, TexturedTriangleClip) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1994 | { |
| 1995 | // The expected result from this test is a red and green checkered triangle |
| 1996 | static const char *vertShaderText = |
| 1997 | "#version 330\n" |
| 1998 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1999 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2000 | "layout (location = 0) out vec2 samplePos;\n" |
| 2001 | "out gl_PerVertex {\n" |
| 2002 | " vec4 gl_Position;\n" |
| 2003 | " float gl_ClipDistance[1];\n" |
| 2004 | "};\n" |
| 2005 | "void main() {\n" |
| 2006 | " vec2 vertices[3];" |
| 2007 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2008 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2009 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2010 | " vec2 positions[3];" |
| 2011 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 2012 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 2013 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 2014 | " float dists[3];\n" |
| 2015 | " dists[0] = 1.0;\n" |
| 2016 | " dists[1] = 1.0;\n" |
| 2017 | " dists[2] = -1.0;\n" |
| 2018 | " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n" |
| 2019 | " samplePos = positions[gl_VertexID % 3];\n" |
| 2020 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2021 | "}\n"; |
| 2022 | |
| 2023 | static const char *fragShaderText = |
| 2024 | "#version 140\n" |
| 2025 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2026 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2027 | "layout (location = 0) in vec2 samplePos;\n" |
| 2028 | "layout (binding = 0) uniform sampler2D surface;\n" |
| 2029 | "layout (location=0) out vec4 outColor;\n" |
| 2030 | "void main() {\n" |
| 2031 | //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n" |
| 2032 | " vec4 texColor = textureLod(surface, samplePos, 0.0);\n" |
| 2033 | " outColor = texColor;\n" |
| 2034 | "}\n"; |
| 2035 | |
| 2036 | |
| 2037 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2038 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2039 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2040 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 2041 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
| 2042 | VkSamplerObj sampler(m_device); |
| 2043 | VkTextureObj texture(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2044 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2045 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2046 | pipelineobj.AddShader(&vs); |
| 2047 | pipelineobj.AddShader(&ps); |
| 2048 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2049 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2050 | descriptorSet.AppendSamplerTexture(&sampler, &texture); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2051 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2052 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2053 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2054 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 2055 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2056 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2057 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2058 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2059 | |
| 2060 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2061 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2062 | pDSDumpDot((char*)"triTest2.dot"); |
| 2063 | #endif |
| 2064 | // render triangle |
| 2065 | cmdBuffer.Draw(0, 3, 0, 1); |
| 2066 | |
| 2067 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 2068 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2069 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2070 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 2071 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2072 | } |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2073 | TEST_F(VkRenderTest, FSTriangle) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2074 | { |
| 2075 | // The expected result from this test is a red and green checkered triangle |
| 2076 | static const char *vertShaderText = |
| 2077 | "#version 140\n" |
| 2078 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2079 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2080 | "layout (location = 0) out vec2 samplePos;\n" |
| 2081 | "void main() {\n" |
| 2082 | " vec2 vertices[3];" |
| 2083 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2084 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2085 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2086 | " vec2 positions[3];" |
| 2087 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 2088 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 2089 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 2090 | " samplePos = positions[gl_VertexID % 3];\n" |
| 2091 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2092 | "}\n"; |
| 2093 | |
| 2094 | static const char *fragShaderText = |
| 2095 | "#version 140\n" |
| 2096 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2097 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2098 | "layout (location = 0) in vec2 samplePos;\n" |
| 2099 | "layout (binding = 0) uniform sampler2D surface;\n" |
| 2100 | "layout (location=0) out vec4 outColor;\n" |
| 2101 | "void main() {\n" |
| 2102 | " vec4 texColor = textureLod(surface, samplePos, 0.0);\n" |
| 2103 | " outColor = texColor;\n" |
| 2104 | "}\n"; |
| 2105 | |
| 2106 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2107 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2108 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2109 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 2110 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
| 2111 | VkSamplerObj sampler(m_device); |
| 2112 | VkTextureObj texture(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2113 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2114 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2115 | pipelineobj.AddShader(&vs); |
| 2116 | pipelineobj.AddShader(&ps); |
| 2117 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2118 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2119 | descriptorSet.AppendSamplerTexture(&sampler, &texture); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2120 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2121 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2122 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2123 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 2124 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2125 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2126 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2127 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2128 | |
| 2129 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2130 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2131 | pDSDumpDot((char*)"triTest2.dot"); |
| 2132 | #endif |
| 2133 | // render triangle |
| 2134 | cmdBuffer.Draw(0, 3, 0, 1); |
| 2135 | |
| 2136 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 2137 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2138 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2139 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 2140 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2141 | } |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2142 | TEST_F(VkRenderTest, SamplerBindingsTriangle) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2143 | { |
| 2144 | // This test sets bindings on the samplers |
| 2145 | // For now we are asserting that sampler and texture pairs |
| 2146 | // march in lock step, and are set via GLSL binding. This can |
| 2147 | // and will probably change. |
| 2148 | // The sampler bindings should match the sampler and texture slot |
| 2149 | // number set up by the application. |
| 2150 | // This test will result in a blue triangle |
| 2151 | static const char *vertShaderText = |
| 2152 | "#version 140\n" |
| 2153 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2154 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2155 | "layout (location = 0) out vec4 samplePos;\n" |
| 2156 | "void main() {\n" |
| 2157 | " vec2 vertices[3];" |
| 2158 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2159 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2160 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2161 | " vec2 positions[3];" |
| 2162 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 2163 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 2164 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 2165 | " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n" |
| 2166 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2167 | "}\n"; |
| 2168 | |
| 2169 | static const char *fragShaderText = |
| 2170 | "#version 140\n" |
| 2171 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2172 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2173 | "layout (location = 0) in vec4 samplePos;\n" |
| 2174 | "layout (binding = 0) uniform sampler2D surface0;\n" |
| 2175 | "layout (binding = 1) uniform sampler2D surface1;\n" |
| 2176 | "layout (binding = 12) uniform sampler2D surface2;\n" |
| 2177 | "void main() {\n" |
| 2178 | " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n" |
| 2179 | "}\n"; |
| 2180 | |
| 2181 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2182 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2183 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2184 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 2185 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2186 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2187 | VkSamplerObj sampler1(m_device); |
| 2188 | VkSamplerObj sampler2(m_device); |
| 2189 | VkSamplerObj sampler3(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2190 | |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2191 | uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 }; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2192 | VkTextureObj texture1(m_device, tex_colors); // Red |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2193 | tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2194 | VkTextureObj texture2(m_device, tex_colors); // Green |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2195 | tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2196 | VkTextureObj texture3(m_device, tex_colors); // Blue |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2197 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2198 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2199 | pipelineobj.AddShader(&vs); |
| 2200 | pipelineobj.AddShader(&ps); |
| 2201 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2202 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2203 | descriptorSet.AppendSamplerTexture(&sampler1, &texture1); |
| 2204 | descriptorSet.AppendSamplerTexture(&sampler2, &texture2); |
| 2205 | for (int i = 0; i < 10; i++) |
| 2206 | descriptorSet.AppendDummy(); |
| 2207 | descriptorSet.AppendSamplerTexture(&sampler3, &texture3); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2208 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2209 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2210 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2211 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 2212 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2213 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2214 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2215 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2216 | |
| 2217 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2218 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2219 | pDSDumpDot((char*)"triTest2.dot"); |
| 2220 | #endif |
| 2221 | // render triangle |
| 2222 | cmdBuffer.Draw(0, 3, 0, 1); |
| 2223 | |
| 2224 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 2225 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2226 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2227 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 2228 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2231 | TEST_F(VkRenderTest, TriangleVSUniformBlock) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2232 | { |
| 2233 | // The expected result from this test is a blue triangle |
| 2234 | |
| 2235 | static const char *vertShaderText = |
| 2236 | "#version 140\n" |
| 2237 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2238 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2239 | "layout (location = 0) out vec4 outColor;\n" |
| 2240 | "layout (std140, binding = 0) uniform bufferVals {\n" |
| 2241 | " vec4 red;\n" |
| 2242 | " vec4 green;\n" |
| 2243 | " vec4 blue;\n" |
| 2244 | " vec4 white;\n" |
| 2245 | "} myBufferVals;\n" |
| 2246 | "void main() {\n" |
| 2247 | " vec2 vertices[3];" |
| 2248 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2249 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2250 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2251 | " outColor = myBufferVals.blue;\n" |
| 2252 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2253 | "}\n"; |
| 2254 | |
| 2255 | static const char *fragShaderText = |
| 2256 | "#version 140\n" |
| 2257 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2258 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2259 | "layout (location = 0) in vec4 inColor;\n" |
| 2260 | "void main() {\n" |
| 2261 | " gl_FragColor = inColor;\n" |
| 2262 | "}\n"; |
| 2263 | |
| 2264 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2265 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2266 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2267 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 2268 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2269 | |
| 2270 | // Let's populate our buffer with the following: |
| 2271 | // vec4 red; |
| 2272 | // vec4 green; |
| 2273 | // vec4 blue; |
| 2274 | // vec4 white; |
| 2275 | const int valCount = 4 * 4; |
| 2276 | const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0, |
| 2277 | 0.0, 1.0, 0.0, 1.0, |
| 2278 | 0.0, 0.0, 1.0, 1.0, |
| 2279 | 1.0, 1.0, 1.0, 1.0 }; |
| 2280 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2281 | VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2282 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2283 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2284 | pipelineobj.AddShader(&vs); |
| 2285 | pipelineobj.AddShader(&ps); |
| 2286 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2287 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2288 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2289 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2290 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2291 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2292 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 2293 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2294 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2295 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2296 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2297 | |
| 2298 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2299 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2300 | pDSDumpDot((char*)"triTest2.dot"); |
| 2301 | #endif |
| 2302 | // render triangle |
| 2303 | cmdBuffer.Draw(0, 3, 0, 1); |
| 2304 | |
| 2305 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 2306 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2307 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2308 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 2309 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2310 | } |
| 2311 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2312 | TEST_F(VkRenderTest, TriangleFSUniformBlockBinding) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2313 | { |
| 2314 | // This test allows the shader to select which buffer it is |
| 2315 | // pulling from using layout binding qualifier. |
| 2316 | // There are corresponding changes in the compiler stack that |
| 2317 | // will select the buffer using binding directly. |
| 2318 | // The binding number should match the slot number set up by |
| 2319 | // the application. |
| 2320 | // The expected result from this test is a purple triangle |
| 2321 | |
| 2322 | static const char *vertShaderText = |
| 2323 | "#version 140\n" |
| 2324 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2325 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2326 | "void main() {\n" |
| 2327 | " vec2 vertices[3];" |
| 2328 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2329 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2330 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2331 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2332 | "}\n"; |
| 2333 | |
| 2334 | static const char *fragShaderText = |
| 2335 | "#version 140\n" |
| 2336 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2337 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2338 | "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;" |
| 2339 | "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;" |
| 2340 | "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;" |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2341 | "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2342 | "void main() {\n" |
| 2343 | " gl_FragColor = myBlueVal.color;\n" |
| 2344 | " gl_FragColor += myRedVal.color;\n" |
| 2345 | "}\n"; |
| 2346 | |
| 2347 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2348 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2349 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2350 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 2351 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2352 | |
| 2353 | // We're going to create a number of uniform buffers, and then allow |
| 2354 | // the shader to select which it wants to read from with a binding |
| 2355 | |
| 2356 | // Let's populate the buffers with a single color each: |
| 2357 | // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal; |
| 2358 | // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal; |
| 2359 | // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal; |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2360 | // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2361 | |
| 2362 | const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 }; |
| 2363 | const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 }; |
| 2364 | const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 }; |
| 2365 | const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 2366 | |
| 2367 | const int redCount = sizeof(redVals) / sizeof(float); |
| 2368 | const int greenCount = sizeof(greenVals) / sizeof(float); |
| 2369 | const int blueCount = sizeof(blueVals) / sizeof(float); |
| 2370 | const int whiteCount = sizeof(whiteVals) / sizeof(float); |
| 2371 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2372 | VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2373 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2374 | VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2375 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2376 | VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2377 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2378 | VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2379 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2380 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2381 | pipelineobj.AddShader(&vs); |
| 2382 | pipelineobj.AddShader(&ps); |
| 2383 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2384 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2385 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer); |
| 2386 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer); |
| 2387 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer); |
| 2388 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2389 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2390 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2391 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2392 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2393 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2394 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2395 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2396 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2397 | |
| 2398 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2399 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2400 | pDSDumpDot((char*)"triTest2.dot"); |
| 2401 | #endif |
| 2402 | // render triangle |
| 2403 | cmdBuffer.Draw(0, 3, 0, 1); |
| 2404 | |
| 2405 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 2406 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2407 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2408 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 2409 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2412 | TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2413 | { |
| 2414 | // This test is the same as TriangleFSUniformBlockBinding, but |
| 2415 | // it does not provide an instance name. |
| 2416 | // The expected result from this test is a purple triangle |
| 2417 | |
| 2418 | static const char *vertShaderText = |
| 2419 | "#version 140\n" |
| 2420 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2421 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2422 | "void main() {\n" |
| 2423 | " vec2 vertices[3];" |
| 2424 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2425 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2426 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2427 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2428 | "}\n"; |
| 2429 | |
| 2430 | static const char *fragShaderText = |
| 2431 | "#version 430\n" |
| 2432 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2433 | "#extension GL_ARB_shading_language_420pack : enable\n" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2434 | "layout (std140, binding = 0) uniform redVal { vec4 red; };" |
| 2435 | "layout (std140, binding = 1) uniform greenVal { vec4 green; };" |
| 2436 | "layout (std140, binding = 2) uniform blueVal { vec4 blue; };" |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2437 | "layout (std140, binding = 3) uniform whiteVal { vec4 white; };" |
Cody Northrop | d43c52e | 2014-12-05 15:44:14 -0700 | [diff] [blame] | 2438 | "layout (location = 0) out vec4 outColor;\n" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2439 | "void main() {\n" |
Cody Northrop | d43c52e | 2014-12-05 15:44:14 -0700 | [diff] [blame] | 2440 | " outColor = blue;\n" |
| 2441 | " outColor += red;\n" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2442 | "}\n"; |
| 2443 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2444 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2445 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2446 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 2447 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2448 | |
| 2449 | // We're going to create a number of uniform buffers, and then allow |
| 2450 | // the shader to select which it wants to read from with a binding |
| 2451 | |
| 2452 | // Let's populate the buffers with a single color each: |
| 2453 | // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal; |
| 2454 | // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal; |
| 2455 | // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal; |
| 2456 | // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal; |
| 2457 | |
| 2458 | const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 }; |
| 2459 | const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 }; |
| 2460 | const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 }; |
| 2461 | const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 2462 | |
| 2463 | const int redCount = sizeof(redVals) / sizeof(float); |
| 2464 | const int greenCount = sizeof(greenVals) / sizeof(float); |
| 2465 | const int blueCount = sizeof(blueVals) / sizeof(float); |
| 2466 | const int whiteCount = sizeof(whiteVals) / sizeof(float); |
| 2467 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2468 | VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2469 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2470 | VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2471 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2472 | VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2473 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2474 | VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2475 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2476 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2477 | pipelineobj.AddShader(&vs); |
| 2478 | pipelineobj.AddShader(&ps); |
| 2479 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2480 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2481 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer); |
| 2482 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer); |
| 2483 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer); |
| 2484 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2485 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2486 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2487 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2488 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 2489 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2490 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2491 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2492 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2493 | |
| 2494 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2495 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2496 | pDSDumpDot((char*)"triTest2.dot"); |
| 2497 | #endif |
| 2498 | // render triangle |
| 2499 | cmdBuffer.Draw(0, 3, 0, 1); |
| 2500 | |
| 2501 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 2502 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2503 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2504 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 2505 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2508 | TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2509 | { |
| 2510 | static const char *vertShaderText = |
| 2511 | "#version 140\n" |
| 2512 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2513 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2514 | "layout (std140, binding=0) uniform bufferVals {\n" |
| 2515 | " mat4 mvp;\n" |
| 2516 | "} myBufferVals;\n" |
| 2517 | "layout (location=0) in vec4 pos;\n" |
| 2518 | "layout (location=0) out vec2 UV;\n" |
| 2519 | "void main() {\n" |
| 2520 | " vec2 positions[3];" |
| 2521 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 2522 | " positions[1] = vec2( 0.25, 0.1);\n" |
| 2523 | " positions[2] = vec2( 0.1, 0.25);\n" |
| 2524 | " UV = positions[gl_VertexID % 3];\n" |
| 2525 | " gl_Position = myBufferVals.mvp * pos;\n" |
| 2526 | "}\n"; |
| 2527 | |
| 2528 | static const char *fragShaderText = |
| 2529 | "#version 140\n" |
| 2530 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2531 | "#extension GL_ARB_shading_language_420pack : enable\n" |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2532 | "layout (binding=1) uniform sampler2D surface;\n" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2533 | "layout (location=0) out vec4 outColor;\n" |
| 2534 | "layout (location=0) in vec2 UV;\n" |
| 2535 | "void main() {\n" |
| 2536 | " outColor= textureLod(surface, UV, 0.0);\n" |
| 2537 | "}\n"; |
| 2538 | glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f); |
| 2539 | |
| 2540 | glm::mat4 View = glm::lookAt( |
| 2541 | glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space |
| 2542 | glm::vec3(0,0,0), // and looks at the origin |
| 2543 | glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down) |
| 2544 | ); |
| 2545 | |
| 2546 | glm::mat4 Model = glm::mat4(1.0f); |
| 2547 | |
| 2548 | glm::mat4 MVP = Projection * View * Model; |
| 2549 | |
| 2550 | |
| 2551 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2552 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 2553 | m_depthStencil->Init(m_device, m_width, m_height); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2554 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2555 | VkConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]), |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2556 | sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 2557 | meshBuffer.BufferMemoryBarrier(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2558 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 2559 | const int buf_size = sizeof(MVP) / sizeof(float); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2560 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2561 | VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]); |
| 2562 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 2563 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
| 2564 | VkSamplerObj sampler(m_device); |
| 2565 | VkTextureObj texture(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2566 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2567 | VkPipelineObj pipelineobj(m_device); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2568 | pipelineobj.AddShader(&vs); |
| 2569 | pipelineobj.AddShader(&ps); |
| 2570 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2571 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2572 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2573 | descriptorSet.AppendSamplerTexture(&sampler, &texture); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2574 | |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 2575 | #define MESH_BIND_ID 0 |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2576 | VkVertexInputBindingDescription vi_binding = { |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 2577 | MESH_BIND_ID, // binding ID |
| 2578 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2579 | VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 2580 | }; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2581 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2582 | VkVertexInputAttributeDescription vi_attribs[2]; |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 2583 | vi_attribs[0].binding = MESH_BIND_ID; // Binding ID |
| 2584 | vi_attribs[0].location = 0; // location |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 2585 | vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 2586 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 2587 | vi_attribs[1].binding = MESH_BIND_ID; // Binding ID |
| 2588 | vi_attribs[1].location = 1; // location |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 2589 | vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 2590 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2591 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2592 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
Courtney Goeltzenleuchter | 0d62527 | 2015-03-31 16:36:30 -0600 | [diff] [blame] | 2593 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 2594 | pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2595 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2596 | VkPipelineDsStateCreateInfo ds_state; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2597 | ds_state.depthTestEnable = VK_TRUE; |
| 2598 | ds_state.depthWriteEnable = VK_TRUE; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 2599 | ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2600 | ds_state.depthBoundsEnable = VK_FALSE; |
| 2601 | ds_state.stencilTestEnable = VK_FALSE; |
| 2602 | ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP; |
| 2603 | ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP; |
| 2604 | ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 2605 | ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS; |
| 2606 | ds_state.format = VK_FORMAT_D32_SFLOAT; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 2607 | ds_state.front = ds_state.back; |
| 2608 | pipelineobj.SetDepthStencil(&ds_state); |
| 2609 | |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 2610 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo())); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2611 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2612 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2613 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2614 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 2615 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2616 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2617 | |
| 2618 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 2619 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2620 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2621 | pDSDumpDot((char*)"triTest2.dot"); |
| 2622 | #endif |
| 2623 | // render triangle |
| 2624 | cmdBuffer.Draw(0, 36, 0, 1); |
| 2625 | |
| 2626 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 2627 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2628 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2629 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 2630 | RecordImages(m_renderTargets); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2631 | } |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2632 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2633 | TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding) |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2634 | { |
| 2635 | // This test mixes binding slots of textures and buffers, ensuring |
| 2636 | // that sparse and overlapping assignments work. |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2637 | // The expected result from this test is a purple triangle, although |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2638 | // you can modify it to move the desired result around. |
| 2639 | |
| 2640 | static const char *vertShaderText = |
| 2641 | "#version 140\n" |
| 2642 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2643 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2644 | "void main() {\n" |
| 2645 | " vec2 vertices[3];" |
| 2646 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2647 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2648 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2649 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2650 | "}\n"; |
| 2651 | |
| 2652 | static const char *fragShaderText = |
| 2653 | "#version 430\n" |
| 2654 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2655 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2656 | "layout (binding = 0) uniform sampler2D surface0;\n" |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2657 | "layout (binding = 3) uniform sampler2D surface1;\n" |
| 2658 | "layout (binding = 1) uniform sampler2D surface2;\n" |
| 2659 | "layout (binding = 2) uniform sampler2D surface3;\n" |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2660 | |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2661 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2662 | "layout (std140, binding = 4) uniform redVal { vec4 red; };" |
| 2663 | "layout (std140, binding = 6) uniform greenVal { vec4 green; };" |
| 2664 | "layout (std140, binding = 5) uniform blueVal { vec4 blue; };" |
| 2665 | "layout (std140, binding = 7) uniform whiteVal { vec4 white; };" |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2666 | "layout (location = 0) out vec4 outColor;\n" |
| 2667 | "void main() {\n" |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2668 | " outColor = red * vec4(0.00001);\n" |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2669 | " outColor += white * vec4(0.00001);\n" |
| 2670 | " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n" |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2671 | " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n" |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2672 | "}\n"; |
| 2673 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2674 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2675 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2676 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 2677 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2678 | |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2679 | const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 }; |
| 2680 | const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 }; |
| 2681 | const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 }; |
| 2682 | const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 2683 | |
| 2684 | const int redCount = sizeof(redVals) / sizeof(float); |
| 2685 | const int greenCount = sizeof(greenVals) / sizeof(float); |
| 2686 | const int blueCount = sizeof(blueVals) / sizeof(float); |
| 2687 | const int whiteCount = sizeof(whiteVals) / sizeof(float); |
| 2688 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2689 | VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals); |
| 2690 | VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals); |
| 2691 | VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals); |
| 2692 | VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2693 | |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2694 | uint32_t tex_colors[2] = { 0xff800000, 0xff800000 }; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2695 | VkSamplerObj sampler0(m_device); |
| 2696 | VkTextureObj texture0(m_device, tex_colors); // Light Red |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2697 | tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2698 | VkSamplerObj sampler2(m_device); |
| 2699 | VkTextureObj texture2(m_device, tex_colors); // Light Blue |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2700 | tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2701 | VkSamplerObj sampler4(m_device); |
| 2702 | VkTextureObj texture4(m_device, tex_colors); // Light Green |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2703 | |
| 2704 | // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!! |
| 2705 | // TODO: Get back here ASAP and understand why. |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2706 | tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2707 | VkSamplerObj sampler7(m_device); |
| 2708 | VkTextureObj texture7(m_device, tex_colors); // Red and Blue |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2709 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2710 | VkPipelineObj pipelineobj(m_device); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2711 | pipelineobj.AddShader(&vs); |
| 2712 | pipelineobj.AddShader(&ps); |
| 2713 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2714 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2715 | descriptorSet.AppendSamplerTexture(&sampler0, &texture0); |
| 2716 | descriptorSet.AppendSamplerTexture(&sampler2, &texture2); |
| 2717 | descriptorSet.AppendSamplerTexture(&sampler4, &texture4); |
| 2718 | descriptorSet.AppendSamplerTexture(&sampler7, &texture7); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2719 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2720 | // swap blue and green |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2721 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer); |
| 2722 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer); |
| 2723 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2724 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2725 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2726 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2727 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2728 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2729 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2730 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2731 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2732 | |
| 2733 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2734 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2735 | pDSDumpDot((char*)"triTest2.dot"); |
| 2736 | #endif |
| 2737 | // render triangle |
| 2738 | cmdBuffer.Draw(0, 3, 0, 1); |
| 2739 | |
| 2740 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 2741 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2742 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2743 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 2744 | RecordImages(m_renderTargets); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2747 | TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding) |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2748 | { |
| 2749 | // This test matches binding slots of textures and buffers, requiring |
| 2750 | // the driver to give them distinct number spaces. |
| 2751 | // The expected result from this test is a red triangle, although |
| 2752 | // you can modify it to move the desired result around. |
| 2753 | |
| 2754 | static const char *vertShaderText = |
| 2755 | "#version 140\n" |
| 2756 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2757 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2758 | "void main() {\n" |
| 2759 | " vec2 vertices[3];" |
| 2760 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2761 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2762 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2763 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2764 | "}\n"; |
| 2765 | |
| 2766 | static const char *fragShaderText = |
| 2767 | "#version 430\n" |
| 2768 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2769 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2770 | "layout (binding = 0) uniform sampler2D surface0;\n" |
| 2771 | "layout (binding = 1) uniform sampler2D surface1;\n" |
| 2772 | "layout (binding = 2) uniform sampler2D surface2;\n" |
| 2773 | "layout (binding = 3) uniform sampler2D surface3;\n" |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2774 | "layout (std140, binding = 4) uniform redVal { vec4 red; };" |
| 2775 | "layout (std140, binding = 5) uniform greenVal { vec4 green; };" |
| 2776 | "layout (std140, binding = 6) uniform blueVal { vec4 blue; };" |
| 2777 | "layout (std140, binding = 7) uniform whiteVal { vec4 white; };" |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2778 | "layout (location = 0) out vec4 outColor;\n" |
| 2779 | "void main() {\n" |
| 2780 | " outColor = red;// * vec4(0.00001);\n" |
| 2781 | " outColor += white * vec4(0.00001);\n" |
| 2782 | " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n" |
| 2783 | " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n" |
| 2784 | "}\n"; |
| 2785 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2786 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2787 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2788 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 2789 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2790 | |
| 2791 | const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 }; |
| 2792 | const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 }; |
| 2793 | const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 }; |
| 2794 | const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 2795 | |
| 2796 | const int redCount = sizeof(redVals) / sizeof(float); |
| 2797 | const int greenCount = sizeof(greenVals) / sizeof(float); |
| 2798 | const int blueCount = sizeof(blueVals) / sizeof(float); |
| 2799 | const int whiteCount = sizeof(whiteVals) / sizeof(float); |
| 2800 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2801 | VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals); |
| 2802 | VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals); |
| 2803 | VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals); |
| 2804 | VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals); |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2805 | |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2806 | uint32_t tex_colors[2] = { 0xff800000, 0xff800000 }; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2807 | VkSamplerObj sampler0(m_device); |
| 2808 | VkTextureObj texture0(m_device, tex_colors); // Light Red |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2809 | tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2810 | VkSamplerObj sampler2(m_device); |
| 2811 | VkTextureObj texture2(m_device, tex_colors); // Light Blue |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2812 | tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2813 | VkSamplerObj sampler4(m_device); |
| 2814 | VkTextureObj texture4(m_device, tex_colors); // Light Green |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 2815 | tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2816 | VkSamplerObj sampler7(m_device); |
| 2817 | VkTextureObj texture7(m_device, tex_colors); // Red and Blue |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2818 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2819 | VkPipelineObj pipelineobj(m_device); |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2820 | pipelineobj.AddShader(&vs); |
| 2821 | pipelineobj.AddShader(&ps); |
| 2822 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2823 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 2824 | descriptorSet.AppendSamplerTexture(&sampler0, &texture0); |
| 2825 | descriptorSet.AppendSamplerTexture(&sampler2, &texture2); |
| 2826 | descriptorSet.AppendSamplerTexture(&sampler4, &texture4); |
| 2827 | descriptorSet.AppendSamplerTexture(&sampler7, &texture7); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2828 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer); |
| 2829 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer); |
| 2830 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer); |
| 2831 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer); |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2832 | |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2833 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2834 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2835 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2836 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2837 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2838 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2839 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2840 | |
| 2841 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2842 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2843 | pDSDumpDot((char*)"triTest2.dot"); |
| 2844 | #endif |
| 2845 | // render triangle |
| 2846 | cmdBuffer.Draw(0, 3, 0, 1); |
| 2847 | |
| 2848 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 2849 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 2850 | cmdBuffer.QueueCommandBuffer(); |
Tony Barbour | 664accc | 2015-01-09 12:55:14 -0700 | [diff] [blame] | 2851 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 2852 | RecordImages(m_renderTargets); |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2853 | } |
| 2854 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2855 | TEST_F(VkRenderTest, TriangleUniformBufferLayout) |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 2856 | { |
| 2857 | // This test populates a buffer with a variety of different data |
| 2858 | // types, then reads them out with a shader. |
| 2859 | // The expected result from this test is a green triangle |
| 2860 | |
| 2861 | static const char *vertShaderText = |
| 2862 | "#version 140\n" |
| 2863 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2864 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2865 | "layout (std140, binding = 0) uniform mixedBuffer {\n" |
| 2866 | " vec4 fRed;\n" |
| 2867 | " vec4 fGreen;\n" |
| 2868 | " layout(row_major) mat4 worldToProj;\n" |
| 2869 | " layout(row_major) mat4 projToWorld;\n" |
| 2870 | " layout(row_major) mat4 worldToView;\n" |
| 2871 | " layout(row_major) mat4 viewToProj;\n" |
| 2872 | " layout(row_major) mat4 worldToShadow[4];\n" |
| 2873 | " float fZero;\n" |
| 2874 | " float fOne;\n" |
| 2875 | " float fTwo;\n" |
| 2876 | " float fThree;\n" |
| 2877 | " vec3 fZeroZeroZero;\n" |
| 2878 | " float fFour;\n" |
| 2879 | " vec3 fZeroZeroOne;\n" |
| 2880 | " float fFive;\n" |
| 2881 | " vec3 fZeroOneZero;\n" |
| 2882 | " float fSix;\n" |
| 2883 | " float fSeven;\n" |
| 2884 | " float fEight;\n" |
| 2885 | " float fNine;\n" |
| 2886 | " vec2 fZeroZero;\n" |
| 2887 | " vec2 fZeroOne;\n" |
| 2888 | " vec4 fBlue;\n" |
| 2889 | " vec2 fOneZero;\n" |
| 2890 | " vec2 fOneOne;\n" |
| 2891 | " vec3 fZeroOneOne;\n" |
| 2892 | " float fTen;\n" |
| 2893 | " float fEleven;\n" |
| 2894 | " float fTwelve;\n" |
| 2895 | " vec3 fOneZeroZero;\n" |
| 2896 | " vec4 uvOffsets[4];\n" |
| 2897 | "};\n" |
| 2898 | "layout (location = 0) out vec4 color;" |
| 2899 | "void main() {\n" |
| 2900 | |
| 2901 | " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 2902 | " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2903 | " \n" |
| 2904 | |
| 2905 | // do some exact comparisons, even though we should |
| 2906 | // really have an epsilon involved. |
| 2907 | " vec4 outColor = right;\n" |
| 2908 | " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n" |
| 2909 | " outColor = wrong;\n" |
| 2910 | " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n" |
| 2911 | " outColor = wrong;\n" |
| 2912 | " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n" |
| 2913 | " outColor = wrong;\n" |
| 2914 | |
| 2915 | " color = outColor;\n" |
| 2916 | |
| 2917 | // generic position stuff |
| 2918 | " vec2 vertices;\n" |
| 2919 | " int vertexSelector = gl_VertexID;\n" |
| 2920 | " if (vertexSelector == 0)\n" |
| 2921 | " vertices = vec2(-0.5, -0.5);\n" |
| 2922 | " else if (vertexSelector == 1)\n" |
| 2923 | " vertices = vec2( 0.5, -0.5);\n" |
| 2924 | " else if (vertexSelector == 2)\n" |
| 2925 | " vertices = vec2( 0.5, 0.5);\n" |
| 2926 | " else\n" |
| 2927 | " vertices = vec2( 0.0, 0.0);\n" |
| 2928 | " gl_Position = vec4(vertices, 0.0, 1.0);\n" |
| 2929 | "}\n"; |
| 2930 | |
| 2931 | static const char *fragShaderText = |
| 2932 | "#version 140\n" |
| 2933 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2934 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2935 | "layout (std140, binding = 0) uniform mixedBuffer {\n" |
| 2936 | " vec4 fRed;\n" |
| 2937 | " vec4 fGreen;\n" |
| 2938 | " layout(row_major) mat4 worldToProj;\n" |
| 2939 | " layout(row_major) mat4 projToWorld;\n" |
| 2940 | " layout(row_major) mat4 worldToView;\n" |
| 2941 | " layout(row_major) mat4 viewToProj;\n" |
| 2942 | " layout(row_major) mat4 worldToShadow[4];\n" |
| 2943 | " float fZero;\n" |
| 2944 | " float fOne;\n" |
| 2945 | " float fTwo;\n" |
| 2946 | " float fThree;\n" |
| 2947 | " vec3 fZeroZeroZero;\n" |
| 2948 | " float fFour;\n" |
| 2949 | " vec3 fZeroZeroOne;\n" |
| 2950 | " float fFive;\n" |
| 2951 | " vec3 fZeroOneZero;\n" |
| 2952 | " float fSix;\n" |
| 2953 | " float fSeven;\n" |
| 2954 | " float fEight;\n" |
| 2955 | " float fNine;\n" |
| 2956 | " vec2 fZeroZero;\n" |
| 2957 | " vec2 fZeroOne;\n" |
| 2958 | " vec4 fBlue;\n" |
| 2959 | " vec2 fOneZero;\n" |
| 2960 | " vec2 fOneOne;\n" |
| 2961 | " vec3 fZeroOneOne;\n" |
| 2962 | " float fTen;\n" |
| 2963 | " float fEleven;\n" |
| 2964 | " float fTwelve;\n" |
| 2965 | " vec3 fOneZeroZero;\n" |
| 2966 | " vec4 uvOffsets[4];\n" |
| 2967 | "};\n" |
| 2968 | "layout (location = 0) in vec4 color;\n" |
| 2969 | "void main() {\n" |
| 2970 | " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 2971 | " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2972 | " \n" |
| 2973 | |
| 2974 | // start with VS value to ensure it passed |
| 2975 | " vec4 outColor = color;\n" |
| 2976 | |
| 2977 | // do some exact comparisons, even though we should |
| 2978 | // really have an epsilon involved. |
| 2979 | " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n" |
| 2980 | " outColor = wrong;\n" |
| 2981 | " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n" |
| 2982 | " outColor = wrong;\n" |
| 2983 | " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n" |
| 2984 | " outColor = wrong;\n" |
| 2985 | " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n" |
| 2986 | " outColor = wrong;\n" |
| 2987 | " if (fTwo != 2.0)\n" |
| 2988 | " outColor = wrong;\n" |
| 2989 | " if (fOneOne != vec2(1.0, 1.0))\n" |
| 2990 | " outColor = wrong;\n" |
| 2991 | " if (fTen != 10.0)\n" |
| 2992 | " outColor = wrong;\n" |
| 2993 | " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n" |
| 2994 | " outColor = wrong;\n" |
| 2995 | " \n" |
| 2996 | " gl_FragColor = outColor;\n" |
| 2997 | "}\n"; |
| 2998 | |
| 2999 | |
| 3000 | const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align |
| 3001 | 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align |
| 3002 | 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj; |
| 3003 | 0.0, 1.0, 0.0, 1.0, // align |
| 3004 | 0.0, 0.0, 1.0, 1.0, // align |
| 3005 | 0.0, 0.0, 0.0, 1.0, // align |
| 3006 | 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld; |
| 3007 | 0.0, 2.0, 0.0, 2.0, // align |
| 3008 | 0.0, 0.0, 2.0, 2.0, // align |
| 3009 | 0.0, 0.0, 0.0, 2.0, // align |
| 3010 | 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView; |
| 3011 | 0.0, 3.0, 0.0, 3.0, // align |
| 3012 | 0.0, 0.0, 3.0, 3.0, // align |
| 3013 | 0.0, 0.0, 0.0, 3.0, // align |
| 3014 | 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj; |
| 3015 | 0.0, 4.0, 0.0, 4.0, // align |
| 3016 | 0.0, 0.0, 4.0, 4.0, // align |
| 3017 | 0.0, 0.0, 0.0, 4.0, // align |
| 3018 | 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4]; |
| 3019 | 0.0, 5.0, 0.0, 5.0, // align |
| 3020 | 0.0, 0.0, 5.0, 5.0, // align |
| 3021 | 0.0, 0.0, 0.0, 5.0, // align |
| 3022 | 6.0, 0.0, 0.0, 6.0, // align |
| 3023 | 0.0, 6.0, 0.0, 6.0, // align |
| 3024 | 0.0, 0.0, 6.0, 6.0, // align |
| 3025 | 0.0, 0.0, 0.0, 6.0, // align |
| 3026 | 7.0, 0.0, 0.0, 7.0, // align |
| 3027 | 0.0, 7.0, 0.0, 7.0, // align |
| 3028 | 0.0, 0.0, 7.0, 7.0, // align |
| 3029 | 0.0, 0.0, 0.0, 7.0, // align |
| 3030 | 8.0, 0.0, 0.0, 8.0, // align |
| 3031 | 0.0, 8.0, 0.0, 8.0, // align |
| 3032 | 0.0, 0.0, 8.0, 8.0, // align |
| 3033 | 0.0, 0.0, 0.0, 8.0, // align |
| 3034 | 0.0, // float fZero; // align |
| 3035 | 1.0, // float fOne; // pack |
| 3036 | 2.0, // float fTwo; // pack |
| 3037 | 3.0, // float fThree; // pack |
| 3038 | 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align |
| 3039 | 4.0, // float fFour; // pack |
| 3040 | 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align |
| 3041 | 5.0, // float fFive; // pack |
| 3042 | 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align |
| 3043 | 6.0, // float fSix; // pack |
| 3044 | 7.0, // float fSeven; // align |
| 3045 | 8.0, // float fEight; // pack |
| 3046 | 9.0, // float fNine; // pack |
| 3047 | 0.0, // BUFFER |
| 3048 | 0.0, 0.0, // vec2 fZeroZero; // align |
| 3049 | 0.0, 1.0, // vec2 fZeroOne; // pack |
| 3050 | 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align |
| 3051 | 1.0, 0.0, // vec2 fOneZero; // align |
| 3052 | 1.0, 1.0, // vec2 fOneOne; // pack |
| 3053 | 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align |
| 3054 | 10.0, // float fTen; // pack |
| 3055 | 11.0, // float fEleven; // align |
| 3056 | 12.0, // float fTwelve; // pack |
| 3057 | 0.0, 0.0, // BUFFER |
| 3058 | 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align |
| 3059 | 0.0, // BUFFER |
| 3060 | 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4]; |
| 3061 | 0.5, 0.6, 0.7, 0.8, // align |
| 3062 | 0.9, 1.0, 1.1, 1.2, // align |
| 3063 | 1.3, 1.4, 1.5, 1.6, // align |
| 3064 | }; |
| 3065 | |
| 3066 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3067 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 3068 | |
| 3069 | const int constCount = sizeof(mixedVals) / sizeof(float); |
| 3070 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 3071 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 3072 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 3073 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 3074 | VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals); |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 3075 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 3076 | VkPipelineObj pipelineobj(m_device); |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 3077 | pipelineobj.AddShader(&vs); |
| 3078 | pipelineobj.AddShader(&ps); |
| 3079 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 3080 | VkDescriptorSetObj descriptorSet(m_device); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3081 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer); |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 3082 | |
| 3083 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 3084 | VkCommandBufferObj cmdBuffer(m_device); |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 3085 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 3086 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3087 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 3088 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 3089 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet); |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 3090 | |
| 3091 | #ifdef DUMP_STATE_DOT |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3092 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile"); |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 3093 | pDSDumpDot((char*)"triTest2.dot"); |
| 3094 | #endif |
| 3095 | // render triangle |
| 3096 | cmdBuffer.Draw(0, 3, 0, 1); |
| 3097 | |
| 3098 | // finalize recording of the command buffer |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 3099 | EndCommandBuffer(cmdBuffer); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 3100 | cmdBuffer.QueueCommandBuffer(); |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 3101 | |
Courtney Goeltzenleuchter | e5f0e6c | 2015-04-02 14:17:44 -0600 | [diff] [blame] | 3102 | RecordImages(m_renderTargets); |
Cody Northrop | 04ad120 | 2014-12-17 15:26:33 -0700 | [diff] [blame] | 3103 | } |
| 3104 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 3105 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | 54119a3 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 3106 | int result; |
| 3107 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 3108 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 3109 | VkTestFramework::InitArgs(&argc, argv); |
Courtney Goeltzenleuchter | 54119a3 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 3110 | |
Chia-I Wu | 6f18429 | 2014-12-15 23:57:34 +0800 | [diff] [blame] | 3111 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 3112 | |
Courtney Goeltzenleuchter | 54119a3 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 3113 | result = RUN_ALL_TESTS(); |
| 3114 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 3115 | VkTestFramework::Finish(); |
Courtney Goeltzenleuchter | 54119a3 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 3116 | return result; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 3117 | } |