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 if (info
.const_used_size
== ~0)
76 This
->const_used_size
= NINE_CONSTBUF_SIZE(device
->max_vs_const_f
);
77 This
->lconstf
= info
.lconstf
;
78 This
->sampler_mask
= info
.sampler_mask
;
79 This
->position_t
= info
.position_t
;
80 This
->point_size
= info
.point_size
;
82 for (i
= 0; i
< info
.num_inputs
&& i
< Elements(This
->input_map
); ++i
)
83 This
->input_map
[i
].ndecl
= info
.input_map
[i
];
90 NineVertexShader9_dtor( struct NineVertexShader9
*This
)
92 DBG("This=%p cso=%p\n", This
, This
->variant
.cso
);
94 if (This
->base
.device
) {
95 struct pipe_context
*pipe
= This
->base
.device
->pipe
;
96 struct nine_shader_variant
*var
= &This
->variant
;
99 if (This
->base
.device
->state
.cso
.vs
== var
->cso
)
100 pipe
->bind_vs_state(pipe
, NULL
);
101 pipe
->delete_vs_state(pipe
, var
->cso
);
106 nine_shader_variants_free(&This
->variant
);
108 FREE((void *)This
->byte_code
.tokens
); /* const_cast */
110 FREE(This
->lconstf
.data
);
111 FREE(This
->lconstf
.ranges
);
113 NineUnknown_dtor(&This
->base
);
117 NineVertexShader9_GetFunction( struct NineVertexShader9
*This
,
121 user_assert(pSizeOfData
, D3DERR_INVALIDCALL
);
124 *pSizeOfData
= This
->byte_code
.size
;
127 user_assert(*pSizeOfData
>= This
->byte_code
.size
, D3DERR_INVALIDCALL
);
129 memcpy(pData
, This
->byte_code
.tokens
, This
->byte_code
.size
);
135 NineVertexShader9_GetVariant( struct NineVertexShader9
*This
,
138 void *cso
= nine_shader_variant_get(&This
->variant
, key
);
140 struct NineDevice9
*device
= This
->base
.device
;
141 struct nine_shader_info info
;
144 info
.type
= PIPE_SHADER_VERTEX
;
145 info
.const_i_base
= NINE_CONST_I_BASE(device
->max_vs_const_f
) / 16;
146 info
.const_b_base
= NINE_CONST_B_BASE(device
->max_vs_const_f
) / 16;
147 info
.byte_code
= This
->byte_code
.tokens
;
148 info
.sampler_mask_shadow
= key
& 0xf;
150 hr
= nine_translate_shader(This
->base
.device
, &info
);
153 nine_shader_variant_add(&This
->variant
, key
, info
.cso
);
159 IDirect3DVertexShader9Vtbl NineVertexShader9_vtable
= {
160 (void *)NineUnknown_QueryInterface
,
161 (void *)NineUnknown_AddRef
,
162 (void *)NineUnknown_Release
,
163 (void *)NineUnknown_GetDevice
,
164 (void *)NineVertexShader9_GetFunction
167 static const GUID
*NineVertexShader9_IIDs
[] = {
168 &IID_IDirect3DVertexShader9
,
174 NineVertexShader9_new( struct NineDevice9
*pDevice
,
175 struct NineVertexShader9
**ppOut
,
176 const DWORD
*pFunction
, void *cso
)
178 NINE_DEVICE_CHILD_NEW(VertexShader9
, ppOut
, pDevice
, pFunction
, cso
);