2 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
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:
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
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
24 * Rob Clark <robclark@freedesktop.org>
27 #include "tgsi/tgsi_text.h"
28 #include "tgsi/tgsi_ureg.h"
30 #include "freedreno_program.h"
31 #include "freedreno_context.h"
34 fd_vs_state_bind(struct pipe_context
*pctx
, void *hwcso
)
36 struct fd_context
*ctx
= fd_context(pctx
);
38 ctx
->dirty_shader
[PIPE_SHADER_VERTEX
] |= FD_DIRTY_SHADER_PROG
;
39 ctx
->dirty
|= FD_DIRTY_PROG
;
43 fd_tcs_state_bind(struct pipe_context
*pctx
, void *hwcso
)
45 struct fd_context
*ctx
= fd_context(pctx
);
47 ctx
->dirty_shader
[PIPE_SHADER_TESS_CTRL
] |= FD_DIRTY_SHADER_PROG
;
48 ctx
->dirty
|= FD_DIRTY_PROG
;
52 fd_tes_state_bind(struct pipe_context
*pctx
, void *hwcso
)
54 struct fd_context
*ctx
= fd_context(pctx
);
56 ctx
->dirty_shader
[PIPE_SHADER_TESS_EVAL
] |= FD_DIRTY_SHADER_PROG
;
57 ctx
->dirty
|= FD_DIRTY_PROG
;
61 fd_gs_state_bind(struct pipe_context
*pctx
, void *hwcso
)
63 struct fd_context
*ctx
= fd_context(pctx
);
65 ctx
->dirty_shader
[PIPE_SHADER_GEOMETRY
] |= FD_DIRTY_SHADER_PROG
;
66 ctx
->dirty
|= FD_DIRTY_PROG
;
70 fd_fs_state_bind(struct pipe_context
*pctx
, void *hwcso
)
72 struct fd_context
*ctx
= fd_context(pctx
);
74 ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] |= FD_DIRTY_SHADER_PROG
;
75 ctx
->dirty
|= FD_DIRTY_PROG
;
78 static const char *solid_fs
=
80 "PROPERTY FS_COLOR0_WRITES_ALL_CBUFS 1 \n"
82 "DCL OUT[0], COLOR \n"
83 " 0: MOV OUT[0], CONST[0] \n"
86 static const char *solid_vs
=
89 "DCL OUT[0], POSITION \n"
90 " 0: MOV OUT[0], IN[0] \n"
93 static const char *blit_vs
=
97 "DCL OUT[0], GENERIC[0] \n"
98 "DCL OUT[1], POSITION \n"
99 " 0: MOV OUT[0], IN[0] \n"
100 " 0: MOV OUT[1], IN[1] \n"
103 static void * assemble_tgsi(struct pipe_context
*pctx
,
104 const char *src
, bool frag
)
106 struct tgsi_token toks
[32];
107 struct pipe_shader_state cso
= {
111 bool ret
= tgsi_text_translate(src
, toks
, ARRAY_SIZE(toks
));
115 return pctx
->create_fs_state(pctx
, &cso
);
117 return pctx
->create_vs_state(pctx
, &cso
);
121 fd_prog_blit(struct pipe_context
*pctx
, int rts
, bool depth
)
125 struct ureg_program
*ureg
;
127 debug_assert(rts
<= MAX_RENDER_TARGETS
);
129 ureg
= ureg_create(PIPE_SHADER_FRAGMENT
);
133 tc
= ureg_DECL_fs_input(
134 ureg
, TGSI_SEMANTIC_GENERIC
, 0, TGSI_INTERPOLATE_PERSPECTIVE
);
135 for (i
= 0; i
< rts
; i
++)
136 ureg_TEX(ureg
, ureg_DECL_output(ureg
, TGSI_SEMANTIC_COLOR
, i
),
137 TGSI_TEXTURE_2D
, tc
, ureg_DECL_sampler(ureg
, i
));
141 ureg_DECL_output(ureg
, TGSI_SEMANTIC_POSITION
, 0),
143 TGSI_TEXTURE_2D
, tc
, ureg_DECL_sampler(ureg
, rts
));
147 return ureg_create_shader_and_destroy(ureg
, pctx
);
151 void fd_prog_init(struct pipe_context
*pctx
)
153 struct fd_context
*ctx
= fd_context(pctx
);
156 pctx
->bind_vs_state
= fd_vs_state_bind
;
157 pctx
->bind_tcs_state
= fd_tcs_state_bind
;
158 pctx
->bind_tes_state
= fd_tes_state_bind
;
159 pctx
->bind_gs_state
= fd_gs_state_bind
;
160 pctx
->bind_fs_state
= fd_fs_state_bind
;
162 ctx
->solid_prog
.fs
= assemble_tgsi(pctx
, solid_fs
, true);
163 ctx
->solid_prog
.vs
= assemble_tgsi(pctx
, solid_vs
, false);
164 ctx
->blit_prog
[0].vs
= assemble_tgsi(pctx
, blit_vs
, false);
165 ctx
->blit_prog
[0].fs
= fd_prog_blit(pctx
, 1, false);
167 if (ctx
->screen
->gpu_id
< 300)
170 for (i
= 1; i
< ctx
->screen
->max_rts
; i
++) {
171 ctx
->blit_prog
[i
].vs
= ctx
->blit_prog
[0].vs
;
172 ctx
->blit_prog
[i
].fs
= fd_prog_blit(pctx
, i
+ 1, false);
175 ctx
->blit_z
.vs
= ctx
->blit_prog
[0].vs
;
176 ctx
->blit_z
.fs
= fd_prog_blit(pctx
, 0, true);
177 ctx
->blit_zs
.vs
= ctx
->blit_prog
[0].vs
;
178 ctx
->blit_zs
.fs
= fd_prog_blit(pctx
, 1, true);
181 void fd_prog_fini(struct pipe_context
*pctx
)
183 struct fd_context
*ctx
= fd_context(pctx
);
186 pctx
->delete_vs_state(pctx
, ctx
->solid_prog
.vs
);
187 pctx
->delete_fs_state(pctx
, ctx
->solid_prog
.fs
);
188 pctx
->delete_vs_state(pctx
, ctx
->blit_prog
[0].vs
);
189 for (i
= 0; i
< ctx
->screen
->max_rts
; i
++)
190 pctx
->delete_fs_state(pctx
, ctx
->blit_prog
[i
].fs
);
191 pctx
->delete_fs_state(pctx
, ctx
->blit_z
.fs
);
192 pctx
->delete_fs_state(pctx
, ctx
->blit_zs
.fs
);