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