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