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