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 | |
| 31 | // XGL tests |
| 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 | |
| 63 | #include <xgl.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 |
| 71 | #include <xglDbg.h> |
| 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 | |
| 75 | #include "xgldevice.h" |
Courtney Goeltzenleuchter | efd4e0a | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 76 | #include "xglimage.h" |
Chia-I Wu | fe7c1de | 2014-08-28 11:56:29 +0800 | [diff] [blame] | 77 | #include "icd-bil.h" |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 78 | |
Courtney Goeltzenleuchter | fdcfb9f | 2014-10-10 18:04:39 -0600 | [diff] [blame] | 79 | #define GLM_FORCE_RADIANS |
| 80 | #include "glm/glm.hpp" |
| 81 | #include <glm/gtc/matrix_transform.hpp> |
| 82 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 83 | #include "xglrenderframework.h" |
Tobin Ehlis | 6663f49 | 2014-11-10 12:29:12 -0700 | [diff] [blame] | 84 | #ifdef DEBUG_CALLBACK |
| 85 | XGL_VOID XGLAPI myDbgFunc( |
| 86 | XGL_DBG_MSG_TYPE msgType, |
| 87 | XGL_VALIDATION_LEVEL validationLevel, |
| 88 | XGL_BASE_OBJECT srcObject, |
| 89 | XGL_SIZE location, |
| 90 | XGL_INT msgCode, |
| 91 | const XGL_CHAR* pMsg, |
| 92 | XGL_VOID* pUserData) |
| 93 | { |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 94 | switch (msgType) |
| 95 | { |
| 96 | case XGL_DBG_MSG_WARNING: |
| 97 | printf("CALLBACK WARNING : %s\n", pMsg); |
| 98 | break; |
| 99 | case XGL_DBG_MSG_ERROR: |
| 100 | printf("CALLBACK ERROR : %s\n", pMsg); |
| 101 | break; |
| 102 | default: |
| 103 | printf("EATING Msg of type %u\n", msgType); |
| 104 | break; |
| 105 | } |
Tobin Ehlis | 6663f49 | 2014-11-10 12:29:12 -0700 | [diff] [blame] | 106 | } |
| 107 | #endif |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 108 | |
| 109 | |
| 110 | #undef ASSERT_NO_FATAL_FAILURE |
| 111 | #define ASSERT_NO_FATAL_FAILURE(x) x |
| 112 | |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 113 | //-------------------------------------------------------------------------------------- |
| 114 | // Mesh and VertexFormat Data |
| 115 | //-------------------------------------------------------------------------------------- |
| 116 | struct Vertex |
| 117 | { |
| 118 | XGL_FLOAT posX, posY, posZ, posW; // Position data |
| 119 | XGL_FLOAT r, g, b, a; // Color |
| 120 | }; |
| 121 | |
| 122 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
| 123 | |
| 124 | static const Vertex g_vbData[] = |
| 125 | { |
| 126 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 127 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 128 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 129 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 130 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 131 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 132 | |
| 133 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 134 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 135 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 136 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 137 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 138 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 139 | |
| 140 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 141 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 142 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 143 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 144 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 145 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 146 | |
| 147 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 148 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 149 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 150 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 151 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 152 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 153 | |
| 154 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 155 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 156 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 157 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 158 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 159 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 160 | |
| 161 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 162 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 163 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 164 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 165 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 166 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 167 | }; |
| 168 | |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 169 | static const Vertex g_vb_solid_face_colors_Data[] = |
| 170 | { |
| 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 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 176 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 177 | |
| 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 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 183 | { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 184 | |
| 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 | { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 190 | { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 191 | |
| 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 | { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 197 | { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 198 | |
| 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 | { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 204 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 205 | |
| 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 | { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 211 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 212 | }; |
| 213 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 214 | class XglRenderTest : public XglRenderFramework |
Courtney Goeltzenleuchter | 54119a3 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 215 | { |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 216 | public: |
Cody Northrop | 7ad4aaf | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 217 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 218 | void DrawTriangleTest(const char *vertShaderText, const char *fragShaderText); |
| 219 | void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model, |
Tony Barbour | 1c04203 | 2014-12-03 16:13:23 -0700 | [diff] [blame] | 220 | XglConstantBufferObj *constantBuffer); |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 221 | void GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet, int numTris); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 222 | void QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs); |
| 223 | |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 224 | void InitDepthStencil(); |
Courtney Goeltzenleuchter | a4276c0 | 2014-10-22 18:02:30 -0600 | [diff] [blame] | 225 | void GenerateClearAndPrepareBufferCmds(); |
Courtney Goeltzenleuchter | 71d1f87 | 2014-10-27 13:08:55 -0600 | [diff] [blame] | 226 | void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 227 | |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 228 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 229 | protected: |
Cody Northrop | 7d2035d | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 230 | XGL_IMAGE m_texture; |
| 231 | XGL_IMAGE_VIEW m_textureView; |
| 232 | XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo; |
| 233 | XGL_GPU_MEMORY m_textureMem; |
| 234 | |
| 235 | XGL_SAMPLER m_sampler; |
| 236 | |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 237 | XGL_FORMAT m_depth_stencil_fmt; |
| 238 | XGL_IMAGE m_depthStencilImage; |
| 239 | XGL_GPU_MEMORY m_depthStencilMem; |
| 240 | XGL_DEPTH_STENCIL_VIEW m_depthStencilView; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 241 | XglMemoryRefManager m_memoryRefManager; |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 242 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 243 | |
| 244 | virtual void SetUp() { |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 245 | |
| 246 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 247 | this->app_info.pNext = NULL; |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 248 | this->app_info.pAppName = (const XGL_CHAR *) "render_tests"; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 249 | this->app_info.appVersion = 1; |
| 250 | this->app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 251 | this->app_info.engineVersion = 1; |
| 252 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 253 | |
Cody Northrop | 7d2035d | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 254 | memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo)); |
| 255 | m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
Tony Barbour | e3e2e3f | 2014-12-04 17:14:45 -0700 | [diff] [blame] | 256 | memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage)); |
Cody Northrop | 7d2035d | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 257 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 258 | InitFramework(); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | virtual void TearDown() { |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 262 | // Clean up resources before we reset |
| 263 | ShutdownFramework(); |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 264 | } |
| 265 | }; |
| 266 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 267 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 268 | void XglRenderTest::GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet,int numTris) |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 269 | { |
| 270 | XGL_RESULT err = XGL_SUCCESS; |
| 271 | |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 272 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | d806c8e | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 273 | // Build command buffer |
| 274 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 275 | ASSERT_XGL_SUCCESS(err); |
| 276 | |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 277 | GenerateClearAndPrepareBufferCmds(); |
| 278 | GenerateBindRenderTargetCmd(); |
Tobin Ehlis | f27eba7 | 2014-12-16 17:34:50 -0700 | [diff] [blame] | 279 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 280 | GenerateBindStateAndPipelineCmds(); |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 281 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 282 | pipelineobj->BindPipelineCommandBuffer(m_cmdBuffer,descriptorSet); |
Tony Barbour | 5420af0 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 283 | descriptorSet->BindCommandBuffer(m_cmdBuffer); |
Tobin Ehlis | f27eba7 | 2014-12-16 17:34:50 -0700 | [diff] [blame] | 284 | #ifdef DUMP_STATE_DOT |
| 285 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile"); |
| 286 | pDSDumpDot((char*)"triTest.dot"); |
| 287 | DRAW_STATE_DUMP_PNG_FILE pDSDumpPng = (DRAW_STATE_DUMP_PNG_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpPngFile"); |
| 288 | pDSDumpPng((char*)"triTest.png"); |
| 289 | #endif |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 290 | // render the triangle |
| 291 | xglCmdDraw( m_cmdBuffer, 0, 3*numTris, 0, 1 ); |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 292 | |
| 293 | // finalize recording of the command buffer |
| 294 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 295 | ASSERT_XGL_SUCCESS( err ); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 296 | } |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 297 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 298 | void XglRenderTest::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs) |
| 299 | { |
| 300 | XGL_RESULT err = XGL_SUCCESS; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 301 | XGL_UINT i; |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 302 | |
| 303 | // submit the command buffer to the universal queue |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 304 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, numMemRefs, memRefs, NULL ); |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 305 | ASSERT_XGL_SUCCESS( err ); |
| 306 | |
Chia-I Wu | 113e9d9 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 307 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 308 | ASSERT_XGL_SUCCESS( err ); |
| 309 | |
Courtney Goeltzenleuchter | 464746c | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 310 | // Wait for work to finish before cleaning up. |
| 311 | xglDeviceWaitIdle(m_device->device()); |
| 312 | |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 313 | for (i = 0; i < m_renderTargetCount; i++) |
| 314 | RecordImage(m_renderTargets[i]); |
Courtney Goeltzenleuchter | 0246188 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 315 | } |
| 316 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 317 | void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText) |
Courtney Goeltzenleuchter | 538062a | 2014-10-09 15:40:19 -0600 | [diff] [blame] | 318 | { |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 319 | XGL_RESULT err; |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 320 | |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 321 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 322 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 323 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 324 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 325 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 326 | |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 327 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 328 | XglPipelineObj pipelineobj(m_device); |
| 329 | pipelineobj.AddShader(&vs); |
| 330 | pipelineobj.AddShader(&ps); |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 331 | |
| 332 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 333 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 334 | // Create descriptor set |
| 335 | XglDescriptorSetObj descriptorSet(m_device); |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 336 | |
| 337 | // Build command buffer |
| 338 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 339 | ASSERT_XGL_SUCCESS(err); |
| 340 | |
| 341 | GenerateClearAndPrepareBufferCmds(); |
| 342 | GenerateBindRenderTargetCmd(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 343 | GenerateBindStateAndPipelineCmds(); |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 344 | |
Tobin Ehlis | f27eba7 | 2014-12-16 17:34:50 -0700 | [diff] [blame] | 345 | pipelineobj.BindPipelineCommandBuffer(m_cmdBuffer,&descriptorSet); |
| 346 | descriptorSet.BindCommandBuffer(m_cmdBuffer); |
Tobin Ehlis | 11e5213 | 2014-11-28 11:17:19 -0700 | [diff] [blame] | 347 | #ifdef DUMP_STATE_DOT |
| 348 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile"); |
| 349 | pDSDumpDot((char*)"triUniFS.dot"); |
| 350 | #endif |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 351 | // render the triangle |
| 352 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 353 | |
| 354 | // finalize recording of the command buffer |
| 355 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 356 | ASSERT_XGL_SUCCESS( err ); |
| 357 | |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 358 | // submit the command buffer to the universal queue |
Tony Barbour | 75e9ee4 | 2014-12-04 17:17:26 -0700 | [diff] [blame] | 359 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, 0, m_memRefs, NULL ); |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 360 | ASSERT_XGL_SUCCESS( err ); |
| 361 | |
| 362 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 363 | ASSERT_XGL_SUCCESS( err ); |
| 364 | |
| 365 | // Wait for work to finish before cleaning up. |
| 366 | xglDeviceWaitIdle(m_device->device()); |
| 367 | |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 368 | assert(m_renderTargetCount == 1); |
| 369 | RecordImage(m_renderTargets[0]); |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 370 | |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 371 | } |
| 372 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 373 | void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model, |
Tony Barbour | 1c04203 | 2014-12-03 16:13:23 -0700 | [diff] [blame] | 374 | XglConstantBufferObj *constantBuffer) |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 375 | { |
| 376 | int i; |
| 377 | glm::mat4 MVP; |
| 378 | int matrixSize = sizeof(MVP); |
| 379 | XGL_RESULT err; |
Courtney Goeltzenleuchter | c55471f | 2014-10-13 13:03:31 -0600 | [diff] [blame] | 380 | |
| 381 | for (i = 0; i < 8; i++) { |
| 382 | XGL_UINT8 *pData; |
Tony Barbour | 1c04203 | 2014-12-03 16:13:23 -0700 | [diff] [blame] | 383 | err = xglMapMemory(constantBuffer->m_constantBufferMem, 0, (XGL_VOID **) &pData); |
Courtney Goeltzenleuchter | c55471f | 2014-10-13 13:03:31 -0600 | [diff] [blame] | 384 | ASSERT_XGL_SUCCESS(err); |
| 385 | |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 386 | Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f)); |
| 387 | MVP = Projection * View * Model; |
Courtney Goeltzenleuchter | c55471f | 2014-10-13 13:03:31 -0600 | [diff] [blame] | 388 | memcpy(pData, (const void*) &MVP[0][0], matrixSize); |
| 389 | |
Tony Barbour | 1c04203 | 2014-12-03 16:13:23 -0700 | [diff] [blame] | 390 | err = xglUnmapMemory(constantBuffer->m_constantBufferMem); |
Courtney Goeltzenleuchter | c55471f | 2014-10-13 13:03:31 -0600 | [diff] [blame] | 391 | ASSERT_XGL_SUCCESS(err); |
| 392 | |
| 393 | // submit the command buffer to the universal queue |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 394 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_memoryRefManager.GetNumRefs(), m_memoryRefManager.GetMemoryRefList(), NULL ); |
Courtney Goeltzenleuchter | c55471f | 2014-10-13 13:03:31 -0600 | [diff] [blame] | 395 | ASSERT_XGL_SUCCESS( err ); |
| 396 | |
| 397 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 398 | ASSERT_XGL_SUCCESS( err ); |
| 399 | |
| 400 | // Wait for work to finish before cleaning up. |
| 401 | xglDeviceWaitIdle(m_device->device()); |
| 402 | |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 403 | assert(m_renderTargetCount == 1); |
| 404 | RecordImage(m_renderTargets[0]); |
Courtney Goeltzenleuchter | c55471f | 2014-10-13 13:03:31 -0600 | [diff] [blame] | 405 | } |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 406 | } |
| 407 | |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 408 | void dumpMatrix(const char *note, glm::mat4 MVP) |
| 409 | { |
Chia-I Wu | 6f18429 | 2014-12-15 23:57:34 +0800 | [diff] [blame] | 410 | int i; |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 411 | |
| 412 | printf("%s: \n", note); |
| 413 | for (i=0; i<4; i++) { |
| 414 | printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]); |
| 415 | } |
| 416 | printf("\n"); |
| 417 | fflush(stdout); |
| 418 | } |
| 419 | |
| 420 | void dumpVec4(const char *note, glm::vec4 vector) |
| 421 | { |
| 422 | printf("%s: \n", note); |
| 423 | printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]); |
| 424 | printf("\n"); |
| 425 | fflush(stdout); |
| 426 | } |
| 427 | |
Courtney Goeltzenleuchter | a4276c0 | 2014-10-22 18:02:30 -0600 | [diff] [blame] | 428 | void XglRenderTest::GenerateClearAndPrepareBufferCmds() |
| 429 | { |
| 430 | XglRenderFramework::GenerateClearAndPrepareBufferCmds(); |
Courtney Goeltzenleuchter | a4276c0 | 2014-10-22 18:02:30 -0600 | [diff] [blame] | 431 | |
Tony Barbour | e3e2e3f | 2014-12-04 17:14:45 -0700 | [diff] [blame] | 432 | if (m_depthStencilImage) { |
Tony Barbour | e3e2e3f | 2014-12-04 17:14:45 -0700 | [diff] [blame] | 433 | XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {}; |
| 434 | dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH; |
| 435 | dsRange.baseMipLevel = 0; |
| 436 | dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 437 | dsRange.baseArraySlice = 0; |
| 438 | dsRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 439 | |
Tony Barbour | e3e2e3f | 2014-12-04 17:14:45 -0700 | [diff] [blame] | 440 | // prepare the depth buffer for clear |
| 441 | XGL_IMAGE_STATE_TRANSITION transitionToClear = {}; |
| 442 | transitionToClear.image = m_depthStencilImage; |
| 443 | transitionToClear.oldState = m_depthStencilBinding.depthState; |
| 444 | transitionToClear.newState = XGL_IMAGE_STATE_CLEAR; |
| 445 | transitionToClear.subresourceRange = dsRange; |
| 446 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear ); |
| 447 | m_depthStencilBinding.depthState = transitionToClear.newState; |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 448 | |
Tony Barbour | e3e2e3f | 2014-12-04 17:14:45 -0700 | [diff] [blame] | 449 | xglCmdClearDepthStencil(m_cmdBuffer, m_depthStencilImage, 1.0f, 0, 1, &dsRange); |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 450 | |
Tony Barbour | e3e2e3f | 2014-12-04 17:14:45 -0700 | [diff] [blame] | 451 | // prepare depth buffer for rendering |
| 452 | XGL_IMAGE_STATE_TRANSITION transitionToRender = {}; |
Chia-I Wu | fc0c284 | 2014-12-05 10:48:20 +0800 | [diff] [blame] | 453 | transitionToRender.image = m_depthStencilImage; |
Tony Barbour | e3e2e3f | 2014-12-04 17:14:45 -0700 | [diff] [blame] | 454 | transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR; |
| 455 | transitionToRender.newState = m_depthStencilBinding.depthState; |
| 456 | transitionToRender.subresourceRange = dsRange; |
| 457 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender ); |
| 458 | m_depthStencilBinding.depthState = transitionToClear.newState; |
| 459 | } |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 460 | } |
| 461 | |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 462 | void XglRenderTest::InitDepthStencil() |
| 463 | { |
| 464 | XGL_RESULT err; |
| 465 | XGL_IMAGE_CREATE_INFO image; |
| 466 | XGL_MEMORY_ALLOC_INFO mem_alloc; |
| 467 | XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view; |
| 468 | XGL_MEMORY_REQUIREMENTS mem_reqs; |
Jon Ashburn | b9e193f | 2014-11-21 11:33:20 -0700 | [diff] [blame] | 469 | XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS); |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 470 | |
| 471 | // Clean up default state created by framework |
| 472 | if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil); |
| 473 | |
| 474 | m_depth_stencil_fmt.channelFormat = XGL_CH_FMT_R16; |
| 475 | m_depth_stencil_fmt.numericFormat = XGL_NUM_FMT_DS; |
| 476 | |
| 477 | image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 478 | image.pNext = NULL; |
| 479 | image.imageType = XGL_IMAGE_2D; |
| 480 | image.format = m_depth_stencil_fmt; |
| 481 | image.extent.width = m_width; |
| 482 | image.extent.height = m_height; |
| 483 | image.extent.depth = 1; |
| 484 | image.mipLevels = 1; |
| 485 | image.arraySize = 1; |
| 486 | image.samples = 1; |
| 487 | image.tiling = XGL_OPTIMAL_TILING; |
| 488 | image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT; |
| 489 | image.flags = 0; |
| 490 | |
| 491 | mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 492 | mem_alloc.pNext = NULL; |
| 493 | mem_alloc.allocationSize = 0; |
| 494 | mem_alloc.alignment = 0; |
| 495 | mem_alloc.flags = 0; |
| 496 | mem_alloc.heapCount = 0; |
| 497 | mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 498 | |
| 499 | /* create image */ |
| 500 | err = xglCreateImage(device(), &image, |
| 501 | &m_depthStencilImage); |
| 502 | ASSERT_XGL_SUCCESS(err); |
| 503 | |
| 504 | err = xglGetObjectInfo(m_depthStencilImage, |
| 505 | XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 506 | &mem_reqs_size, &mem_reqs); |
| 507 | ASSERT_XGL_SUCCESS(err); |
| 508 | ASSERT_EQ(mem_reqs_size, sizeof(mem_reqs)); |
| 509 | |
| 510 | mem_alloc.allocationSize = mem_reqs.size; |
| 511 | mem_alloc.alignment = mem_reqs.alignment; |
| 512 | mem_alloc.heapCount = mem_reqs.heapCount; |
| 513 | memcpy(mem_alloc.heaps, mem_reqs.heaps, |
| 514 | sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount); |
| 515 | |
| 516 | /* allocate memory */ |
| 517 | err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem); |
| 518 | ASSERT_XGL_SUCCESS(err); |
| 519 | |
| 520 | /* bind memory */ |
| 521 | err = xglBindObjectMemory(m_depthStencilImage, m_depthStencilMem, 0); |
| 522 | ASSERT_XGL_SUCCESS(err); |
| 523 | |
| 524 | XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {}; |
| 525 | depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO; |
| 526 | depthStencil.depthTestEnable = XGL_TRUE; |
| 527 | depthStencil.depthWriteEnable = XGL_TRUE; |
| 528 | depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL; |
| 529 | depthStencil.depthBoundsEnable = XGL_FALSE; |
| 530 | depthStencil.minDepth = 0.f; |
| 531 | depthStencil.maxDepth = 1.f; |
| 532 | depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP; |
| 533 | depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP; |
| 534 | depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP; |
| 535 | depthStencil.back.stencilRef = 0x00; |
| 536 | depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS; |
| 537 | depthStencil.front = depthStencil.back; |
| 538 | |
| 539 | err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil ); |
| 540 | ASSERT_XGL_SUCCESS( err ); |
| 541 | |
| 542 | /* create image view */ |
| 543 | view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO; |
| 544 | view.pNext = NULL; |
| 545 | view.image = XGL_NULL_HANDLE; |
| 546 | view.mipLevel = 0; |
| 547 | view.baseArraySlice = 0; |
| 548 | view.arraySize = 1; |
| 549 | view.flags = 0; |
| 550 | view.image = m_depthStencilImage; |
| 551 | err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView); |
| 552 | ASSERT_XGL_SUCCESS(err); |
| 553 | |
| 554 | m_depthStencilBinding.view = m_depthStencilView; |
| 555 | m_depthStencilBinding.depthState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 556 | m_depthStencilBinding.stencilState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 557 | } |
| 558 | |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 559 | struct xgltriangle_vs_uniform { |
| 560 | // Must start with MVP |
| 561 | XGL_FLOAT mvp[4][4]; |
| 562 | XGL_FLOAT position[3][4]; |
| 563 | XGL_FLOAT color[3][4]; |
| 564 | }; |
| 565 | |
Courtney Goeltzenleuchter | 71d1f87 | 2014-10-27 13:08:55 -0600 | [diff] [blame] | 566 | void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText) |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 567 | { |
Tobin Ehlis | 6663f49 | 2014-11-10 12:29:12 -0700 | [diff] [blame] | 568 | #ifdef DEBUG_CALLBACK |
| 569 | xglDbgRegisterMsgCallback(myDbgFunc, NULL); |
| 570 | #endif |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 571 | // Create identity matrix |
| 572 | int i; |
| 573 | struct xgltriangle_vs_uniform data; |
| 574 | |
| 575 | glm::mat4 Projection = glm::mat4(1.0f); |
| 576 | glm::mat4 View = glm::mat4(1.0f); |
| 577 | glm::mat4 Model = glm::mat4(1.0f); |
| 578 | glm::mat4 MVP = Projection * View * Model; |
| 579 | const int matrixSize = sizeof(MVP); |
| 580 | const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT); |
| 581 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 582 | |
| 583 | static const Vertex tri_data[] = |
| 584 | { |
| 585 | { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 586 | { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 587 | { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 588 | }; |
| 589 | |
| 590 | for (i=0; i<3; i++) { |
| 591 | data.position[i][0] = tri_data[i].posX; |
| 592 | data.position[i][1] = tri_data[i].posY; |
| 593 | data.position[i][2] = tri_data[i].posZ; |
| 594 | data.position[i][3] = tri_data[i].posW; |
| 595 | data.color[i][0] = tri_data[i].r; |
| 596 | data.color[i][1] = tri_data[i].g; |
| 597 | data.color[i][2] = tri_data[i].b; |
| 598 | data.color[i][3] = tri_data[i].a; |
| 599 | } |
| 600 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 601 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 602 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 603 | |
| 604 | XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data); |
| 605 | |
| 606 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 607 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 608 | vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &constantBuffer); |
| 609 | |
| 610 | XglPipelineObj pipelineobj(m_device); |
| 611 | pipelineobj.AddShader(&vs); |
| 612 | pipelineobj.AddShader(&ps); |
| 613 | |
| 614 | XglDescriptorSetObj descriptorSet(m_device); |
| 615 | descriptorSet.AttachMemoryView(&constantBuffer); |
| 616 | m_memoryRefManager.AddMemoryRef(&constantBuffer); |
| 617 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 618 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 619 | QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs()); |
| 620 | |
Tony Barbour | 1c04203 | 2014-12-03 16:13:23 -0700 | [diff] [blame] | 621 | RotateTriangleVSUniform(Projection, View, Model, &constantBuffer); |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 622 | #ifdef PRINT_OBJECTS |
| 623 | //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type) |
| 624 | OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount"); |
| 625 | XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY); |
| 626 | //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects"); |
| 627 | printf("DEBUG : Number of Objects : %lu\n", numObjects); |
| 628 | OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects"); |
| 629 | OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects); |
| 630 | pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray); |
| 631 | for (i=0; i < numObjects; i++) { |
| 632 | printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_XGL_OBJECT_TYPE(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses); |
| 633 | } |
| 634 | free(pObjNodeArray); |
| 635 | #endif |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 636 | |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 637 | } |
| 638 | |
Courtney Goeltzenleuchter | 71d1f87 | 2014-10-27 13:08:55 -0600 | [diff] [blame] | 639 | TEST_F(XglRenderTest, XGLTriangle_FragColor) |
| 640 | { |
| 641 | static const char *vertShaderText = |
| 642 | "#version 140\n" |
| 643 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 644 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 645 | "\n" |
| 646 | "layout(binding = 0) uniform buf {\n" |
| 647 | " mat4 MVP;\n" |
| 648 | " vec4 position[3];\n" |
| 649 | " vec4 color[3];\n" |
| 650 | "} ubuf;\n" |
| 651 | "\n" |
| 652 | "layout (location = 0) out vec4 outColor;\n" |
| 653 | "\n" |
| 654 | "void main() \n" |
| 655 | "{\n" |
| 656 | " outColor = ubuf.color[gl_VertexID];\n" |
| 657 | " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n" |
| 658 | "}\n"; |
| 659 | |
| 660 | static const char *fragShaderText = |
| 661 | "#version 140\n" |
| 662 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 663 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 664 | "\n" |
| 665 | "layout (location = 0) in vec4 inColor;\n" |
| 666 | "\n" |
| 667 | "void main()\n" |
| 668 | "{\n" |
| 669 | " gl_FragColor = inColor;\n" |
| 670 | "}\n"; |
| 671 | |
Courtney Goeltzenleuchter | 9fb6249 | 2014-10-27 13:09:23 -0600 | [diff] [blame] | 672 | TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor"); |
Courtney Goeltzenleuchter | 71d1f87 | 2014-10-27 13:08:55 -0600 | [diff] [blame] | 673 | XGLTriangleTest(vertShaderText, fragShaderText); |
| 674 | } |
| 675 | |
| 676 | TEST_F(XglRenderTest, XGLTriangle_OutputLocation) |
| 677 | { |
| 678 | static const char *vertShaderText = |
| 679 | "#version 140\n" |
| 680 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 681 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 682 | "\n" |
| 683 | "layout(binding = 0) uniform buf {\n" |
| 684 | " mat4 MVP;\n" |
| 685 | " vec4 position[3];\n" |
| 686 | " vec4 color[3];\n" |
| 687 | "} ubuf;\n" |
| 688 | "\n" |
| 689 | "layout (location = 0) out vec4 outColor;\n" |
| 690 | "\n" |
| 691 | "void main() \n" |
| 692 | "{\n" |
| 693 | " outColor = ubuf.color[gl_VertexID];\n" |
| 694 | " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n" |
| 695 | "}\n"; |
| 696 | |
| 697 | static const char *fragShaderText = |
| 698 | "#version 140\n" |
| 699 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 700 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 701 | "\n" |
| 702 | "layout (location = 0) in vec4 inColor;\n" |
| 703 | "layout (location = 0) out vec4 outColor;\n" |
| 704 | "\n" |
| 705 | "void main()\n" |
| 706 | "{\n" |
| 707 | " outColor = inColor;\n" |
| 708 | "}\n"; |
| 709 | |
Courtney Goeltzenleuchter | 9fb6249 | 2014-10-27 13:09:23 -0600 | [diff] [blame] | 710 | TEST_DESCRIPTION("XGL-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] | 711 | |
| 712 | XGLTriangleTest(vertShaderText, fragShaderText); |
| 713 | } |
| 714 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 715 | TEST_F(XglRenderTest, BIL_XGLTriangle) |
| 716 | { |
| 717 | bool saved_use_bil = XglTestFramework::m_use_bil; |
| 718 | |
| 719 | static const char *vertShaderText = |
| 720 | "#version 140\n" |
| 721 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 722 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 723 | "\n" |
| 724 | "layout(binding = 0) uniform buf {\n" |
| 725 | " mat4 MVP;\n" |
| 726 | " vec4 position[3];\n" |
| 727 | " vec4 color[3];\n" |
| 728 | "} ubuf;\n" |
| 729 | "\n" |
| 730 | "layout (location = 0) out vec4 outColor;\n" |
| 731 | "\n" |
| 732 | "void main() \n" |
| 733 | "{\n" |
| 734 | " outColor = ubuf.color[gl_VertexID];\n" |
| 735 | " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n" |
| 736 | "}\n"; |
| 737 | |
| 738 | static const char *fragShaderText = |
| 739 | "#version 140\n" |
| 740 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 741 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 742 | "\n" |
| 743 | "layout (location = 0) in vec4 inColor;\n" |
| 744 | "\n" |
| 745 | "void main()\n" |
| 746 | "{\n" |
| 747 | " gl_FragColor = inColor;\n" |
| 748 | "}\n"; |
| 749 | |
| 750 | TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver."); |
| 751 | |
| 752 | XglTestFramework::m_use_bil = true; |
| 753 | |
| 754 | XGLTriangleTest(vertShaderText, fragShaderText); |
| 755 | |
| 756 | XglTestFramework::m_use_bil = saved_use_bil; |
| 757 | } |
| 758 | |
Courtney Goeltzenleuchter | 2f53dfa | 2014-10-10 17:02:53 -0600 | [diff] [blame] | 759 | TEST_F(XglRenderTest, GreenTriangle) |
Cody Northrop | d1a256b | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 760 | { |
| 761 | static const char *vertShaderText = |
| 762 | "#version 130\n" |
| 763 | "vec2 vertices[3];\n" |
| 764 | "void main() {\n" |
| 765 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 766 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 767 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 768 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 769 | "}\n"; |
Courtney Goeltzenleuchter | 538062a | 2014-10-09 15:40:19 -0600 | [diff] [blame] | 770 | |
Cody Northrop | d1a256b | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 771 | static const char *fragShaderText = |
| 772 | "#version 130\n" |
Cody Northrop | d1a256b | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 773 | "void main() {\n" |
Steve K | c53f863 | 2014-10-10 08:54:29 -0600 | [diff] [blame] | 774 | " gl_FragColor = vec4(0,1,0,1);\n" |
Cody Northrop | d1a256b | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 775 | "}\n"; |
Courtney Goeltzenleuchter | 5adb181 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 776 | |
Courtney Goeltzenleuchter | 9fb6249 | 2014-10-27 13:09:23 -0600 | [diff] [blame] | 777 | TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader."); |
| 778 | |
Cody Northrop | d1a256b | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 779 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 780 | } |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 781 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 782 | TEST_F(XglRenderTest, BIL_GreenTriangle) |
| 783 | { |
| 784 | bool saved_use_bil = XglTestFramework::m_use_bil; |
| 785 | |
| 786 | static const char *vertShaderText = |
| 787 | "#version 130\n" |
| 788 | "vec2 vertices[3];\n" |
| 789 | "void main() {\n" |
| 790 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 791 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 792 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 793 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 794 | "}\n"; |
| 795 | |
| 796 | static const char *fragShaderText = |
| 797 | "#version 130\n" |
| 798 | "void main() {\n" |
| 799 | " gl_FragColor = vec4(0,1,0,1);\n" |
| 800 | "}\n"; |
| 801 | |
| 802 | TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver."); |
| 803 | |
| 804 | XglTestFramework::m_use_bil = true; |
| 805 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 806 | XglTestFramework::m_use_bil = saved_use_bil; |
| 807 | } |
| 808 | |
| 809 | TEST_F(XglRenderTest, YellowTriangle) |
| 810 | { |
| 811 | static const char *vertShaderText = |
| 812 | "#version 130\n" |
| 813 | "void main() {\n" |
| 814 | " vec2 vertices[3];" |
| 815 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 816 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 817 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 818 | " vec4 colors[3];\n" |
| 819 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 820 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 821 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 822 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 823 | "}\n"; |
| 824 | |
| 825 | static const char *fragShaderText = |
| 826 | "#version 130\n" |
| 827 | "void main() {\n" |
| 828 | " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n" |
| 829 | "}\n"; |
| 830 | |
| 831 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 832 | } |
| 833 | |
Courtney Goeltzenleuchter | 2f53dfa | 2014-10-10 17:02:53 -0600 | [diff] [blame] | 834 | TEST_F(XglRenderTest, TriangleWithVertexFetch) |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 835 | { |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 836 | static const char *vertShaderText = |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 837 | "#version 130\n" |
| 838 | //XYZ1( -1, -1, -1 ) |
| 839 | "in vec4 pos;\n" |
| 840 | //XYZ1( 0.f, 0.f, 0.f ) |
| 841 | "in vec4 inColor;\n" |
| 842 | "out vec4 outColor;\n" |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 843 | "void main() {\n" |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 844 | " outColor = inColor;\n" |
Cody Northrop | 7ad4aaf | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 845 | " gl_Position = pos;\n" |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 846 | "}\n"; |
| 847 | |
Cody Northrop | ee6586d | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 848 | |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 849 | static const char *fragShaderText = |
Cody Northrop | d43c52e | 2014-12-05 15:44:14 -0700 | [diff] [blame] | 850 | "#version 140\n" |
| 851 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 852 | "#extension GL_ARB_shading_language_420pack : enable\n" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 853 | "in vec4 color;\n" |
Cody Northrop | d43c52e | 2014-12-05 15:44:14 -0700 | [diff] [blame] | 854 | "layout (location = 0) out vec4 outColor;\n" |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 855 | "void main() {\n" |
Cody Northrop | d43c52e | 2014-12-05 15:44:14 -0700 | [diff] [blame] | 856 | " outColor = color;\n" |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 857 | "}\n"; |
Courtney Goeltzenleuchter | ce25e25 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 858 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 859 | |
| 860 | |
| 861 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 862 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 863 | |
| 864 | XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 865 | meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 866 | |
| 867 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 868 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 869 | |
| 870 | XglPipelineObj pipelineobj(m_device); |
| 871 | pipelineobj.AddShader(&vs); |
| 872 | pipelineobj.AddShader(&ps); |
| 873 | |
| 874 | XglDescriptorSetObj descriptorSet(m_device); |
| 875 | descriptorSet.AttachMemoryView(&meshBuffer); |
| 876 | |
| 877 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 878 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 879 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 880 | }; |
| 881 | |
| 882 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 883 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 884 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 885 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 886 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 887 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 888 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 889 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 890 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 891 | |
| 892 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 893 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 894 | pipelineobj.AddVertexDataBuffer(&meshBuffer,0); |
| 895 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 896 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 897 | QueueCommandBuffer(NULL, 0); |
| 898 | |
Tobin Ehlis | d806c8e | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 899 | } |
| 900 | |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 901 | TEST_F(XglRenderTest, TriangleMRT) |
| 902 | { |
| 903 | static const char *vertShaderText = |
| 904 | "#version 130\n" |
| 905 | "in vec4 pos;\n" |
| 906 | "void main() {\n" |
| 907 | " gl_Position = pos;\n" |
| 908 | "}\n"; |
| 909 | |
| 910 | static const char *fragShaderText = |
| 911 | "#version 130\n" |
| 912 | "void main() {\n" |
| 913 | " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 914 | " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 915 | "}\n"; |
| 916 | const XGL_FLOAT vb_data[][2] = { |
| 917 | { -1.0f, -1.0f }, |
| 918 | { 1.0f, -1.0f }, |
| 919 | { -1.0f, 1.0f } |
| 920 | }; |
| 921 | |
| 922 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 923 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 924 | |
| 925 | XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 926 | meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY); |
Chia-I Wu | fe7bb8f | 2014-12-05 10:32:23 +0800 | [diff] [blame] | 927 | |
| 928 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 929 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 930 | |
| 931 | XglPipelineObj pipelineobj(m_device); |
| 932 | pipelineobj.AddShader(&vs); |
| 933 | pipelineobj.AddShader(&ps); |
| 934 | |
| 935 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 936 | sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 937 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 938 | }; |
| 939 | |
| 940 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib; |
| 941 | vi_attrib.binding = 0; // index into vertexBindingDescriptions |
| 942 | vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data |
| 943 | vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 944 | vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 945 | |
| 946 | pipelineobj.AddVertexInputAttribs(&vi_attrib, 1); |
| 947 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 948 | pipelineobj.AddVertexDataBuffer(&meshBuffer,0); |
| 949 | |
| 950 | XglDescriptorSetObj descriptorSet(m_device); |
| 951 | |
| 952 | m_renderTargetCount = 2; |
| 953 | |
| 954 | XGL_PIPELINE_CB_ATTACHMENT_STATE att = {}; |
| 955 | att.blendEnable = XGL_FALSE; |
| 956 | att.format = m_render_target_fmt; |
| 957 | att.channelWriteMask = 0xf; |
| 958 | pipelineobj.SetColorAttachment(1, &att); |
| 959 | |
| 960 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
| 961 | QueueCommandBuffer(NULL, 0); |
| 962 | } |
| 963 | |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 964 | TEST_F(XglRenderTest, QuadWithIndexedVertexFetch) |
| 965 | { |
| 966 | static const char *vertShaderText = |
| 967 | "#version 140\n" |
| 968 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 969 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 970 | "layout(location = 0) in vec4 pos;\n" |
| 971 | "layout(location = 1) in vec4 inColor;\n" |
| 972 | "layout(location = 0) out vec4 outColor;\n" |
| 973 | "void main() {\n" |
| 974 | " outColor = inColor;\n" |
| 975 | " gl_Position = pos;\n" |
| 976 | "}\n"; |
| 977 | |
| 978 | |
| 979 | static const char *fragShaderText = |
| 980 | "#version 140\n" |
| 981 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 982 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 983 | "layout(location = 0) in vec4 color;\n" |
| 984 | "void main() {\n" |
| 985 | " gl_FragColor = color;\n" |
| 986 | "}\n"; |
| 987 | |
| 988 | const Vertex g_vbData[] = |
| 989 | { |
| 990 | // first tri |
| 991 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black |
| 992 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red |
| 993 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green |
| 994 | |
| 995 | // second tri |
| 996 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green |
| 997 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red |
| 998 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow |
| 999 | }; |
| 1000 | |
| 1001 | const uint16_t g_idxData[6] = { |
| 1002 | 0, 1, 2, |
| 1003 | 3, 4, 5, |
| 1004 | }; |
| 1005 | |
| 1006 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1007 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1008 | |
| 1009 | XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 1010 | meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 1011 | |
| 1012 | XglIndexBufferObj indexBuffer(m_device); |
| 1013 | indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 1014 | indexBuffer.SetMemoryState(XGL_MEMORY_STATE_INDEX_DATA); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 1015 | |
| 1016 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1017 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1018 | |
| 1019 | XglPipelineObj pipelineobj(m_device); |
| 1020 | pipelineobj.AddShader(&vs); |
| 1021 | pipelineobj.AddShader(&ps); |
| 1022 | |
| 1023 | XglDescriptorSetObj descriptorSet(m_device); |
| 1024 | |
| 1025 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1026 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1027 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1028 | }; |
| 1029 | |
| 1030 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1031 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1032 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1033 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1034 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1035 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1036 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1037 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1038 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1039 | |
| 1040 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 1041 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
Tony Barbour | ad8f154 | 2014-12-17 11:16:05 -0700 | [diff] [blame^] | 1042 | pipelineobj.CreateXGLPipeline(&descriptorSet); |
| 1043 | descriptorSet.CreateXGLDescriptorSet(); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 1044 | |
| 1045 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | ad8f154 | 2014-12-17 11:16:05 -0700 | [diff] [blame^] | 1046 | XglCommandBufferObj cmdBuffer(m_device); |
| 1047 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 1048 | ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(0)); |
| 1049 | cmdBuffer.ClearAllBuffers(NULL, NULL); |
| 1050 | cmdBuffer.BindAttachments(NULL); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 1051 | |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 1052 | #ifdef DUMP_STATE_DOT |
| 1053 | DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile"); |
Tobin Ehlis | f27eba7 | 2014-12-16 17:34:50 -0700 | [diff] [blame] | 1054 | pDSDumpDot((char*)"triTest2.dot"); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 1055 | #endif |
Tony Barbour | ad8f154 | 2014-12-17 11:16:05 -0700 | [diff] [blame^] | 1056 | cmdBuffer.BindState(m_stateRaster, m_stateViewport, m_colorBlend, m_stateDepthStencil, m_stateMsaa); |
| 1057 | cmdBuffer.BindPipeline(pipelineobj.GetPipelineHandle()); |
| 1058 | cmdBuffer.BindDescriptorSet(descriptorSet.GetDescriptorSetHandle()); |
| 1059 | cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0); |
| 1060 | cmdBuffer.BindIndexBuffer(&indexBuffer,0); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 1061 | |
| 1062 | // render two triangles |
Tony Barbour | ad8f154 | 2014-12-17 11:16:05 -0700 | [diff] [blame^] | 1063 | cmdBuffer.DrawIndexed(0, 6, 0, 0, 1); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 1064 | |
| 1065 | // finalize recording of the command buffer |
Tony Barbour | ad8f154 | 2014-12-17 11:16:05 -0700 | [diff] [blame^] | 1066 | cmdBuffer.EndCommandBuffer(); |
| 1067 | cmdBuffer.QueueCommandBuffer(NULL, 0); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 1068 | |
Tony Barbour | ad8f154 | 2014-12-17 11:16:05 -0700 | [diff] [blame^] | 1069 | for (int i = 0; i < m_renderTargetCount; i++) |
| 1070 | RecordImage(m_renderTargets[i]); |
Courtney Goeltzenleuchter | 5e5c48f | 2014-12-04 15:45:16 -0700 | [diff] [blame] | 1071 | |
| 1072 | } |
| 1073 | |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1074 | TEST_F(XglRenderTest, GreyandRedCirclesonBlue) |
| 1075 | { |
| 1076 | // This tests gl_FragCoord |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1077 | |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1078 | static const char *vertShaderText = |
| 1079 | "#version 140\n" |
| 1080 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1081 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1082 | "layout (location = 0) in vec4 pos;\n" |
| 1083 | "layout (location = 0) out vec4 outColor;\n" |
| 1084 | "layout (location = 1) out vec4 outColor2;\n" |
| 1085 | "void main() {\n" |
| 1086 | " gl_Position = pos;\n" |
| 1087 | " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n" |
| 1088 | " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n" |
| 1089 | "}\n"; |
| 1090 | |
| 1091 | static const char *fragShaderText = |
| 1092 | //"#version 140\n" |
| 1093 | "#version 330\n" |
| 1094 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1095 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1096 | //"#extension GL_ARB_fragment_coord_conventions : enable\n" |
| 1097 | //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n" |
| 1098 | "layout (location = 0) in vec4 color;\n" |
| 1099 | "layout (location = 1) in vec4 color2;\n" |
| 1100 | "void main() {\n" |
| 1101 | " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n" |
| 1102 | " float dist_squared = dot(pos, pos);\n" |
| 1103 | " gl_FragColor = (dist_squared < 400.0)\n" |
| 1104 | " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n" |
| 1105 | " : color2;\n" |
| 1106 | "}\n"; |
| 1107 | |
| 1108 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1109 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1110 | |
| 1111 | XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 1112 | meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1113 | |
| 1114 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1115 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1116 | |
| 1117 | XglPipelineObj pipelineobj(m_device); |
| 1118 | pipelineobj.AddShader(&vs); |
| 1119 | pipelineobj.AddShader(&ps); |
| 1120 | |
| 1121 | XglDescriptorSetObj descriptorSet(m_device); |
| 1122 | descriptorSet.AttachMemoryView(&meshBuffer); |
| 1123 | |
| 1124 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1125 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1126 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1127 | }; |
| 1128 | |
| 1129 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1130 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1131 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1132 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1133 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1134 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1135 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1136 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1137 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1138 | |
| 1139 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 1140 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 1141 | pipelineobj.AddVertexDataBuffer(&meshBuffer,0); |
| 1142 | |
Tony Barbour | 1c04203 | 2014-12-03 16:13:23 -0700 | [diff] [blame] | 1143 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1144 | QueueCommandBuffer(NULL, 0); |
| 1145 | |
| 1146 | } |
| 1147 | |
| 1148 | TEST_F(XglRenderTest, RedCirclesonBlue) |
| 1149 | { |
| 1150 | // This tests that we correctly handle unread fragment inputs |
| 1151 | |
| 1152 | static const char *vertShaderText = |
| 1153 | "#version 140\n" |
| 1154 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1155 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1156 | "layout (location = 0) in vec4 pos;\n" |
| 1157 | "layout (location = 0) out vec4 outColor;\n" |
| 1158 | "layout (location = 1) out vec4 outColor2;\n" |
| 1159 | "void main() {\n" |
| 1160 | " gl_Position = pos;\n" |
| 1161 | " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n" |
| 1162 | " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n" |
| 1163 | "}\n"; |
| 1164 | |
| 1165 | static const char *fragShaderText = |
| 1166 | //"#version 140\n" |
| 1167 | "#version 330\n" |
| 1168 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1169 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1170 | //"#extension GL_ARB_fragment_coord_conventions : enable\n" |
| 1171 | //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n" |
| 1172 | "layout (location = 0) in vec4 color;\n" |
| 1173 | "layout (location = 1) in vec4 color2;\n" |
| 1174 | "void main() {\n" |
| 1175 | " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n" |
| 1176 | " float dist_squared = dot(pos, pos);\n" |
| 1177 | " gl_FragColor = (dist_squared < 400.0)\n" |
| 1178 | " ? vec4(1.0, 0.0, 0.0, 1.0)\n" |
| 1179 | " : color2;\n" |
| 1180 | "}\n"; |
| 1181 | |
| 1182 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1183 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1184 | |
| 1185 | XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 1186 | meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1187 | |
| 1188 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1189 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1190 | |
| 1191 | XglPipelineObj pipelineobj(m_device); |
| 1192 | pipelineobj.AddShader(&vs); |
| 1193 | pipelineobj.AddShader(&ps); |
| 1194 | |
| 1195 | XglDescriptorSetObj descriptorSet(m_device); |
| 1196 | descriptorSet.AttachMemoryView(&meshBuffer); |
| 1197 | |
| 1198 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1199 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1200 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1201 | }; |
| 1202 | |
| 1203 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1204 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1205 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1206 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1207 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1208 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1209 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1210 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1211 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1212 | |
| 1213 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 1214 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 1215 | pipelineobj.AddVertexDataBuffer(&meshBuffer,0); |
| 1216 | |
Tony Barbour | 1c04203 | 2014-12-03 16:13:23 -0700 | [diff] [blame] | 1217 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1218 | QueueCommandBuffer(NULL, 0); |
| 1219 | |
| 1220 | } |
| 1221 | |
| 1222 | TEST_F(XglRenderTest, GreyCirclesonBlueFade) |
| 1223 | { |
| 1224 | // This tests reading gl_ClipDistance from FS |
| 1225 | |
| 1226 | static const char *vertShaderText = |
| 1227 | "#version 330\n" |
| 1228 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1229 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1230 | "out gl_PerVertex {\n" |
| 1231 | " vec4 gl_Position;\n" |
| 1232 | " float gl_ClipDistance[1];\n" |
| 1233 | "};\n" |
| 1234 | "layout (location = 0) in vec4 pos;\n" |
| 1235 | "layout (location = 0) out vec4 outColor;\n" |
| 1236 | "layout (location = 1) out vec4 outColor2;\n" |
| 1237 | "void main() {\n" |
| 1238 | " gl_Position = pos;\n" |
| 1239 | " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n" |
| 1240 | " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n" |
| 1241 | " float dists[3];\n" |
| 1242 | " dists[0] = 0.0;\n" |
| 1243 | " dists[1] = 1.0;\n" |
| 1244 | " dists[2] = 1.0;\n" |
| 1245 | " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n" |
| 1246 | "}\n"; |
| 1247 | |
| 1248 | |
| 1249 | static const char *fragShaderText = |
| 1250 | //"#version 140\n" |
| 1251 | "#version 330\n" |
| 1252 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1253 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1254 | //"#extension GL_ARB_fragment_coord_conventions : enable\n" |
| 1255 | //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n" |
| 1256 | "layout (location = 0) in vec4 color;\n" |
| 1257 | "layout (location = 1) in vec4 color2;\n" |
| 1258 | "void main() {\n" |
| 1259 | " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n" |
| 1260 | " float dist_squared = dot(pos, pos);\n" |
| 1261 | " gl_FragColor = (dist_squared < 400.0)\n" |
| 1262 | " ? color * gl_ClipDistance[0]\n" |
| 1263 | " : color2;\n" |
| 1264 | "}\n"; |
| 1265 | |
| 1266 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1267 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1268 | |
| 1269 | XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 1270 | meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1271 | |
| 1272 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1273 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1274 | |
| 1275 | XglPipelineObj pipelineobj(m_device); |
| 1276 | pipelineobj.AddShader(&vs); |
| 1277 | pipelineobj.AddShader(&ps); |
| 1278 | |
| 1279 | XglDescriptorSetObj descriptorSet(m_device); |
| 1280 | descriptorSet.AttachMemoryView(&meshBuffer); |
| 1281 | |
| 1282 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1283 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1284 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1285 | }; |
| 1286 | |
| 1287 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1288 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1289 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1290 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1291 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1292 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1293 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1294 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1295 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1296 | |
| 1297 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 1298 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 1299 | pipelineobj.AddVertexDataBuffer(&meshBuffer,0); |
| 1300 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 1301 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2); |
GregF | 3156cb0 | 2014-12-02 15:41:44 -0700 | [diff] [blame] | 1302 | QueueCommandBuffer(NULL, 0); |
| 1303 | |
| 1304 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1305 | |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1306 | TEST_F(XglRenderTest, GreyCirclesonBlueDiscard) |
| 1307 | { |
| 1308 | static const char *vertShaderText = |
| 1309 | "#version 140\n" |
| 1310 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1311 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1312 | "layout (location = 0) in vec4 pos;\n" |
| 1313 | "layout (location = 0) out vec4 outColor;\n" |
| 1314 | "layout (location = 1) out vec4 outColor2;\n" |
| 1315 | "void main() {\n" |
| 1316 | " gl_Position = pos;\n" |
| 1317 | " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n" |
| 1318 | " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n" |
| 1319 | "}\n"; |
| 1320 | |
| 1321 | |
| 1322 | static const char *fragShaderText = |
| 1323 | //"#version 140\n" |
| 1324 | "#version 330\n" |
| 1325 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1326 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1327 | //"#extension GL_ARB_fragment_coord_conventions : enable\n" |
| 1328 | //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n" |
| 1329 | "layout (location = 0) in vec4 color;\n" |
| 1330 | "layout (location = 1) in vec4 color2;\n" |
| 1331 | "void main() {\n" |
| 1332 | " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n" |
| 1333 | " float dist_squared = dot(pos, pos);\n" |
| 1334 | " if (dist_squared < 100.0)\n" |
| 1335 | " discard;\n" |
| 1336 | " gl_FragColor = (dist_squared < 400.0)\n" |
| 1337 | " ? color\n" |
| 1338 | " : color2;\n" |
| 1339 | "}\n"; |
| 1340 | |
| 1341 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1342 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1343 | |
| 1344 | XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 1345 | meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY); |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1346 | |
| 1347 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1348 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1349 | |
| 1350 | XglPipelineObj pipelineobj(m_device); |
| 1351 | pipelineobj.AddShader(&vs); |
| 1352 | pipelineobj.AddShader(&ps); |
| 1353 | |
| 1354 | XglDescriptorSetObj descriptorSet(m_device); |
| 1355 | descriptorSet.AttachMemoryView(&meshBuffer); |
| 1356 | |
| 1357 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1358 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1359 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1360 | }; |
| 1361 | |
| 1362 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1363 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1364 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1365 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1366 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1367 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1368 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1369 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1370 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1371 | |
| 1372 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 1373 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 1374 | pipelineobj.AddVertexDataBuffer(&meshBuffer,0); |
| 1375 | |
Tony Barbour | 1c04203 | 2014-12-03 16:13:23 -0700 | [diff] [blame] | 1376 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2); |
GregF | 4222658 | 2014-12-02 17:19:34 -0700 | [diff] [blame] | 1377 | QueueCommandBuffer(NULL, 0); |
| 1378 | |
| 1379 | } |
| 1380 | |
| 1381 | |
Courtney Goeltzenleuchter | d66e41e | 2014-10-27 13:06:08 -0600 | [diff] [blame] | 1382 | TEST_F(XglRenderTest, TriangleVSUniform) |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1383 | { |
| 1384 | static const char *vertShaderText = |
Courtney Goeltzenleuchter | 8285704 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1385 | "#version 140\n" |
| 1386 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1387 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1388 | "\n" |
| 1389 | "layout(binding = 0) uniform buf {\n" |
| 1390 | " mat4 MVP;\n" |
| 1391 | "} ubuf;\n" |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1392 | "void main() {\n" |
| 1393 | " vec2 vertices[3];" |
| 1394 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1395 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1396 | " vertices[2] = vec2( 0.5, 0.5);\n" |
Courtney Goeltzenleuchter | 8285704 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1397 | " 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] | 1398 | "}\n"; |
| 1399 | |
| 1400 | static const char *fragShaderText = |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1401 | "#version 130\n" |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1402 | "void main() {\n" |
Cody Northrop | bb38ad3 | 2014-10-10 15:45:00 -0600 | [diff] [blame] | 1403 | " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" |
Cody Northrop | 66594a7 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1404 | "}\n"; |
| 1405 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1406 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1407 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1408 | |
Courtney Goeltzenleuchter | fdcfb9f | 2014-10-10 18:04:39 -0600 | [diff] [blame] | 1409 | // Create identity matrix |
Courtney Goeltzenleuchter | 8285704 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1410 | glm::mat4 Projection = glm::mat4(1.0f); |
| 1411 | glm::mat4 View = glm::mat4(1.0f); |
| 1412 | glm::mat4 Model = glm::mat4(1.0f); |
| 1413 | glm::mat4 MVP = Projection * View * Model; |
| 1414 | const int matrixSize = sizeof(MVP) / sizeof(MVP[0]); |
| 1415 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1416 | XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]); |
| 1417 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1418 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
Courtney Goeltzenleuchter | 8285704 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1419 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1420 | vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer); |
| 1421 | |
| 1422 | XglPipelineObj pipelineobj(m_device); |
| 1423 | pipelineobj.AddShader(&vs); |
| 1424 | pipelineobj.AddShader(&ps); |
| 1425 | |
| 1426 | // Create descriptor set and attach the constant buffer to it |
| 1427 | XglDescriptorSetObj descriptorSet(m_device); |
| 1428 | descriptorSet.AttachMemoryView(&MVPBuffer); |
| 1429 | |
| 1430 | m_memoryRefManager.AddMemoryRef(&MVPBuffer); |
| 1431 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 1432 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1433 | QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs()); |
| 1434 | |
Tony Barbour | 1c04203 | 2014-12-03 16:13:23 -0700 | [diff] [blame] | 1435 | RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer); |
Courtney Goeltzenleuchter | 8285704 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1436 | } |
| 1437 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1438 | TEST_F(XglRenderTest, MixTriangle) |
| 1439 | { |
| 1440 | // This tests location applied to varyings. Notice that we have switched foo |
| 1441 | // and bar in the FS. The triangle should be blended with red, green and blue |
| 1442 | // corners. |
| 1443 | static const char *vertShaderText = |
| 1444 | "#version 140\n" |
| 1445 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1446 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1447 | "layout (location=0) out vec4 bar;\n" |
| 1448 | "layout (location=1) out vec4 foo;\n" |
| 1449 | "layout (location=2) out float scale;\n" |
| 1450 | "vec2 vertices[3];\n" |
| 1451 | "void main() {\n" |
| 1452 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 1453 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 1454 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 1455 | "vec4 colors[3];\n" |
| 1456 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 1457 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 1458 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 1459 | " foo = colors[gl_VertexID % 3];\n" |
| 1460 | " bar = vec4(1.0, 1.0, 1.0, 1.0);\n" |
| 1461 | " scale = 1.0;\n" |
| 1462 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1463 | "}\n"; |
| 1464 | |
| 1465 | static const char *fragShaderText = |
| 1466 | "#version 140\n" |
| 1467 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1468 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1469 | "layout (location = 1) in vec4 bar;\n" |
| 1470 | "layout (location = 0) in vec4 foo;\n" |
| 1471 | "layout (location = 2) in float scale;\n" |
| 1472 | "void main() {\n" |
| 1473 | " gl_FragColor = bar * scale + foo * (1.0-scale);\n" |
| 1474 | "}\n"; |
| 1475 | |
| 1476 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1477 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1478 | |
| 1479 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1480 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1481 | |
| 1482 | XglPipelineObj pipelineobj(m_device); |
| 1483 | pipelineobj.AddShader(&vs); |
| 1484 | pipelineobj.AddShader(&ps); |
| 1485 | |
| 1486 | XglDescriptorSetObj descriptorSet(m_device); |
| 1487 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 1488 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1489 | QueueCommandBuffer(NULL, 0); |
| 1490 | } |
| 1491 | |
| 1492 | TEST_F(XglRenderTest, TriVertFetchAndVertID) |
| 1493 | { |
| 1494 | // This tests that attributes work in the presence of gl_VertexID |
| 1495 | |
| 1496 | static const char *vertShaderText = |
| 1497 | "#version 140\n" |
| 1498 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1499 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1500 | //XYZ1( -1, -1, -1 ) |
| 1501 | "layout (location = 0) in vec4 pos;\n" |
| 1502 | //XYZ1( 0.f, 0.f, 0.f ) |
| 1503 | "layout (location = 1) in vec4 inColor;\n" |
| 1504 | "layout (location = 0) out vec4 outColor;\n" |
| 1505 | "void main() {\n" |
| 1506 | " outColor = inColor;\n" |
| 1507 | " vec4 vertices[3];" |
| 1508 | " vertices[gl_VertexID % 3] = pos;\n" |
| 1509 | " gl_Position = vertices[(gl_VertexID + 3) % 3];\n" |
| 1510 | "}\n"; |
| 1511 | |
| 1512 | |
| 1513 | static const char *fragShaderText = |
| 1514 | "#version 140\n" |
| 1515 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1516 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1517 | "layout (location = 0) in vec4 color;\n" |
| 1518 | "void main() {\n" |
| 1519 | " gl_FragColor = color;\n" |
| 1520 | "}\n"; |
| 1521 | |
| 1522 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1523 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1524 | |
| 1525 | XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 1526 | meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1527 | |
| 1528 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1529 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1530 | |
| 1531 | XglPipelineObj pipelineobj(m_device); |
| 1532 | pipelineobj.AddShader(&vs); |
| 1533 | pipelineobj.AddShader(&ps); |
| 1534 | |
| 1535 | XglDescriptorSetObj descriptorSet(m_device); |
| 1536 | descriptorSet.AttachMemoryView(&meshBuffer); |
| 1537 | |
| 1538 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1539 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1540 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1541 | }; |
| 1542 | |
| 1543 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1544 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1545 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1546 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1547 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1548 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1549 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1550 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1551 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1552 | |
| 1553 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 1554 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 1555 | pipelineobj.AddVertexDataBuffer(&meshBuffer,0); |
| 1556 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 1557 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1558 | QueueCommandBuffer(NULL, 0); |
| 1559 | } |
| 1560 | |
| 1561 | TEST_F(XglRenderTest, TriVertFetchDeadAttr) |
| 1562 | { |
| 1563 | // This tests that attributes work in the presence of gl_VertexID |
| 1564 | // and a dead attribute in position 0. Draws a triangle with yellow, |
| 1565 | // red and green corners, starting at top and going clockwise. |
| 1566 | |
| 1567 | static const char *vertShaderText = |
| 1568 | "#version 140\n" |
| 1569 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1570 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1571 | //XYZ1( -1, -1, -1 ) |
| 1572 | "layout (location = 0) in vec4 pos;\n" |
| 1573 | //XYZ1( 0.f, 0.f, 0.f ) |
| 1574 | "layout (location = 1) in vec4 inColor;\n" |
| 1575 | "layout (location = 0) out vec4 outColor;\n" |
| 1576 | "void main() {\n" |
| 1577 | " outColor = inColor;\n" |
| 1578 | " vec2 vertices[3];" |
| 1579 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 1580 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 1581 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 1582 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1583 | "}\n"; |
| 1584 | |
| 1585 | |
| 1586 | static const char *fragShaderText = |
| 1587 | "#version 140\n" |
| 1588 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1589 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1590 | "layout (location = 0) in vec4 color;\n" |
| 1591 | "void main() {\n" |
| 1592 | " gl_FragColor = color;\n" |
| 1593 | "}\n"; |
| 1594 | |
| 1595 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1596 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1597 | |
| 1598 | XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 1599 | meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1600 | |
| 1601 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1602 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1603 | |
| 1604 | XglPipelineObj pipelineobj(m_device); |
| 1605 | pipelineobj.AddShader(&vs); |
| 1606 | pipelineobj.AddShader(&ps); |
| 1607 | |
| 1608 | XglDescriptorSetObj descriptorSet(m_device); |
| 1609 | descriptorSet.AttachMemoryView(&meshBuffer); |
| 1610 | |
| 1611 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1612 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1613 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1614 | }; |
| 1615 | |
| 1616 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1617 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1618 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1619 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1620 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1621 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1622 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1623 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1624 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1625 | |
| 1626 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 1627 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 1628 | pipelineobj.AddVertexDataBuffer(&meshBuffer,0); |
| 1629 | |
Tony Barbour | 1c04203 | 2014-12-03 16:13:23 -0700 | [diff] [blame] | 1630 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1631 | QueueCommandBuffer(NULL, 0); |
| 1632 | |
| 1633 | } |
| 1634 | |
| 1635 | TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP) |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1636 | { |
| 1637 | static const char *vertShaderText = |
| 1638 | "#version 140\n" |
| 1639 | "layout (std140) uniform bufferVals {\n" |
| 1640 | " mat4 mvp;\n" |
| 1641 | "} myBufferVals;\n" |
| 1642 | "in vec4 pos;\n" |
| 1643 | "in vec4 inColor;\n" |
| 1644 | "out vec4 outColor;\n" |
| 1645 | "void main() {\n" |
| 1646 | " outColor = inColor;\n" |
| 1647 | " gl_Position = myBufferVals.mvp * pos;\n" |
| 1648 | "}\n"; |
| 1649 | |
| 1650 | static const char *fragShaderText = |
| 1651 | "#version 130\n" |
| 1652 | "in vec4 color;\n" |
| 1653 | "void main() {\n" |
| 1654 | " gl_FragColor = color;\n" |
| 1655 | "}\n"; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1656 | 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] | 1657 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1658 | glm::mat4 View = glm::lookAt( |
| 1659 | glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space |
| 1660 | glm::vec3(0,0,0), // and looks at the origin |
| 1661 | glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down) |
| 1662 | ); |
| 1663 | |
| 1664 | glm::mat4 Model = glm::mat4(1.0f); |
| 1665 | |
| 1666 | glm::mat4 MVP = Projection * View * Model; |
| 1667 | |
| 1668 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1669 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1670 | ASSERT_NO_FATAL_FAILURE(InitDepthStencil()); |
| 1671 | |
| 1672 | XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]), |
| 1673 | sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data); |
| 1674 | |
| 1675 | const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT); |
| 1676 | |
| 1677 | XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]); |
| 1678 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1679 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1680 | |
| 1681 | vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer); |
| 1682 | |
| 1683 | XglPipelineObj pipelineobj(m_device); |
| 1684 | pipelineobj.AddShader(&vs); |
| 1685 | pipelineobj.AddShader(&ps); |
| 1686 | |
| 1687 | XglDescriptorSetObj descriptorSet(m_device); |
| 1688 | descriptorSet.AttachMemoryView(&MVPBuffer); |
| 1689 | |
| 1690 | m_memoryRefManager.AddMemoryRef(&meshBuffer); |
| 1691 | m_memoryRefManager.AddMemoryRef(&MVPBuffer); |
| 1692 | |
| 1693 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1694 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1695 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1696 | }; |
| 1697 | |
| 1698 | // this is the current description of g_vbData |
| 1699 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1700 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1701 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1702 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1703 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1704 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1705 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1706 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1707 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1708 | |
| 1709 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 1710 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 1711 | pipelineobj.AddVertexDataBuffer(&meshBuffer,0); |
| 1712 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 1713 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 12); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1714 | |
| 1715 | QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs()); |
| 1716 | |
Courtney Goeltzenleuchter | 8388495 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1717 | } |
| 1718 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1719 | TEST_F(XglRenderTest, VSTexture) |
| 1720 | { |
| 1721 | // The expected result from this test is a green and red triangle; |
| 1722 | // one red vertex on the left, two green vertices on the right. |
| 1723 | static const char *vertShaderText = |
| 1724 | "#version 130\n" |
| 1725 | "out vec4 texColor;\n" |
| 1726 | "uniform sampler2D surface;\n" |
| 1727 | "void main() {\n" |
| 1728 | " vec2 vertices[3];" |
| 1729 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1730 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1731 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 1732 | " vec2 positions[3];" |
| 1733 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 1734 | " positions[1] = vec2( 0.25, 0.1);\n" |
| 1735 | " positions[2] = vec2( 0.1, 0.25);\n" |
| 1736 | " vec2 samplePos = positions[gl_VertexID % 3];\n" |
| 1737 | " texColor = textureLod(surface, samplePos, 0.0);\n" |
| 1738 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1739 | "}\n"; |
| 1740 | |
| 1741 | static const char *fragShaderText = |
| 1742 | "#version 130\n" |
| 1743 | "in vec4 texColor;\n" |
| 1744 | "void main() {\n" |
| 1745 | " gl_FragColor = texColor;\n" |
| 1746 | "}\n"; |
| 1747 | |
| 1748 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1749 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1750 | |
| 1751 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1752 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1753 | XglSamplerObj sampler(m_device); |
| 1754 | XglTextureObj texture(m_device); |
| 1755 | |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 1756 | vs.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1757 | vs.BindShaderEntitySlotToSampler(0, &sampler); |
| 1758 | |
| 1759 | XglPipelineObj pipelineobj(m_device); |
| 1760 | pipelineobj.AddShader(&vs); |
| 1761 | pipelineobj.AddShader(&ps); |
| 1762 | |
| 1763 | XglDescriptorSetObj descriptorSet(m_device); |
| 1764 | descriptorSet.AttachImageView(&texture); |
| 1765 | descriptorSet.AttachSampler(&sampler); |
| 1766 | |
| 1767 | m_memoryRefManager.AddMemoryRef(&texture); |
| 1768 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 1769 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1770 | QueueCommandBuffer(NULL, 0); |
| 1771 | |
| 1772 | } |
| 1773 | TEST_F(XglRenderTest, TexturedTriangle) |
| 1774 | { |
| 1775 | // The expected result from this test is a red and green checkered triangle |
| 1776 | static const char *vertShaderText = |
| 1777 | "#version 140\n" |
| 1778 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1779 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1780 | "layout (location = 0) out vec2 samplePos;\n" |
| 1781 | "void main() {\n" |
| 1782 | " vec2 vertices[3];" |
| 1783 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1784 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1785 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 1786 | " vec2 positions[3];" |
| 1787 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 1788 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 1789 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 1790 | " samplePos = positions[gl_VertexID % 3];\n" |
| 1791 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1792 | "}\n"; |
| 1793 | |
| 1794 | static const char *fragShaderText = |
| 1795 | "#version 140\n" |
| 1796 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1797 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1798 | "layout (location = 0) in vec2 samplePos;\n" |
| 1799 | "layout (binding = 0) uniform sampler2D surface;\n" |
| 1800 | "layout (location=0) out vec4 outColor;\n" |
| 1801 | "void main() {\n" |
| 1802 | " vec4 texColor = textureLod(surface, samplePos, 0.0);\n" |
| 1803 | " outColor = texColor;\n" |
| 1804 | "}\n"; |
| 1805 | |
| 1806 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1807 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1808 | |
| 1809 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1810 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1811 | XglSamplerObj sampler(m_device); |
| 1812 | XglTextureObj texture(m_device); |
| 1813 | |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 1814 | ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1815 | ps.BindShaderEntitySlotToSampler(0, &sampler); |
| 1816 | |
| 1817 | XglPipelineObj pipelineobj(m_device); |
| 1818 | pipelineobj.AddShader(&vs); |
| 1819 | pipelineobj.AddShader(&ps); |
| 1820 | |
| 1821 | XglDescriptorSetObj descriptorSet(m_device); |
| 1822 | descriptorSet.AttachImageView(&texture); |
| 1823 | descriptorSet.AttachSampler(&sampler); |
| 1824 | |
| 1825 | m_memoryRefManager.AddMemoryRef(&texture); |
| 1826 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 1827 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1828 | QueueCommandBuffer(NULL, 0); |
| 1829 | } |
| 1830 | TEST_F(XglRenderTest, TexturedTriangleClip) |
| 1831 | { |
| 1832 | // The expected result from this test is a red and green checkered triangle |
| 1833 | static const char *vertShaderText = |
| 1834 | "#version 330\n" |
| 1835 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1836 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1837 | "layout (location = 0) out vec2 samplePos;\n" |
| 1838 | "out gl_PerVertex {\n" |
| 1839 | " vec4 gl_Position;\n" |
| 1840 | " float gl_ClipDistance[1];\n" |
| 1841 | "};\n" |
| 1842 | "void main() {\n" |
| 1843 | " vec2 vertices[3];" |
| 1844 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1845 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1846 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 1847 | " vec2 positions[3];" |
| 1848 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 1849 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 1850 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 1851 | " float dists[3];\n" |
| 1852 | " dists[0] = 1.0;\n" |
| 1853 | " dists[1] = 1.0;\n" |
| 1854 | " dists[2] = -1.0;\n" |
| 1855 | " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n" |
| 1856 | " samplePos = positions[gl_VertexID % 3];\n" |
| 1857 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1858 | "}\n"; |
| 1859 | |
| 1860 | static const char *fragShaderText = |
| 1861 | "#version 140\n" |
| 1862 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1863 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1864 | "layout (location = 0) in vec2 samplePos;\n" |
| 1865 | "layout (binding = 0) uniform sampler2D surface;\n" |
| 1866 | "layout (location=0) out vec4 outColor;\n" |
| 1867 | "void main() {\n" |
| 1868 | //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n" |
| 1869 | " vec4 texColor = textureLod(surface, samplePos, 0.0);\n" |
| 1870 | " outColor = texColor;\n" |
| 1871 | "}\n"; |
| 1872 | |
| 1873 | |
| 1874 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1875 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1876 | |
| 1877 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1878 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1879 | XglSamplerObj sampler(m_device); |
| 1880 | XglTextureObj texture(m_device); |
| 1881 | |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 1882 | ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1883 | ps.BindShaderEntitySlotToSampler(0, &sampler); |
| 1884 | |
| 1885 | XglPipelineObj pipelineobj(m_device); |
| 1886 | pipelineobj.AddShader(&vs); |
| 1887 | pipelineobj.AddShader(&ps); |
| 1888 | |
| 1889 | XglDescriptorSetObj descriptorSet(m_device); |
| 1890 | descriptorSet.AttachImageView(&texture); |
| 1891 | descriptorSet.AttachSampler(&sampler); |
| 1892 | |
| 1893 | m_memoryRefManager.AddMemoryRef(&texture); |
| 1894 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 1895 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1896 | QueueCommandBuffer(NULL, 0); |
| 1897 | } |
| 1898 | TEST_F(XglRenderTest, FSTriangle) |
| 1899 | { |
| 1900 | // The expected result from this test is a red and green checkered triangle |
| 1901 | static const char *vertShaderText = |
| 1902 | "#version 140\n" |
| 1903 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1904 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1905 | "layout (location = 0) out vec2 samplePos;\n" |
| 1906 | "void main() {\n" |
| 1907 | " vec2 vertices[3];" |
| 1908 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1909 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1910 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 1911 | " vec2 positions[3];" |
| 1912 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 1913 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 1914 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 1915 | " samplePos = positions[gl_VertexID % 3];\n" |
| 1916 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1917 | "}\n"; |
| 1918 | |
| 1919 | static const char *fragShaderText = |
| 1920 | "#version 140\n" |
| 1921 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1922 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1923 | "layout (location = 0) in vec2 samplePos;\n" |
| 1924 | "layout (binding = 0) uniform sampler2D surface;\n" |
| 1925 | "layout (location=0) out vec4 outColor;\n" |
| 1926 | "void main() {\n" |
| 1927 | " vec4 texColor = textureLod(surface, samplePos, 0.0);\n" |
| 1928 | " outColor = texColor;\n" |
| 1929 | "}\n"; |
| 1930 | |
| 1931 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1932 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1933 | |
| 1934 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1935 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1936 | XglSamplerObj sampler(m_device); |
| 1937 | XglTextureObj texture(m_device); |
| 1938 | |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 1939 | ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1940 | ps.BindShaderEntitySlotToSampler(0, &sampler); |
| 1941 | |
| 1942 | XglPipelineObj pipelineobj(m_device); |
| 1943 | pipelineobj.AddShader(&vs); |
| 1944 | pipelineobj.AddShader(&ps); |
| 1945 | |
| 1946 | XglDescriptorSetObj descriptorSet(m_device); |
| 1947 | descriptorSet.AttachImageView(&texture); |
| 1948 | descriptorSet.AttachSampler(&sampler); |
| 1949 | |
| 1950 | m_memoryRefManager.AddMemoryRef(&texture); |
| 1951 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 1952 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1953 | QueueCommandBuffer(NULL, 0); |
| 1954 | } |
| 1955 | TEST_F(XglRenderTest, SamplerBindingsTriangle) |
| 1956 | { |
| 1957 | // This test sets bindings on the samplers |
| 1958 | // For now we are asserting that sampler and texture pairs |
| 1959 | // march in lock step, and are set via GLSL binding. This can |
| 1960 | // and will probably change. |
| 1961 | // The sampler bindings should match the sampler and texture slot |
| 1962 | // number set up by the application. |
| 1963 | // This test will result in a blue triangle |
| 1964 | static const char *vertShaderText = |
| 1965 | "#version 140\n" |
| 1966 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1967 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1968 | "layout (location = 0) out vec4 samplePos;\n" |
| 1969 | "void main() {\n" |
| 1970 | " vec2 vertices[3];" |
| 1971 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1972 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1973 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 1974 | " vec2 positions[3];" |
| 1975 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 1976 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 1977 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 1978 | " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n" |
| 1979 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1980 | "}\n"; |
| 1981 | |
| 1982 | static const char *fragShaderText = |
| 1983 | "#version 140\n" |
| 1984 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1985 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1986 | "layout (location = 0) in vec4 samplePos;\n" |
| 1987 | "layout (binding = 0) uniform sampler2D surface0;\n" |
| 1988 | "layout (binding = 1) uniform sampler2D surface1;\n" |
| 1989 | "layout (binding = 12) uniform sampler2D surface2;\n" |
| 1990 | "void main() {\n" |
| 1991 | " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n" |
| 1992 | "}\n"; |
| 1993 | |
| 1994 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1995 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1996 | |
| 1997 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 1998 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 1999 | |
| 2000 | XglSamplerObj sampler1(m_device); |
| 2001 | XglSamplerObj sampler2(m_device); |
| 2002 | XglSamplerObj sampler3(m_device); |
| 2003 | |
| 2004 | XglTextureObj texture1(m_device); // Red |
| 2005 | texture1.ChangeColors(0xffff0000,0xffff0000); |
| 2006 | XglTextureObj texture2(m_device); // Green |
| 2007 | texture2.ChangeColors(0xff00ff00,0xff00ff00); |
| 2008 | XglTextureObj texture3(m_device); // Blue |
| 2009 | texture3.ChangeColors(0xff0000ff,0xff0000ff); |
| 2010 | |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2011 | ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2012 | ps.BindShaderEntitySlotToSampler(0, &sampler1); |
| 2013 | |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2014 | ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2015 | ps.BindShaderEntitySlotToSampler(1, &sampler2); |
| 2016 | |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2017 | ps.BindShaderEntitySlotToImage(12, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture3); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2018 | ps.BindShaderEntitySlotToSampler(12, &sampler3); |
| 2019 | |
| 2020 | XglPipelineObj pipelineobj(m_device); |
| 2021 | pipelineobj.AddShader(&vs); |
| 2022 | pipelineobj.AddShader(&ps); |
| 2023 | |
| 2024 | XglDescriptorSetObj descriptorSet(m_device); |
| 2025 | descriptorSet.AttachImageView(&texture1); |
| 2026 | descriptorSet.AttachSampler(&sampler1); |
| 2027 | descriptorSet.AttachImageView(&texture2); |
| 2028 | descriptorSet.AttachSampler(&sampler2); |
| 2029 | descriptorSet.AttachImageView(&texture3); |
| 2030 | descriptorSet.AttachSampler(&sampler3); |
| 2031 | |
| 2032 | m_memoryRefManager.AddMemoryRef(&texture1); |
| 2033 | m_memoryRefManager.AddMemoryRef(&texture2); |
| 2034 | m_memoryRefManager.AddMemoryRef(&texture3); |
| 2035 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 2036 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2037 | QueueCommandBuffer(NULL, 0); |
| 2038 | |
| 2039 | } |
| 2040 | |
| 2041 | TEST_F(XglRenderTest, TriangleVSUniformBlock) |
| 2042 | { |
| 2043 | // The expected result from this test is a blue triangle |
| 2044 | |
| 2045 | static const char *vertShaderText = |
| 2046 | "#version 140\n" |
| 2047 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2048 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2049 | "layout (location = 0) out vec4 outColor;\n" |
| 2050 | "layout (std140, binding = 0) uniform bufferVals {\n" |
| 2051 | " vec4 red;\n" |
| 2052 | " vec4 green;\n" |
| 2053 | " vec4 blue;\n" |
| 2054 | " vec4 white;\n" |
| 2055 | "} myBufferVals;\n" |
| 2056 | "void main() {\n" |
| 2057 | " vec2 vertices[3];" |
| 2058 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2059 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2060 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2061 | " outColor = myBufferVals.blue;\n" |
| 2062 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2063 | "}\n"; |
| 2064 | |
| 2065 | static const char *fragShaderText = |
| 2066 | "#version 140\n" |
| 2067 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2068 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2069 | "layout (location = 0) in vec4 inColor;\n" |
| 2070 | "void main() {\n" |
| 2071 | " gl_FragColor = inColor;\n" |
| 2072 | "}\n"; |
| 2073 | |
| 2074 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2075 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2076 | |
| 2077 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 2078 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 2079 | |
| 2080 | // Let's populate our buffer with the following: |
| 2081 | // vec4 red; |
| 2082 | // vec4 green; |
| 2083 | // vec4 blue; |
| 2084 | // vec4 white; |
| 2085 | const int valCount = 4 * 4; |
| 2086 | const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0, |
| 2087 | 0.0, 1.0, 0.0, 1.0, |
| 2088 | 0.0, 0.0, 1.0, 1.0, |
| 2089 | 1.0, 1.0, 1.0, 1.0 }; |
| 2090 | |
| 2091 | XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals); |
| 2092 | vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &colorBuffer); |
| 2093 | |
| 2094 | XglPipelineObj pipelineobj(m_device); |
| 2095 | pipelineobj.AddShader(&vs); |
| 2096 | pipelineobj.AddShader(&ps); |
| 2097 | |
| 2098 | XglDescriptorSetObj descriptorSet(m_device); |
| 2099 | descriptorSet.AttachMemoryView(&colorBuffer); |
| 2100 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 2101 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2102 | QueueCommandBuffer(NULL, 0); |
| 2103 | |
| 2104 | } |
| 2105 | |
| 2106 | TEST_F(XglRenderTest, TriangleFSUniformBlockBinding) |
| 2107 | { |
| 2108 | // This test allows the shader to select which buffer it is |
| 2109 | // pulling from using layout binding qualifier. |
| 2110 | // There are corresponding changes in the compiler stack that |
| 2111 | // will select the buffer using binding directly. |
| 2112 | // The binding number should match the slot number set up by |
| 2113 | // the application. |
| 2114 | // The expected result from this test is a purple triangle |
| 2115 | |
| 2116 | static const char *vertShaderText = |
| 2117 | "#version 140\n" |
| 2118 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2119 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2120 | "void main() {\n" |
| 2121 | " vec2 vertices[3];" |
| 2122 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2123 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2124 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2125 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2126 | "}\n"; |
| 2127 | |
| 2128 | static const char *fragShaderText = |
| 2129 | "#version 140\n" |
| 2130 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2131 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2132 | "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;" |
| 2133 | "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;" |
| 2134 | "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;" |
| 2135 | "layout (std140, binding = 18) uniform whiteVal { vec4 color; } myWhiteVal\n;" |
| 2136 | "void main() {\n" |
| 2137 | " gl_FragColor = myBlueVal.color;\n" |
| 2138 | " gl_FragColor += myRedVal.color;\n" |
| 2139 | "}\n"; |
| 2140 | |
| 2141 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2142 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2143 | |
| 2144 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 2145 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 2146 | |
| 2147 | // We're going to create a number of uniform buffers, and then allow |
| 2148 | // the shader to select which it wants to read from with a binding |
| 2149 | |
| 2150 | // Let's populate the buffers with a single color each: |
| 2151 | // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal; |
| 2152 | // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal; |
| 2153 | // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal; |
| 2154 | // layout (std140, binding = 18) uniform bufferVals { vec4 white; } myWhiteVal; |
| 2155 | |
| 2156 | const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 }; |
| 2157 | const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 }; |
| 2158 | const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 }; |
| 2159 | const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 2160 | |
| 2161 | const int redCount = sizeof(redVals) / sizeof(float); |
| 2162 | const int greenCount = sizeof(greenVals) / sizeof(float); |
| 2163 | const int blueCount = sizeof(blueVals) / sizeof(float); |
| 2164 | const int whiteCount = sizeof(whiteVals) / sizeof(float); |
| 2165 | |
| 2166 | XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals); |
| 2167 | ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer); |
| 2168 | |
| 2169 | XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals); |
| 2170 | ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer); |
| 2171 | |
| 2172 | XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals); |
| 2173 | ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer); |
| 2174 | |
| 2175 | XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals); |
| 2176 | ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer); |
| 2177 | |
| 2178 | XglPipelineObj pipelineobj(m_device); |
| 2179 | pipelineobj.AddShader(&vs); |
| 2180 | pipelineobj.AddShader(&ps); |
| 2181 | |
| 2182 | XglDescriptorSetObj descriptorSet(m_device); |
| 2183 | descriptorSet.AttachMemoryView(&redBuffer); |
| 2184 | descriptorSet.AttachMemoryView(&greenBuffer); |
| 2185 | descriptorSet.AttachMemoryView(&blueBuffer); |
| 2186 | descriptorSet.AttachMemoryView(&whiteBuffer); |
| 2187 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 2188 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2189 | QueueCommandBuffer(NULL, 0); |
| 2190 | |
| 2191 | } |
| 2192 | |
| 2193 | TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding) |
| 2194 | { |
| 2195 | // This test is the same as TriangleFSUniformBlockBinding, but |
| 2196 | // it does not provide an instance name. |
| 2197 | // The expected result from this test is a purple triangle |
| 2198 | |
| 2199 | static const char *vertShaderText = |
| 2200 | "#version 140\n" |
| 2201 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2202 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2203 | "void main() {\n" |
| 2204 | " vec2 vertices[3];" |
| 2205 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2206 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2207 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2208 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2209 | "}\n"; |
| 2210 | |
| 2211 | static const char *fragShaderText = |
| 2212 | "#version 430\n" |
| 2213 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2214 | "#extension GL_ARB_shading_language_420pack : enable\n" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2215 | "layout (std140, binding = 0) uniform redVal { vec4 red; };" |
| 2216 | "layout (std140, binding = 1) uniform greenVal { vec4 green; };" |
| 2217 | "layout (std140, binding = 2) uniform blueVal { vec4 blue; };" |
| 2218 | "layout (std140, binding = 18) uniform whiteVal { vec4 white; };" |
Cody Northrop | d43c52e | 2014-12-05 15:44:14 -0700 | [diff] [blame] | 2219 | "layout (location = 0) out vec4 outColor;\n" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2220 | "void main() {\n" |
Cody Northrop | d43c52e | 2014-12-05 15:44:14 -0700 | [diff] [blame] | 2221 | " outColor = blue;\n" |
| 2222 | " outColor += red;\n" |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2223 | "}\n"; |
| 2224 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2225 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2226 | |
| 2227 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 2228 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 2229 | |
| 2230 | // We're going to create a number of uniform buffers, and then allow |
| 2231 | // the shader to select which it wants to read from with a binding |
| 2232 | |
| 2233 | // Let's populate the buffers with a single color each: |
| 2234 | // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal; |
| 2235 | // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal; |
| 2236 | // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal; |
| 2237 | // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal; |
| 2238 | |
| 2239 | const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 }; |
| 2240 | const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 }; |
| 2241 | const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 }; |
| 2242 | const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 2243 | |
| 2244 | const int redCount = sizeof(redVals) / sizeof(float); |
| 2245 | const int greenCount = sizeof(greenVals) / sizeof(float); |
| 2246 | const int blueCount = sizeof(blueVals) / sizeof(float); |
| 2247 | const int whiteCount = sizeof(whiteVals) / sizeof(float); |
| 2248 | |
| 2249 | XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals); |
| 2250 | ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer); |
| 2251 | |
| 2252 | XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals); |
| 2253 | ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer); |
| 2254 | |
| 2255 | XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals); |
| 2256 | ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer); |
| 2257 | |
| 2258 | XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2259 | ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2260 | |
| 2261 | XglPipelineObj pipelineobj(m_device); |
| 2262 | pipelineobj.AddShader(&vs); |
| 2263 | pipelineobj.AddShader(&ps); |
| 2264 | |
| 2265 | XglDescriptorSetObj descriptorSet(m_device); |
| 2266 | descriptorSet.AttachMemoryView(&redBuffer); |
| 2267 | descriptorSet.AttachMemoryView(&greenBuffer); |
| 2268 | descriptorSet.AttachMemoryView(&blueBuffer); |
| 2269 | descriptorSet.AttachMemoryView(&whiteBuffer); |
| 2270 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 2271 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2272 | QueueCommandBuffer(NULL, 0); |
| 2273 | |
| 2274 | } |
| 2275 | |
| 2276 | TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture) |
| 2277 | { |
| 2278 | static const char *vertShaderText = |
| 2279 | "#version 140\n" |
| 2280 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2281 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2282 | "layout (std140, binding=0) uniform bufferVals {\n" |
| 2283 | " mat4 mvp;\n" |
| 2284 | "} myBufferVals;\n" |
| 2285 | "layout (location=0) in vec4 pos;\n" |
| 2286 | "layout (location=0) out vec2 UV;\n" |
| 2287 | "void main() {\n" |
| 2288 | " vec2 positions[3];" |
| 2289 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 2290 | " positions[1] = vec2( 0.25, 0.1);\n" |
| 2291 | " positions[2] = vec2( 0.1, 0.25);\n" |
| 2292 | " UV = positions[gl_VertexID % 3];\n" |
| 2293 | " gl_Position = myBufferVals.mvp * pos;\n" |
| 2294 | "}\n"; |
| 2295 | |
| 2296 | static const char *fragShaderText = |
| 2297 | "#version 140\n" |
| 2298 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2299 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2300 | "layout (binding=0) uniform sampler2D surface;\n" |
| 2301 | "layout (location=0) out vec4 outColor;\n" |
| 2302 | "layout (location=0) in vec2 UV;\n" |
| 2303 | "void main() {\n" |
| 2304 | " outColor= textureLod(surface, UV, 0.0);\n" |
| 2305 | "}\n"; |
| 2306 | glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f); |
| 2307 | |
| 2308 | glm::mat4 View = glm::lookAt( |
| 2309 | glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space |
| 2310 | glm::vec3(0,0,0), // and looks at the origin |
| 2311 | glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down) |
| 2312 | ); |
| 2313 | |
| 2314 | glm::mat4 Model = glm::mat4(1.0f); |
| 2315 | |
| 2316 | glm::mat4 MVP = Projection * View * Model; |
| 2317 | |
| 2318 | |
| 2319 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2320 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2321 | ASSERT_NO_FATAL_FAILURE(InitDepthStencil()); |
| 2322 | |
| 2323 | XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]), |
| 2324 | sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data); |
Tony Barbour | 099a9eb | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 2325 | meshBuffer.SetMemoryState(XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2326 | |
| 2327 | |
| 2328 | const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT); |
| 2329 | |
| 2330 | XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]); |
| 2331 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 2332 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 2333 | XglSamplerObj sampler(m_device); |
| 2334 | XglTextureObj texture(m_device); |
| 2335 | |
| 2336 | // vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_VERTEX_INPUT, (XGL_OBJECT) &meshBuffer.m_constantBufferView); |
| 2337 | vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &mvpBuffer); |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2338 | ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2339 | ps.BindShaderEntitySlotToSampler(0, &sampler); |
| 2340 | |
| 2341 | XglPipelineObj pipelineobj(m_device); |
| 2342 | pipelineobj.AddShader(&vs); |
| 2343 | pipelineobj.AddShader(&ps); |
| 2344 | |
| 2345 | XglDescriptorSetObj descriptorSet(m_device); |
| 2346 | |
| 2347 | descriptorSet.AttachMemoryView(&mvpBuffer); |
| 2348 | descriptorSet.AttachImageView(&texture); |
| 2349 | descriptorSet.AttachSampler(&sampler); |
| 2350 | |
| 2351 | m_memoryRefManager.AddMemoryRef(&meshBuffer); |
| 2352 | m_memoryRefManager.AddMemoryRef(&mvpBuffer); |
| 2353 | m_memoryRefManager.AddMemoryRef(&texture); |
| 2354 | |
| 2355 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 2356 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 2357 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 2358 | }; |
| 2359 | |
| 2360 | // this is the current description of g_vbData |
| 2361 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 2362 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 2363 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 2364 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 2365 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 2366 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 2367 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 2368 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 2369 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 2370 | |
| 2371 | pipelineobj.AddVertexInputBindings(&vi_binding,1); |
| 2372 | pipelineobj.AddVertexInputAttribs(vi_attribs,2); |
| 2373 | pipelineobj.AddVertexDataBuffer(&meshBuffer,0); |
| 2374 | |
Tony Barbour | 2bd9616 | 2014-12-03 15:46:29 -0700 | [diff] [blame] | 2375 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 12); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 2376 | |
| 2377 | QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs()); |
| 2378 | |
| 2379 | } |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2380 | |
| 2381 | TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding) |
| 2382 | { |
| 2383 | // This test mixes binding slots of textures and buffers, ensuring |
| 2384 | // that sparse and overlapping assignments work. |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2385 | // The expected result from this test is a purple triangle, although |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2386 | // you can modify it to move the desired result around. |
| 2387 | |
| 2388 | static const char *vertShaderText = |
| 2389 | "#version 140\n" |
| 2390 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2391 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2392 | "void main() {\n" |
| 2393 | " vec2 vertices[3];" |
| 2394 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2395 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2396 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2397 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2398 | "}\n"; |
| 2399 | |
| 2400 | static const char *fragShaderText = |
| 2401 | "#version 430\n" |
| 2402 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2403 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2404 | "layout (binding = 0) uniform sampler2D surface0;\n" |
Courtney Goeltzenleuchter | c97ceea | 2014-12-11 09:03:03 -0700 | [diff] [blame] | 2405 | "layout (binding = 9) uniform sampler2D surface1;\n" |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2406 | "layout (binding = 2) uniform sampler2D surface2;\n" |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2407 | "layout (binding = 4) uniform sampler2D surface3;\n" |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2408 | |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2409 | |
| 2410 | "layout (std140, binding = 10) uniform redVal { vec4 red; };" |
| 2411 | "layout (std140, binding = 15) uniform greenVal { vec4 green; };" |
| 2412 | "layout (std140, binding = 13) uniform blueVal { vec4 blue; };" |
| 2413 | "layout (std140, binding = 17) uniform whiteVal { vec4 white; };" |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2414 | "layout (location = 0) out vec4 outColor;\n" |
| 2415 | "void main() {\n" |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2416 | " outColor = red * vec4(0.00001);\n" |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2417 | " outColor += white * vec4(0.00001);\n" |
| 2418 | " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n" |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2419 | " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n" |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2420 | "}\n"; |
| 2421 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2422 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2423 | |
| 2424 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 2425 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 2426 | |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2427 | const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 }; |
| 2428 | const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 }; |
| 2429 | const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 }; |
| 2430 | const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 2431 | |
| 2432 | const int redCount = sizeof(redVals) / sizeof(float); |
| 2433 | const int greenCount = sizeof(greenVals) / sizeof(float); |
| 2434 | const int blueCount = sizeof(blueVals) / sizeof(float); |
| 2435 | const int whiteCount = sizeof(whiteVals) / sizeof(float); |
| 2436 | |
| 2437 | XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals); |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2438 | ps.BindShaderEntitySlotToMemory(10, XGL_SLOT_SHADER_RESOURCE, &redBuffer); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2439 | |
| 2440 | XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals); |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2441 | ps.BindShaderEntitySlotToMemory(15, XGL_SLOT_SHADER_RESOURCE, &greenBuffer); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2442 | |
| 2443 | XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals); |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2444 | ps.BindShaderEntitySlotToMemory(13, XGL_SLOT_SHADER_RESOURCE, &blueBuffer); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2445 | |
| 2446 | XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals); |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2447 | ps.BindShaderEntitySlotToMemory(17, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2448 | |
| 2449 | XglSamplerObj sampler0(m_device); |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2450 | XglTextureObj texture0(m_device); // Light Red |
| 2451 | texture0.ChangeColors(0xff800000,0xff800000); |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2452 | ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2453 | ps.BindShaderEntitySlotToSampler(0, &sampler0); |
| 2454 | XglSamplerObj sampler2(m_device); |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2455 | XglTextureObj texture2(m_device); // Light Blue |
| 2456 | texture2.ChangeColors(0xff000080,0xff000080); |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2457 | ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2458 | ps.BindShaderEntitySlotToSampler(2, &sampler2); |
| 2459 | XglSamplerObj sampler4(m_device); |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2460 | XglTextureObj texture4(m_device); // Light Green |
| 2461 | texture4.ChangeColors(0xff008000,0xff008000); |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2462 | ps.BindShaderEntitySlotToImage(4, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2463 | ps.BindShaderEntitySlotToSampler(4, &sampler4); |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2464 | |
| 2465 | // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!! |
| 2466 | // TODO: Get back here ASAP and understand why. |
| 2467 | XglSamplerObj sampler7(m_device); |
| 2468 | XglTextureObj texture7(m_device); // Red and Blue |
| 2469 | texture7.ChangeColors(0xffff00ff,0xffff00ff); |
Courtney Goeltzenleuchter | c97ceea | 2014-12-11 09:03:03 -0700 | [diff] [blame] | 2470 | ps.BindShaderEntitySlotToImage(9, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7); |
| 2471 | ps.BindShaderEntitySlotToSampler(9, &sampler7); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2472 | |
| 2473 | |
| 2474 | XglPipelineObj pipelineobj(m_device); |
| 2475 | pipelineobj.AddShader(&vs); |
| 2476 | pipelineobj.AddShader(&ps); |
| 2477 | |
| 2478 | XglDescriptorSetObj descriptorSet(m_device); |
| 2479 | descriptorSet.AttachMemoryView(&redBuffer); |
| 2480 | descriptorSet.AttachMemoryView(&greenBuffer); |
| 2481 | descriptorSet.AttachMemoryView(&blueBuffer); |
| 2482 | descriptorSet.AttachMemoryView(&whiteBuffer); |
| 2483 | descriptorSet.AttachImageView(&texture0); |
| 2484 | descriptorSet.AttachSampler(&sampler0); |
| 2485 | descriptorSet.AttachImageView(&texture2); |
| 2486 | descriptorSet.AttachSampler(&sampler2); |
| 2487 | descriptorSet.AttachImageView(&texture4); |
| 2488 | descriptorSet.AttachSampler(&sampler4); |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2489 | descriptorSet.AttachImageView(&texture7); |
| 2490 | descriptorSet.AttachSampler(&sampler7); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2491 | |
| 2492 | m_memoryRefManager.AddMemoryRef(&texture0); |
| 2493 | m_memoryRefManager.AddMemoryRef(&texture2); |
| 2494 | m_memoryRefManager.AddMemoryRef(&texture4); |
Cody Northrop | b110b4f | 2014-12-09 13:59:39 -0700 | [diff] [blame] | 2495 | m_memoryRefManager.AddMemoryRef(&texture7); |
Cody Northrop | f1990a9 | 2014-12-09 11:17:01 -0700 | [diff] [blame] | 2496 | |
| 2497 | |
| 2498 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
| 2499 | QueueCommandBuffer(NULL, 0); |
| 2500 | |
| 2501 | } |
| 2502 | |
Cody Northrop | bd531de | 2014-12-09 19:08:54 -0700 | [diff] [blame] | 2503 | TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding) |
| 2504 | { |
| 2505 | // This test matches binding slots of textures and buffers, requiring |
| 2506 | // the driver to give them distinct number spaces. |
| 2507 | // The expected result from this test is a red triangle, although |
| 2508 | // you can modify it to move the desired result around. |
| 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 | "void main() {\n" |
| 2515 | " vec2 vertices[3];" |
| 2516 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2517 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2518 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2519 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2520 | "}\n"; |
| 2521 | |
| 2522 | static const char *fragShaderText = |
| 2523 | "#version 430\n" |
| 2524 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2525 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2526 | "layout (binding = 0) uniform sampler2D surface0;\n" |
| 2527 | "layout (binding = 1) uniform sampler2D surface1;\n" |
| 2528 | "layout (binding = 2) uniform sampler2D surface2;\n" |
| 2529 | "layout (binding = 3) uniform sampler2D surface3;\n" |
| 2530 | "layout (std140, binding = 0) uniform redVal { vec4 red; };" |
| 2531 | "layout (std140, binding = 1) uniform greenVal { vec4 green; };" |
| 2532 | "layout (std140, binding = 2) uniform blueVal { vec4 blue; };" |
| 2533 | "layout (std140, binding = 3) uniform whiteVal { vec4 white; };" |
| 2534 | "layout (location = 0) out vec4 outColor;\n" |
| 2535 | "void main() {\n" |
| 2536 | " outColor = red;// * vec4(0.00001);\n" |
| 2537 | " outColor += white * vec4(0.00001);\n" |
| 2538 | " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n" |
| 2539 | " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n" |
| 2540 | "}\n"; |
| 2541 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2542 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2543 | |
| 2544 | XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this); |
| 2545 | XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this); |
| 2546 | |
| 2547 | const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 }; |
| 2548 | const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 }; |
| 2549 | const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 }; |
| 2550 | const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 2551 | |
| 2552 | const int redCount = sizeof(redVals) / sizeof(float); |
| 2553 | const int greenCount = sizeof(greenVals) / sizeof(float); |
| 2554 | const int blueCount = sizeof(blueVals) / sizeof(float); |
| 2555 | const int whiteCount = sizeof(whiteVals) / sizeof(float); |
| 2556 | |
| 2557 | XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals); |
| 2558 | ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer); |
| 2559 | |
| 2560 | XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals); |
| 2561 | ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer); |
| 2562 | |
| 2563 | XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals); |
| 2564 | ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer); |
| 2565 | |
| 2566 | XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals); |
| 2567 | ps.BindShaderEntitySlotToMemory(3, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer); |
| 2568 | |
| 2569 | XglSamplerObj sampler0(m_device); |
| 2570 | XglTextureObj texture0(m_device); // Light Red |
| 2571 | texture0.ChangeColors(0xff800000,0xff800000); |
| 2572 | ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture0); |
| 2573 | ps.BindShaderEntitySlotToSampler(0, &sampler0); |
| 2574 | XglSamplerObj sampler2(m_device); |
| 2575 | XglTextureObj texture2(m_device); // Light Blue |
| 2576 | texture2.ChangeColors(0xff000080,0xff000080); |
| 2577 | ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture2); |
| 2578 | ps.BindShaderEntitySlotToSampler(1, &sampler2); |
| 2579 | XglSamplerObj sampler4(m_device); |
| 2580 | XglTextureObj texture4(m_device); // Light Green |
| 2581 | texture4.ChangeColors(0xff008000,0xff008000); |
| 2582 | ps.BindShaderEntitySlotToImage(2, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture4); |
| 2583 | ps.BindShaderEntitySlotToSampler(2, &sampler4); |
| 2584 | XglSamplerObj sampler7(m_device); |
| 2585 | XglTextureObj texture7(m_device); // Red and Blue |
| 2586 | texture7.ChangeColors(0xffff00ff,0xffff00ff); |
| 2587 | ps.BindShaderEntitySlotToImage(3, XGL_SLOT_SHADER_TEXTURE_RESOURCE, &texture7); |
| 2588 | ps.BindShaderEntitySlotToSampler(3, &sampler7); |
| 2589 | |
| 2590 | |
| 2591 | XglPipelineObj pipelineobj(m_device); |
| 2592 | pipelineobj.AddShader(&vs); |
| 2593 | pipelineobj.AddShader(&ps); |
| 2594 | |
| 2595 | XglDescriptorSetObj descriptorSet(m_device); |
| 2596 | descriptorSet.AttachMemoryView(&redBuffer); |
| 2597 | descriptorSet.AttachMemoryView(&greenBuffer); |
| 2598 | descriptorSet.AttachMemoryView(&blueBuffer); |
| 2599 | descriptorSet.AttachMemoryView(&whiteBuffer); |
| 2600 | descriptorSet.AttachImageView(&texture0); |
| 2601 | descriptorSet.AttachSampler(&sampler0); |
| 2602 | descriptorSet.AttachImageView(&texture2); |
| 2603 | descriptorSet.AttachSampler(&sampler2); |
| 2604 | descriptorSet.AttachImageView(&texture4); |
| 2605 | descriptorSet.AttachSampler(&sampler4); |
| 2606 | descriptorSet.AttachImageView(&texture7); |
| 2607 | descriptorSet.AttachSampler(&sampler7); |
| 2608 | |
| 2609 | m_memoryRefManager.AddMemoryRef(&texture0); |
| 2610 | m_memoryRefManager.AddMemoryRef(&texture2); |
| 2611 | m_memoryRefManager.AddMemoryRef(&texture4); |
| 2612 | m_memoryRefManager.AddMemoryRef(&texture7); |
| 2613 | |
| 2614 | |
| 2615 | GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1); |
| 2616 | QueueCommandBuffer(NULL, 0); |
| 2617 | |
| 2618 | } |
| 2619 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 2620 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | 54119a3 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 2621 | int result; |
| 2622 | |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 2623 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | 54119a3 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 2624 | XglTestFramework::InitArgs(&argc, argv); |
| 2625 | |
Chia-I Wu | 6f18429 | 2014-12-15 23:57:34 +0800 | [diff] [blame] | 2626 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 2627 | |
Courtney Goeltzenleuchter | 54119a3 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 2628 | result = RUN_ALL_TESTS(); |
| 2629 | |
| 2630 | XglTestFramework::Finish(); |
| 2631 | return result; |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 2632 | } |