1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3bf215546Sopenharmony_ci *                Joakim Sindholt <opensource@zhasha.com>
4bf215546Sopenharmony_ci * Copyright 2009 Marek Olšák <maraeo@gmail.com>
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub
10bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom
11bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
14bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
15bf215546Sopenharmony_ci * Software.
16bf215546Sopenharmony_ci *
17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci#ifndef R300_FS_H
26bf215546Sopenharmony_ci#define R300_FS_H
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include "pipe/p_state.h"
29bf215546Sopenharmony_ci#include "tgsi/tgsi_scan.h"
30bf215546Sopenharmony_ci#include "compiler/radeon_code.h"
31bf215546Sopenharmony_ci#include "r300_shader_semantics.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_cistruct r300_fragment_shader_code {
34bf215546Sopenharmony_ci    struct rX00_fragment_program_code code;
35bf215546Sopenharmony_ci    struct tgsi_shader_info info;
36bf215546Sopenharmony_ci    struct r300_shader_semantics inputs;
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci    /* Whether the shader was replaced by a dummy one due to a shader
39bf215546Sopenharmony_ci     * compilation failure. */
40bf215546Sopenharmony_ci    boolean dummy;
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci    /* Numbers of constants for each type. */
43bf215546Sopenharmony_ci    unsigned externals_count;
44bf215546Sopenharmony_ci    unsigned immediates_count;
45bf215546Sopenharmony_ci    unsigned rc_state_count;
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci    /* Registers for fragment depth output setup. */
48bf215546Sopenharmony_ci    uint32_t fg_depth_src;      /* R300_FG_DEPTH_SRC: 0x4bd8 */
49bf215546Sopenharmony_ci    uint32_t us_out_w;          /* R300_US_W_FMT:     0x46b4 */
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci    struct r300_fragment_program_external_state compare_state;
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci    unsigned cb_code_size;
54bf215546Sopenharmony_ci    uint32_t *cb_code;
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci    struct r300_fragment_shader_code* next;
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci    boolean write_all;
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci};
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_cistruct r300_fragment_shader {
63bf215546Sopenharmony_ci    /* Parent class */
64bf215546Sopenharmony_ci    struct pipe_shader_state state;
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci    /* Currently-bound fragment shader. */
67bf215546Sopenharmony_ci    struct r300_fragment_shader_code* shader;
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci    /* List of the same shaders compiled with different texture-compare
70bf215546Sopenharmony_ci     * states. */
71bf215546Sopenharmony_ci    struct r300_fragment_shader_code* first;
72bf215546Sopenharmony_ci};
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_civoid r300_shader_read_fs_inputs(struct tgsi_shader_info* info,
75bf215546Sopenharmony_ci                                struct r300_shader_semantics* fs_inputs);
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci/* Return TRUE if the shader was switched and should be re-emitted. */
78bf215546Sopenharmony_ciboolean r300_pick_fragment_shader(struct r300_context *r300,
79bf215546Sopenharmony_ci                                  struct r300_fragment_shader* fs,
80bf215546Sopenharmony_ci                                  struct r300_fragment_program_external_state *state);
81bf215546Sopenharmony_civoid r300_fragment_program_get_external_state(struct r300_context *r300,
82bf215546Sopenharmony_ci                                              struct r300_fragment_program_external_state *state);
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_cistatic inline boolean r300_fragment_shader_writes_depth(struct r300_fragment_shader *fs)
85bf215546Sopenharmony_ci{
86bf215546Sopenharmony_ci    if (!fs)
87bf215546Sopenharmony_ci        return FALSE;
88bf215546Sopenharmony_ci    return (fs->shader->code.writes_depth) ? TRUE : FALSE;
89bf215546Sopenharmony_ci}
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_cistatic inline boolean r300_fragment_shader_writes_all(struct r300_fragment_shader *fs)
92bf215546Sopenharmony_ci{
93bf215546Sopenharmony_ci    if (!fs)
94bf215546Sopenharmony_ci        return FALSE;
95bf215546Sopenharmony_ci    return (fs->shader->write_all) ? TRUE : FALSE;
96bf215546Sopenharmony_ci}
97bf215546Sopenharmony_ci#endif /* R300_FS_H */
98