blob: 3149dee6f8675f17d1e78f8220f3b53ac92c9c2f [file] [log] [blame]
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -06001/*
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
33class XglRenderFramework : public XglTestFramework
34{
35public:
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 Ehlis3c26a542014-11-18 11:28:33 -070044 XGL_PHYSICAL_GPU gpu() {return objs[0];}
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060045 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 Goeltzenleuchter34b81772014-10-10 18:04:39 -060049 void UpdateConstantBuffer(const void* data);
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060050 void InitViewport(float width, float height);
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -060051 void InitViewport();
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060052 void InitRenderTarget();
53 void InitFramework();
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060054 void ShutdownFramework();
55 void InitState();
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -060056 void CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
57 void GenerateClearAndPrepareBufferCmds();
58 void GenerateBindRenderTargetCmd();
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060059 void GenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline);
Tony Barbourf43b6982014-11-25 13:18:32 -070060 void GenerateBindStateAndPipelineCmds();
61
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060062
63protected:
64 XGL_APPLICATION_INFO app_info;
65 XGL_PHYSICAL_GPU objs[MAX_GPUS];
66 XGL_UINT gpu_count;
67 XGL_GPU_MEMORY m_descriptor_set_mem;
68 XGL_GPU_MEMORY m_pipe_mem;
69 XglDevice *m_device;
70 XGL_CMD_BUFFER m_cmdBuffer;
71 XGL_UINT32 m_numVertices;
72 XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView;
73 XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView;
74 XGL_GPU_MEMORY m_vtxBufferMem;
75 XGL_GPU_MEMORY m_constantBufferMem;
76 XGL_UINT32 m_numMemRefs;
77 XGL_MEMORY_REF m_memRefs[5];
78 XGL_RASTER_STATE_OBJECT m_stateRaster;
79 XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend;
80 XGL_VIEWPORT_STATE_OBJECT m_stateViewport;
81 XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil;
82 XGL_MSAA_STATE_OBJECT m_stateMsaa;
83 XGL_DESCRIPTOR_SET m_rsrcDescSet;
84 XglImage *m_renderTarget;
85 XGL_FLOAT m_width, m_height;
86 XGL_FORMAT m_render_target_fmt;
Courtney Goeltzenleuchterb66e7de2014-10-22 14:12:38 -060087 XGL_COLOR_ATTACHMENT_BIND_INFO m_colorBinding;
88 XGL_DEPTH_STENCIL_BIND_INFO m_depthStencilBinding;
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060089
90 /*
91 * SetUp and TearDown are called by the Google Test framework
92 * to initialize a test framework based on this class.
93 */
94 virtual void SetUp() {
95 XGL_RESULT err;
96
97 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
98 this->app_info.pNext = NULL;
99 this->app_info.pAppName = (const XGL_CHAR *) "base";
100 this->app_info.appVersion = 1;
101 this->app_info.pEngineName = (const XGL_CHAR *) "unittest";
102 this->app_info.engineVersion = 1;
103 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
104
105 memset(&m_vtxBufferView, 0, sizeof(m_vtxBufferView));
106 m_vtxBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO;
107
108 memset(&m_constantBufferView, 0, sizeof(m_constantBufferView));
109 m_constantBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO;
110
111 err = xglInitAndEnumerateGpus(&app_info, NULL,
112 MAX_GPUS, &this->gpu_count, objs);
113 ASSERT_XGL_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -0700114 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -0600115
116 m_device = new XglDevice(0, objs[0]);
117 m_device->get_device_queue();
118 }
119
120 virtual void TearDown() {
121 xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE);
122 }
123};
124
Tony Barbour685f4332014-11-20 15:06:56 -0700125class XglConstantBufferObj
Tony Barbourf12bfb92014-11-19 16:33:11 -0700126{
127public:
Courtney Goeltzenleuchterea2db0d2014-12-04 15:18:47 -0700128 XglConstantBufferObj(XglDevice *device);
Tony Barbour685f4332014-11-20 15:06:56 -0700129 XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data);
130 void SetMemoryState(XGL_CMD_BUFFER cmdBuffer, XGL_MEMORY_STATE newState);
131 XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView;
132 XGL_GPU_MEMORY m_constantBufferMem;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700133
134protected:
Tony Barbour685f4332014-11-20 15:06:56 -0700135 XglDevice *m_device;
136 int m_numVertices;
137 int m_stride;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700138};
Tony Barbourf12bfb92014-11-19 16:33:11 -0700139class XglTextureObj
140{
141public:
142 XglTextureObj(XglDevice *device);
Tony Barbour84d3d022014-11-21 17:17:49 -0700143 void ChangeColors(uint32_t color1, uint32_t color2);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700144 XGL_IMAGE m_texture;
145 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
146 XGL_GPU_MEMORY m_textureMem;
147
148protected:
149 XglDevice *m_device;
150 XGL_IMAGE_VIEW m_textureView;
Tony Barbour84d3d022014-11-21 17:17:49 -0700151 int m_texHeight;
152 int m_texWidth;
153 int m_rowPitch;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700154
155};
156
157class XglSamplerObj
158{
159public:
160 XglSamplerObj(XglDevice *device);
161 XGL_SAMPLER m_sampler;
162
163protected:
164 XGL_SAMPLER_CREATE_INFO m_samplerCreateInfo;
165 XglDevice *m_device;
166
167};
168
Tony Barbour685f4332014-11-20 15:06:56 -0700169class XglDescriptorSetObj
Tony Barbourf12bfb92014-11-19 16:33:11 -0700170{
171public:
Tony Barbour685f4332014-11-20 15:06:56 -0700172 XglDescriptorSetObj(XglDevice *device);
173 void AttachMemoryView(XglConstantBufferObj* constantBuffer);
174 void AttachSampler( XglSamplerObj* sampler);
175 void AttachImageView( XglTextureObj* texture);
176 void BindCommandBuffer(XGL_CMD_BUFFER commandBuffer);
177 XGL_DESCRIPTOR_SLOT_INFO * GetSlotInfo(vector<int>slots, vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types, vector<XGL_OBJECT>objs );
Tony Barbourf12bfb92014-11-19 16:33:11 -0700178
179protected:
Tony Barbour685f4332014-11-20 15:06:56 -0700180 XGL_DESCRIPTOR_SET_CREATE_INFO m_descriptorInfo;
181 XGL_DESCRIPTOR_SET m_rsrcDescSet;
182 XGL_GPU_MEMORY m_descriptor_set_mem;
183 XglDevice *m_device;
184 XGL_DESCRIPTOR_SLOT_INFO *m_slotInfo;
185 int m_nextSlot;
186 vector<int> m_memorySlots;
187 vector<XGL_MEMORY_VIEW_ATTACH_INFO*> m_memoryViews;
188 vector<int> m_samplerSlots;
189 vector<XGL_SAMPLER*> m_samplers;
190 vector<int> m_imageSlots;
191 vector<XGL_IMAGE_VIEW_ATTACH_INFO*> m_imageViews;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700192};
Tony Barbour685f4332014-11-20 15:06:56 -0700193
194
Tony Barbourf12bfb92014-11-19 16:33:11 -0700195class XglShaderObj
196{
197public:
Tony Barbourf43b6982014-11-25 13:18:32 -0700198 XglShaderObj(XglDevice *device, const char * shaderText, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700199 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* GetStageCreateInfo(XglDescriptorSetObj descriptorSet);
Tony Barbour685f4332014-11-20 15:06:56 -0700200 void BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer);
201 void BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture);
202 void BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700203
204protected:
205 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO stage_info;
206 XGL_SHADER m_shader;
207 XGL_PIPELINE_SHADER_STAGE m_stage;
208 XglDevice *m_device;
209 vector<int> m_memSlots;
210 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_memTypes;
211 vector<XGL_OBJECT> m_memObjs;
212 vector<int> m_samplerSlots;
213 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_samplerTypes;
214 vector<XGL_OBJECT> m_samplerObjs;
215 vector<int> m_imageSlots;
216 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_imageTypes;
217 vector<XGL_OBJECT> m_imageObjs;
218
219};
220
221class XglPipelineObj
222{
223public:
224 XglPipelineObj(XglDevice *device);
225 void BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj descriptorSet);
226 void AddShader(XglShaderObj* shaderObj);
227 void AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count);
228 void AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count);
229 void AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding);
230
231protected:
232 XGL_PIPELINE m_pipeline;
233 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO m_vi_state;
234 XGL_PIPELINE_IA_STATE_CREATE_INFO m_ia_state;
235 XGL_PIPELINE_RS_STATE_CREATE_INFO m_rs_state;
236 XGL_PIPELINE_CB_STATE m_cb_state;
237 XGL_PIPELINE_DB_STATE_CREATE_INFO m_db_state;
238 XGL_FORMAT m_render_target_format;
239 XGL_PIPELINE_CB_ATTACHMENT_STATE m_cb_attachment_state;
240 XGL_GPU_MEMORY m_pipe_mem;
241 XglDevice *m_device;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700242 vector<XglShaderObj*> m_shaderObjs;
243 vector<XglConstantBufferObj*> m_vertexBufferObjs;
244 vector<int> m_vertexBufferBindings;
245 int m_vertexBufferCount;
246
247};
248class XglMemoryRefManager{
249public:
250 XglMemoryRefManager();
Tony Barbour685f4332014-11-20 15:06:56 -0700251 void AddMemoryRef(XglConstantBufferObj* constantBuffer);
252 void AddMemoryRef(XglTextureObj *texture);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700253 XGL_MEMORY_REF* GetMemoryRefList();
254 int GetNumRefs();
255
256protected:
257 int m_numRefs;
258 vector<XGL_GPU_MEMORY*> m_bufferObjs;
259
260};
261
262
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -0600263#endif // XGLRENDERFRAMEWORK_H