blob: aadfb1a54e179fb00c30e1e219a07935e2ffd63d [file] [log] [blame]
Jakob Bornecrantz31926332009-11-16 19:56:18 +01001/**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
José Fonseca28486882010-02-02 14:42:17 +000026#include "util/u_inlines.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010027#include "util/u_math.h"
28#include "util/u_memory.h"
José Fonsecacdb445f2010-01-03 00:47:30 +000029#include "util/u_bitmask.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010030#include "tgsi/tgsi_parse.h"
Brian Paul022e2702011-11-03 17:40:56 -060031#include "draw/draw_context.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010032
Jakob Bornecrantz31926332009-11-16 19:56:18 +010033#include "svga_context.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010034#include "svga_hw_reg.h"
35#include "svga_cmd.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010036#include "svga_debug.h"
Brian Paul4686f612014-01-31 17:23:11 -070037#include "svga_shader.h"
Jakob Bornecrantz31926332009-11-16 19:56:18 +010038
39
Jakob Bornecrantz31926332009-11-16 19:56:18 +010040static void *
41svga_create_fs_state(struct pipe_context *pipe,
42 const struct pipe_shader_state *templ)
43{
44 struct svga_context *svga = svga_context(pipe);
Jakob Bornecrantz31926332009-11-16 19:56:18 +010045 struct svga_fragment_shader *fs;
46
47 fs = CALLOC_STRUCT(svga_fragment_shader);
48 if (!fs)
49 return NULL;
50
Charmaine Lee2e1cfcc2016-08-19 08:49:17 -060051 SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATEFS);
52
Jakob Bornecrantz31926332009-11-16 19:56:18 +010053 fs->base.tokens = tgsi_dup_tokens(templ->tokens);
54
55 /* Collect basic info that we'll need later:
56 */
57 tgsi_scan_shader(fs->base.tokens, &fs->base.info);
58
59 fs->base.id = svga->debug.shader_id++;
Brian Paulef1b2b82013-04-18 15:56:53 -060060
Brian Paul58ea42b2011-11-03 17:40:56 -060061 fs->generic_inputs = svga_get_generic_inputs_mask(&fs->base.info);
62
63 svga_remap_generics(fs->generic_inputs, fs->generic_remap_table);
64
Brian Paul022e2702011-11-03 17:40:56 -060065 fs->draw_shader = draw_create_fragment_shader(svga->swtnl.draw, templ);
66
Charmaine Lee2e1cfcc2016-08-19 08:49:17 -060067 SVGA_STATS_TIME_POP(svga_sws(svga));
Jakob Bornecrantz31926332009-11-16 19:56:18 +010068 return fs;
69}
70
Brian Paulef1b2b82013-04-18 15:56:53 -060071
Jakob Bornecrantz31926332009-11-16 19:56:18 +010072static void
73svga_bind_fs_state(struct pipe_context *pipe, void *shader)
74{
75 struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader;
76 struct svga_context *svga = svga_context(pipe);
77
78 svga->curr.fs = fs;
79 svga->dirty |= SVGA_NEW_FS;
80}
81
Brian Paulef1b2b82013-04-18 15:56:53 -060082
83static void
84svga_delete_fs_state(struct pipe_context *pipe, void *shader)
Jakob Bornecrantz31926332009-11-16 19:56:18 +010085{
86 struct svga_context *svga = svga_context(pipe);
87 struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader;
Brian Paul2a303792014-01-18 03:45:41 -080088 struct svga_shader_variant *variant, *tmp;
Jakob Bornecrantz31926332009-11-16 19:56:18 +010089 enum pipe_error ret;
90
Brian Paulef1b2b82013-04-18 15:56:53 -060091 svga_hwtnl_flush_retry(svga);
Jakob Bornecrantz31926332009-11-16 19:56:18 +010092
Brian Paule0542512015-08-13 11:00:58 -070093 assert(fs->base.parent == NULL);
94
Brian Paul022e2702011-11-03 17:40:56 -060095 draw_delete_fragment_shader(svga->swtnl.draw, fs->draw_shader);
96
Brian Paul2a303792014-01-18 03:45:41 -080097 for (variant = fs->base.variants; variant; variant = tmp) {
98 tmp = variant->next;
Jakob Bornecrantz31926332009-11-16 19:56:18 +010099
Brian Paule0542512015-08-13 11:00:58 -0700100 /* Check if deleting currently bound shader */
101 if (variant == svga->state.hw_draw.fs) {
102 ret = svga_set_shader(svga, SVGA3D_SHADERTYPE_PS, NULL);
103 if (ret != PIPE_OK) {
104 svga_context_flush(svga, NULL);
105 ret = svga_set_shader(svga, SVGA3D_SHADERTYPE_PS, NULL);
106 assert(ret == PIPE_OK);
107 }
José Fonseca38d8b182010-01-05 17:56:26 +0000108 svga->state.hw_draw.fs = NULL;
Brian Paule0542512015-08-13 11:00:58 -0700109 }
110
111 ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant);
112 if (ret != PIPE_OK) {
113 svga_context_flush(svga, NULL);
114 ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant);
115 assert(ret == PIPE_OK);
116 }
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100117 }
118
119 FREE((void *)fs->base.tokens);
120 FREE(fs);
121}
122
123
Brian Paulef1b2b82013-04-18 15:56:53 -0600124void
125svga_init_fs_functions(struct svga_context *svga)
Jakob Bornecrantz31926332009-11-16 19:56:18 +0100126{
127 svga->pipe.create_fs_state = svga_create_fs_state;
128 svga->pipe.bind_fs_state = svga_bind_fs_state;
129 svga->pipe.delete_fs_state = svga_delete_fs_state;
130}