1b8e80941Smrg/* 2b8e80941Smrg * Copyright 2011 Joakim Sindholt <opensource@zhasha.com> 3b8e80941Smrg * 4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 6b8e80941Smrg * to deal in the Software without restriction, including without limitation 7b8e80941Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 8b8e80941Smrg * license, and/or sell copies of the Software, and to permit persons to whom 9b8e80941Smrg * the Software is furnished to do so, subject to the following conditions: 10b8e80941Smrg * 11b8e80941Smrg * The above copyright notice and this permission notice (including the next 12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 13b8e80941Smrg * Software. 14b8e80941Smrg * 15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18b8e80941Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19b8e80941Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20b8e80941Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21b8e80941Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 22b8e80941Smrg 23b8e80941Smrg#ifndef _NINE_VERTEXSHADER9_H_ 24b8e80941Smrg#define _NINE_VERTEXSHADER9_H_ 25b8e80941Smrg 26b8e80941Smrg#include "util/u_half.h" 27b8e80941Smrg 28b8e80941Smrg#include "iunknown.h" 29b8e80941Smrg#include "device9.h" 30b8e80941Smrg#include "nine_helpers.h" 31b8e80941Smrg#include "nine_shader.h" 32b8e80941Smrg#include "nine_state.h" 33b8e80941Smrg 34b8e80941Smrgstruct NineVertexDeclaration9; 35b8e80941Smrg 36b8e80941Smrgstruct NineVertexShader9 37b8e80941Smrg{ 38b8e80941Smrg struct NineUnknown base; 39b8e80941Smrg struct nine_shader_variant variant; 40b8e80941Smrg 41b8e80941Smrg struct { 42b8e80941Smrg uint16_t ndecl; /* NINE_DECLUSAGE_x */ 43b8e80941Smrg } input_map[PIPE_MAX_ATTRIBS]; 44b8e80941Smrg unsigned num_inputs; 45b8e80941Smrg 46b8e80941Smrg struct { 47b8e80941Smrg const DWORD *tokens; 48b8e80941Smrg DWORD size; 49b8e80941Smrg uint8_t version; /* (major << 4) | minor */ 50b8e80941Smrg } byte_code; 51b8e80941Smrg 52b8e80941Smrg uint8_t sampler_mask; 53b8e80941Smrg 54b8e80941Smrg boolean position_t; /* if true, disable vport transform */ 55b8e80941Smrg boolean point_size; /* if true, set rasterizer.point_size_per_vertex to 1 */ 56b8e80941Smrg boolean swvp_only; 57b8e80941Smrg 58b8e80941Smrg struct nine_lconstf lconstf; 59b8e80941Smrg 60b8e80941Smrg boolean int_slots_used[NINE_MAX_CONST_I]; 61b8e80941Smrg boolean bool_slots_used[NINE_MAX_CONST_B]; 62b8e80941Smrg 63b8e80941Smrg unsigned const_int_slots; 64b8e80941Smrg unsigned const_bool_slots; 65b8e80941Smrg 66b8e80941Smrg struct nine_shader_constant_combination *c_combinations; 67b8e80941Smrg 68b8e80941Smrg uint64_t ff_key[3]; 69b8e80941Smrg void *ff_cso; 70b8e80941Smrg 71b8e80941Smrg uint64_t last_key; 72b8e80941Smrg void *last_cso; 73b8e80941Smrg unsigned *last_const_ranges; 74b8e80941Smrg unsigned last_const_used_size; /* in bytes */ 75b8e80941Smrg 76b8e80941Smrg uint64_t next_key; 77b8e80941Smrg 78b8e80941Smrg /* so */ 79b8e80941Smrg struct nine_shader_variant_so variant_so; 80b8e80941Smrg}; 81b8e80941Smrgstatic inline struct NineVertexShader9 * 82b8e80941SmrgNineVertexShader9( void *data ) 83b8e80941Smrg{ 84b8e80941Smrg return (struct NineVertexShader9 *)data; 85b8e80941Smrg} 86b8e80941Smrg 87b8e80941Smrgstatic inline BOOL 88b8e80941SmrgNineVertexShader9_UpdateKey( struct NineVertexShader9 *vs, 89b8e80941Smrg struct NineDevice9 *device ) 90b8e80941Smrg{ 91b8e80941Smrg struct nine_context *context = &(device->context); 92b8e80941Smrg uint8_t samplers_shadow; 93b8e80941Smrg uint64_t key; 94b8e80941Smrg BOOL res; 95b8e80941Smrg 96b8e80941Smrg samplers_shadow = (uint8_t)((context->samplers_shadow & NINE_VS_SAMPLERS_MASK) >> NINE_SAMPLER_VS(0)); 97b8e80941Smrg samplers_shadow &= vs->sampler_mask; 98b8e80941Smrg key = samplers_shadow; 99b8e80941Smrg 100b8e80941Smrg if (vs->byte_code.version < 0x30) 101b8e80941Smrg key |= (uint32_t) ((!!context->rs[D3DRS_FOGENABLE]) << 8); 102b8e80941Smrg key |= (uint32_t) (context->swvp << 9); 103b8e80941Smrg 104b8e80941Smrg if ((vs->const_int_slots > 0 || vs->const_bool_slots > 0) && context->inline_constants && !context->swvp) 105b8e80941Smrg key |= ((uint64_t)nine_shader_constant_combination_key(&vs->c_combinations, 106b8e80941Smrg vs->int_slots_used, 107b8e80941Smrg vs->bool_slots_used, 108b8e80941Smrg context->vs_const_i, 109b8e80941Smrg context->vs_const_b)) << 16; 110b8e80941Smrg 111b8e80941Smrg /* We want to use a 64 bits key for performance. 112b8e80941Smrg * Use compressed float16 values for the pointsize min/max in the key. 113b8e80941Smrg * Shaders do not usually output psize.*/ 114b8e80941Smrg if (vs->point_size) { 115b8e80941Smrg key |= ((uint64_t)util_float_to_half(asfloat(context->rs[D3DRS_POINTSIZE_MIN]))) << 32; 116b8e80941Smrg key |= ((uint64_t)util_float_to_half(asfloat(context->rs[D3DRS_POINTSIZE_MAX]))) << 48; 117b8e80941Smrg } 118b8e80941Smrg 119b8e80941Smrg res = vs->last_key != key; 120b8e80941Smrg if (res) 121b8e80941Smrg vs->next_key = key; 122b8e80941Smrg return res; 123b8e80941Smrg} 124b8e80941Smrg 125b8e80941Smrgvoid * 126b8e80941SmrgNineVertexShader9_GetVariant( struct NineVertexShader9 *vs, 127b8e80941Smrg unsigned **const_ranges, 128b8e80941Smrg unsigned *const_used_size ); 129b8e80941Smrg 130b8e80941Smrgvoid * 131b8e80941SmrgNineVertexShader9_GetVariantProcessVertices( struct NineVertexShader9 *vs, 132b8e80941Smrg struct NineVertexDeclaration9 *vdecl_out, 133b8e80941Smrg struct pipe_stream_output_info *so ); 134b8e80941Smrg 135b8e80941Smrg/*** public ***/ 136b8e80941Smrg 137b8e80941SmrgHRESULT 138b8e80941SmrgNineVertexShader9_new( struct NineDevice9 *pDevice, 139b8e80941Smrg struct NineVertexShader9 **ppOut, 140b8e80941Smrg const DWORD *pFunction, void *cso ); 141b8e80941Smrg 142b8e80941SmrgHRESULT 143b8e80941SmrgNineVertexShader9_ctor( struct NineVertexShader9 *, 144b8e80941Smrg struct NineUnknownParams *pParams, 145b8e80941Smrg const DWORD *pFunction, void *cso ); 146b8e80941Smrg 147b8e80941Smrgvoid 148b8e80941SmrgNineVertexShader9_dtor( struct NineVertexShader9 * ); 149b8e80941Smrg 150b8e80941SmrgHRESULT NINE_WINAPI 151b8e80941SmrgNineVertexShader9_GetFunction( struct NineVertexShader9 *This, 152b8e80941Smrg void *pData, 153b8e80941Smrg UINT *pSizeOfData ); 154b8e80941Smrg 155b8e80941Smrg#endif /* _NINE_VERTEXSHADER9_H_ */ 156