Commit b3563dac authored by Oliver Stieber's avatar Oliver Stieber Committed by Alexandre Julliard

Implement state tracking for pixel shader constants.

parent 60a52559
...@@ -539,13 +539,13 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, WINED3 ...@@ -539,13 +539,13 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, WINED3
TRACE("PIXELSTATE => Pretend all pixel shates have changed\n"); TRACE("PIXELSTATE => Pretend all pixel shates have changed\n");
memset(&object->changed, FALSE, sizeof(This->stateBlock->changed)); memset(&object->changed, FALSE, sizeof(This->stateBlock->changed));
object->changed.pixelShader = TRUE; object->changed.pixelShader = TRUE;
#if 0 /* TODO: Pixel Shader Constants */ /* Pixel Shader Constants */
for (i = 0; i < MAX_PSHADER_CONSTANTS; ++i) { for (i = 0; i < MAX_PSHADER_CONSTANTS; ++i) {
object->changed.pixelShaderConstants[i] = TRUE; object->changed.pixelShaderConstants[i] = TRUE;
} }
#endif
for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) { for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
object->changed.renderState[SavedPixelStates_R[i]] = TRUE; object->changed.renderState[SavedPixelStates_R[i]] = TRUE;
} }
...@@ -565,8 +565,10 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, WINED3 ...@@ -565,8 +565,10 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, WINED3
TRACE("VERTEXSTATE => Pretend all vertex shates have changed\n"); TRACE("VERTEXSTATE => Pretend all vertex shates have changed\n");
memset(&object->changed, FALSE, sizeof(This->stateBlock->changed)); memset(&object->changed, FALSE, sizeof(This->stateBlock->changed));
/* TODO: Vertex Shader Constants */
object->changed.vertexShader = TRUE; object->changed.vertexShader = TRUE;
/* Vertex Shader Constants */
for (i = 0; i < MAX_VSHADER_CONSTANTS; ++i) { for (i = 0; i < MAX_VSHADER_CONSTANTS; ++i) {
object->changed.vertexShaderConstants[i] = TRUE; object->changed.vertexShaderConstants[i] = TRUE;
} }
...@@ -3867,7 +3869,6 @@ HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShader(IWineD3DDevice *iface, IWineD3D ...@@ -3867,7 +3869,6 @@ HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShader(IWineD3DDevice *iface, IWineD3D
IWineD3DPixelShader *oldpShader = This->updateStateBlock->pixelShader; IWineD3DPixelShader *oldpShader = This->updateStateBlock->pixelShader;
static BOOL showFixmes = TRUE; static BOOL showFixmes = TRUE;
/** FIXME: reference counting? **/
This->updateStateBlock->pixelShader = pShader; This->updateStateBlock->pixelShader = pShader;
This->updateStateBlock->changed.pixelShader = TRUE; This->updateStateBlock->changed.pixelShader = TRUE;
This->updateStateBlock->set.pixelShader = TRUE; This->updateStateBlock->set.pixelShader = TRUE;
...@@ -3902,8 +3903,6 @@ HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShader(IWineD3DDevice *iface, IWineD3D ...@@ -3902,8 +3903,6 @@ HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShader(IWineD3DDevice *iface, IWineD3D
IUnknown_Release(parent); /* and once for the ref */ IUnknown_Release(parent); /* and once for the ref */
} }
return D3D_OK; return D3D_OK;
} }
...@@ -3924,7 +3923,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_GetPixelShader(IWineD3DDevice *iface, IWineD3D ...@@ -3924,7 +3923,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_GetPixelShader(IWineD3DDevice *iface, IWineD3D
} }
#define GET_SHADER_CONSTANT(_pixelshaderconstant, _count, _sizecount) \ #define GET_SHADER_CONSTANT(_pixelshaderconstant, _count, _sizecount) \
int count = min(_count, MAX_PSHADER_CONSTANTS - (StartRegister + 1)); \ count = min(_count, MAX_PSHADER_CONSTANTS - (StartRegister + 1)); \
if (NULL == pConstantData || count < 0 /* || _count != count */ ) \ if (NULL == pConstantData || count < 0 /* || _count != count */ ) \
return D3DERR_INVALIDCALL; \ return D3DERR_INVALIDCALL; \
memcpy(pConstantData, This->updateStateBlock->_pixelshaderconstant + (StartRegister * _sizecount), count * (sizeof(*pConstantData) * _sizecount)); \ memcpy(pConstantData, This->updateStateBlock->_pixelshaderconstant + (StartRegister * _sizecount), count * (sizeof(*pConstantData) * _sizecount)); \
...@@ -3941,68 +3940,109 @@ This->updateStateBlock->set.pixelShader = TRUE; ...@@ -3941,68 +3940,109 @@ This->updateStateBlock->set.pixelShader = TRUE;
HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantB(IWineD3DDevice *iface, UINT StartRegister, CONST BOOL *pConstantData, UINT BoolCount) { HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantB(IWineD3DDevice *iface, UINT StartRegister, CONST BOOL *pConstantData, UINT BoolCount) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
static BOOL showFixmes = TRUE; int i;
SET_SHADER_CONSTANT(pixelShaderConstantB, BoolCount, 1); SET_SHADER_CONSTANT(pixelShaderConstantB, BoolCount, 1);
if(showFixmes) {
FIXME("(%p) : stub\n", This); /* populate the bitmap that says which constant type we should load */
showFixmes = FALSE; for (i = StartRegister; i < BoolCount + StartRegister; ++i) {
This->updateStateBlock->changed.pixelShaderConstants[i] = TRUE;
This->updateStateBlock->set.pixelShaderConstants[i] = TRUE;
This->updateStateBlock->pixelShaderConstantT[i] = WINESHADERCNST_BOOL;
TRACE("(%p) : Setting psb %d to %d\n", This->updateStateBlock, i, pConstantData[i - StartRegister]);
} }
return D3D_OK; return D3D_OK;
} }
HRESULT WINAPI IWineD3DDeviceImpl_GetPixelShaderConstantB(IWineD3DDevice *iface, UINT StartRegister, BOOL *pConstantData, UINT BoolCount) { HRESULT WINAPI IWineD3DDeviceImpl_GetPixelShaderConstantB(IWineD3DDevice *iface, UINT StartRegister, BOOL *pConstantData, UINT BoolCount) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
static BOOL showFixmes = TRUE; int i, count;
GET_SHADER_CONSTANT(pixelShaderConstantB, BoolCount, 1);
if(showFixmes) { /* populate the bitmap that says which constant type we should load */
FIXME("(%p) : stub\n", This); for (i = StartRegister; i < BoolCount + StartRegister; ++i) {
showFixmes = FALSE; This->updateStateBlock->changed.pixelShaderConstants[i] = TRUE;
This->updateStateBlock->set.pixelShaderConstants[i] = TRUE;
This->updateStateBlock->pixelShaderConstantT[i] = WINESHADERCNST_BOOL;
TRACE("(%p) : Setting psb %d to %d\n", This->updateStateBlock, i, pConstantData[i - StartRegister]);
} }
GET_SHADER_CONSTANT(pixelShaderConstantB, BoolCount, 1);
return D3D_OK; return D3D_OK;
} }
HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantI(IWineD3DDevice *iface, UINT StartRegister, CONST int *pConstantData, UINT Vector4iCount) { HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantI(IWineD3DDevice *iface, UINT StartRegister, CONST int *pConstantData, UINT Vector4iCount) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
static BOOL showFixmes = TRUE; int i;
SET_SHADER_CONSTANT(pixelShaderConstantI, Vector4iCount, 4); SET_SHADER_CONSTANT(pixelShaderConstantI, Vector4iCount, 4);
if(showFixmes) {
FIXME("(%p) : stub\n", This); /* populate the bitmap that says which constant type we should load */
showFixmes = FALSE; for (i = StartRegister; i < Vector4iCount + StartRegister; ++i) {
This->updateStateBlock->changed.pixelShaderConstants[i] = TRUE;
This->updateStateBlock->set.pixelShaderConstants[i] = TRUE;
This->updateStateBlock->pixelShaderConstantT[i] = WINESHADERCNST_INTEGER;
TRACE("(%p) : Setting psb %d to %d\n", This->updateStateBlock, i, pConstantData[i - StartRegister]);
} }
return D3D_OK; return D3D_OK;
} }
HRESULT WINAPI IWineD3DDeviceImpl_GetPixelShaderConstantI(IWineD3DDevice *iface, UINT StartRegister, int *pConstantData, UINT Vector4iCount) { HRESULT WINAPI IWineD3DDeviceImpl_GetPixelShaderConstantI(IWineD3DDevice *iface, UINT StartRegister, int *pConstantData, UINT Vector4iCount) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
static BOOL showFixmes = TRUE; int i, count;
GET_SHADER_CONSTANT(pixelShaderConstantI, Vector4iCount, 4);
if(showFixmes) { /* verify that the requested shader constant was populated with a integer */
FIXME("(%p) : stub\n", This); for (i = StartRegister; i < Vector4iCount; ++i) {
showFixmes = FALSE; if (WINESHADERCNST_INTEGER != This->updateStateBlock->pixelShaderConstantT[i]) {
/* the constant for this register isn't a integer */
WARN("(%p) : Caller requested a integer where stateblock (%p) entry is a %s. Returning D3DERR_INVALIDCALL\n", This, This->updateStateBlock,
WINESHADERCNST_BOOL == This->updateStateBlock->vertexShaderConstantT[i] ? "boolean" : "float");
return D3DERR_INVALIDCALL;
}
} }
GET_SHADER_CONSTANT(pixelShaderConstantI, Vector4iCount, 4);
return D3D_OK; return D3D_OK;
} }
HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantF(IWineD3DDevice *iface, UINT StartRegister, CONST float *pConstantData, UINT Vector4fCount) { HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantF(IWineD3DDevice *iface, UINT StartRegister, CONST float *pConstantData, UINT Vector4fCount) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
static BOOL showFixmes = TRUE; int i;
SET_SHADER_CONSTANT(pixelShaderConstantF, Vector4fCount, 4); SET_SHADER_CONSTANT(pixelShaderConstantF, Vector4fCount, 4);
if(showFixmes) {
FIXME("(%p) : stub\n", This); /* populate the bitmap that says which constant type we should load */
showFixmes = FALSE; for (i = StartRegister; i < Vector4fCount + StartRegister; ++i) {
This->updateStateBlock->changed.pixelShaderConstants[i] = TRUE;
This->updateStateBlock->set.pixelShaderConstants[i] = TRUE;
This->updateStateBlock->pixelShaderConstantT[i] = WINESHADERCNST_FLOAT;
TRACE("(%p) : Setting psb %d to %f\n", This->updateStateBlock, i, pConstantData[i - StartRegister]);
} }
return D3D_OK; return D3D_OK;
} }
HRESULT WINAPI IWineD3DDeviceImpl_GetPixelShaderConstantF(IWineD3DDevice *iface, UINT StartRegister, float *pConstantData, UINT Vector4fCount) { HRESULT WINAPI IWineD3DDeviceImpl_GetPixelShaderConstantF(IWineD3DDevice *iface, UINT StartRegister, float *pConstantData, UINT Vector4fCount) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
static BOOL showFixmes = TRUE; int i, count;
GET_SHADER_CONSTANT(pixelShaderConstantF, Vector4fCount, 4);
if(showFixmes) { /* verify that the requested shader constant was populated with a integer */
FIXME("(%p) : stub\n", This); for (i = StartRegister; i < Vector4fCount; ++i) {
showFixmes = FALSE; if (WINESHADERCNST_FLOAT != This->updateStateBlock->pixelShaderConstantT[i]) {
/* the constant for this register isn't a float */
WARN("(%p) : Caller requested a integer where stateblock (%p) entry is a %s. Returning D3DERR_INVALIDCALL\n", This, This->updateStateBlock,
WINESHADERCNST_BOOL == This->updateStateBlock->vertexShaderConstantT[i] ? "boolean" : "integer");
return D3DERR_INVALIDCALL;
}
} }
GET_SHADER_CONSTANT(pixelShaderConstantF, Vector4fCount, 4);
return D3D_OK; return D3D_OK;
} }
......
...@@ -207,14 +207,28 @@ HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface){ ...@@ -207,14 +207,28 @@ HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface){
src = src->next; src = src->next;
} }
/* Recorded => Only update 'changed' values */
#if 0 /*TODO: Pixel shaders*/ if (This->pixelShader != targetStateBlock->pixelShader) {
if (This->set.pixelShader && This->pixelShader != pDeviceImpl->stateBlock->pixelShader) {
TRACE("Updating pixel shader to %p\n", pDeviceImpl->stateBlock->pixelShader);
This->pixelShader = targetStateBlock->pixelShader; This->pixelShader = targetStateBlock->pixelShader;
TRACE("Updating pixrl shader to %p\n", targetStateBlock->pixelShader);
}
/* Pixel Shader Constants */
for (i = 0; i < MAX_PSHADER_CONSTANTS; ++i) {
if (This->set.pixelShaderConstants[i]) {
TRACE("Setting %p from %p %d to %f\n", This, targetStateBlock, i, targetStateBlock->pixelShaderConstantF[i * 4 + 1]);
This->pixelShaderConstantB[i] = targetStateBlock->pixelShaderConstantB[i];
This->pixelShaderConstantF[i * 4] = targetStateBlock->pixelShaderConstantF[i * 4];
This->pixelShaderConstantF[i * 4 + 1] = targetStateBlock->pixelShaderConstantF[i * 4 + 1];
This->pixelShaderConstantF[i * 4 + 2] = targetStateBlock->pixelShaderConstantF[i * 4 + 2];
This->pixelShaderConstantF[i * 4 + 3] = targetStateBlock->pixelShaderConstantF[i * 4 + 3];
This->pixelShaderConstantI[i * 4] = targetStateBlock->pixelShaderConstantI[i * 4];
This->pixelShaderConstantI[i * 4 + 1] = targetStateBlock->pixelShaderConstantI[i * 4 + 1];
This->pixelShaderConstantI[i * 4 + 2] = targetStateBlock->pixelShaderConstantI[i * 4 + 2];
This->pixelShaderConstantI[i * 4 + 3] = targetStateBlock->pixelShaderConstantI[i * 4 + 3];
This->pixelShaderConstantT[i] = targetStateBlock->pixelShaderConstantT[i];
}
} }
#endif
/* TODO: Pixel Shader Constants */
/* Others + Render & Texture */ /* Others + Render & Texture */
for (i = 1; i <= HIGHEST_TRANSFORMSTATE; i++) { for (i = 1; i <= HIGHEST_TRANSFORMSTATE; i++) {
...@@ -385,15 +399,30 @@ should really perform a delta so that only the changes get updated*/ ...@@ -385,15 +399,30 @@ should really perform a delta so that only the changes get updated*/
} }
#if 0 /*TODO: Pixel Shaders*/
if (/*TODO: 'magic' statetype, replace with BOOL This->blockType == D3DSBT_RECORDED || */ This->blockType == D3DSBT_ALL || This->blockType == D3DSBT_PIXELSTATE) { if (/*TODO: 'magic' statetype, replace with BOOL This->blockType == D3DSBT_RECORDED || */ This->blockType == D3DSBT_ALL || This->blockType == D3DSBT_PIXELSTATE) {
if (This->set.pixelShader && This->changed.pixelShader) /* Pixel Shader */
if (This->set.pixelShader && This->changed.pixelShader) {
IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader); IWineD3DDevice_SetPixelShader(pDevice, This->pixelShader);
}
/* TODO: Pixel Shader Constants */ /* Pixel Shader Constants */
for (i = 0; i < MAX_PSHADER_CONSTANTS; ++i) {
if (This->set.pixelShaderConstants[i] && This->changed.pixelShaderConstants[i]) {
switch (This->pixelShaderConstantT[i]) {
case WINESHADERCNST_FLOAT:
IWineD3DDevice_SetPixelShaderConstantF(pDevice, i, This->pixelShaderConstantF + i * 4, 1);
break;
case WINESHADERCNST_BOOL:
IWineD3DDevice_SetPixelShaderConstantB(pDevice, i, This->pixelShaderConstantB + i, 1);
break;
case WINESHADERCNST_INTEGER:
IWineD3DDevice_SetPixelShaderConstantI(pDevice, i, This->pixelShaderConstantI + i * 4, 1);
break;
}
}
}
} }
#endif
if (This->set.fvf && This->changed.fvf) { if (This->set.fvf && This->changed.fvf) {
IWineD3DDevice_SetFVF(pDevice, This->fvf); IWineD3DDevice_SetFVF(pDevice, This->fvf);
......
...@@ -873,6 +873,7 @@ typedef struct SAVEDSTATES { ...@@ -873,6 +873,7 @@ typedef struct SAVEDSTATES {
BOOL clipplane[MAX_CLIPPLANES]; BOOL clipplane[MAX_CLIPPLANES];
BOOL vertexDecl; BOOL vertexDecl;
BOOL pixelShader; BOOL pixelShader;
BOOL pixelShaderConstants[MAX_PSHADER_CONSTANTS];
BOOL vertexShader; BOOL vertexShader;
BOOL vertexShaderConstants[MAX_VSHADER_CONSTANTS]; BOOL vertexShaderConstants[MAX_VSHADER_CONSTANTS];
} SAVEDSTATES; } SAVEDSTATES;
...@@ -903,7 +904,7 @@ struct IWineD3DStateBlockImpl ...@@ -903,7 +904,7 @@ struct IWineD3DStateBlockImpl
/* Vertex Shader Declaration */ /* Vertex Shader Declaration */
IWineD3DVertexDeclaration *vertexDecl; IWineD3DVertexDeclaration *vertexDecl;
IWineD3DVertexShader *vertexShader; /* @TODO: Replace void * with IWineD3DVertexShader * */ IWineD3DVertexShader *vertexShader;
/* Vertex Shader Constants */ /* Vertex Shader Constants */
BOOL vertexShaderConstantB[MAX_VSHADER_CONSTANTS]; BOOL vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
...@@ -942,12 +943,13 @@ struct IWineD3DStateBlockImpl ...@@ -942,12 +943,13 @@ struct IWineD3DStateBlockImpl
WINED3DMATERIAL material; WINED3DMATERIAL material;
/* Pixel Shader */ /* Pixel Shader */
IWineD3DPixelShader *pixelShader; /* TODO: Replace void * with IWineD3DPixelShader */ IWineD3DPixelShader *pixelShader;
/* Pixel Shader Constants */ /* Pixel Shader Constants */
BOOL pixelShaderConstantB[MAX_PSHADER_CONSTANTS]; BOOL pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
UINT pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4]; INT pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
float pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4]; float pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
WINESHADERCNST pixelShaderConstantT[MAX_PSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
/* Indexed Vertex Blending */ /* Indexed Vertex Blending */
D3DVERTEXBLENDFLAGS vertex_blend; D3DVERTEXBLENDFLAGS vertex_blend;
...@@ -1172,21 +1174,22 @@ extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl; ...@@ -1172,21 +1174,22 @@ extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
* IDirect3DPixelShader implementation structure * IDirect3DPixelShader implementation structure
*/ */
typedef struct IWineD3DPixelShaderImpl { typedef struct IWineD3DPixelShaderImpl {
/* IUnknown parts*/ /* IUnknown parts */
const IWineD3DPixelShaderVtbl *lpVtbl; const IWineD3DPixelShaderVtbl *lpVtbl;
LONG ref; /* Note: Ref counting not required */ LONG ref; /* Note: Ref counting not required */
IUnknown *parent; IUnknown *parent;
IWineD3DDeviceImpl *wineD3DDevice; IWineD3DDeviceImpl *wineD3DDevice;
/* IWineD3DPixelShaderImpl */ /* IWineD3DPixelShaderImpl */
CONST DWORD *function; CONST DWORD *function;
UINT functionLength; UINT functionLength;
DWORD version;
/* run time data */
PSHADERDATA *data;
#if 0 /* needs reworking */ #if 0 /* needs reworking */
/* run time datas */
PSHADERDATA* data;
PSHADERINPUTDATA input; PSHADERINPUTDATA input;
PSHADEROUTPUTDATA output; PSHADEROUTPUTDATA output;
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment