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