updated some printfs, added comment about sched_yield
[mesa.git] / src / mesa / shader / slang / slang_analyse.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file slang_analyse.c
27 * slang assembly code analysis
28 * \author Michal Krol
29 */
30
31 #include "imports.h"
32 #include "slang_analyse.h"
33 #include "slang_utility.h"
34
35 GLboolean _slang_analyse_texture_usage (slang_program *prog)
36 {
37 GLuint i, count = 0;
38
39 slang_texture_usages_dtr (&prog->texture_usage);
40 slang_texture_usages_ctr (&prog->texture_usage);
41
42 /*
43 * We could do a full code analysis to find out which uniforms are actually used.
44 * For now, we are very conservative and extract them from uniform binding table, which
45 * in turn also do not come from code analysis.
46 */
47
48 for (i = 0; i < prog->uniforms.count; i++)
49 {
50 slang_uniform_binding *b = &prog->uniforms.table[i];
51
52 if (b->address[SLANG_SHADER_FRAGMENT] != ~0 && b->quant->structure == NULL)
53 {
54 switch (b->quant->u.basic_type)
55 {
56 case GL_SAMPLER_1D_ARB:
57 case GL_SAMPLER_2D_ARB:
58 case GL_SAMPLER_3D_ARB:
59 case GL_SAMPLER_CUBE_ARB:
60 case GL_SAMPLER_1D_SHADOW_ARB:
61 case GL_SAMPLER_2D_SHADOW_ARB:
62 count++;
63 break;
64 }
65 }
66 }
67
68 if (count == 0)
69 return GL_TRUE;
70 prog->texture_usage.table = (slang_texture_usage *) slang_alloc_malloc (
71 count * sizeof (slang_texture_usage));
72 if (prog->texture_usage.table == NULL)
73 return GL_FALSE;
74 prog->texture_usage.count = count;
75
76 for (count = i = 0; i < prog->uniforms.count; i++)
77 {
78 slang_uniform_binding *b = &prog->uniforms.table[i];
79
80 if (b->address[SLANG_SHADER_FRAGMENT] != ~0 && b->quant->structure == NULL)
81 {
82 switch (b->quant->u.basic_type)
83 {
84 case GL_SAMPLER_1D_ARB:
85 case GL_SAMPLER_2D_ARB:
86 case GL_SAMPLER_3D_ARB:
87 case GL_SAMPLER_CUBE_ARB:
88 case GL_SAMPLER_1D_SHADOW_ARB:
89 case GL_SAMPLER_2D_SHADOW_ARB:
90 prog->texture_usage.table[count].quant = b->quant;
91 prog->texture_usage.table[count].frag_address = b->address[SLANG_SHADER_FRAGMENT];
92 count++;
93 break;
94 }
95 }
96 }
97
98 return GL_TRUE;
99 }
100