Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 1 | /* |
| 2 | * XGL Tests |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | */ |
| 27 | |
| 28 | #ifndef XGLRENDERFRAMEWORK_H |
| 29 | #define XGLRENDERFRAMEWORK_H |
| 30 | |
| 31 | #include "xgltestframework.h" |
| 32 | |
| 33 | class XglRenderFramework : public XglTestFramework |
| 34 | { |
| 35 | public: |
| 36 | XglRenderFramework(); |
| 37 | ~XglRenderFramework(); |
| 38 | |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 39 | XGL_DEVICE device() {return m_device->device();} |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 40 | XGL_PHYSICAL_GPU gpu() {return objs[0];} |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 41 | void InitViewport(float width, float height); |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 42 | void InitViewport(); |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 43 | void InitRenderTarget(); |
| 44 | void InitFramework(); |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 45 | void ShutdownFramework(); |
| 46 | void InitState(); |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 47 | void GenerateClearAndPrepareBufferCmds(); |
| 48 | void GenerateBindRenderTargetCmd(); |
Tony Barbour | f43b698 | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 49 | void GenerateBindStateAndPipelineCmds(); |
| 50 | |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 51 | |
| 52 | protected: |
| 53 | XGL_APPLICATION_INFO app_info; |
| 54 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 55 | XGL_UINT gpu_count; |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 56 | XglDevice *m_device; |
| 57 | XGL_CMD_BUFFER m_cmdBuffer; |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 58 | XGL_MEMORY_REF m_memRefs[5]; |
| 59 | XGL_RASTER_STATE_OBJECT m_stateRaster; |
| 60 | XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend; |
| 61 | XGL_VIEWPORT_STATE_OBJECT m_stateViewport; |
| 62 | XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil; |
| 63 | XGL_MSAA_STATE_OBJECT m_stateMsaa; |
Chia-I Wu | e774880 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 64 | XglImage *m_renderTargets[XGL_MAX_COLOR_ATTACHMENTS]; |
| 65 | XGL_UINT m_renderTargetCount; |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 66 | XGL_FLOAT m_width, m_height; |
| 67 | XGL_FORMAT m_render_target_fmt; |
Chia-I Wu | e774880 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 68 | XGL_COLOR_ATTACHMENT_BIND_INFO m_colorBindings[XGL_MAX_COLOR_ATTACHMENTS]; |
Courtney Goeltzenleuchter | b66e7de | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 69 | XGL_DEPTH_STENCIL_BIND_INFO m_depthStencilBinding; |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * SetUp and TearDown are called by the Google Test framework |
| 73 | * to initialize a test framework based on this class. |
| 74 | */ |
| 75 | virtual void SetUp() { |
| 76 | XGL_RESULT err; |
| 77 | |
| 78 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 79 | this->app_info.pNext = NULL; |
| 80 | this->app_info.pAppName = (const XGL_CHAR *) "base"; |
| 81 | this->app_info.appVersion = 1; |
| 82 | this->app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 83 | this->app_info.engineVersion = 1; |
| 84 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 85 | |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 86 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
| 87 | MAX_GPUS, &this->gpu_count, objs); |
| 88 | ASSERT_XGL_SUCCESS(err); |
Jon Ashburn | 19733c9 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 89 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 90 | |
| 91 | m_device = new XglDevice(0, objs[0]); |
| 92 | m_device->get_device_queue(); |
| 93 | } |
| 94 | |
| 95 | virtual void TearDown() { |
| 96 | xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE); |
| 97 | } |
| 98 | }; |
| 99 | |
Tony Barbour | 4f3e5a6 | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 100 | class XglCommandBufferObj |
| 101 | { |
| 102 | public: |
| 103 | XglCommandBufferObj(XglDevice *device); |
| 104 | ~XglCommandBufferObj(); |
Tony Barbour | e8f1416 | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 105 | XGL_CMD_BUFFER GetBufferHandle(); |
| 106 | XGL_RESULT BeginCommandBuffer(XGL_FLAGS flags); |
| 107 | XGL_RESULT EndCommandBuffer(); |
| 108 | void PrepareMemoryRegions(int transitionCount, XGL_MEMORY_STATE_TRANSITION *transitionPtr); |
Tony Barbour | 4f3e5a6 | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 109 | |
| 110 | protected: |
| 111 | XglDevice *m_device; |
| 112 | XGL_CMD_BUFFER_CREATE_INFO m_cmdInfo; |
| 113 | XGL_CMD_BUFFER m_cmdBuffer; |
| 114 | |
| 115 | }; |
| 116 | |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 117 | class XglConstantBufferObj |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 118 | { |
| 119 | public: |
Courtney Goeltzenleuchter | ea2db0d | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 120 | XglConstantBufferObj(XglDevice *device); |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 121 | XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data); |
Tony Barbour | 74ca8af | 2014-12-03 16:23:43 -0700 | [diff] [blame] | 122 | ~XglConstantBufferObj(); |
Tony Barbour | e615204 | 2014-12-10 17:40:15 -0700 | [diff] [blame] | 123 | void SetMemoryState(XGL_MEMORY_STATE newState); |
Courtney Goeltzenleuchter | 7715bc4 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 124 | void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding); |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 125 | XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView; |
| 126 | XGL_GPU_MEMORY m_constantBufferMem; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 127 | |
| 128 | protected: |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 129 | XglDevice *m_device; |
| 130 | int m_numVertices; |
| 131 | int m_stride; |
Tony Barbour | 9f47dc7 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 132 | XglCommandBufferObj *m_commandBuffer; |
| 133 | XGL_FENCE m_fence; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 134 | }; |
Courtney Goeltzenleuchter | fa834c9 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 135 | |
| 136 | class XglIndexBufferObj : public XglConstantBufferObj |
| 137 | { |
| 138 | public: |
| 139 | XglIndexBufferObj(XglDevice *device); |
| 140 | void CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE dataFormat, const void* data); |
| 141 | void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset); |
Tony Barbour | 140a59f | 2014-12-17 10:57:58 -0700 | [diff] [blame^] | 142 | XGL_INDEX_TYPE GetIndexType(); |
Courtney Goeltzenleuchter | fa834c9 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 143 | |
| 144 | protected: |
| 145 | XGL_INDEX_TYPE m_indexType; |
| 146 | }; |
| 147 | |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 148 | class XglTextureObj |
| 149 | { |
| 150 | public: |
| 151 | XglTextureObj(XglDevice *device); |
Tony Barbour | 2cb6bf5 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 152 | ~XglTextureObj(); |
Tony Barbour | 84d3d02 | 2014-11-21 17:17:49 -0700 | [diff] [blame] | 153 | void ChangeColors(uint32_t color1, uint32_t color2); |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 154 | XGL_IMAGE m_texture; |
| 155 | XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo; |
| 156 | XGL_GPU_MEMORY m_textureMem; |
| 157 | |
| 158 | protected: |
| 159 | XglDevice *m_device; |
| 160 | XGL_IMAGE_VIEW m_textureView; |
Tony Barbour | 84d3d02 | 2014-11-21 17:17:49 -0700 | [diff] [blame] | 161 | int m_texHeight; |
| 162 | int m_texWidth; |
| 163 | int m_rowPitch; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 164 | |
| 165 | }; |
| 166 | |
| 167 | class XglSamplerObj |
| 168 | { |
| 169 | public: |
| 170 | XglSamplerObj(XglDevice *device); |
Tony Barbour | 2cb6bf5 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 171 | ~XglSamplerObj(); |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 172 | XGL_SAMPLER m_sampler; |
| 173 | |
| 174 | protected: |
| 175 | XGL_SAMPLER_CREATE_INFO m_samplerCreateInfo; |
| 176 | XglDevice *m_device; |
| 177 | |
| 178 | }; |
| 179 | |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 180 | class XglDescriptorSetObj |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 181 | { |
| 182 | public: |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 183 | XglDescriptorSetObj(XglDevice *device); |
Tony Barbour | 342ae3b | 2014-12-03 13:59:18 -0700 | [diff] [blame] | 184 | ~XglDescriptorSetObj(); |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 185 | void AttachMemoryView(XglConstantBufferObj* constantBuffer); |
| 186 | void AttachSampler( XglSamplerObj* sampler); |
| 187 | void AttachImageView( XglTextureObj* texture); |
| 188 | void BindCommandBuffer(XGL_CMD_BUFFER commandBuffer); |
| 189 | XGL_DESCRIPTOR_SLOT_INFO * GetSlotInfo(vector<int>slots, vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types, vector<XGL_OBJECT>objs ); |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 190 | |
| 191 | protected: |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 192 | XGL_DESCRIPTOR_SET_CREATE_INFO m_descriptorInfo; |
| 193 | XGL_DESCRIPTOR_SET m_rsrcDescSet; |
| 194 | XGL_GPU_MEMORY m_descriptor_set_mem; |
| 195 | XglDevice *m_device; |
| 196 | XGL_DESCRIPTOR_SLOT_INFO *m_slotInfo; |
| 197 | int m_nextSlot; |
| 198 | vector<int> m_memorySlots; |
| 199 | vector<XGL_MEMORY_VIEW_ATTACH_INFO*> m_memoryViews; |
| 200 | vector<int> m_samplerSlots; |
| 201 | vector<XGL_SAMPLER*> m_samplers; |
| 202 | vector<int> m_imageSlots; |
| 203 | vector<XGL_IMAGE_VIEW_ATTACH_INFO*> m_imageViews; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 204 | }; |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 205 | |
| 206 | |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 207 | class XglShaderObj |
| 208 | { |
| 209 | public: |
Tony Barbour | f43b698 | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 210 | XglShaderObj(XglDevice *device, const char * shaderText, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework); |
Tony Barbour | 2cb6bf5 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 211 | ~XglShaderObj(); |
Tony Barbour | bf67847 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 212 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* GetStageCreateInfo(XglDescriptorSetObj *descriptorSet); |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 213 | void BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer); |
| 214 | void BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture); |
| 215 | void BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler); |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 216 | |
| 217 | protected: |
| 218 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO stage_info; |
| 219 | XGL_SHADER m_shader; |
| 220 | XGL_PIPELINE_SHADER_STAGE m_stage; |
| 221 | XglDevice *m_device; |
| 222 | vector<int> m_memSlots; |
| 223 | vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_memTypes; |
| 224 | vector<XGL_OBJECT> m_memObjs; |
| 225 | vector<int> m_samplerSlots; |
| 226 | vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_samplerTypes; |
| 227 | vector<XGL_OBJECT> m_samplerObjs; |
| 228 | vector<int> m_imageSlots; |
| 229 | vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_imageTypes; |
| 230 | vector<XGL_OBJECT> m_imageObjs; |
| 231 | |
| 232 | }; |
| 233 | |
| 234 | class XglPipelineObj |
| 235 | { |
| 236 | public: |
| 237 | XglPipelineObj(XglDevice *device); |
Tony Barbour | 2cb6bf5 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 238 | ~XglPipelineObj(); |
Tony Barbour | bf67847 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 239 | void BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet); |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 240 | void AddShader(XglShaderObj* shaderObj); |
| 241 | void AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count); |
| 242 | void AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count); |
| 243 | void AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding); |
Chia-I Wu | e774880 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 244 | void SetColorAttachment(XGL_UINT binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att); |
Tony Barbour | e7f2c7c | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 245 | void CreateXGLPipeline(XglDescriptorSetObj *descriptorSet); |
| 246 | XGL_PIPELINE GetPipelineHandle(); |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 247 | |
| 248 | protected: |
| 249 | XGL_PIPELINE m_pipeline; |
| 250 | XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO m_vi_state; |
| 251 | XGL_PIPELINE_IA_STATE_CREATE_INFO m_ia_state; |
| 252 | XGL_PIPELINE_RS_STATE_CREATE_INFO m_rs_state; |
| 253 | XGL_PIPELINE_CB_STATE m_cb_state; |
| 254 | XGL_PIPELINE_DB_STATE_CREATE_INFO m_db_state; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 255 | XGL_GPU_MEMORY m_pipe_mem; |
| 256 | XglDevice *m_device; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 257 | vector<XglShaderObj*> m_shaderObjs; |
| 258 | vector<XglConstantBufferObj*> m_vertexBufferObjs; |
| 259 | vector<int> m_vertexBufferBindings; |
| 260 | int m_vertexBufferCount; |
| 261 | |
| 262 | }; |
| 263 | class XglMemoryRefManager{ |
| 264 | public: |
| 265 | XglMemoryRefManager(); |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 266 | void AddMemoryRef(XglConstantBufferObj* constantBuffer); |
| 267 | void AddMemoryRef(XglTextureObj *texture); |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 268 | XGL_MEMORY_REF* GetMemoryRefList(); |
| 269 | int GetNumRefs(); |
| 270 | |
| 271 | protected: |
| 272 | int m_numRefs; |
| 273 | vector<XGL_GPU_MEMORY*> m_bufferObjs; |
| 274 | |
| 275 | }; |
| 276 | |
| 277 | |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 278 | #endif // XGLRENDERFRAMEWORK_H |