nine_shader.h revision fdd96578ef2dfe9c4ad5aab5858036298d444a64
1fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt/* 2fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * Copyright 2011 Joakim Sindholt <opensource@zhasha.com> 3fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * 4fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * Permission is hereby granted, free of charge, to any person obtaining a 5fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * copy of this software and associated documentation files (the "Software"), 6fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * to deal in the Software without restriction, including without limitation 7fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * on the rights to use, copy, modify, merge, publish, distribute, sub 8fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * license, and/or sell copies of the Software, and to permit persons to whom 9fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * the Software is furnished to do so, subject to the following conditions: 10fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * 11fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * The above copyright notice and this permission notice (including the next 12fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * paragraph) shall be included in all copies or substantial portions of the 13fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * Software. 14fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * 15fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 22fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 23fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#ifndef _NINE_SHADER_H_ 24fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#define _NINE_SHADER_H_ 25fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 26fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "d3d9types.h" 27fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "d3d9caps.h" 28fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "nine_defines.h" 29fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "pipe/p_state.h" /* PIPE_MAX_ATTRIBS */ 30fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#include "util/u_memory.h" 31fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 32fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstruct NineDevice9; 33fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 34fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstruct nine_lconstf /* NOTE: both pointers should be FREE'd by the user */ 35fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{ 36fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt struct nine_range *ranges; /* single MALLOC, but next-pointers valid */ 37fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt float *data; 38fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}; 39fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 40fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstruct nine_shader_info 41fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{ 42fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt unsigned type; /* in, PIPE_SHADER_x */ 43fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 44fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt uint8_t version; /* (major << 4) | minor */ 45fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 46fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt const DWORD *byte_code; /* in, pointer to shader tokens */ 47fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt DWORD byte_size; /* out, size of data at byte_code */ 48fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 49fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt void *cso; /* out, pipe cso for bind_vs,fs_state */ 50fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 51fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt uint8_t input_map[PIPE_MAX_ATTRIBS]; /* VS input -> NINE_DECLUSAGE_x */ 52fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt uint8_t num_inputs; /* there may be unused inputs (NINE_DECLUSAGE_NONE) */ 53fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 54fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt boolean position_t; /* out, true if VP writes pre-transformed position */ 55fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt boolean point_size; /* out, true if VP writes point size */ 56fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 57fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt uint32_t sampler_ps1xtypes; /* 2 bits per sampler */ 58fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt uint16_t sampler_mask; /* out, which samplers are being used */ 59fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt uint16_t sampler_mask_shadow; /* in, which samplers use depth compare */ 60fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt uint8_t rt_mask; /* out, which render targets are being written */ 61fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 62fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt unsigned const_i_base; /* in vec4 (16 byte) units */ 63fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt unsigned const_b_base; /* in vec4 (16 byte) units */ 64fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt unsigned const_used_size; 65fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 66fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt struct nine_lconstf lconstf; /* out, NOTE: members to be free'd by user */ 67fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}; 68fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 69fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstatic INLINE void 70fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtnine_info_mark_const_f_used(struct nine_shader_info *info, int idx) 71fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{ 72fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt unsigned size = (idx + 1) * 16; 73fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 74fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt if (info->const_used_size < size) 75fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt info->const_used_size = size; 76fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt} 77fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstatic INLINE void 78fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtnine_info_mark_const_i_used(struct nine_shader_info *info, int idx) 79fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{ 80fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt unsigned size = (info->const_i_base + (idx + 1)) * 16; 81fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 82fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt if (info->const_used_size < size) 83fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt info->const_used_size = size; 84fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt} 85fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstatic INLINE void 86fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtnine_info_mark_const_b_used(struct nine_shader_info *info, int idx) 87fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{ 88fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt unsigned size = (info->const_b_base + ((idx + 4) / 4)) * 16; 89fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 90fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt if (info->const_used_size < size) 91fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt info->const_used_size = size; 92fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt} 93fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 94fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim SindholtHRESULT 95fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtnine_translate_shader(struct NineDevice9 *device, struct nine_shader_info *); 96fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 97fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 98fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstruct nine_shader_variant 99fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{ 100fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt struct nine_shader_variant *next; 101fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt void *cso; 102fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt uint32_t key; 103fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt}; 104fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 105fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstatic INLINE void * 106fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtnine_shader_variant_get(struct nine_shader_variant *list, uint32_t key) 107fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{ 108fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt while (list->key != key && list->next) 109fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt list = list->next; 110fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt if (list->key == key) 111fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt return list->cso; 112fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt return NULL; 113fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt} 114fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 115fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstatic INLINE boolean 116fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtnine_shader_variant_add(struct nine_shader_variant *list, 117fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt uint32_t key, void *cso) 118fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{ 119fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt while (list->next) { 120fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt assert(list->key != key); 121fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt list = list->next; 122fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt } 123fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt list->next = MALLOC_STRUCT(nine_shader_variant); 124fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt if (!list->next) 125fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt return FALSE; 126fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt list->next->next = NULL; 127fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt list->next->key = key; 128fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt list->next->cso = cso; 129fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt return TRUE; 130fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt} 131fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 132fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtstatic INLINE void 133fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholtnine_shader_variants_free(struct nine_shader_variant *list) 134fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt{ 135fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt while (list->next) { 136fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt struct nine_shader_variant *ptr = list->next; 137fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt list->next = ptr->next; 138fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt FREE(ptr); 139fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt } 140fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt} 141fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt 142fdd96578ef2dfe9c4ad5aab5858036298d444a64Joakim Sindholt#endif /* _NINE_SHADER_H_ */ 143