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
);
51 This
->variant
.cso
= cso
;
54 device
= This
->base
.device
;
56 info
.type
= PIPE_SHADER_VERTEX
;
57 info
.byte_code
= pFunction
;
58 info
.const_i_base
= NINE_CONST_I_BASE(device
->max_vs_const_f
) / 16;
59 info
.const_b_base
= NINE_CONST_B_BASE(device
->max_vs_const_f
) / 16;
60 info
.sampler_mask_shadow
= 0x0;
61 info
.sampler_ps1xtypes
= 0x0;
63 hr
= nine_translate_shader(device
, &info
);
66 This
->byte_code
.version
= info
.version
;
68 This
->byte_code
.tokens
= mem_dup(pFunction
, info
.byte_size
);
69 if (!This
->byte_code
.tokens
)
71 This
->byte_code
.size
= info
.byte_size
;
73 This
->variant
.cso
= info
.cso
;
74 This
->const_used_size
= info
.const_used_size
;
75 This
->lconstf
= info
.lconstf
;
76 This
->sampler_mask
= info
.sampler_mask
;
77 This
->position_t
= info
.position_t
;
78 This
->point_size
= info
.point_size
;
80 for (i
= 0; i
< info
.num_inputs
&& i
< Elements(This
->input_map
); ++i
)
81 This
->input_map
[i
].ndecl
= info
.input_map
[i
];
88 NineVertexShader9_dtor( struct NineVertexShader9
*This
)
90 DBG("This=%p cso=%p\n", This
, This
->variant
.cso
);
92 if (This
->base
.device
) {
93 struct pipe_context
*pipe
= This
->base
.device
->pipe
;
94 struct nine_shader_variant
*var
= &This
->variant
;
97 if (This
->base
.device
->state
.cso
.vs
== var
->cso
)
98 pipe
->bind_vs_state(pipe
, NULL
);
99 pipe
->delete_vs_state(pipe
, var
->cso
);
104 nine_shader_variants_free(&This
->variant
);
106 FREE((void *)This
->byte_code
.tokens
); /* const_cast */
108 FREE(This
->lconstf
.data
);
109 FREE(This
->lconstf
.ranges
);
111 NineUnknown_dtor(&This
->base
);
115 NineVertexShader9_GetFunction( struct NineVertexShader9
*This
,
119 user_assert(pSizeOfData
, D3DERR_INVALIDCALL
);
122 *pSizeOfData
= This
->byte_code
.size
;
125 user_assert(*pSizeOfData
>= This
->byte_code
.size
, D3DERR_INVALIDCALL
);
127 memcpy(pData
, This
->byte_code
.tokens
, This
->byte_code
.size
);
133 NineVertexShader9_GetVariant( struct NineVertexShader9
*This
,
136 void *cso
= nine_shader_variant_get(&This
->variant
, key
);
138 struct NineDevice9
*device
= This
->base
.device
;
139 struct nine_shader_info info
;
142 info
.type
= PIPE_SHADER_VERTEX
;
143 info
.const_i_base
= NINE_CONST_I_BASE(device
->max_vs_const_f
) / 16;
144 info
.const_b_base
= NINE_CONST_B_BASE(device
->max_vs_const_f
) / 16;
145 info
.byte_code
= This
->byte_code
.tokens
;
146 info
.sampler_mask_shadow
= key
& 0xf;
148 hr
= nine_translate_shader(This
->base
.device
, &info
);
151 nine_shader_variant_add(&This
->variant
, key
, info
.cso
);
157 IDirect3DVertexShader9Vtbl NineVertexShader9_vtable
= {
158 (void *)NineUnknown_QueryInterface
,
159 (void *)NineUnknown_AddRef
,
160 (void *)NineUnknown_Release
,
161 (void *)NineUnknown_GetDevice
,
162 (void *)NineVertexShader9_GetFunction
165 static const GUID
*NineVertexShader9_IIDs
[] = {
166 &IID_IDirect3DVertexShader9
,
172 NineVertexShader9_new( struct NineDevice9
*pDevice
,
173 struct NineVertexShader9
**ppOut
,
174 const DWORD
*pFunction
, void *cso
)
176 NINE_DEVICE_CHILD_NEW(VertexShader9
, ppOut
, pDevice
, pFunction
, cso
);