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 | |
| 39 | void CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots, |
| 40 | XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem); |
| 41 | void DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem); |
| 42 | |
| 43 | XGL_DEVICE device() {return m_device->device();} |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 44 | XGL_PHYSICAL_GPU gpu() {return objs[0];} |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 45 | void CreateShader(XGL_PIPELINE_SHADER_STAGE stage, const char *shader_code, XGL_SHADER *pshader); |
| 46 | void InitPipeline(); |
| 47 | void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices ); |
| 48 | void InitConstantBuffer( int constantCount, int constantSize, const void* data ); |
Courtney Goeltzenleuchter | 34b8177 | 2014-10-10 18:04:39 -0600 | [diff] [blame] | 49 | void UpdateConstantBuffer(const void* data); |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 50 | void InitViewport(float width, float height); |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 51 | void InitViewport(); |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 52 | void InitRenderTarget(); |
| 53 | void InitFramework(); |
Courtney Goeltzenleuchter | cb5a89c | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 54 | void ShutdownFramework(); |
| 55 | void InitState(); |
Courtney Goeltzenleuchter | e540934 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 56 | void CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); |
| 57 | void GenerateClearAndPrepareBufferCmds(); |
| 58 | void GenerateBindRenderTargetCmd(); |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 59 | void GenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline); |
| 60 | |
| 61 | protected: |
| 62 | XGL_APPLICATION_INFO app_info; |
| 63 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 64 | XGL_UINT gpu_count; |
| 65 | XGL_GPU_MEMORY m_descriptor_set_mem; |
| 66 | XGL_GPU_MEMORY m_pipe_mem; |
| 67 | XglDevice *m_device; |
| 68 | XGL_CMD_BUFFER m_cmdBuffer; |
| 69 | XGL_UINT32 m_numVertices; |
| 70 | XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView; |
| 71 | XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView; |
| 72 | XGL_GPU_MEMORY m_vtxBufferMem; |
| 73 | XGL_GPU_MEMORY m_constantBufferMem; |
| 74 | XGL_UINT32 m_numMemRefs; |
| 75 | XGL_MEMORY_REF m_memRefs[5]; |
| 76 | XGL_RASTER_STATE_OBJECT m_stateRaster; |
| 77 | XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend; |
| 78 | XGL_VIEWPORT_STATE_OBJECT m_stateViewport; |
| 79 | XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil; |
| 80 | XGL_MSAA_STATE_OBJECT m_stateMsaa; |
| 81 | XGL_DESCRIPTOR_SET m_rsrcDescSet; |
| 82 | XglImage *m_renderTarget; |
| 83 | XGL_FLOAT m_width, m_height; |
| 84 | XGL_FORMAT m_render_target_fmt; |
Courtney Goeltzenleuchter | b66e7de | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 85 | XGL_COLOR_ATTACHMENT_BIND_INFO m_colorBinding; |
| 86 | XGL_DEPTH_STENCIL_BIND_INFO m_depthStencilBinding; |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * SetUp and TearDown are called by the Google Test framework |
| 90 | * to initialize a test framework based on this class. |
| 91 | */ |
| 92 | virtual void SetUp() { |
| 93 | XGL_RESULT err; |
| 94 | |
| 95 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 96 | this->app_info.pNext = NULL; |
| 97 | this->app_info.pAppName = (const XGL_CHAR *) "base"; |
| 98 | this->app_info.appVersion = 1; |
| 99 | this->app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 100 | this->app_info.engineVersion = 1; |
| 101 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 102 | |
| 103 | memset(&m_vtxBufferView, 0, sizeof(m_vtxBufferView)); |
| 104 | m_vtxBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO; |
| 105 | |
| 106 | memset(&m_constantBufferView, 0, sizeof(m_constantBufferView)); |
| 107 | m_constantBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO; |
| 108 | |
| 109 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
| 110 | MAX_GPUS, &this->gpu_count, objs); |
| 111 | ASSERT_XGL_SUCCESS(err); |
Jon Ashburn | 19733c9 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 112 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 113 | |
| 114 | m_device = new XglDevice(0, objs[0]); |
| 115 | m_device->get_device_queue(); |
| 116 | } |
| 117 | |
| 118 | virtual void TearDown() { |
| 119 | xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE); |
| 120 | } |
| 121 | }; |
| 122 | |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 123 | class XglConstantBufferObj |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 124 | { |
| 125 | public: |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 126 | XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data); |
| 127 | void SetMemoryState(XGL_CMD_BUFFER cmdBuffer, XGL_MEMORY_STATE newState); |
| 128 | XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView; |
| 129 | XGL_GPU_MEMORY m_constantBufferMem; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 130 | |
| 131 | protected: |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 132 | XglDevice *m_device; |
| 133 | int m_numVertices; |
| 134 | int m_stride; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 135 | }; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 136 | class XglTextureObj |
| 137 | { |
| 138 | public: |
| 139 | XglTextureObj(XglDevice *device); |
Tony Barbour | 84d3d02 | 2014-11-21 17:17:49 -0700 | [diff] [blame] | 140 | void ChangeColors(uint32_t color1, uint32_t color2); |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 141 | XGL_IMAGE m_texture; |
| 142 | XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo; |
| 143 | XGL_GPU_MEMORY m_textureMem; |
| 144 | |
| 145 | protected: |
| 146 | XglDevice *m_device; |
| 147 | XGL_IMAGE_VIEW m_textureView; |
Tony Barbour | 84d3d02 | 2014-11-21 17:17:49 -0700 | [diff] [blame] | 148 | int m_texHeight; |
| 149 | int m_texWidth; |
| 150 | int m_rowPitch; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 151 | |
| 152 | }; |
| 153 | |
| 154 | class XglSamplerObj |
| 155 | { |
| 156 | public: |
| 157 | XglSamplerObj(XglDevice *device); |
| 158 | XGL_SAMPLER m_sampler; |
| 159 | |
| 160 | protected: |
| 161 | XGL_SAMPLER_CREATE_INFO m_samplerCreateInfo; |
| 162 | XglDevice *m_device; |
| 163 | |
| 164 | }; |
| 165 | |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 166 | class XglDescriptorSetObj |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 167 | { |
| 168 | public: |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 169 | XglDescriptorSetObj(XglDevice *device); |
| 170 | void AttachMemoryView(XglConstantBufferObj* constantBuffer); |
| 171 | void AttachSampler( XglSamplerObj* sampler); |
| 172 | void AttachImageView( XglTextureObj* texture); |
| 173 | void BindCommandBuffer(XGL_CMD_BUFFER commandBuffer); |
| 174 | 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] | 175 | |
| 176 | protected: |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 177 | XGL_DESCRIPTOR_SET_CREATE_INFO m_descriptorInfo; |
| 178 | XGL_DESCRIPTOR_SET m_rsrcDescSet; |
| 179 | XGL_GPU_MEMORY m_descriptor_set_mem; |
| 180 | XglDevice *m_device; |
| 181 | XGL_DESCRIPTOR_SLOT_INFO *m_slotInfo; |
| 182 | int m_nextSlot; |
| 183 | vector<int> m_memorySlots; |
| 184 | vector<XGL_MEMORY_VIEW_ATTACH_INFO*> m_memoryViews; |
| 185 | vector<int> m_samplerSlots; |
| 186 | vector<XGL_SAMPLER*> m_samplers; |
| 187 | vector<int> m_imageSlots; |
| 188 | vector<XGL_IMAGE_VIEW_ATTACH_INFO*> m_imageViews; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 189 | }; |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 190 | |
| 191 | |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 192 | class XglShaderObj |
| 193 | { |
| 194 | public: |
| 195 | XglShaderObj(XglDevice *device, const char * shaderText, XGL_PIPELINE_SHADER_STAGE stage ); |
| 196 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* GetStageCreateInfo(XglDescriptorSetObj descriptorSet); |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 197 | void BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer); |
| 198 | void BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture); |
| 199 | void BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler); |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 200 | |
| 201 | protected: |
| 202 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO stage_info; |
| 203 | XGL_SHADER m_shader; |
| 204 | XGL_PIPELINE_SHADER_STAGE m_stage; |
| 205 | XglDevice *m_device; |
| 206 | vector<int> m_memSlots; |
| 207 | vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_memTypes; |
| 208 | vector<XGL_OBJECT> m_memObjs; |
| 209 | vector<int> m_samplerSlots; |
| 210 | vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_samplerTypes; |
| 211 | vector<XGL_OBJECT> m_samplerObjs; |
| 212 | vector<int> m_imageSlots; |
| 213 | vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_imageTypes; |
| 214 | vector<XGL_OBJECT> m_imageObjs; |
| 215 | |
| 216 | }; |
| 217 | |
| 218 | class XglPipelineObj |
| 219 | { |
| 220 | public: |
| 221 | XglPipelineObj(XglDevice *device); |
| 222 | void BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj descriptorSet); |
| 223 | void AddShader(XglShaderObj* shaderObj); |
| 224 | void AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count); |
| 225 | void AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count); |
| 226 | void AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding); |
| 227 | |
| 228 | protected: |
| 229 | XGL_PIPELINE m_pipeline; |
| 230 | XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO m_vi_state; |
| 231 | XGL_PIPELINE_IA_STATE_CREATE_INFO m_ia_state; |
| 232 | XGL_PIPELINE_RS_STATE_CREATE_INFO m_rs_state; |
| 233 | XGL_PIPELINE_CB_STATE m_cb_state; |
| 234 | XGL_PIPELINE_DB_STATE_CREATE_INFO m_db_state; |
| 235 | XGL_FORMAT m_render_target_format; |
| 236 | XGL_PIPELINE_CB_ATTACHMENT_STATE m_cb_attachment_state; |
| 237 | XGL_GPU_MEMORY m_pipe_mem; |
| 238 | XglDevice *m_device; |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 239 | vector<XglShaderObj*> m_shaderObjs; |
| 240 | vector<XglConstantBufferObj*> m_vertexBufferObjs; |
| 241 | vector<int> m_vertexBufferBindings; |
| 242 | int m_vertexBufferCount; |
| 243 | |
| 244 | }; |
| 245 | class XglMemoryRefManager{ |
| 246 | public: |
| 247 | XglMemoryRefManager(); |
Tony Barbour | 685f433 | 2014-11-20 15:06:56 -0700 | [diff] [blame] | 248 | void AddMemoryRef(XglConstantBufferObj* constantBuffer); |
| 249 | void AddMemoryRef(XglTextureObj *texture); |
Tony Barbour | f12bfb9 | 2014-11-19 16:33:11 -0700 | [diff] [blame] | 250 | XGL_MEMORY_REF* GetMemoryRefList(); |
| 251 | int GetNumRefs(); |
| 252 | |
| 253 | protected: |
| 254 | int m_numRefs; |
| 255 | vector<XGL_GPU_MEMORY*> m_bufferObjs; |
| 256 | |
| 257 | }; |
| 258 | |
| 259 | |
Courtney Goeltzenleuchter | 5744b97 | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 260 | #endif // XGLRENDERFRAMEWORK_H |