st/nine: Programmable ps D3DTTSS_PROJECTED support
[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
32 struct nine_lconstf;
33
34 struct NinePixelShader9
35 {
36 struct NineUnknown base;
37 struct nine_shader_variant64 variant;
38
39 struct {
40 const DWORD *tokens;
41 DWORD size;
42 uint8_t version; /* (major << 4) | minor */
43 } byte_code;
44
45 unsigned const_used_size; /* in bytes */
46
47 uint8_t bumpenvmat_needed;
48 uint16_t sampler_mask;
49 uint8_t rt_mask;
50
51 uint64_t ff_key[6];
52 void *ff_cso;
53
54 uint64_t last_key;
55 void *last_cso;
56
57 uint64_t next_key;
58 };
59 static inline struct NinePixelShader9 *
60 NinePixelShader9( void *data )
61 {
62 return (struct NinePixelShader9 *)data;
63 }
64
65 static inline BOOL
66 NinePixelShader9_UpdateKey( struct NinePixelShader9 *ps,
67 struct nine_state *state )
68 {
69 uint16_t samplers_shadow;
70 uint32_t samplers_ps1_types;
71 uint16_t projected;
72 uint64_t key;
73 BOOL res;
74
75 if (unlikely(ps->byte_code.version < 0x20)) {
76 /* no depth textures, but variable targets */
77 uint32_t m = ps->sampler_mask;
78 samplers_ps1_types = 0;
79 while (m) {
80 int s = ffs(m) - 1;
81 m &= ~(1 << s);
82 samplers_ps1_types |= (state->texture[s] ? state->texture[s]->pstype : 1) << (s * 2);
83 }
84 key = samplers_ps1_types;
85 } else {
86 samplers_shadow = (uint16_t)((state->samplers_shadow & NINE_PS_SAMPLERS_MASK) >> NINE_SAMPLER_PS(0));
87 key = samplers_shadow & ps->sampler_mask;
88 }
89
90 if (ps->byte_code.version < 0x30) {
91 key |= ((uint64_t)state->rs[D3DRS_FOGENABLE]) << 32;
92 key |= ((uint64_t)state->rs[D3DRS_FOGTABLEMODE]) << 33;
93 }
94
95 if (unlikely(ps->byte_code.version < 0x14)) {
96 projected = nine_ff_get_projected_key(state);
97 key |= ((uint64_t) projected) << 48;
98 }
99
100 res = ps->last_key != key;
101 if (res)
102 ps->next_key = key;
103 return res;
104 }
105
106 void *
107 NinePixelShader9_GetVariant( struct NinePixelShader9 *ps );
108
109 /*** public ***/
110
111 HRESULT
112 NinePixelShader9_new( struct NineDevice9 *pDevice,
113 struct NinePixelShader9 **ppOut,
114 const DWORD *pFunction, void *cso );
115
116 HRESULT
117 NinePixelShader9_ctor( struct NinePixelShader9 *,
118 struct NineUnknownParams *pParams,
119 const DWORD *pFunction, void *cso );
120
121 void
122 NinePixelShader9_dtor( struct NinePixelShader9 * );
123
124 HRESULT WINAPI
125 NinePixelShader9_GetFunction( struct NinePixelShader9 *This,
126 void *pData,
127 UINT *pSizeOfData );
128
129 #endif /* _NINE_PIXELSHADER9_H_ */