wined3d: Use shader_sm1_read_opcode() in shader_get_registers_used().

This commit is contained in:
Henri Verbeet 2009-04-24 09:17:58 +02:00 committed by Alexandre Julliard
parent 521fcf11db
commit 19b84ffda1
1 changed files with 64 additions and 51 deletions

View File

@ -384,8 +384,8 @@ HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, struct shader_reg_m
pshader = shader_is_pshader_version(shader_version); pshader = shader_is_pshader_version(shader_version);
while (WINED3DVS_END() != *pToken) { while (WINED3DVS_END() != *pToken) {
CONST SHADER_OPCODE* curOpcode; struct wined3d_shader_instruction ins;
DWORD opcode_token; UINT param_size;
/* Skip comments */ /* Skip comments */
if (shader_is_comment(*pToken)) if (shader_is_comment(*pToken))
@ -397,17 +397,19 @@ HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, struct shader_reg_m
} }
/* Fetch opcode */ /* Fetch opcode */
opcode_token = *pToken++; shader_sm1_read_opcode(&pToken, &ins, &param_size, shader_ins, shader_version);
curOpcode = shader_get_opcode(shader_ins, shader_version, opcode_token);
/* Unhandled opcode, and its parameters */ /* Unhandled opcode, and its parameters */
if (NULL == curOpcode) { if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
while (*pToken & 0x80000000) {
++pToken; TRACE("Skipping unrecognized instruction.\n");
pToken += param_size;
continue;
}
/* Handle declarations */ /* Handle declarations */
} else if (WINED3DSIO_DCL == curOpcode->opcode) { if (ins.handler_idx == WINED3DSIH_DCL)
{
DWORD usage = *pToken++; DWORD usage = *pToken++;
DWORD param = *pToken++; DWORD param = *pToken++;
DWORD regtype = shader_get_regtype(param); DWORD regtype = shader_get_regtype(param);
@ -441,9 +443,9 @@ HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, struct shader_reg_m
/* Save sampler usage token */ /* Save sampler usage token */
} else if (WINED3DSPR_SAMPLER == regtype) } else if (WINED3DSPR_SAMPLER == regtype)
reg_maps->samplers[regnum] = usage; reg_maps->samplers[regnum] = usage;
}
} else if (WINED3DSIO_DEF == curOpcode->opcode) { else if (ins.handler_idx == WINED3DSIH_DEF)
{
local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant)); local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
if (!lconst) return E_OUTOFMEMORY; if (!lconst) return E_OUTOFMEMORY;
lconst->idx = *pToken & WINED3DSP_REGNUM_MASK; lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
@ -464,65 +466,70 @@ HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, struct shader_reg_m
} }
list_add_head(&This->baseShader.constantsF, &lconst->entry); list_add_head(&This->baseShader.constantsF, &lconst->entry);
pToken += curOpcode->num_params; pToken += param_size;
}
} else if (WINED3DSIO_DEFI == curOpcode->opcode) { else if (ins.handler_idx == WINED3DSIH_DEFI)
{
local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant)); local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
if (!lconst) return E_OUTOFMEMORY; if (!lconst) return E_OUTOFMEMORY;
lconst->idx = *pToken & WINED3DSP_REGNUM_MASK; lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
memcpy(lconst->value, pToken + 1, 4 * sizeof(DWORD)); memcpy(lconst->value, pToken + 1, 4 * sizeof(DWORD));
list_add_head(&This->baseShader.constantsI, &lconst->entry); list_add_head(&This->baseShader.constantsI, &lconst->entry);
pToken += curOpcode->num_params; pToken += param_size;
}
} else if (WINED3DSIO_DEFB == curOpcode->opcode) { else if (ins.handler_idx == WINED3DSIH_DEFB)
{
local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant)); local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
if (!lconst) return E_OUTOFMEMORY; if (!lconst) return E_OUTOFMEMORY;
lconst->idx = *pToken & WINED3DSP_REGNUM_MASK; lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
memcpy(lconst->value, pToken + 1, 1 * sizeof(DWORD)); memcpy(lconst->value, pToken + 1, 1 * sizeof(DWORD));
list_add_head(&This->baseShader.constantsB, &lconst->entry); list_add_head(&This->baseShader.constantsB, &lconst->entry);
pToken += curOpcode->num_params; pToken += param_size;
}
/* If there's a loop in the shader */ /* If there's a loop in the shader */
} else if (WINED3DSIO_LOOP == curOpcode->opcode || else if (ins.handler_idx == WINED3DSIH_LOOP
WINED3DSIO_REP == curOpcode->opcode) { || ins.handler_idx == WINED3DSIH_REP)
{
cur_loop_depth++; cur_loop_depth++;
if(cur_loop_depth > max_loop_depth) if(cur_loop_depth > max_loop_depth)
max_loop_depth = cur_loop_depth; max_loop_depth = cur_loop_depth;
pToken += curOpcode->num_params; pToken += param_size;
/* Rep and Loop always use an integer constant for the control parameters */ /* Rep and Loop always use an integer constant for the control parameters */
This->baseShader.uses_int_consts = TRUE; This->baseShader.uses_int_consts = TRUE;
} else if (WINED3DSIO_ENDLOOP == curOpcode->opcode || }
WINED3DSIO_ENDREP == curOpcode->opcode) { else if (ins.handler_idx == WINED3DSIH_ENDLOOP
|| ins.handler_idx == WINED3DSIH_ENDREP)
{
cur_loop_depth--; cur_loop_depth--;
}
/* For subroutine prototypes */ /* For subroutine prototypes */
} else if (WINED3DSIO_LABEL == curOpcode->opcode) { else if (ins.handler_idx == WINED3DSIH_LABEL)
{
DWORD snum = *pToken & WINED3DSP_REGNUM_MASK; DWORD snum = *pToken & WINED3DSP_REGNUM_MASK;
reg_maps->labels[snum] = 1; reg_maps->labels[snum] = 1;
pToken += curOpcode->num_params; pToken += param_size;
}
/* Set texture, address, temporary registers */ /* Set texture, address, temporary registers */
} else { else
{
int i, limit; int i, limit;
/* Declare 1.X samplers implicitly, based on the destination reg. number */ /* Declare 1.X samplers implicitly, based on the destination reg. number */
if (WINED3DSHADER_VERSION_MAJOR(shader_version) == 1 if (WINED3DSHADER_VERSION_MAJOR(shader_version) == 1
&& pshader /* Filter different instructions with the same enum values in VS */ && pshader /* Filter different instructions with the same enum values in VS */
&& (WINED3DSIO_TEX == curOpcode->opcode && (ins.handler_idx == WINED3DSIH_TEX
|| WINED3DSIO_TEXBEM == curOpcode->opcode || ins.handler_idx == WINED3DSIH_TEXBEM
|| WINED3DSIO_TEXBEML == curOpcode->opcode || ins.handler_idx == WINED3DSIH_TEXBEML
|| WINED3DSIO_TEXDP3TEX == curOpcode->opcode || ins.handler_idx == WINED3DSIH_TEXDP3TEX
|| WINED3DSIO_TEXM3x2TEX == curOpcode->opcode || ins.handler_idx == WINED3DSIH_TEXM3x2TEX
|| WINED3DSIO_TEXM3x3SPEC == curOpcode->opcode || ins.handler_idx == WINED3DSIH_TEXM3x3SPEC
|| WINED3DSIO_TEXM3x3TEX == curOpcode->opcode || ins.handler_idx == WINED3DSIH_TEXM3x3TEX
|| WINED3DSIO_TEXM3x3VSPEC == curOpcode->opcode || ins.handler_idx == WINED3DSIH_TEXM3x3VSPEC
|| WINED3DSIO_TEXREG2AR == curOpcode->opcode || ins.handler_idx == WINED3DSIH_TEXREG2AR
|| WINED3DSIO_TEXREG2GB == curOpcode->opcode || ins.handler_idx == WINED3DSIH_TEXREG2GB
|| WINED3DSIO_TEXREG2RGB == curOpcode->opcode)) || ins.handler_idx == WINED3DSIH_TEXREG2RGB))
{ {
/* Fake sampler usage, only set reserved bit and ttype */ /* Fake sampler usage, only set reserved bit and ttype */
DWORD sampler_code = *pToken & WINED3DSP_REGNUM_MASK; DWORD sampler_code = *pToken & WINED3DSP_REGNUM_MASK;
@ -531,20 +538,27 @@ HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, struct shader_reg_m
reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_2D; reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_2D;
/* texbem is only valid with < 1.4 pixel shaders */ /* texbem is only valid with < 1.4 pixel shaders */
if(WINED3DSIO_TEXBEM == curOpcode->opcode || if (ins.handler_idx == WINED3DSIH_TEXBEM
WINED3DSIO_TEXBEML == curOpcode->opcode) { || ins.handler_idx == WINED3DSIH_TEXBEML)
{
reg_maps->bumpmat[sampler_code] = TRUE; reg_maps->bumpmat[sampler_code] = TRUE;
if(WINED3DSIO_TEXBEML == curOpcode->opcode) { if (ins.handler_idx == WINED3DSIH_TEXBEML)
{
reg_maps->luminanceparams[sampler_code] = TRUE; reg_maps->luminanceparams[sampler_code] = TRUE;
} }
} }
} }
if(WINED3DSIO_NRM == curOpcode->opcode) { if (ins.handler_idx == WINED3DSIH_NRM)
{
reg_maps->usesnrm = 1; reg_maps->usesnrm = 1;
} else if(WINED3DSIO_BEM == curOpcode->opcode && pshader) { }
else if (pshader && ins.handler_idx == WINED3DSIH_BEM)
{
DWORD regnum = *pToken & WINED3DSP_REGNUM_MASK; DWORD regnum = *pToken & WINED3DSP_REGNUM_MASK;
reg_maps->bumpmat[regnum] = TRUE; reg_maps->bumpmat[regnum] = TRUE;
} else if(WINED3DSIO_DSY == curOpcode->opcode) { }
else if (ins.handler_idx == WINED3DSIH_DSY)
{
reg_maps->usesdsy = 1; reg_maps->usesdsy = 1;
} }
@ -555,8 +569,7 @@ HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, struct shader_reg_m
* okay, since we'll catch any address registers when * okay, since we'll catch any address registers when
* they are initialized (required by spec) */ * they are initialized (required by spec) */
limit = (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED)? limit = ins.dst_count + ins.src_count + (ins.predicate ? 1 : 0);
curOpcode->num_params + 1: curOpcode->num_params;
for (i = 0; i < limit; ++i) { for (i = 0; i < limit; ++i) {