Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 1 | // Copyright 2005, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | |
| 31 | // XGL tests |
| 32 | // |
| 33 | // Copyright (C) 2014 LunarG, Inc. |
| 34 | // |
| 35 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 36 | // copy of this software and associated documentation files (the "Software"), |
| 37 | // to deal in the Software without restriction, including without limitation |
| 38 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 39 | // and/or sell copies of the Software, and to permit persons to whom the |
| 40 | // Software is furnished to do so, subject to the following conditions: |
| 41 | // |
| 42 | // The above copyright notice and this permission notice shall be included |
| 43 | // in all copies or substantial portions of the Software. |
| 44 | // |
| 45 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 46 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 47 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 48 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 49 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 50 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 51 | // DEALINGS IN THE SOFTWARE. |
| 52 | |
| 53 | |
| 54 | // Basic rendering tests |
| 55 | |
| 56 | #include <stdlib.h> |
| 57 | #include <stdio.h> |
| 58 | #include <stdbool.h> |
| 59 | #include <string.h> |
Courtney Goeltzenleuchter | 76a643b | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 60 | #include <iostream> |
| 61 | #include <fstream> |
| 62 | using namespace std; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 63 | |
| 64 | #include <xgl.h> |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 65 | #include <xglIntelExt.h> |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 66 | #include "gtest-1.7.0/include/gtest/gtest.h" |
| 67 | |
| 68 | #include "xgldevice.h" |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 69 | #include "xglimage.h" |
Chia-I Wu | 4115c89 | 2014-08-28 11:56:29 +0800 | [diff] [blame] | 70 | #include "icd-bil.h" |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 71 | |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 72 | #include "xgltestframework.h" |
Courtney Goeltzenleuchter | 2268d1e | 2014-09-01 13:57:15 -0600 | [diff] [blame] | 73 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 74 | //-------------------------------------------------------------------------------------- |
| 75 | // Mesh and VertexFormat Data |
| 76 | //-------------------------------------------------------------------------------------- |
| 77 | struct Vertex |
| 78 | { |
| 79 | XGL_FLOAT posX, posY, posZ, posW; // Position data |
| 80 | XGL_FLOAT r, g, b, a; // Color |
| 81 | }; |
| 82 | |
| 83 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
| 84 | |
| 85 | static const Vertex g_vbData[] = |
| 86 | { |
| 87 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 88 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 89 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 90 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 91 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 92 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 93 | |
| 94 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 95 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 96 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 97 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 98 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 99 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 100 | |
| 101 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 102 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 103 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 104 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 105 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 106 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 107 | |
| 108 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 109 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 110 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 111 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 112 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 113 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 114 | |
| 115 | { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) }, |
| 116 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 117 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 118 | { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, |
| 119 | { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) }, |
| 120 | { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 121 | |
| 122 | { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) }, |
| 123 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 124 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 125 | { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 126 | { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 127 | { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, |
| 128 | }; |
| 129 | |
Chia-I Wu | 6e9789c | 2014-08-30 14:03:32 +0800 | [diff] [blame] | 130 | static const uint32_t gen6_fs[] = { |
| 131 | 0x00600001, 0x202003fe, 0x00000000, 0x3f800000, // mov(8) m1<1>F 1F { align1 1Q }; |
| 132 | 0x00600001, 0x204003fe, 0x00000000, 0x00000000, // mov(8) m2<1>F 0F { align1 1Q }; |
| 133 | 0x00600001, 0x206003fe, 0x00000000, 0x00000000, // mov(8) m3<1>F 0F { align1 1Q }; |
| 134 | 0x00600001, 0x208003fe, 0x00000000, 0x3f800000, // mov(8) m4<1>F 1F { align1 1Q }; |
| 135 | 0x05600032, 0x20001fc8, 0x008d0020, 0x88019400, // sendc(8) null m1<8,8,1>F |
| 136 | // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT }; |
| 137 | }; |
| 138 | |
| 139 | static const uint32_t gen6_vs[] = { |
| 140 | 0x01600110, 0x200f1ca4, 0x00600020, 0x00000000, // cmp.z.f0(8) null g1<4,4,1>.xD 0D { align16 1Q }; |
| 141 | 0x00670122, 0x000a108f, 0x000e0004, 0x000e0004, // (+f0.all4h) if(8) JIP: 10 { align16 1Q }; |
| 142 | 0x00600501, 0x204303fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.xyF -1F { align16 NoDDClr 1Q }; |
| 143 | 0x00600d01, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDClr,NoDDChk 1Q }; |
| 144 | 0x00600901, 0x204803fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.wF 1F { align16 NoDDChk 1Q }; |
| 145 | 0x00600124, 0x0014108f, 0x006e0004, 0x006e0004, // else(8) JIP: 20 { align16 1Q }; |
| 146 | 0x01600110, 0x200f1ca4, 0x00600020, 0x00000001, // cmp.z.f0(8) null g1<4,4,1>.xD 1D { align16 1Q }; |
| 147 | 0x00670122, 0x000a108f, 0x000e0004, 0x000e0004, // (+f0.all4h) if(8) JIP: 10 { align16 1Q }; |
| 148 | 0x00600501, 0x204903fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.xwF 1F { align16 NoDDClr 1Q }; |
| 149 | 0x00600d01, 0x204203fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.yF -1F { align16 NoDDClr,NoDDChk 1Q }; |
| 150 | 0x00600901, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDChk 1Q }; |
| 151 | 0x00600124, 0x0006108f, 0x006e0004, 0x006e0004, // else(8) JIP: 6 { align16 1Q }; |
| 152 | 0x00600501, 0x204503fd, 0x00000000, 0x00000000, // mov(8) g2<1>.xzF 0F { align16 NoDDClr 1Q }; |
| 153 | 0x00600901, 0x204a03fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.ywF 1F { align16 NoDDChk 1Q }; |
| 154 | 0x00600125, 0x0002108f, 0x006e0004, 0x006e0002, // endif(8) JIP: 2 { align16 1Q }; |
| 155 | 0x00600125, 0x0002108f, 0x006e0004, 0x006e0002, // endif(8) JIP: 2 { align16 1Q }; |
| 156 | 0x00600101, 0x204f0062, 0x00000000, 0x00000000, // mov(8) m2<1>UD 0x00000000UD { align16 1Q }; |
| 157 | 0x00600101, 0x206f03be, 0x006e0044, 0x00000000, // mov(8) m3<1>F g2<4,4,1>F { align16 1Q }; |
| 158 | 0x00600301, 0x202f0022, 0x006e0004, 0x00000000, // mov(8) m1<1>UD g0<4,4,1>UD { align16 WE_all 1Q }; |
| 159 | 0x06600131, 0x200f1fdc, 0x006e0024, 0x8608c400, // send(8) null m1<4,4,1>F |
| 160 | // urb 0 urb_write interleave used complete mlen 3 rlen 0 { align16 1Q EOT }; |
| 161 | }; |
| 162 | |
| 163 | static const uint32_t gen7_fs[] = { |
| 164 | 0x00600001, 0x2e2003fd, 0x00000000, 0x3f800000, // mov(8) g113<1>F 1F { align1 1Q }; |
| 165 | 0x00600001, 0x2e4003fd, 0x00000000, 0x00000000, // mov(8) g114<1>F 0F { align1 1Q }; |
| 166 | 0x00600001, 0x2e6003fd, 0x00000000, 0x00000000, // mov(8) g115<1>F 0F { align1 1Q }; |
| 167 | 0x00600001, 0x2e8003fd, 0x00000000, 0x3f800000, // mov(8) g116<1>F 1F { align1 1Q }; |
| 168 | 0x05600032, 0x20001fa8, 0x008d0e20, 0x88031400, // sendc(8) null g113<8,8,1>F |
| 169 | // render RT write SIMD8 LastRT Surface = 0 mlen 4 rlen 0 { align1 1Q EOT }; |
| 170 | }; |
| 171 | |
| 172 | static const uint32_t gen7_vs[] = { |
| 173 | 0x01608110, 0x200f1ca4, 0x00600020, 0x00000000, // cmp.z.f0(8) null g1<4,4,1>.xD 0D { align16 1Q switch }; |
| 174 | 0x00670122, 0x200f0c84, 0x000e0004, 0x001c000a, // (+f0.all4h) if(8) JIP: 10 UIP: 28 { align16 1Q }; |
| 175 | 0x00600501, 0x204303fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.xyF -1F { align16 NoDDClr 1Q }; |
| 176 | 0x00600d01, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDClr,NoDDChk 1Q }; |
| 177 | 0x00600901, 0x204803fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.wF 1F { align16 NoDDChk 1Q }; |
| 178 | 0x00600124, 0x200f0c84, 0x006e0004, 0x00000014, // else(8) JIP: 20 { align16 1Q }; |
| 179 | 0x01608110, 0x200f1ca4, 0x00600020, 0x00000001, // cmp.z.f0(8) null g1<4,4,1>.xD 1D { align16 1Q switch }; |
| 180 | 0x00670122, 0x200f0c84, 0x000e0004, 0x000e000a, // (+f0.all4h) if(8) JIP: 10 UIP: 14 { align16 1Q }; |
| 181 | 0x00600501, 0x204903fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.xwF 1F { align16 NoDDClr 1Q }; |
| 182 | 0x00600d01, 0x204203fd, 0x00000000, 0xbf800000, // mov(8) g2<1>.yF -1F { align16 NoDDClr,NoDDChk 1Q }; |
| 183 | 0x00600901, 0x204403fd, 0x00000000, 0x00000000, // mov(8) g2<1>.zF 0F { align16 NoDDChk 1Q }; |
| 184 | 0x00600124, 0x200f0c84, 0x006e0004, 0x00000006, // else(8) JIP: 6 { align16 1Q }; |
| 185 | 0x00600501, 0x204503fd, 0x00000000, 0x00000000, // mov(8) g2<1>.xzF 0F { align16 NoDDClr 1Q }; |
| 186 | 0x00600901, 0x204a03fd, 0x00000000, 0x3f800000, // mov(8) g2<1>.ywF 1F { align16 NoDDChk 1Q }; |
| 187 | 0x00600125, 0x200f0c84, 0x006e0004, 0x00000002, // endif(8) JIP: 2 { align16 1Q }; |
| 188 | 0x00600125, 0x200f0c84, 0x006e0004, 0x00000002, // endif(8) JIP: 2 { align16 1Q }; |
| 189 | 0x00600101, 0x2e4f0061, 0x00000000, 0x00000000, // mov(8) g114<1>UD 0x00000000UD { align16 1Q }; |
| 190 | 0x00600101, 0x2e6f03bd, 0x006e0044, 0x00000000, // mov(8) g115<1>F g2<4,4,1>F { align16 1Q }; |
| 191 | 0x00600301, 0x2e2f0021, 0x006e0004, 0x00000000, // mov(8) g113<1>UD g0<4,4,1>UD { align16 WE_all 1Q }; |
| 192 | 0x00000206, 0x2e340c21, 0x00000014, 0x0000ff00, // or(1) g113.5<1>UD g0.5<0,1,0>UD 0x0000ff00UD { align1 WE_all }; |
| 193 | 0x06600131, 0x200f1fbc, 0x006e0e24, 0x8608c000, // send(8) null g113<4,4,1>F |
| 194 | // urb 0 write HWord interleave complete mlen 3 rlen 0 { align16 1Q EOT }; |
| 195 | }; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 196 | |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 197 | class XglRenderTest : public XglTestFramework |
| 198 | { |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 199 | public: |
Chia-I Wu | a3b9d6a | 2014-08-30 23:53:01 +0800 | [diff] [blame] | 200 | void CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots, |
| 201 | XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem); |
| 202 | void DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 203 | void CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER* vs, XGL_SHADER* ps, int width, int height); |
| 204 | void GenerateClearAndPrepareBufferCmds(XglImage *renderTarget); |
| 205 | void GenerateBindRenderTargetCmd(XglImage *renderTarget); |
| 206 | void GenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline); |
Chia-I Wu | a3b9d6a | 2014-08-30 23:53:01 +0800 | [diff] [blame] | 207 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 208 | XGL_DEVICE device() {return m_device->device();} |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 209 | void CreateShader(XGL_PIPELINE_SHADER_STAGE stage, const char *shader_code, XGL_SHADER *pshader); |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 210 | void InitPipeline(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 211 | void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices ); |
Cody Northrop | 2c4c6d9 | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 212 | void InitConstantBuffer( int constantCount, int constantSize, const void* data ); |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame^] | 213 | void InitTexture(); |
| 214 | void InitSampler(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 215 | void DrawTriangleTest(); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 216 | void DrawRotatedTriangleTest(); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 217 | |
| 218 | protected: |
| 219 | XGL_APPLICATION_INFO app_info; |
| 220 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 221 | XGL_UINT gpu_count; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 222 | XGL_GPU_MEMORY m_descriptor_set_mem; |
| 223 | XGL_GPU_MEMORY m_pipe_mem; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 224 | XglDevice *m_device; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 225 | XGL_CMD_BUFFER m_cmdBuffer; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 226 | XGL_UINT32 m_numVertices; |
| 227 | XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView; |
Cody Northrop | 2c4c6d9 | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 228 | XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView; |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame^] | 229 | |
| 230 | XGL_IMAGE m_texture; |
| 231 | XGL_IMAGE_VIEW m_textureView; |
| 232 | XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo; |
| 233 | XGL_GPU_MEMORY m_textureMem; |
| 234 | |
| 235 | XGL_SAMPLER m_sampler; |
| 236 | |
| 237 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 238 | XGL_GPU_MEMORY m_vtxBufferMem; |
Cody Northrop | 2c4c6d9 | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 239 | XGL_GPU_MEMORY m_constantBufferMem; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 240 | XGL_UINT32 m_numMemRefs; |
| 241 | XGL_MEMORY_REF m_memRefs[5]; |
| 242 | XGL_RASTER_STATE_OBJECT m_stateRaster; |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 243 | XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 244 | XGL_VIEWPORT_STATE_OBJECT m_stateViewport; |
| 245 | XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil; |
| 246 | XGL_MSAA_STATE_OBJECT m_stateMsaa; |
| 247 | XGL_DESCRIPTOR_SET m_rsrcDescSet; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 248 | |
| 249 | virtual void SetUp() { |
| 250 | XGL_RESULT err; |
| 251 | |
| 252 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 253 | this->app_info.pNext = NULL; |
| 254 | this->app_info.pAppName = (const XGL_CHAR *) "base"; |
| 255 | this->app_info.appVersion = 1; |
| 256 | this->app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 257 | this->app_info.engineVersion = 1; |
| 258 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 259 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 260 | memset(&m_vtxBufferView, 0, sizeof(m_vtxBufferView)); |
| 261 | m_vtxBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO; |
| 262 | |
Cody Northrop | 2c4c6d9 | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 263 | memset(&m_constantBufferView, 0, sizeof(m_constantBufferView)); |
| 264 | m_constantBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO; |
| 265 | |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame^] | 266 | memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo)); |
| 267 | m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
| 268 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 269 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
| 270 | MAX_GPUS, &this->gpu_count, objs); |
| 271 | ASSERT_XGL_SUCCESS(err); |
| 272 | ASSERT_GE(1, this->gpu_count) << "No GPU available"; |
| 273 | |
| 274 | m_device = new XglDevice(0, objs[0]); |
| 275 | m_device->get_device_queue(); |
| 276 | } |
| 277 | |
| 278 | virtual void TearDown() { |
Tobin Ehlis | a9b1354 | 2014-10-23 13:45:13 -0600 | [diff] [blame] | 279 | m_device->destroy_device(); |
Tobin Ehlis | dcd421a | 2014-10-23 15:18:50 -0600 | [diff] [blame] | 280 | xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 281 | } |
| 282 | }; |
| 283 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 284 | |
Chia-I Wu | a3b9d6a | 2014-08-30 23:53:01 +0800 | [diff] [blame] | 285 | void XglRenderTest::CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots, |
| 286 | XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem) |
| 287 | { |
| 288 | XGL_RESULT err; |
| 289 | |
| 290 | XGL_QUERY_POOL_CREATE_INFO poolCreateInfo = {}; |
| 291 | poolCreateInfo.sType = XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 292 | poolCreateInfo.pNext = NULL; |
| 293 | poolCreateInfo.queryType = type; |
| 294 | poolCreateInfo.slots = slots; |
| 295 | |
| 296 | err = xglCreateQueryPool(device(), &poolCreateInfo, pPool); |
| 297 | ASSERT_XGL_SUCCESS(err); |
| 298 | |
| 299 | XGL_MEMORY_REQUIREMENTS mem_req; |
Jon Ashburn | b8e4389 | 2014-09-25 14:36:58 -0600 | [diff] [blame] | 300 | XGL_UINT data_size = sizeof(mem_req); |
Chia-I Wu | a3b9d6a | 2014-08-30 23:53:01 +0800 | [diff] [blame] | 301 | err = xglGetObjectInfo(*pPool, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 302 | &data_size, &mem_req); |
| 303 | ASSERT_XGL_SUCCESS(err); |
| 304 | ASSERT_EQ(data_size, sizeof(mem_req)); |
| 305 | |
| 306 | if (!mem_req.size) { |
| 307 | *pMem = XGL_NULL_HANDLE; |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 312 | |
| 313 | memset(&mem_info, 0, sizeof(mem_info)); |
| 314 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 315 | mem_info.allocationSize = mem_req.size; |
| 316 | mem_info.alignment = mem_req.alignment; |
| 317 | mem_info.heapCount = mem_req.heapCount; |
| 318 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 319 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 320 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
| 321 | err = xglAllocMemory(device(), &mem_info, pMem); |
| 322 | ASSERT_XGL_SUCCESS(err); |
| 323 | |
| 324 | err = xglBindObjectMemory(*pPool, *pMem, 0); |
| 325 | ASSERT_XGL_SUCCESS(err); |
| 326 | } |
| 327 | |
| 328 | void XglRenderTest::DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem) |
| 329 | { |
| 330 | ASSERT_XGL_SUCCESS(xglBindObjectMemory(pool, XGL_NULL_HANDLE, 0)); |
| 331 | ASSERT_XGL_SUCCESS(xglFreeMemory(mem)); |
| 332 | ASSERT_XGL_SUCCESS(xglDestroyObject(pool)); |
| 333 | } |
| 334 | |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 335 | void XglRenderTest::CreateShader(XGL_PIPELINE_SHADER_STAGE stage, |
| 336 | const char *shader_code, |
| 337 | XGL_SHADER *pshader) |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 338 | { |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 339 | XGL_RESULT err; |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 340 | std::vector<unsigned int> bil; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 341 | XGL_SHADER_CREATE_INFO createInfo; |
| 342 | XGL_SHADER shader; |
Courtney Goeltzenleuchter | 76a643b | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 343 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 344 | createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 345 | createInfo.pNext = NULL; |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 346 | |
| 347 | if (this->m_device->extension_exist("XGL_COMPILE_GLSL")) { |
Courtney Goeltzenleuchter | d6f7589 | 2014-10-06 12:45:37 -0600 | [diff] [blame] | 348 | XGL_INTEL_COMPILE_GLSL glsl_header; |
| 349 | |
| 350 | glsl_header.stage = stage; |
| 351 | glsl_header.pCode = shader_code; |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 352 | // Driver has extended CreateShader to process GLSL |
| 353 | createInfo.sType = (XGL_STRUCTURE_TYPE) XGL_INTEL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
Courtney Goeltzenleuchter | d6f7589 | 2014-10-06 12:45:37 -0600 | [diff] [blame] | 354 | createInfo.pCode = &glsl_header; |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 355 | createInfo.codeSize = strlen(shader_code); |
| 356 | createInfo.flags = 0; |
| 357 | } else { |
| 358 | // Use Reference GLSL to BIL compiler |
| 359 | GLSLtoBIL(stage, shader_code, bil); |
| 360 | createInfo.pCode = bil.data(); |
| 361 | createInfo.codeSize = bil.size() * sizeof(unsigned int); |
| 362 | createInfo.flags = 0; |
| 363 | } |
| 364 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 365 | err = xglCreateShader(device(), &createInfo, &shader); |
| 366 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 76a643b | 2014-08-21 17:34:22 -0600 | [diff] [blame] | 367 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 368 | *pshader = shader; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 369 | } |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 370 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 371 | // this function will create the vertex buffer and fill it with the mesh data |
| 372 | void XglRenderTest::InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, |
| 373 | const void* vertices ) |
| 374 | { |
| 375 | XGL_RESULT err = XGL_SUCCESS; |
| 376 | |
| 377 | assert( numVertices * vbStride > 0 ); |
| 378 | m_numVertices = numVertices; |
| 379 | |
| 380 | XGL_MEMORY_ALLOC_INFO alloc_info = {}; |
| 381 | XGL_UINT8 *pData; |
| 382 | |
| 383 | alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 384 | alloc_info.allocationSize = numVertices * vbStride; |
| 385 | alloc_info.alignment = 0; |
| 386 | alloc_info.heapCount = 1; |
| 387 | alloc_info.heaps[0] = 0; // TODO: Use known existing heap |
| 388 | |
| 389 | alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT; |
| 390 | alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 391 | |
| 392 | err = xglAllocMemory(device(), &alloc_info, &m_vtxBufferMem); |
| 393 | ASSERT_XGL_SUCCESS(err); |
| 394 | |
| 395 | err = xglMapMemory(m_vtxBufferMem, 0, (XGL_VOID **) &pData); |
| 396 | ASSERT_XGL_SUCCESS(err); |
| 397 | |
| 398 | memcpy(pData, vertices, alloc_info.allocationSize); |
| 399 | |
| 400 | err = xglUnmapMemory(m_vtxBufferMem); |
| 401 | ASSERT_XGL_SUCCESS(err); |
| 402 | |
| 403 | // set up the memory view for the vertex buffer |
| 404 | this->m_vtxBufferView.stride = vbStride; |
| 405 | this->m_vtxBufferView.range = numVertices * vbStride; |
| 406 | this->m_vtxBufferView.offset = 0; |
| 407 | this->m_vtxBufferView.mem = m_vtxBufferMem; |
| 408 | this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 409 | this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED; |
| 410 | |
| 411 | // open the command buffer |
| 412 | err = xglBeginCommandBuffer( m_cmdBuffer, 0 ); |
| 413 | ASSERT_XGL_SUCCESS(err); |
| 414 | |
| 415 | XGL_MEMORY_STATE_TRANSITION transition = {}; |
| 416 | transition.mem = m_vtxBufferMem; |
| 417 | transition.oldState = XGL_MEMORY_STATE_DATA_TRANSFER; |
| 418 | transition.newState = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 419 | transition.offset = 0; |
| 420 | transition.regionSize = numVertices * vbStride; |
| 421 | |
| 422 | // write transition to the command buffer |
| 423 | xglCmdPrepareMemoryRegions( m_cmdBuffer, 1, &transition ); |
| 424 | this->m_vtxBufferView.state = XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY; |
| 425 | |
| 426 | // finish recording the command buffer |
| 427 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 428 | ASSERT_XGL_SUCCESS(err); |
| 429 | |
| 430 | // this command buffer only uses the vertex buffer memory |
| 431 | m_numMemRefs = 1; |
| 432 | m_memRefs[0].flags = 0; |
| 433 | m_memRefs[0].mem = m_vtxBufferMem; |
| 434 | |
| 435 | // submit the command buffer to the universal queue |
| 436 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 437 | ASSERT_XGL_SUCCESS(err); |
| 438 | } |
| 439 | |
Cody Northrop | 2c4c6d9 | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 440 | void XglRenderTest::InitConstantBuffer(int constantCount, int constantSize, const void* data) |
| 441 | { |
| 442 | XGL_RESULT err = XGL_SUCCESS; |
| 443 | |
| 444 | XGL_MEMORY_ALLOC_INFO alloc_info = {}; |
| 445 | XGL_UINT8 *pData; |
| 446 | |
| 447 | alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 448 | alloc_info.allocationSize = constantCount * constantSize; |
| 449 | alloc_info.alignment = 0; |
| 450 | alloc_info.heapCount = 1; |
| 451 | alloc_info.heaps[0] = 0; // TODO: Use known existing heap |
| 452 | |
| 453 | alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT; |
| 454 | alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 455 | |
| 456 | err = xglAllocMemory(device(), &alloc_info, &m_constantBufferMem); |
| 457 | ASSERT_XGL_SUCCESS(err); |
| 458 | |
| 459 | err = xglMapMemory(m_constantBufferMem, 0, (XGL_VOID **) &pData); |
| 460 | ASSERT_XGL_SUCCESS(err); |
| 461 | |
| 462 | memcpy(pData, data, alloc_info.allocationSize); |
| 463 | |
| 464 | err = xglUnmapMemory(m_constantBufferMem); |
| 465 | ASSERT_XGL_SUCCESS(err); |
| 466 | |
| 467 | // set up the memory view for the constant buffer |
| 468 | this->m_constantBufferView.stride = 1; |
| 469 | this->m_constantBufferView.range = 16; |
| 470 | this->m_constantBufferView.offset = 0; |
| 471 | this->m_constantBufferView.mem = m_constantBufferMem; |
| 472 | this->m_constantBufferView.format.channelFormat = XGL_CH_FMT_R32G32B32A32; |
| 473 | this->m_constantBufferView.format.numericFormat = XGL_NUM_FMT_FLOAT; |
| 474 | } |
| 475 | |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame^] | 476 | void XglRenderTest::InitTexture() |
| 477 | { |
| 478 | XGL_RESULT err; |
| 479 | XGL_UINT mipCount; |
| 480 | XGL_SIZE size; |
| 481 | XGL_FORMAT fmt; |
| 482 | XGL_FORMAT_PROPERTIES image_fmt; |
| 483 | |
| 484 | // size of LunarG image |
| 485 | XGL_UINT w = 300; |
| 486 | XGL_UINT h = 280; |
| 487 | |
| 488 | mipCount = 0; |
| 489 | |
| 490 | XGL_UINT _w = w; |
| 491 | XGL_UINT _h = h; |
| 492 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 493 | { |
| 494 | _w >>= 1; |
| 495 | _h >>= 1; |
| 496 | mipCount++; |
| 497 | } |
| 498 | |
| 499 | fmt.channelFormat = XGL_CH_FMT_R8G8B8A8; |
| 500 | fmt.numericFormat = XGL_NUM_FMT_UNORM; |
| 501 | |
| 502 | size = sizeof(image_fmt); |
| 503 | err = xglGetFormatInfo(this->device(), fmt, |
| 504 | XGL_INFO_TYPE_FORMAT_PROPERTIES, |
| 505 | &size, &image_fmt); |
| 506 | ASSERT_XGL_SUCCESS(err); |
| 507 | |
| 508 | |
| 509 | XGL_IMAGE_CREATE_INFO imageCreateInfo = {}; |
| 510 | imageCreateInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 511 | imageCreateInfo.imageType = XGL_IMAGE_2D; |
| 512 | imageCreateInfo.format = fmt; |
| 513 | imageCreateInfo.arraySize = 1; |
| 514 | imageCreateInfo.extent.width = w; |
| 515 | imageCreateInfo.extent.height = h; |
| 516 | imageCreateInfo.extent.depth = 1; |
| 517 | imageCreateInfo.mipLevels = mipCount; |
| 518 | imageCreateInfo.samples = 1; |
| 519 | imageCreateInfo.tiling = XGL_LINEAR_TILING; |
| 520 | imageCreateInfo.usage = XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 521 | |
| 522 | err = xglCreateImage(device(), &imageCreateInfo, &m_texture); |
| 523 | ASSERT_XGL_SUCCESS(err); |
| 524 | |
| 525 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 526 | XGL_UINT data_size = sizeof(mem_req); |
| 527 | err = xglGetObjectInfo(m_texture, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 528 | &data_size, &mem_req); |
| 529 | ASSERT_XGL_SUCCESS(err); |
| 530 | ASSERT_EQ(data_size, sizeof(mem_req)); |
| 531 | ASSERT_NE(0, mem_req.size) << "xglGetObjectInfo (Event): Failed - expect images to require memory"; |
| 532 | |
| 533 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 534 | |
| 535 | memset(&mem_info, 0, sizeof(mem_info)); |
| 536 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 537 | mem_info.allocationSize = mem_req.size; |
| 538 | mem_info.alignment = mem_req.alignment; |
| 539 | mem_info.heapCount = mem_req.heapCount; |
| 540 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 541 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 542 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
| 543 | err = xglAllocMemory(device(), &mem_info, &m_textureMem); |
| 544 | ASSERT_XGL_SUCCESS(err); |
| 545 | |
| 546 | XGL_UINT8 *pData; |
| 547 | const int texture_size = 300*280*4; // RGBA_UNORM |
| 548 | char data[texture_size]; |
| 549 | for (int i = 0; i < h; ++i) { |
| 550 | for (int j = 0; j < w; j += 4) { |
| 551 | // grey |
| 552 | data[i + j + 0] = 0x80; |
| 553 | data[i + j + 1] = 0x80; |
| 554 | data[i + j + 2] = 0x80; |
| 555 | data[i + j + 3] = 0xFF; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | err = xglMapMemory(m_textureMem, 0, (XGL_VOID **) &pData); |
| 560 | ASSERT_XGL_SUCCESS(err); |
| 561 | |
| 562 | memcpy(pData, data, texture_size); |
| 563 | |
| 564 | err = xglUnmapMemory(m_textureMem); |
| 565 | ASSERT_XGL_SUCCESS(err); |
| 566 | |
| 567 | err = xglBindObjectMemory(m_texture, m_textureMem, 0); |
| 568 | ASSERT_XGL_SUCCESS(err); |
| 569 | |
| 570 | XGL_IMAGE_VIEW_CREATE_INFO viewInfo = {}; |
| 571 | viewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 572 | viewInfo.viewType = XGL_IMAGE_VIEW_2D; |
| 573 | viewInfo.format = fmt; |
| 574 | viewInfo.image = m_texture; |
| 575 | |
| 576 | viewInfo.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 577 | viewInfo.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 578 | viewInfo.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 579 | viewInfo.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 580 | |
| 581 | viewInfo.subresourceRange.baseArraySlice = 0; |
| 582 | viewInfo.subresourceRange.arraySize = 1; |
| 583 | viewInfo.subresourceRange.baseMipLevel = 0; |
| 584 | viewInfo.subresourceRange.mipLevels = 1; |
| 585 | viewInfo.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 586 | |
| 587 | ASSERT_XGL_SUCCESS(xglCreateImageView(device(), &viewInfo, &m_textureView)); |
| 588 | |
| 589 | m_textureViewInfo.view = m_textureView; |
| 590 | } |
| 591 | |
| 592 | void XglRenderTest::InitSampler() |
| 593 | { |
| 594 | XGL_RESULT err; |
| 595 | |
| 596 | XGL_SAMPLER_CREATE_INFO samplerCreateInfo = {}; |
| 597 | samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 598 | samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST; |
| 599 | samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST; |
| 600 | samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE; |
| 601 | samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP; |
| 602 | samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP; |
| 603 | samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP; |
| 604 | samplerCreateInfo.mipLodBias = 0.0; |
| 605 | samplerCreateInfo.maxAnisotropy = 0.0; |
| 606 | samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER; |
| 607 | samplerCreateInfo.minLod = 0.0; |
| 608 | samplerCreateInfo.maxLod = 0.0; |
| 609 | samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE; |
| 610 | |
| 611 | err = xglCreateSampler(device(),&samplerCreateInfo, &m_sampler); |
| 612 | ASSERT_XGL_SUCCESS(err); |
| 613 | } |
| 614 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 615 | void XglRenderTest::CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER* vs, XGL_SHADER* ps, int width, int height) |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 616 | { |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 617 | XGL_RESULT err; |
| 618 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 619 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage; |
| 620 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage; |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 621 | //XGL_PIPELINE pipeline; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 622 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 623 | // create a raster state (solid, back-face culling) |
| 624 | XGL_RASTER_STATE_CREATE_INFO raster = {}; |
| 625 | raster.sType = XGL_STRUCTURE_TYPE_RASTER_STATE_CREATE_INFO; |
| 626 | raster.fillMode = XGL_FILL_SOLID; |
Chia-I Wu | 0059c37 | 2014-08-31 00:52:42 +0800 | [diff] [blame] | 627 | raster.cullMode = XGL_CULL_NONE; |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 628 | raster.frontFace = XGL_FRONT_FACE_CCW; |
| 629 | err = xglCreateRasterState( device(), &raster, &m_stateRaster ); |
| 630 | ASSERT_XGL_SUCCESS(err); |
| 631 | |
| 632 | XGL_VIEWPORT_STATE_CREATE_INFO viewport = {}; |
| 633 | viewport.viewportCount = 1; |
| 634 | viewport.scissorEnable = XGL_FALSE; |
| 635 | viewport.viewports[0].originX = 0; |
| 636 | viewport.viewports[0].originY = 0; |
| 637 | viewport.viewports[0].width = 1.f * width; |
| 638 | viewport.viewports[0].height = 1.f * height; |
| 639 | viewport.viewports[0].minDepth = 0.f; |
| 640 | viewport.viewports[0].maxDepth = 1.f; |
| 641 | |
| 642 | err = xglCreateViewportState( device(), &viewport, &m_stateViewport ); |
| 643 | ASSERT_XGL_SUCCESS( err ); |
| 644 | |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 645 | XGL_COLOR_BLEND_STATE_CREATE_INFO blend = {}; |
| 646 | blend.sType = XGL_STRUCTURE_TYPE_COLOR_BLEND_STATE_CREATE_INFO; |
| 647 | err = xglCreateColorBlendState(device(), &blend, &m_colorBlend); |
| 648 | ASSERT_XGL_SUCCESS( err ); |
| 649 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 650 | XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {}; |
| 651 | depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO; |
| 652 | depthStencil.depthTestEnable = XGL_FALSE; |
| 653 | depthStencil.depthWriteEnable = XGL_FALSE; |
| 654 | depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL; |
| 655 | depthStencil.depthBoundsEnable = XGL_FALSE; |
| 656 | depthStencil.minDepth = 0.f; |
| 657 | depthStencil.maxDepth = 1.f; |
| 658 | depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP; |
| 659 | depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP; |
| 660 | depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP; |
| 661 | depthStencil.back.stencilRef = 0x00; |
| 662 | depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS; |
| 663 | depthStencil.front = depthStencil.back; |
| 664 | |
| 665 | err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil ); |
| 666 | ASSERT_XGL_SUCCESS( err ); |
| 667 | |
| 668 | XGL_MSAA_STATE_CREATE_INFO msaa = {}; |
| 669 | msaa.sType = XGL_STRUCTURE_TYPE_MSAA_STATE_CREATE_INFO; |
| 670 | msaa.sampleMask = 1; |
| 671 | msaa.samples = 1; |
| 672 | |
| 673 | err = xglCreateMsaaState( device(), &msaa, &m_stateMsaa ); |
| 674 | ASSERT_XGL_SUCCESS( err ); |
| 675 | |
| 676 | XGL_CMD_BUFFER_CREATE_INFO cmdInfo = {}; |
| 677 | |
| 678 | cmdInfo.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
| 679 | cmdInfo.queueType = XGL_QUEUE_TYPE_GRAPHICS; |
| 680 | err = xglCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer); |
| 681 | ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed"; |
| 682 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 683 | #if 0 |
| 684 | // Create descriptor set for our one resource |
| 685 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 686 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 687 | descriptorInfo.slots = 1; // Vertex buffer only |
| 688 | |
| 689 | // create a descriptor set with a single slot |
| 690 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 691 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 692 | |
| 693 | // bind memory to the descriptor set |
| 694 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 695 | |
| 696 | // set up the memory view for the vertex buffer |
| 697 | this->m_vtxBufferView.stride = vbStride; |
| 698 | this->m_vtxBufferView.range = numVertices * vbStride; |
| 699 | this->m_vtxBufferView.offset = 0; |
| 700 | this->m_vtxBufferView.mem = m_vtxBufferMem; |
| 701 | this->m_vtxBufferView.format.channelFormat = XGL_CH_FMT_UNDEFINED; |
| 702 | this->m_vtxBufferView.format.numericFormat = XGL_NUM_FMT_UNDEFINED; |
| 703 | // write the vertex buffer view to the descriptor set |
| 704 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 705 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_vtxBufferView ); |
| 706 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 707 | #endif |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 708 | |
Cody Northrop | 2c4c6d9 | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 709 | const int constantCount = 4; |
| 710 | const float constants[constantCount] = { 0.5, 0.5, 0.5, 1.0 }; |
| 711 | InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants); |
| 712 | |
| 713 | // Create descriptor set for a uniform resource |
| 714 | XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; |
| 715 | descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; |
| 716 | descriptorInfo.slots = 1; |
| 717 | |
| 718 | // create a descriptor set with a single slot |
| 719 | err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); |
| 720 | ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; |
| 721 | |
| 722 | // bind memory to the descriptor set |
| 723 | err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); |
| 724 | |
| 725 | // write the constant buffer view to the descriptor set |
| 726 | xglBeginDescriptorSetUpdate( m_rsrcDescSet ); |
| 727 | xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); |
| 728 | xglEndDescriptorSetUpdate( m_rsrcDescSet ); |
| 729 | |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 730 | static const char *vertShaderText = |
| 731 | "#version 130\n" |
| 732 | "vec2 vertices[3];\n" |
| 733 | "void main() {\n" |
| 734 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 735 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 736 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 737 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 738 | "}\n"; |
Courtney Goeltzenleuchter | d6f7589 | 2014-10-06 12:45:37 -0600 | [diff] [blame] | 739 | static const char *vertShader2 = |
Steve K | 42652ba | 2014-10-07 10:44:41 -0600 | [diff] [blame] | 740 | "#version 130\n" |
Courtney Goeltzenleuchter | d6f7589 | 2014-10-06 12:45:37 -0600 | [diff] [blame] | 741 | "out vec4 color;\n" |
| 742 | "out vec4 scale;\n" |
| 743 | "void main() {\n" |
| 744 | " vec2 vertices[3];" |
| 745 | " vertices[0] = vec2(-0.5, -0.5);\n" |
| 746 | " vertices[1] = vec2( 0.5, -0.5);\n" |
| 747 | " vertices[2] = vec2( 0.5, 0.5);\n" |
| 748 | " vec4 colors[3];\n" |
| 749 | " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 750 | " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 751 | " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame^] | 752 | " color = colors[int(mod(gl_VertexID, 3))];\n" |
| 753 | " scale = vec4(0.5, 0.5, 0.5, 1.0);\n" |
| 754 | " gl_Position = vec4(vertices[int(mod(gl_VertexID, 3))], 0.0, 1.0);\n" |
Courtney Goeltzenleuchter | d6f7589 | 2014-10-06 12:45:37 -0600 | [diff] [blame] | 755 | "}\n"; |
| 756 | |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 757 | |
Cody Northrop | 350727b | 2014-10-06 15:42:00 -0600 | [diff] [blame^] | 758 | |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 759 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, |
Courtney Goeltzenleuchter | d6f7589 | 2014-10-06 12:45:37 -0600 | [diff] [blame] | 760 | vertShader2, vs)); |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 761 | |
| 762 | vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 763 | vs_stage.pNext = XGL_NULL_HANDLE; |
| 764 | vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX; |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 765 | vs_stage.shader.shader = *vs; |
Jon Ashburn | f93c1bd | 2014-10-20 13:37:31 -0600 | [diff] [blame] | 766 | for (unsigned int i = 0; i < XGL_MAX_DESCRIPTOR_SETS; i++) |
| 767 | vs_stage.shader.descriptorSetMapping[i].descriptorCount = 0; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 768 | vs_stage.shader.linkConstBufferCount = 0; |
| 769 | vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
Chia-I Wu | 3c89e4e | 2014-08-23 17:47:45 +0800 | [diff] [blame] | 770 | vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 771 | vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 772 | |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 773 | static const char *fragShaderText = |
| 774 | "#version 130\n" |
Steve K | 147013a | 2014-10-07 10:57:33 -0600 | [diff] [blame] | 775 | "in vec4 color;\n" |
| 776 | "in vec4 scale;\n" |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 777 | "void main() {\n" |
Steve K | 147013a | 2014-10-07 10:57:33 -0600 | [diff] [blame] | 778 | " gl_FragColor = color * scale;\n" |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 779 | "}\n"; |
Courtney Goeltzenleuchter | d6f7589 | 2014-10-06 12:45:37 -0600 | [diff] [blame] | 780 | static const char *fragShader2 = |
| 781 | "#version 430\n" |
| 782 | "in vec4 color;\n" |
| 783 | "in vec4 scale;\n" |
| 784 | "layout(location = 0) uniform vec4 foo;\n" |
| 785 | "void main() {\n" |
| 786 | " gl_FragColor = color * scale + foo;\n" |
| 787 | "}\n"; |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 788 | |
| 789 | ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, |
Steve K | 147013a | 2014-10-07 10:57:33 -0600 | [diff] [blame] | 790 | fragShaderText, ps)); |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 791 | |
| 792 | ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 793 | ps_stage.pNext = &vs_stage; |
| 794 | ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 795 | ps_stage.shader.shader = *ps; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 796 | // TODO: Do we need a descriptor set mapping for fragment? |
Jon Ashburn | f93c1bd | 2014-10-20 13:37:31 -0600 | [diff] [blame] | 797 | for (unsigned int i = 0; i < XGL_MAX_DESCRIPTOR_SETS; i++) |
| 798 | ps_stage.shader.descriptorSetMapping[i].descriptorCount = 0; |
Cody Northrop | 2c4c6d9 | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 799 | |
| 800 | const int slots = 1; |
| 801 | XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( slots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); |
| 802 | slotInfo[0].shaderEntityIndex = 0; |
| 803 | slotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; |
| 804 | |
| 805 | ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; |
| 806 | ps_stage.shader.descriptorSetMapping[0].descriptorCount = 1; |
| 807 | |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 808 | ps_stage.shader.linkConstBufferCount = 0; |
| 809 | ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
Chia-I Wu | 3c89e4e | 2014-08-23 17:47:45 +0800 | [diff] [blame] | 810 | ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED; |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 811 | ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0; |
| 812 | |
| 813 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = { |
| 814 | XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType |
| 815 | &ps_stage, // pNext |
| 816 | XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY |
| 817 | XGL_FALSE, // disableVertexReuse |
| 818 | XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION |
| 819 | XGL_FALSE, // primitiveRestartEnable |
| 820 | 0 // primitiveRestartIndex |
| 821 | }; |
| 822 | |
| 823 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = { |
| 824 | XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO, |
| 825 | &ia_state, |
| 826 | XGL_FALSE, // depthClipEnable |
| 827 | XGL_FALSE, // rasterizerDiscardEnable |
| 828 | 1.0 // pointSize |
| 829 | }; |
| 830 | |
| 831 | XGL_PIPELINE_CB_STATE cb_state = { |
| 832 | XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO, |
| 833 | &rs_state, |
| 834 | XGL_FALSE, // alphaToCoverageEnable |
| 835 | XGL_FALSE, // dualSourceBlendEnable |
| 836 | XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP |
| 837 | { // XGL_PIPELINE_CB_ATTACHMENT_STATE |
| 838 | { |
| 839 | XGL_FALSE, // blendEnable |
Chia-I Wu | f5d5c1a | 2014-08-27 15:02:10 +0800 | [diff] [blame] | 840 | {XGL_CH_FMT_R8G8B8A8, XGL_NUM_FMT_UNORM}, // XGL_FORMAT |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 841 | 0xF // channelWriteMask |
| 842 | } |
| 843 | } |
| 844 | }; |
| 845 | |
| 846 | // TODO: Should take depth buffer format from queried formats |
| 847 | XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = { |
| 848 | XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO, |
| 849 | &cb_state, |
| 850 | {XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT |
| 851 | }; |
| 852 | |
| 853 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 854 | info.pNext = &db_state; |
| 855 | info.flags = 0; |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 856 | |
| 857 | err = xglCreateGraphicsPipeline(device(), &info, pipeline); |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 858 | ASSERT_XGL_SUCCESS(err); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 859 | } |
Courtney Goeltzenleuchter | ac8bd17 | 2014-08-20 15:28:00 -0600 | [diff] [blame] | 860 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 861 | void XglRenderTest::GenerateClearAndPrepareBufferCmds(XglImage *renderTarget) |
| 862 | { |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 863 | // whatever we want to do, we do it to the whole buffer |
| 864 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 865 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 866 | srRange.baseMipLevel = 0; |
| 867 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 868 | srRange.baseArraySlice = 0; |
| 869 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 870 | |
| 871 | // prepare the whole back buffer for clear |
| 872 | XGL_IMAGE_STATE_TRANSITION transitionToClear = {}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 873 | transitionToClear.image = renderTarget->image(); |
| 874 | transitionToClear.oldState = renderTarget->state(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 875 | transitionToClear.newState = XGL_IMAGE_STATE_CLEAR; |
| 876 | transitionToClear.subresourceRange = srRange; |
| 877 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear ); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 878 | renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 879 | |
| 880 | // clear the back buffer to dark grey |
| 881 | XGL_UINT clearColor[4] = {64, 64, 64, 0}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 882 | xglCmdClearColorImageRaw( m_cmdBuffer, renderTarget->image(), clearColor, 1, &srRange ); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 883 | |
| 884 | // prepare back buffer for rendering |
| 885 | XGL_IMAGE_STATE_TRANSITION transitionToRender = {}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 886 | transitionToRender.image = renderTarget->image(); |
| 887 | transitionToRender.oldState = renderTarget->state(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 888 | transitionToRender.newState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 889 | transitionToRender.subresourceRange = srRange; |
| 890 | xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender ); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 891 | renderTarget->state(( XGL_IMAGE_STATE ) transitionToClear.newState); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 892 | } |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 893 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 894 | void XglRenderTest::GenerateBindRenderTargetCmd(XglImage *renderTarget) |
| 895 | { |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 896 | // bind render target |
| 897 | XGL_COLOR_ATTACHMENT_BIND_INFO colorBind = {}; |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 898 | colorBind.view = renderTarget->targetView(); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 899 | colorBind.colorAttachmentState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL; |
| 900 | xglCmdBindAttachments(m_cmdBuffer, 1, &colorBind, NULL ); |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 901 | } |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 902 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 903 | void XglRenderTest::GenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline) |
| 904 | { |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 905 | // set all states |
| 906 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_RASTER, m_stateRaster ); |
| 907 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_VIEWPORT, m_stateViewport ); |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 908 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_COLOR_BLEND, m_colorBlend); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 909 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil ); |
| 910 | xglCmdBindStateObject( m_cmdBuffer, XGL_STATE_BIND_MSAA, m_stateMsaa ); |
| 911 | |
| 912 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic memory view) |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 913 | xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, *pipeline ); |
| 914 | } |
| 915 | |
| 916 | void XglRenderTest::DrawRotatedTriangleTest() |
| 917 | { |
| 918 | // TODO : This test will pass a matrix into VS to affect triangle orientation. |
| 919 | } |
| 920 | |
| 921 | void XglRenderTest::DrawTriangleTest() |
| 922 | { |
| 923 | XGL_PIPELINE pipeline; |
| 924 | XGL_SHADER vs, ps; |
| 925 | XGL_RESULT err; |
| 926 | int width = 256, height = 256; |
| 927 | CreateDefaultPipeline(&pipeline, &vs, &ps, width, height); |
| 928 | //ASSERT_XGL_SUCCESS(err); |
| 929 | |
| 930 | err = m_device->AllocAndBindGpuMemory(pipeline, "Pipeline", &m_pipe_mem); |
| 931 | ASSERT_XGL_SUCCESS(err); |
| 932 | |
| 933 | /* |
| 934 | * Shaders are now part of the pipeline, don't need these anymore |
| 935 | */ |
| 936 | ASSERT_XGL_SUCCESS(xglDestroyObject(ps)); |
| 937 | ASSERT_XGL_SUCCESS(xglDestroyObject(vs)); |
| 938 | |
| 939 | XGL_QUERY_POOL query; |
| 940 | XGL_GPU_MEMORY query_mem; |
| 941 | ASSERT_NO_FATAL_FAILURE(CreateQueryPool(XGL_QUERY_PIPELINE_STATISTICS, 1, &query, &query_mem)); |
| 942 | |
| 943 | XglImage *renderTarget; |
| 944 | XGL_FORMAT fmt = { |
| 945 | XGL_CH_FMT_R8G8B8A8, |
| 946 | XGL_NUM_FMT_UNORM |
| 947 | }; |
| 948 | ASSERT_NO_FATAL_FAILURE(m_device->CreateImage(width, height, fmt, |
| 949 | XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | |
| 950 | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 951 | &renderTarget)); |
| 952 | |
| 953 | // Build command buffer |
| 954 | err = xglBeginCommandBuffer(m_cmdBuffer, 0); |
| 955 | ASSERT_XGL_SUCCESS(err); |
| 956 | |
| 957 | GenerateClearAndPrepareBufferCmds(renderTarget); |
| 958 | GenerateBindRenderTargetCmd(renderTarget); |
| 959 | GenerateBindStateAndPipelineCmds(&pipeline); |
| 960 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 961 | // xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
Cody Northrop | 2c4c6d9 | 2014-10-01 14:03:25 -0600 | [diff] [blame] | 962 | xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 ); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 963 | // xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView ); |
| 964 | |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 965 | xglCmdResetQueryPool(m_cmdBuffer, query, 0, 1); |
| 966 | xglCmdBeginQuery(m_cmdBuffer, query, 0, 0); |
| 967 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 968 | // render the cube |
| 969 | xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 ); |
| 970 | |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 971 | xglCmdEndQuery(m_cmdBuffer, query, 0); |
| 972 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 973 | // prepare the back buffer for present |
| 974 | // XGL_IMAGE_STATE_TRANSITION transitionToPresent = {}; |
| 975 | // transitionToPresent.image = m_image; |
| 976 | // transitionToPresent.oldState = m_image_state; |
| 977 | // transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT; |
| 978 | // transitionToPresent.subresourceRange = srRange; |
| 979 | // xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent ); |
| 980 | // m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState; |
| 981 | |
| 982 | // finalize recording of the command buffer |
| 983 | err = xglEndCommandBuffer( m_cmdBuffer ); |
| 984 | ASSERT_XGL_SUCCESS( err ); |
| 985 | |
| 986 | // this command buffer only uses the vertex buffer memory |
| 987 | m_numMemRefs = 0; |
| 988 | // m_memRefs[0].flags = 0; |
| 989 | // m_memRefs[0].mem = m_vtxBufferMemory; |
| 990 | |
| 991 | // submit the command buffer to the universal queue |
| 992 | err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL ); |
| 993 | ASSERT_XGL_SUCCESS( err ); |
| 994 | |
Chia-I Wu | f34ac50 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 995 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 996 | ASSERT_XGL_SUCCESS( err ); |
| 997 | |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 998 | // Wait for work to finish before cleaning up. |
| 999 | xglDeviceWaitIdle(m_device->device()); |
| 1000 | |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 1001 | XGL_PIPELINE_STATISTICS_DATA stats; |
Jon Ashburn | b8e4389 | 2014-09-25 14:36:58 -0600 | [diff] [blame] | 1002 | XGL_SIZE stats_size = sizeof(stats); |
Chia-I Wu | f070ec1 | 2014-08-30 23:58:36 +0800 | [diff] [blame] | 1003 | err = xglGetQueryPoolResults(query, 0, 1, &stats_size, &stats); |
| 1004 | ASSERT_XGL_SUCCESS( err ); |
| 1005 | ASSERT_EQ(stats_size, sizeof(stats)); |
| 1006 | |
| 1007 | ASSERT_EQ(stats.vsInvocations, 3); |
| 1008 | ASSERT_EQ(stats.cPrimitives, 1); |
| 1009 | ASSERT_EQ(stats.cInvocations, 1); |
| 1010 | |
| 1011 | DestroyQueryPool(query, query_mem); |
| 1012 | |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 1013 | const ::testing::TestInfo* const test_info = |
| 1014 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 1015 | |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 1016 | // renderTarget->WritePPM(test_info->test_case_name()); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 1017 | // m_screen.Display(renderTarget, m_image_mem); |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 1018 | RecordImage(renderTarget); |
Chia-I Wu | f34ac50 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 1019 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 1020 | ASSERT_XGL_SUCCESS(xglDestroyObject(pipeline)); |
Courtney Goeltzenleuchter | 68cfe61 | 2014-08-26 18:16:41 -0600 | [diff] [blame] | 1021 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_cmdBuffer)); |
| 1022 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateRaster)); |
| 1023 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateViewport)); |
| 1024 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateDepthStencil)); |
| 1025 | ASSERT_XGL_SUCCESS(xglDestroyObject(m_stateMsaa)); |
Courtney Goeltzenleuchter | 04814f8 | 2014-09-01 16:37:18 -0600 | [diff] [blame] | 1026 | free(renderTarget); |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 1027 | } |
| 1028 | |
Chia-I Wu | f34ac50 | 2014-08-27 14:58:05 +0800 | [diff] [blame] | 1029 | |
Courtney Goeltzenleuchter | a948d84 | 2014-08-22 16:27:58 -0600 | [diff] [blame] | 1030 | TEST_F(XglRenderTest, TestDrawTriangle) { |
| 1031 | DrawTriangleTest(); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 1032 | } |
| 1033 | |
Tobin Ehlis | 34e0e44 | 2014-10-07 14:41:29 -0600 | [diff] [blame] | 1034 | TEST_F(XglRenderTest, TestDrawRotatedTriangle) { |
| 1035 | DrawRotatedTriangleTest(); |
| 1036 | } |
| 1037 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 1038 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 1039 | int result; |
| 1040 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 1041 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | 2802979 | 2014-09-04 16:26:02 -0600 | [diff] [blame] | 1042 | XglTestFramework::InitArgs(&argc, argv); |
| 1043 | |
| 1044 | result = RUN_ALL_TESTS(); |
| 1045 | |
| 1046 | XglTestFramework::Finish(); |
| 1047 | return result; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 1048 | } |