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