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