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