1 /*
2 * Copyright 2011 Joakim Sindholt <[email protected]>
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef _NINE_VERTEXSHADER9_H_
7 #define _NINE_VERTEXSHADER9_H_
8
9 #include "util/half_float.h"
10
11 #include "iunknown.h"
12 #include "device9.h"
13 #include "nine_helpers.h"
14 #include "nine_shader.h"
15 #include "nine_state.h"
16
17 struct NineVertexDeclaration9;
18
19 struct NineVertexShader9
20 {
21 struct NineUnknown base;
22 struct nine_shader_variant variant;
23
24 struct {
25 uint16_t ndecl; /* NINE_DECLUSAGE_x */
26 } input_map[PIPE_MAX_ATTRIBS];
27 unsigned num_inputs;
28
29 struct {
30 const DWORD *tokens;
31 DWORD size;
32 uint8_t version; /* (major << 4) | minor */
33 } byte_code;
34
35 uint8_t sampler_mask;
36
37 bool position_t; /* if true, disable vport transform */
38 bool point_size; /* if true, set rasterizer.point_size_per_vertex to 1 */
39 bool swvp_only;
40
41 struct nine_lconstf lconstf;
42
43 bool int_slots_used[NINE_MAX_CONST_I];
44 bool bool_slots_used[NINE_MAX_CONST_B];
45
46 unsigned const_int_slots;
47 unsigned const_bool_slots;
48
49 struct nine_shader_constant_combination *c_combinations;
50
51 uint64_t ff_key[3];
52 void *ff_cso;
53
54 uint64_t last_key;
55 void *last_cso;
56 unsigned *last_const_ranges;
57 unsigned last_const_used_size; /* in bytes */
58
59 uint64_t next_key;
60
61 /* so */
62 struct nine_shader_variant_so variant_so;
63 };
64 static inline struct NineVertexShader9 *
NineVertexShader9(void * data)65 NineVertexShader9( void *data )
66 {
67 return (struct NineVertexShader9 *)data;
68 }
69
70 static inline BOOL
NineVertexShader9_UpdateKey(struct NineVertexShader9 * vs,struct NineDevice9 * device)71 NineVertexShader9_UpdateKey( struct NineVertexShader9 *vs,
72 struct NineDevice9 *device )
73 {
74 struct nine_context *context = &(device->context);
75 uint8_t samplers_shadow;
76 uint64_t key;
77 BOOL res;
78
79 samplers_shadow = (uint8_t)((context->samplers_shadow & NINE_VS_SAMPLERS_MASK) >> NINE_SAMPLER_VS(0));
80 samplers_shadow &= vs->sampler_mask;
81 key = samplers_shadow;
82
83 if (vs->byte_code.version < 0x30)
84 key |= (uint32_t) ((!!context->rs[D3DRS_FOGENABLE]) << 8);
85 key |= (uint32_t) (context->swvp << 9);
86
87 if ((vs->const_int_slots > 0 || vs->const_bool_slots > 0) && context->inline_constants && !context->swvp)
88 key |= ((uint64_t)nine_shader_constant_combination_key(&vs->c_combinations,
89 vs->int_slots_used,
90 vs->bool_slots_used,
91 context->vs_const_i,
92 context->vs_const_b)) << 16;
93
94 if (device->driver_caps.emulate_ucp)
95 key |= (context->rs[D3DRS_CLIPPLANEENABLE] & 0xff) << 24;
96
97 /* We want to use a 64 bits key for performance.
98 * Use compressed float16 values for the pointsize min/max in the key.
99 * Shaders do not usually output psize.*/
100 if (vs->point_size) {
101 key |= ((uint64_t)_mesa_float_to_half(asfloat(context->rs[D3DRS_POINTSIZE_MIN]))) << 32;
102 key |= ((uint64_t)_mesa_float_to_half(asfloat(context->rs[D3DRS_POINTSIZE_MAX]))) << 48;
103 }
104
105 res = vs->last_key != key;
106 if (res)
107 vs->next_key = key;
108 return res;
109 }
110
111 void *
112 NineVertexShader9_GetVariant( struct NineVertexShader9 *vs,
113 unsigned **const_ranges,
114 unsigned *const_used_size );
115
116 void *
117 NineVertexShader9_GetVariantProcessVertices( struct NineVertexShader9 *vs,
118 struct NineVertexDeclaration9 *vdecl_out,
119 struct pipe_stream_output_info *so );
120
121 /*** public ***/
122
123 HRESULT
124 NineVertexShader9_new( struct NineDevice9 *pDevice,
125 struct NineVertexShader9 **ppOut,
126 const DWORD *pFunction, void *cso );
127
128 HRESULT
129 NineVertexShader9_ctor( struct NineVertexShader9 *,
130 struct NineUnknownParams *pParams,
131 const DWORD *pFunction, void *cso );
132
133 void
134 NineVertexShader9_dtor( struct NineVertexShader9 * );
135
136 HRESULT NINE_WINAPI
137 NineVertexShader9_GetFunction( struct NineVertexShader9 *This,
138 void *pData,
139 UINT *pSizeOfData );
140
141 #endif /* _NINE_VERTEXSHADER9_H_ */
142