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 "pixelshader9.h"
29 #include "pipe/p_context.h"
31 #define DBG_CHANNEL DBG_PIXELSHADER
34 NinePixelShader9_ctor( struct NinePixelShader9
*This
,
35 struct NineUnknownParams
*pParams
,
36 const DWORD
*pFunction
, void *cso
)
38 struct NineDevice9
*device
;
39 struct nine_shader_info info
;
42 hr
= NineUnknown_ctor(&This
->base
, pParams
);
47 This
->variant
.cso
= cso
;
50 device
= This
->base
.device
;
52 info
.type
= PIPE_SHADER_FRAGMENT
;
53 info
.byte_code
= pFunction
;
54 info
.const_i_base
= NINE_CONST_I_BASE(device
->max_ps_const_f
) / 16;
55 info
.const_b_base
= NINE_CONST_B_BASE(device
->max_ps_const_f
) / 16;
56 info
.sampler_mask_shadow
= 0x0;
57 info
.sampler_ps1xtypes
= 0x0;
59 hr
= nine_translate_shader(device
, &info
);
62 This
->byte_code
.version
= info
.version
;
64 This
->byte_code
.tokens
= mem_dup(pFunction
, info
.byte_size
);
65 if (!This
->byte_code
.tokens
)
67 This
->byte_code
.size
= info
.byte_size
;
69 This
->variant
.cso
= info
.cso
;
70 This
->sampler_mask
= info
.sampler_mask
;
71 This
->rt_mask
= info
.rt_mask
;
72 This
->const_used_size
= info
.const_used_size
;
73 if (info
.const_used_size
== ~0)
74 This
->const_used_size
= NINE_CONSTBUF_SIZE(device
->max_ps_const_f
);
75 This
->lconstf
= info
.lconstf
;
81 NinePixelShader9_dtor( struct NinePixelShader9
*This
)
83 DBG("This=%p cso=%p\n", This
, This
->variant
.cso
);
85 if (This
->base
.device
) {
86 struct pipe_context
*pipe
= This
->base
.device
->pipe
;
87 struct nine_shader_variant
*var
= &This
->variant
;
90 if (This
->base
.device
->state
.cso
.ps
== var
->cso
)
91 pipe
->bind_fs_state(pipe
, NULL
);
92 pipe
->delete_fs_state(pipe
, var
->cso
);
97 nine_shader_variants_free(&This
->variant
);
99 if (This
->byte_code
.tokens
)
100 FREE((void *)This
->byte_code
.tokens
); /* const_cast */
102 FREE(This
->lconstf
.data
);
103 FREE(This
->lconstf
.ranges
);
105 NineUnknown_dtor(&This
->base
);
109 NinePixelShader9_GetFunction( struct NinePixelShader9
*This
,
113 user_assert(pSizeOfData
, D3DERR_INVALIDCALL
);
116 *pSizeOfData
= This
->byte_code
.size
;
119 user_assert(*pSizeOfData
>= This
->byte_code
.size
, D3DERR_INVALIDCALL
);
121 memcpy(pData
, This
->byte_code
.tokens
, This
->byte_code
.size
);
127 NinePixelShader9_GetVariant( struct NinePixelShader9
*This
,
130 void *cso
= nine_shader_variant_get(&This
->variant
, key
);
132 struct NineDevice9
*device
= This
->base
.device
;
133 struct nine_shader_info info
;
136 info
.type
= PIPE_SHADER_FRAGMENT
;
137 info
.const_i_base
= NINE_CONST_I_BASE(device
->max_ps_const_f
) / 16;
138 info
.const_b_base
= NINE_CONST_B_BASE(device
->max_ps_const_f
) / 16;
139 info
.byte_code
= This
->byte_code
.tokens
;
140 info
.sampler_mask_shadow
= key
& 0xffff;
141 info
.sampler_ps1xtypes
= key
;
143 hr
= nine_translate_shader(This
->base
.device
, &info
);
146 nine_shader_variant_add(&This
->variant
, key
, info
.cso
);
152 IDirect3DPixelShader9Vtbl NinePixelShader9_vtable
= {
153 (void *)NineUnknown_QueryInterface
,
154 (void *)NineUnknown_AddRef
,
155 (void *)NineUnknown_Release
,
156 (void *)NineUnknown_GetDevice
,
157 (void *)NinePixelShader9_GetFunction
160 static const GUID
*NinePixelShader9_IIDs
[] = {
161 &IID_IDirect3DPixelShader9
,
167 NinePixelShader9_new( struct NineDevice9
*pDevice
,
168 struct NinePixelShader9
**ppOut
,
169 const DWORD
*pFunction
, void *cso
)
171 NINE_DEVICE_CHILD_NEW(PixelShader9
, ppOut
, pDevice
, pFunction
, cso
);