1/*
2 * Copyright (c) 2011 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 *    Chris Wilson <chris@chris-wilson.co.uk>
25 *
26 */
27
28#include "brw_test.h"
29
30#include <string.h>
31
32static const uint32_t ps_kernel_nomask_affine[][4] = {
33#include "exa_wm_src_affine.g6b"
34#include "exa_wm_src_sample_argb.g6b"
35#include "exa_wm_write.g6b"
36};
37
38static const uint32_t ps_kernel_nomask_projective[][4] = {
39#include "exa_wm_src_projective.g6b"
40#include "exa_wm_src_sample_argb.g6b"
41#include "exa_wm_write.g6b"
42};
43
44static const uint32_t ps_kernel_maskca_affine[][4] = {
45#include "exa_wm_src_affine.g6b"
46#include "exa_wm_src_sample_argb.g6b"
47#include "exa_wm_mask_affine.g6b"
48#include "exa_wm_mask_sample_argb.g6b"
49#include "exa_wm_ca.g6b"
50#include "exa_wm_write.g6b"
51};
52
53static const uint32_t ps_kernel_maskca_projective[][4] = {
54#include "exa_wm_src_projective.g6b"
55#include "exa_wm_src_sample_argb.g6b"
56#include "exa_wm_mask_projective.g6b"
57#include "exa_wm_mask_sample_argb.g6b"
58#include "exa_wm_ca.g6b"
59#include "exa_wm_write.g6b"
60};
61
62static const uint32_t ps_kernel_maskca_srcalpha_affine[][4] = {
63#include "exa_wm_src_affine.g6b"
64#include "exa_wm_src_sample_a.g6b"
65#include "exa_wm_mask_affine.g6b"
66#include "exa_wm_mask_sample_argb.g6b"
67#include "exa_wm_ca_srcalpha.g6b"
68#include "exa_wm_write.g6b"
69};
70
71static const uint32_t ps_kernel_maskca_srcalpha_projective[][4] = {
72#include "exa_wm_src_projective.g6b"
73#include "exa_wm_src_sample_a.g6b"
74#include "exa_wm_mask_projective.g6b"
75#include "exa_wm_mask_sample_argb.g6b"
76#include "exa_wm_ca_srcalpha.g6b"
77#include "exa_wm_write.g6b"
78};
79
80static const uint32_t ps_kernel_masknoca_affine[][4] = {
81#include "exa_wm_src_affine.g6b"
82#include "exa_wm_src_sample_argb.g6b"
83#include "exa_wm_mask_affine.g6b"
84#include "exa_wm_mask_sample_a.g6b"
85#include "exa_wm_noca.g6b"
86#include "exa_wm_write.g6b"
87};
88
89static const uint32_t ps_kernel_masknoca_projective[][4] = {
90#include "exa_wm_src_projective.g6b"
91#include "exa_wm_src_sample_argb.g6b"
92#include "exa_wm_mask_projective.g6b"
93#include "exa_wm_mask_sample_a.g6b"
94#include "exa_wm_noca.g6b"
95#include "exa_wm_write.g6b"
96};
97
98static const uint32_t ps_kernel_packed[][4] = {
99#include "exa_wm_src_affine.g6b"
100#include "exa_wm_src_sample_argb.g6b"
101#include "exa_wm_yuv_rgb.g6b"
102#include "exa_wm_write.g6b"
103};
104
105static const uint32_t ps_kernel_planar[][4] = {
106#include "exa_wm_src_affine.g6b"
107#include "exa_wm_src_sample_planar.g6b"
108#include "exa_wm_yuv_rgb.g6b"
109#include "exa_wm_write.g6b"
110};
111
112#define compare(old) brw_test_compare(__FUNCTION__, p.gen, p.store, p.nr_insn, (struct brw_instruction *)old, ARRAY_SIZE(old))
113
114#if 0
115static void wm_src_affine(struct brw_compile *p)
116{
117	brw_PLN(p, brw_message_reg(2), brw_vec1_grf(6,0), brw_vec8_grf(2,0));
118	brw_PLN(p, brw_message_reg(3), brw_vec1_grf(6,0), brw_vec8_grf(4,0));
119	brw_PLN(p, brw_message_reg(4), brw_vec1_grf(6,4), brw_vec8_grf(2,0));
120	brw_PLN(p, brw_message_reg(5), brw_vec1_grf(6,4), brw_vec8_grf(4,0));
121}
122
123static void wm_src_sample_argb(struct brw_compile *p)
124{
125	static const uint32_t fragment[][4] = {
126#include "exa_wm_src_affine.g6b"
127#include "exa_wm_src_sample_argb.g6b"
128#include "exa_wm_write.g6b"
129	};
130	int n;
131
132	brw_push_insn_state(p);
133	brw_set_mask_control(p, BRW_MASK_DISABLE);
134	brw_set_compression_control(p, BRW_COMPRESSION_NONE);
135	brw_MOV(p,
136		retype(brw_vec1_grf(0,2), BRW_REGISTER_TYPE_UD),
137		brw_imm_ud(0));
138	brw_pop_insn_state(p);
139
140	brw_SAMPLE(p,
141		   retype(vec16(brw_vec8_grf(14, 0)), BRW_REGISTER_TYPE_UW),
142		   1,
143		   retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD),
144		   1, 0,
145		   WRITEMASK_XYZW,
146		   GEN5_SAMPLER_MESSAGE_SAMPLE,
147		   8,
148		   5,
149		   true,
150		   BRW_SAMPLER_SIMD_MODE_SIMD16);
151
152
153	for (n = 0; n < p->nr_insn; n++) {
154		brw_disasm(stdout, &p->store[n], 60);
155	}
156
157	printf("\n\n");
158	for (n = 0; n < ARRAY_SIZE(fragment); n++) {
159		brw_disasm(stdout,
160			   (const struct brw_instruction *)&fragment[n][0],
161			   60);
162	}
163}
164
165static void wm_write(struct brw_compile *p)
166{
167}
168#endif
169
170static void gen6_ps_nomask_affine(void)
171{
172	uint32_t store[1024];
173	struct brw_compile p;
174
175	brw_compile_init(&p, 060, store);
176	brw_wm_kernel__affine(&p, 16);
177
178	compare(ps_kernel_nomask_affine);
179}
180
181static void gen6_ps_mask_affine(void)
182{
183	uint32_t store[1024];
184	struct brw_compile p;
185
186	brw_compile_init(&p, 060, store);
187	brw_wm_kernel__affine_mask(&p, 16);
188
189	compare(ps_kernel_masknoca_affine);
190}
191
192static void gen6_ps_nomask_projective(void)
193{
194	uint32_t store[1024];
195	struct brw_compile p;
196
197	brw_compile_init(&p, 060, store);
198	brw_wm_kernel__projective(&p, 16);
199
200	compare(ps_kernel_nomask_projective);
201}
202
203void brw_test_gen6(void)
204{
205	gen6_ps_nomask_affine();
206	gen6_ps_mask_affine();
207
208	gen6_ps_nomask_projective();
209}
210