13464ebd5Sriastradh/**************************************************************************
23464ebd5Sriastradh *
33464ebd5Sriastradh * Copyright 2010 VMware, Inc.
43464ebd5Sriastradh * All Rights Reserved.
53464ebd5Sriastradh *
63464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
73464ebd5Sriastradh * copy of this software and associated documentation files (the
83464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including
93464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish,
103464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to
113464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to
123464ebd5Sriastradh * the following conditions:
133464ebd5Sriastradh *
143464ebd5Sriastradh * The above copyright notice and this permission notice (including the
153464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions
163464ebd5Sriastradh * of the Software.
173464ebd5Sriastradh *
183464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
193464ebd5Sriastradh * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
203464ebd5Sriastradh * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
213464ebd5Sriastradh * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
223464ebd5Sriastradh * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
233464ebd5Sriastradh * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
243464ebd5Sriastradh * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
253464ebd5Sriastradh *
263464ebd5Sriastradh **************************************************************************/
273464ebd5Sriastradh
283464ebd5Sriastradh#include "pipe/p_shader_tokens.h"
293464ebd5Sriastradh
303464ebd5Sriastradh#include "util/u_math.h"
313464ebd5Sriastradh#include "util/u_memory.h"
323464ebd5Sriastradh#include "util/u_prim.h"
333464ebd5Sriastradh
343464ebd5Sriastradh#include "tgsi/tgsi_parse.h"
357ec681f3Smrg#include "nir/nir_to_tgsi_info.h"
363464ebd5Sriastradh
373464ebd5Sriastradh#include "draw_fs.h"
383464ebd5Sriastradh#include "draw_private.h"
393464ebd5Sriastradh#include "draw_context.h"
403464ebd5Sriastradh
413464ebd5Sriastradh
423464ebd5Sriastradhstruct draw_fragment_shader *
433464ebd5Sriastradhdraw_create_fragment_shader(struct draw_context *draw,
443464ebd5Sriastradh                            const struct pipe_shader_state *shader)
453464ebd5Sriastradh{
463464ebd5Sriastradh   struct draw_fragment_shader *dfs;
473464ebd5Sriastradh
483464ebd5Sriastradh   dfs = CALLOC_STRUCT(draw_fragment_shader);
493464ebd5Sriastradh   if (dfs) {
503464ebd5Sriastradh      dfs->base = *shader;
517ec681f3Smrg      if (shader->type == PIPE_SHADER_IR_TGSI)
527ec681f3Smrg         tgsi_scan_shader(shader->tokens, &dfs->info);
537ec681f3Smrg      else
547ec681f3Smrg         nir_tgsi_scan_shader(shader->ir.nir, &dfs->info, true);
553464ebd5Sriastradh   }
563464ebd5Sriastradh
573464ebd5Sriastradh   return dfs;
583464ebd5Sriastradh}
593464ebd5Sriastradh
603464ebd5Sriastradh
613464ebd5Sriastradhvoid
623464ebd5Sriastradhdraw_bind_fragment_shader(struct draw_context *draw,
633464ebd5Sriastradh                          struct draw_fragment_shader *dfs)
643464ebd5Sriastradh{
653464ebd5Sriastradh   draw_do_flush(draw, DRAW_FLUSH_STATE_CHANGE);
663464ebd5Sriastradh
673464ebd5Sriastradh   draw->fs.fragment_shader = dfs;
683464ebd5Sriastradh}
693464ebd5Sriastradh
703464ebd5Sriastradh
713464ebd5Sriastradhvoid
723464ebd5Sriastradhdraw_delete_fragment_shader(struct draw_context *draw,
733464ebd5Sriastradh                            struct draw_fragment_shader *dfs)
743464ebd5Sriastradh{
753464ebd5Sriastradh   FREE(dfs);
763464ebd5Sriastradh}
773464ebd5Sriastradh
78