2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
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:
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
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. */
23 #include "nine_helpers.h"
24 #include "nine_shader.h"
26 #include "vertexshader9.h"
29 #include "pipe/p_context.h"
31 #define DBG_CHANNEL DBG_VERTEXSHADER
34 NineVertexShader9_ctor( struct NineVertexShader9
*This
,
35 struct NineUnknownParams
*pParams
,
36 const DWORD
*pFunction
, void *cso
)
38 struct NineDevice9
*device
;
39 struct nine_shader_info info
;
43 DBG("This=%p pParams=%p pFunction=%p cso=%p\n",
44 This
, pParams
, pFunction
, cso
);
46 hr
= NineUnknown_ctor(&This
->base
, pParams
);
55 device
= This
->base
.device
;
57 info
.type
= PIPE_SHADER_VERTEX
;
58 info
.byte_code
= pFunction
;
59 info
.const_i_base
= NINE_CONST_I_BASE(device
->max_vs_const_f
) / 16;
60 info
.const_b_base
= NINE_CONST_B_BASE(device
->max_vs_const_f
) / 16;
61 info
.sampler_mask_shadow
= 0x0;
62 info
.sampler_ps1xtypes
= 0x0;
65 hr
= nine_translate_shader(device
, &info
);
68 This
->byte_code
.version
= info
.version
;
70 This
->byte_code
.tokens
= mem_dup(pFunction
, info
.byte_size
);
71 if (!This
->byte_code
.tokens
)
73 This
->byte_code
.size
= info
.byte_size
;
75 This
->variant
.cso
= info
.cso
;
76 This
->last_cso
= info
.cso
;
79 This
->const_used_size
= info
.const_used_size
;
80 This
->lconstf
= info
.lconstf
;
81 This
->sampler_mask
= info
.sampler_mask
;
82 This
->position_t
= info
.position_t
;
83 This
->point_size
= info
.point_size
;
85 for (i
= 0; i
< info
.num_inputs
&& i
< Elements(This
->input_map
); ++i
)
86 This
->input_map
[i
].ndecl
= info
.input_map
[i
];
93 NineVertexShader9_dtor( struct NineVertexShader9
*This
)
95 DBG("This=%p\n", This
);
97 if (This
->base
.device
) {
98 struct pipe_context
*pipe
= This
->base
.device
->pipe
;
99 struct nine_shader_variant
*var
= &This
->variant
;
103 if (This
->base
.device
->state
.cso
.vs
== var
->cso
)
104 pipe
->bind_vs_state(pipe
, NULL
);
105 pipe
->delete_vs_state(pipe
, var
->cso
);
111 if (This
->ff_cso
== This
->base
.device
->state
.cso
.vs
)
112 pipe
->bind_vs_state(pipe
, NULL
);
113 pipe
->delete_vs_state(pipe
, This
->ff_cso
);
116 nine_shader_variants_free(&This
->variant
);
118 FREE((void *)This
->byte_code
.tokens
); /* const_cast */
120 FREE(This
->lconstf
.data
);
121 FREE(This
->lconstf
.ranges
);
123 NineUnknown_dtor(&This
->base
);
127 NineVertexShader9_GetFunction( struct NineVertexShader9
*This
,
131 user_assert(pSizeOfData
, D3DERR_INVALIDCALL
);
134 *pSizeOfData
= This
->byte_code
.size
;
137 user_assert(*pSizeOfData
>= This
->byte_code
.size
, D3DERR_INVALIDCALL
);
139 memcpy(pData
, This
->byte_code
.tokens
, This
->byte_code
.size
);
145 NineVertexShader9_GetVariant( struct NineVertexShader9
*This
)
150 key
= This
->next_key
;
151 if (key
== This
->last_key
)
152 return This
->last_cso
;
154 cso
= nine_shader_variant_get(&This
->variant
, key
);
156 struct NineDevice9
*device
= This
->base
.device
;
157 struct nine_shader_info info
;
160 info
.type
= PIPE_SHADER_VERTEX
;
161 info
.const_i_base
= NINE_CONST_I_BASE(device
->max_vs_const_f
) / 16;
162 info
.const_b_base
= NINE_CONST_B_BASE(device
->max_vs_const_f
) / 16;
163 info
.byte_code
= This
->byte_code
.tokens
;
164 info
.sampler_mask_shadow
= key
& 0xf;
165 info
.fog_enable
= device
->state
.rs
[D3DRS_FOGENABLE
];
167 hr
= nine_translate_shader(This
->base
.device
, &info
);
170 nine_shader_variant_add(&This
->variant
, key
, info
.cso
);
174 This
->last_key
= key
;
175 This
->last_cso
= cso
;
180 IDirect3DVertexShader9Vtbl NineVertexShader9_vtable
= {
181 (void *)NineUnknown_QueryInterface
,
182 (void *)NineUnknown_AddRef
,
183 (void *)NineUnknown_Release
,
184 (void *)NineUnknown_GetDevice
,
185 (void *)NineVertexShader9_GetFunction
188 static const GUID
*NineVertexShader9_IIDs
[] = {
189 &IID_IDirect3DVertexShader9
,
195 NineVertexShader9_new( struct NineDevice9
*pDevice
,
196 struct NineVertexShader9
**ppOut
,
197 const DWORD
*pFunction
, void *cso
)
199 NINE_DEVICE_CHILD_NEW(VertexShader9
, ppOut
, pDevice
, pFunction
, cso
);