st/nine: Fix volumetexture dtor on ctor failure
[mesa.git] / src / gallium / state_trackers / nine / pixelshader9.h
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #ifndef _NINE_PIXELSHADER9_H_
24 #define _NINE_PIXELSHADER9_H_
25
26 #include "iunknown.h"
27 #include "nine_shader.h"
28 #include "nine_state.h"
29 #include "basetexture9.h"
30 #include "nine_ff.h"
31 #include "surface9.h"
32
33 struct nine_lconstf;
34
35 struct NinePixelShader9
36 {
37 struct NineUnknown base;
38 struct nine_shader_variant variant;
39
40 struct {
41 const DWORD *tokens;
42 DWORD size;
43 uint8_t version; /* (major << 4) | minor */
44 } byte_code;
45
46 unsigned const_used_size; /* in bytes */
47
48 uint8_t bumpenvmat_needed;
49 uint16_t sampler_mask;
50 uint8_t rt_mask;
51
52 uint64_t ff_key[6];
53 void *ff_cso;
54
55 uint64_t last_key;
56 void *last_cso;
57
58 uint64_t next_key;
59 };
60 static inline struct NinePixelShader9 *
61 NinePixelShader9( void *data )
62 {
63 return (struct NinePixelShader9 *)data;
64 }
65
66 static inline BOOL
67 NinePixelShader9_UpdateKey( struct NinePixelShader9 *ps,
68 struct nine_context *context )
69 {
70 uint16_t samplers_shadow;
71 uint16_t samplers_ps1_types;
72 uint16_t projected;
73 uint64_t key;
74 BOOL res;
75
76 samplers_shadow = (uint16_t)((context->samplers_shadow & NINE_PS_SAMPLERS_MASK) >> NINE_SAMPLER_PS(0));
77 key = samplers_shadow & ps->sampler_mask;
78
79 if (unlikely(ps->byte_code.version < 0x20)) {
80 /* variable targets */
81 uint32_t m = ps->sampler_mask;
82 samplers_ps1_types = 0;
83 while (m) {
84 int s = ffs(m) - 1;
85 m &= ~(1 << s);
86 samplers_ps1_types |= (context->texture[s].enabled ? context->texture[s].pstype : 1) << (s * 2);
87 }
88 /* Note: For ps 1.X, only samplers 0 1 2 and 3 are available (except 1.4 where 4 and 5 are available).
89 * Thus there is no overflow of samplers_ps1_types. */
90 key |= samplers_ps1_types << 16;
91 }
92
93 if (ps->byte_code.version < 0x30) {
94 key |= ((uint64_t)context->rs[D3DRS_FOGENABLE]) << 32;
95 key |= ((uint64_t)context->rs[D3DRS_FOGTABLEMODE]) << 33;
96 }
97
98 /* centroid interpolation automatically used for color ps inputs */
99 if (context->rt[0]->base.info.nr_samples)
100 key |= ((uint64_t)1) << 34;
101
102 if (unlikely(ps->byte_code.version < 0x14)) {
103 projected = nine_ff_get_projected_key(context);
104 key |= ((uint64_t) projected) << 48;
105 }
106
107 res = ps->last_key != key;
108 if (res)
109 ps->next_key = key;
110 return res;
111 }
112
113 void *
114 NinePixelShader9_GetVariant( struct NinePixelShader9 *ps );
115
116 /*** public ***/
117
118 HRESULT
119 NinePixelShader9_new( struct NineDevice9 *pDevice,
120 struct NinePixelShader9 **ppOut,
121 const DWORD *pFunction, void *cso );
122
123 HRESULT
124 NinePixelShader9_ctor( struct NinePixelShader9 *,
125 struct NineUnknownParams *pParams,
126 const DWORD *pFunction, void *cso );
127
128 void
129 NinePixelShader9_dtor( struct NinePixelShader9 * );
130
131 HRESULT NINE_WINAPI
132 NinePixelShader9_GetFunction( struct NinePixelShader9 *This,
133 void *pData,
134 UINT *pSizeOfData );
135
136 #endif /* _NINE_PIXELSHADER9_H_ */