freedreno/log: avoid duplicate ts's
[mesa.git] / src / gallium / drivers / freedreno / freedreno_program.c
index 52a165b64af6d0f4b1a35a3d68f90e1ed3222e62..deadb3d73a4fbacc2bf3574a868a5d0a05c32d42 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
-
 /*
  * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
  *
 #include "freedreno_context.h"
 
 static void
-fd_fp_state_bind(struct pipe_context *pctx, void *hwcso)
+fd_vs_state_bind(struct pipe_context *pctx, void *hwcso)
+{
+       struct fd_context *ctx = fd_context(pctx);
+       ctx->prog.vs = hwcso;
+       ctx->dirty_shader[PIPE_SHADER_VERTEX] |= FD_DIRTY_SHADER_PROG;
+       ctx->dirty |= FD_DIRTY_PROG;
+}
+
+static void
+fd_tcs_state_bind(struct pipe_context *pctx, void *hwcso)
 {
        struct fd_context *ctx = fd_context(pctx);
-       ctx->prog.fp = hwcso;
-       ctx->prog.dirty |= FD_SHADER_DIRTY_FP;
+       ctx->prog.hs = hwcso;
+       ctx->dirty_shader[PIPE_SHADER_TESS_CTRL] |= FD_DIRTY_SHADER_PROG;
        ctx->dirty |= FD_DIRTY_PROG;
 }
 
 static void
-fd_vp_state_bind(struct pipe_context *pctx, void *hwcso)
+fd_tes_state_bind(struct pipe_context *pctx, void *hwcso)
 {
        struct fd_context *ctx = fd_context(pctx);
-       ctx->prog.vp = hwcso;
-       ctx->prog.dirty |= FD_SHADER_DIRTY_VP;
+       ctx->prog.ds = hwcso;
+       ctx->dirty_shader[PIPE_SHADER_TESS_EVAL] |= FD_DIRTY_SHADER_PROG;
        ctx->dirty |= FD_DIRTY_PROG;
 }
 
-static const char *solid_fp =
+static void
+fd_gs_state_bind(struct pipe_context *pctx, void *hwcso)
+{
+       struct fd_context *ctx = fd_context(pctx);
+       ctx->prog.gs = hwcso;
+       ctx->dirty_shader[PIPE_SHADER_GEOMETRY] |= FD_DIRTY_SHADER_PROG;
+       ctx->dirty |= FD_DIRTY_PROG;
+}
+
+static void
+fd_fs_state_bind(struct pipe_context *pctx, void *hwcso)
+{
+       struct fd_context *ctx = fd_context(pctx);
+       ctx->prog.fs = hwcso;
+       ctx->dirty_shader[PIPE_SHADER_FRAGMENT] |= FD_DIRTY_SHADER_PROG;
+       ctx->dirty |= FD_DIRTY_PROG;
+}
+
+static const char *solid_fs =
        "FRAG                                        \n"
        "PROPERTY FS_COLOR0_WRITES_ALL_CBUFS 1       \n"
        "DCL CONST[0]                                \n"
@@ -58,18 +83,18 @@ static const char *solid_fp =
        "  0: MOV OUT[0], CONST[0]                   \n"
        "  1: END                                    \n";
 
-static const char *solid_vp =
+static const char *solid_vs =
        "VERT                                        \n"
        "DCL IN[0]                                   \n"
        "DCL OUT[0], POSITION                        \n"
        "  0: MOV OUT[0], IN[0]                      \n"
        "  1: END                                    \n";
 
-static const char *blit_vp =
+static const char *blit_vs =
        "VERT                                        \n"
        "DCL IN[0]                                   \n"
        "DCL IN[1]                                   \n"
-       "DCL OUT[0], TEXCOORD[0]                     \n"
+       "DCL OUT[0], GENERIC[0]                      \n"
        "DCL OUT[1], POSITION                        \n"
        "  0: MOV OUT[0], IN[0]                      \n"
        "  0: MOV OUT[1], IN[1]                      \n"
@@ -83,7 +108,8 @@ static void * assemble_tgsi(struct pipe_context *pctx,
                        .tokens = toks,
        };
 
-       tgsi_text_translate(src, toks, ARRAY_SIZE(toks));
+       bool ret = tgsi_text_translate(src, toks, ARRAY_SIZE(toks));
+       assume(ret);
 
        if (frag)
                return pctx->create_fs_state(pctx, &cso);
@@ -92,11 +118,15 @@ static void * assemble_tgsi(struct pipe_context *pctx,
 }
 
 static void *
-fd_prog_blit(struct pipe_context *pctx, int rts)
+fd_prog_blit(struct pipe_context *pctx, int rts, bool depth)
 {
        int i;
        struct ureg_src tc;
-       struct ureg_program *ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT);
+       struct ureg_program *ureg;
+
+       debug_assert(rts <= MAX_RENDER_TARGETS);
+
+       ureg = ureg_create(PIPE_SHADER_FRAGMENT);
        if (!ureg)
                return NULL;
 
@@ -105,6 +135,12 @@ fd_prog_blit(struct pipe_context *pctx, int rts)
        for (i = 0; i < rts; i++)
                ureg_TEX(ureg, ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, i),
                                 TGSI_TEXTURE_2D, tc, ureg_DECL_sampler(ureg, i));
+       if (depth)
+               ureg_TEX(ureg,
+                                ureg_writemask(
+                                                ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0),
+                                                TGSI_WRITEMASK_Z),
+                                TGSI_TEXTURE_2D, tc, ureg_DECL_sampler(ureg, rts));
 
        ureg_END(ureg);
 
@@ -117,22 +153,29 @@ void fd_prog_init(struct pipe_context *pctx)
        struct fd_context *ctx = fd_context(pctx);
        int i;
 
-       pctx->bind_fs_state = fd_fp_state_bind;
-       pctx->bind_vs_state = fd_vp_state_bind;
+       pctx->bind_vs_state = fd_vs_state_bind;
+       pctx->bind_tcs_state = fd_tcs_state_bind;
+       pctx->bind_tes_state = fd_tes_state_bind;
+       pctx->bind_gs_state = fd_gs_state_bind;
+       pctx->bind_fs_state = fd_fs_state_bind;
+
+       ctx->solid_prog.fs = assemble_tgsi(pctx, solid_fs, true);
+       ctx->solid_prog.vs = assemble_tgsi(pctx, solid_vs, false);
+       ctx->blit_prog[0].vs = assemble_tgsi(pctx, blit_vs, false);
+       ctx->blit_prog[0].fs = fd_prog_blit(pctx, 1, false);
 
-       // XXX for now, let a2xx keep it's own hand-rolled shaders
-       // for solid and blit progs:
        if (ctx->screen->gpu_id < 300)
                return;
 
-       ctx->solid_prog.fp = assemble_tgsi(pctx, solid_fp, true);
-       ctx->solid_prog.vp = assemble_tgsi(pctx, solid_vp, false);
-       ctx->blit_prog[0].vp = assemble_tgsi(pctx, blit_vp, false);
-       ctx->blit_prog[0].fp = fd_prog_blit(pctx, 1);
        for (i = 1; i < ctx->screen->max_rts; i++) {
-               ctx->blit_prog[i].vp = ctx->blit_prog[0].vp;
-               ctx->blit_prog[i].fp = fd_prog_blit(pctx, i + 1);
+               ctx->blit_prog[i].vs = ctx->blit_prog[0].vs;
+               ctx->blit_prog[i].fs = fd_prog_blit(pctx, i + 1, false);
        }
+
+       ctx->blit_z.vs = ctx->blit_prog[0].vs;
+       ctx->blit_z.fs = fd_prog_blit(pctx, 0, true);
+       ctx->blit_zs.vs = ctx->blit_prog[0].vs;
+       ctx->blit_zs.fs = fd_prog_blit(pctx, 1, true);
 }
 
 void fd_prog_fini(struct pipe_context *pctx)
@@ -140,9 +183,11 @@ void fd_prog_fini(struct pipe_context *pctx)
        struct fd_context *ctx = fd_context(pctx);
        int i;
 
-       pctx->delete_vs_state(pctx, ctx->solid_prog.vp);
-       pctx->delete_fs_state(pctx, ctx->solid_prog.fp);
-       pctx->delete_vs_state(pctx, ctx->blit_prog[0].vp);
+       pctx->delete_vs_state(pctx, ctx->solid_prog.vs);
+       pctx->delete_fs_state(pctx, ctx->solid_prog.fs);
+       pctx->delete_vs_state(pctx, ctx->blit_prog[0].vs);
        for (i = 0; i < ctx->screen->max_rts; i++)
-               pctx->delete_fs_state(pctx, ctx->blit_prog[i].fp);
+               pctx->delete_fs_state(pctx, ctx->blit_prog[i].fs);
+       pctx->delete_fs_state(pctx, ctx->blit_z.fs);
+       pctx->delete_fs_state(pctx, ctx->blit_zs.fs);
 }