From 9b0b803b4769c80c18af63b48f60688b1b389d42 Mon Sep 17 00:00:00 2001 From: Oliver Stieber Date: Wed, 17 Aug 2005 10:27:01 +0000 Subject: [PATCH] Add support for vertex shader constants to the stateblock. --- dlls/wined3d/device.c | 110 ++++++++++++++++++++++++++++----- dlls/wined3d/stateblock.c | 13 ++-- dlls/wined3d/wined3d_private.h | 7 +++ 3 files changed, 111 insertions(+), 19 deletions(-) diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 275882e31f0..17fe5cd37ac 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -3457,7 +3457,6 @@ HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShader(IWineD3DDevice *iface, IWineD3 * TODO: merge HAL shaders context switching from prototype */ return D3D_OK; - } HRESULT WINAPI IWineD3DDeviceImpl_GetVertexShader(IWineD3DDevice *iface, IWineD3DVertexShader** ppShader) { @@ -3469,43 +3468,126 @@ HRESULT WINAPI IWineD3DDeviceImpl_GetVertexShader(IWineD3DDevice *iface, IWineD3 return D3D_OK; } -HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantB(IWineD3DDevice *iface, UINT StartRegister, CONST BOOL *pConstantData, UINT BoolCount) { - IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; +#define GET_SHADER_CONSTANT(_vertexshaderconstant, _count, _sizecount) \ +int count = min(_count, MAX_VSHADER_CONSTANTS - (StartRegister + 1)); \ +if (NULL == pConstantData || count < 0 /* || _count != count */ ) \ + return D3DERR_INVALIDCALL; \ +memcpy(pConstantData, This->updateStateBlock->_vertexshaderconstant + (StartRegister * _sizecount), count * (sizeof(*pConstantData) * _sizecount)); - TRACE("(%p) : stub\n", This); +#define SET_SHADER_CONSTANT(_vertexshaderconstant, _count, _sizecount) \ +int count = min(_count, MAX_VSHADER_CONSTANTS - (StartRegister + 1)); \ +if (NULL == pConstantData || count < 0 /* || _count != count */ ) \ + return D3DERR_INVALIDCALL; \ +memcpy(This->updateStateBlock->_vertexshaderconstant + (StartRegister * _sizecount), pConstantData, count * (sizeof(*pConstantData) * _sizecount)); \ +This->updateStateBlock->changed.vertexShader = TRUE; \ +This->updateStateBlock->set.vertexShader = TRUE; + +HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantB(IWineD3DDevice *iface, UINT StartRegister, CONST BOOL *pConstantData, UINT BoolCount){ + IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; + static BOOL showFixmes = TRUE; + SET_SHADER_CONSTANT(vertexShaderConstantB, BoolCount, 1); +#if 0 /* TODO: a bitmasp to say which constant type we should load */ + memset(This->updateStateBlock->vsibfBitmap + StartRegister, WINESHADER_CONSTANTB, BoolCount); +#endif + /* clean out the other constants? */ + if(showFixmes || TRUE) { + FIXME("(%p) : stub\n", This); + showFixmes = FALSE; + } return D3D_OK; } -HRESULT WINAPI IWineD3DDeviceImpl_GetVertexShaderConstantB(IWineD3DDevice *iface, UINT StartRegister, BOOL *pConstantData, UINT BoolCount) { +HRESULT WINAPI IWineD3DDeviceImpl_GetVertexShaderConstantB(IWineD3DDevice *iface, UINT StartRegister, BOOL *pConstantData, UINT BoolCount){ IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; - TRACE("(%p) : stub\n", This); + static BOOL showFixmes = TRUE; +#if 0 /* TODO: a bitmasp to say which constant type we should load */ + for (i = 0; i < BoolCount; i++ ) { + if (This->updateStateBlock->vsibfBitmap[StartRegister + i] != WINESHADER_CONSTANTB) { + /* the constant for this register isn't a boolean */ + return D3DERR_INVALIDCALL; + } + } +#endif + GET_SHADER_CONSTANT(vertexShaderConstantB, BoolCount, 1); + if(showFixmes || TRUE) { + FIXME("(%p) : stub\n", This); + showFixmes = FALSE; + } return D3D_OK; } -HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantI(IWineD3DDevice *iface, UINT StartRegister, CONST int *pConstantData, UINT Vector4iCount) { +HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantI(IWineD3DDevice *iface, UINT StartRegister, CONST int *pConstantData, UINT Vector4iCount){ IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; - TRACE("(%p) : stub\n", This); + static BOOL showFixmes = TRUE; +#if 0 /* TODO: a bitmasp to say which constant type we should load */ + memset(This->updateStateBlock->vsibfBitmap + StartRegister, WINESHADER_CONSTANTI, Vector4iCount); +#endif + SET_SHADER_CONSTANT(vertexShaderConstantI, Vector4iCount, 4); + /* clean out the other constants? */ + if(showFixmes || TRUE) { + FIXME("(%p) : stub\n", This); + showFixmes = FALSE; + } return D3D_OK; } -HRESULT WINAPI IWineD3DDeviceImpl_GetVertexShaderConstantI(IWineD3DDevice *iface, UINT StartRegister, int *pConstantData, UINT Vector4iCount) { +HRESULT WINAPI IWineD3DDeviceImpl_GetVertexShaderConstantI(IWineD3DDevice *iface, UINT StartRegister, int *pConstantData, UINT Vector4iCount){ IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; - TRACE("(%p) : stub\n", This); + static BOOL showFixmes = TRUE; +#if 0 /* TODO: a bitmap to say which constant type we should load */ + for (i = 0; i < Vector4iCount; i++ ) { + if (This->updateStateBlock->vsibfBitmap[StartRegister + i] != WINESHADER_CONSTANTI) { + /* the constant for this register isn't a boolean */ + return D3DERR_INVALIDCALL; + } + } +#endif + GET_SHADER_CONSTANT(vertexShaderConstantI, Vector4iCount, 4); + if(showFixmes || TRUE) { + FIXME("(%p) : stub\n", This); + showFixmes = FALSE; + } return D3D_OK; } -HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantF(IWineD3DDevice *iface, UINT StartRegister, CONST float *pConstantData, UINT Vector4fCount) { +HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantF(IWineD3DDevice *iface, UINT StartRegister, CONST float *pConstantData, UINT Vector4fCount){ IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; - TRACE("(%p) : stub\n", This); + static BOOL showFixmes = TRUE; +#if 0 /* TODO: a bitmasp to say which constant type we should load */ + memset(This->updateStateBlock->vsibfBitmap + StartRegister, WINESHADER_CONSTANTF, Vector4fCount); +#endif + SET_SHADER_CONSTANT(vertexShaderConstantF, Vector4fCount, 4); + /* clean out the other constants? */ + if(showFixmes) { + TRACE("(%p) : ConstantF isn't intergrated properly with the other constants.\n", This); + showFixmes = FALSE; + } return D3D_OK; } -HRESULT WINAPI IWineD3DDeviceImpl_GetVertexShaderConstantF(IWineD3DDevice *iface, UINT StartRegister, float *pConstantData, UINT Vector4fCount) { +HRESULT WINAPI IWineD3DDeviceImpl_GetVertexShaderConstantF(IWineD3DDevice *iface, UINT StartRegister, float *pConstantData, UINT Vector4fCount){ IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; - TRACE("(%p) : stub\n", This); + static BOOL showFixmes = TRUE; +#if 0 /* TODO: a bitmap to say which constant type we should load */ + for (i = 0; i < Vector4fCount; i++ ) { + if (This->updateStateBlock->vsibfBitmap[StartRegister + i] != WINESHADER_CONSTANTF) { + /* the constant for this register isn't a boolean */ + return D3DERR_INVALIDCALL; + } + } +#endif + GET_SHADER_CONSTANT(vertexShaderConstantF, Vector4fCount, 4); + if(showFixmes) { + TRACE("(%p) : ConstantF isn't intergrated properly with the other constants.\n", This); + showFixmes = FALSE; + } return D3D_OK; } +#undef SET_SHADER_CONSTANT +#undef GET_SHADER_CONSTANT + + HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShader(IWineD3DDevice *iface, IWineD3DPixelShader *pShader) { IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; TRACE("(%p) : stub\n", This); diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 5dc769ef2e7..b0def0a4a25 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -152,7 +152,7 @@ HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface){ PLIGHTINFOEL *src; /* Recorded => Only update 'changed' values */ - if (This->set.vertexShader && This->vertexShader != targetStateBlock->vertexShader) { + if (This->vertexShader != targetStateBlock->vertexShader) { This->vertexShader = targetStateBlock->vertexShader; TRACE("Updating vertex shader to %p\n", targetStateBlock->vertexShader); } @@ -342,11 +342,14 @@ should really perform a delta so that only the changes get updated*/ toDo = toDo->next; } -#if 0 /*TODO: VertexShaders*/ - if (This->set.vertexShader && This->changed.vertexShader) + if (This->changed.vertexShader) { IWineD3DDevice_SetVertexShader(pDevice, This->vertexShader); - /* TODO: Vertex Shader Constants */ -#endif + /* TODO: Vertex Shader Constants */ + IWineD3DDevice_SetVertexShaderConstantB(pDevice, 0 , This->vertexShaderConstantB , MAX_VSHADER_CONSTANTS); + IWineD3DDevice_SetVertexShaderConstantI(pDevice, 0 , This->vertexShaderConstantI , MAX_VSHADER_CONSTANTS); + IWineD3DDevice_SetVertexShaderConstantF(pDevice, 0 , This->vertexShaderConstantF , MAX_VSHADER_CONSTANTS); + } + } #if 0 /*TODO: Pixel Shaders*/ diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 69eeac5af8f..6be07eef4be 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -51,6 +51,8 @@ #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES #define MAX_LEVELS 256 +#define MAX_VSHADER_CONSTANTS 96 + /* Used for CreateStateBlock */ #define NUM_SAVEDPIXELSTATES_R 35 #define NUM_SAVEDPIXELSTATES_T 18 @@ -890,6 +892,11 @@ struct IWineD3DStateBlockImpl void *vertexShader; /* @TODO: Replace void * with IWineD3DVertexShader * */ + /* Vertex Shader Constants */ + BOOL vertexShaderConstantB[MAX_VSHADER_CONSTANTS]; + UINT vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4]; + float vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4]; + BOOL softwareVertexProcessing; /* Stream Source */