Courtney Goeltzenleuchter | b85c581 | 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 | b85c581 | 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 | 76a643b | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 59 | #include <iostream> |
| 60 | #include <fstream> |
| 61 | using namespace std; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 62 | |
| 63 | #include <xgl.h> |
| 64 | #include "gtest-1.7.0/include/gtest/gtest.h" |
| 65 | |
| 66 | #include "xgldevice.h" |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 67 | #include "xglimage.h" |
Chia-I Wu | 4115c89 | 2014-08-28 11:56:29 +0800 | [diff] [blame] | 68 | #include "icd-bil.h" |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 69 | |
Courtney Goeltzenleuchter | 34b8177 | 2014-10-10 18:04:39 -0600 | [diff] [blame] | 70 | #define GLM_FORCE_RADIANS |
| 71 | #include "glm/glm.hpp" |
| 72 | #include <glm/gtc/matrix_transform.hpp> |
| 73 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 74 | #include "xglrenderframework.h" |
Courtney Goeltzenleuchter | 2268d1e | 2014-09-01 13:57:15 -0600 | [diff] [blame] | 75 | |
Courtney Goeltzenleuchter | bb7014d | 2014-10-09 11:05:19 -0600 | [diff] [blame] | 76 | #undef ASSERT_NO_FATAL_FAILURE |
| 77 | #define ASSERT_NO_FATAL_FAILURE(x) x |
| 78 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 79 | //-------------------------------------------------------------------------------------- |
| 80 | // Mesh and VertexFormat Data |
| 81 | //-------------------------------------------------------------------------------------- |
| 82 | struct Vertex |
| 83 | { |
| 84 | XGL_FLOAT posX, posY, posZ, posW; // Position data |
| 85 | XGL_FLOAT r, g, b, a; // Color |
| 86 | }; |
| 87 | |
| 88 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
| 89 | |
| 90 | static const Vertex g_vbData[] = |
| 91 | { |
| 92 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 93 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 94 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 95 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 96 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 97 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 98 | |
| 99 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 100 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 101 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 102 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 103 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 104 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 105 | |
| 106 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 107 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 108 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 109 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 110 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 111 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 112 | |
| 113 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 114 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 115 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 116 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 117 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 118 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 119 | |
| 120 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 121 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 122 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 123 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 124 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 125 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 126 | |
| 127 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 128 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 129 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 130 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 131 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 132 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 133 | }; |
| 134 | |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 135 | static const Vertex g_vb_solid_face_colors_Data[] = |
| 136 | { |
| 137 | { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 138 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 139 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 140 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 141 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 142 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 143 | |
| 144 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 145 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 146 | { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 147 | { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 148 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 149 | { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 150 | |
| 151 | { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 152 | { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 153 | { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 154 | { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 155 | { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 156 | { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 157 | |
| 158 | { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 159 | { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 160 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 161 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 162 | { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 163 | { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 164 | |
| 165 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 166 | { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 167 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 168 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 169 | { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 170 | { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 171 | |
| 172 | { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 173 | { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 174 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 175 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 176 | { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 177 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 178 | }; |
| 179 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 180 | class XglRenderTest : public XglRenderFramework |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 181 | { |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 182 | public: |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 183 | void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices ); |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 184 | void UploadMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices ); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 185 | void InitTexture(); |
| 186 | void InitSampler(); |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 187 | void DrawTriangleTest(const char *vertShaderText, const char *fragShaderText); |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 188 | void DrawTriangleTwoUniformsFS(const char *vertShaderText, const char *fragShaderText); |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 189 | void DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText); |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 190 | void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model); |
| 191 | void DrawTriangleVSUniform(const char *vertShaderText, const char *fragShaderText, int numTris); |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 192 | void DrawTriangleWithVertexFetchAndMVP(const char *vertShaderText, const char *fragShaderText); |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 193 | |
| 194 | void CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 195 | void CreatePipelineWithVertexFetchAndMVP(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 196 | void CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 197 | void ClearDepthStencil(XGL_FLOAT value); |
| 198 | void ClearRenderBuffer(XGL_UINT32 clear_color); |
| 199 | void InitDepthStencil(); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 200 | void DrawRotatedTriangleTest(); |
Courtney Goeltzenleuchter | d04e38c | 2014-10-22 18:02:30 -0600 | [diff] [blame] | 201 | void GenerateClearAndPrepareBufferCmds(); |
Courtney Goeltzenleuchter | 6acb802 | 2014-10-27 13:08:55 -0600 | [diff] [blame^] | 202 | void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 203 | |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 204 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 205 | protected: |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 206 | XGL_IMAGE m_texture; |
| 207 | XGL_IMAGE_VIEW m_textureView; |
| 208 | XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo; |
| 209 | XGL_GPU_MEMORY m_textureMem; |
| 210 | |
| 211 | XGL_SAMPLER m_sampler; |
| 212 | |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 213 | XGL_FORMAT m_depth_stencil_fmt; |
| 214 | XGL_IMAGE m_depthStencilImage; |
| 215 | XGL_GPU_MEMORY m_depthStencilMem; |
| 216 | XGL_DEPTH_STENCIL_VIEW m_depthStencilView; |
| 217 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 218 | // XGL_APPLICATION_INFO app_info; |
| 219 | // XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 220 | // XGL_UINT gpu_count; |
| 221 | // XGL_GPU_MEMORY m_descriptor_set_mem; |
| 222 | // XGL_GPU_MEMORY m_pipe_mem; |
| 223 | // XglDevice *m_device; |
| 224 | // XGL_CMD_BUFFER m_cmdBuffer; |
| 225 | // XGL_UINT32 m_numVertices; |
| 226 | // XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView; |
| 227 | // XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView; |
| 228 | // XGL_GPU_MEMORY m_vtxBufferMem; |
| 229 | // XGL_GPU_MEMORY m_constantBufferMem; |
| 230 | // XGL_UINT32 m_numMemRefs; |
| 231 | // XGL_MEMORY_REF m_memRefs[5]; |
| 232 | // XGL_RASTER_STATE_OBJECT m_stateRaster; |
| 233 | // XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend; |
| 234 | // XGL_VIEWPORT_STATE_OBJECT m_stateViewport; |
| 235 | // XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil; |
| 236 | // XGL_MSAA_STATE_OBJECT m_stateMsaa; |
| 237 | // XGL_DESCRIPTOR_SET m_rsrcDescSet; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 238 | |
| 239 | virtual void SetUp() { |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 240 | |
| 241 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 242 | this->app_info.pNext = NULL; |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 243 | this->app_info.pAppName = (const XGL_CHAR *) "render_tests"; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 244 | this->app_info.appVersion = 1; |
| 245 | this->app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 246 | this->app_info.engineVersion = 1; |
| 247 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 248 | |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 249 | memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo)); |
| 250 | m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
| 251 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 252 | InitFramework(); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | virtual void TearDown() { |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 256 | // Clean up resources before we reset |
| 257 | ShutdownFramework(); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 258 | } |
| 259 | }; |
| 260 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 261 | // this function will create the vertex buffer and fill it with the mesh data |
| 262 | void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, |
| 263 | const void* vertices ) |
| 264 | { |
| 265 | XGL_RESULT err = XGL_SUCCESS; |
| 266 | |
| 267 | assert( numVertices * vbStride > 0 ); |
| 268 | m_numVertices = numVertices; |
| 269 | |
| 270 | XGL_MEMORY_ALLOC_INFO alloc_info = {}; |
| 271 | XGL_UINT8 *pData; |
| 272 | |
| 273 | alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 274 | alloc_info.allocationSize = numVertices * vbStride; |
| 275 | alloc_info.alignment = 0; |
| 276 | alloc_info.heapCount = 1; |
| 277 | alloc_info.heaps[0] = 0; // TODO: Use known existing heap |
| 278 | |
| 279 | alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT; |
| 280 | alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 281 | |
| 282 | err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem); |
| 283 | ASSERT_XGL_SUCCESS(err); |
| 284 | |
| 285 | err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData); |
| 286 | ASSERT_XGL_SUCCESS(err); |
| 287 | |
| 288 | memcpy(pData, vertices, alloc_info.allocationSize); |
| 289 | |
| 290 | err = xglUnmapMemory(m_vtxBufferMem); |
| 291 | ASSERT_XGL_SUCCESS(err); |
| 292 | |
| 293 | // set up the memory view for the vertex buffer |
| 294 | this->m_vtxBufferView.stride = vbStride; |
| 295 | this->m_vtxBufferView.range = numVertices * vbStride; |
| 296 | this->m_vtxBufferView.offset = 0; |
| 297 | this->m_vtxBufferView.mem = m_vtxBufferMem; |
| 298 | this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 299 | this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED; |
| 300 | |
| 301 | // open the command buffer |
| 302 | err = xglBeginCommandBuffer( m_cmdBuffer, 0 ); |
| 303 | ASSERT_XGL_SUCCESS(err); |
| 304 | |
| 305 | XGL_MEMORY_STATE_TRANSITION transition = {}; |
| 306 | transition.mem = m_vtxBufferMem; |
| 307 | transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER; |
| 308 | transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 309 | transition.offset = 0; |
| 310 | transition.regionSize = numVertices * vbStride; |
| 311 | |
| 312 | // write transition to the command buffer |
| 313 | xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition ); |
| 314 | this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 315 | |
| 316 | // finish recording the command buffer |
| 317 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 318 | ASSERT_XGL_SUCCESS(err); |
| 319 | |
| 320 | // this command buffer only uses the vertex buffer memory |
| 321 | m_numMemRefs = 1; |
| 322 | m_memRefs[0].flags = 0; |
| 323 | m_memRefs[0].mem = m_vtxBufferMem; |
| 324 | |
| 325 | // submit the command buffer to the universal queue |
| 326 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 327 | ASSERT_XGL_SUCCESS(err); |
| 328 | } |
| 329 | |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 330 | // this function will create the vertex buffer and fill it with the mesh data |
| 331 | void XglRenderTest::UploadMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, |
| 332 | const void* vertices ) |
| 333 | { |
| 334 | XGL_UINT8 *pData; |
| 335 | XGL_RESULT err = XGL_SUCCESS; |
| 336 | |
| 337 | assert( numVertices * vbStride > 0 ); |
| 338 | m_numVertices = numVertices; |
| 339 | |
| 340 | err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData); |
| 341 | ASSERT_XGL_SUCCESS(err); |
| 342 | |
| 343 | memcpy(pData, vertices, numVertices * vbStride); |
| 344 | |
| 345 | err = xglUnmapMemory(m_vtxBufferMem); |
| 346 | ASSERT_XGL_SUCCESS(err); |
| 347 | } |
| 348 | |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 349 | void XglRenderTest::InitTexture() |
| 350 | { |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 351 | #define DEMO_TEXTURE_COUNT 1 |
| 352 | |
| 353 | const XGL_FORMAT tex_format = { XGL_CH_FMT_B8G8R8A8, XGL_NUM_FMT_UNORM }; |
| 354 | const XGL_INT tex_width = 16; |
| 355 | const XGL_INT tex_height = 16; |
| 356 | const uint32_t tex_colors[DEMO_TEXTURE_COUNT][2] = { |
| 357 | { 0xffff0000, 0xff00ff00 }, |
| 358 | }; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 359 | XGL_RESULT err; |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 360 | XGL_UINT i; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 361 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 362 | for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { |
| 363 | const XGL_SAMPLER_CREATE_INFO sampler = { |
| 364 | .sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, |
| 365 | .pNext = NULL, |
| 366 | .magFilter = XGL_TEX_FILTER_NEAREST, |
| 367 | .minFilter = XGL_TEX_FILTER_NEAREST, |
| 368 | .mipMode = XGL_TEX_MIPMAP_BASE, |
| 369 | .addressU = XGL_TEX_ADDRESS_WRAP, |
| 370 | .addressV = XGL_TEX_ADDRESS_WRAP, |
| 371 | .addressW = XGL_TEX_ADDRESS_WRAP, |
| 372 | .mipLodBias = 0.0f, |
| 373 | .maxAnisotropy = 0, |
| 374 | .compareFunc = XGL_COMPARE_NEVER, |
| 375 | .minLod = 0.0f, |
| 376 | .maxLod = 0.0f, |
| 377 | .borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE, |
| 378 | }; |
| 379 | const XGL_IMAGE_CREATE_INFO image = { |
| 380 | .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 381 | .pNext = NULL, |
| 382 | .imageType = XGL_IMAGE_2D, |
| 383 | .format = tex_format, |
| 384 | .extent = { tex_width, tex_height, 1 }, |
| 385 | .mipLevels = 1, |
| 386 | .arraySize = 1, |
| 387 | .samples = 1, |
| 388 | .tiling = XGL_LINEAR_TILING, |
| 389 | .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT, |
| 390 | .flags = 0, |
| 391 | }; |
| 392 | XGL_MEMORY_ALLOC_INFO mem_alloc; |
| 393 | mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 394 | mem_alloc.pNext = NULL; |
| 395 | mem_alloc.allocationSize = 0; |
| 396 | mem_alloc.alignment = 0; |
| 397 | mem_alloc.flags = 0; |
| 398 | mem_alloc.heapCount = 0; |
| 399 | mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 400 | XGL_IMAGE_VIEW_CREATE_INFO view; |
| 401 | view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 402 | view.pNext = NULL; |
| 403 | view.image = XGL_NULL_HANDLE; |
| 404 | view.viewType = XGL_IMAGE_VIEW_2D; |
| 405 | view.format = image.format; |
| 406 | view.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 407 | view.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 408 | view.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 409 | view.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 410 | view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 411 | view.subresourceRange.baseMipLevel = 0; |
| 412 | view.subresourceRange.mipLevels = 1; |
| 413 | view.subresourceRange.baseArraySlice = 0; |
| 414 | view.subresourceRange.arraySize = 1; |
| 415 | view.minLod = 0.0f; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 416 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 417 | XGL_MEMORY_REQUIREMENTS mem_reqs; |
| 418 | XGL_SIZE mem_reqs_size; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 419 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 420 | /* create sampler */ |
| 421 | err = xglCreateSampler(device(), &sampler, &m_sampler); |
| 422 | assert(!err); |
| 423 | |
| 424 | /* create image */ |
| 425 | err = xglCreateImage(device(), &image, &m_texture); |
| 426 | assert(!err); |
| 427 | |
| 428 | err = xglGetObjectInfo(m_texture, |
| 429 | XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 430 | &mem_reqs_size, &mem_reqs); |
| 431 | assert(!err && mem_reqs_size == sizeof(mem_reqs)); |
| 432 | |
| 433 | mem_alloc.allocationSize = mem_reqs.size; |
| 434 | mem_alloc.alignment = mem_reqs.alignment; |
| 435 | mem_alloc.heapCount = mem_reqs.heapCount; |
| 436 | memcpy(mem_alloc.heaps, mem_reqs.heaps, |
| 437 | sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount); |
| 438 | |
| 439 | /* allocate memory */ |
| 440 | err = xglAllocMemory(device(), &mem_alloc, &m_textureMem); |
| 441 | assert(!err); |
| 442 | |
| 443 | /* bind memory */ |
| 444 | err = xglBindObjectMemory(m_texture, m_textureMem, 0); |
| 445 | assert(!err); |
| 446 | |
| 447 | /* create image view */ |
| 448 | view.image = m_texture; |
| 449 | err = xglCreateImageView(device(), &view, &m_textureView); |
| 450 | assert(!err); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 451 | } |
| 452 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 453 | for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { |
| 454 | const XGL_IMAGE_SUBRESOURCE subres = { |
| 455 | .aspect = XGL_IMAGE_ASPECT_COLOR, |
| 456 | .mipLevel = 0, |
| 457 | .arraySlice = 0, |
| 458 | }; |
| 459 | XGL_SUBRESOURCE_LAYOUT layout; |
| 460 | XGL_SIZE layout_size; |
| 461 | XGL_VOID *data; |
| 462 | XGL_INT x, y; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 463 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 464 | err = xglGetImageSubresourceInfo(m_texture, &subres, |
| 465 | XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &layout_size, &layout); |
| 466 | assert(!err && layout_size == sizeof(layout)); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 467 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 468 | err = xglMapMemory(m_textureMem, 0, &data); |
| 469 | assert(!err); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 470 | |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 471 | for (y = 0; y < tex_height; y++) { |
| 472 | uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y); |
| 473 | for (x = 0; x < tex_width; x++) |
| 474 | row[x] = tex_colors[i][(x & 1) ^ (y & 1)]; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 475 | } |
Cody Northrop | 904742c | 2014-10-07 16:25:00 -0600 | [diff] [blame] | 476 | |
| 477 | err = xglUnmapMemory(m_textureMem); |
| 478 | assert(!err); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 479 | } |
| 480 | |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame] | 481 | m_textureViewInfo.view = m_textureView; |
| 482 | } |
| 483 | |
| 484 | void XglRenderTest::InitSampler() |
| 485 | { |
| 486 | XGL_RESULT err; |
| 487 | |
| 488 | XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {}; |
| 489 | samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 490 | samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST; |
| 491 | samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST; |
| 492 | samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE; |
| 493 | samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP; |
| 494 | samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP; |
| 495 | samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP; |
| 496 | samplerCreateInfo.mipLodBias = 0.0; |
| 497 | samplerCreateInfo.maxAnisotropy = 0.0; |
| 498 | samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER; |
| 499 | samplerCreateInfo.minLod = 0.0; |
| 500 | samplerCreateInfo.maxLod = 0.0; |
| 501 | samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE; |
| 502 | |
| 503 | err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler); |
| 504 | ASSERT_XGL_SUCCESS(err); |
| 505 | } |
| 506 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 507 | void XglRenderTest::DrawRotatedTriangleTest() |
| 508 | { |
| 509 | // TODO : This test will pass a matrix into VS to affect triangle orientation. |
| 510 | } |
| 511 | |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 512 | void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText) |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 513 | { |
| 514 | XGL_PIPELINE pipeline; |
| 515 | XGL_SHADER vs, ps; |
| 516 | XGL_RESULT err; |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 517 | |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 518 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 519 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 520 | |
| 521 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 522 | vertShaderText, &vs)); |
| 523 | |
| 524 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 525 | fragShaderText, &ps)); |
| 526 | |
| 527 | ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps)); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 528 | |
| 529 | /* |
| 530 | * Shaders are now part of the pipeline, don't need these anymore |
| 531 | */ |
| 532 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 533 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 534 | |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 535 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 536 | |
Cody Northrop | 342912c | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 537 | const int constantCount = 4; |
| 538 | const float constants[constantCount] = { 0.5, 0.5, 0.5, 1.0 }; |
| 539 | InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants); |
| 540 | |
| 541 | // Create descriptor set for a uniform resource |
| 542 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 543 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 544 | descriptorInfo.slots = 1; |
| 545 | |
| 546 | // create a descriptor set with a single slot |
| 547 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 548 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 549 | |
| 550 | // bind memory to the descriptor set |
| 551 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 552 | |
| 553 | // write the constant buffer view to the descriptor set |
| 554 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 555 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 556 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 557 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 558 | // Build command buffer |
| 559 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 560 | ASSERT_XGL_SUCCESS(err); |
| 561 | |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 562 | GenerateClearAndPrepareBufferCmds(); |
| 563 | GenerateBindRenderTargetCmd(); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 564 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 565 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 566 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 567 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 568 | |
| 569 | // render the cube |
| 570 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 571 | |
| 572 | // prepare the back buffer for present |
| 573 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 574 | // transitionToPresent.image = m_image; |
| 575 | // transitionToPresent.oldState = m_image_state; |
| 576 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 577 | // transitionToPresent.subresourceRange = srRange; |
| 578 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 579 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 580 | |
| 581 | // finalize recording of the command buffer |
| 582 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 583 | ASSERT_XGL_SUCCESS( err ); |
| 584 | |
| 585 | // this command buffer only uses the vertex buffer memory |
| 586 | m_numMemRefs = 0; |
| 587 | // m_memRefs[0].flags = 0; |
| 588 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 589 | |
| 590 | // submit the command buffer to the universal queue |
| 591 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 592 | ASSERT_XGL_SUCCESS( err ); |
| 593 | |
Chia-I Wu | f34ac50 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 594 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 595 | ASSERT_XGL_SUCCESS( err ); |
| 596 | |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 597 | // Wait for work to finish before cleaning up. |
| 598 | xglDeviceWaitIdle(m_device->device()); |
| 599 | |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 600 | RecordImage(m_renderTarget); |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 601 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 602 | } |
| 603 | |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 604 | void XglRenderTest::DrawTriangleTwoUniformsFS(const char *vertShaderText, const char *fragShaderText) |
Courtney Goeltzenleuchter | 98e4943 | 2014-10-09 15:40:19 -0600 | [diff] [blame] | 605 | { |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 606 | XGL_PIPELINE pipeline; |
| 607 | XGL_SHADER vs, ps; |
| 608 | XGL_RESULT err; |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 609 | |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 610 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 611 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 612 | |
| 613 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 614 | vertShaderText, &vs)); |
| 615 | |
| 616 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 617 | fragShaderText, &ps)); |
| 618 | |
| 619 | ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps)); |
| 620 | |
| 621 | /* |
| 622 | * Shaders are now part of the pipeline, don't need these anymore |
| 623 | */ |
| 624 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 625 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 626 | |
| 627 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 628 | |
| 629 | const int constantCount = 8; |
| 630 | const float constants[constantCount] = { 1.0, 0.0, 0.0, 1.0, |
| 631 | 0.0, 0.0, 1.0, 1.0 }; |
| 632 | |
| 633 | InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants); |
| 634 | |
| 635 | // Create descriptor set for a uniform resource |
| 636 | const int slotCount = 1; |
| 637 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 638 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 639 | descriptorInfo.slots = slotCount; |
| 640 | |
| 641 | // create a descriptor set with a single slot |
| 642 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 643 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 644 | |
| 645 | // bind memory to the descriptor set |
| 646 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 647 | |
| 648 | // write the constant buffer view to the descriptor set |
| 649 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 650 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 651 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 652 | |
| 653 | // Build command buffer |
| 654 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 655 | ASSERT_XGL_SUCCESS(err); |
| 656 | |
| 657 | GenerateClearAndPrepareBufferCmds(); |
| 658 | GenerateBindRenderTargetCmd(); |
| 659 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 660 | |
| 661 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 662 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 663 | |
| 664 | // render the cube |
| 665 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 666 | |
| 667 | // prepare the back buffer for present |
| 668 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 669 | // transitionToPresent.image = m_image; |
| 670 | // transitionToPresent.oldState = m_image_state; |
| 671 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 672 | // transitionToPresent.subresourceRange = srRange; |
| 673 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 674 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 675 | |
| 676 | // finalize recording of the command buffer |
| 677 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 678 | ASSERT_XGL_SUCCESS( err ); |
| 679 | |
| 680 | // this command buffer only uses the vertex buffer memory |
| 681 | m_numMemRefs = 0; |
| 682 | // m_memRefs[0].flags = 0; |
| 683 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 684 | |
| 685 | // submit the command buffer to the universal queue |
| 686 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 687 | ASSERT_XGL_SUCCESS( err ); |
| 688 | |
| 689 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 690 | ASSERT_XGL_SUCCESS( err ); |
| 691 | |
| 692 | // Wait for work to finish before cleaning up. |
| 693 | xglDeviceWaitIdle(m_device->device()); |
| 694 | |
| 695 | RecordImage(m_renderTarget); |
| 696 | |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 697 | } |
| 698 | |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 699 | |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 700 | void XglRenderTest::DrawTriangleVSUniform(const char *vertShaderText, const char *fragShaderText, int numTris) |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 701 | { |
| 702 | XGL_PIPELINE pipeline; |
| 703 | XGL_SHADER vs, ps; |
| 704 | XGL_RESULT err; |
| 705 | |
| 706 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 707 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 708 | |
| 709 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 710 | vertShaderText, &vs)); |
| 711 | |
| 712 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 713 | fragShaderText, &ps)); |
| 714 | |
| 715 | ASSERT_NO_FATAL_FAILURE(CreatePipelineVSUniform(&pipeline, vs, ps)); |
| 716 | |
| 717 | /* |
| 718 | * Shaders are now part of the pipeline, don't need these anymore |
| 719 | */ |
| 720 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 721 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 722 | |
| 723 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 724 | |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 725 | // Create descriptor set for a uniform resource |
| 726 | const int slotCount = 1; |
| 727 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 728 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 729 | descriptorInfo.slots = slotCount; |
| 730 | |
| 731 | // create a descriptor set with a single slot |
| 732 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 733 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 734 | |
| 735 | // bind memory to the descriptor set |
| 736 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 737 | |
| 738 | // write the constant buffer view to the descriptor set |
| 739 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 740 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 741 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 742 | |
| 743 | // Build command buffer |
| 744 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 745 | ASSERT_XGL_SUCCESS(err); |
| 746 | |
| 747 | GenerateClearAndPrepareBufferCmds(); |
| 748 | GenerateBindRenderTargetCmd(); |
| 749 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 750 | |
| 751 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 752 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 753 | |
| 754 | // render the cube |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 755 | xglCmdDraw( m_cmdBuffer, 0, numTris*3, 0, 1 ); |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 756 | |
| 757 | // prepare the back buffer for present |
| 758 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 759 | // transitionToPresent.image = m_image; |
| 760 | // transitionToPresent.oldState = m_image_state; |
| 761 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 762 | // transitionToPresent.subresourceRange = srRange; |
| 763 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 764 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 765 | |
| 766 | // finalize recording of the command buffer |
| 767 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 768 | ASSERT_XGL_SUCCESS( err ); |
| 769 | |
Courtney Goeltzenleuchter | c3f4ac8 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 770 | // this command buffer only uses a data buffer for the MVP |
| 771 | m_numMemRefs = 1; |
| 772 | m_memRefs[0].flags = 0; |
| 773 | m_memRefs[0].mem = m_constantBufferMem; |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 774 | |
| 775 | // submit the command buffer to the universal queue |
| 776 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 777 | ASSERT_XGL_SUCCESS( err ); |
| 778 | |
| 779 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 780 | ASSERT_XGL_SUCCESS( err ); |
| 781 | |
| 782 | // Wait for work to finish before cleaning up. |
| 783 | xglDeviceWaitIdle(m_device->device()); |
| 784 | |
| 785 | RecordImage(m_renderTarget); |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | |
| 789 | void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model) |
| 790 | { |
| 791 | int i; |
| 792 | glm::mat4 MVP; |
| 793 | int matrixSize = sizeof(MVP); |
| 794 | XGL_RESULT err; |
Courtney Goeltzenleuchter | 3c601d8 | 2014-10-13 13:03:31 -0600 | [diff] [blame] | 795 | |
| 796 | for (i = 0; i < 8; i++) { |
| 797 | XGL_UINT8 *pData; |
| 798 | err = xglMapMemory(m_constantBufferMem, 0, (XGL_VOID **) &pData); |
| 799 | ASSERT_XGL_SUCCESS(err); |
| 800 | |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 801 | Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f)); |
| 802 | MVP = Projection * View * Model; |
Courtney Goeltzenleuchter | 3c601d8 | 2014-10-13 13:03:31 -0600 | [diff] [blame] | 803 | memcpy(pData, (const void*) &MVP[0][0], matrixSize); |
| 804 | |
| 805 | err = xglUnmapMemory(m_constantBufferMem); |
| 806 | ASSERT_XGL_SUCCESS(err); |
| 807 | |
| 808 | // submit the command buffer to the universal queue |
| 809 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 810 | ASSERT_XGL_SUCCESS( err ); |
| 811 | |
| 812 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 813 | ASSERT_XGL_SUCCESS( err ); |
| 814 | |
| 815 | // Wait for work to finish before cleaning up. |
| 816 | xglDeviceWaitIdle(m_device->device()); |
| 817 | |
| 818 | RecordImage(m_renderTarget); |
| 819 | } |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 820 | } |
| 821 | |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 822 | void dumpMatrix(const char *note, glm::mat4 MVP) |
| 823 | { |
| 824 | int i,j; |
| 825 | |
| 826 | printf("%s: \n", note); |
| 827 | for (i=0; i<4; i++) { |
| 828 | printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]); |
| 829 | } |
| 830 | printf("\n"); |
| 831 | fflush(stdout); |
| 832 | } |
| 833 | |
| 834 | void dumpVec4(const char *note, glm::vec4 vector) |
| 835 | { |
| 836 | printf("%s: \n", note); |
| 837 | printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]); |
| 838 | printf("\n"); |
| 839 | fflush(stdout); |
| 840 | } |
| 841 | |
Courtney Goeltzenleuchter | d04e38c | 2014-10-22 18:02:30 -0600 | [diff] [blame] | 842 | void XglRenderTest::GenerateClearAndPrepareBufferCmds() |
| 843 | { |
| 844 | XglRenderFramework::GenerateClearAndPrepareBufferCmds(); |
| 845 | |
| 846 | if (0) { |
| 847 | // if (m_depthStencilImage) { |
| 848 | XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {}; |
| 849 | dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH; |
| 850 | dsRange.baseMipLevel = 0; |
| 851 | dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 852 | dsRange.baseArraySlice = 0; |
| 853 | dsRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 854 | |
| 855 | // prepare the depth buffer for clear |
| 856 | XGL_IMAGE_STATE_TRANSITION transitionToClear = {}; |
| 857 | transitionToClear.image = m_depthStencilImage; |
| 858 | transitionToClear.oldState = m_depthStencilBinding.depthState; |
| 859 | transitionToClear.newState = XGL_IMAGE_STATE_CLEAR; |
| 860 | transitionToClear.subresourceRange = dsRange; |
| 861 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear ); |
| 862 | m_renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
| 863 | |
| 864 | xglCmdClearDepthStencil(m_cmdBuffer, m_depthStencilImage, 1.0f, 0, 1, &dsRange); |
| 865 | |
| 866 | // prepare depth buffer for rendering |
| 867 | XGL_IMAGE_STATE_TRANSITION transitionToRender = {}; |
| 868 | transitionToRender.image = m_renderTarget->image(); |
| 869 | transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR; |
| 870 | transitionToRender.newState = m_depthStencilBinding.depthState; |
| 871 | transitionToRender.subresourceRange = dsRange; |
| 872 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender ); |
| 873 | m_renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
| 874 | } |
| 875 | } |
| 876 | |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 877 | void XglRenderTest::DrawTriangleWithVertexFetchAndMVP(const char *vertShaderText, const char *fragShaderText) |
| 878 | { |
| 879 | XGL_PIPELINE pipeline; |
| 880 | XGL_SHADER vs, ps; |
| 881 | XGL_RESULT err; |
| 882 | int i, loop; |
| 883 | |
| 884 | // Projection matrix : 45° Field of View, 1:1 ratio, display range : 0.1 unit <-> 100 units |
| 885 | glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f); |
| 886 | // dumpMatrix("Projection", Projection); |
| 887 | |
| 888 | // Camera matrix |
| 889 | glm::mat4 View = glm::lookAt( |
| 890 | glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space |
| 891 | glm::vec3(0,0,0), // and looks at the origin |
| 892 | glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down) |
| 893 | ); |
| 894 | // dumpMatrix("View", View); |
| 895 | |
| 896 | // Model matrix : an identity matrix (model will be at the origin) |
| 897 | glm::mat4 Model = glm::mat4(1.0f); |
| 898 | // dumpMatrix("Model", Model); |
| 899 | |
| 900 | // Our ModelViewProjection : multiplication of our 3 matrices |
| 901 | // Model = glm::translate(Model, glm::vec3(0.0f, 0.0f, 4.0f)); |
| 902 | // Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f)); |
| 903 | glm::mat4 MVP = Projection * View * Model; |
| 904 | |
| 905 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 906 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 907 | ASSERT_NO_FATAL_FAILURE(InitDepthStencil()); |
| 908 | ASSERT_NO_FATAL_FAILURE(InitMesh(sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]), |
| 909 | sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data)); |
| 910 | |
| 911 | const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT); |
| 912 | |
| 913 | InitConstantBuffer(buf_size, sizeof(MVP[0][0]), (const void*) &MVP[0][0]); |
| 914 | |
| 915 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 916 | vertShaderText, &vs)); |
| 917 | |
| 918 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 919 | fragShaderText, &ps)); |
| 920 | |
| 921 | ASSERT_NO_FATAL_FAILURE(CreatePipelineWithVertexFetchAndMVP(&pipeline, vs, ps)); |
| 922 | |
| 923 | /* |
| 924 | * Shaders are now part of the pipeline, don't need these anymore |
| 925 | */ |
| 926 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 927 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 928 | |
| 929 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 930 | |
| 931 | // Build command buffer |
| 932 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 933 | ASSERT_XGL_SUCCESS(err); |
| 934 | |
| 935 | GenerateClearAndPrepareBufferCmds(); |
| 936 | ClearDepthStencil(1.0f); // HACK for now |
| 937 | GenerateBindRenderTargetCmd(); |
| 938 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 939 | |
| 940 | // render the cube |
| 941 | xglCmdDraw( m_cmdBuffer, 0, 12*3, 0, 1 ); |
| 942 | |
| 943 | // prepare the back buffer for present |
| 944 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 945 | // transitionToPresent.image = m_image; |
| 946 | // transitionToPresent.oldState = m_image_state; |
| 947 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 948 | // transitionToPresent.subresourceRange = srRange; |
| 949 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 950 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 951 | |
| 952 | // finalize recording of the command buffer |
| 953 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 954 | ASSERT_XGL_SUCCESS( err ); |
| 955 | |
Courtney Goeltzenleuchter | c3f4ac8 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 956 | // this command buffer uses the vertex buffer memory and a data buffer (for MVP) |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 957 | m_numMemRefs = 2; |
| 958 | m_memRefs[0].flags = 0; |
| 959 | m_memRefs[0].mem = m_vtxBufferMem; |
| 960 | m_memRefs[1].flags = 0; |
| 961 | m_memRefs[1].mem = m_constantBufferMem; |
| 962 | |
| 963 | // submit the command buffer to the universal queue |
| 964 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 965 | ASSERT_XGL_SUCCESS( err ); |
| 966 | |
| 967 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 968 | ASSERT_XGL_SUCCESS( err ); |
| 969 | |
| 970 | // Wait for work to finish before cleaning up. |
| 971 | xglDeviceWaitIdle(m_device->device()); |
| 972 | |
| 973 | RecordImage(m_renderTarget); |
| 974 | |
| 975 | for (loop = 0; loop < 16; loop++) { |
Courtney Goeltzenleuchter | d04e38c | 2014-10-22 18:02:30 -0600 | [diff] [blame] | 976 | // ClearRenderBuffer(0x80); // HACK |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 977 | ClearDepthStencil(1.0f); // HACK for now |
| 978 | |
| 979 | // TODO: Do we need to transition the constant buffer? |
| 980 | XGL_UINT8 *pData; |
| 981 | err = xglMapMemory(m_constantBufferMem, 0, (XGL_VOID **) &pData); |
| 982 | ASSERT_XGL_SUCCESS(err); |
| 983 | |
| 984 | Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f)); |
Courtney Goeltzenleuchter | d04e38c | 2014-10-22 18:02:30 -0600 | [diff] [blame] | 985 | // dumpMatrix("Model", Model); |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 986 | glm::mat4 MVP = Projection * View * Model; |
| 987 | // dumpMatrix("MVP", MVP); |
| 988 | |
| 989 | memcpy(pData, (const void*) &MVP[0][0], buf_size * sizeof(XGL_FLOAT)); |
| 990 | |
| 991 | err = xglUnmapMemory(m_constantBufferMem); |
| 992 | ASSERT_XGL_SUCCESS(err); |
| 993 | |
| 994 | // submit the command buffer to the universal queue |
| 995 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 996 | ASSERT_XGL_SUCCESS( err ); |
| 997 | |
| 998 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 999 | ASSERT_XGL_SUCCESS( err ); |
| 1000 | |
| 1001 | // Wait for work to finish before cleaning up. |
| 1002 | xglDeviceWaitIdle(m_device->device()); |
| 1003 | |
| 1004 | RecordImage(m_renderTarget); |
| 1005 | } |
| 1006 | } |
| 1007 | |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 1008 | void XglRenderTest::CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps) |
| 1009 | { |
| 1010 | XGL_RESULT err; |
| 1011 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1012 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 1013 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
| 1014 | |
| 1015 | |
| 1016 | // Create descriptor set for our one resource |
| 1017 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 1018 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1019 | descriptorInfo.slots = 1; // Vertex buffer only |
| 1020 | |
| 1021 | // create a descriptor set with a single slot |
| 1022 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 1023 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1024 | |
| 1025 | // bind memory to the descriptor set |
| 1026 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1027 | |
| 1028 | // write the vertex buffer view to the descriptor set |
| 1029 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 1030 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView ); |
| 1031 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 1032 | |
| 1033 | const int slots = 1; |
| 1034 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( slots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 1035 | slotInfo[0].shaderEntityIndex = 0; |
| 1036 | slotInfo[0].slotObjectType = XGL_SLOT_VERTEX_INPUT; |
| 1037 | |
| 1038 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1039 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 1040 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
| 1041 | vs_stage.shader.shader = vs; |
| 1042 | vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 1043 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = slots; |
| 1044 | vs_stage.shader.linkConstBufferCount = 0; |
| 1045 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1046 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1047 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1048 | |
| 1049 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1050 | ps_stage.pNext = &vs_stage; |
| 1051 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 1052 | ps_stage.shader.shader = ps; |
| 1053 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
| 1054 | ps_stage.shader.linkConstBufferCount = 0; |
| 1055 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1056 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1057 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1058 | |
| 1059 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1060 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1061 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1062 | }; |
| 1063 | |
| 1064 | // this is the current description of g_vbData |
| 1065 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1066 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1067 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1068 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1069 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1070 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1071 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1072 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1073 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1074 | |
| 1075 | XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO vi_state = { |
| 1076 | XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO, // sType; |
| 1077 | &ps_stage, // pNext; |
| 1078 | 1, // bindingCount |
| 1079 | &vi_binding, // pVertexBindingDescriptions; |
| 1080 | 2, // attributeCount; // number of attributes |
| 1081 | vi_attribs // pVertexAttributeDescriptions; |
| 1082 | }; |
| 1083 | |
| 1084 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 1085 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 1086 | &vi_state, // pNext |
| 1087 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 1088 | XGL_FALSE, // disableVertexReuse |
| 1089 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 1090 | XGL_FALSE, // primitiveRestartEnable |
| 1091 | 0 // primitiveRestartIndex |
| 1092 | }; |
| 1093 | |
| 1094 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 1095 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 1096 | &ia_state, |
| 1097 | XGL_FALSE, // depthClipEnable |
| 1098 | XGL_FALSE, // rasterizerDiscardEnable |
| 1099 | 1.0 // pointSize |
| 1100 | }; |
| 1101 | |
| 1102 | XGL_PIPELINE_CB_STATE cb_state = { |
| 1103 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 1104 | &rs_state, |
| 1105 | XGL_FALSE, // alphaToCoverageEnable |
| 1106 | XGL_FALSE, // dualSourceBlendEnable |
| 1107 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 1108 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 1109 | { |
| 1110 | XGL_FALSE, // blendEnable |
| 1111 | m_render_target_fmt, // XGL_FORMAT |
| 1112 | 0xF // channelWriteMask |
| 1113 | } |
| 1114 | } |
| 1115 | }; |
| 1116 | |
| 1117 | // TODO: Should take depth buffer format from queried formats |
| 1118 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 1119 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 1120 | &cb_state, |
| 1121 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 1122 | }; |
| 1123 | |
| 1124 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1125 | info.pNext = &db_state; |
| 1126 | info.flags = 0; |
| 1127 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
| 1128 | ASSERT_XGL_SUCCESS(err); |
| 1129 | |
| 1130 | err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem); |
| 1131 | ASSERT_XGL_SUCCESS(err); |
| 1132 | } |
| 1133 | |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1134 | /* |
| 1135 | * Based on CreatePipelineWithVertexFetch and CreatePipelineVSUniform |
| 1136 | */ |
| 1137 | void XglRenderTest::CreatePipelineWithVertexFetchAndMVP(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps) |
| 1138 | { |
| 1139 | XGL_RESULT err; |
| 1140 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1141 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 1142 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
| 1143 | |
| 1144 | // Create descriptor set for our two resources |
| 1145 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 1146 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1147 | descriptorInfo.slots = 2; // Vertex buffer and Model View Matrix |
| 1148 | |
| 1149 | // create a descriptor set with a single slot |
| 1150 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 1151 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1152 | |
| 1153 | // bind memory to the descriptor set |
| 1154 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1155 | |
| 1156 | // write the vertex buffer view to the descriptor set |
| 1157 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 1158 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView ); |
| 1159 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 1, 1, &m_constantBufferView ); |
| 1160 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 1161 | |
| 1162 | const int slots = 2; |
| 1163 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( slots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 1164 | slotInfo[0].shaderEntityIndex = 0; |
| 1165 | slotInfo[0].slotObjectType = XGL_SLOT_VERTEX_INPUT; |
| 1166 | slotInfo[1].shaderEntityIndex = 0; |
| 1167 | slotInfo[1].slotObjectType = XGL_SLOT_SHADER_RESOURCE; |
| 1168 | |
| 1169 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1170 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 1171 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
| 1172 | vs_stage.shader.shader = vs; |
| 1173 | vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 1174 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = slots; |
| 1175 | vs_stage.shader.linkConstBufferCount = 0; |
| 1176 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1177 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1178 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1179 | |
| 1180 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1181 | ps_stage.pNext = &vs_stage; |
| 1182 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 1183 | ps_stage.shader.shader = ps; |
| 1184 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
| 1185 | ps_stage.shader.linkConstBufferCount = 0; |
| 1186 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1187 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1188 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1189 | |
| 1190 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1191 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1192 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1193 | }; |
| 1194 | |
| 1195 | // this is the current description of g_vbData |
| 1196 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1197 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1198 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1199 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1200 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1201 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1202 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1203 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1204 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1205 | |
| 1206 | XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO vi_state = { |
| 1207 | XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO, // sType; |
| 1208 | &ps_stage, // pNext; |
| 1209 | 1, // bindingCount |
| 1210 | &vi_binding, // pVertexBindingDescriptions; |
| 1211 | 2, // attributeCount; // number of attributes |
| 1212 | vi_attribs // pVertexAttributeDescriptions; |
| 1213 | }; |
| 1214 | |
| 1215 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 1216 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 1217 | &vi_state, // pNext |
| 1218 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 1219 | XGL_FALSE, // disableVertexReuse |
| 1220 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 1221 | XGL_FALSE, // primitiveRestartEnable |
| 1222 | 0 // primitiveRestartIndex |
| 1223 | }; |
| 1224 | |
| 1225 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 1226 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 1227 | &ia_state, |
| 1228 | XGL_FALSE, // depthClipEnable |
| 1229 | XGL_FALSE, // rasterizerDiscardEnable |
| 1230 | 1.0 // pointSize |
| 1231 | }; |
| 1232 | |
| 1233 | XGL_PIPELINE_CB_STATE cb_state = { |
| 1234 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 1235 | &rs_state, |
| 1236 | XGL_FALSE, // alphaToCoverageEnable |
| 1237 | XGL_FALSE, // dualSourceBlendEnable |
| 1238 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 1239 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 1240 | { |
| 1241 | XGL_FALSE, // blendEnable |
| 1242 | m_render_target_fmt, // XGL_FORMAT |
| 1243 | 0xF // channelWriteMask |
| 1244 | } |
| 1245 | } |
| 1246 | }; |
| 1247 | |
| 1248 | // TODO: Should take depth buffer format from queried formats |
| 1249 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 1250 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 1251 | &cb_state, |
| 1252 | m_depth_stencil_fmt // XGL_FORMAT |
| 1253 | }; |
| 1254 | |
| 1255 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1256 | info.pNext = &db_state; |
| 1257 | info.flags = 0; |
| 1258 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
| 1259 | ASSERT_XGL_SUCCESS(err); |
| 1260 | |
| 1261 | err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem); |
| 1262 | ASSERT_XGL_SUCCESS(err); |
| 1263 | } |
| 1264 | |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1265 | void XglRenderTest::CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps) |
| 1266 | { |
| 1267 | XGL_RESULT err; |
| 1268 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1269 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 1270 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
| 1271 | |
| 1272 | |
| 1273 | const int vsSlots = 1; // Uniform buffer only |
| 1274 | |
| 1275 | // Create descriptor set for our one resource |
| 1276 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 1277 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1278 | descriptorInfo.slots = vsSlots; |
| 1279 | |
| 1280 | // create a descriptor set with a single slot |
| 1281 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 1282 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1283 | |
| 1284 | // bind memory to the descriptor set |
| 1285 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1286 | |
| 1287 | |
| 1288 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 1289 | slotInfo[0].shaderEntityIndex = 0; |
| 1290 | slotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; |
| 1291 | |
| 1292 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1293 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 1294 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
| 1295 | vs_stage.shader.shader = vs; |
| 1296 | vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 1297 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots; |
| 1298 | vs_stage.shader.linkConstBufferCount = 0; |
| 1299 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1300 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1301 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1302 | |
| 1303 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1304 | ps_stage.pNext = &vs_stage; |
| 1305 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 1306 | ps_stage.shader.shader = ps; |
| 1307 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
| 1308 | ps_stage.shader.linkConstBufferCount = 0; |
| 1309 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1310 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1311 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1312 | |
| 1313 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 1314 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 1315 | &ps_stage, // pNext |
| 1316 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 1317 | XGL_FALSE, // disableVertexReuse |
| 1318 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 1319 | XGL_FALSE, // primitiveRestartEnable |
| 1320 | 0 // primitiveRestartIndex |
| 1321 | }; |
| 1322 | |
| 1323 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 1324 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 1325 | &ia_state, |
| 1326 | XGL_FALSE, // depthClipEnable |
| 1327 | XGL_FALSE, // rasterizerDiscardEnable |
| 1328 | 1.0 // pointSize |
| 1329 | }; |
| 1330 | |
| 1331 | XGL_PIPELINE_CB_STATE cb_state = { |
| 1332 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 1333 | &rs_state, |
| 1334 | XGL_FALSE, // alphaToCoverageEnable |
| 1335 | XGL_FALSE, // dualSourceBlendEnable |
| 1336 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 1337 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 1338 | { |
| 1339 | XGL_FALSE, // blendEnable |
| 1340 | m_render_target_fmt, // XGL_FORMAT |
| 1341 | 0xF // channelWriteMask |
| 1342 | } |
| 1343 | } |
| 1344 | }; |
| 1345 | |
| 1346 | // TODO: Should take depth buffer format from queried formats |
| 1347 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 1348 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 1349 | &cb_state, |
| 1350 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 1351 | }; |
| 1352 | |
| 1353 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1354 | info.pNext = &db_state; |
| 1355 | info.flags = 0; |
| 1356 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
| 1357 | ASSERT_XGL_SUCCESS(err); |
| 1358 | |
| 1359 | err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem); |
| 1360 | ASSERT_XGL_SUCCESS(err); |
| 1361 | } |
| 1362 | |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1363 | void XglRenderTest::ClearDepthStencil(XGL_FLOAT value) |
| 1364 | /* clear the buffer */ |
| 1365 | { |
| 1366 | XGL_RESULT err; |
| 1367 | const uint16_t depth_value = (uint16_t) (value * 65535); |
| 1368 | const XGL_INT tw = 128 / sizeof(uint16_t); |
| 1369 | const XGL_INT th = 32; |
| 1370 | XGL_INT i, j, w, h; |
| 1371 | XGL_VOID *data; |
| 1372 | |
| 1373 | w = (m_width + tw - 1) / tw; |
| 1374 | h = (m_height + th - 1) / th; |
| 1375 | |
| 1376 | err = xglMapMemory(m_depthStencilMem, 0, &data); |
| 1377 | ASSERT_XGL_SUCCESS(err); |
| 1378 | |
| 1379 | for (i = 0; i < w * h; i++) { |
| 1380 | uint16_t *tile = (uint16_t *) ((char *) data + 4096 * i); |
| 1381 | |
| 1382 | for (j = 0; j < 2048; j++) |
| 1383 | tile[j] = depth_value; |
| 1384 | } |
| 1385 | |
| 1386 | err = xglUnmapMemory(m_depthStencilMem); |
| 1387 | ASSERT_XGL_SUCCESS(err); |
| 1388 | } |
| 1389 | |
| 1390 | void XglRenderTest::ClearRenderBuffer(XGL_UINT32 clear_color) |
| 1391 | /* clear the buffer */ |
| 1392 | { |
| 1393 | XGL_RESULT err; |
| 1394 | const XGL_IMAGE_SUBRESOURCE sr = { |
| 1395 | XGL_IMAGE_ASPECT_COLOR, 0, 0 |
| 1396 | }; |
| 1397 | XGL_SUBRESOURCE_LAYOUT sr_layout; |
| 1398 | XGL_UINT data_size = sizeof(sr_layout); |
| 1399 | XGL_VOID *ptr; |
| 1400 | |
| 1401 | err = xglGetImageSubresourceInfo( m_renderTarget->image(), |
| 1402 | &sr, XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, |
| 1403 | &data_size, &sr_layout); |
| 1404 | ASSERT_XGL_SUCCESS( err ); |
| 1405 | ASSERT_EQ(data_size, sizeof(sr_layout)); |
| 1406 | |
| 1407 | err = m_renderTarget->MapMemory( &ptr ); |
| 1408 | ASSERT_XGL_SUCCESS( err ); |
| 1409 | |
| 1410 | ptr = (void *) ((char *) ptr + sr_layout.offset); |
| 1411 | |
| 1412 | memset(ptr, clear_color, m_width * m_height *sizeof(XGL_UINT32)); |
| 1413 | |
| 1414 | err = m_renderTarget->UnmapMemory(); |
| 1415 | ASSERT_XGL_SUCCESS(err); |
| 1416 | } |
| 1417 | |
| 1418 | void XglRenderTest::InitDepthStencil() |
| 1419 | { |
| 1420 | XGL_RESULT err; |
| 1421 | XGL_IMAGE_CREATE_INFO image; |
| 1422 | XGL_MEMORY_ALLOC_INFO mem_alloc; |
| 1423 | XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view; |
| 1424 | XGL_MEMORY_REQUIREMENTS mem_reqs; |
| 1425 | XGL_SIZE mem_reqs_size; |
| 1426 | |
| 1427 | // Clean up default state created by framework |
| 1428 | if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil); |
| 1429 | |
| 1430 | m_depth_stencil_fmt.channelFormat = XGL_CH_FMT_R16; |
| 1431 | m_depth_stencil_fmt.numericFormat = XGL_NUM_FMT_DS; |
| 1432 | |
| 1433 | image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1434 | image.pNext = NULL; |
| 1435 | image.imageType = XGL_IMAGE_2D; |
| 1436 | image.format = m_depth_stencil_fmt; |
| 1437 | image.extent.width = m_width; |
| 1438 | image.extent.height = m_height; |
| 1439 | image.extent.depth = 1; |
| 1440 | image.mipLevels = 1; |
| 1441 | image.arraySize = 1; |
| 1442 | image.samples = 1; |
| 1443 | image.tiling = XGL_OPTIMAL_TILING; |
| 1444 | image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT; |
| 1445 | image.flags = 0; |
| 1446 | |
| 1447 | mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 1448 | mem_alloc.pNext = NULL; |
| 1449 | mem_alloc.allocationSize = 0; |
| 1450 | mem_alloc.alignment = 0; |
| 1451 | mem_alloc.flags = 0; |
| 1452 | mem_alloc.heapCount = 0; |
| 1453 | mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 1454 | |
| 1455 | /* create image */ |
| 1456 | err = xglCreateImage(device(), &image, |
| 1457 | &m_depthStencilImage); |
| 1458 | ASSERT_XGL_SUCCESS(err); |
| 1459 | |
| 1460 | err = xglGetObjectInfo(m_depthStencilImage, |
| 1461 | XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 1462 | &mem_reqs_size, &mem_reqs); |
| 1463 | ASSERT_XGL_SUCCESS(err); |
| 1464 | ASSERT_EQ(mem_reqs_size, sizeof(mem_reqs)); |
| 1465 | |
| 1466 | mem_alloc.allocationSize = mem_reqs.size; |
| 1467 | mem_alloc.alignment = mem_reqs.alignment; |
| 1468 | mem_alloc.heapCount = mem_reqs.heapCount; |
| 1469 | memcpy(mem_alloc.heaps, mem_reqs.heaps, |
| 1470 | sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount); |
| 1471 | |
| 1472 | /* allocate memory */ |
| 1473 | err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem); |
| 1474 | ASSERT_XGL_SUCCESS(err); |
| 1475 | |
| 1476 | /* bind memory */ |
| 1477 | err = xglBindObjectMemory(m_depthStencilImage, m_depthStencilMem, 0); |
| 1478 | ASSERT_XGL_SUCCESS(err); |
| 1479 | |
| 1480 | XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {}; |
| 1481 | depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO; |
| 1482 | depthStencil.depthTestEnable = XGL_TRUE; |
| 1483 | depthStencil.depthWriteEnable = XGL_TRUE; |
| 1484 | depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL; |
| 1485 | depthStencil.depthBoundsEnable = XGL_FALSE; |
| 1486 | depthStencil.minDepth = 0.f; |
| 1487 | depthStencil.maxDepth = 1.f; |
| 1488 | depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP; |
| 1489 | depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP; |
| 1490 | depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP; |
| 1491 | depthStencil.back.stencilRef = 0x00; |
| 1492 | depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS; |
| 1493 | depthStencil.front = depthStencil.back; |
| 1494 | |
| 1495 | err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil ); |
| 1496 | ASSERT_XGL_SUCCESS( err ); |
| 1497 | |
| 1498 | /* create image view */ |
| 1499 | view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO; |
| 1500 | view.pNext = NULL; |
| 1501 | view.image = XGL_NULL_HANDLE; |
| 1502 | view.mipLevel = 0; |
| 1503 | view.baseArraySlice = 0; |
| 1504 | view.arraySize = 1; |
| 1505 | view.flags = 0; |
| 1506 | view.image = m_depthStencilImage; |
| 1507 | err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView); |
| 1508 | ASSERT_XGL_SUCCESS(err); |
| 1509 | |
| 1510 | m_depthStencilBinding.view = m_depthStencilView; |
| 1511 | m_depthStencilBinding.depthState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 1512 | m_depthStencilBinding.stencilState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 1513 | } |
| 1514 | |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 1515 | void XglRenderTest::DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText) |
| 1516 | { |
| 1517 | XGL_PIPELINE pipeline; |
| 1518 | XGL_SHADER vs, ps; |
| 1519 | XGL_RESULT err; |
| 1520 | |
| 1521 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1522 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1523 | ASSERT_NO_FATAL_FAILURE(InitMesh(sizeof(g_vbData)/sizeof(g_vbData[0]), sizeof(g_vbData[0]), g_vbData)); |
| 1524 | |
| 1525 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 1526 | vertShaderText, &vs)); |
| 1527 | |
| 1528 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 1529 | fragShaderText, &ps)); |
| 1530 | |
| 1531 | ASSERT_NO_FATAL_FAILURE(CreatePipelineWithVertexFetch(&pipeline, vs, ps)); |
| 1532 | |
| 1533 | /* |
| 1534 | * Shaders are now part of the pipeline, don't need these anymore |
| 1535 | */ |
| 1536 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 1537 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 1538 | |
| 1539 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1540 | |
| 1541 | // Build command buffer |
| 1542 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 1543 | ASSERT_XGL_SUCCESS(err); |
| 1544 | |
| 1545 | GenerateClearAndPrepareBufferCmds(); |
| 1546 | GenerateBindRenderTargetCmd(); |
| 1547 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 1548 | |
| 1549 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 1550 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 1551 | |
| 1552 | // render the cube |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1553 | xglCmdDraw( m_cmdBuffer, 0, 12*3, 0, 1 ); |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 1554 | |
| 1555 | // prepare the back buffer for present |
| 1556 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 1557 | // transitionToPresent.image = m_image; |
| 1558 | // transitionToPresent.oldState = m_image_state; |
| 1559 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 1560 | // transitionToPresent.subresourceRange = srRange; |
| 1561 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 1562 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 1563 | |
| 1564 | // finalize recording of the command buffer |
| 1565 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 1566 | ASSERT_XGL_SUCCESS( err ); |
| 1567 | |
| 1568 | // this command buffer only uses the vertex buffer memory |
| 1569 | m_numMemRefs = 0; |
| 1570 | // m_memRefs[0].flags = 0; |
| 1571 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 1572 | |
| 1573 | // submit the command buffer to the universal queue |
| 1574 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 1575 | ASSERT_XGL_SUCCESS( err ); |
| 1576 | |
| 1577 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 1578 | ASSERT_XGL_SUCCESS( err ); |
| 1579 | |
| 1580 | // Wait for work to finish before cleaning up. |
| 1581 | xglDeviceWaitIdle(m_device->device()); |
| 1582 | |
| 1583 | RecordImage(m_renderTarget); |
| 1584 | |
| 1585 | } |
| 1586 | |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 1587 | struct xgltriangle_vs_uniform { |
| 1588 | // Must start with MVP |
| 1589 | XGL_FLOAT mvp[4][4]; |
| 1590 | XGL_FLOAT position[3][4]; |
| 1591 | XGL_FLOAT color[3][4]; |
| 1592 | }; |
| 1593 | |
Courtney Goeltzenleuchter | 6acb802 | 2014-10-27 13:08:55 -0600 | [diff] [blame^] | 1594 | void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText) |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 1595 | { |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 1596 | // Create identity matrix |
| 1597 | int i; |
| 1598 | struct xgltriangle_vs_uniform data; |
| 1599 | |
| 1600 | glm::mat4 Projection = glm::mat4(1.0f); |
| 1601 | glm::mat4 View = glm::mat4(1.0f); |
| 1602 | glm::mat4 Model = glm::mat4(1.0f); |
| 1603 | glm::mat4 MVP = Projection * View * Model; |
| 1604 | const int matrixSize = sizeof(MVP); |
| 1605 | const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT); |
| 1606 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 1607 | |
| 1608 | static const Vertex tri_data[] = |
| 1609 | { |
| 1610 | { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 1611 | { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 1612 | { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 1613 | }; |
| 1614 | |
| 1615 | for (i=0; i<3; i++) { |
| 1616 | data.position[i][0] = tri_data[i].posX; |
| 1617 | data.position[i][1] = tri_data[i].posY; |
| 1618 | data.position[i][2] = tri_data[i].posZ; |
| 1619 | data.position[i][3] = tri_data[i].posW; |
| 1620 | data.color[i][0] = tri_data[i].r; |
| 1621 | data.color[i][1] = tri_data[i].g; |
| 1622 | data.color[i][2] = tri_data[i].b; |
| 1623 | data.color[i][3] = tri_data[i].a; |
| 1624 | } |
| 1625 | |
| 1626 | InitConstantBuffer(bufSize*2, sizeof(XGL_FLOAT), (const void*) &data); |
| 1627 | |
| 1628 | DrawTriangleVSUniform(vertShaderText, fragShaderText, 1); |
| 1629 | RotateTriangleVSUniform(Projection, View, Model); |
| 1630 | } |
| 1631 | |
Courtney Goeltzenleuchter | 6acb802 | 2014-10-27 13:08:55 -0600 | [diff] [blame^] | 1632 | TEST_F(XglRenderTest, XGLTriangle_FragColor) |
| 1633 | { |
| 1634 | static const char *vertShaderText = |
| 1635 | "#version 140\n" |
| 1636 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1637 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1638 | "\n" |
| 1639 | "layout(binding = 0) uniform buf {\n" |
| 1640 | " mat4 MVP;\n" |
| 1641 | " vec4 position[3];\n" |
| 1642 | " vec4 color[3];\n" |
| 1643 | "} ubuf;\n" |
| 1644 | "\n" |
| 1645 | "layout (location = 0) out vec4 outColor;\n" |
| 1646 | "\n" |
| 1647 | "void main() \n" |
| 1648 | "{\n" |
| 1649 | " outColor = ubuf.color[gl_VertexID];\n" |
| 1650 | " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n" |
| 1651 | "}\n"; |
| 1652 | |
| 1653 | static const char *fragShaderText = |
| 1654 | "#version 140\n" |
| 1655 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1656 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1657 | "\n" |
| 1658 | "layout (location = 0) in vec4 inColor;\n" |
| 1659 | "\n" |
| 1660 | "void main()\n" |
| 1661 | "{\n" |
| 1662 | " gl_FragColor = inColor;\n" |
| 1663 | "}\n"; |
| 1664 | |
| 1665 | XGLTriangleTest(vertShaderText, fragShaderText); |
| 1666 | } |
| 1667 | |
| 1668 | TEST_F(XglRenderTest, XGLTriangle_OutputLocation) |
| 1669 | { |
| 1670 | static const char *vertShaderText = |
| 1671 | "#version 140\n" |
| 1672 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1673 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1674 | "\n" |
| 1675 | "layout(binding = 0) uniform buf {\n" |
| 1676 | " mat4 MVP;\n" |
| 1677 | " vec4 position[3];\n" |
| 1678 | " vec4 color[3];\n" |
| 1679 | "} ubuf;\n" |
| 1680 | "\n" |
| 1681 | "layout (location = 0) out vec4 outColor;\n" |
| 1682 | "\n" |
| 1683 | "void main() \n" |
| 1684 | "{\n" |
| 1685 | " outColor = ubuf.color[gl_VertexID];\n" |
| 1686 | " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n" |
| 1687 | "}\n"; |
| 1688 | |
| 1689 | static const char *fragShaderText = |
| 1690 | "#version 140\n" |
| 1691 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1692 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1693 | "\n" |
| 1694 | "layout (location = 0) in vec4 inColor;\n" |
| 1695 | "layout (location = 0) out vec4 outColor;\n" |
| 1696 | "\n" |
| 1697 | "void main()\n" |
| 1698 | "{\n" |
| 1699 | " outColor = inColor;\n" |
| 1700 | "}\n"; |
| 1701 | |
| 1702 | |
| 1703 | XGLTriangleTest(vertShaderText, fragShaderText); |
| 1704 | } |
| 1705 | |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 1706 | TEST_F(XglRenderTest, BIL_XGLTriangle) |
| 1707 | { |
| 1708 | bool saved_use_bil = XglTestFramework::m_use_bil; |
| 1709 | |
| 1710 | static const char *vertShaderText = |
| 1711 | "#version 140\n" |
| 1712 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1713 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1714 | "\n" |
| 1715 | "layout(binding = 0) uniform buf {\n" |
| 1716 | " mat4 MVP;\n" |
| 1717 | " vec4 position[3];\n" |
| 1718 | " vec4 color[3];\n" |
| 1719 | "} ubuf;\n" |
| 1720 | "\n" |
| 1721 | "layout (location = 0) out vec4 outColor;\n" |
| 1722 | "\n" |
| 1723 | "void main() \n" |
| 1724 | "{\n" |
| 1725 | " outColor = ubuf.color[gl_VertexID];\n" |
| 1726 | " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n" |
| 1727 | "}\n"; |
| 1728 | |
| 1729 | static const char *fragShaderText = |
| 1730 | "#version 140\n" |
| 1731 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1732 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1733 | "\n" |
| 1734 | "layout (location = 0) in vec4 inColor;\n" |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 1735 | "\n" |
| 1736 | "void main()\n" |
| 1737 | "{\n" |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 1738 | " gl_FragColor = inColor;\n" |
| 1739 | "}\n"; |
| 1740 | |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 1741 | |
| 1742 | XglTestFramework::m_use_bil = true; |
| 1743 | |
Courtney Goeltzenleuchter | 6acb802 | 2014-10-27 13:08:55 -0600 | [diff] [blame^] | 1744 | XGLTriangleTest(vertShaderText, fragShaderText); |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 1745 | |
| 1746 | XglTestFramework::m_use_bil = saved_use_bil; |
| 1747 | } |
| 1748 | |
Courtney Goeltzenleuchter | 08ccb48 | 2014-10-10 17:02:53 -0600 | [diff] [blame] | 1749 | TEST_F(XglRenderTest, GreenTriangle) |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1750 | { |
| 1751 | static const char *vertShaderText = |
| 1752 | "#version 130\n" |
| 1753 | "vec2 vertices[3];\n" |
| 1754 | "void main() {\n" |
| 1755 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 1756 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 1757 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 1758 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1759 | "}\n"; |
Courtney Goeltzenleuchter | 98e4943 | 2014-10-09 15:40:19 -0600 | [diff] [blame] | 1760 | |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1761 | static const char *fragShaderText = |
| 1762 | "#version 130\n" |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1763 | "void main() {\n" |
Steve K | 10b3251 | 2014-10-10 08:54:29 -0600 | [diff] [blame] | 1764 | " gl_FragColor = vec4(0,1,0,1);\n" |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1765 | "}\n"; |
Courtney Goeltzenleuchter | 7bbb420 | 2014-10-24 16:26:12 -0600 | [diff] [blame] | 1766 | |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1767 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 1768 | } |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1769 | |
Courtney Goeltzenleuchter | d4ee38d | 2014-10-10 13:59:38 -0600 | [diff] [blame] | 1770 | TEST_F(XglRenderTest, BIL_GreenTriangle) |
| 1771 | { |
| 1772 | bool saved_use_bil = XglTestFramework::m_use_bil; |
| 1773 | |
| 1774 | static const char *vertShaderText = |
| 1775 | "#version 130\n" |
| 1776 | "vec2 vertices[3];\n" |
| 1777 | "void main() {\n" |
| 1778 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 1779 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 1780 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 1781 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1782 | "}\n"; |
| 1783 | |
| 1784 | static const char *fragShaderText = |
| 1785 | "#version 130\n" |
| 1786 | "void main() {\n" |
| 1787 | " gl_FragColor = vec4(0,1,0,1);\n" |
| 1788 | "}\n"; |
| 1789 | XglTestFramework::m_use_bil = true; |
| 1790 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 1791 | XglTestFramework::m_use_bil = saved_use_bil; |
| 1792 | } |
| 1793 | |
Courtney Goeltzenleuchter | 08ccb48 | 2014-10-10 17:02:53 -0600 | [diff] [blame] | 1794 | TEST_F(XglRenderTest, TriangleFragUniform) |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1795 | { |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1796 | |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1797 | static const char *vertShaderText = |
| 1798 | "#version 130\n" |
| 1799 | "out vec4 color;\n" |
| 1800 | "out vec4 scale;\n" |
| 1801 | "vec2 vertices[3];\n" |
| 1802 | "void main() {\n" |
| 1803 | "vec2 vertices[3];\n" |
| 1804 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1805 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1806 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 1807 | "vec4 colors[3];\n" |
| 1808 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 1809 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 1810 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 1811 | " color = colors[gl_VertexID % 3];\n" |
| 1812 | " scale = vec4(1.0, 1.0, 1.0, 1.0);\n" |
| 1813 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1814 | "}\n"; |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1815 | |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1816 | static const char *fragShaderText = |
| 1817 | "#version 130\n" |
| 1818 | "in vec4 color;\n" |
| 1819 | "in vec4 scale;\n" |
| 1820 | "uniform vec4 foo;\n" |
| 1821 | "void main() {\n" |
| 1822 | " gl_FragColor = color * scale + foo;\n" |
| 1823 | "}\n"; |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1824 | |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1825 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 1826 | } |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1827 | |
Courtney Goeltzenleuchter | 08ccb48 | 2014-10-10 17:02:53 -0600 | [diff] [blame] | 1828 | TEST_F(XglRenderTest, YellowTriangle) |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1829 | { |
| 1830 | static const char *vertShaderText = |
| 1831 | "#version 130\n" |
| 1832 | "void main() {\n" |
| 1833 | " vec2 vertices[3];" |
| 1834 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1835 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1836 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 1837 | " vec4 colors[3];\n" |
| 1838 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 1839 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 1840 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 1841 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1842 | "}\n"; |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1843 | |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1844 | static const char *fragShaderText = |
| 1845 | "#version 130\n" |
| 1846 | "void main() {\n" |
| 1847 | " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n" |
| 1848 | "}\n"; |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1849 | |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1850 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 1851 | } |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1852 | |
Courtney Goeltzenleuchter | 08ccb48 | 2014-10-10 17:02:53 -0600 | [diff] [blame] | 1853 | TEST_F(XglRenderTest, RotatedTriangle) { |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1854 | DrawRotatedTriangleTest(); |
| 1855 | } |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1856 | |
Courtney Goeltzenleuchter | 08ccb48 | 2014-10-10 17:02:53 -0600 | [diff] [blame] | 1857 | TEST_F(XglRenderTest, TriangleTwoFSUniforms) |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1858 | { |
| 1859 | static const char *vertShaderText = |
| 1860 | "#version 130\n" |
| 1861 | "out vec4 color;\n" |
| 1862 | "out vec4 scale;\n" |
| 1863 | "out vec2 samplePos;\n" |
| 1864 | "void main() {\n" |
| 1865 | " vec2 vertices[3];" |
| 1866 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1867 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1868 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 1869 | " vec4 colors[3];\n" |
| 1870 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 1871 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 1872 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 1873 | " color = colors[gl_VertexID % 3];\n" |
| 1874 | " vec2 positions[3];" |
| 1875 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 1876 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 1877 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 1878 | " scale = vec4(0.0, 0.0, 0.0, 0.0);\n" |
| 1879 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 1880 | "}\n"; |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 1881 | |
| 1882 | |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1883 | static const char *fragShaderText = |
| 1884 | "#version 430\n" |
| 1885 | "in vec4 color;\n" |
| 1886 | "in vec4 scale;\n" |
| 1887 | "uniform vec4 foo;\n" |
| 1888 | "uniform vec4 bar;\n" |
| 1889 | "void main() {\n" |
| 1890 | // by default, with no location or blocks |
| 1891 | // the compiler will read them from buffer |
| 1892 | // in reverse order of first use in shader |
| 1893 | // The buffer contains red, followed by blue, |
| 1894 | // so foo should be blue, bar should be red |
| 1895 | " gl_FragColor = color * scale * foo * bar + foo;\n" |
| 1896 | "}\n"; |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 1897 | |
Cody Northrop | 5b7d85a | 2014-10-09 21:26:47 -0600 | [diff] [blame] | 1898 | DrawTriangleTwoUniformsFS(vertShaderText, fragShaderText); |
| 1899 | } |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 1900 | |
Courtney Goeltzenleuchter | 08ccb48 | 2014-10-10 17:02:53 -0600 | [diff] [blame] | 1901 | TEST_F(XglRenderTest, TriangleWithVertexFetch) |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1902 | { |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 1903 | static const char *vertShaderText = |
Courtney Goeltzenleuchter | bb7014d | 2014-10-09 11:05:19 -0600 | [diff] [blame] | 1904 | "#version 130\n" |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 1905 | //XYZ1( -1, -1, -1 ) |
| 1906 | "in vec4 pos;\n" |
| 1907 | //XYZ1( 0.f, 0.f, 0.f ) |
| 1908 | "in vec4 inColor;\n" |
| 1909 | "out vec4 outColor;\n" |
Courtney Goeltzenleuchter | 9b4ab89 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 1910 | "void main() {\n" |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1911 | " outColor = inColor;\n" |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 1912 | " gl_Position = pos;\n" |
Courtney Goeltzenleuchter | 9b4ab89 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 1913 | "}\n"; |
| 1914 | |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1915 | |
Courtney Goeltzenleuchter | 9b4ab89 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 1916 | static const char *fragShaderText = |
Cody Northrop | 0dbe84f | 2014-10-09 19:55:56 -0600 | [diff] [blame] | 1917 | "#version 430\n" |
| 1918 | "in vec4 color;\n" |
Courtney Goeltzenleuchter | 9b4ab89 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 1919 | "void main() {\n" |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 1920 | " gl_FragColor = color;\n" |
Courtney Goeltzenleuchter | 9b4ab89 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 1921 | "}\n"; |
Courtney Goeltzenleuchter | 9b4ab89 | 2014-10-09 15:37:21 -0600 | [diff] [blame] | 1922 | |
Cody Northrop | 4e6b476 | 2014-10-09 21:25:22 -0600 | [diff] [blame] | 1923 | DrawTriangleWithVertexFetch(vertShaderText, fragShaderText); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 1924 | } |
| 1925 | |
Courtney Goeltzenleuchter | 3d10c9c | 2014-10-27 13:06:08 -0600 | [diff] [blame] | 1926 | TEST_F(XglRenderTest, TriangleVSUniform) |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1927 | { |
| 1928 | static const char *vertShaderText = |
Courtney Goeltzenleuchter | c3f4ac8 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1929 | "#version 140\n" |
| 1930 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1931 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1932 | "\n" |
| 1933 | "layout(binding = 0) uniform buf {\n" |
| 1934 | " mat4 MVP;\n" |
| 1935 | "} ubuf;\n" |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1936 | "void main() {\n" |
| 1937 | " vec2 vertices[3];" |
| 1938 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 1939 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 1940 | " vertices[2] = vec2( 0.5, 0.5);\n" |
Courtney Goeltzenleuchter | c3f4ac8 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1941 | " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1942 | "}\n"; |
| 1943 | |
| 1944 | static const char *fragShaderText = |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1945 | "#version 130\n" |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1946 | "void main() {\n" |
Cody Northrop | 78eac04 | 2014-10-10 15:45:00 -0600 | [diff] [blame] | 1947 | " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" |
Cody Northrop | 7a1f046 | 2014-10-10 14:49:36 -0600 | [diff] [blame] | 1948 | "}\n"; |
| 1949 | |
Courtney Goeltzenleuchter | 34b8177 | 2014-10-10 18:04:39 -0600 | [diff] [blame] | 1950 | // Create identity matrix |
Courtney Goeltzenleuchter | c3f4ac8 | 2014-10-27 09:48:52 -0600 | [diff] [blame] | 1951 | glm::mat4 Projection = glm::mat4(1.0f); |
| 1952 | glm::mat4 View = glm::mat4(1.0f); |
| 1953 | glm::mat4 Model = glm::mat4(1.0f); |
| 1954 | glm::mat4 MVP = Projection * View * Model; |
| 1955 | const int matrixSize = sizeof(MVP) / sizeof(MVP[0]); |
| 1956 | |
| 1957 | InitConstantBuffer(matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]); |
| 1958 | |
| 1959 | DrawTriangleVSUniform(vertShaderText, fragShaderText, 1); |
| 1960 | RotateTriangleVSUniform(Projection, View, Model); |
| 1961 | } |
| 1962 | |
Courtney Goeltzenleuchter | d055629 | 2014-10-20 16:33:15 -0600 | [diff] [blame] | 1963 | TEST_F(XglRenderTest, TriangleWithVertexFetchAndMVP) |
| 1964 | { |
| 1965 | static const char *vertShaderText = |
| 1966 | "#version 140\n" |
| 1967 | "layout (std140) uniform bufferVals {\n" |
| 1968 | " mat4 mvp;\n" |
| 1969 | "} myBufferVals;\n" |
| 1970 | "in vec4 pos;\n" |
| 1971 | "in vec4 inColor;\n" |
| 1972 | "out vec4 outColor;\n" |
| 1973 | "void main() {\n" |
| 1974 | " outColor = inColor;\n" |
| 1975 | " gl_Position = myBufferVals.mvp * pos;\n" |
| 1976 | "}\n"; |
| 1977 | |
| 1978 | static const char *fragShaderText = |
| 1979 | "#version 130\n" |
| 1980 | "in vec4 color;\n" |
| 1981 | "void main() {\n" |
| 1982 | " gl_FragColor = color;\n" |
| 1983 | "}\n"; |
| 1984 | |
| 1985 | DrawTriangleWithVertexFetchAndMVP(vertShaderText, fragShaderText); |
| 1986 | } |
| 1987 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 1988 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 1989 | int result; |
| 1990 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 1991 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 1992 | XglTestFramework::InitArgs(&argc, argv); |
| 1993 | |
Courtney Goeltzenleuchter | f12c776 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 1994 | ::testing::Environment* const xgl_test_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 1995 | |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 1996 | result = RUN_ALL_TESTS(); |
| 1997 | |
| 1998 | XglTestFramework::Finish(); |
| 1999 | return result; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 2000 | } |