blob: cbaee3d93ba4121bfeb4b5c2f8953cc14f4876e4 [file] [log] [blame]
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001/*
2 * XGL
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
25#include "mem.h"
26#include "obj.h"
27#include "query.h"
28#include "cmd_priv.h"
29
30static void gen6_MI_STORE_REGISTER_MEM(struct intel_cmd *cmd,
31 struct intel_bo *bo,
32 uint32_t offset,
33 uint32_t reg)
34{
35 const uint8_t cmd_len = 3;
36 uint32_t dw0 = GEN6_MI_CMD(MI_STORE_REGISTER_MEM) |
37 (cmd_len - 2);
38
39 if (cmd_gen(cmd) == INTEL_GEN(6))
40 dw0 |= GEN6_MI_STORE_REGISTER_MEM_DW0_USE_GGTT;
41
42 cmd_batch_reserve(cmd, cmd_len);
43 cmd_batch_write(cmd, dw0);
44 cmd_batch_write(cmd, reg);
45 cmd_batch_reloc(cmd, offset, bo, INTEL_RELOC_GGTT | INTEL_RELOC_WRITE);
46}
47
48static void gen6_MI_STORE_DATA_IMM(struct intel_cmd *cmd,
49 struct intel_bo *bo,
50 uint32_t offset,
51 uint64_t val)
52{
53 const uint8_t cmd_len = 5;
54 uint32_t dw0 = GEN6_MI_CMD(MI_STORE_DATA_IMM) |
55 (cmd_len - 2);
56
57 if (cmd_gen(cmd) == INTEL_GEN(6))
58 dw0 |= GEN6_MI_STORE_DATA_IMM_DW0_USE_GGTT;
59
60 cmd_batch_reserve(cmd, cmd_len);
61 cmd_batch_write(cmd, dw0);
62 cmd_batch_write(cmd, 0);
63 cmd_batch_reloc(cmd, offset, bo, INTEL_RELOC_GGTT | INTEL_RELOC_WRITE);
64 cmd_batch_write(cmd, (uint32_t) val);
65 cmd_batch_write(cmd, (uint32_t) (val >> 32));
66}
67
68static void cmd_query_pipeline_statistics(struct intel_cmd *cmd,
69 struct intel_bo *bo,
70 XGL_GPU_SIZE offset)
71{
72 const uint32_t regs[] = {
73 GEN6_REG_PS_INVOCATION_COUNT,
74 GEN6_REG_CL_PRIMITIVES_COUNT,
75 GEN6_REG_CL_INVOCATION_COUNT,
76 GEN6_REG_VS_INVOCATION_COUNT,
77 GEN6_REG_GS_INVOCATION_COUNT,
78 GEN6_REG_GS_PRIMITIVES_COUNT,
Chia-I Wu8a927bd2014-08-31 00:06:36 +080079 /* well, we do not enable 3DSTATE_VF_STATISTICS yet */
Chia-I Wu759fa2e2014-08-30 18:44:47 +080080 GEN6_REG_IA_PRIMITIVES_COUNT,
81 GEN6_REG_IA_VERTICES_COUNT,
82 (cmd_gen(cmd) >= INTEL_GEN(7)) ? GEN6_REG_HS_INVOCATION_COUNT : 0,
83 (cmd_gen(cmd) >= INTEL_GEN(7)) ? GEN6_REG_DS_INVOCATION_COUNT : 0,
84 0,
85 };
86 XGL_UINT i;
87
88 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_CS_STALL);
89
90 for (i = 0; i < ARRAY_SIZE(regs); i++) {
91 if (regs[i]) {
92 /* store lower 32 bits */
93 gen6_MI_STORE_REGISTER_MEM(cmd, bo, offset, regs[i]);
94 /* store higher 32 bits */
95 gen6_MI_STORE_REGISTER_MEM(cmd, bo, offset + 4, regs[i] + 4);
96 } else {
97 gen6_MI_STORE_DATA_IMM(cmd, bo, offset, 0);
98 }
Chia-I Wu8a927bd2014-08-31 00:06:36 +080099
100 offset += sizeof(uint64_t);
Chia-I Wu759fa2e2014-08-30 18:44:47 +0800101 }
102}
103
104XGL_VOID XGLAPI intelCmdBeginQuery(
105 XGL_CMD_BUFFER cmdBuffer,
106 XGL_QUERY_POOL queryPool,
107 XGL_UINT slot,
108 XGL_FLAGS flags)
109{
110 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
111 struct intel_query *query = intel_query(queryPool);
112 struct intel_bo *bo = query->obj.mem->bo;
113 const XGL_GPU_SIZE offset = query->slot_stride * slot;
114
115 switch (query->type) {
116 case XGL_QUERY_OCCLUSION:
117 cmd_batch_depth_count(cmd, bo, offset);
118 break;
119 case XGL_QUERY_PIPELINE_STATISTICS:
120 cmd_query_pipeline_statistics(cmd, bo, offset);
121 break;
122 default:
123 cmd->result = XGL_ERROR_UNKNOWN;
124 break;
125 }
126}
127
128XGL_VOID XGLAPI intelCmdEndQuery(
129 XGL_CMD_BUFFER cmdBuffer,
130 XGL_QUERY_POOL queryPool,
131 XGL_UINT slot)
132{
133 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
134 struct intel_query *query = intel_query(queryPool);
135 struct intel_bo *bo = query->obj.mem->bo;
136 const XGL_GPU_SIZE offset = query->slot_stride * slot;
137
138 switch (query->type) {
139 case XGL_QUERY_OCCLUSION:
140 cmd_batch_depth_count(cmd, bo, offset + sizeof(uint64_t));
141 break;
142 case XGL_QUERY_PIPELINE_STATISTICS:
143 cmd_query_pipeline_statistics(cmd, bo,
144 offset + sizeof(XGL_PIPELINE_STATISTICS_DATA));
145 break;
146 default:
147 cmd->result = XGL_ERROR_UNKNOWN;
148 break;
149 }
150}
151
152XGL_VOID XGLAPI intelCmdResetQueryPool(
153 XGL_CMD_BUFFER cmdBuffer,
154 XGL_QUERY_POOL queryPool,
155 XGL_UINT startQuery,
156 XGL_UINT queryCount)
157{
158}