ReactOS 0.4.15-dev-7924-g5949c20
preshader.c File Reference
#include "d3dx9_private.h"
#include <float.h>
#include <math.h>
#include <assert.h>
Include dependency graph for preshader.c:

Go to the source code of this file.

Classes

struct  op_info
 
struct  d3dx_pres_reg
 
struct  d3dx_pres_operand
 
struct  d3dx_pres_ins
 
struct  const_upload_info
 

Macros

#define PRES_OPCODE_MASK   0x7ff00000
 
#define PRES_OPCODE_SHIFT   20
 
#define PRES_SCALAR_FLAG   0x80000000
 
#define PRES_NCOMP_MASK   0x0000ffff
 
#define FOURCC_PRES   0x53455250
 
#define FOURCC_CLIT   0x54494c43
 
#define FOURCC_FXLC   0x434c5846
 
#define FOURCC_PRSI   0x49535250
 
#define PRES_SIGN   0x46580000
 
#define MAX_INPUTS_COUNT   8
 
#define PRES_BITMASK_BLOCK_SIZE   (sizeof(unsigned int) * 8)
 
#define INITIAL_CONST_SET_SIZE   16
 
#define ARGS_ARRAY_SIZE   8
 

Typedefs

typedef double(* pres_op_func) (double *args, int n)
 

Enumerations

enum  pres_ops {
  PRESHADER_OP_NOP , PRESHADER_OP_MOV , PRESHADER_OP_NEG , PRESHADER_OP_RCP ,
  PRESHADER_OP_FRC , PRESHADER_OP_EXP , PRESHADER_OP_LOG , PRESHADER_OP_RSQ ,
  PRESHADER_OP_SIN , PRESHADER_OP_COS , PRESHADER_OP_ASIN , PRESHADER_OP_ACOS ,
  PRESHADER_OP_ATAN , PRESHADER_OP_MIN , PRESHADER_OP_MAX , PRESHADER_OP_LT ,
  PRESHADER_OP_GE , PRESHADER_OP_ADD , PRESHADER_OP_MUL , PRESHADER_OP_ATAN2 ,
  PRESHADER_OP_DIV , PRESHADER_OP_CMP , PRESHADER_OP_DOT , PRESHADER_OP_DOTSWIZ6 ,
  PRESHADER_OP_DOTSWIZ8
}
 
enum  pres_value_type {
  PRES_VT_FLOAT , PRES_VT_DOUBLE , PRES_VT_INT , PRES_VT_BOOL ,
  PRES_VT_COUNT
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d3dx)
 
static double to_signed_nan (double v)
 
static double pres_mov (double *args, int n)
 
static double pres_add (double *args, int n)
 
static double pres_mul (double *args, int n)
 
static double pres_dot (double *args, int n)
 
static double pres_dotswiz6 (double *args, int n)
 
static double pres_dotswiz8 (double *args, int n)
 
static double pres_neg (double *args, int n)
 
static double pres_rcp (double *args, int n)
 
static double pres_lt (double *args, int n)
 
static double pres_ge (double *args, int n)
 
static double pres_frc (double *args, int n)
 
static double pres_min (double *args, int n)
 
static double pres_max (double *args, int n)
 
static double pres_cmp (double *args, int n)
 
static double pres_sin (double *args, int n)
 
static double pres_cos (double *args, int n)
 
static double pres_rsq (double *args, int n)
 
static double pres_exp (double *args, int n)
 
static double pres_log (double *args, int n)
 
static double pres_asin (double *args, int n)
 
static double pres_acos (double *args, int n)
 
static double pres_atan (double *args, int n)
 
static double pres_atan2 (double *args, int n)
 
static double pres_div (double *args, int n)
 
static enum pres_value_type table_type_from_param_type (D3DXPARAMETER_TYPE type)
 
static unsigned int get_reg_offset (unsigned int table, unsigned int offset)
 
static unsigned int get_offset_reg (unsigned int table, unsigned int reg_idx)
 
static unsigned int get_reg_components (unsigned int table)
 
static HRESULT regstore_alloc_table (struct d3dx_regstore *rs, unsigned int table)
 
static void regstore_free_tables (struct d3dx_regstore *rs)
 
static void regstore_set_values (struct d3dx_regstore *rs, unsigned int table, const void *data, unsigned int start_offset, unsigned int count)
 
static double regstore_get_double (struct d3dx_regstore *rs, unsigned int table, unsigned int offset)
 
static void regstore_set_double (struct d3dx_regstore *rs, unsigned int table, unsigned int offset, double v)
 
static void dump_bytecode (void *data, unsigned int size)
 
static unsigned intfind_bytecode_comment (unsigned int *ptr, unsigned int count, unsigned int fourcc, unsigned int *size)
 
static unsigned intparse_pres_reg (unsigned int *ptr, struct d3dx_pres_reg *reg)
 
static unsigned intparse_pres_arg (unsigned int *ptr, unsigned int count, struct d3dx_pres_operand *opr)
 
static unsigned intparse_pres_ins (unsigned int *ptr, unsigned int count, struct d3dx_pres_ins *ins)
 
static HRESULT get_ctab_constant_desc (ID3DXConstantTable *ctab, D3DXHANDLE hc, D3DXCONSTANT_DESC *desc, WORD *constantinfo_reserved)
 
static void get_const_upload_info (struct d3dx_const_param_eval_output *const_set, struct const_upload_info *info)
 
static HRESULT append_const_set (struct d3dx_const_tab *const_tab, struct d3dx_const_param_eval_output *set)
 
static void append_pres_const_sets_for_shader_input (struct d3dx_const_tab *const_tab, struct d3dx_preshader *pres)
 
static int __cdecl compare_const_set (const void *a, const void *b)
 
static HRESULT merge_const_set_entries (struct d3dx_const_tab *const_tab, struct d3dx_parameter *param, unsigned int index)
 
static HRESULT init_set_constants_param (struct d3dx_const_tab *const_tab, ID3DXConstantTable *ctab, D3DXHANDLE hc, struct d3dx_parameter *param)
 
static HRESULT get_constants_desc (unsigned int *byte_code, struct d3dx_const_tab *out, struct d3dx_effect *effect, const char **skip_constants, unsigned int skip_constants_count, struct d3dx_preshader *pres)
 
static void update_table_size (unsigned int *table_sizes, unsigned int table, unsigned int max_register)
 
static void update_table_sizes_consts (unsigned int *table_sizes, struct d3dx_const_tab *ctab)
 
static void dump_arg (struct d3dx_regstore *rs, const struct d3dx_pres_operand *arg, int component_count)
 
static void dump_registers (struct d3dx_const_tab *ctab)
 
static void dump_ins (struct d3dx_regstore *rs, const struct d3dx_pres_ins *ins)
 
static void dump_preshader (struct d3dx_preshader *pres)
 
static HRESULT parse_preshader (struct d3dx_preshader *pres, unsigned int *ptr, unsigned int count, struct d3dx_effect *effect)
 
HRESULT d3dx_create_param_eval (struct d3dx_effect *effect, void *byte_code, unsigned int byte_code_size, D3DXPARAMETER_TYPE type, struct d3dx_param_eval **peval_out, ULONG64 *version_counter, const char **skip_constants, unsigned int skip_constants_count)
 
static void d3dx_free_const_tab (struct d3dx_const_tab *ctab)
 
static void d3dx_free_preshader (struct d3dx_preshader *pres)
 
void d3dx_free_param_eval (struct d3dx_param_eval *peval)
 
static void pres_int_from_float (void *out, const void *in, unsigned int count)
 
static void pres_bool_from_value (void *out, const void *in, unsigned int count)
 
static void pres_float_from_int (void *out, const void *in, unsigned int count)
 
static void pres_float_from_bool (void *out, const void *in, unsigned int count)
 
static void pres_int_from_bool (void *out, const void *in, unsigned int count)
 
static void regstore_set_data (struct d3dx_regstore *rs, unsigned int table, unsigned int offset, const unsigned int *in, unsigned int count, enum pres_value_type param_type)
 
static HRESULT set_constants_device (ID3DXEffectStateManager *manager, struct IDirect3DDevice9 *device, D3DXPARAMETER_TYPE type, enum pres_reg_tables table, void *ptr, unsigned int start, unsigned int count)
 
static HRESULT set_constants (struct d3dx_regstore *rs, struct d3dx_const_tab *const_tab, ULONG64 new_update_version, ID3DXEffectStateManager *manager, struct IDirect3DDevice9 *device, D3DXPARAMETER_TYPE type, BOOL device_update_all, BOOL pres_dirty)
 
static double exec_get_reg_value (struct d3dx_regstore *rs, enum pres_reg_tables table, unsigned int offset)
 
static double exec_get_arg (struct d3dx_regstore *rs, const struct d3dx_pres_operand *opr, unsigned int comp)
 
static void exec_set_arg (struct d3dx_regstore *rs, const struct d3dx_pres_reg *reg, unsigned int comp, double res)
 
static HRESULT execute_preshader (struct d3dx_preshader *pres)
 
static BOOL is_const_tab_input_dirty (struct d3dx_const_tab *ctab, ULONG64 update_version)
 
BOOL is_param_eval_input_dirty (struct d3dx_param_eval *peval, ULONG64 update_version)
 
HRESULT d3dx_evaluate_parameter (struct d3dx_param_eval *peval, const struct d3dx_parameter *param, void *param_value)
 
HRESULT d3dx_param_eval_set_shader_constants (ID3DXEffectStateManager *manager, struct IDirect3DDevice9 *device, struct d3dx_param_eval *peval, BOOL update_all)
 

Variables

static const struct op_info pres_op_info []
 
struct {
   unsigned int   component_size
 
   enum pres_value_type   type
 
table_info []
 
static const chartable_symbol []
 
static enum pres_reg_tables pres_regset2table []
 
static enum pres_reg_tables shad_regset2table []
 

Macro Definition Documentation

◆ ARGS_ARRAY_SIZE

#define ARGS_ARRAY_SIZE   8

Definition at line 1658 of file preshader.c.

◆ FOURCC_CLIT

#define FOURCC_CLIT   0x54494c43

Definition at line 154 of file preshader.c.

◆ FOURCC_FXLC

#define FOURCC_FXLC   0x434c5846

Definition at line 155 of file preshader.c.

◆ FOURCC_PRES

#define FOURCC_PRES   0x53455250

Definition at line 153 of file preshader.c.

◆ FOURCC_PRSI

#define FOURCC_PRSI   0x49535250

Definition at line 156 of file preshader.c.

◆ INITIAL_CONST_SET_SIZE

#define INITIAL_CONST_SET_SIZE   16

Definition at line 593 of file preshader.c.

◆ MAX_INPUTS_COUNT

#define MAX_INPUTS_COUNT   8

Definition at line 257 of file preshader.c.

◆ PRES_BITMASK_BLOCK_SIZE

#define PRES_BITMASK_BLOCK_SIZE   (sizeof(unsigned int) * 8)

Definition at line 311 of file preshader.c.

◆ PRES_NCOMP_MASK

#define PRES_NCOMP_MASK   0x0000ffff

Definition at line 151 of file preshader.c.

◆ PRES_OPCODE_MASK

#define PRES_OPCODE_MASK   0x7ff00000

Definition at line 148 of file preshader.c.

◆ PRES_OPCODE_SHIFT

#define PRES_OPCODE_SHIFT   20

Definition at line 149 of file preshader.c.

◆ PRES_SCALAR_FLAG

#define PRES_SCALAR_FLAG   0x80000000

Definition at line 150 of file preshader.c.

◆ PRES_SIGN

#define PRES_SIGN   0x46580000

Definition at line 157 of file preshader.c.

Typedef Documentation

◆ pres_op_func

typedef double(* pres_op_func) (double *args, int n)

Definition at line 67 of file preshader.c.

Enumeration Type Documentation

◆ pres_ops

Enumerator
PRESHADER_OP_NOP 
PRESHADER_OP_MOV 
PRESHADER_OP_NEG 
PRESHADER_OP_RCP 
PRESHADER_OP_FRC 
PRESHADER_OP_EXP 
PRESHADER_OP_LOG 
PRESHADER_OP_RSQ 
PRESHADER_OP_SIN 
PRESHADER_OP_COS 
PRESHADER_OP_ASIN 
PRESHADER_OP_ACOS 
PRESHADER_OP_ATAN 
PRESHADER_OP_MIN 
PRESHADER_OP_MAX 
PRESHADER_OP_LT 
PRESHADER_OP_GE 
PRESHADER_OP_ADD 
PRESHADER_OP_MUL 
PRESHADER_OP_ATAN2 
PRESHADER_OP_DIV 
PRESHADER_OP_CMP 
PRESHADER_OP_DOT 
PRESHADER_OP_DOTSWIZ6 
PRESHADER_OP_DOTSWIZ8 

Definition at line 38 of file preshader.c.

39{
65};
@ PRESHADER_OP_ATAN
Definition: preshader.c:52
@ PRESHADER_OP_SIN
Definition: preshader.c:48
@ PRESHADER_OP_MUL
Definition: preshader.c:58
@ PRESHADER_OP_NOP
Definition: preshader.c:40
@ PRESHADER_OP_ASIN
Definition: preshader.c:50
@ PRESHADER_OP_DOT
Definition: preshader.c:62
@ PRESHADER_OP_ACOS
Definition: preshader.c:51
@ PRESHADER_OP_LOG
Definition: preshader.c:46
@ PRESHADER_OP_NEG
Definition: preshader.c:42
@ PRESHADER_OP_LT
Definition: preshader.c:55
@ PRESHADER_OP_MIN
Definition: preshader.c:53
@ PRESHADER_OP_COS
Definition: preshader.c:49
@ PRESHADER_OP_DIV
Definition: preshader.c:60
@ PRESHADER_OP_CMP
Definition: preshader.c:61
@ PRESHADER_OP_FRC
Definition: preshader.c:44
@ PRESHADER_OP_RSQ
Definition: preshader.c:47
@ PRESHADER_OP_ATAN2
Definition: preshader.c:59
@ PRESHADER_OP_RCP
Definition: preshader.c:43
@ PRESHADER_OP_MOV
Definition: preshader.c:41
@ PRESHADER_OP_MAX
Definition: preshader.c:54
@ PRESHADER_OP_DOTSWIZ8
Definition: preshader.c:64
@ PRESHADER_OP_GE
Definition: preshader.c:56
@ PRESHADER_OP_DOTSWIZ6
Definition: preshader.c:63
@ PRESHADER_OP_EXP
Definition: preshader.c:45
@ PRESHADER_OP_ADD
Definition: preshader.c:57

◆ pres_value_type

Enumerator
PRES_VT_FLOAT 
PRES_VT_DOUBLE 
PRES_VT_INT 
PRES_VT_BOOL 
PRES_VT_COUNT 

Definition at line 197 of file preshader.c.

198{
204};
@ PRES_VT_DOUBLE
Definition: preshader.c:200
@ PRES_VT_FLOAT
Definition: preshader.c:199
@ PRES_VT_BOOL
Definition: preshader.c:202
@ PRES_VT_COUNT
Definition: preshader.c:203
@ PRES_VT_INT
Definition: preshader.c:201

Function Documentation

◆ append_const_set()

static HRESULT append_const_set ( struct d3dx_const_tab const_tab,
struct d3dx_const_param_eval_output set 
)
static

Definition at line 595 of file preshader.c.

596{
597 if (const_tab->const_set_count >= const_tab->const_set_size)
598 {
599 unsigned int new_size;
600 struct d3dx_const_param_eval_output *new_alloc;
601
602 if (!const_tab->const_set_size)
603 {
604 new_size = INITIAL_CONST_SET_SIZE;
605 new_alloc = HeapAlloc(GetProcessHeap(), 0, sizeof(*const_tab->const_set) * new_size);
606 if (!new_alloc)
607 {
608 ERR("Out of memory.\n");
609 return E_OUTOFMEMORY;
610 }
611 }
612 else
613 {
614 new_size = const_tab->const_set_size * 2;
615 new_alloc = HeapReAlloc(GetProcessHeap(), 0, const_tab->const_set,
616 sizeof(*const_tab->const_set) * new_size);
617 if (!new_alloc)
618 {
619 ERR("Out of memory.\n");
620 return E_OUTOFMEMORY;
621 }
622 }
623 const_tab->const_set = new_alloc;
624 const_tab->const_set_size = new_size;
625 }
626 const_tab->const_set[const_tab->const_set_count++] = *set;
627 return D3D_OK;
628}
#define ERR(fmt,...)
Definition: debug.h:110
Definition: _set.h:50
#define D3D_OK
Definition: d3d.h:106
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapReAlloc
Definition: compat.h:734
#define INITIAL_CONST_SET_SIZE
Definition: preshader.c:593
struct d3dx_const_param_eval_output * const_set
unsigned int const_set_count
unsigned int const_set_size

Referenced by append_pres_const_sets_for_shader_input(), and init_set_constants_param().

◆ append_pres_const_sets_for_shader_input()

static void append_pres_const_sets_for_shader_input ( struct d3dx_const_tab const_tab,
struct d3dx_preshader pres 
)
static

Definition at line 630 of file preshader.c.

632{
633 unsigned int i;
634 struct d3dx_const_param_eval_output const_set = {NULL};
635
636 for (i = 0; i < pres->ins_count; ++i)
637 {
638 const struct d3dx_pres_ins *ins = &pres->ins[i];
639 const struct d3dx_pres_reg *reg = &ins->output.reg;
640
641 if (reg->table == PRES_REGTAB_TEMP)
642 continue;
643
644 const_set.register_index = get_reg_offset(reg->table, reg->offset);
645 const_set.register_count = 1;
646 const_set.table = reg->table;
648 const_set.element_count = 1;
649 append_const_set(const_tab, &const_set);
650 }
651}
@ PRES_REGTAB_TEMP
@ D3DXPC_FORCE_DWORD
Definition: d3dx9shader.h:68
#define NULL
Definition: types.h:112
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static int reg
Definition: i386-dis.c:1290
static HRESULT append_const_set(struct d3dx_const_tab *const_tab, struct d3dx_const_param_eval_output *set)
Definition: preshader.c:595
static unsigned int get_reg_offset(unsigned int table, unsigned int offset)
Definition: preshader.c:296
enum D3DXPARAMETER_CLASS constant_class
enum pres_reg_tables table
struct d3dx_pres_operand output
Definition: preshader.c:267
unsigned int ins_count
struct d3dx_pres_ins * ins

Referenced by get_constants_desc().

◆ compare_const_set()

static int __cdecl compare_const_set ( const void a,
const void b 
)
static

Definition at line 653 of file preshader.c.

654{
655 const struct d3dx_const_param_eval_output *r1 = a;
656 const struct d3dx_const_param_eval_output *r2 = b;
657
658 if (r1->table != r2->table)
659 return r1->table - r2->table;
660 return r1->register_index - r2->register_index;
661}
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
static DNS_RECORDW r1
Definition: record.c:37
static DNS_RECORDW r2
Definition: record.c:38

Referenced by get_constants_desc().

◆ d3dx_create_param_eval()

HRESULT d3dx_create_param_eval ( struct d3dx_effect effect,
void byte_code,
unsigned int  byte_code_size,
D3DXPARAMETER_TYPE  type,
struct d3dx_param_eval **  peval_out,
ULONG64 version_counter,
const char **  skip_constants,
unsigned int  skip_constants_count 
)

Definition at line 1233 of file preshader.c.

1236{
1237 struct d3dx_param_eval *peval;
1238 unsigned int *ptr, *shader_ptr = NULL;
1239 unsigned int i;
1240 BOOL shader;
1241 unsigned int count, pres_size;
1242 HRESULT ret;
1243
1244 TRACE("effect %p, byte_code %p, byte_code_size %u, type %u, peval_out %p.\n",
1245 effect, byte_code, byte_code_size, type, peval_out);
1246
1247 count = byte_code_size / sizeof(unsigned int);
1248 if (!byte_code || !count)
1249 {
1250 *peval_out = NULL;
1251 return D3D_OK;
1252 }
1253
1254 peval = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*peval));
1255 if (!peval)
1256 {
1258 goto err_out;
1259 }
1261
1262 peval->param_type = type;
1263 switch (type)
1264 {
1266 case D3DXPT_PIXELSHADER:
1267 shader = TRUE;
1268 break;
1269 default:
1270 shader = FALSE;
1271 break;
1272 }
1273 peval->shader_inputs.regset2table = shad_regset2table;
1274
1275 ptr = (unsigned int *)byte_code;
1276 if (shader)
1277 {
1278 if ((*ptr & 0xfffe0000) != 0xfffe0000)
1279 {
1280 FIXME("Invalid shader signature %#x.\n", *ptr);
1282 goto err_out;
1283 }
1284 TRACE("Shader version %#x.\n", *ptr & 0xffff);
1285 shader_ptr = ptr;
1286 ptr = find_bytecode_comment(ptr + 1, count - 1, FOURCC_PRES, &pres_size);
1287 if (!ptr)
1288 TRACE("No preshader found.\n");
1289 }
1290 else
1291 {
1292 pres_size = count;
1293 }
1294
1295 if (ptr && FAILED(ret = parse_preshader(&peval->pres, ptr, pres_size, effect)))
1296 {
1297 FIXME("Failed parsing preshader, byte code for analysis follows.\n");
1298 dump_bytecode(byte_code, byte_code_size);
1299 goto err_out;
1300 }
1301
1302 if (shader)
1303 {
1304 if (FAILED(ret = get_constants_desc(shader_ptr, &peval->shader_inputs, effect,
1305 skip_constants, skip_constants_count, &peval->pres)))
1306 {
1307 TRACE("Could not get shader constant table, hr %#x.\n", ret);
1308 goto err_out;
1309 }
1310 update_table_sizes_consts(peval->pres.regs.table_sizes, &peval->shader_inputs);
1311 }
1312
1314 {
1315 if (FAILED(ret = regstore_alloc_table(&peval->pres.regs, i)))
1316 goto err_out;
1317 }
1318
1319 if (TRACE_ON(d3dx))
1320 {
1321 dump_bytecode(byte_code, byte_code_size);
1322 dump_preshader(&peval->pres);
1323 if (shader)
1324 {
1325 TRACE("// Shader registers:\n");
1327 }
1328 }
1329 *peval_out = peval;
1330 TRACE("Created parameter evaluator %p.\n", *peval_out);
1331 return D3D_OK;
1332
1333err_out:
1334 WARN("Error creating parameter evaluator.\n");
1335 if (TRACE_ON(d3dx))
1336 dump_bytecode(byte_code, byte_code_size);
1337
1338 d3dx_free_param_eval(peval);
1339 *peval_out = NULL;
1340 return ret;
1341}
#define FIXME(fmt,...)
Definition: debug.h:111
#define WARN(fmt,...)
Definition: debug.h:112
#define D3DXERR_INVALIDDATA
Definition: compiler.c:30
@ PRES_REGTAB_COUNT
@ PRES_REGTAB_FIRST_SHADER
@ D3DXPT_VERTEXSHADER
Definition: d3dx9shader.h:89
@ D3DXPT_PIXELSHADER
Definition: d3dx9shader.h:88
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define TRACE_ON(x)
Definition: compat.h:75
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint shader
Definition: glext.h:6030
#define FAILED(hr)
Definition: intsafe.h:51
static PVOID ptr
Definition: dispmode.c:27
static void dump_preshader(struct d3dx_preshader *pres)
Definition: preshader.c:1089
#define FOURCC_PRES
Definition: preshader.c:153
static unsigned int * find_bytecode_comment(unsigned int *ptr, unsigned int count, unsigned int fourcc, unsigned int *size)
Definition: preshader.c:401
static HRESULT get_constants_desc(unsigned int *byte_code, struct d3dx_const_tab *out, struct d3dx_effect *effect, const char **skip_constants, unsigned int skip_constants_count, struct d3dx_preshader *pres)
Definition: preshader.c:862
static void dump_registers(struct d3dx_const_tab *ctab)
Definition: preshader.c:1063
static void update_table_sizes_consts(unsigned int *table_sizes, struct d3dx_const_tab *ctab)
Definition: preshader.c:1015
static enum pres_reg_tables shad_regset2table[]
Definition: preshader.c:235
enum pres_value_type type
Definition: preshader.c:209
void d3dx_free_param_eval(struct d3dx_param_eval *peval)
Definition: preshader.c:1358
static HRESULT regstore_alloc_table(struct d3dx_regstore *rs, unsigned int table)
Definition: preshader.c:313
static HRESULT parse_preshader(struct d3dx_preshader *pres, unsigned int *ptr, unsigned int count, struct d3dx_effect *effect)
Definition: preshader.c:1113
static void dump_bytecode(void *data, unsigned int size)
Definition: preshader.c:384
#define TRACE(s)
Definition: solgame.cpp:4
struct d3dx_const_tab shader_inputs
struct d3dx_preshader pres
ULONG64 * version_counter
D3DXPARAMETER_TYPE param_type
int ret

Referenced by d3dx_parse_array_selector(), and d3dx_parse_resource().

◆ d3dx_evaluate_parameter()

HRESULT d3dx_evaluate_parameter ( struct d3dx_param_eval peval,
const struct d3dx_parameter param,
void param_value 
)

Definition at line 1723 of file preshader.c.

1725{
1726 HRESULT hr;
1727 unsigned int i;
1728 unsigned int elements, elements_param, elements_table;
1729 float *oc;
1730
1731 TRACE("peval %p, param %p, param_value %p.\n", peval, param, param_value);
1732
1733 if (is_const_tab_input_dirty(&peval->pres.inputs, ULONG64_MAX))
1734 {
1735 set_constants(&peval->pres.regs, &peval->pres.inputs,
1737 NULL, NULL, peval->param_type, FALSE, FALSE);
1738
1739 if (FAILED(hr = execute_preshader(&peval->pres)))
1740 return hr;
1741 }
1742
1743 elements_table = get_offset_reg(PRES_REGTAB_OCONST, peval->pres.regs.table_sizes[PRES_REGTAB_OCONST]);
1744 elements_param = param->bytes / sizeof(unsigned int);
1745 elements = min(elements_table, elements_param);
1746 oc = (float *)peval->pres.regs.tables[PRES_REGTAB_OCONST];
1747 for (i = 0; i < elements; ++i)
1748 set_number((unsigned int *)param_value + i, param->type, oc + i, D3DXPT_FLOAT);
1749 return D3D_OK;
1750}
static ULONG64 next_update_version(ULONG64 *version_counter)
static void set_number(void *outdata, D3DXPARAMETER_TYPE outtype, const void *indata, D3DXPARAMETER_TYPE intype)
#define ULONG64_MAX
Definition: d3dx9_private.h:34
@ PRES_REGTAB_OCONST
@ D3DXPT_FLOAT
Definition: d3dx9shader.h:76
GLfloat param
Definition: glext.h:5796
#define for
Definition: utility.h:88
#define min(a, b)
Definition: monoChain.cc:55
static BOOL is_const_tab_input_dirty(struct d3dx_const_tab *ctab, ULONG64 update_version)
Definition: preshader.c:1702
static HRESULT execute_preshader(struct d3dx_preshader *pres)
Definition: preshader.c:1659
static HRESULT set_constants(struct d3dx_regstore *rs, struct d3dx_const_tab *const_tab, ULONG64 new_update_version, ID3DXEffectStateManager *manager, struct IDirect3DDevice9 *device, D3DXPARAMETER_TYPE type, BOOL device_update_all, BOOL pres_dirty)
Definition: preshader.c:1483
static unsigned int get_offset_reg(unsigned int table, unsigned int reg_idx)
Definition: preshader.c:301
HRESULT hr
Definition: shlfolder.c:183

Referenced by d3dx9_get_param_value_ptr().

◆ d3dx_free_const_tab()

static void d3dx_free_const_tab ( struct d3dx_const_tab ctab)
static

Definition at line 1343 of file preshader.c.

1344{
1345 HeapFree(GetProcessHeap(), 0, ctab->inputs);
1347 HeapFree(GetProcessHeap(), 0, ctab->const_set);
1348}
#define HeapFree(x, y, z)
Definition: compat.h:735
struct d3dx_parameter ** inputs_param
D3DXCONSTANT_DESC * inputs

Referenced by d3dx_free_param_eval(), and d3dx_free_preshader().

◆ d3dx_free_param_eval()

void d3dx_free_param_eval ( struct d3dx_param_eval peval)

Definition at line 1358 of file preshader.c.

1359{
1360 TRACE("peval %p.\n", peval);
1361
1362 if (!peval)
1363 return;
1364
1365 d3dx_free_preshader(&peval->pres);
1367 HeapFree(GetProcessHeap(), 0, peval);
1368}
static void d3dx_free_preshader(struct d3dx_preshader *pres)
Definition: preshader.c:1350
static void d3dx_free_const_tab(struct d3dx_const_tab *ctab)
Definition: preshader.c:1343

Referenced by d3dx_create_param_eval(), and free_parameter().

◆ d3dx_free_preshader()

static void d3dx_free_preshader ( struct d3dx_preshader pres)
static

Definition at line 1350 of file preshader.c.

1351{
1352 HeapFree(GetProcessHeap(), 0, pres->ins);
1353
1354 regstore_free_tables(&pres->regs);
1356}
static void regstore_free_tables(struct d3dx_regstore *rs)
Definition: preshader.c:327
struct d3dx_const_tab inputs
struct d3dx_regstore regs

Referenced by d3dx_free_param_eval().

◆ d3dx_param_eval_set_shader_constants()

HRESULT d3dx_param_eval_set_shader_constants ( ID3DXEffectStateManager *  manager,
struct IDirect3DDevice9 *  device,
struct d3dx_param_eval peval,
BOOL  update_all 
)

Definition at line 1752 of file preshader.c.

1754{
1755 HRESULT hr;
1756 struct d3dx_preshader *pres = &peval->pres;
1757 struct d3dx_regstore *rs = &pres->regs;
1758 ULONG64 new_update_version = next_update_version(peval->version_counter);
1759 BOOL pres_dirty = FALSE;
1760
1761 TRACE("device %p, peval %p, param_type %u.\n", device, peval, peval->param_type);
1762
1764 {
1765 set_constants(rs, &pres->inputs, new_update_version,
1766 NULL, NULL, peval->param_type, FALSE, FALSE);
1767 if (FAILED(hr = execute_preshader(pres)))
1768 return hr;
1769 pres_dirty = TRUE;
1770 }
1771
1772 return set_constants(rs, &peval->shader_inputs, new_update_version,
1773 manager, device, peval->param_type, update_all, pres_dirty);
1774}
unsigned __int64 ULONG64
Definition: imports.h:198
Definition: devices.h:37

Referenced by d3dx_set_shader_constants().

◆ dump_arg()

static void dump_arg ( struct d3dx_regstore rs,
const struct d3dx_pres_operand arg,
int  component_count 
)
static

Definition at line 1029 of file preshader.c.

1030{
1031 static const char *xyzw_str = "xyzw";
1032 unsigned int i, table;
1033
1034 table = arg->reg.table;
1035 if (table == PRES_REGTAB_IMMED && arg->index_reg.table == PRES_REGTAB_COUNT)
1036 {
1037 TRACE("(");
1038 for (i = 0; i < component_count; ++i)
1039 TRACE(i < component_count - 1 ? "%.16e, " : "%.16e",
1040 ((double *)rs->tables[PRES_REGTAB_IMMED])[arg->reg.offset + i]);
1041 TRACE(")");
1042 }
1043 else
1044 {
1045 if (arg->index_reg.table == PRES_REGTAB_COUNT)
1046 {
1047 TRACE("%s%u.", table_symbol[table], get_reg_offset(table, arg->reg.offset));
1048 }
1049 else
1050 {
1051 unsigned int index_reg;
1052
1053 index_reg = get_reg_offset(arg->index_reg.table, arg->index_reg.offset);
1054 TRACE("%s[%u + %s%u.%c].", table_symbol[table], get_reg_offset(table, arg->reg.offset),
1055 table_symbol[arg->index_reg.table], index_reg,
1056 xyzw_str[arg->index_reg.offset - get_offset_reg(arg->index_reg.table, index_reg)]);
1057 }
1058 for (i = 0; i < component_count; ++i)
1059 TRACE("%c", xyzw_str[(arg->reg.offset + i) % 4]);
1060 }
1061}
unsigned int component_count
@ PRES_REGTAB_IMMED
static const char * table_symbol[]
Definition: preshader.c:222
void * tables[PRES_REGTAB_COUNT]

Referenced by dump_ins().

◆ dump_bytecode()

static void dump_bytecode ( void data,
unsigned int  size 
)
static

Definition at line 384 of file preshader.c.

385{
386 unsigned int *bytecode = (unsigned int *)data;
387 unsigned int i, j, n;
388
389 size /= sizeof(*bytecode);
390 i = 0;
391 while (i < size)
392 {
393 n = min(size - i, 8);
394 for (j = 0; j < n; ++j)
395 TRACE("0x%08x,", bytecode[i + j]);
396 i += n;
397 TRACE("\n");
398 }
399}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250

Referenced by d3dx_create_param_eval().

◆ dump_ins()

static void dump_ins ( struct d3dx_regstore rs,
const struct d3dx_pres_ins ins 
)
static

Definition at line 1075 of file preshader.c.

1076{
1077 unsigned int i;
1078
1079 TRACE("%s ", pres_op_info[ins->op].mnem);
1080 dump_arg(rs, &ins->output, pres_op_info[ins->op].func_all_comps ? 1 : ins->component_count);
1081 for (i = 0; i < pres_op_info[ins->op].input_count; ++i)
1082 {
1083 TRACE(", ");
1084 dump_arg(rs, &ins->inputs[i], ins->scalar_op && !i ? 1 : ins->component_count);
1085 }
1086 TRACE("\n");
1087}
static const struct op_info pres_op_info[]
Definition: preshader.c:168
static void dump_arg(struct d3dx_regstore *rs, const struct d3dx_pres_operand *arg, int component_count)
Definition: preshader.c:1029
BOOL scalar_op
Definition: preshader.c:264
enum pres_ops op
Definition: preshader.c:261
struct d3dx_pres_operand inputs[MAX_INPUTS_COUNT]
Definition: preshader.c:266
unsigned int component_count
Definition: preshader.c:265

Referenced by dump_preshader().

◆ dump_preshader()

static void dump_preshader ( struct d3dx_preshader pres)
static

Definition at line 1089 of file preshader.c.

1090{
1091 unsigned int i, immediate_count = pres->regs.table_sizes[PRES_REGTAB_IMMED] * 4;
1092 const double *immediates = pres->regs.tables[PRES_REGTAB_IMMED];
1093
1094 if (immediate_count)
1095 TRACE("// Immediates:\n");
1096 for (i = 0; i < immediate_count; ++i)
1097 {
1098 if (!(i % 4))
1099 TRACE("// ");
1100 TRACE("%.8e", immediates[i]);
1101 if (i % 4 == 3)
1102 TRACE("\n");
1103 else
1104 TRACE(", ");
1105 }
1106 TRACE("// Preshader registers:\n");
1107 dump_registers(&pres->inputs);
1108 TRACE("preshader\n");
1109 for (i = 0; i < pres->ins_count; ++i)
1110 dump_ins(&pres->regs, &pres->ins[i]);
1111}
static void dump_ins(struct d3dx_regstore *rs, const struct d3dx_pres_ins *ins)
Definition: preshader.c:1075

Referenced by d3dx_create_param_eval().

◆ dump_registers()

static void dump_registers ( struct d3dx_const_tab ctab)
static

Definition at line 1063 of file preshader.c.

1064{
1065 unsigned int table, i;
1066
1067 for (i = 0; i < ctab->input_count; ++i)
1068 {
1069 table = ctab->regset2table[ctab->inputs[i].RegisterSet];
1070 TRACE("// %-12s %s%-4u %u\n", ctab->inputs_param[i] ? ctab->inputs_param[i]->name : "(nil)",
1072 }
1073}
D3DXREGISTER_SET RegisterSet
Definition: d3dx9shader.h:106
unsigned int input_count
enum pres_reg_tables * regset2table

Referenced by d3dx_create_param_eval(), and dump_preshader().

◆ exec_get_arg()

static double exec_get_arg ( struct d3dx_regstore rs,
const struct d3dx_pres_operand opr,
unsigned int  comp 
)
static

Definition at line 1610 of file preshader.c.

1611{
1612 unsigned int offset, base_index, reg_index, table;
1613
1614 table = opr->reg.table;
1615
1616 if (opr->index_reg.table == PRES_REGTAB_COUNT)
1617 base_index = 0;
1618 else
1619 base_index = lrint(exec_get_reg_value(rs, opr->index_reg.table, opr->index_reg.offset));
1620
1621 offset = get_offset_reg(table, base_index) + opr->reg.offset + comp;
1622 reg_index = get_reg_offset(table, offset);
1623
1624 if (reg_index >= rs->table_sizes[table])
1625 {
1626 unsigned int wrap_size;
1627
1628 if (table == PRES_REGTAB_CONST)
1629 {
1630 /* As it can be guessed from tests, offset into floating constant table is wrapped
1631 * to the nearest power of 2 and not to the actual table size. */
1632 for (wrap_size = 1; wrap_size < rs->table_sizes[table]; wrap_size <<= 1)
1633 ;
1634 }
1635 else
1636 {
1637 wrap_size = rs->table_sizes[table];
1638 }
1639 WARN("Wrapping register index %u, table %u, wrap_size %u, table size %u.\n",
1640 reg_index, table, wrap_size, rs->table_sizes[table]);
1641 reg_index %= wrap_size;
1642
1643 if (reg_index >= rs->table_sizes[table])
1644 return 0.0;
1645
1647 }
1648
1649 return exec_get_reg_value(rs, table, offset);
1650}
@ PRES_REGTAB_CONST
GLintptr offset
Definition: glext.h:5920
_Check_return_ __CRT_INLINE long lrint(_In_ double x)
Definition: math.h:292
static double exec_get_reg_value(struct d3dx_regstore *rs, enum pres_reg_tables table, unsigned int offset)
Definition: preshader.c:1605
static unsigned int get_reg_components(unsigned int table)
Definition: preshader.c:306
struct d3dx_pres_reg index_reg
Definition: preshader.c:254
struct d3dx_pres_reg reg
Definition: preshader.c:253
unsigned int table_sizes[PRES_REGTAB_COUNT]

Referenced by execute_preshader().

◆ exec_get_reg_value()

static double exec_get_reg_value ( struct d3dx_regstore rs,
enum pres_reg_tables  table,
unsigned int  offset 
)
static

Definition at line 1605 of file preshader.c.

1606{
1607 return regstore_get_double(rs, table, offset);
1608}
static double regstore_get_double(struct d3dx_regstore *rs, unsigned int table, unsigned int offset)
Definition: preshader.c:350

Referenced by exec_get_arg().

◆ exec_set_arg()

static void exec_set_arg ( struct d3dx_regstore rs,
const struct d3dx_pres_reg reg,
unsigned int  comp,
double  res 
)
static

Definition at line 1652 of file preshader.c.

1654{
1655 regstore_set_double(rs, reg->table, reg->offset + comp, res);
1656}
GLuint res
Definition: glext.h:9613
static void regstore_set_double(struct d3dx_regstore *rs, unsigned int table, unsigned int offset, double v)
Definition: preshader.c:367

Referenced by execute_preshader().

◆ execute_preshader()

static HRESULT execute_preshader ( struct d3dx_preshader pres)
static

Definition at line 1659 of file preshader.c.

1660{
1661 unsigned int i, j, k;
1662 double args[ARGS_ARRAY_SIZE];
1663 double res;
1664
1665 for (i = 0; i < pres->ins_count; ++i)
1666 {
1667 const struct d3dx_pres_ins *ins;
1668 const struct op_info *oi;
1669
1670 ins = &pres->ins[i];
1671 oi = &pres_op_info[ins->op];
1672 if (oi->func_all_comps)
1673 {
1675 {
1676 FIXME("Too many arguments (%u) for one instruction.\n", oi->input_count * ins->component_count);
1677 return E_FAIL;
1678 }
1679 for (k = 0; k < oi->input_count; ++k)
1680 for (j = 0; j < ins->component_count; ++j)
1681 args[k * ins->component_count + j] = exec_get_arg(&pres->regs, &ins->inputs[k],
1682 ins->scalar_op && !k ? 0 : j);
1683 res = oi->func(args, ins->component_count);
1684
1685 /* only 'dot' instruction currently falls here */
1686 exec_set_arg(&pres->regs, &ins->output.reg, 0, res);
1687 }
1688 else
1689 {
1690 for (j = 0; j < ins->component_count; ++j)
1691 {
1692 for (k = 0; k < oi->input_count; ++k)
1693 args[k] = exec_get_arg(&pres->regs, &ins->inputs[k], ins->scalar_op && !k ? 0 : j);
1694 res = oi->func(args, ins->component_count);
1695 exec_set_arg(&pres->regs, &ins->output.reg, j, res);
1696 }
1697 }
1698 }
1699 return D3D_OK;
1700}
#define E_FAIL
Definition: ddrawi.h:102
int k
Definition: mpi.c:3369
static double exec_get_arg(struct d3dx_regstore *rs, const struct d3dx_pres_operand *opr, unsigned int comp)
Definition: preshader.c:1610
static void exec_set_arg(struct d3dx_regstore *rs, const struct d3dx_pres_reg *reg, unsigned int comp, double res)
Definition: preshader.c:1652
#define ARGS_ARRAY_SIZE
Definition: preshader.c:1658
Definition: match.c:390
unsigned int input_count
Definition: preshader.c:163
BOOL func_all_comps
Definition: preshader.c:164
pres_op_func func
Definition: preshader.c:165

Referenced by d3dx_evaluate_parameter(), and d3dx_param_eval_set_shader_constants().

◆ find_bytecode_comment()

static unsigned int * find_bytecode_comment ( unsigned int ptr,
unsigned int  count,
unsigned int  fourcc,
unsigned int size 
)
static

Definition at line 401 of file preshader.c.

403{
404 /* Provide at least one value in comment section on non-NULL return. */
405 while (count > 2 && (*ptr & 0xffff) == 0xfffe)
406 {
407 unsigned int section_size;
408
409 section_size = (*ptr >> 16);
410 if (!section_size || section_size + 1 > count)
411 break;
412 if (*(ptr + 1) == fourcc)
413 {
414 *size = section_size;
415 return ptr + 2;
416 }
417 count -= section_size + 1;
418 ptr += section_size + 1;
419 }
420 return NULL;
421}

Referenced by d3dx_create_param_eval(), and parse_preshader().

◆ get_const_upload_info()

static void get_const_upload_info ( struct d3dx_const_param_eval_output const_set,
struct const_upload_info info 
)
static

Definition at line 557 of file preshader.c.

559{
560 struct d3dx_parameter *param = const_set->param;
561 unsigned int table = const_set->table;
562
563 info->transpose = (const_set->constant_class == D3DXPC_MATRIX_COLUMNS && param->class == D3DXPC_MATRIX_ROWS)
564 || (param->class == D3DXPC_MATRIX_COLUMNS && const_set->constant_class == D3DXPC_MATRIX_ROWS);
565 if (const_set->constant_class == D3DXPC_MATRIX_COLUMNS)
566 {
567 info->major = param->columns;
568 info->minor = param->rows;
569 }
570 else
571 {
572 info->major = param->rows;
573 info->minor = param->columns;
574 }
575
576 if (get_reg_components(table) == 1)
577 {
578 unsigned int const_length = get_offset_reg(table, const_set->register_count);
579
580 info->major_stride = info->minor;
581 info->major_count = const_length / info->major_stride;
582 info->minor_remainder = const_length % info->major_stride;
583 }
584 else
585 {
586 info->major_stride = get_reg_components(table);
587 info->major_count = const_set->register_count;
588 info->minor_remainder = 0;
589 }
590 info->count = info->major_count * info->minor + info->minor_remainder;
591}
@ D3DXPC_MATRIX_COLUMNS
Definition: d3dx9shader.h:65
@ D3DXPC_MATRIX_ROWS
Definition: d3dx9shader.h:64
struct d3dx_parameter * param
unsigned int count
Definition: notification.c:64

Referenced by init_set_constants_param(), and set_constants().

◆ get_constants_desc()

static HRESULT get_constants_desc ( unsigned int byte_code,
struct d3dx_const_tab out,
struct d3dx_effect effect,
const char **  skip_constants,
unsigned int  skip_constants_count,
struct d3dx_preshader pres 
)
static

Definition at line 862 of file preshader.c.

865{
866 ID3DXConstantTable *ctab;
867 D3DXCONSTANT_DESC *cdesc;
868 struct d3dx_parameter **inputs_param;
870 HRESULT hr;
871 D3DXHANDLE hc;
872 unsigned int i, j;
873
874 hr = D3DXGetShaderConstantTable(byte_code, &ctab);
875 if (FAILED(hr) || !ctab)
876 {
877 TRACE("Could not get CTAB data, hr %#x.\n", hr);
878 /* returning OK, shaders and preshaders without CTAB are valid */
879 return D3D_OK;
880 }
882 {
883 FIXME("Could not get CTAB desc, hr %#x.\n", hr);
884 goto cleanup;
885 }
886
887 out->inputs = cdesc = HeapAlloc(GetProcessHeap(), 0, sizeof(*cdesc) * desc.Constants);
888 out->inputs_param = inputs_param = HeapAlloc(GetProcessHeap(), 0, sizeof(*inputs_param) * desc.Constants);
889 if (!cdesc || !inputs_param)
890 {
892 goto cleanup;
893 }
894
895 for (i = 0; i < desc.Constants; ++i)
896 {
897 unsigned int index = out->input_count;
898 WORD constantinfo_reserved;
899
901 if (!hc)
902 {
903 FIXME("Null constant handle.\n");
904 goto cleanup;
905 }
906 if (FAILED(hr = get_ctab_constant_desc(ctab, hc, &cdesc[index], &constantinfo_reserved)))
907 goto cleanup;
908 inputs_param[index] = get_parameter_by_name(effect, NULL, cdesc[index].Name);
909 if (!inputs_param[index])
910 {
911 WARN("Could not find parameter %s in effect.\n", cdesc[index].Name);
912 continue;
913 }
914 if (cdesc[index].Class == D3DXPC_OBJECT)
915 {
916 TRACE("Object %s, parameter %p.\n", cdesc[index].Name, inputs_param[index]);
917 if (cdesc[index].RegisterSet != D3DXRS_SAMPLER || inputs_param[index]->class != D3DXPC_OBJECT
918 || !is_param_type_sampler(inputs_param[index]->type))
919 {
920 WARN("Unexpected object type, constant %s.\n", debugstr_a(cdesc[index].Name));
922 goto cleanup;
923 }
924 if (max(inputs_param[index]->element_count, 1) < cdesc[index].RegisterCount)
925 {
926 WARN("Register count exceeds parameter size, constant %s.\n", debugstr_a(cdesc[index].Name));
928 goto cleanup;
929 }
930 }
931 if (!is_top_level_parameter(inputs_param[index]))
932 {
933 WARN("Expected top level parameter '%s'.\n", debugstr_a(cdesc[index].Name));
934 hr = E_FAIL;
935 goto cleanup;
936 }
937
938 for (j = 0; j < skip_constants_count; ++j)
939 {
940 if (!strcmp(cdesc[index].Name, skip_constants[j]))
941 {
942 if (!constantinfo_reserved)
943 {
944 WARN("skip_constants parameter %s is not register bound.\n",
945 cdesc[index].Name);
947 goto cleanup;
948 }
949 TRACE("Skipping constant %s.\n", cdesc[index].Name);
950 break;
951 }
952 }
953 if (j < skip_constants_count)
954 continue;
955 ++out->input_count;
956 if (inputs_param[index]->class == D3DXPC_OBJECT)
957 continue;
958 if (FAILED(hr = init_set_constants_param(out, ctab, hc, inputs_param[index])))
959 goto cleanup;
960 }
961 if (pres)
963 if (out->const_set_count)
964 {
965 struct d3dx_const_param_eval_output *new_alloc;
966
967 qsort(out->const_set, out->const_set_count, sizeof(*out->const_set), compare_const_set);
968
969 i = 0;
970 while (i < out->const_set_count - 1)
971 {
972 if (out->const_set[i].constant_class == D3DXPC_FORCE_DWORD
973 && out->const_set[i + 1].constant_class == D3DXPC_FORCE_DWORD
974 && out->const_set[i].table == out->const_set[i + 1].table
975 && out->const_set[i].register_index + out->const_set[i].register_count
976 >= out->const_set[i + 1].register_index)
977 {
978 assert(out->const_set[i].register_index + out->const_set[i].register_count
979 <= out->const_set[i + 1].register_index + 1);
980 out->const_set[i].register_count = out->const_set[i + 1].register_index + 1
981 - out->const_set[i].register_index;
982 memmove(&out->const_set[i + 1], &out->const_set[i + 2], sizeof(out->const_set[i])
983 * (out->const_set_count - i - 2));
984 --out->const_set_count;
985 }
986 else
987 {
988 ++i;
989 }
990 }
991
992 new_alloc = HeapReAlloc(GetProcessHeap(), 0, out->const_set,
993 sizeof(*out->const_set) * out->const_set_count);
994 if (new_alloc)
995 {
996 out->const_set = new_alloc;
997 out->const_set_size = out->const_set_count;
998 }
999 else
1000 {
1001 WARN("Out of memory.\n");
1002 }
1003 }
1004cleanup:
1006 return hr;
1007}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define index(s, c)
Definition: various.h:29
#define D3DERR_INVALIDCALL
static BOOL is_param_type_sampler(D3DXPARAMETER_TYPE type)
struct d3dx_parameter * get_parameter_by_name(struct d3dx_effect *effect, struct d3dx_parameter *parameter, const char *name) DECLSPEC_HIDDEN
Definition: effect.c:1026
static BOOL is_top_level_parameter(struct d3dx_parameter *param)
@ D3DXPC_OBJECT
Definition: d3dx9shader.h:66
#define ID3DXConstantTable_GetDesc(p, a)
Definition: d3dx9shader.h:182
@ D3DXRS_SAMPLER
Definition: d3dx9shader.h:56
#define ID3DXConstantTable_Release(p)
Definition: d3dx9shader.h:177
const char * D3DXHANDLE
Definition: d3dx9shader.h:48
#define ID3DXConstantTable_GetConstant(p, a, b)
Definition: d3dx9shader.h:185
HRESULT WINAPI D3DXGetShaderConstantTable(const DWORD *byte_code, ID3DXConstantTable **constant_table)
Definition: shader.c:2111
static void cleanup(void)
Definition: main.c:1335
#define assert(x)
Definition: debug.h:53
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint index
Definition: glext.h:6031
#define debugstr_a
Definition: kernel32.h:31
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static const WCHAR desc[]
Definition: protectdata.c:36
static HRESULT get_ctab_constant_desc(ID3DXConstantTable *ctab, D3DXHANDLE hc, D3DXCONSTANT_DESC *desc, WORD *constantinfo_reserved)
Definition: preshader.c:539
static void append_pres_const_sets_for_shader_input(struct d3dx_const_tab *const_tab, struct d3dx_preshader *pres)
Definition: preshader.c:630
static HRESULT init_set_constants_param(struct d3dx_const_tab *const_tab, ID3DXConstantTable *ctab, D3DXHANDLE hc, struct d3dx_parameter *param)
Definition: preshader.c:740
static int __cdecl compare_const_set(const void *a, const void *b)
Definition: preshader.c:653
static FILE * out
Definition: regtests2xml.c:44
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))
#define max(a, b)
Definition: svc.c:63

Referenced by d3dx_create_param_eval(), and parse_preshader().

◆ get_ctab_constant_desc()

static HRESULT get_ctab_constant_desc ( ID3DXConstantTable *  ctab,
D3DXHANDLE  hc,
D3DXCONSTANT_DESC desc,
WORD constantinfo_reserved 
)
static

Definition at line 539 of file preshader.c.

541{
542 const struct ctab_constant *constant = d3dx_shader_get_ctab_constant(ctab, hc);
543
544 if (!constant)
545 {
546 FIXME("Could not get constant desc.\n");
549 return D3DERR_INVALIDCALL;
550 }
551 *desc = constant->desc;
553 *constantinfo_reserved = constant->constantinfo_reserved;
554 return D3D_OK;
555}
const struct ctab_constant * d3dx_shader_get_ctab_constant(ID3DXConstantTable *iface, D3DXHANDLE constant) DECLSPEC_HIDDEN
Definition: shader.c:984
WORD constantinfo_reserved

Referenced by get_constants_desc(), and init_set_constants_param().

◆ get_offset_reg()

static unsigned int get_offset_reg ( unsigned int  table,
unsigned int  reg_idx 
)
static

◆ get_reg_components()

static unsigned int get_reg_components ( unsigned int  table)
static

Definition at line 306 of file preshader.c.

307{
308 return get_offset_reg(table, 1);
309}

Referenced by exec_get_arg(), get_const_upload_info(), parse_preshader(), and set_constants().

◆ get_reg_offset()

static unsigned int get_reg_offset ( unsigned int  table,
unsigned int  offset 
)
static

◆ init_set_constants_param()

static HRESULT init_set_constants_param ( struct d3dx_const_tab const_tab,
ID3DXConstantTable *  ctab,
D3DXHANDLE  hc,
struct d3dx_parameter param 
)
static

Definition at line 740 of file preshader.c.

742{
744 unsigned int const_count, param_count, i;
745 BOOL get_element;
746 struct d3dx_const_param_eval_output const_set;
747 struct const_upload_info info;
748 enum pres_value_type table_type;
749 HRESULT hr;
750
751 if (FAILED(get_ctab_constant_desc(ctab, hc, &desc, NULL)))
752 return D3DERR_INVALIDCALL;
753
754 if (param->element_count)
755 {
756 param_count = param->element_count;
757 const_count = desc.Elements;
758 get_element = TRUE;
759 }
760 else
761 {
762 if (desc.Elements > 1)
763 {
764 FIXME("Unexpected number of constant elements %u.\n", desc.Elements);
765 return D3DERR_INVALIDCALL;
766 }
767 param_count = param->member_count;
768 const_count = desc.StructMembers;
769 get_element = FALSE;
770 }
771 if (const_count != param_count)
772 {
773 FIXME("Number of elements or struct members differs between parameter (%u) and constant (%u).\n",
774 param_count, const_count);
775 return D3DERR_INVALIDCALL;
776 }
777 if (const_count)
778 {
780 D3DXHANDLE hc_element;
781 unsigned int index = const_tab->const_set_count;
782
783 for (i = 0; i < const_count; ++i)
784 {
785 if (get_element)
786 hc_element = ID3DXConstantTable_GetConstantElement(ctab, hc, i);
787 else
788 hc_element = ID3DXConstantTable_GetConstant(ctab, hc, i);
789 if (!hc_element)
790 {
791 FIXME("Could not get constant.\n");
793 }
794 else
795 {
796 hr = init_set_constants_param(const_tab, ctab, hc_element, &param->members[i]);
797 }
798 if (FAILED(hr))
799 ret = hr;
800 }
801 if (FAILED(ret))
802 return ret;
803 return merge_const_set_entries(const_tab, param, index);
804 }
805
806 TRACE("Constant %s, rows %u, columns %u, class %u, bytes %u.\n",
807 debugstr_a(desc.Name), desc.Rows, desc.Columns, desc.Class, desc.Bytes);
808 TRACE("Parameter %s, rows %u, columns %u, class %u, flags %#x, bytes %u.\n",
809 debugstr_a(param->name), param->rows, param->columns, param->class,
810 param->flags, param->bytes);
811
812 const_set.element_count = 1;
813 const_set.param = param;
814 const_set.constant_class = desc.Class;
815 if (desc.RegisterSet >= ARRAY_SIZE(shad_regset2table))
816 {
817 FIXME("Unknown register set %u.\n", desc.RegisterSet);
818 return D3DERR_INVALIDCALL;
819 }
820 const_set.register_index = desc.RegisterIndex;
821 const_set.table = const_tab->regset2table[desc.RegisterSet];
822 if (const_set.table >= PRES_REGTAB_COUNT)
823 {
824 ERR("Unexpected register set %u.\n", desc.RegisterSet);
825 return D3DERR_INVALIDCALL;
826 }
827 assert(table_info[const_set.table].component_size == sizeof(unsigned int));
828 assert(param->bytes / (param->rows * param->columns) == sizeof(unsigned int));
829 const_set.register_count = desc.RegisterCount;
830 table_type = table_info[const_set.table].type;
831 get_const_upload_info(&const_set, &info);
832 if (!info.count)
833 {
834 TRACE("%s has zero count, skipping.\n", debugstr_a(param->name));
835 return D3D_OK;
836 }
837
839 return D3DERR_INVALIDCALL;
840
841 const_set.direct_copy = table_type_from_param_type(param->type) == table_type
842 && !info.transpose && info.minor == info.major_stride
843 && info.count == get_offset_reg(const_set.table, const_set.register_count)
844 && info.count * sizeof(unsigned int) <= param->bytes;
845 if (info.minor_remainder && !const_set.direct_copy && !info.transpose)
846 FIXME("Incomplete last row for not transposed matrix which cannot be directly copied, parameter %s.\n",
847 debugstr_a(param->name));
848
849 if (info.major_count > info.major
850 || (info.major_count == info.major && info.minor_remainder))
851 {
852 WARN("Constant dimensions exceed parameter size.\n");
853 return D3DERR_INVALIDCALL;
854 }
855
856 if (FAILED(hr = append_const_set(const_tab, &const_set)))
857 return hr;
858
859 return D3D_OK;
860}
#define ARRAY_SIZE(A)
Definition: main.h:33
#define ID3DXConstantTable_GetConstantElement(p, a, b)
Definition: d3dx9shader.h:187
if(dx< 0)
Definition: linetemp.h:194
static enum pres_value_type table_type_from_param_type(D3DXPARAMETER_TYPE type)
Definition: preshader.c:280
static HRESULT merge_const_set_entries(struct d3dx_const_tab *const_tab, struct d3dx_parameter *param, unsigned int index)
Definition: preshader.c:663
static const struct @250 table_info[]
static void get_const_upload_info(struct d3dx_const_param_eval_output *const_set, struct const_upload_info *info)
Definition: preshader.c:557
pres_value_type
Definition: preshader.c:198

Referenced by get_constants_desc(), and init_set_constants_param().

◆ is_const_tab_input_dirty()

static BOOL is_const_tab_input_dirty ( struct d3dx_const_tab ctab,
ULONG64  update_version 
)
static

Definition at line 1702 of file preshader.c.

1703{
1704 unsigned int i;
1705
1706 if (update_version == ULONG64_MAX)
1707 update_version = ctab->update_version;
1708 for (i = 0; i < ctab->input_count; ++i)
1709 {
1711 update_version))
1712 return TRUE;
1713 }
1714 return FALSE;
1715}
static struct d3dx_top_level_parameter * top_level_parameter_from_parameter(struct d3dx_parameter *param)
static BOOL is_top_level_param_dirty(struct d3dx_top_level_parameter *param, ULONG64 update_version)
ULONG64 update_version

Referenced by d3dx_evaluate_parameter(), d3dx_param_eval_set_shader_constants(), and is_param_eval_input_dirty().

◆ is_param_eval_input_dirty()

BOOL is_param_eval_input_dirty ( struct d3dx_param_eval peval,
ULONG64  update_version 
)

Definition at line 1717 of file preshader.c.

1718{
1719 return is_const_tab_input_dirty(&peval->pres.inputs, update_version)
1720 || is_const_tab_input_dirty(&peval->shader_inputs, update_version);
1721}

Referenced by d3dx9_get_param_value_ptr().

◆ merge_const_set_entries()

static HRESULT merge_const_set_entries ( struct d3dx_const_tab const_tab,
struct d3dx_parameter param,
unsigned int  index 
)
static

Definition at line 663 of file preshader.c.

665{
666 unsigned int i, start_index = index;
667 DWORD *current_data;
668 enum pres_reg_tables current_table;
669 unsigned int current_start_offset, element_count;
670 struct d3dx_const_param_eval_output *first_const;
671
672 if (!const_tab->const_set_count)
673 return D3D_OK;
674
675 while (index < const_tab->const_set_count - 1)
676 {
677 first_const = &const_tab->const_set[index];
678 current_data = first_const->param->data;
679 current_table = first_const->table;
680 current_start_offset = get_offset_reg(current_table, first_const->register_index);
681 element_count = 0;
682 for (i = index; i < const_tab->const_set_count; ++i)
683 {
684 struct d3dx_const_param_eval_output *const_set = &const_tab->const_set[i];
685 unsigned int count = get_offset_reg(const_set->table,
686 const_set->register_count * const_set->element_count);
687 unsigned int start_offset = get_offset_reg(const_set->table, const_set->register_index);
688
689 if (!(const_set->table == current_table && current_start_offset == start_offset
690 && const_set->direct_copy == first_const->direct_copy
691 && current_data == const_set->param->data
692 && (const_set->direct_copy || (first_const->param->type == const_set->param->type
693 && first_const->param->class == const_set->param->class
694 && first_const->param->columns == const_set->param->columns
695 && first_const->param->rows == const_set->param->rows
696 && first_const->register_count == const_set->register_count
697 && (i == const_tab->const_set_count - 1
698 || first_const->param->element_count == const_set->param->element_count)))))
699 break;
700
701 current_start_offset += count;
702 current_data += const_set->direct_copy ? count : const_set->param->rows
703 * const_set->param->columns * const_set->element_count;
704 element_count += const_set->element_count;
705 }
706
707 if (i > index + 1)
708 {
709 TRACE("Merging %u child parameters for %s, not merging %u, direct_copy %#x.\n", i - index,
710 debugstr_a(param->name), const_tab->const_set_count - i, first_const->direct_copy);
711
712 first_const->element_count = element_count;
713 if (first_const->direct_copy)
714 {
715 first_const->element_count = 1;
716 if (index == start_index
717 && !(param->type == D3DXPT_VOID && param->class == D3DXPC_STRUCT))
718 {
720 return D3DERR_INVALIDCALL;
721 first_const->param = param;
722 }
723 first_const->register_count = get_reg_offset(current_table, current_start_offset)
724 - first_const->register_index;
725 }
726 memmove(&const_tab->const_set[index + 1], &const_tab->const_set[i],
727 sizeof(*const_tab->const_set) * (const_tab->const_set_count - i));
728 const_tab->const_set_count -= i - index - 1;
729 }
730 else
731 {
732 TRACE("Not merging %u child parameters for %s, direct_copy %#x.\n",
733 const_tab->const_set_count - i, debugstr_a(param->name), first_const->direct_copy);
734 }
735 index = i;
736 }
737 return D3D_OK;
738}
pres_reg_tables
@ D3DXPC_STRUCT
Definition: d3dx9shader.h:67
@ D3DXPT_VOID
Definition: d3dx9shader.h:73
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by init_set_constants_param().

◆ parse_pres_arg()

static unsigned int * parse_pres_arg ( unsigned int ptr,
unsigned int  count,
struct d3dx_pres_operand opr 
)
static

Definition at line 442 of file preshader.c.

443{
444 if (count < 3 || (*ptr && count < 5))
445 {
446 WARN("Byte code buffer ends unexpectedly, count %u.\n", count);
447 return NULL;
448 }
449
450 if (*ptr)
451 {
452 if (*ptr != 1)
453 {
454 FIXME("Unknown relative addressing flag, word %#x.\n", *ptr);
455 return NULL;
456 }
457 ptr = parse_pres_reg(ptr + 1, &opr->index_reg);
458 if (!ptr)
459 return NULL;
460 }
461 else
462 {
463 opr->index_reg.table = PRES_REGTAB_COUNT;
464 ++ptr;
465 }
466
467 ptr = parse_pres_reg(ptr, &opr->reg);
468
469 if (opr->reg.table == PRES_REGTAB_OBCONST)
470 opr->reg.offset /= 4;
471 return ptr;
472}
static unsigned int * parse_pres_reg(unsigned int *ptr, struct d3dx_pres_reg *reg)
Definition: preshader.c:423

Referenced by parse_pres_ins().

◆ parse_pres_ins()

static unsigned int * parse_pres_ins ( unsigned int ptr,
unsigned int  count,
struct d3dx_pres_ins ins 
)
static

Definition at line 474 of file preshader.c.

475{
476 unsigned int ins_code, ins_raw;
477 unsigned int input_count;
478 unsigned int i;
479
480 if (count < 2)
481 {
482 WARN("Byte code buffer ends unexpectedly.\n");
483 return NULL;
484 }
485
486 ins_raw = *ptr++;
487 ins_code = (ins_raw & PRES_OPCODE_MASK) >> PRES_OPCODE_SHIFT;
488 ins->component_count = ins_raw & PRES_NCOMP_MASK;
489 ins->scalar_op = !!(ins_raw & PRES_SCALAR_FLAG);
490
491 if (ins->component_count < 1 || ins->component_count > 4)
492 {
493 FIXME("Unsupported number of components %u.\n", ins->component_count);
494 return NULL;
495 }
496 input_count = *ptr++;
497 count -= 2;
498 for (i = 0; i < ARRAY_SIZE(pres_op_info); ++i)
499 if (ins_code == pres_op_info[i].opcode && input_count == pres_op_info[i].input_count)
500 break;
501 if (i == ARRAY_SIZE(pres_op_info))
502 {
503 FIXME("Unknown opcode %#x, input_count %u, raw %#x.\n", ins_code, input_count, ins_raw);
504 return NULL;
505 }
506 ins->op = i;
507 if (input_count > ARRAY_SIZE(ins->inputs))
508 {
509 FIXME("Actual input args count %u exceeds inputs array size, instruction %s.\n", input_count,
510 pres_op_info[i].mnem);
511 return NULL;
512 }
513 for (i = 0; i < input_count; ++i)
514 {
515 unsigned int *p;
516
517 p = parse_pres_arg(ptr, count, &ins->inputs[i]);
518 if (!p)
519 return NULL;
520 count -= p - ptr;
521 ptr = p;
522 }
523 ptr = parse_pres_arg(ptr, count, &ins->output);
524 if (ins->output.index_reg.table != PRES_REGTAB_COUNT)
525 {
526 FIXME("Relative addressing in output register not supported.\n");
527 return NULL;
528 }
529 if (get_reg_offset(ins->output.reg.table, ins->output.reg.offset
530 + (pres_op_info[ins->op].func_all_comps ? 0 : ins->component_count - 1))
531 != get_reg_offset(ins->output.reg.table, ins->output.reg.offset))
532 {
533 FIXME("Instructions outputting multiple registers are not supported.\n");
534 return NULL;
535 }
536 return ptr;
537}
GLfloat GLfloat p
Definition: glext.h:8902
#define PRES_OPCODE_MASK
Definition: preshader.c:148
#define PRES_OPCODE_SHIFT
Definition: preshader.c:149
static unsigned int * parse_pres_arg(unsigned int *ptr, unsigned int count, struct d3dx_pres_operand *opr)
Definition: preshader.c:442
#define PRES_NCOMP_MASK
Definition: preshader.c:151
#define PRES_SCALAR_FLAG
Definition: preshader.c:150

Referenced by parse_preshader().

◆ parse_pres_reg()

static unsigned int * parse_pres_reg ( unsigned int ptr,
struct d3dx_pres_reg reg 
)
static

Definition at line 423 of file preshader.c.

424{
425 static const enum pres_reg_tables reg_table[8] =
426 {
429 };
430
431 if (*ptr >= ARRAY_SIZE(reg_table) || reg_table[*ptr] == PRES_REGTAB_COUNT)
432 {
433 FIXME("Unsupported register table %#x.\n", *ptr);
434 return NULL;
435 }
436
437 reg->table = reg_table[*ptr++];
438 reg->offset = *ptr++;
439 return ptr;
440}
@ PRES_REGTAB_OICONST

Referenced by parse_pres_arg().

◆ parse_preshader()

static HRESULT parse_preshader ( struct d3dx_preshader pres,
unsigned int ptr,
unsigned int  count,
struct d3dx_effect effect 
)
static

Definition at line 1113 of file preshader.c.

1114{
1115 unsigned int *p;
1116 unsigned int i, j, const_count;
1117 double *dconst;
1118 HRESULT hr;
1119 unsigned int saved_word;
1120 unsigned int section_size;
1121
1122 TRACE("Preshader version %#x.\n", *ptr & 0xffff);
1123
1124 if (!count)
1125 {
1126 WARN("Unexpected end of byte code buffer.\n");
1127 return D3DXERR_INVALIDDATA;
1128 }
1129
1130 p = find_bytecode_comment(ptr + 1, count - 1, FOURCC_CLIT, &section_size);
1131 if (p)
1132 {
1133 const_count = *p++;
1134 if (const_count > (section_size - 1) / (sizeof(double) / sizeof(unsigned int)))
1135 {
1136 WARN("Byte code buffer ends unexpectedly.\n");
1137 return D3DXERR_INVALIDDATA;
1138 }
1139 dconst = (double *)p;
1140 }
1141 else
1142 {
1143 const_count = 0;
1144 dconst = NULL;
1145 }
1146 TRACE("%u double constants.\n", const_count);
1147
1148 p = find_bytecode_comment(ptr + 1, count - 1, FOURCC_FXLC, &section_size);
1149 if (!p)
1150 {
1151 WARN("Could not find preshader code.\n");
1152 return D3D_OK;
1153 }
1154 pres->ins_count = *p++;
1155 --section_size;
1156 if (pres->ins_count > UINT_MAX / sizeof(*pres->ins))
1157 {
1158 WARN("Invalid instruction count %u.\n", pres->ins_count);
1159 return D3DXERR_INVALIDDATA;
1160 }
1161 TRACE("%u instructions.\n", pres->ins_count);
1162 pres->ins = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pres->ins) * pres->ins_count);
1163 if (!pres->ins)
1164 return E_OUTOFMEMORY;
1165 for (i = 0; i < pres->ins_count; ++i)
1166 {
1167 unsigned int *ptr_next;
1168
1169 ptr_next = parse_pres_ins(p, section_size, &pres->ins[i]);
1170 if (!ptr_next)
1171 return D3DXERR_INVALIDDATA;
1172 section_size -= ptr_next - p;
1173 p = ptr_next;
1174 }
1175
1176 pres->inputs.regset2table = pres_regset2table;
1177
1178 saved_word = *ptr;
1179 *ptr = 0xfffe0000;
1180 hr = get_constants_desc(ptr, &pres->inputs, effect, NULL, 0, NULL);
1181 *ptr = saved_word;
1182 if (FAILED(hr))
1183 return hr;
1184
1185 if (const_count % get_reg_components(PRES_REGTAB_IMMED))
1186 {
1187 FIXME("const_count %u is not a multiple of %u.\n", const_count,
1189 return D3DXERR_INVALIDDATA;
1190 }
1191 pres->regs.table_sizes[PRES_REGTAB_IMMED] = get_reg_offset(PRES_REGTAB_IMMED, const_count);
1192
1193 update_table_sizes_consts(pres->regs.table_sizes, &pres->inputs);
1194 for (i = 0; i < pres->ins_count; ++i)
1195 {
1196 for (j = 0; j < pres_op_info[pres->ins[i].op].input_count; ++j)
1197 {
1199 unsigned int reg_idx;
1200
1201 if (pres->ins[i].inputs[j].index_reg.table == PRES_REGTAB_COUNT)
1202 {
1203 unsigned int last_component_index = pres->ins[i].scalar_op && !j ? 0
1204 : pres->ins[i].component_count - 1;
1205
1206 table = pres->ins[i].inputs[j].reg.table;
1207 reg_idx = get_reg_offset(table, pres->ins[i].inputs[j].reg.offset
1208 + last_component_index);
1209 }
1210 else
1211 {
1212 table = pres->ins[i].inputs[j].index_reg.table;
1213 reg_idx = get_reg_offset(table, pres->ins[i].inputs[j].index_reg.offset);
1214 }
1215 if (reg_idx >= pres->regs.table_sizes[table])
1216 {
1217 /* Native accepts these broken preshaders. */
1218 FIXME("Out of bounds register index, i %u, j %u, table %u, reg_idx %u, preshader parsing failed.\n",
1219 i, j, table, reg_idx);
1220 return D3DXERR_INVALIDDATA;
1221 }
1222 }
1223 update_table_size(pres->regs.table_sizes, pres->ins[i].output.reg.table,
1224 get_reg_offset(pres->ins[i].output.reg.table, pres->ins[i].output.reg.offset));
1225 }
1227 return E_OUTOFMEMORY;
1228 regstore_set_values(&pres->regs, PRES_REGTAB_IMMED, dconst, 0, const_count);
1229
1230 return D3D_OK;
1231}
#define UINT_MAX
Definition: limits.h:41
static unsigned int * parse_pres_ins(unsigned int *ptr, unsigned int count, struct d3dx_pres_ins *ins)
Definition: preshader.c:474
static enum pres_reg_tables pres_regset2table[]
Definition: preshader.c:227
static void update_table_size(unsigned int *table_sizes, unsigned int table, unsigned int max_register)
Definition: preshader.c:1009
#define FOURCC_FXLC
Definition: preshader.c:155
static void regstore_set_values(struct d3dx_regstore *rs, unsigned int table, const void *data, unsigned int start_offset, unsigned int count)
Definition: preshader.c:337
#define FOURCC_CLIT
Definition: preshader.c:154

Referenced by d3dx_create_param_eval().

◆ pres_acos()

static double pres_acos ( double args,
int  n 
)
static

Definition at line 140 of file preshader.c.

140{return to_signed_nan(acos(args[0]));}
valarray< _Tp > acos(const valarray< _Tp > &__x)
Definition: _valarray.h:901
static double to_signed_nan(double v)
Definition: preshader.c:69

◆ pres_add()

static double pres_add ( double args,
int  n 
)
static

Definition at line 85 of file preshader.c.

85{return args[0] + args[1];}

◆ pres_asin()

static double pres_asin ( double args,
int  n 
)
static

Definition at line 139 of file preshader.c.

139{return to_signed_nan(asin(args[0]));}
valarray< _Tp > asin(const valarray< _Tp > &__x)
Definition: _valarray.h:910

◆ pres_atan()

static double pres_atan ( double args,
int  n 
)
static

Definition at line 141 of file preshader.c.

141{return atan(args[0]);}
valarray< _Tp > atan(const valarray< _Tp > &__x)
Definition: _valarray.h:919

◆ pres_atan2()

static double pres_atan2 ( double args,
int  n 
)
static

Definition at line 142 of file preshader.c.

142{return atan2(args[0], args[1]);}
valarray< _Tp > atan2(const valarray< _Tp > &__x, const valarray< _Tp > &__y)
Definition: _valarray.h:928

◆ pres_bool_from_value()

static void pres_bool_from_value ( void out,
const void in,
unsigned int  count 
)
static

Definition at line 1380 of file preshader.c.

1381{
1382 unsigned int i;
1383 const DWORD *in_dword = in;
1384 BOOL *out_bool = out;
1385
1386 for (i = 0; i < count; ++i)
1387 out_bool[i] = !!in_dword[i];
1388}
GLuint in
Definition: glext.h:9616

Referenced by regstore_set_data().

◆ pres_cmp()

static double pres_cmp ( double args,
int  n 
)
static

Definition at line 115 of file preshader.c.

115{return args[0] >= 0.0 ? args[1] : args[2];}

◆ pres_cos()

static double pres_cos ( double args,
int  n 
)
static

Definition at line 117 of file preshader.c.

117{return cos(args[0]);}
_STLP_DECLSPEC complex< float > _STLP_CALL cos(const complex< float > &)

◆ pres_div()

static double pres_div ( double args,
int  n 
)
static

Definition at line 146 of file preshader.c.

146{return 0.0;}

◆ pres_dot()

static double pres_dot ( double args,
int  n 
)
static

Definition at line 87 of file preshader.c.

88{
89 int i;
90 double sum;
91
92 sum = 0.0;
93 for (i = 0; i < n; ++i)
94 sum += args[i] * args[i + n];
95 return sum;
96}
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35

Referenced by pres_dotswiz6(), and pres_dotswiz8().

◆ pres_dotswiz6()

static double pres_dotswiz6 ( double args,
int  n 
)
static

Definition at line 98 of file preshader.c.

99{
100 return pres_dot(args, 3);
101}
static double pres_dot(double *args, int n)
Definition: preshader.c:87

◆ pres_dotswiz8()

static double pres_dotswiz8 ( double args,
int  n 
)
static

Definition at line 103 of file preshader.c.

104{
105 return pres_dot(args, 4);
106}

◆ pres_exp()

static double pres_exp ( double args,
int  n 
)
static

Definition at line 128 of file preshader.c.

128{return pow(2.0, args[0]);}
double pow(double x, double y)
Definition: freeldr.c:112

◆ pres_float_from_bool()

static void pres_float_from_bool ( void out,
const void in,
unsigned int  count 
)
static

Definition at line 1400 of file preshader.c.

1401{
1402 unsigned int i;
1403 const BOOL *in_bool = in;
1404 float *out_float = out;
1405
1406 for (i = 0; i < count; ++i)
1407 out_float[i] = !!in_bool[i];
1408}

Referenced by regstore_set_data().

◆ pres_float_from_int()

static void pres_float_from_int ( void out,
const void in,
unsigned int  count 
)
static

Definition at line 1390 of file preshader.c.

1391{
1392 unsigned int i;
1393 const int *in_int = in;
1394 float *out_float = out;
1395
1396 for (i = 0; i < count; ++i)
1397 out_float[i] = in_int[i];
1398}

Referenced by regstore_set_data().

◆ pres_frc()

static double pres_frc ( double args,
int  n 
)
static

Definition at line 112 of file preshader.c.

112{return args[0] - floor(args[0]);}
_Check_return_ _CRTIMP double __cdecl floor(_In_ double x)

◆ pres_ge()

static double pres_ge ( double args,
int  n 
)
static

Definition at line 111 of file preshader.c.

111{return args[0] >= args[1] ? 1.0 : 0.0;}

◆ pres_int_from_bool()

static void pres_int_from_bool ( void out,
const void in,
unsigned int  count 
)
static

Definition at line 1410 of file preshader.c.

1411{
1412 unsigned int i;
1413 const float *in_bool = in;
1414 int *out_int = out;
1415
1416 for (i = 0; i < count; ++i)
1417 out_int[i] = !!in_bool[i];
1418}

Referenced by regstore_set_data().

◆ pres_int_from_float()

static void pres_int_from_float ( void out,
const void in,
unsigned int  count 
)
static

Definition at line 1370 of file preshader.c.

1371{
1372 unsigned int i;
1373 const float *in_float = in;
1374 int *out_int = out;
1375
1376 for (i = 0; i < count; ++i)
1377 out_int[i] = in_float[i];
1378}

Referenced by regstore_set_data().

◆ pres_log()

static double pres_log ( double args,
int  n 
)
static

Definition at line 129 of file preshader.c.

130{
131 double v;
132
133 v = fabs(args[0]);
134 if (v == 0.0)
135 return 0.0;
136 else
137 return log2(v);
138}
const GLdouble * v
Definition: gl.h:2040
_Check_return_ _CRT_JIT_INTRINSIC double __cdecl fabs(_In_ double x)
Definition: fabs.c:17
_Check_return_ __CRT_INLINE double log2(_In_ double x)
Definition: math.h:301

◆ pres_lt()

static double pres_lt ( double args,
int  n 
)
static

Definition at line 110 of file preshader.c.

110{return args[0] < args[1] ? 1.0 : 0.0;}

◆ pres_max()

static double pres_max ( double args,
int  n 
)
static

Definition at line 114 of file preshader.c.

114{return fmax(args[0], args[1]);}
#define fmax
Definition: graphics.c:64

◆ pres_min()

static double pres_min ( double args,
int  n 
)
static

Definition at line 113 of file preshader.c.

113{return fmin(args[0], args[1]);}
double __cdecl fmin(double, double)

◆ pres_mov()

static double pres_mov ( double args,
int  n 
)
static

Definition at line 84 of file preshader.c.

84{return args[0];}

◆ pres_mul()

static double pres_mul ( double args,
int  n 
)
static

Definition at line 86 of file preshader.c.

86{return args[0] * args[1];}

◆ pres_neg()

static double pres_neg ( double args,
int  n 
)
static

Definition at line 108 of file preshader.c.

108{return -args[0];}

◆ pres_rcp()

static double pres_rcp ( double args,
int  n 
)
static

Definition at line 109 of file preshader.c.

109{return 1.0 / args[0];}

◆ pres_rsq()

static double pres_rsq ( double args,
int  n 
)
static

Definition at line 118 of file preshader.c.

119{
120 double v;
121
122 v = fabs(args[0]);
123 if (v == 0.0)
124 return INFINITY;
125 else
126 return 1.0 / sqrt(v);
127}
_STLP_DECLSPEC complex< float > _STLP_CALL sqrt(const complex< float > &)
Definition: complex.cpp:188
#define INFINITY
Definition: misc.c:36

◆ pres_sin()

static double pres_sin ( double args,
int  n 
)
static

Definition at line 116 of file preshader.c.

116{return sin(args[0]);}
_STLP_DECLSPEC complex< float > _STLP_CALL sin(const complex< float > &)

◆ regstore_alloc_table()

static HRESULT regstore_alloc_table ( struct d3dx_regstore rs,
unsigned int  table 
)
static

Definition at line 313 of file preshader.c.

314{
315 unsigned int size;
316
317 size = get_offset_reg(table, rs->table_sizes[table]) * table_info[table].component_size;
318 if (size)
319 {
321 if (!rs->tables[table])
322 return E_OUTOFMEMORY;
323 }
324 return D3D_OK;
325}

Referenced by d3dx_create_param_eval(), and parse_preshader().

◆ regstore_free_tables()

static void regstore_free_tables ( struct d3dx_regstore rs)
static

Definition at line 327 of file preshader.c.

328{
329 unsigned int i;
330
331 for (i = 0; i < PRES_REGTAB_COUNT; ++i)
332 {
333 HeapFree(GetProcessHeap(), 0, rs->tables[i]);
334 }
335}

Referenced by d3dx_free_preshader().

◆ regstore_get_double()

static double regstore_get_double ( struct d3dx_regstore rs,
unsigned int  table,
unsigned int  offset 
)
static

Definition at line 350 of file preshader.c.

351{
352 BYTE *p;
353
354 p = (BYTE *)rs->tables[table] + table_info[table].component_size * offset;
356 {
357 case PRES_VT_FLOAT:
358 return *(float *)p;
359 case PRES_VT_DOUBLE:
360 return *(double *)p;
361 default:
362 FIXME("Unexpected preshader input from table %u.\n", table);
363 return NAN;
364 }
365}
switch(r->id)
Definition: btrfs.c:3046
#define NAN
Definition: mesh.c:39
unsigned char BYTE
Definition: xxhash.c:193

Referenced by exec_get_reg_value().

◆ regstore_set_data()

static void regstore_set_data ( struct d3dx_regstore rs,
unsigned int  table,
unsigned int  offset,
const unsigned int in,
unsigned int  count,
enum pres_value_type  param_type 
)
static

Definition at line 1420 of file preshader.c.

1422{
1423 typedef void (*conv_func)(void *out, const void *in, unsigned int count);
1424 static const conv_func set_const_funcs[PRES_VT_COUNT][PRES_VT_COUNT] =
1425 {
1427 {NULL, NULL, NULL, NULL},
1430 };
1431 enum pres_value_type table_type = table_info[table].type;
1432
1433 if (param_type == table_type)
1434 {
1436 return;
1437 }
1438
1439 set_const_funcs[param_type][table_type]((unsigned int *)rs->tables[table] + offset, in, count);
1440}
static void pres_float_from_bool(void *out, const void *in, unsigned int count)
Definition: preshader.c:1400
static void pres_float_from_int(void *out, const void *in, unsigned int count)
Definition: preshader.c:1390
static void pres_bool_from_value(void *out, const void *in, unsigned int count)
Definition: preshader.c:1380
static void pres_int_from_bool(void *out, const void *in, unsigned int count)
Definition: preshader.c:1410
static void pres_int_from_float(void *out, const void *in, unsigned int count)
Definition: preshader.c:1370

Referenced by set_constants().

◆ regstore_set_double()

static void regstore_set_double ( struct d3dx_regstore rs,
unsigned int  table,
unsigned int  offset,
double  v 
)
static

Definition at line 367 of file preshader.c.

368{
369 BYTE *p;
370
371 p = (BYTE *)rs->tables[table] + table_info[table].component_size * offset;
373 {
374 case PRES_VT_FLOAT : *(float *)p = v; break;
375 case PRES_VT_DOUBLE: *(double *)p = v; break;
376 case PRES_VT_INT : *(int *)p = lrint(v); break;
377 case PRES_VT_BOOL : *(BOOL *)p = !!v; break;
378 default:
379 FIXME("Bad type %u.\n", table_info[table].type);
380 break;
381 }
382}

Referenced by exec_set_arg().

◆ regstore_set_values()

static void regstore_set_values ( struct d3dx_regstore rs,
unsigned int  table,
const void data,
unsigned int  start_offset,
unsigned int  count 
)
static

Definition at line 337 of file preshader.c.

339{
340 BYTE *dst = rs->tables[table];
341 const BYTE *src = data;
342 unsigned int size;
343
344 dst += start_offset * table_info[table].component_size;
345 size = count * table_info[table].component_size;
346 assert((src < dst && size <= dst - src) || (src > dst && size <= src - dst));
347 memcpy(dst, src, size);
348}
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by parse_preshader(), regstore_set_data(), and set_constants().

◆ set_constants()

static HRESULT set_constants ( struct d3dx_regstore rs,
struct d3dx_const_tab const_tab,
ULONG64  new_update_version,
ID3DXEffectStateManager *  manager,
struct IDirect3DDevice9 *  device,
D3DXPARAMETER_TYPE  type,
BOOL  device_update_all,
BOOL  pres_dirty 
)
static

Definition at line 1483 of file preshader.c.

1486{
1487 unsigned int const_idx;
1488 unsigned int current_start = 0, current_count = 0;
1489 enum pres_reg_tables current_table = PRES_REGTAB_COUNT;
1490 BOOL update_device = manager || device;
1492 ULONG64 update_version = const_tab->update_version;
1493
1494 for (const_idx = 0; const_idx < const_tab->const_set_count; ++const_idx)
1495 {
1496 struct d3dx_const_param_eval_output *const_set = &const_tab->const_set[const_idx];
1497 enum pres_reg_tables table = const_set->table;
1498 struct d3dx_parameter *param = const_set->param;
1499 unsigned int element, i, j, start_offset;
1500 struct const_upload_info info;
1501 unsigned int *data;
1502 enum pres_value_type param_type;
1503
1504 if (!(param && is_param_dirty(param, update_version)))
1505 continue;
1506
1507 data = param->data;
1508 start_offset = get_offset_reg(table, const_set->register_index);
1509 if (const_set->direct_copy)
1510 {
1511 regstore_set_values(rs, table, data, start_offset,
1512 get_offset_reg(table, const_set->register_count));
1513 continue;
1514 }
1515 param_type = table_type_from_param_type(param->type);
1516 if (const_set->constant_class == D3DXPC_SCALAR || const_set->constant_class == D3DXPC_VECTOR)
1517 {
1518 unsigned int count = max(param->rows, param->columns);
1519
1521 {
1522 regstore_set_data(rs, table, start_offset, data,
1523 count * const_set->element_count, param_type);
1524 }
1525 else
1526 {
1527 for (element = 0; element < const_set->element_count; ++element)
1528 regstore_set_data(rs, table, start_offset + get_offset_reg(table, element),
1529 &data[element * count], count, param_type);
1530 }
1531 continue;
1532 }
1533 get_const_upload_info(const_set, &info);
1534 for (element = 0; element < const_set->element_count; ++element)
1535 {
1536 unsigned int *out = (unsigned int *)rs->tables[table] + start_offset;
1537
1538 /* Store reshaped but (possibly) not converted yet data temporarily in the same constants buffer.
1539 * All the supported types of parameters and table values have the same size. */
1540 if (info.transpose)
1541 {
1542 for (i = 0; i < info.major_count; ++i)
1543 for (j = 0; j < info.minor; ++j)
1544 out[i * info.major_stride + j] = data[i + j * info.major];
1545
1546 for (j = 0; j < info.minor_remainder; ++j)
1547 out[i * info.major_stride + j] = data[i + j * info.major];
1548 }
1549 else
1550 {
1551 for (i = 0; i < info.major_count; ++i)
1552 for (j = 0; j < info.minor; ++j)
1553 out[i * info.major_stride + j] = data[i * info.minor + j];
1554 }
1555 start_offset += get_offset_reg(table, const_set->register_count);
1556 data += param->rows * param->columns;
1557 }
1558 start_offset = get_offset_reg(table, const_set->register_index);
1559 if (table_info[table].type != param_type)
1560 regstore_set_data(rs, table, start_offset, (unsigned int *)rs->tables[table] + start_offset,
1561 get_offset_reg(table, const_set->register_count) * const_set->element_count, param_type);
1562 }
1563 const_tab->update_version = new_update_version;
1564 if (!update_device)
1565 return D3D_OK;
1566
1567 for (const_idx = 0; const_idx < const_tab->const_set_count; ++const_idx)
1568 {
1569 struct d3dx_const_param_eval_output *const_set = &const_tab->const_set[const_idx];
1570
1571 if (device_update_all || (const_set->param
1572 ? is_param_dirty(const_set->param, update_version) : pres_dirty))
1573 {
1574 enum pres_reg_tables table = const_set->table;
1575
1576 if (table == current_table && current_start + current_count == const_set->register_index)
1577 {
1578 current_count += const_set->register_count * const_set->element_count;
1579 }
1580 else
1581 {
1582 if (current_count)
1583 {
1584 if (FAILED(hr = set_constants_device(manager, device, type, current_table,
1585 (DWORD *)rs->tables[current_table]
1586 + get_offset_reg(current_table, current_start), current_start, current_count)))
1587 result = hr;
1588 }
1589 current_table = table;
1590 current_start = const_set->register_index;
1591 current_count = const_set->register_count * const_set->element_count;
1592 }
1593 }
1594 }
1595 if (current_count)
1596 {
1597 if (FAILED(hr = set_constants_device(manager, device, type, current_table,
1598 (DWORD *)rs->tables[current_table]
1599 + get_offset_reg(current_table, current_start), current_start, current_count)))
1600 result = hr;
1601 }
1602 return result;
1603}
static BOOL is_param_dirty(struct d3dx_parameter *param, ULONG64 update_version)
@ D3DXPC_SCALAR
Definition: d3dx9shader.h:62
@ D3DXPC_VECTOR
Definition: d3dx9shader.h:63
GLuint64EXT * result
Definition: glext.h:11304
static HRESULT set_constants_device(ID3DXEffectStateManager *manager, struct IDirect3DDevice9 *device, D3DXPARAMETER_TYPE type, enum pres_reg_tables table, void *ptr, unsigned int start, unsigned int count)
Definition: preshader.c:1442
static void regstore_set_data(struct d3dx_regstore *rs, unsigned int table, unsigned int offset, const unsigned int *in, unsigned int count, enum pres_value_type param_type)
Definition: preshader.c:1420

Referenced by d3dx_evaluate_parameter(), and d3dx_param_eval_set_shader_constants().

◆ set_constants_device()

static HRESULT set_constants_device ( ID3DXEffectStateManager *  manager,
struct IDirect3DDevice9 *  device,
D3DXPARAMETER_TYPE  type,
enum pres_reg_tables  table,
void ptr,
unsigned int  start,
unsigned int  count 
)
static

Definition at line 1442 of file preshader.c.

1445{
1447 {
1448 switch(table)
1449 {
1450 case PRES_REGTAB_OCONST:
1451 return SET_D3D_STATE_(manager, device, SetVertexShaderConstantF, start, ptr, count);
1453 return SET_D3D_STATE_(manager, device, SetVertexShaderConstantI, start, ptr, count);
1455 return SET_D3D_STATE_(manager, device, SetVertexShaderConstantB, start, ptr, count);
1456 default:
1457 FIXME("Unexpected register table %u.\n", table);
1458 return D3DERR_INVALIDCALL;
1459 }
1460 }
1461 else if (type == D3DXPT_PIXELSHADER)
1462 {
1463 switch(table)
1464 {
1465 case PRES_REGTAB_OCONST:
1466 return SET_D3D_STATE_(manager, device, SetPixelShaderConstantF, start, ptr, count);
1468 return SET_D3D_STATE_(manager, device, SetPixelShaderConstantI, start, ptr, count);
1470 return SET_D3D_STATE_(manager, device, SetPixelShaderConstantB, start, ptr, count);
1471 default:
1472 FIXME("Unexpected register table %u.\n", table);
1473 return D3DERR_INVALIDCALL;
1474 }
1475 }
1476 else
1477 {
1478 FIXME("Unexpected parameter type %u.\n", type);
1479 return D3DERR_INVALIDCALL;
1480 }
1481}
#define SET_D3D_STATE_(manager, device, method, args...)
GLuint start
Definition: gl.h:1545

Referenced by set_constants().

◆ table_type_from_param_type()

static enum pres_value_type table_type_from_param_type ( D3DXPARAMETER_TYPE  type)
static

Definition at line 280 of file preshader.c.

281{
282 switch (type)
283 {
284 case D3DXPT_FLOAT:
285 return PRES_VT_FLOAT;
286 case D3DXPT_INT:
287 return PRES_VT_INT;
288 case D3DXPT_BOOL:
289 return PRES_VT_BOOL;
290 default:
291 FIXME("Unsupported type %u.\n", type);
292 return PRES_VT_COUNT;
293 }
294}
@ D3DXPT_BOOL
Definition: d3dx9shader.h:74
@ D3DXPT_INT
Definition: d3dx9shader.h:75

Referenced by init_set_constants_param(), merge_const_set_entries(), and set_constants().

◆ to_signed_nan()

static double to_signed_nan ( double  v)
static

Definition at line 69 of file preshader.c.

70{
71 static const union
72 {
73 ULONG64 ulong64_value;
74 double double_value;
75 }
76 signed_nan =
77 {
78 0xfff8000000000000
79 };
80
81 return isnan(v) ? signed_nan.double_value : v;
82}
#define isnan(x)
Definition: mingw_math.h:133

Referenced by pres_acos(), and pres_asin().

◆ update_table_size()

static void update_table_size ( unsigned int table_sizes,
unsigned int  table,
unsigned int  max_register 
)
static

Definition at line 1009 of file preshader.c.

1010{
1012 table_sizes[table] = max(table_sizes[table], max_register + 1);
1013}

Referenced by parse_preshader(), and update_table_sizes_consts().

◆ update_table_sizes_consts()

static void update_table_sizes_consts ( unsigned int table_sizes,
struct d3dx_const_tab ctab 
)
static

Definition at line 1015 of file preshader.c.

1016{
1017 unsigned int i, table, max_register;
1018
1019 for (i = 0; i < ctab->input_count; ++i)
1020 {
1021 if (!ctab->inputs[i].RegisterCount)
1022 continue;
1023 max_register = ctab->inputs[i].RegisterIndex + ctab->inputs[i].RegisterCount - 1;
1024 table = ctab->regset2table[ctab->inputs[i].RegisterSet];
1025 update_table_size(table_sizes, table, max_register);
1026 }
1027}

Referenced by d3dx_create_param_eval(), and parse_preshader().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3dx  )

Variable Documentation

◆ component_size

unsigned int component_size

Definition at line 208 of file preshader.c.

◆ pres_op_info

const struct op_info pres_op_info[]
static
Initial value:
=
{
{0x000, "nop", 0, 0, NULL },
{0x100, "mov", 1, 0, pres_mov},
{0x101, "neg", 1, 0, pres_neg},
{0x103, "rcp", 1, 0, pres_rcp},
{0x104, "frc", 1, 0, pres_frc},
{0x105, "exp", 1, 0, pres_exp},
{0x106, "log", 1, 0, pres_log},
{0x107, "rsq", 1, 0, pres_rsq},
{0x108, "sin", 1, 0, pres_sin},
{0x109, "cos", 1, 0, pres_cos},
{0x10a, "asin", 1, 0, pres_asin},
{0x10b, "acos", 1, 0, pres_acos},
{0x10c, "atan", 1, 0, pres_atan},
{0x200, "min", 2, 0, pres_min},
{0x201, "max", 2, 0, pres_max},
{0x202, "lt", 2, 0, pres_lt },
{0x203, "ge", 2, 0, pres_ge },
{0x204, "add", 2, 0, pres_add},
{0x205, "mul", 2, 0, pres_mul},
{0x206, "atan2", 2, 0, pres_atan2},
{0x208, "div", 2, 0, pres_div},
{0x300, "cmp", 3, 0, pres_cmp},
{0x500, "dot", 2, 1, pres_dot},
{0x70e, "d3ds_dotswiz", 6, 0, pres_dotswiz6},
{0x70e, "d3ds_dotswiz", 8, 0, pres_dotswiz8},
}
static double pres_frc(double *args, int n)
Definition: preshader.c:112
static double pres_div(double *args, int n)
Definition: preshader.c:146
static double pres_sin(double *args, int n)
Definition: preshader.c:116
static double pres_dotswiz6(double *args, int n)
Definition: preshader.c:98
static double pres_mov(double *args, int n)
Definition: preshader.c:84
static double pres_cmp(double *args, int n)
Definition: preshader.c:115
static double pres_cos(double *args, int n)
Definition: preshader.c:117
static double pres_lt(double *args, int n)
Definition: preshader.c:110
static double pres_mul(double *args, int n)
Definition: preshader.c:86
static double pres_exp(double *args, int n)
Definition: preshader.c:128
static double pres_rcp(double *args, int n)
Definition: preshader.c:109
static double pres_neg(double *args, int n)
Definition: preshader.c:108
static double pres_atan(double *args, int n)
Definition: preshader.c:141
static double pres_add(double *args, int n)
Definition: preshader.c:85
static double pres_asin(double *args, int n)
Definition: preshader.c:139
static double pres_atan2(double *args, int n)
Definition: preshader.c:142
static double pres_max(double *args, int n)
Definition: preshader.c:114
static double pres_acos(double *args, int n)
Definition: preshader.c:140
static double pres_log(double *args, int n)
Definition: preshader.c:129
static double pres_ge(double *args, int n)
Definition: preshader.c:111
static double pres_min(double *args, int n)
Definition: preshader.c:113
static double pres_dotswiz8(double *args, int n)
Definition: preshader.c:103
static double pres_rsq(double *args, int n)
Definition: preshader.c:118

Definition at line 168 of file preshader.c.

Referenced by dump_ins(), execute_preshader(), parse_pres_ins(), and parse_preshader().

◆ pres_regset2table

enum pres_reg_tables pres_regset2table[]
static
Initial value:

Definition at line 227 of file preshader.c.

Referenced by parse_preshader().

◆ shad_regset2table

enum pres_reg_tables shad_regset2table[]
static

◆ 

const struct { ... } table_info[]
Initial value:
=
{
{sizeof(double), PRES_VT_DOUBLE},
{sizeof(float), PRES_VT_FLOAT },
{sizeof(float), PRES_VT_FLOAT },
{sizeof(BOOL), PRES_VT_BOOL },
{sizeof(int), PRES_VT_INT, },
{sizeof(float), PRES_VT_FLOAT }
}
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
static float(__cdecl *square_half_float)(float x
#define BOOL
Definition: nt_native.h:43

Referenced by FT_DEFINE_SERVICE(), init_set_constants_param(), regstore_alloc_table(), regstore_get_double(), regstore_set_data(), regstore_set_double(), regstore_set_values(), and set_constants().

◆ table_symbol

const char* table_symbol[]
static
Initial value:
=
{
"imm", "c", "oc", "ob", "oi", "r", "(null)",
}

Definition at line 222 of file preshader.c.

Referenced by dump_arg(), and dump_registers().

◆ type

Definition at line 209 of file preshader.c.

Referenced by d3dx_create_param_eval().