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