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); |
| 150 | void DrawTriangleTwoUniformsFS(const char *vertShaderText, const char *fragShaderText); |
| 151 | void DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText); |
| 152 | void DrawTriangleVSUniform(const char *vertShaderText, const char *fragShaderText); |
Cody Northrop | 0fdf64e | 2014-10-20 11:51:06 -0600 | [diff] [blame] | 153 | void DrawTriangleFSUniformBlock(const char *vertShaderText, const char *fragShaderText); |
Cody Northrop | ec1d3c3 | 2014-10-28 15:41:42 -0600 | [diff] [blame] | 154 | void DrawTriangleFSUniformBlockBinding(const char *vertShaderText, const char *fragShaderText); |
Cody Northrop | 0fdf64e | 2014-10-20 11:51:06 -0600 | [diff] [blame] | 155 | void DrawTriangleVSUniformBlock(const char *vertShaderText, const char *fragShaderText); |
| 156 | void DrawTriangleVSFSUniformBlock(const char *vertShaderText, const char *fragShaderText); |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 157 | void DrawTexturedTriangle(const char *vertShaderText, const char *fragShaderText); |
Cody Northrop | 9394e0c | 2014-10-23 10:21:47 -0600 | [diff] [blame] | 158 | void DrawVSTexture(const char *vertShaderText, const char *fragShaderText); |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 159 | void DrawSamplerBindingsTriangle(const char *vertShaderText, const char *fragShaderText, int textureCount, int samplerCount); |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 160 | |
Cody Northrop | 0fdf64e | 2014-10-20 11:51:06 -0600 | [diff] [blame] | 161 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 162 | void CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); |
Cody Northrop | ec1d3c3 | 2014-10-28 15:41:42 -0600 | [diff] [blame] | 163 | 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] | 164 | void CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); |
Cody Northrop | 0fdf64e | 2014-10-20 11:51:06 -0600 | [diff] [blame] | 165 | void CreatePipelineVSFSUniformBlock(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 166 | void CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 167 | 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] | 168 | |
| 169 | protected: |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 170 | XGL_IMAGE m_texture[g_TextureCount]; |
| 171 | XGL_IMAGE_VIEW m_textureView[g_TextureCount]; |
| 172 | XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo[g_TextureCount]; |
| 173 | XGL_GPU_MEMORY m_textureMem[g_TextureCount]; |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 174 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 175 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 176 | XGL_SAMPLER m_sampler[g_SamplerCount]; |
| 177 | |
| 178 | XGL_GPU_MEMORY m_uniformBufferMem[g_UniformBufferCount]; |
| 179 | XGL_MEMORY_VIEW_ATTACH_INFO m_uniformBufferView[g_UniformBufferCount]; |
Cody Northrop | ec1d3c3 | 2014-10-28 15:41:42 -0600 | [diff] [blame] | 180 | |
| 181 | |
| 182 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 183 | // XGL_APPLICATION_INFO app_info; |
| 184 | // XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 185 | // XGL_UINT gpu_count; |
| 186 | // XGL_GPU_MEMORY m_descriptor_set_mem; |
| 187 | // XGL_GPU_MEMORY m_pipe_mem; |
| 188 | // XglDevice *m_device; |
| 189 | // XGL_CMD_BUFFER m_cmdBuffer; |
| 190 | // XGL_UINT32 m_numVertices; |
| 191 | // XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView; |
| 192 | // XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView; |
| 193 | // XGL_GPU_MEMORY m_vtxBufferMem; |
| 194 | // XGL_GPU_MEMORY m_constantBufferMem; |
| 195 | // XGL_UINT32 m_numMemRefs; |
| 196 | // XGL_MEMORY_REF m_memRefs[5]; |
| 197 | // XGL_RASTER_STATE_OBJECT m_stateRaster; |
| 198 | // XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend; |
| 199 | // XGL_VIEWPORT_STATE_OBJECT m_stateViewport; |
| 200 | // XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil; |
| 201 | // XGL_MSAA_STATE_OBJECT m_stateMsaa; |
| 202 | // XGL_DESCRIPTOR_SET m_rsrcDescSet; |
| 203 | |
| 204 | virtual void SetUp() { |
| 205 | |
| 206 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 207 | this->app_info.pNext = NULL; |
Cody Northrop | aa85325 | 2014-10-20 09:25:17 -0600 | [diff] [blame] | 208 | this->app_info.pAppName = (const XGL_CHAR *) "compiler render_tests"; |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 209 | this->app_info.appVersion = 1; |
| 210 | this->app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 211 | this->app_info.engineVersion = 1; |
| 212 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 213 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 214 | for (int i = 0; i < g_TextureCount; ++i) { |
| 215 | m_textureViewInfo[i].sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
| 216 | } |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 217 | |
| 218 | InitFramework(); |
| 219 | } |
| 220 | |
| 221 | virtual void TearDown() { |
| 222 | // Clean up resources before we reset |
| 223 | ShutdownFramework(); |
| 224 | } |
| 225 | }; |
| 226 | |
| 227 | // this function will create the vertex buffer and fill it with the mesh data |
| 228 | void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, |
| 229 | const void* vertices ) |
| 230 | { |
| 231 | XGL_RESULT err = XGL_SUCCESS; |
| 232 | |
| 233 | assert( numVertices * vbStride > 0 ); |
| 234 | m_numVertices = numVertices; |
| 235 | |
| 236 | XGL_MEMORY_ALLOC_INFO alloc_info = {}; |
| 237 | XGL_UINT8 *pData; |
| 238 | |
| 239 | alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 240 | alloc_info.allocationSize = numVertices * vbStride; |
| 241 | alloc_info.alignment = 0; |
| 242 | alloc_info.heapCount = 1; |
| 243 | alloc_info.heaps[0] = 0; // TODO: Use known existing heap |
| 244 | |
| 245 | alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT; |
| 246 | alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 247 | |
| 248 | err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem); |
| 249 | ASSERT_XGL_SUCCESS(err); |
| 250 | |
| 251 | err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData); |
| 252 | ASSERT_XGL_SUCCESS(err); |
| 253 | |
| 254 | memcpy(pData, vertices, alloc_info.allocationSize); |
| 255 | |
| 256 | err = xglUnmapMemory(m_vtxBufferMem); |
| 257 | ASSERT_XGL_SUCCESS(err); |
| 258 | |
| 259 | // set up the memory view for the vertex buffer |
| 260 | this->m_vtxBufferView.stride = vbStride; |
| 261 | this->m_vtxBufferView.range = numVertices * vbStride; |
| 262 | this->m_vtxBufferView.offset = 0; |
| 263 | this->m_vtxBufferView.mem = m_vtxBufferMem; |
| 264 | this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 265 | this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED; |
| 266 | |
| 267 | // open the command buffer |
| 268 | err = xglBeginCommandBuffer( m_cmdBuffer, 0 ); |
| 269 | ASSERT_XGL_SUCCESS(err); |
| 270 | |
| 271 | XGL_MEMORY_STATE_TRANSITION transition = {}; |
| 272 | transition.mem = m_vtxBufferMem; |
| 273 | transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER; |
| 274 | transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 275 | transition.offset = 0; |
| 276 | transition.regionSize = numVertices * vbStride; |
| 277 | |
| 278 | // write transition to the command buffer |
| 279 | xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition ); |
| 280 | this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 281 | |
| 282 | // finish recording the command buffer |
| 283 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 284 | ASSERT_XGL_SUCCESS(err); |
| 285 | |
| 286 | // this command buffer only uses the vertex buffer memory |
| 287 | m_numMemRefs = 1; |
| 288 | m_memRefs[0].flags = 0; |
| 289 | m_memRefs[0].mem = m_vtxBufferMem; |
| 290 | |
| 291 | // submit the command buffer to the universal queue |
| 292 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 293 | ASSERT_XGL_SUCCESS(err); |
| 294 | } |
| 295 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 296 | void XglRenderTest::InitTexture(int textureSlot, int* color) |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 297 | { |
| 298 | #define DEMO_TEXTURE_COUNT 1 |
| 299 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 300 | 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] | 301 | const XGL_INT tex_width = 16; |
| 302 | const XGL_INT tex_height = 16; |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 303 | uint32_t tex_colors[DEMO_TEXTURE_COUNT][2]; |
| 304 | |
| 305 | // assign the texture color with parameter |
| 306 | assert(1 == DEMO_TEXTURE_COUNT); |
| 307 | if (color != NULL) { |
| 308 | tex_colors[0][0] = *color; |
| 309 | tex_colors[0][1] = *color; |
| 310 | } else { |
| 311 | tex_colors[0][0] = 0xffff0000; |
| 312 | tex_colors[0][1] = 0xff00ff00; |
| 313 | } |
| 314 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 315 | XGL_RESULT err; |
| 316 | XGL_UINT i; |
| 317 | |
| 318 | for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 319 | const XGL_IMAGE_CREATE_INFO image = { |
| 320 | .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 321 | .pNext = NULL, |
| 322 | .imageType = XGL_IMAGE_2D, |
| 323 | .format = tex_format, |
| 324 | .extent = { tex_width, tex_height, 1 }, |
| 325 | .mipLevels = 1, |
| 326 | .arraySize = 1, |
| 327 | .samples = 1, |
| 328 | .tiling = XGL_LINEAR_TILING, |
| 329 | .usage = XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT, |
| 330 | .flags = 0, |
| 331 | }; |
| 332 | XGL_MEMORY_ALLOC_INFO mem_alloc; |
| 333 | mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 334 | mem_alloc.pNext = NULL; |
| 335 | mem_alloc.allocationSize = 0; |
| 336 | mem_alloc.alignment = 0; |
| 337 | mem_alloc.flags = 0; |
| 338 | mem_alloc.heapCount = 0; |
| 339 | mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 340 | XGL_IMAGE_VIEW_CREATE_INFO view; |
| 341 | view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 342 | view.pNext = NULL; |
| 343 | view.image = XGL_NULL_HANDLE; |
| 344 | view.viewType = XGL_IMAGE_VIEW_2D; |
| 345 | view.format = image.format; |
| 346 | view.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 347 | view.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 348 | view.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 349 | view.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 350 | view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 351 | view.subresourceRange.baseMipLevel = 0; |
| 352 | view.subresourceRange.mipLevels = 1; |
| 353 | view.subresourceRange.baseArraySlice = 0; |
| 354 | view.subresourceRange.arraySize = 1; |
| 355 | view.minLod = 0.0f; |
| 356 | |
| 357 | XGL_MEMORY_REQUIREMENTS mem_reqs; |
| 358 | XGL_SIZE mem_reqs_size; |
| 359 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 360 | /* create image */ |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 361 | err = xglCreateImage(device(), &image, &m_texture[textureSlot]); |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 362 | assert(!err); |
| 363 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 364 | err = xglGetObjectInfo(m_texture[textureSlot], |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 365 | XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 366 | &mem_reqs_size, &mem_reqs); |
| 367 | assert(!err && mem_reqs_size == sizeof(mem_reqs)); |
| 368 | |
| 369 | mem_alloc.allocationSize = mem_reqs.size; |
| 370 | mem_alloc.alignment = mem_reqs.alignment; |
| 371 | mem_alloc.heapCount = mem_reqs.heapCount; |
| 372 | memcpy(mem_alloc.heaps, mem_reqs.heaps, |
| 373 | sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount); |
| 374 | |
| 375 | /* allocate memory */ |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 376 | err = xglAllocMemory(device(), &mem_alloc, &m_textureMem[textureSlot]); |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 377 | assert(!err); |
| 378 | |
| 379 | /* bind memory */ |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 380 | err = xglBindObjectMemory(m_texture[textureSlot], m_textureMem[textureSlot], 0); |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 381 | assert(!err); |
| 382 | |
| 383 | /* create image view */ |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 384 | view.image = m_texture[textureSlot]; |
| 385 | err = xglCreateImageView(device(), &view, &m_textureView[textureSlot]); |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 386 | assert(!err); |
| 387 | } |
| 388 | |
| 389 | for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { |
| 390 | const XGL_IMAGE_SUBRESOURCE subres = { |
| 391 | .aspect = XGL_IMAGE_ASPECT_COLOR, |
| 392 | .mipLevel = 0, |
| 393 | .arraySlice = 0, |
| 394 | }; |
| 395 | XGL_SUBRESOURCE_LAYOUT layout; |
| 396 | XGL_SIZE layout_size; |
| 397 | XGL_VOID *data; |
| 398 | XGL_INT x, y; |
| 399 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 400 | err = xglGetImageSubresourceInfo(m_texture[textureSlot], &subres, |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 401 | XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &layout_size, &layout); |
| 402 | assert(!err && layout_size == sizeof(layout)); |
| 403 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 404 | err = xglMapMemory(m_textureMem[textureSlot], 0, &data); |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 405 | assert(!err); |
| 406 | |
| 407 | for (y = 0; y < tex_height; y++) { |
| 408 | uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y); |
| 409 | for (x = 0; x < tex_width; x++) |
| 410 | row[x] = tex_colors[i][(x & 1) ^ (y & 1)]; |
| 411 | } |
| 412 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 413 | err = xglUnmapMemory(m_textureMem[textureSlot]); |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 414 | assert(!err); |
| 415 | } |
| 416 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 417 | m_textureViewInfo[textureSlot].view = m_textureView[textureSlot]; |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 418 | } |
| 419 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 420 | |
| 421 | void XglRenderTest::InitMultipleTextures(int textureCount, int* colors) |
| 422 | { |
| 423 | |
| 424 | for (int i = 0; i < textureCount; ++i) |
| 425 | InitTexture(i, &colors[i]); |
| 426 | } |
| 427 | |
| 428 | |
| 429 | void XglRenderTest::InitMultipleSamplers(const int samplerCount) |
| 430 | { |
| 431 | XGL_RESULT err; |
| 432 | |
| 433 | for (int i = 0; i < samplerCount; ++i) { |
| 434 | |
| 435 | XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {}; |
| 436 | samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 437 | samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST; |
| 438 | samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST; |
| 439 | samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE; |
| 440 | samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP; |
| 441 | samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP; |
| 442 | samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP; |
| 443 | samplerCreateInfo.mipLodBias = 0.0; |
| 444 | samplerCreateInfo.maxAnisotropy = 0.0; |
| 445 | samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER; |
| 446 | samplerCreateInfo.minLod = 0.0; |
| 447 | samplerCreateInfo.maxLod = 0.0; |
| 448 | samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE; |
| 449 | |
| 450 | err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler[i]); |
| 451 | ASSERT_XGL_SUCCESS(err); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | void XglRenderTest::InitSampler(int samplerSlot) |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 456 | { |
| 457 | XGL_RESULT err; |
| 458 | |
| 459 | XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {}; |
| 460 | samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 461 | samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST; |
| 462 | samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST; |
| 463 | samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE; |
| 464 | samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP; |
| 465 | samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP; |
| 466 | samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP; |
| 467 | samplerCreateInfo.mipLodBias = 0.0; |
| 468 | samplerCreateInfo.maxAnisotropy = 0.0; |
| 469 | samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER; |
| 470 | samplerCreateInfo.minLod = 0.0; |
| 471 | samplerCreateInfo.maxLod = 0.0; |
| 472 | samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE; |
| 473 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 474 | err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler[samplerSlot]); |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 475 | ASSERT_XGL_SUCCESS(err); |
| 476 | } |
| 477 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 478 | |
Cody Northrop | ec1d3c3 | 2014-10-28 15:41:42 -0600 | [diff] [blame] | 479 | void XglRenderTest::InitUniformBuffer(int constantCount, int constantSize, |
| 480 | int constantIndex, const void* data) |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 481 | { |
Cody Northrop | ec1d3c3 | 2014-10-28 15:41:42 -0600 | [diff] [blame] | 482 | // based on XglRenderFramework::InitConstantBuffer |
| 483 | // mainly add an index when selecting which buffer you are creating |
| 484 | |
| 485 | XGL_RESULT err = XGL_SUCCESS; |
| 486 | |
| 487 | XGL_MEMORY_ALLOC_INFO alloc_info = {}; |
| 488 | XGL_UINT8 *pData; |
| 489 | |
| 490 | alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 491 | alloc_info.allocationSize = constantCount * constantSize; |
| 492 | alloc_info.alignment = 0; |
| 493 | alloc_info.heapCount = 1; |
| 494 | alloc_info.heaps[0] = 0; // TODO: Use known existing heap |
| 495 | |
| 496 | alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT; |
| 497 | alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 498 | |
| 499 | err = xglAllocMemory(device(), &alloc_info, &m_uniformBufferMem[constantIndex]); |
| 500 | ASSERT_XGL_SUCCESS(err); |
| 501 | |
| 502 | err = xglMapMemory(m_uniformBufferMem[constantIndex], 0, (XGL_VOID **) &pData); |
| 503 | ASSERT_XGL_SUCCESS(err); |
| 504 | |
| 505 | memcpy(pData, data, alloc_info.allocationSize); |
| 506 | |
| 507 | err = xglUnmapMemory(m_uniformBufferMem[constantIndex]); |
| 508 | ASSERT_XGL_SUCCESS(err); |
| 509 | |
| 510 | // set up the memory view for the constant buffer |
| 511 | this->m_uniformBufferView[constantIndex].stride = 16; |
| 512 | this->m_uniformBufferView[constantIndex].range = alloc_info.allocationSize; |
| 513 | this->m_uniformBufferView[constantIndex].offset = 0; |
| 514 | this->m_uniformBufferView[constantIndex].mem = m_uniformBufferMem[constantIndex]; |
| 515 | this->m_uniformBufferView[constantIndex].format.channelFormat = XGL_CH_FMT_R32G32B32A32; |
| 516 | this->m_uniformBufferView[constantIndex].format.numericFormat = XGL_NUM_FMT_FLOAT; |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText) |
| 520 | { |
| 521 | XGL_PIPELINE pipeline; |
| 522 | XGL_SHADER vs, ps; |
| 523 | XGL_RESULT err; |
| 524 | |
| 525 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 526 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 527 | |
| 528 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 529 | vertShaderText, &vs)); |
| 530 | |
| 531 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 532 | fragShaderText, &ps)); |
| 533 | |
| 534 | ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps)); |
| 535 | |
| 536 | /* |
| 537 | * Shaders are now part of the pipeline, don't need these anymore |
| 538 | */ |
| 539 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 540 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 541 | |
| 542 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 543 | |
| 544 | const int constantCount = 4; |
| 545 | const float constants[constantCount] = { 0.5, 0.5, 0.5, 1.0 }; |
| 546 | InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants); |
| 547 | |
| 548 | // Create descriptor set for a uniform resource |
| 549 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 550 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 551 | descriptorInfo.slots = 1; |
| 552 | |
| 553 | // create a descriptor set with a single slot |
| 554 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 555 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 556 | |
| 557 | // bind memory to the descriptor set |
| 558 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 559 | |
| 560 | // write the constant buffer view to the descriptor set |
| 561 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 562 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 563 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 564 | |
| 565 | // Build command buffer |
| 566 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 567 | ASSERT_XGL_SUCCESS(err); |
| 568 | |
| 569 | GenerateClearAndPrepareBufferCmds(); |
| 570 | GenerateBindRenderTargetCmd(); |
| 571 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 572 | |
| 573 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 574 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 575 | |
| 576 | // render the cube |
| 577 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 578 | |
| 579 | // prepare the back buffer for present |
| 580 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 581 | // transitionToPresent.image = m_image; |
| 582 | // transitionToPresent.oldState = m_image_state; |
| 583 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 584 | // transitionToPresent.subresourceRange = srRange; |
| 585 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 586 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 587 | |
| 588 | // finalize recording of the command buffer |
| 589 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 590 | ASSERT_XGL_SUCCESS( err ); |
| 591 | |
| 592 | // this command buffer only uses the vertex buffer memory |
| 593 | m_numMemRefs = 0; |
| 594 | // m_memRefs[0].flags = 0; |
| 595 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 596 | |
| 597 | // submit the command buffer to the universal queue |
| 598 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 599 | ASSERT_XGL_SUCCESS( err ); |
| 600 | |
| 601 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 602 | ASSERT_XGL_SUCCESS( err ); |
| 603 | |
| 604 | // Wait for work to finish before cleaning up. |
| 605 | xglDeviceWaitIdle(m_device->device()); |
| 606 | |
| 607 | RecordImage(m_renderTarget); |
| 608 | |
| 609 | } |
| 610 | |
| 611 | void XglRenderTest::DrawTriangleTwoUniformsFS(const char *vertShaderText, const char *fragShaderText) |
| 612 | { |
| 613 | XGL_PIPELINE pipeline; |
| 614 | XGL_SHADER vs, ps; |
| 615 | XGL_RESULT err; |
| 616 | |
| 617 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 618 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 619 | |
| 620 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 621 | vertShaderText, &vs)); |
| 622 | |
| 623 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 624 | fragShaderText, &ps)); |
| 625 | |
| 626 | ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps)); |
| 627 | |
| 628 | /* |
| 629 | * Shaders are now part of the pipeline, don't need these anymore |
| 630 | */ |
| 631 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 632 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 633 | |
| 634 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 635 | |
| 636 | const int constantCount = 8; |
| 637 | const float constants[constantCount] = { 1.0, 0.0, 0.0, 1.0, |
| 638 | 0.0, 0.0, 1.0, 1.0 }; |
| 639 | |
| 640 | InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants); |
| 641 | |
| 642 | // Create descriptor set for a uniform resource |
| 643 | const int slotCount = 1; |
| 644 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 645 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 646 | descriptorInfo.slots = slotCount; |
| 647 | |
| 648 | // create a descriptor set with a single slot |
| 649 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 650 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 651 | |
| 652 | // bind memory to the descriptor set |
| 653 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 654 | |
| 655 | // write the constant buffer view to the descriptor set |
| 656 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 657 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 658 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 659 | |
| 660 | // Build command buffer |
| 661 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 662 | ASSERT_XGL_SUCCESS(err); |
| 663 | |
| 664 | GenerateClearAndPrepareBufferCmds(); |
| 665 | GenerateBindRenderTargetCmd(); |
| 666 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 667 | |
| 668 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 669 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 670 | |
| 671 | // render the cube |
| 672 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 673 | |
| 674 | // prepare the back buffer for present |
| 675 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 676 | // transitionToPresent.image = m_image; |
| 677 | // transitionToPresent.oldState = m_image_state; |
| 678 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 679 | // transitionToPresent.subresourceRange = srRange; |
| 680 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 681 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 682 | |
| 683 | // finalize recording of the command buffer |
| 684 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 685 | ASSERT_XGL_SUCCESS( err ); |
| 686 | |
| 687 | // this command buffer only uses the vertex buffer memory |
| 688 | m_numMemRefs = 0; |
| 689 | // m_memRefs[0].flags = 0; |
| 690 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 691 | |
| 692 | // submit the command buffer to the universal queue |
| 693 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 694 | ASSERT_XGL_SUCCESS( err ); |
| 695 | |
| 696 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 697 | ASSERT_XGL_SUCCESS( err ); |
| 698 | |
| 699 | // Wait for work to finish before cleaning up. |
| 700 | xglDeviceWaitIdle(m_device->device()); |
| 701 | |
| 702 | RecordImage(m_renderTarget); |
| 703 | |
| 704 | } |
| 705 | |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 706 | void XglRenderTest::DrawTexturedTriangle(const char *vertShaderText, const char *fragShaderText) |
| 707 | { |
| 708 | |
| 709 | // based on DrawTriangleTwoUniformsFS |
| 710 | |
| 711 | XGL_PIPELINE pipeline; |
| 712 | XGL_SHADER vs, ps; |
| 713 | XGL_RESULT err; |
| 714 | |
| 715 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 716 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 717 | |
| 718 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 719 | vertShaderText, &vs)); |
| 720 | |
| 721 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 722 | fragShaderText, &ps)); |
| 723 | |
| 724 | ASSERT_NO_FATAL_FAILURE(CreatePipelineSingleTextureAndSampler(&pipeline, vs, ps)); |
| 725 | |
| 726 | /* |
| 727 | * Shaders are now part of the pipeline, don't need these anymore |
| 728 | */ |
| 729 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 730 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 731 | |
| 732 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 733 | |
| 734 | |
| 735 | // Enable our single sampler |
| 736 | ASSERT_NO_FATAL_FAILURE(InitSampler()); |
| 737 | |
| 738 | // Enable our single texture |
| 739 | ASSERT_NO_FATAL_FAILURE(InitTexture()); |
| 740 | |
| 741 | // Create descriptor set for a texture and sampler resources |
Cody Northrop | 5fa1d33 | 2014-10-20 11:51:32 -0600 | [diff] [blame] | 742 | const int slotCount = 2; |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 743 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 744 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 745 | descriptorInfo.slots = slotCount; |
| 746 | |
| 747 | // create a descriptor set with a single slot |
| 748 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 749 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 750 | |
| 751 | // bind memory to the descriptor set |
| 752 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 753 | |
| 754 | // write the sampler and image views to the descriptor set |
| 755 | // ensure this matches order set in CreatePipelineSingleTextureAndSampler |
| 756 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 757 | xglAttachImageViewDescriptors( m_rsrcDescSet, 0, 1, &m_textureViewInfo[0] ); |
| 758 | xglAttachSamplerDescriptors(m_rsrcDescSet, 1, 1, &m_sampler[0]); |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 759 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 760 | |
| 761 | // Build command buffer |
| 762 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 763 | ASSERT_XGL_SUCCESS(err); |
| 764 | |
| 765 | GenerateClearAndPrepareBufferCmds(); |
| 766 | GenerateBindRenderTargetCmd(); |
| 767 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 768 | |
| 769 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 770 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 771 | |
| 772 | // render the cube |
| 773 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 774 | |
| 775 | // prepare the back buffer for present |
| 776 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 777 | // transitionToPresent.image = m_image; |
| 778 | // transitionToPresent.oldState = m_image_state; |
| 779 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 780 | // transitionToPresent.subresourceRange = srRange; |
| 781 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 782 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 783 | |
| 784 | // finalize recording of the command buffer |
| 785 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 786 | ASSERT_XGL_SUCCESS( err ); |
| 787 | |
| 788 | // this command buffer only uses the vertex buffer memory |
| 789 | m_numMemRefs = 0; |
| 790 | // m_memRefs[0].flags = 0; |
| 791 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 792 | |
| 793 | // submit the command buffer to the universal queue |
| 794 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 795 | ASSERT_XGL_SUCCESS( err ); |
| 796 | |
| 797 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 798 | ASSERT_XGL_SUCCESS( err ); |
| 799 | |
| 800 | // Wait for work to finish before cleaning up. |
| 801 | xglDeviceWaitIdle(m_device->device()); |
| 802 | |
| 803 | RecordImage(m_renderTarget); |
| 804 | |
| 805 | } |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 806 | |
| 807 | void XglRenderTest::DrawTriangleVSUniform(const char *vertShaderText, const char *fragShaderText) |
| 808 | { |
| 809 | XGL_PIPELINE pipeline; |
| 810 | XGL_SHADER vs, ps; |
| 811 | XGL_RESULT err; |
| 812 | glm::mat4 MVP; |
| 813 | int i; |
| 814 | |
| 815 | // Create identity matrix |
| 816 | glm::mat4 Model = glm::mat4(1.0f); |
| 817 | |
| 818 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 819 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 820 | |
| 821 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 822 | vertShaderText, &vs)); |
| 823 | |
| 824 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 825 | fragShaderText, &ps)); |
| 826 | |
| 827 | ASSERT_NO_FATAL_FAILURE(CreatePipelineVSUniform(&pipeline, vs, ps)); |
| 828 | |
| 829 | /* |
| 830 | * Shaders are now part of the pipeline, don't need these anymore |
| 831 | */ |
| 832 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 833 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 834 | |
| 835 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 836 | |
| 837 | const int matrixSize = 16; |
| 838 | MVP = Model; |
| 839 | |
| 840 | InitConstantBuffer(matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]); |
| 841 | |
| 842 | // Create descriptor set for a uniform resource |
| 843 | const int slotCount = 1; |
| 844 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 845 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 846 | descriptorInfo.slots = slotCount; |
| 847 | |
| 848 | // create a descriptor set with a single slot |
| 849 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 850 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 851 | |
| 852 | // bind memory to the descriptor set |
| 853 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 854 | |
| 855 | // write the constant buffer view to the descriptor set |
| 856 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 857 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 858 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 859 | |
| 860 | // Build command buffer |
| 861 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 862 | ASSERT_XGL_SUCCESS(err); |
| 863 | |
| 864 | GenerateClearAndPrepareBufferCmds(); |
| 865 | GenerateBindRenderTargetCmd(); |
| 866 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 867 | |
| 868 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 869 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 870 | |
| 871 | // render the cube |
| 872 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 873 | |
| 874 | // prepare the back buffer for present |
| 875 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 876 | // transitionToPresent.image = m_image; |
| 877 | // transitionToPresent.oldState = m_image_state; |
| 878 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 879 | // transitionToPresent.subresourceRange = srRange; |
| 880 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 881 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 882 | |
| 883 | // finalize recording of the command buffer |
| 884 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 885 | ASSERT_XGL_SUCCESS( err ); |
| 886 | |
| 887 | // this command buffer only uses the vertex buffer memory |
| 888 | m_numMemRefs = 0; |
| 889 | // m_memRefs[0].flags = 0; |
| 890 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 891 | |
| 892 | // submit the command buffer to the universal queue |
| 893 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 894 | ASSERT_XGL_SUCCESS( err ); |
| 895 | |
| 896 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 897 | ASSERT_XGL_SUCCESS( err ); |
| 898 | |
| 899 | // Wait for work to finish before cleaning up. |
| 900 | xglDeviceWaitIdle(m_device->device()); |
| 901 | |
| 902 | RecordImage(m_renderTarget); |
| 903 | |
| 904 | for (i = 0; i < 8; i++) { |
| 905 | XGL_UINT8 *pData; |
| 906 | err = xglMapMemory(m_constantBufferMem, 0, (XGL_VOID **) &pData); |
| 907 | ASSERT_XGL_SUCCESS(err); |
| 908 | |
| 909 | MVP = glm::rotate(MVP, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f)); |
| 910 | memcpy(pData, (const void*) &MVP[0][0], matrixSize); |
| 911 | |
| 912 | err = xglUnmapMemory(m_constantBufferMem); |
| 913 | ASSERT_XGL_SUCCESS(err); |
| 914 | |
| 915 | // submit the command buffer to the universal queue |
| 916 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 917 | ASSERT_XGL_SUCCESS( err ); |
| 918 | |
| 919 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 920 | ASSERT_XGL_SUCCESS( err ); |
| 921 | |
| 922 | // Wait for work to finish before cleaning up. |
| 923 | xglDeviceWaitIdle(m_device->device()); |
| 924 | |
| 925 | RecordImage(m_renderTarget); |
| 926 | } |
| 927 | } |
| 928 | |
Cody Northrop | 0fdf64e | 2014-10-20 11:51:06 -0600 | [diff] [blame] | 929 | void XglRenderTest::DrawTriangleVSUniformBlock(const char *vertShaderText, const char *fragShaderText) |
| 930 | { |
| 931 | // sourced from DrawTriangleVSUniform |
| 932 | XGL_PIPELINE pipeline; |
| 933 | XGL_SHADER vs, ps; |
| 934 | XGL_RESULT err; |
| 935 | |
| 936 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 937 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 938 | |
| 939 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 940 | vertShaderText, &vs)); |
| 941 | |
| 942 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 943 | fragShaderText, &ps)); |
| 944 | |
| 945 | ASSERT_NO_FATAL_FAILURE(CreatePipelineVSUniform(&pipeline, vs, ps)); |
| 946 | |
| 947 | /* |
| 948 | * Shaders are now part of the pipeline, don't need these anymore |
| 949 | */ |
| 950 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 951 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 952 | |
| 953 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 954 | |
| 955 | // Let's populate our buffer with the following: |
| 956 | // vec4 red; |
| 957 | // vec4 green; |
| 958 | // vec4 blue; |
| 959 | // vec4 white; |
| 960 | const int valCount = 4 * 4; |
| 961 | const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0, |
| 962 | 0.0, 1.0, 0.0, 1.0, |
| 963 | 0.0, 0.0, 1.0, 1.0, |
| 964 | 1.0, 1.0, 1.0, 1.0 }; |
| 965 | |
| 966 | InitConstantBuffer(valCount, sizeof(bufferVals[0]), (const void*) bufferVals); |
| 967 | |
| 968 | // Create descriptor set for a uniform resource |
| 969 | const int slotCount = 1; |
| 970 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 971 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 972 | descriptorInfo.slots = slotCount; |
| 973 | |
| 974 | // create a descriptor set with a single slot |
| 975 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 976 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 977 | |
| 978 | // bind memory to the descriptor set |
| 979 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 980 | |
| 981 | // write the constant buffer view to the descriptor set |
| 982 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 983 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 984 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 985 | |
| 986 | // Build command buffer |
| 987 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 988 | ASSERT_XGL_SUCCESS(err); |
| 989 | |
| 990 | GenerateClearAndPrepareBufferCmds(); |
| 991 | GenerateBindRenderTargetCmd(); |
| 992 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 993 | |
| 994 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 995 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 996 | |
| 997 | // render the cube |
| 998 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 999 | |
| 1000 | // prepare the back buffer for present |
| 1001 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 1002 | // transitionToPresent.image = m_image; |
| 1003 | // transitionToPresent.oldState = m_image_state; |
| 1004 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 1005 | // transitionToPresent.subresourceRange = srRange; |
| 1006 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 1007 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 1008 | |
| 1009 | // finalize recording of the command buffer |
| 1010 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 1011 | ASSERT_XGL_SUCCESS( err ); |
| 1012 | |
| 1013 | // this command buffer only uses the vertex buffer memory |
| 1014 | m_numMemRefs = 0; |
| 1015 | // m_memRefs[0].flags = 0; |
| 1016 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 1017 | |
| 1018 | // submit the command buffer to the universal queue |
| 1019 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 1020 | ASSERT_XGL_SUCCESS( err ); |
| 1021 | |
| 1022 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 1023 | ASSERT_XGL_SUCCESS( err ); |
| 1024 | |
| 1025 | // Wait for work to finish before cleaning up. |
| 1026 | xglDeviceWaitIdle(m_device->device()); |
| 1027 | |
| 1028 | RecordImage(m_renderTarget); |
| 1029 | } |
| 1030 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 1031 | void XglRenderTest::CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps) |
| 1032 | { |
| 1033 | XGL_RESULT err; |
| 1034 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1035 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 1036 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
| 1037 | |
| 1038 | |
| 1039 | // Create descriptor set for our one resource |
| 1040 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 1041 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1042 | descriptorInfo.slots = 1; // Vertex buffer only |
| 1043 | |
| 1044 | // create a descriptor set with a single slot |
| 1045 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 1046 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1047 | |
| 1048 | // bind memory to the descriptor set |
| 1049 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1050 | |
| 1051 | // write the vertex buffer view to the descriptor set |
| 1052 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 1053 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView ); |
| 1054 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 1055 | |
| 1056 | const int slots = 1; |
| 1057 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( slots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 1058 | slotInfo[0].shaderEntityIndex = 0; |
| 1059 | slotInfo[0].slotObjectType = XGL_SLOT_VERTEX_INPUT; |
| 1060 | |
| 1061 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1062 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 1063 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
| 1064 | vs_stage.shader.shader = vs; |
| 1065 | vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 1066 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = slots; |
| 1067 | vs_stage.shader.linkConstBufferCount = 0; |
| 1068 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1069 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1070 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1071 | |
| 1072 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1073 | ps_stage.pNext = &vs_stage; |
| 1074 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 1075 | ps_stage.shader.shader = ps; |
| 1076 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
| 1077 | ps_stage.shader.linkConstBufferCount = 0; |
| 1078 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1079 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1080 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1081 | |
| 1082 | XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = { |
| 1083 | sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement) |
| 1084 | XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented |
| 1085 | }; |
| 1086 | |
| 1087 | // this is the current description of g_vbData |
| 1088 | XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2]; |
| 1089 | vi_attribs[0].binding = 0; // index into vertexBindingDescriptions |
| 1090 | vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1091 | vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1092 | vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex |
| 1093 | vi_attribs[1].binding = 0; // index into vertexBindingDescriptions |
| 1094 | vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data |
| 1095 | vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 1096 | vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex |
| 1097 | |
| 1098 | XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO vi_state = { |
| 1099 | XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO, // sType; |
| 1100 | &ps_stage, // pNext; |
| 1101 | 1, // bindingCount |
| 1102 | &vi_binding, // pVertexBindingDescriptions; |
| 1103 | 2, // attributeCount; // number of attributes |
| 1104 | vi_attribs // pVertexAttributeDescriptions; |
| 1105 | }; |
| 1106 | |
| 1107 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 1108 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 1109 | &vi_state, // pNext |
| 1110 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 1111 | XGL_FALSE, // disableVertexReuse |
| 1112 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 1113 | XGL_FALSE, // primitiveRestartEnable |
| 1114 | 0 // primitiveRestartIndex |
| 1115 | }; |
| 1116 | |
| 1117 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 1118 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 1119 | &ia_state, |
| 1120 | XGL_FALSE, // depthClipEnable |
| 1121 | XGL_FALSE, // rasterizerDiscardEnable |
| 1122 | 1.0 // pointSize |
| 1123 | }; |
| 1124 | |
| 1125 | XGL_PIPELINE_CB_STATE cb_state = { |
| 1126 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 1127 | &rs_state, |
| 1128 | XGL_FALSE, // alphaToCoverageEnable |
| 1129 | XGL_FALSE, // dualSourceBlendEnable |
| 1130 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 1131 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 1132 | { |
| 1133 | XGL_FALSE, // blendEnable |
| 1134 | m_render_target_fmt, // XGL_FORMAT |
| 1135 | 0xF // channelWriteMask |
| 1136 | } |
| 1137 | } |
| 1138 | }; |
| 1139 | |
| 1140 | // TODO: Should take depth buffer format from queried formats |
| 1141 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 1142 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 1143 | &cb_state, |
| 1144 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 1145 | }; |
| 1146 | |
| 1147 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1148 | info.pNext = &db_state; |
| 1149 | info.flags = 0; |
| 1150 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
| 1151 | ASSERT_XGL_SUCCESS(err); |
| 1152 | |
| 1153 | err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem); |
| 1154 | ASSERT_XGL_SUCCESS(err); |
| 1155 | } |
| 1156 | |
| 1157 | void XglRenderTest::CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps) |
| 1158 | { |
| 1159 | XGL_RESULT err; |
| 1160 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1161 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 1162 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
| 1163 | |
| 1164 | |
| 1165 | const int vsSlots = 1; // Uniform buffer only |
| 1166 | |
| 1167 | // Create descriptor set for our one resource |
| 1168 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 1169 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1170 | descriptorInfo.slots = vsSlots; |
| 1171 | |
| 1172 | // create a descriptor set with a single slot |
| 1173 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 1174 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1175 | |
| 1176 | // bind memory to the descriptor set |
| 1177 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1178 | |
| 1179 | |
| 1180 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 1181 | slotInfo[0].shaderEntityIndex = 0; |
| 1182 | slotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; |
| 1183 | |
| 1184 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1185 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 1186 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
| 1187 | vs_stage.shader.shader = vs; |
| 1188 | vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 1189 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots; |
| 1190 | vs_stage.shader.linkConstBufferCount = 0; |
| 1191 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1192 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1193 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1194 | |
| 1195 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1196 | ps_stage.pNext = &vs_stage; |
| 1197 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 1198 | ps_stage.shader.shader = ps; |
| 1199 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
| 1200 | ps_stage.shader.linkConstBufferCount = 0; |
| 1201 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1202 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1203 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1204 | |
| 1205 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 1206 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 1207 | &ps_stage, // pNext |
| 1208 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 1209 | XGL_FALSE, // disableVertexReuse |
| 1210 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 1211 | XGL_FALSE, // primitiveRestartEnable |
| 1212 | 0 // primitiveRestartIndex |
| 1213 | }; |
| 1214 | |
| 1215 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 1216 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 1217 | &ia_state, |
| 1218 | XGL_FALSE, // depthClipEnable |
| 1219 | XGL_FALSE, // rasterizerDiscardEnable |
| 1220 | 1.0 // pointSize |
| 1221 | }; |
| 1222 | |
| 1223 | XGL_PIPELINE_CB_STATE cb_state = { |
| 1224 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 1225 | &rs_state, |
| 1226 | XGL_FALSE, // alphaToCoverageEnable |
| 1227 | XGL_FALSE, // dualSourceBlendEnable |
| 1228 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 1229 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 1230 | { |
| 1231 | XGL_FALSE, // blendEnable |
| 1232 | m_render_target_fmt, // XGL_FORMAT |
| 1233 | 0xF // channelWriteMask |
| 1234 | } |
| 1235 | } |
| 1236 | }; |
| 1237 | |
| 1238 | // TODO: Should take depth buffer format from queried formats |
| 1239 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 1240 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 1241 | &cb_state, |
| 1242 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 1243 | }; |
| 1244 | |
| 1245 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1246 | info.pNext = &db_state; |
| 1247 | info.flags = 0; |
| 1248 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
| 1249 | ASSERT_XGL_SUCCESS(err); |
| 1250 | |
| 1251 | err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem); |
| 1252 | ASSERT_XGL_SUCCESS(err); |
| 1253 | } |
| 1254 | |
Cody Northrop | ec1d3c3 | 2014-10-28 15:41:42 -0600 | [diff] [blame] | 1255 | void XglRenderTest::CreatePipelineFSUniformBlockBinding(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps, const int bufferCount) |
| 1256 | { |
| 1257 | // based on CreateDefaultPipeline |
| 1258 | // only difference is number of constant buffers |
| 1259 | |
| 1260 | XGL_RESULT err; |
| 1261 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1262 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 1263 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
| 1264 | |
| 1265 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1266 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 1267 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
| 1268 | vs_stage.shader.shader = vs; |
| 1269 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
| 1270 | vs_stage.shader.linkConstBufferCount = 0; |
| 1271 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1272 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1273 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1274 | |
| 1275 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1276 | ps_stage.pNext = &vs_stage; |
| 1277 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 1278 | ps_stage.shader.shader = ps; |
| 1279 | |
| 1280 | // const int slots = 4; |
| 1281 | // assert (slots == bufferCount); // update as needed |
| 1282 | |
| 1283 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( bufferCount * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 1284 | for (int i = 0; i < bufferCount; ++i) { |
| 1285 | // Note: These are all constant buffers |
| 1286 | slotInfo[i].shaderEntityIndex = i; |
| 1287 | slotInfo[i].slotObjectType = XGL_SLOT_SHADER_RESOURCE; |
| 1288 | } |
| 1289 | |
| 1290 | ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 1291 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = bufferCount; |
| 1292 | |
| 1293 | ps_stage.shader.linkConstBufferCount = 0; |
| 1294 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1295 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1296 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1297 | |
| 1298 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 1299 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 1300 | &ps_stage, // pNext |
| 1301 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 1302 | XGL_FALSE, // disableVertexReuse |
| 1303 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 1304 | XGL_FALSE, // primitiveRestartEnable |
| 1305 | 0 // primitiveRestartIndex |
| 1306 | }; |
| 1307 | |
| 1308 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 1309 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 1310 | &ia_state, |
| 1311 | XGL_FALSE, // depthClipEnable |
| 1312 | XGL_FALSE, // rasterizerDiscardEnable |
| 1313 | 1.0 // pointSize |
| 1314 | }; |
| 1315 | |
| 1316 | XGL_PIPELINE_CB_STATE cb_state = { |
| 1317 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 1318 | &rs_state, |
| 1319 | XGL_FALSE, // alphaToCoverageEnable |
| 1320 | XGL_FALSE, // dualSourceBlendEnable |
| 1321 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 1322 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 1323 | { |
| 1324 | XGL_FALSE, // blendEnable |
| 1325 | m_render_target_fmt, // XGL_FORMAT |
| 1326 | 0xF // channelWriteMask |
| 1327 | } |
| 1328 | } |
| 1329 | }; |
| 1330 | |
| 1331 | // TODO: Should take depth buffer format from queried formats |
| 1332 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 1333 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 1334 | &cb_state, |
| 1335 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 1336 | }; |
| 1337 | |
| 1338 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1339 | info.pNext = &db_state; |
| 1340 | info.flags = 0; |
| 1341 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
| 1342 | ASSERT_XGL_SUCCESS(err); |
| 1343 | |
| 1344 | err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem); |
| 1345 | ASSERT_XGL_SUCCESS(err); |
| 1346 | } |
| 1347 | |
Cody Northrop | 0fdf64e | 2014-10-20 11:51:06 -0600 | [diff] [blame] | 1348 | void XglRenderTest::CreatePipelineVSFSUniformBlock(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps) |
| 1349 | { |
| 1350 | // this is based on CreatePipelineVSUniform |
| 1351 | |
| 1352 | XGL_RESULT err; |
| 1353 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1354 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 1355 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
| 1356 | |
| 1357 | |
| 1358 | const int slots = 1; // Uniform buffer only |
| 1359 | |
| 1360 | // Create descriptor set for our one resource |
| 1361 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 1362 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1363 | descriptorInfo.slots = slots; |
| 1364 | |
| 1365 | // create a descriptor set with a single slot |
| 1366 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 1367 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1368 | |
| 1369 | // bind memory to the descriptor set |
| 1370 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1371 | |
| 1372 | |
| 1373 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( slots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 1374 | slotInfo[0].shaderEntityIndex = 0; |
| 1375 | slotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; |
| 1376 | |
| 1377 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1378 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 1379 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
| 1380 | vs_stage.shader.shader = vs; |
| 1381 | vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 1382 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = slots; |
| 1383 | vs_stage.shader.linkConstBufferCount = 0; |
| 1384 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1385 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1386 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1387 | |
| 1388 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1389 | ps_stage.pNext = &vs_stage; |
| 1390 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 1391 | ps_stage.shader.shader = ps; |
| 1392 | ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 1393 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = slots; |
| 1394 | ps_stage.shader.linkConstBufferCount = 0; |
| 1395 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1396 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1397 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1398 | |
| 1399 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 1400 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 1401 | &ps_stage, // pNext |
| 1402 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 1403 | XGL_FALSE, // disableVertexReuse |
| 1404 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 1405 | XGL_FALSE, // primitiveRestartEnable |
| 1406 | 0 // primitiveRestartIndex |
| 1407 | }; |
| 1408 | |
| 1409 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 1410 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 1411 | &ia_state, |
| 1412 | XGL_FALSE, // depthClipEnable |
| 1413 | XGL_FALSE, // rasterizerDiscardEnable |
| 1414 | 1.0 // pointSize |
| 1415 | }; |
| 1416 | |
| 1417 | XGL_PIPELINE_CB_STATE cb_state = { |
| 1418 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 1419 | &rs_state, |
| 1420 | XGL_FALSE, // alphaToCoverageEnable |
| 1421 | XGL_FALSE, // dualSourceBlendEnable |
| 1422 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 1423 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 1424 | { |
| 1425 | XGL_FALSE, // blendEnable |
| 1426 | m_render_target_fmt, // XGL_FORMAT |
| 1427 | 0xF // channelWriteMask |
| 1428 | } |
| 1429 | } |
| 1430 | }; |
| 1431 | |
| 1432 | // TODO: Should take depth buffer format from queried formats |
| 1433 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 1434 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 1435 | &cb_state, |
| 1436 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 1437 | }; |
| 1438 | |
| 1439 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1440 | info.pNext = &db_state; |
| 1441 | info.flags = 0; |
| 1442 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
| 1443 | ASSERT_XGL_SUCCESS(err); |
| 1444 | |
| 1445 | err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem); |
| 1446 | ASSERT_XGL_SUCCESS(err); |
| 1447 | } |
| 1448 | |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 1449 | void XglRenderTest::CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps) |
| 1450 | { |
| 1451 | // based on CreatePipelineVSUniform |
| 1452 | |
| 1453 | XGL_RESULT err; |
| 1454 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1455 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 1456 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
| 1457 | |
Cody Northrop | 9394e0c | 2014-10-23 10:21:47 -0600 | [diff] [blame] | 1458 | const int vsSlots = 2; // One texture, one sampler |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 1459 | |
| 1460 | // Create descriptor set for single texture and sampler |
Cody Northrop | 9394e0c | 2014-10-23 10:21:47 -0600 | [diff] [blame] | 1461 | XGL_DESCRIPTOR_SET_CREATE_INFO vsDescriptorInfo = {}; |
| 1462 | vsDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1463 | vsDescriptorInfo.slots = vsSlots; |
| 1464 | err = xglCreateDescriptorSet( device(), &vsDescriptorInfo, &m_rsrcDescSet ); |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 1465 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1466 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1467 | |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 1468 | // 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] | 1469 | XGL_DESCRIPTOR_SLOT_INFO *vsSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 1470 | vsSlotInfo[0].shaderEntityIndex = 0; |
| 1471 | vsSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; |
| 1472 | vsSlotInfo[1].shaderEntityIndex = 0; |
| 1473 | vsSlotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER; |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 1474 | |
| 1475 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1476 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 1477 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
| 1478 | vs_stage.shader.shader = vs; |
Cody Northrop | 9394e0c | 2014-10-23 10:21:47 -0600 | [diff] [blame] | 1479 | vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) vsSlotInfo; |
| 1480 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots; |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 1481 | vs_stage.shader.linkConstBufferCount = 0; |
| 1482 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1483 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1484 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1485 | |
Cody Northrop | 9394e0c | 2014-10-23 10:21:47 -0600 | [diff] [blame] | 1486 | const int psSlots = 2; // One texture, one sampler |
| 1487 | |
| 1488 | // Create descriptor set for single texture and sampler |
| 1489 | XGL_DESCRIPTOR_SET_CREATE_INFO psDescriptorInfo = {}; |
| 1490 | psDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1491 | psDescriptorInfo.slots = psSlots; |
| 1492 | err = xglCreateDescriptorSet( device(), &psDescriptorInfo, &m_rsrcDescSet ); |
| 1493 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1494 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1495 | |
| 1496 | // Assign the slots, note that only t0 and s0 will work as of writing this test |
| 1497 | XGL_DESCRIPTOR_SLOT_INFO *psSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 1498 | psSlotInfo[0].shaderEntityIndex = 0; |
| 1499 | psSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; |
| 1500 | psSlotInfo[1].shaderEntityIndex = 0; |
| 1501 | psSlotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER; |
| 1502 | |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 1503 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1504 | ps_stage.pNext = &vs_stage; |
| 1505 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 1506 | ps_stage.shader.shader = ps; |
Cody Northrop | 9394e0c | 2014-10-23 10:21:47 -0600 | [diff] [blame] | 1507 | ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) psSlotInfo; |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 1508 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = psSlots; |
| 1509 | ps_stage.shader.linkConstBufferCount = 0; |
| 1510 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1511 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1512 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1513 | |
| 1514 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 1515 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 1516 | &ps_stage, // pNext |
| 1517 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 1518 | XGL_FALSE, // disableVertexReuse |
| 1519 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 1520 | XGL_FALSE, // primitiveRestartEnable |
| 1521 | 0 // primitiveRestartIndex |
| 1522 | }; |
| 1523 | |
| 1524 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 1525 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 1526 | &ia_state, |
| 1527 | XGL_FALSE, // depthClipEnable |
| 1528 | XGL_FALSE, // rasterizerDiscardEnable |
| 1529 | 1.0 // pointSize |
| 1530 | }; |
| 1531 | |
| 1532 | XGL_PIPELINE_CB_STATE cb_state = { |
| 1533 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 1534 | &rs_state, |
| 1535 | XGL_FALSE, // alphaToCoverageEnable |
| 1536 | XGL_FALSE, // dualSourceBlendEnable |
| 1537 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 1538 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 1539 | { |
| 1540 | XGL_FALSE, // blendEnable |
| 1541 | m_render_target_fmt, // XGL_FORMAT |
| 1542 | 0xF // channelWriteMask |
| 1543 | } |
| 1544 | } |
| 1545 | }; |
| 1546 | |
| 1547 | // TODO: Should take depth buffer format from queried formats |
| 1548 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 1549 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 1550 | &cb_state, |
| 1551 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 1552 | }; |
| 1553 | |
| 1554 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1555 | info.pNext = &db_state; |
| 1556 | info.flags = 0; |
| 1557 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
| 1558 | ASSERT_XGL_SUCCESS(err); |
| 1559 | |
| 1560 | err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem); |
| 1561 | ASSERT_XGL_SUCCESS(err); |
| 1562 | } |
| 1563 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 1564 | void XglRenderTest::CreatePipelineMultipleTexturesAndSamplers(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps, |
| 1565 | int textureCount, int samplerCount) |
| 1566 | { |
| 1567 | // based on CreatePipelineSingleTextureAndSampler |
| 1568 | |
| 1569 | XGL_RESULT err; |
| 1570 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1571 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 1572 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
| 1573 | |
| 1574 | const int psSlots = textureCount + samplerCount; |
| 1575 | |
| 1576 | // Create descriptor set for single texture and sampler |
| 1577 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 1578 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1579 | descriptorInfo.slots = psSlots; |
| 1580 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 1581 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1582 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1583 | |
| 1584 | // Assign the slots, note that only t0 and s0 will work as of writing this test |
| 1585 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 1586 | int slotIndex = 0; |
| 1587 | for (int i = 0; i < textureCount; ++i) { |
| 1588 | slotInfo[slotIndex].shaderEntityIndex = i; |
| 1589 | slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_RESOURCE; |
| 1590 | } |
| 1591 | for (int i = 0; i < samplerCount; ++i) { |
| 1592 | slotInfo[slotIndex].shaderEntityIndex = i; |
| 1593 | slotInfo[slotIndex++].slotObjectType = XGL_SLOT_SHADER_SAMPLER; |
| 1594 | } |
| 1595 | |
| 1596 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1597 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 1598 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
| 1599 | vs_stage.shader.shader = vs; |
| 1600 | vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0; |
| 1601 | vs_stage.shader.linkConstBufferCount = 0; |
| 1602 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1603 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1604 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1605 | |
| 1606 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1607 | ps_stage.pNext = &vs_stage; |
| 1608 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 1609 | ps_stage.shader.shader = ps; |
| 1610 | ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 1611 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = psSlots; |
| 1612 | ps_stage.shader.linkConstBufferCount = 0; |
| 1613 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
| 1614 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
| 1615 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 1616 | |
| 1617 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 1618 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 1619 | &ps_stage, // pNext |
| 1620 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 1621 | XGL_FALSE, // disableVertexReuse |
| 1622 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 1623 | XGL_FALSE, // primitiveRestartEnable |
| 1624 | 0 // primitiveRestartIndex |
| 1625 | }; |
| 1626 | |
| 1627 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 1628 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 1629 | &ia_state, |
| 1630 | XGL_FALSE, // depthClipEnable |
| 1631 | XGL_FALSE, // rasterizerDiscardEnable |
| 1632 | 1.0 // pointSize |
| 1633 | }; |
| 1634 | |
| 1635 | XGL_PIPELINE_CB_STATE cb_state = { |
| 1636 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 1637 | &rs_state, |
| 1638 | XGL_FALSE, // alphaToCoverageEnable |
| 1639 | XGL_FALSE, // dualSourceBlendEnable |
| 1640 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 1641 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 1642 | { |
| 1643 | XGL_FALSE, // blendEnable |
| 1644 | m_render_target_fmt, // XGL_FORMAT |
| 1645 | 0xF // channelWriteMask |
| 1646 | } |
| 1647 | } |
| 1648 | }; |
| 1649 | |
| 1650 | // TODO: Should take depth buffer format from queried formats |
| 1651 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 1652 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 1653 | &cb_state, |
| 1654 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 1655 | }; |
| 1656 | |
| 1657 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1658 | info.pNext = &db_state; |
| 1659 | info.flags = 0; |
| 1660 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
| 1661 | ASSERT_XGL_SUCCESS(err); |
| 1662 | |
| 1663 | err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem); |
| 1664 | ASSERT_XGL_SUCCESS(err); |
| 1665 | } |
| 1666 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 1667 | void XglRenderTest::DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText) |
| 1668 | { |
| 1669 | XGL_PIPELINE pipeline; |
| 1670 | XGL_SHADER vs, ps; |
| 1671 | XGL_RESULT err; |
| 1672 | |
| 1673 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1674 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1675 | ASSERT_NO_FATAL_FAILURE(InitMesh(sizeof(g_vbData)/sizeof(g_vbData[0]), sizeof(g_vbData[0]), g_vbData)); |
| 1676 | |
| 1677 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 1678 | vertShaderText, &vs)); |
| 1679 | |
| 1680 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 1681 | fragShaderText, &ps)); |
| 1682 | |
| 1683 | ASSERT_NO_FATAL_FAILURE(CreatePipelineWithVertexFetch(&pipeline, vs, ps)); |
| 1684 | |
| 1685 | /* |
| 1686 | * Shaders are now part of the pipeline, don't need these anymore |
| 1687 | */ |
| 1688 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 1689 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 1690 | |
| 1691 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1692 | |
| 1693 | // Build command buffer |
| 1694 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 1695 | ASSERT_XGL_SUCCESS(err); |
| 1696 | |
| 1697 | GenerateClearAndPrepareBufferCmds(); |
| 1698 | GenerateBindRenderTargetCmd(); |
| 1699 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 1700 | |
| 1701 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 1702 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 1703 | |
| 1704 | // render the cube |
| 1705 | xglCmdDraw( m_cmdBuffer, 0, 6, 0, 1 ); |
| 1706 | |
| 1707 | // prepare the back buffer for present |
| 1708 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 1709 | // transitionToPresent.image = m_image; |
| 1710 | // transitionToPresent.oldState = m_image_state; |
| 1711 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 1712 | // transitionToPresent.subresourceRange = srRange; |
| 1713 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 1714 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 1715 | |
| 1716 | // finalize recording of the command buffer |
| 1717 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 1718 | ASSERT_XGL_SUCCESS( err ); |
| 1719 | |
| 1720 | // this command buffer only uses the vertex buffer memory |
| 1721 | m_numMemRefs = 0; |
| 1722 | // m_memRefs[0].flags = 0; |
| 1723 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 1724 | |
| 1725 | // submit the command buffer to the universal queue |
| 1726 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 1727 | ASSERT_XGL_SUCCESS( err ); |
| 1728 | |
| 1729 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 1730 | ASSERT_XGL_SUCCESS( err ); |
| 1731 | |
| 1732 | // Wait for work to finish before cleaning up. |
| 1733 | xglDeviceWaitIdle(m_device->device()); |
| 1734 | |
| 1735 | RecordImage(m_renderTarget); |
| 1736 | |
| 1737 | } |
| 1738 | |
Cody Northrop | 0fdf64e | 2014-10-20 11:51:06 -0600 | [diff] [blame] | 1739 | void XglRenderTest::DrawTriangleFSUniformBlock(const char *vertShaderText, const char *fragShaderText) |
| 1740 | { |
| 1741 | // probably sourced from DrawTriangleTwoUniformsFS |
| 1742 | |
| 1743 | XGL_PIPELINE pipeline; |
| 1744 | XGL_SHADER vs, ps; |
| 1745 | XGL_RESULT err; |
| 1746 | |
| 1747 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1748 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1749 | |
| 1750 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 1751 | vertShaderText, &vs)); |
| 1752 | |
| 1753 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 1754 | fragShaderText, &ps)); |
| 1755 | |
| 1756 | ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, vs, ps)); |
| 1757 | |
| 1758 | /* |
| 1759 | * Shaders are now part of the pipeline, don't need these anymore |
| 1760 | */ |
| 1761 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 1762 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 1763 | |
| 1764 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1765 | |
| 1766 | |
| 1767 | // Let's populate our buffer with the following: |
| 1768 | // vec4 red; |
| 1769 | // vec4 green; |
| 1770 | // vec4 blue; |
| 1771 | // vec4 white; |
| 1772 | const int valCount = 4 * 4; |
| 1773 | const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0, |
| 1774 | 0.0, 1.0, 0.0, 1.0, |
| 1775 | 0.0, 0.0, 1.0, 1.0, |
| 1776 | 1.0, 1.0, 1.0, 1.0 }; |
| 1777 | |
| 1778 | InitConstantBuffer(valCount, sizeof(bufferVals[0]), (const void*) bufferVals); |
| 1779 | |
| 1780 | // Create descriptor set for a uniform resource |
| 1781 | const int slotCount = 1; |
| 1782 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 1783 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1784 | descriptorInfo.slots = slotCount; |
| 1785 | |
| 1786 | // create a descriptor set with a single slot |
| 1787 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 1788 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1789 | |
| 1790 | // bind memory to the descriptor set |
| 1791 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1792 | |
| 1793 | // write the constant buffer view to the descriptor set |
| 1794 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 1795 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 1796 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 1797 | |
| 1798 | // Build command buffer |
| 1799 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 1800 | ASSERT_XGL_SUCCESS(err); |
| 1801 | |
| 1802 | GenerateClearAndPrepareBufferCmds(); |
| 1803 | GenerateBindRenderTargetCmd(); |
| 1804 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 1805 | |
| 1806 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 1807 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 1808 | |
| 1809 | // render the cube |
| 1810 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 1811 | |
| 1812 | // prepare the back buffer for present |
| 1813 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 1814 | // transitionToPresent.image = m_image; |
| 1815 | // transitionToPresent.oldState = m_image_state; |
| 1816 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 1817 | // transitionToPresent.subresourceRange = srRange; |
| 1818 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 1819 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 1820 | |
| 1821 | // finalize recording of the command buffer |
| 1822 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 1823 | ASSERT_XGL_SUCCESS( err ); |
| 1824 | |
| 1825 | // this command buffer only uses the vertex buffer memory |
| 1826 | m_numMemRefs = 0; |
| 1827 | // m_memRefs[0].flags = 0; |
| 1828 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 1829 | |
| 1830 | // submit the command buffer to the universal queue |
| 1831 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 1832 | ASSERT_XGL_SUCCESS( err ); |
| 1833 | |
| 1834 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 1835 | ASSERT_XGL_SUCCESS( err ); |
| 1836 | |
| 1837 | // Wait for work to finish before cleaning up. |
| 1838 | xglDeviceWaitIdle(m_device->device()); |
| 1839 | |
| 1840 | RecordImage(m_renderTarget); |
| 1841 | |
| 1842 | } |
| 1843 | |
Cody Northrop | ec1d3c3 | 2014-10-28 15:41:42 -0600 | [diff] [blame] | 1844 | void XglRenderTest::DrawTriangleFSUniformBlockBinding(const char *vertShaderText, const char *fragShaderText) |
| 1845 | { |
| 1846 | // sourced from DrawTriangleFSUniformBlock |
| 1847 | |
| 1848 | XGL_PIPELINE pipeline; |
| 1849 | XGL_SHADER vs, ps; |
| 1850 | XGL_RESULT err; |
| 1851 | |
| 1852 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1853 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1854 | |
| 1855 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 1856 | vertShaderText, &vs)); |
| 1857 | |
| 1858 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 1859 | fragShaderText, &ps)); |
| 1860 | |
| 1861 | const int bufferCount = 4; |
| 1862 | ASSERT_NO_FATAL_FAILURE(CreatePipelineFSUniformBlockBinding(&pipeline, vs, ps, bufferCount)); |
| 1863 | |
| 1864 | /* |
| 1865 | * Shaders are now part of the pipeline, don't need these anymore |
| 1866 | */ |
| 1867 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 1868 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 1869 | |
| 1870 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1871 | |
| 1872 | |
| 1873 | // We're going to create a number of uniform buffers, and then allow |
| 1874 | // the shader to select which it wants to read from with a binding |
| 1875 | |
| 1876 | // Let's populate the buffers with a single color each: |
| 1877 | // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal; |
| 1878 | // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal; |
| 1879 | // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal; |
| 1880 | // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal; |
| 1881 | |
| 1882 | assert(4 == bufferCount); // update the following code if you want more than 4 |
| 1883 | |
| 1884 | const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 }; |
| 1885 | const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 }; |
| 1886 | const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 }; |
| 1887 | const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 1888 | |
| 1889 | const int redCount = sizeof(redVals) / sizeof(float); |
| 1890 | const int greenCount = sizeof(greenVals) / sizeof(float); |
| 1891 | const int blueCount = sizeof(blueVals) / sizeof(float); |
| 1892 | const int whiteCount = sizeof(whiteVals) / sizeof(float); |
| 1893 | |
| 1894 | int index = 0; |
| 1895 | InitUniformBuffer(redCount, sizeof(redVals[0]), index++, (const void *) redVals); |
| 1896 | InitUniformBuffer(greenCount, sizeof(greenVals[0]), index++, (const void *) greenVals); |
| 1897 | InitUniformBuffer(blueCount, sizeof(blueVals[0]), index++, (const void *) blueVals); |
| 1898 | InitUniformBuffer(whiteCount, sizeof(whiteVals[0]), index++, (const void *) whiteVals); |
| 1899 | |
| 1900 | |
| 1901 | // Create descriptor set for a uniform resource |
| 1902 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 1903 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 1904 | descriptorInfo.slots = bufferCount; |
| 1905 | |
| 1906 | // create a descriptor set with a single slot |
| 1907 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 1908 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 1909 | |
| 1910 | // bind memory to the descriptor set |
| 1911 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 1912 | |
| 1913 | // write the constant buffer view to the descriptor set |
| 1914 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 1915 | |
| 1916 | for(int i = 0; i < bufferCount; ++i) |
| 1917 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, i, 1, &m_uniformBufferView[i] ); |
| 1918 | |
| 1919 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 1920 | |
| 1921 | // Build command buffer |
| 1922 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 1923 | ASSERT_XGL_SUCCESS(err); |
| 1924 | |
| 1925 | GenerateClearAndPrepareBufferCmds(); |
| 1926 | GenerateBindRenderTargetCmd(); |
| 1927 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 1928 | |
| 1929 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 1930 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 1931 | |
| 1932 | // render the cube |
| 1933 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 1934 | |
| 1935 | // prepare the back buffer for present |
| 1936 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 1937 | // transitionToPresent.image = m_image; |
| 1938 | // transitionToPresent.oldState = m_image_state; |
| 1939 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 1940 | // transitionToPresent.subresourceRange = srRange; |
| 1941 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 1942 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 1943 | |
| 1944 | // finalize recording of the command buffer |
| 1945 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 1946 | ASSERT_XGL_SUCCESS( err ); |
| 1947 | |
| 1948 | // this command buffer only uses the vertex buffer memory |
| 1949 | m_numMemRefs = 0; |
| 1950 | // m_memRefs[0].flags = 0; |
| 1951 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 1952 | |
| 1953 | // submit the command buffer to the universal queue |
| 1954 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 1955 | ASSERT_XGL_SUCCESS( err ); |
| 1956 | |
| 1957 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 1958 | ASSERT_XGL_SUCCESS( err ); |
| 1959 | |
| 1960 | // Wait for work to finish before cleaning up. |
| 1961 | xglDeviceWaitIdle(m_device->device()); |
| 1962 | |
| 1963 | RecordImage(m_renderTarget); |
| 1964 | |
| 1965 | } |
| 1966 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 1967 | void XglRenderTest::DrawSamplerBindingsTriangle(const char *vertShaderText, const char *fragShaderText, |
| 1968 | int textureCount, int samplerCount) |
| 1969 | { |
| 1970 | // based on DrawTexturedTriangle |
| 1971 | |
| 1972 | XGL_PIPELINE pipeline; |
| 1973 | XGL_SHADER vs, ps; |
| 1974 | XGL_RESULT err; |
| 1975 | |
| 1976 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1977 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1978 | |
| 1979 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 1980 | vertShaderText, &vs)); |
| 1981 | |
| 1982 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 1983 | fragShaderText, &ps)); |
| 1984 | |
| 1985 | ASSERT_NO_FATAL_FAILURE(CreatePipelineMultipleTexturesAndSamplers(&pipeline, vs, ps, textureCount, samplerCount)); |
| 1986 | |
| 1987 | /* |
| 1988 | * Shaders are now part of the pipeline, don't need these anymore |
| 1989 | */ |
| 1990 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 1991 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 1992 | |
| 1993 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1994 | |
| 1995 | |
| 1996 | // Create a few texture/sampler pairs |
| 1997 | int textureColors[16]; |
| 1998 | assert(textureCount < 16); |
| 1999 | textureColors[0] = 0xFF0000FF; //red |
| 2000 | textureColors[1] = 0xFF00FF00; //green |
| 2001 | textureColors[2] = 0xFFFF0000; //blue |
| 2002 | |
| 2003 | ASSERT_NO_FATAL_FAILURE(InitMultipleSamplers(samplerCount)); |
| 2004 | ASSERT_NO_FATAL_FAILURE(InitMultipleTextures(textureCount, textureColors)); |
| 2005 | |
| 2006 | // Create descriptor set for a texture and sampler resources |
| 2007 | const int slotCount = textureCount + samplerCount; |
| 2008 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 2009 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 2010 | descriptorInfo.slots = slotCount; |
| 2011 | |
| 2012 | // create a descriptor set with a single slot |
| 2013 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 2014 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 2015 | |
| 2016 | // bind memory to the descriptor set |
| 2017 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 2018 | |
| 2019 | // write the sampler and image views to the descriptor set |
| 2020 | // ensure this matches order set in CreatePipelineSingleTextureAndSampler |
| 2021 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 2022 | int descSlot = 0; |
| 2023 | for (int i = 0; i < textureCount; ++i) |
| 2024 | xglAttachImageViewDescriptors( m_rsrcDescSet, descSlot++, 1, &m_textureViewInfo[i]); |
| 2025 | for (int i = 0; i < samplerCount; ++i) |
| 2026 | xglAttachSamplerDescriptors(m_rsrcDescSet, descSlot++, 1, &m_sampler[i]); |
| 2027 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 2028 | |
| 2029 | // Build command buffer |
| 2030 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 2031 | ASSERT_XGL_SUCCESS(err); |
| 2032 | |
| 2033 | GenerateClearAndPrepareBufferCmds(); |
| 2034 | GenerateBindRenderTargetCmd(); |
| 2035 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 2036 | |
| 2037 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 2038 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 2039 | |
| 2040 | // render the cube |
| 2041 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 2042 | |
| 2043 | // prepare the back buffer for present |
| 2044 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 2045 | // transitionToPresent.image = m_image; |
| 2046 | // transitionToPresent.oldState = m_image_state; |
| 2047 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 2048 | // transitionToPresent.subresourceRange = srRange; |
| 2049 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 2050 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 2051 | |
| 2052 | // finalize recording of the command buffer |
| 2053 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 2054 | ASSERT_XGL_SUCCESS( err ); |
| 2055 | |
| 2056 | // this command buffer only uses the vertex buffer memory |
| 2057 | m_numMemRefs = 0; |
| 2058 | // m_memRefs[0].flags = 0; |
| 2059 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 2060 | |
| 2061 | // submit the command buffer to the universal queue |
| 2062 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 2063 | ASSERT_XGL_SUCCESS( err ); |
| 2064 | |
| 2065 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 2066 | ASSERT_XGL_SUCCESS( err ); |
| 2067 | |
| 2068 | // Wait for work to finish before cleaning up. |
| 2069 | xglDeviceWaitIdle(m_device->device()); |
| 2070 | |
| 2071 | RecordImage(m_renderTarget); |
| 2072 | |
| 2073 | } |
| 2074 | |
Cody Northrop | 0fdf64e | 2014-10-20 11:51:06 -0600 | [diff] [blame] | 2075 | void XglRenderTest::DrawTriangleVSFSUniformBlock(const char *vertShaderText, const char *fragShaderText) |
| 2076 | { |
| 2077 | // this is sourced from DrawTriangleFSUniformBlock |
| 2078 | |
| 2079 | XGL_PIPELINE pipeline; |
| 2080 | XGL_SHADER vs, ps; |
| 2081 | XGL_RESULT err; |
| 2082 | |
| 2083 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2084 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2085 | |
| 2086 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
| 2087 | vertShaderText, &vs)); |
| 2088 | |
| 2089 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
| 2090 | fragShaderText, &ps)); |
| 2091 | |
| 2092 | ASSERT_NO_FATAL_FAILURE(CreatePipelineVSFSUniformBlock(&pipeline, vs, ps)); |
| 2093 | |
| 2094 | /* |
| 2095 | * Shaders are now part of the pipeline, don't need these anymore |
| 2096 | */ |
| 2097 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 2098 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 2099 | |
| 2100 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2101 | |
| 2102 | |
| 2103 | // Let's populate our buffer with the following: |
| 2104 | // vec4 red; |
| 2105 | // vec4 green; |
| 2106 | // vec4 blue; |
| 2107 | // vec4 white; |
| 2108 | const int valCount = 4 * 4; |
| 2109 | const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0, |
| 2110 | 0.0, 1.0, 0.0, 1.0, |
| 2111 | 0.0, 0.0, 1.0, 1.0, |
| 2112 | 1.0, 1.0, 1.0, 1.0 }; |
| 2113 | |
| 2114 | InitConstantBuffer(valCount, sizeof(bufferVals[0]), (const void*) bufferVals); |
| 2115 | |
| 2116 | // Create descriptor set for a uniform resource |
| 2117 | const int slotCount = 1; |
| 2118 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 2119 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 2120 | descriptorInfo.slots = slotCount; |
| 2121 | |
| 2122 | // create a descriptor set with a single slot |
| 2123 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 2124 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 2125 | |
| 2126 | // bind memory to the descriptor set |
| 2127 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 2128 | |
| 2129 | // write the constant buffer view to the descriptor set |
| 2130 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 2131 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 2132 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 2133 | |
| 2134 | // Build command buffer |
| 2135 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 2136 | ASSERT_XGL_SUCCESS(err); |
| 2137 | |
| 2138 | GenerateClearAndPrepareBufferCmds(); |
| 2139 | GenerateBindRenderTargetCmd(); |
| 2140 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 2141 | |
| 2142 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
| 2143 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 2144 | |
| 2145 | // render the cube |
| 2146 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 2147 | |
| 2148 | // prepare the back buffer for present |
| 2149 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 2150 | // transitionToPresent.image = m_image; |
| 2151 | // transitionToPresent.oldState = m_image_state; |
| 2152 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 2153 | // transitionToPresent.subresourceRange = srRange; |
| 2154 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 2155 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 2156 | |
| 2157 | // finalize recording of the command buffer |
| 2158 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 2159 | ASSERT_XGL_SUCCESS( err ); |
| 2160 | |
| 2161 | // this command buffer only uses the vertex buffer memory |
| 2162 | m_numMemRefs = 0; |
| 2163 | // m_memRefs[0].flags = 0; |
| 2164 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 2165 | |
| 2166 | // submit the command buffer to the universal queue |
| 2167 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 2168 | ASSERT_XGL_SUCCESS( err ); |
| 2169 | |
| 2170 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 2171 | ASSERT_XGL_SUCCESS( err ); |
| 2172 | |
| 2173 | // Wait for work to finish before cleaning up. |
| 2174 | xglDeviceWaitIdle(m_device->device()); |
| 2175 | |
| 2176 | RecordImage(m_renderTarget); |
| 2177 | |
| 2178 | } |
| 2179 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 2180 | TEST_F(XglRenderTest, GreenTriangle) |
| 2181 | { |
| 2182 | static const char *vertShaderText = |
| 2183 | "#version 130\n" |
| 2184 | "vec2 vertices[3];\n" |
| 2185 | "void main() {\n" |
| 2186 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 2187 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 2188 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 2189 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2190 | "}\n"; |
| 2191 | |
| 2192 | static const char *fragShaderText = |
| 2193 | "#version 130\n" |
| 2194 | "void main() {\n" |
| 2195 | " gl_FragColor = vec4(0,1,0,1);\n" |
| 2196 | "}\n"; |
| 2197 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 2198 | } |
| 2199 | |
| 2200 | TEST_F(XglRenderTest, BIL_GreenTriangle) |
| 2201 | { |
| 2202 | bool saved_use_bil = XglTestFramework::m_use_bil; |
| 2203 | |
| 2204 | static const char *vertShaderText = |
| 2205 | "#version 130\n" |
| 2206 | "vec2 vertices[3];\n" |
| 2207 | "void main() {\n" |
| 2208 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 2209 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 2210 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 2211 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2212 | "}\n"; |
| 2213 | |
| 2214 | static const char *fragShaderText = |
| 2215 | "#version 130\n" |
| 2216 | "void main() {\n" |
| 2217 | " gl_FragColor = vec4(0,1,0,1);\n" |
| 2218 | "}\n"; |
| 2219 | XglTestFramework::m_use_bil = true; |
| 2220 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 2221 | XglTestFramework::m_use_bil = saved_use_bil; |
| 2222 | } |
| 2223 | |
GregF | ef5d9cf | 2014-10-22 14:40:26 -0600 | [diff] [blame] | 2224 | TEST_F(XglRenderTest, MixTriangle) |
| 2225 | { |
| 2226 | // This tests location applied to varyings. Notice that we have switched foo |
| 2227 | // and bar in the FS. The triangle should be blended with red, green and blue |
| 2228 | // corners. |
| 2229 | static const char *vertShaderText = |
| 2230 | "#version 140\n" |
| 2231 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2232 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2233 | "layout (location=0) out vec4 bar;\n" |
| 2234 | "layout (location=1) out vec4 foo;\n" |
| 2235 | "layout (location=2) out vec4 scale;\n" |
| 2236 | "vec2 vertices[3];\n" |
| 2237 | "void main() {\n" |
| 2238 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 2239 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 2240 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 2241 | "vec4 colors[3];\n" |
| 2242 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2243 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 2244 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 2245 | " foo = colors[gl_VertexID % 3];\n" |
| 2246 | " bar = vec4(1.0, 1.0, 1.0, 1.0);\n" |
| 2247 | " scale.x = 0.0;\n" |
| 2248 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2249 | "}\n"; |
| 2250 | |
| 2251 | static const char *fragShaderText = |
| 2252 | "#version 140\n" |
| 2253 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2254 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2255 | "layout (location=1) in vec4 bar;\n" |
| 2256 | "layout (location=0) in vec4 foo;\n" |
| 2257 | "layout (location=2) in vec4 scale;\n" |
| 2258 | "void main() {\n" |
| 2259 | " gl_FragColor = bar + foo * scale.x;\n" |
| 2260 | "}\n"; |
| 2261 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 2262 | } |
| 2263 | |
GregF | 91b2d30 | 2014-10-23 10:44:44 -0600 | [diff] [blame] | 2264 | TEST_F(XglRenderTest, BIL_MixTriangle) |
| 2265 | { |
| 2266 | bool saved_use_bil = XglTestFramework::m_use_bil; |
| 2267 | |
| 2268 | // This tests location applied to varyings. Notice that we have switched foo |
| 2269 | // and bar in the FS. The triangle should be blended with red, green and blue |
| 2270 | // corners. |
| 2271 | static const char *vertShaderText = |
| 2272 | "#version 140\n" |
| 2273 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2274 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2275 | "layout (location=0) out vec4 bar;\n" |
| 2276 | "layout (location=1) out vec4 foo;\n" |
| 2277 | "layout (location=2) out vec4 scale;\n" |
| 2278 | "vec2 vertices[3];\n" |
| 2279 | "void main() {\n" |
| 2280 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 2281 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 2282 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 2283 | "vec4 colors[3];\n" |
| 2284 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2285 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 2286 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 2287 | " foo = colors[gl_VertexID % 3];\n" |
| 2288 | " bar = vec4(1.0, 1.0, 1.0, 1.0);\n" |
| 2289 | " scale.x = 0.0;\n" |
| 2290 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2291 | "}\n"; |
| 2292 | |
| 2293 | static const char *fragShaderText = |
| 2294 | "#version 140\n" |
| 2295 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2296 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2297 | "layout (location=1) in vec4 bar;\n" |
| 2298 | "layout (location=0) in vec4 foo;\n" |
| 2299 | "layout (location=2) in vec4 scale;\n" |
| 2300 | "void main() {\n" |
| 2301 | " gl_FragColor = bar + foo * scale.x;\n" |
| 2302 | "}\n"; |
| 2303 | XglTestFramework::m_use_bil = true; |
| 2304 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 2305 | XglTestFramework::m_use_bil = saved_use_bil; |
| 2306 | } |
| 2307 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 2308 | TEST_F(XglRenderTest, TriangleFragUniform) |
| 2309 | { |
| 2310 | |
| 2311 | static const char *vertShaderText = |
| 2312 | "#version 130\n" |
| 2313 | "out vec4 color;\n" |
| 2314 | "out vec4 scale;\n" |
| 2315 | "vec2 vertices[3];\n" |
| 2316 | "void main() {\n" |
| 2317 | "vec2 vertices[3];\n" |
| 2318 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2319 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2320 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2321 | "vec4 colors[3];\n" |
| 2322 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2323 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 2324 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 2325 | " color = colors[gl_VertexID % 3];\n" |
| 2326 | " scale = vec4(1.0, 1.0, 1.0, 1.0);\n" |
| 2327 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2328 | "}\n"; |
| 2329 | |
| 2330 | static const char *fragShaderText = |
| 2331 | "#version 130\n" |
| 2332 | "in vec4 color;\n" |
| 2333 | "in vec4 scale;\n" |
| 2334 | "uniform vec4 foo;\n" |
| 2335 | "void main() {\n" |
| 2336 | " gl_FragColor = color * scale + foo;\n" |
| 2337 | "}\n"; |
| 2338 | |
| 2339 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 2340 | } |
| 2341 | |
| 2342 | TEST_F(XglRenderTest, YellowTriangle) |
| 2343 | { |
| 2344 | static const char *vertShaderText = |
| 2345 | "#version 130\n" |
| 2346 | "void main() {\n" |
| 2347 | " vec2 vertices[3];" |
| 2348 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2349 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2350 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2351 | " vec4 colors[3];\n" |
| 2352 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2353 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 2354 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 2355 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2356 | "}\n"; |
| 2357 | |
| 2358 | static const char *fragShaderText = |
| 2359 | "#version 130\n" |
| 2360 | "void main() {\n" |
| 2361 | " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n" |
| 2362 | "}\n"; |
| 2363 | |
| 2364 | DrawTriangleTest(vertShaderText, fragShaderText); |
| 2365 | } |
| 2366 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 2367 | TEST_F(XglRenderTest, TriangleTwoFSUniforms) |
| 2368 | { |
| 2369 | static const char *vertShaderText = |
| 2370 | "#version 130\n" |
| 2371 | "out vec4 color;\n" |
| 2372 | "out vec4 scale;\n" |
| 2373 | "out vec2 samplePos;\n" |
| 2374 | "void main() {\n" |
| 2375 | " vec2 vertices[3];" |
| 2376 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2377 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2378 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2379 | " vec4 colors[3];\n" |
| 2380 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2381 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 2382 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 2383 | " color = colors[gl_VertexID % 3];\n" |
| 2384 | " vec2 positions[3];" |
| 2385 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 2386 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 2387 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 2388 | " scale = vec4(0.0, 0.0, 0.0, 0.0);\n" |
| 2389 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2390 | "}\n"; |
| 2391 | |
| 2392 | |
| 2393 | static const char *fragShaderText = |
| 2394 | "#version 430\n" |
| 2395 | "in vec4 color;\n" |
| 2396 | "in vec4 scale;\n" |
| 2397 | "uniform vec4 foo;\n" |
| 2398 | "uniform vec4 bar;\n" |
| 2399 | "void main() {\n" |
| 2400 | // by default, with no location or blocks |
| 2401 | // the compiler will read them from buffer |
| 2402 | // in reverse order of first use in shader |
| 2403 | // The buffer contains red, followed by blue, |
| 2404 | // so foo should be blue, bar should be red |
| 2405 | " gl_FragColor = color * scale * foo * bar + foo;\n" |
| 2406 | "}\n"; |
| 2407 | |
| 2408 | DrawTriangleTwoUniformsFS(vertShaderText, fragShaderText); |
| 2409 | } |
| 2410 | |
| 2411 | TEST_F(XglRenderTest, TriangleWithVertexFetch) |
| 2412 | { |
| 2413 | static const char *vertShaderText = |
| 2414 | "#version 130\n" |
| 2415 | //XYZ1( -1, -1, -1 ) |
| 2416 | "in vec4 pos;\n" |
| 2417 | //XYZ1( 0.f, 0.f, 0.f ) |
| 2418 | "in vec4 inColor;\n" |
| 2419 | "out vec4 outColor;\n" |
| 2420 | "void main() {\n" |
| 2421 | " outColor = inColor;\n" |
| 2422 | " gl_Position = pos;\n" |
| 2423 | "}\n"; |
| 2424 | |
| 2425 | |
| 2426 | static const char *fragShaderText = |
| 2427 | "#version 430\n" |
| 2428 | "in vec4 color;\n" |
| 2429 | "void main() {\n" |
| 2430 | " gl_FragColor = color;\n" |
| 2431 | "}\n"; |
| 2432 | |
| 2433 | DrawTriangleWithVertexFetch(vertShaderText, fragShaderText); |
| 2434 | } |
| 2435 | |
| 2436 | TEST_F(XglRenderTest, TriangleVSUniform) |
| 2437 | { |
| 2438 | static const char *vertShaderText = |
| 2439 | "#version 130\n" |
| 2440 | "uniform mat4 mvp;\n" |
| 2441 | "void main() {\n" |
| 2442 | " vec2 vertices[3];" |
| 2443 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2444 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2445 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2446 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0) * mvp;\n" |
| 2447 | "}\n"; |
| 2448 | |
| 2449 | static const char *fragShaderText = |
| 2450 | "#version 430\n" |
| 2451 | "void main() {\n" |
| 2452 | " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2453 | "}\n"; |
| 2454 | |
| 2455 | // Create identity matrix |
| 2456 | glm::mat4 Model = glm::mat4(1.0f); |
| 2457 | DrawTriangleVSUniform(vertShaderText, fragShaderText); |
| 2458 | |
| 2459 | // Model = glm::rotate(Model, glm::radians(45.0f), glm::vec3(0.0f, 0.0f, 1.0f)); |
| 2460 | // DrawTriangleVSUniform(vertShaderText, fragShaderText, Model); |
| 2461 | } |
| 2462 | |
Cody Northrop | 0fdf64e | 2014-10-20 11:51:06 -0600 | [diff] [blame] | 2463 | TEST_F(XglRenderTest, TriangleFSUniformBlock) |
| 2464 | { |
| 2465 | // The expected result from this test is a blue triangle |
| 2466 | |
| 2467 | static const char *vertShaderText = |
| 2468 | "#version 130\n" |
| 2469 | "void main() {\n" |
| 2470 | " vec2 vertices[3];" |
| 2471 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2472 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2473 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2474 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2475 | "}\n"; |
| 2476 | |
| 2477 | static const char *fragShaderText = |
| 2478 | "#version 430\n" |
| 2479 | "layout (std140) uniform bufferVals {\n" |
| 2480 | " vec4 red;\n" |
| 2481 | " vec4 green;\n" |
| 2482 | " vec4 blue;\n" |
| 2483 | " vec4 white;\n" |
| 2484 | "} myBufferVals;\n" |
| 2485 | "void main() {\n" |
| 2486 | " gl_FragColor = myBufferVals.blue;\n" |
| 2487 | "}\n"; |
| 2488 | |
| 2489 | DrawTriangleFSUniformBlock(vertShaderText, fragShaderText); |
| 2490 | } |
| 2491 | |
| 2492 | TEST_F(XglRenderTest, TriangleVSUniformBlock) |
| 2493 | { |
| 2494 | // The expected result from this test is a blue triangle |
| 2495 | |
| 2496 | static const char *vertShaderText = |
| 2497 | "#version 140\n" |
| 2498 | "out vec4 outColor;\n" |
| 2499 | "layout (std140) uniform bufferVals {\n" |
| 2500 | " vec4 red;\n" |
| 2501 | " vec4 green;\n" |
| 2502 | " vec4 blue;\n" |
| 2503 | " vec4 white;\n" |
| 2504 | "} myBufferVals;\n" |
| 2505 | "void main() {\n" |
| 2506 | " vec2 vertices[3];" |
| 2507 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2508 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2509 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2510 | " outColor = myBufferVals.blue;\n" |
| 2511 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2512 | "}\n"; |
| 2513 | |
| 2514 | static const char *fragShaderText = |
| 2515 | "#version 430\n" |
| 2516 | "in vec4 inColor;\n" |
| 2517 | "void main() {\n" |
| 2518 | " gl_FragColor = inColor;\n" |
| 2519 | "}\n"; |
| 2520 | |
| 2521 | DrawTriangleVSUniformBlock(vertShaderText, fragShaderText); |
| 2522 | } |
| 2523 | |
| 2524 | TEST_F(XglRenderTest, TriangleVSFSUniformBlock) |
| 2525 | { |
| 2526 | // The expected result from this test is a green triangle |
| 2527 | // Note the buffer is shared between stages, idenitical layout |
| 2528 | |
| 2529 | static const char *vertShaderText = |
| 2530 | "#version 140\n" |
| 2531 | "out vec4 outRed;\n" |
| 2532 | "out vec4 outGreen;\n" |
| 2533 | "out vec4 outBlue;\n" |
| 2534 | "out vec4 outWhite;\n" |
| 2535 | "layout (std140) uniform bufferVals {\n" |
| 2536 | " vec4 red;\n" |
| 2537 | " vec4 green;\n" |
| 2538 | " vec4 blue;\n" |
| 2539 | " vec4 white;\n" |
| 2540 | "} myBufferVals;\n" |
| 2541 | "void main() {\n" |
| 2542 | " vec2 vertices[3];" |
| 2543 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2544 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2545 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2546 | " outRed = myBufferVals.red;\n" |
| 2547 | " outGreen = myBufferVals.green;\n" |
| 2548 | " outBlue = myBufferVals.blue;\n" |
| 2549 | " outWhite = myBufferVals.white;\n" |
| 2550 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2551 | "}\n"; |
| 2552 | |
| 2553 | static const char *fragShaderText = |
| 2554 | "#version 430\n" |
| 2555 | "in vec4 inRed;\n" |
| 2556 | "in vec4 inGreen;\n" |
| 2557 | "in vec4 inBlue;\n" |
| 2558 | "in vec4 inWhite;\n" |
| 2559 | "layout (std140) uniform bufferVals {\n" |
| 2560 | " vec4 red;\n" |
| 2561 | " vec4 green;\n" |
| 2562 | " vec4 blue;\n" |
| 2563 | " vec4 white;\n" |
| 2564 | "} myBufferVals;\n" |
| 2565 | "void main() {\n" |
| 2566 | " if (inRed == myBufferVals.red && \n" |
| 2567 | " inGreen == myBufferVals.green && \n" |
| 2568 | " inBlue == myBufferVals.blue && \n" |
| 2569 | " inWhite == myBufferVals.white) \n" |
| 2570 | " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 2571 | " else\n" |
| 2572 | " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2573 | "}\n"; |
| 2574 | |
| 2575 | DrawTriangleVSFSUniformBlock(vertShaderText, fragShaderText); |
| 2576 | } |
| 2577 | |
| 2578 | |
Cody Northrop | c6953d0 | 2014-10-20 11:23:32 -0600 | [diff] [blame] | 2579 | TEST_F(XglRenderTest, TexturedTriangle) |
| 2580 | { |
Cody Northrop | 5fa1d33 | 2014-10-20 11:51:32 -0600 | [diff] [blame] | 2581 | // 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] | 2582 | static const char *vertShaderText = |
| 2583 | "#version 130\n" |
| 2584 | "out vec2 samplePos;\n" |
| 2585 | "void main() {\n" |
| 2586 | " vec2 vertices[3];" |
| 2587 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2588 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2589 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2590 | " vec2 positions[3];" |
| 2591 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 2592 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 2593 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 2594 | " samplePos = positions[gl_VertexID % 3];\n" |
| 2595 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2596 | "}\n"; |
| 2597 | |
| 2598 | static const char *fragShaderText = |
| 2599 | "#version 130\n" |
| 2600 | "in vec2 samplePos;\n" |
| 2601 | "uniform sampler2D surface;\n" |
| 2602 | "void main() {\n" |
| 2603 | " vec4 texColor = textureLod(surface, samplePos, 0.0);\n" |
| 2604 | " gl_FragColor = texColor;\n" |
| 2605 | "}\n"; |
| 2606 | DrawTexturedTriangle(vertShaderText, fragShaderText); |
| 2607 | } |
| 2608 | |
Cody Northrop | 9394e0c | 2014-10-23 10:21:47 -0600 | [diff] [blame] | 2609 | TEST_F(XglRenderTest, VSTexture) |
| 2610 | { |
| 2611 | // The expected result from this test is a green and red triangle; |
| 2612 | // one red vertex on the left, two green vertices on the right. |
| 2613 | static const char *vertShaderText = |
| 2614 | "#version 130\n" |
| 2615 | "out vec4 texColor;\n" |
| 2616 | "uniform sampler2D surface;\n" |
| 2617 | "void main() {\n" |
| 2618 | " vec2 vertices[3];" |
| 2619 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2620 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2621 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2622 | " vec2 positions[3];" |
| 2623 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 2624 | " positions[1] = vec2( 0.25, 0.1);\n" |
| 2625 | " positions[2] = vec2( 0.1, 0.25);\n" |
| 2626 | " vec2 samplePos = positions[gl_VertexID % 3];\n" |
| 2627 | " texColor = textureLod(surface, samplePos, 0.0);\n" |
| 2628 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2629 | "}\n"; |
| 2630 | |
| 2631 | static const char *fragShaderText = |
| 2632 | "#version 130\n" |
| 2633 | "in vec4 texColor;\n" |
| 2634 | "void main() {\n" |
| 2635 | " gl_FragColor = texColor;\n" |
| 2636 | "}\n"; |
| 2637 | |
| 2638 | DrawTexturedTriangle(vertShaderText, fragShaderText); |
| 2639 | } |
| 2640 | |
Cody Northrop | ec1d3c3 | 2014-10-28 15:41:42 -0600 | [diff] [blame] | 2641 | TEST_F(XglRenderTest, TriangleFSUniformBlockBinding) |
| 2642 | { |
| 2643 | // This test allows the shader to select which buffer it is |
| 2644 | // pulling from using layout binding qualifier. |
| 2645 | // There are corresponding changes in the compiler stack that |
| 2646 | // will select the buffer using binding directly. |
| 2647 | // The expected result from this test is a purple triangle |
| 2648 | |
| 2649 | static const char *vertShaderText = |
| 2650 | "#version 130\n" |
| 2651 | "void main() {\n" |
| 2652 | " vec2 vertices[3];" |
| 2653 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2654 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2655 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2656 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2657 | "}\n"; |
| 2658 | |
| 2659 | static const char *fragShaderText = |
| 2660 | "#version 140\n" |
| 2661 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2662 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2663 | "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;" |
| 2664 | "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;" |
| 2665 | "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;" |
| 2666 | "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;" |
| 2667 | "void main() {\n" |
| 2668 | " gl_FragColor = myBlueVal.color;\n" |
| 2669 | " gl_FragColor += myRedVal.color;\n" |
| 2670 | "}\n"; |
| 2671 | |
| 2672 | DrawTriangleFSUniformBlockBinding(vertShaderText, fragShaderText); |
| 2673 | } |
| 2674 | |
Cody Northrop | ac6179b | 2014-10-29 12:09:45 -0600 | [diff] [blame^] | 2675 | TEST_F(XglRenderTest, SamplerBindingsTriangle) |
| 2676 | { |
| 2677 | // This test sets bindings on the samplers |
| 2678 | // For this implementation, we are asserting that sampler and texture pairs |
| 2679 | // march in lock step, and are set via GLSL binding. |
| 2680 | // This test will result in a blue triangle |
| 2681 | static const char *vertShaderText = |
| 2682 | "#version 140\n" |
| 2683 | "out vec4 samplePos;\n" |
| 2684 | "void main() {\n" |
| 2685 | " vec2 vertices[3];" |
| 2686 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 2687 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 2688 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 2689 | " vec2 positions[3];" |
| 2690 | " positions[0] = vec2( 0.0, 0.0);\n" |
| 2691 | " positions[1] = vec2( 1.0, 0.0);\n" |
| 2692 | " positions[2] = vec2( 1.0, 1.0);\n" |
| 2693 | " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n" |
| 2694 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 2695 | "}\n"; |
| 2696 | |
| 2697 | static const char *fragShaderText = |
| 2698 | "#version 140\n" |
| 2699 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 2700 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 2701 | "in vec4 samplePos;\n" |
| 2702 | "layout (binding = 0) uniform sampler2D surface0;\n" |
| 2703 | "layout (binding = 1) uniform sampler2D surface1;\n" |
| 2704 | "layout (binding = 2) uniform sampler2D surface2;\n" |
| 2705 | "void main() {\n" |
| 2706 | " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n" |
| 2707 | "}\n"; |
| 2708 | |
| 2709 | int textureCount = g_TextureCount; |
| 2710 | int samplerCount = g_SamplerCount; |
| 2711 | DrawSamplerBindingsTriangle(vertShaderText, fragShaderText, textureCount, samplerCount); |
| 2712 | } |
| 2713 | |
Cody Northrop | 722ff40 | 2014-10-20 09:22:42 -0600 | [diff] [blame] | 2714 | int main(int argc, char **argv) { |
| 2715 | int result; |
| 2716 | |
| 2717 | ::testing::InitGoogleTest(&argc, argv); |
| 2718 | XglTestFramework::InitArgs(&argc, argv); |
| 2719 | |
| 2720 | ::testing::Environment* const xgl_test_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 2721 | |
| 2722 | result = RUN_ALL_TESTS(); |
| 2723 | |
| 2724 | XglTestFramework::Finish(); |
| 2725 | return result; |
| 2726 | } |