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