blob: a1e2ea3d8fb74ed372cb7aa7dda72bfef386f29a [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
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060039 XGL_DEVICE device() {return m_device->device();}
Tobin Ehlis3c26a542014-11-18 11:28:33 -070040 XGL_PHYSICAL_GPU gpu() {return objs[0];}
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060041 void InitViewport(float width, float height);
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -060042 void InitViewport();
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060043 void InitRenderTarget();
44 void InitFramework();
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060045 void ShutdownFramework();
46 void InitState();
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -060047 void GenerateClearAndPrepareBufferCmds();
48 void GenerateBindRenderTargetCmd();
Tony Barbourf43b6982014-11-25 13:18:32 -070049 void GenerateBindStateAndPipelineCmds();
50
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060051
52protected:
53 XGL_APPLICATION_INFO app_info;
54 XGL_PHYSICAL_GPU objs[MAX_GPUS];
55 XGL_UINT gpu_count;
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060056 XglDevice *m_device;
57 XGL_CMD_BUFFER m_cmdBuffer;
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060058 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 Wue7748802014-12-05 10:45:15 +080064 XglImage *m_renderTargets[XGL_MAX_COLOR_ATTACHMENTS];
65 XGL_UINT m_renderTargetCount;
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060066 XGL_FLOAT m_width, m_height;
67 XGL_FORMAT m_render_target_fmt;
Chia-I Wue7748802014-12-05 10:45:15 +080068 XGL_COLOR_ATTACHMENT_BIND_INFO m_colorBindings[XGL_MAX_COLOR_ATTACHMENTS];
Courtney Goeltzenleuchterb66e7de2014-10-22 14:12:38 -060069 XGL_DEPTH_STENCIL_BIND_INFO m_depthStencilBinding;
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060070
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 Goeltzenleuchter5744b972014-10-08 08:50:49 -060086 err = xglInitAndEnumerateGpus(&app_info, NULL,
87 MAX_GPUS, &this->gpu_count, objs);
88 ASSERT_XGL_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -070089 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060090
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 Barbour4f3e5a62014-12-10 14:34:45 -0700100class XglCommandBufferObj
101{
102public:
103 XglCommandBufferObj(XglDevice *device);
104 ~XglCommandBufferObj();
105 XGL_CMD_BUFFER GetBufferHandle();
106 XGL_CMD_BUFFER* GetBufferPointer();
107
108protected:
109 XglDevice *m_device;
110 XGL_CMD_BUFFER_CREATE_INFO m_cmdInfo;
111 XGL_CMD_BUFFER m_cmdBuffer;
112
113};
114
Tony Barbour685f4332014-11-20 15:06:56 -0700115class XglConstantBufferObj
Tony Barbourf12bfb92014-11-19 16:33:11 -0700116{
117public:
Courtney Goeltzenleuchterea2db0d2014-12-04 15:18:47 -0700118 XglConstantBufferObj(XglDevice *device);
Tony Barbour685f4332014-11-20 15:06:56 -0700119 XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data);
Tony Barbour74ca8af2014-12-03 16:23:43 -0700120 ~XglConstantBufferObj();
Tony Barbour685f4332014-11-20 15:06:56 -0700121 void SetMemoryState(XGL_CMD_BUFFER cmdBuffer, XGL_MEMORY_STATE newState);
Courtney Goeltzenleuchter7715bc42014-12-04 15:26:56 -0700122 void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding);
Tony Barbour685f4332014-11-20 15:06:56 -0700123 XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView;
124 XGL_GPU_MEMORY m_constantBufferMem;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700125
126protected:
Tony Barbour685f4332014-11-20 15:06:56 -0700127 XglDevice *m_device;
128 int m_numVertices;
129 int m_stride;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700130};
Courtney Goeltzenleuchterfa834c92014-12-04 15:24:05 -0700131
132class XglIndexBufferObj : public XglConstantBufferObj
133{
134public:
135 XglIndexBufferObj(XglDevice *device);
136 void CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE dataFormat, const void* data);
137 void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset);
138
139protected:
140 XGL_INDEX_TYPE m_indexType;
141};
142
Tony Barbourf12bfb92014-11-19 16:33:11 -0700143class XglTextureObj
144{
145public:
146 XglTextureObj(XglDevice *device);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700147 ~XglTextureObj();
Tony Barbour84d3d022014-11-21 17:17:49 -0700148 void ChangeColors(uint32_t color1, uint32_t color2);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700149 XGL_IMAGE m_texture;
150 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
151 XGL_GPU_MEMORY m_textureMem;
152
153protected:
154 XglDevice *m_device;
155 XGL_IMAGE_VIEW m_textureView;
Tony Barbour84d3d022014-11-21 17:17:49 -0700156 int m_texHeight;
157 int m_texWidth;
158 int m_rowPitch;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700159
160};
161
162class XglSamplerObj
163{
164public:
165 XglSamplerObj(XglDevice *device);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700166 ~XglSamplerObj();
Tony Barbourf12bfb92014-11-19 16:33:11 -0700167 XGL_SAMPLER m_sampler;
168
169protected:
170 XGL_SAMPLER_CREATE_INFO m_samplerCreateInfo;
171 XglDevice *m_device;
172
173};
174
Tony Barbour685f4332014-11-20 15:06:56 -0700175class XglDescriptorSetObj
Tony Barbourf12bfb92014-11-19 16:33:11 -0700176{
177public:
Tony Barbour685f4332014-11-20 15:06:56 -0700178 XglDescriptorSetObj(XglDevice *device);
Tony Barbour342ae3b2014-12-03 13:59:18 -0700179 ~XglDescriptorSetObj();
Tony Barbour685f4332014-11-20 15:06:56 -0700180 void AttachMemoryView(XglConstantBufferObj* constantBuffer);
181 void AttachSampler( XglSamplerObj* sampler);
182 void AttachImageView( XglTextureObj* texture);
183 void BindCommandBuffer(XGL_CMD_BUFFER commandBuffer);
184 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 -0700185
186protected:
Tony Barbour685f4332014-11-20 15:06:56 -0700187 XGL_DESCRIPTOR_SET_CREATE_INFO m_descriptorInfo;
188 XGL_DESCRIPTOR_SET m_rsrcDescSet;
189 XGL_GPU_MEMORY m_descriptor_set_mem;
190 XglDevice *m_device;
191 XGL_DESCRIPTOR_SLOT_INFO *m_slotInfo;
192 int m_nextSlot;
193 vector<int> m_memorySlots;
194 vector<XGL_MEMORY_VIEW_ATTACH_INFO*> m_memoryViews;
195 vector<int> m_samplerSlots;
196 vector<XGL_SAMPLER*> m_samplers;
197 vector<int> m_imageSlots;
198 vector<XGL_IMAGE_VIEW_ATTACH_INFO*> m_imageViews;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700199};
Tony Barbour685f4332014-11-20 15:06:56 -0700200
201
Tony Barbourf12bfb92014-11-19 16:33:11 -0700202class XglShaderObj
203{
204public:
Tony Barbourf43b6982014-11-25 13:18:32 -0700205 XglShaderObj(XglDevice *device, const char * shaderText, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700206 ~XglShaderObj();
Tony Barbourbf678472014-12-03 13:58:15 -0700207 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* GetStageCreateInfo(XglDescriptorSetObj *descriptorSet);
Tony Barbour685f4332014-11-20 15:06:56 -0700208 void BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer);
209 void BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture);
210 void BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700211
212protected:
213 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO stage_info;
214 XGL_SHADER m_shader;
215 XGL_PIPELINE_SHADER_STAGE m_stage;
216 XglDevice *m_device;
217 vector<int> m_memSlots;
218 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_memTypes;
219 vector<XGL_OBJECT> m_memObjs;
220 vector<int> m_samplerSlots;
221 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_samplerTypes;
222 vector<XGL_OBJECT> m_samplerObjs;
223 vector<int> m_imageSlots;
224 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_imageTypes;
225 vector<XGL_OBJECT> m_imageObjs;
226
227};
228
229class XglPipelineObj
230{
231public:
232 XglPipelineObj(XglDevice *device);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700233 ~XglPipelineObj();
Tony Barbourbf678472014-12-03 13:58:15 -0700234 void BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700235 void AddShader(XglShaderObj* shaderObj);
236 void AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count);
237 void AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count);
238 void AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding);
Chia-I Wue7748802014-12-05 10:45:15 +0800239 void SetColorAttachment(XGL_UINT binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700240
241protected:
242 XGL_PIPELINE m_pipeline;
243 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO m_vi_state;
244 XGL_PIPELINE_IA_STATE_CREATE_INFO m_ia_state;
245 XGL_PIPELINE_RS_STATE_CREATE_INFO m_rs_state;
246 XGL_PIPELINE_CB_STATE m_cb_state;
247 XGL_PIPELINE_DB_STATE_CREATE_INFO m_db_state;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700248 XGL_GPU_MEMORY m_pipe_mem;
249 XglDevice *m_device;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700250 vector<XglShaderObj*> m_shaderObjs;
251 vector<XglConstantBufferObj*> m_vertexBufferObjs;
252 vector<int> m_vertexBufferBindings;
253 int m_vertexBufferCount;
254
255};
256class XglMemoryRefManager{
257public:
258 XglMemoryRefManager();
Tony Barbour685f4332014-11-20 15:06:56 -0700259 void AddMemoryRef(XglConstantBufferObj* constantBuffer);
260 void AddMemoryRef(XglTextureObj *texture);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700261 XGL_MEMORY_REF* GetMemoryRefList();
262 int GetNumRefs();
263
264protected:
265 int m_numRefs;
266 vector<XGL_GPU_MEMORY*> m_bufferObjs;
267
268};
269
270
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -0600271#endif // XGLRENDERFRAMEWORK_H