blob: 263ddf9989659856cc94e08b9b4cc6afa8597cfc [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);
Courtney Goeltzenleuchter7715bc42014-12-04 15:26:56 -0700131 void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding);
Tony Barbour685f4332014-11-20 15:06:56 -0700132 XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView;
133 XGL_GPU_MEMORY m_constantBufferMem;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700134
135protected:
Tony Barbour685f4332014-11-20 15:06:56 -0700136 XglDevice *m_device;
137 int m_numVertices;
138 int m_stride;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700139};
Tony Barbourf12bfb92014-11-19 16:33:11 -0700140class XglTextureObj
141{
142public:
143 XglTextureObj(XglDevice *device);
Tony Barbour84d3d022014-11-21 17:17:49 -0700144 void ChangeColors(uint32_t color1, uint32_t color2);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700145 XGL_IMAGE m_texture;
146 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
147 XGL_GPU_MEMORY m_textureMem;
148
149protected:
150 XglDevice *m_device;
151 XGL_IMAGE_VIEW m_textureView;
Tony Barbour84d3d022014-11-21 17:17:49 -0700152 int m_texHeight;
153 int m_texWidth;
154 int m_rowPitch;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700155
156};
157
158class XglSamplerObj
159{
160public:
161 XglSamplerObj(XglDevice *device);
162 XGL_SAMPLER m_sampler;
163
164protected:
165 XGL_SAMPLER_CREATE_INFO m_samplerCreateInfo;
166 XglDevice *m_device;
167
168};
169
Tony Barbour685f4332014-11-20 15:06:56 -0700170class XglDescriptorSetObj
Tony Barbourf12bfb92014-11-19 16:33:11 -0700171{
172public:
Tony Barbour685f4332014-11-20 15:06:56 -0700173 XglDescriptorSetObj(XglDevice *device);
174 void AttachMemoryView(XglConstantBufferObj* constantBuffer);
175 void AttachSampler( XglSamplerObj* sampler);
176 void AttachImageView( XglTextureObj* texture);
177 void BindCommandBuffer(XGL_CMD_BUFFER commandBuffer);
178 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 -0700179
180protected:
Tony Barbour685f4332014-11-20 15:06:56 -0700181 XGL_DESCRIPTOR_SET_CREATE_INFO m_descriptorInfo;
182 XGL_DESCRIPTOR_SET m_rsrcDescSet;
183 XGL_GPU_MEMORY m_descriptor_set_mem;
184 XglDevice *m_device;
185 XGL_DESCRIPTOR_SLOT_INFO *m_slotInfo;
186 int m_nextSlot;
187 vector<int> m_memorySlots;
188 vector<XGL_MEMORY_VIEW_ATTACH_INFO*> m_memoryViews;
189 vector<int> m_samplerSlots;
190 vector<XGL_SAMPLER*> m_samplers;
191 vector<int> m_imageSlots;
192 vector<XGL_IMAGE_VIEW_ATTACH_INFO*> m_imageViews;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700193};
Tony Barbour685f4332014-11-20 15:06:56 -0700194
195
Tony Barbourf12bfb92014-11-19 16:33:11 -0700196class XglShaderObj
197{
198public:
Tony Barbourf43b6982014-11-25 13:18:32 -0700199 XglShaderObj(XglDevice *device, const char * shaderText, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700200 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* GetStageCreateInfo(XglDescriptorSetObj descriptorSet);
Tony Barbour685f4332014-11-20 15:06:56 -0700201 void BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer);
202 void BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture);
203 void BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700204
205protected:
206 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO stage_info;
207 XGL_SHADER m_shader;
208 XGL_PIPELINE_SHADER_STAGE m_stage;
209 XglDevice *m_device;
210 vector<int> m_memSlots;
211 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_memTypes;
212 vector<XGL_OBJECT> m_memObjs;
213 vector<int> m_samplerSlots;
214 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_samplerTypes;
215 vector<XGL_OBJECT> m_samplerObjs;
216 vector<int> m_imageSlots;
217 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_imageTypes;
218 vector<XGL_OBJECT> m_imageObjs;
219
220};
221
222class XglPipelineObj
223{
224public:
225 XglPipelineObj(XglDevice *device);
226 void BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj descriptorSet);
227 void AddShader(XglShaderObj* shaderObj);
228 void AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count);
229 void AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count);
230 void AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding);
231
232protected:
233 XGL_PIPELINE m_pipeline;
234 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO m_vi_state;
235 XGL_PIPELINE_IA_STATE_CREATE_INFO m_ia_state;
236 XGL_PIPELINE_RS_STATE_CREATE_INFO m_rs_state;
237 XGL_PIPELINE_CB_STATE m_cb_state;
238 XGL_PIPELINE_DB_STATE_CREATE_INFO m_db_state;
239 XGL_FORMAT m_render_target_format;
240 XGL_PIPELINE_CB_ATTACHMENT_STATE m_cb_attachment_state;
241 XGL_GPU_MEMORY m_pipe_mem;
242 XglDevice *m_device;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700243 vector<XglShaderObj*> m_shaderObjs;
244 vector<XglConstantBufferObj*> m_vertexBufferObjs;
245 vector<int> m_vertexBufferBindings;
246 int m_vertexBufferCount;
247
248};
249class XglMemoryRefManager{
250public:
251 XglMemoryRefManager();
Tony Barbour685f4332014-11-20 15:06:56 -0700252 void AddMemoryRef(XglConstantBufferObj* constantBuffer);
253 void AddMemoryRef(XglTextureObj *texture);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700254 XGL_MEMORY_REF* GetMemoryRefList();
255 int GetNumRefs();
256
257protected:
258 int m_numRefs;
259 vector<XGL_GPU_MEMORY*> m_bufferObjs;
260
261};
262
263
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -0600264#endif // XGLRENDERFRAMEWORK_H