blob: 0fb589428f2dd066dbc251ed84e6b173480bb37f [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,
79 GEN6_REG_IA_PRIMITIVES_COUNT,
80 GEN6_REG_IA_VERTICES_COUNT,
81 (cmd_gen(cmd) >= INTEL_GEN(7)) ? GEN6_REG_HS_INVOCATION_COUNT : 0,
82 (cmd_gen(cmd) >= INTEL_GEN(7)) ? GEN6_REG_DS_INVOCATION_COUNT : 0,
83 0,
84 };
85 XGL_UINT i;
86
87 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_CS_STALL);
88
89 for (i = 0; i < ARRAY_SIZE(regs); i++) {
90 if (regs[i]) {
91 /* store lower 32 bits */
92 gen6_MI_STORE_REGISTER_MEM(cmd, bo, offset, regs[i]);
93 /* store higher 32 bits */
94 gen6_MI_STORE_REGISTER_MEM(cmd, bo, offset + 4, regs[i] + 4);
95 } else {
96 gen6_MI_STORE_DATA_IMM(cmd, bo, offset, 0);
97 }
98 }
99}
100
101XGL_VOID XGLAPI intelCmdBeginQuery(
102 XGL_CMD_BUFFER cmdBuffer,
103 XGL_QUERY_POOL queryPool,
104 XGL_UINT slot,
105 XGL_FLAGS flags)
106{
107 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
108 struct intel_query *query = intel_query(queryPool);
109 struct intel_bo *bo = query->obj.mem->bo;
110 const XGL_GPU_SIZE offset = query->slot_stride * slot;
111
112 switch (query->type) {
113 case XGL_QUERY_OCCLUSION:
114 cmd_batch_depth_count(cmd, bo, offset);
115 break;
116 case XGL_QUERY_PIPELINE_STATISTICS:
117 cmd_query_pipeline_statistics(cmd, bo, offset);
118 break;
119 default:
120 cmd->result = XGL_ERROR_UNKNOWN;
121 break;
122 }
123}
124
125XGL_VOID XGLAPI intelCmdEndQuery(
126 XGL_CMD_BUFFER cmdBuffer,
127 XGL_QUERY_POOL queryPool,
128 XGL_UINT slot)
129{
130 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
131 struct intel_query *query = intel_query(queryPool);
132 struct intel_bo *bo = query->obj.mem->bo;
133 const XGL_GPU_SIZE offset = query->slot_stride * slot;
134
135 switch (query->type) {
136 case XGL_QUERY_OCCLUSION:
137 cmd_batch_depth_count(cmd, bo, offset + sizeof(uint64_t));
138 break;
139 case XGL_QUERY_PIPELINE_STATISTICS:
140 cmd_query_pipeline_statistics(cmd, bo,
141 offset + sizeof(XGL_PIPELINE_STATISTICS_DATA));
142 break;
143 default:
144 cmd->result = XGL_ERROR_UNKNOWN;
145 break;
146 }
147}
148
149XGL_VOID XGLAPI intelCmdResetQueryPool(
150 XGL_CMD_BUFFER cmdBuffer,
151 XGL_QUERY_POOL queryPool,
152 XGL_UINT startQuery,
153 XGL_UINT queryCount)
154{
155}