d3d: Limit d3d8 and d3d9 vshader constants to 256.

DX10 cards support 512(ATI) or 1024(Nvidia) vertex shader constants in
GL. The dx9 DXCapsViewer shows that dx10 windows drivers only claim
256 constants on Windows, so we can and should do the same.
This commit is contained in:
Stefan Dösinger 2009-04-25 15:02:42 +02:00 committed by Alexandre Julliard
parent 7ded3afe93
commit 9f1731edb6
7 changed files with 45 additions and 4 deletions

View file

@ -601,6 +601,8 @@ struct IDirect3DVertexShader8Impl {
IWineD3DVertexShader *wineD3DVertexShader;
};
#define D3D8_MAX_VERTEX_SHADER_CONSTANTF 256
/* ------------------------ */
/* IDirect3DPixelShaderImpl */

View file

@ -359,6 +359,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface
if(pCaps->VertexShaderVersion > D3DVS_VERSION(1,1)){
pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
}
pCaps->MaxVertexShaderConst = min(D3D8_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
TRACE("Returning %p %p\n", This, pCaps);
return hrc;
@ -1998,6 +1999,12 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEV
HRESULT hr;
TRACE("(%p) : Relay\n", This);
if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
WARN("Trying to access %u constants, but d3d8 only supports %u\n",
Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
return D3DERR_INVALIDCALL;
}
EnterCriticalSection(&d3d8_cs);
hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
LeaveCriticalSection(&d3d8_cs);
@ -2009,6 +2016,12 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEV
HRESULT hr;
TRACE("(%p) : Relay\n", This);
if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
WARN("Trying to access %u constants, but d3d8 only supports %u\n",
Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
return D3DERR_INVALIDCALL;
}
EnterCriticalSection(&d3d8_cs);
hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
LeaveCriticalSection(&d3d8_cs);

View file

@ -265,6 +265,7 @@ static HRESULT WINAPI IDirect3D8Impl_GetDeviceCaps(LPDIRECT3D8 iface, UINT Ada
if(pCaps->VertexShaderVersion > D3DVS_VERSION(1,1)){
pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
}
pCaps->MaxVertexShaderConst = min(D3D8_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
TRACE("(%p) returning %p\n", This, pCaps);
return hrc;

View file

@ -497,6 +497,8 @@ typedef struct IDirect3DVertexShader9Impl {
LPDIRECT3DDEVICE9EX parentDevice;
} IDirect3DVertexShader9Impl;
#define D3D9_MAX_VERTEX_SHADER_CONSTANTF 256
/* --------------------- */
/* IDirect3DPixelShader9 */
/* --------------------- */

View file

@ -311,6 +311,8 @@ void filter_caps(D3DCAPS9* pCaps)
D3DPTEXTURECAPS_PROJECTED | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_VOLUMEMAP |
D3DPTEXTURECAPS_MIPMAP | D3DPTEXTURECAPS_MIPVOLUMEMAP | D3DPTEXTURECAPS_MIPCUBEMAP |
D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_VOLUMEMAP_POW2| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV;
pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
}
static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) {

View file

@ -192,6 +192,12 @@ HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9EX
HRESULT hr;
TRACE("(%p) : Relay\n", This);
if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
WARN("Trying to access %u constants, but d3d9 only supports %u\n",
Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
return D3DERR_INVALIDCALL;
}
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
LeaveCriticalSection(&d3d9_cs);
@ -202,6 +208,12 @@ HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9EX
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
HRESULT hr;
if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
WARN("Trying to access %u constants, but d3d9 only supports %u\n",
Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
return D3DERR_INVALIDCALL;
}
TRACE("(%p) : Relay\n", This);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);

View file

@ -115,9 +115,6 @@ static void vshader_set_limits(
This->baseShader.limits.attributes = 16;
This->baseShader.limits.packed_input = 0;
/* Must match D3DCAPS9.MaxVertexShaderConst: at least 256 for vs_2_0 */
This->baseShader.limits.constant_float = GL_LIMITS(vshader_constantsF);
switch (This->baseShader.reg_maps.shader_version)
{
case WINED3DVS_VERSION(1,0):
@ -129,8 +126,12 @@ static void vshader_set_limits(
This->baseShader.limits.packed_output = 0;
This->baseShader.limits.sampler = 0;
This->baseShader.limits.label = 0;
/* TODO: vs_1_1 has a minimum of 96 constants. What happens if a vs_1_1 shader is used
* on a vs_3_0 capable card that has 256 constants?
*/
This->baseShader.limits.constant_float = min(256, GL_LIMITS(vshader_constantsF));
break;
case WINED3DVS_VERSION(2,0):
case WINED3DVS_VERSION(2,1):
This->baseShader.limits.temporary = 12;
@ -140,6 +141,7 @@ static void vshader_set_limits(
This->baseShader.limits.packed_output = 0;
This->baseShader.limits.sampler = 0;
This->baseShader.limits.label = 16;
This->baseShader.limits.constant_float = min(256, GL_LIMITS(vshader_constantsF));
break;
case WINED3DVS_VERSION(3,0):
@ -150,6 +152,12 @@ static void vshader_set_limits(
This->baseShader.limits.packed_output = 12;
This->baseShader.limits.sampler = 4;
This->baseShader.limits.label = 16; /* FIXME: 2048 */
/* DX10 cards on Windows advertise a d3d9 constant limit of 256 even though they are capable
* of supporting much more(GL drivers advertise 1024). d3d9.dll and d3d8.dll clamp the
* wined3d-advertised maximum. Clamp the constant limit for <= 3.0 shaders to 256.s
* use constant buffers
*/
This->baseShader.limits.constant_float = min(256, GL_LIMITS(vshader_constantsF));
break;
default: This->baseShader.limits.temporary = 12;
@ -159,6 +167,7 @@ static void vshader_set_limits(
This->baseShader.limits.packed_output = 0;
This->baseShader.limits.sampler = 0;
This->baseShader.limits.label = 16;
This->baseShader.limits.constant_float = min(256, GL_LIMITS(vshader_constantsF));
FIXME("Unrecognized vertex shader version %#x\n",
This->baseShader.reg_maps.shader_version);
}