f4dae76de0df7c0d2d1f2ff32723944c5ce907b1
[mesa.git] / src / mesa / shader / prog_instruction.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
5 * Copyright (C) 1999-2005 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 #include "glheader.h"
27 #include "imports.h"
28 #include "mtypes.h"
29 #include "prog_instruction.h"
30
31
32 /**
33 * Initialize program instruction fields to defaults.
34 * \param inst first instruction to initialize
35 * \param count number of instructions to initialize
36 */
37 void
38 _mesa_init_instructions(struct prog_instruction *inst, GLuint count)
39 {
40 GLuint i;
41
42 _mesa_bzero(inst, count * sizeof(struct prog_instruction));
43
44 for (i = 0; i < count; i++) {
45 inst[i].SrcReg[0].File = PROGRAM_UNDEFINED;
46 inst[i].SrcReg[0].Swizzle = SWIZZLE_NOOP;
47 inst[i].SrcReg[1].File = PROGRAM_UNDEFINED;
48 inst[i].SrcReg[1].Swizzle = SWIZZLE_NOOP;
49 inst[i].SrcReg[2].File = PROGRAM_UNDEFINED;
50 inst[i].SrcReg[2].Swizzle = SWIZZLE_NOOP;
51
52 inst[i].DstReg.File = PROGRAM_UNDEFINED;
53 inst[i].DstReg.WriteMask = WRITEMASK_XYZW;
54 inst[i].DstReg.CondMask = COND_TR;
55 inst[i].DstReg.CondSwizzle = SWIZZLE_NOOP;
56
57 inst[i].SaturateMode = SATURATE_OFF;
58 inst[i].Precision = FLOAT32;
59 }
60 }
61
62
63 /**
64 * Allocate an array of program instructions.
65 * \param numInst number of instructions
66 * \return pointer to instruction memory
67 */
68 struct prog_instruction *
69 _mesa_alloc_instructions(GLuint numInst)
70 {
71 return (struct prog_instruction *)
72 _mesa_calloc(numInst * sizeof(struct prog_instruction));
73 }
74
75
76 /**
77 * Reallocate memory storing an array of program instructions.
78 * This is used when we need to append additional instructions onto an
79 * program.
80 * \param oldInst pointer to first of old/src instructions
81 * \param numOldInst number of instructions at <oldInst>
82 * \param numNewInst desired size of new instruction array.
83 * \return pointer to start of new instruction array.
84 */
85 struct prog_instruction *
86 _mesa_realloc_instructions(struct prog_instruction *oldInst,
87 GLuint numOldInst, GLuint numNewInst)
88 {
89 struct prog_instruction *newInst;
90
91 newInst = (struct prog_instruction *)
92 _mesa_realloc(oldInst,
93 numOldInst * sizeof(struct prog_instruction),
94 numNewInst * sizeof(struct prog_instruction));
95
96 return newInst;
97 }
98
99