Merge branch '7.8'
[mesa.git] / src / gallium / drivers / trace / tr_state.c
1 /*
2 * Copyright 2009 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "tr_state.h"
26
27 #include "util/u_memory.h"
28 #include "util/u_simple_list.h"
29
30 #include "tgsi/tgsi_parse.h"
31
32 struct trace_shader * trace_shader_create(struct trace_context *tr_ctx,
33 const struct pipe_shader_state *state,
34 void *result,
35 enum trace_shader_type type)
36 {
37 struct trace_shader *tr_shdr = CALLOC_STRUCT(trace_shader);
38
39 tr_shdr->state = result;
40 tr_shdr->type = type;
41 tr_shdr->tokens = tgsi_dup_tokens(state->tokens);
42
43 /* works on context as well */
44 trace_screen_add_to_list(tr_ctx, shaders, tr_shdr);
45
46 return tr_shdr;
47 }
48
49 void trace_shader_destroy(struct trace_context *tr_ctx,
50 struct trace_shader *tr_shdr)
51 {
52 trace_screen_remove_from_list(tr_ctx, shaders, tr_shdr);
53
54 if (tr_shdr->replaced) {
55 if (tr_shdr->type == TRACE_SHADER_FRAGMENT)
56 tr_ctx->pipe->delete_fs_state(tr_ctx->pipe, tr_shdr->replaced);
57 else if (tr_shdr->type == TRACE_SHADER_VERTEX)
58 tr_ctx->pipe->delete_vs_state(tr_ctx->pipe, tr_shdr->replaced);
59 else
60 assert(0);
61 }
62
63 FREE(tr_shdr->replaced_tokens);
64 FREE(tr_shdr->tokens);
65 FREE(tr_shdr);
66 }