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