2 * Mesa 3-D graphics library
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
26 * \file slang_analyse.c
27 * slang assembly code analysis
32 #include "slang_analyse.h"
33 #include "slang_utility.h"
35 GLboolean
_slang_analyse_texture_usage (slang_program
*prog
)
39 slang_texture_usages_dtr (&prog
->texture_usage
);
40 slang_texture_usages_ctr (&prog
->texture_usage
);
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.
48 for (i
= 0; i
< prog
->uniforms
.count
; i
++)
50 slang_uniform_binding
*b
= &prog
->uniforms
.table
[i
];
52 if (b
->address
[SLANG_SHADER_FRAGMENT
] != ~0 && b
->quant
->structure
== NULL
)
54 switch (b
->quant
->u
.basic_type
)
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
:
70 prog
->texture_usage
.table
= (slang_texture_usage
*) slang_alloc_malloc (
71 count
* sizeof (slang_texture_usage
));
72 if (prog
->texture_usage
.table
== NULL
)
74 prog
->texture_usage
.count
= count
;
76 for (count
= i
= 0; i
< prog
->uniforms
.count
; i
++)
78 slang_uniform_binding
*b
= &prog
->uniforms
.table
[i
];
80 if (b
->address
[SLANG_SHADER_FRAGMENT
] != ~0 && b
->quant
->structure
== NULL
)
82 switch (b
->quant
->u
.basic_type
)
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
];