Commit 588434c4 by Austin Kinross Committed by Jamie Madill

Prevent D3D11 Feature Level 9_3 from sampling from SV_Position in Pixel Shaders

D3D11 FL9_3, like Shader Model 2.0 in D3D9, doesn't support reading from SV_Position in the pixel shader. We have to reconstruct gl_FragCoord using dx_ViewCoords instead. Change-Id: I7e898038d210d73a9d224dcc18b033e5cd4a56f5 Reviewed-on: https://chromium-review.googlesource.com/234277Tested-by: 's avatarAustin Kinross <aukinros@microsoft.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 492a7e43
...@@ -871,12 +871,14 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, InfoLog &infoLog, ...@@ -871,12 +871,14 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, InfoLog &infoLog,
{ {
pixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n"; pixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n";
if (shaderModel >= 4) // Certain Shader Models (4_0+ and 3_0) allow reading from dx_Position in the pixel shader.
// Other Shader Models (4_0_level_9_3 and 2_x) don't support this, so we emulate it using dx_ViewCoords.
if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "")
{ {
pixelHLSL += " gl_FragCoord.x = input.dx_Position.x;\n" pixelHLSL += " gl_FragCoord.x = input.dx_Position.x;\n"
" gl_FragCoord.y = input.dx_Position.y;\n"; " gl_FragCoord.y = input.dx_Position.y;\n";
} }
else if (shaderModel >= 3) else if (shaderModel == 3)
{ {
pixelHLSL += " gl_FragCoord.x = input.dx_Position.x + 0.5;\n" pixelHLSL += " gl_FragCoord.x = input.dx_Position.x + 0.5;\n"
" gl_FragCoord.y = input.dx_Position.y + 0.5;\n"; " gl_FragCoord.y = input.dx_Position.y + 0.5;\n";
......
...@@ -76,6 +76,9 @@ class RendererD3D : public Renderer ...@@ -76,6 +76,9 @@ class RendererD3D : public Renderer
bool isDeviceLost() const override; bool isDeviceLost() const override;
std::string getVendorString() const override; std::string getVendorString() const override;
virtual int getMinorShaderModel() const = 0;
virtual std::string getShaderModelSuffix() const = 0;
DisplayImpl *createDisplay() override; DisplayImpl *createDisplay() override;
// Direct3D Specific methods // Direct3D Specific methods
......
...@@ -114,6 +114,8 @@ class Renderer11 : public RendererD3D ...@@ -114,6 +114,8 @@ class Renderer11 : public RendererD3D
virtual bool getPostSubBufferSupport() const; virtual bool getPostSubBufferSupport() const;
virtual int getMajorShaderModel() const; virtual int getMajorShaderModel() const;
int getMinorShaderModel() const override;
std::string getShaderModelSuffix() const override;
virtual int getMinSwapInterval() const; virtual int getMinSwapInterval() const;
virtual int getMaxSwapInterval() const; virtual int getMaxSwapInterval() const;
...@@ -247,8 +249,6 @@ class Renderer11 : public RendererD3D ...@@ -247,8 +249,6 @@ class Renderer11 : public RendererD3D
void initializeDevice(); void initializeDevice();
void releaseDeviceResources(); void releaseDeviceResources();
int getMinorShaderModel() const;
std::string getShaderModelSuffix() const;
void release(); void release();
RenderStateCache mStateCache; RenderStateCache mStateCache;
......
...@@ -2383,6 +2383,16 @@ int Renderer9::getMajorShaderModel() const ...@@ -2383,6 +2383,16 @@ int Renderer9::getMajorShaderModel() const
return D3DSHADER_VERSION_MAJOR(mDeviceCaps.PixelShaderVersion); return D3DSHADER_VERSION_MAJOR(mDeviceCaps.PixelShaderVersion);
} }
int Renderer9::getMinorShaderModel() const
{
return D3DSHADER_VERSION_MINOR(mDeviceCaps.PixelShaderVersion);
}
std::string Renderer9::getShaderModelSuffix() const
{
return "";
}
DWORD Renderer9::getCapsDeclTypes() const DWORD Renderer9::getCapsDeclTypes() const
{ {
return mDeviceCaps.DeclTypes; return mDeviceCaps.DeclTypes;
......
...@@ -117,6 +117,9 @@ class Renderer9 : public RendererD3D ...@@ -117,6 +117,9 @@ class Renderer9 : public RendererD3D
virtual bool getPostSubBufferSupport() const; virtual bool getPostSubBufferSupport() const;
virtual int getMajorShaderModel() const; virtual int getMajorShaderModel() const;
int getMinorShaderModel() const override;
std::string getShaderModelSuffix() const override;
DWORD getCapsDeclTypes() const; DWORD getCapsDeclTypes() const;
virtual int getMinSwapInterval() const; virtual int getMinSwapInterval() const;
virtual int getMaxSwapInterval() const; virtual int getMaxSwapInterval() const;
......
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