diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-12-07 13:31:06 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-07 13:31:06 -0800 |
| commit | 135eaff6b892fc91a398714ddcf7ef377cd4cccb (patch) | |
| tree | e69f30a4fadfdb834ea141c1ec9efc862ccc70d3 /tests/hlsl/dxsdk/DynamicShaderLinkageFX11 | |
| parent | b0c2423f00b910f2f4d5010e6a04114112e294fd (diff) | |
Change how buffers are emitted (#741)
* Change how buffers are emitted
This is a change with a lot of pieces, which can't always be separated out cleanly. I'm going to walk through them in what I hope is a logical order.
The main goal of this change was to allow arrays of structured buffers to translate to Vulkan. Consider two declarations of structured buffers in HLSL/Slang:
```hlsl
StructuredBuffer<X> single;
StructuredBuffer<Y> multiple[10];
```
The current translation logic was handling `single` by translating it into an *unnamed* GLSL `buffer` block like:
```glsl
layout(std430)
buffer _S1
{
X single[];
};
```
That syntax allows an expression like `single[i]` in Slang to be translated simply as `single[i]` in GLSL.
But that naive translating doesn't work for `multiple`, since we need to declare a array of blocks in GLSL, which requires giving the whole thing a name:
```glsl
layout(std430)
buffer _S2
{
Y _data[];
} multiple[10];
```
Now a reference to `multiple[i][j]` in Slang needs to become `multiple[i]._data[j]` in GLSL.
To avoid having way too many special cases around single structured buffers vs. arrays, it makes sense to allows emit things in the latter form, so that we instead lower `single` as:
```glsl
layout(std430)
buffer _S1
{
X _data[];
} single;
```
So that now a reference to `single[i]` becomes `single._data[i]` in GLSL.
Most of that can be handled in the standard library translation of the structured buffer indexing operations.
The only wrinkle there is that there were some *old* special-case instructions in the IR intended to handle buffer load/store operations (these were added back when I was trying to keep the "VM" path working). These aren't really needed to have structured-buffer operations work; they can be handled as ordinary functions as far as the stdlib is concerned. I removed the old instructions.
Along the way, it became clear that a few other cases follow the same pattern. Byte-addressed buffers are an obvious case. We were lowering HLSL/Slang:
```hlsl
ByteAddressBuffer b;
...
uint x = b.Load(0);
```
to GLSL like:
```glsl
layout(std430)
buffer _S1
{
uint b[];
};
...
uint x = b[0];
```
That logic would fail for arrays the same way that the structured buffer case was failing. The fix is the same: use named `buffer` blocks and then introduce an explicit `_data` field:
```glsl
layout(std430)
buffer _S1
{
uint _data[];
} b;
...
uint x = b._data[0];
```
Just like with structured buffers, all of the VK translation for operations on byte-addressed buffers can be implemented directly in teh stdlib, so once the emit logic was changed it was just a matter of adding `._data` to a bunch of VK tranlsations.
It turns out that arrays of constant buffers have more or less the same problem, and furthermore we have some problems with any code that directly uses the modern HLSL `ConstantBuffer<T>` type.
Note: the emit logic around constant buffers sometimes refers to "parameter groups" because that is being used in the compiler as a catch-all term for constant buffers, texture buffers, and parameter blocks.
The existing code was going out of its way to reproduce the way that constant buffer declarations are implicitly referenced in HLSL:
```hlsl
cbuffer C { float f; }
...
float tmp = f; // No reference to `C` here
```
This can be seen in the emit logic with the `isDerefBaseImplicit` function, which is used to take the internal IR representation for a reference to `f` (which is closer to the expression `(*C).f` or `C->f`) and leave off any reference to `C` so that we emit just `f`.
That kind of logic just flat out doesn't work in some important cases. Arrays of constant buffers are a clear one:
```hlsl
ConstantBuffer<X> cbArray[3];
...
X x = cbArray[0];
```
There is no way to translate that to an ordinary `cbuffer` declaration at all. The same problem can be created without arrays, though:
```hlsl
ConstantBuffer<X> singleCB;
...
X x = singleCB;
```
The current strategy for translating constant buffers was translating `singleCB` into a `cbuffer` declaration that reproduced the fields of `X` as its members, which just wouldn't work:
```hlsl
cbuffer singleCB
{
float f; // field of `X`
}
...
X x = singleCB; // ERROR: there is nothing named `singleCB` in this HLSL
```
The new strategy is more consistent. We still generate a `cbuffer` declaration for a single constant buffer, but we always give it a single field of the chosen element type:
```hlsl
cbuffer singleCB
{
X singleCB;
}
...
X x = singleCB; // this works fine!
```
And in the array case we generate code that uses the explicit `ConstantBuffer<T>` type:
```hlsl
ConstantBuffer<X> cbArray[3];
...
X x = cbArray[0];
```
The GLSL output is more complicated because unlike with HLSL there is no implicit conversion from a uniform block to its element type (there is no notion of an element type). The array case thus needs a `_data` field similar to what we do for structured buffers:
```glsl
layout(std140)
uniform _S3
{
X _data;
} cbArray[3];
...
X x = cbArray[0]._data;
```
And then the non-array case needs to have a similar `_data` field for consistency:
```glsl
layout(std140)
uniform _S1
{
X _data;
} singleCB;
...
X x = singleCB._data;
```
This is handled by inserting the necessary reference to `_data` whenever we dereference a constant buffer, either as part of a load instruction (loading from the whole CB as a pointer), or an `IRFieldAddress` instruction which forms a pointer into the CB (e.g., `&(singleCB->f)` becomes `singleCB._data.f`).
The current emit logic handles `ParameterBlock<X>` differently from `ConstantBuffer<X>`, but really only to allow parameter blocks to be explicitly named in the output, while constant buffers were left implicit by default. Thus the only difference was a legacy one (from back when trying to exactly reproduce the HLSL text we got as input was considered an important goal), and the new approach to emitting constant buffers would get rid of it.
I removed the separate logic for emitting `ParameterBlock<X>` and just let the handling for constant buffers deal with it.
Note that any resource types inside of a `ParameterBlock<X>` would have been moved out as part of legalization, so that a parameter block is 100% equivalent to a constant buffer when it comes time to emit code.
Unsurprisingly, changing the way we generate HLSL and GLSL output for all these buffer types meant that any tests that were directly comparing the output of `slangc` against `fxc`, `dxc`, or `glslang` broke.
The basic approach to fixing the breakage in GLSL tests was to update the GLSL baseline to reflect the new output startegy. In some cases I used macros to name the various `_S<digits>` temporaries so that future renaming will hopefully be easier (it would be great if we auto-generated temporary names with a bit more context). There was one GLSL test (`tests/bugs/vk-structured-buffer-binding`) that was using raw GLSL expected output, and this was changed to use a GLSL baseline to generate SPIR-V for comparison.
For HLSL tests we were sometimes running the same input file through `slangc` and `fxc`/`dxc`, and in these cases I macro-ized the various `cbuffer` declarations to generate different declarations depending on the compiler.
I completely dropped the tests coming from the D3D SDK because they aren't providing much coverage, and updating them would change them so far from the original code that the purported benefit (using a body of existing shaders) would be lost.
I also dropped the explicit matrix layout qualifiers in the `matrix-layout` test because the new output strategy breaks those for GLSL (you can't put matrix layout qualifiers on `struct` fields, and now the body of every constant buffer is inside a `struct`). This isn't as big of a loss as it seems, because our handling of those qualifiers wasn't really right to begin with. Slang users should only be setting the matrix layout mode globally (and we should probably switch to error out on the explicit qualifiers for now).
The other thing that got dropped is tests involving `packoffset` modifiers.
Slang already warns that it doesn't support these, and the way they were used in the test cases is actually misleading. For the binding/layout-related tests, the goal was to show that Slang reproduces the same layout as fxc, in which case explicitly enforcing a layout via `packoffset` seems like cheating (are we sure we enforced the layout fxc would have produced?). The real reason was that Slang used to emit explicit `packoffset` on *every* field of a `cbuffer` it would output, because of an `fxc` bug where you couldn't use `register` on textures/samplers declared inside a `cbuffer` unless *every* field in the `cbuffer` used a `register` or `packoffset` modifier. Slang hasn't required that behavior in a while because it now splits textures and samplers, and the one test case where we needed `packoffset` to work around the `fxc` bug in the baseline HLSL has been macro-ified even more to work around the bug.
The amount of churn in the test cases is unfortunate, but it continues to point at the weakness of any testing strategy that checks for exact equivalent between Slang's output and that of other compilers. We need to keep working to replace these tests with better alternatives.
In `check.cpp` there is logic to perform implicit dereferencing, so that if you write `obj.f` where `obj` is a `ConstantBuffer<X>` (or some other "pointer-like" type) and `f` is a field in `X`, then this effectively translates as `(*obj).f`. That is, we dereference the value of type `ConstantBuffer<X>` to get a value of type `X`, and then refer to the field of the `X` value.
There was a problem where the logic to insert that kind of implicit dereference operation was using a reference (`auto& type = ...`) for the type of the expression being dereferenced, and then clobbering it. This would mean that an expression of type `ConstantBuffer<X>` would have its type overwritten to be just `X` and then codegen would break later on.
I'm not sure how we haven't run into that before.
The `array-of-buffers` test case was added to confirm that we now support arrays of constant, structured, and byte-address buffers for both DXIL and SPIR-V output.
Okay, so that was a lot of stuff, but hopefully it is clear how this all works to make the output of the compiler more consistent and explicit, while also supporting the required new functionality.
* fixup: review feedback
Diffstat (limited to 'tests/hlsl/dxsdk/DynamicShaderLinkageFX11')
6 files changed, 0 insertions, 707 deletions
diff --git a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11.fx b/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11.fx deleted file mode 100644 index c72b98843..000000000 --- a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11.fx +++ /dev/null @@ -1,192 +0,0 @@ -//TEST_IGNORE_FILE: -//-------------------------------------------------------------------------------------- -// File: DynamicShaderLinkageFX11.fx -// -// The effect file for the DynamicShaderLinkageFX11 sample. -// -// Copyright (c) Microsoft Corporation. All rights reserved. -//-------------------------------------------------------------------------------------- - -#include "DynamicShaderLinkageFX11_VS.hlsl" -#include "DynamicShaderLinkageFX11_PS.hlsl" - -// -// Settings for static permutations. -// All of the pre-5.0 targets need static specialization -// since they don't support late binding. The below -// just selects a single specialization but you could -// create any number of them, each one representing -// a new shader with the interfaces compiled out -// due to the compile-time class references. -// - -#define StaticMaterial g_plasticTexturedMaterial -#define StaticAmbientLight g_ambientLight -#define StaticDirectLight g_directionalLight -#define StaticEnvironmentLight g_environmentLight - -technique11 FeatureLevel10 -{ - pass - { - SetRasterizerState(g_rasterizerState[g_fillMode]); - SetVertexShader(CompileShader(vs_4_0, - VSMain())); - SetPixelShader(CompileShader(ps_4_0, - PSMainUniform(StaticAmbientLight, - StaticDirectLight, - StaticEnvironmentLight, - StaticMaterial))); - } -} - -technique11 FeatureLevel10_1 -{ - pass - { - SetRasterizerState(g_rasterizerState[g_fillMode]); - SetVertexShader(CompileShader(vs_4_1, - VSMain())); - SetPixelShader(CompileShader(ps_4_1, - PSMainUniform(StaticAmbientLight, - StaticDirectLight, - StaticEnvironmentLight, - StaticMaterial))); - } -} - -// -// Variables for dynamic shader linkage. -// There are two variations here for dynamic usage. -// In the first we use the uniform entry point -// and pass in global interface variables. This -// creates a shader which refers to the global -// interface variables when running and we can bind -// concrete instances in our C++ code by using -// ID3DX11EffectInterfaceVariable::SetClassInstance. -// This approach works well when you have several -// independent variations and want to bind them -// individually in your C++ code, such as the -// different lighting and material parameters in -// this sample. -// - -iBaseLight g_abstractAmbientLighting; -iBaseLight g_abstractDirectLighting; -iBaseLight g_abstractEnvironmentLighting; -iBaseMaterial g_abstractMaterial; - -technique11 FeatureLevel11 -{ - pass - { - SetRasterizerState(g_rasterizerState[g_fillMode]); - SetVertexShader(CompileShader(vs_5_0, - VSMain())); - SetPixelShader(CompileShader(ps_5_0, - PSMainUniform(g_abstractAmbientLighting, - g_abstractDirectLighting, - g_abstractEnvironmentLighting, - g_abstractMaterial))); - } -} - -// -// In this second variation we use the non-uniform -// entry point so that we don't have to specify -// any interfaces when compiling the shader. We -// then reuse the compiled shader with different -// BindInterfaces calls so that all bindings are -// handled automatically by the effect runtime. -// Below we have multiple techniques where -// we've given a concrete binding for the material. -// Lighting parameters are left as interfaces for -// binding via effect variables, but could also -// be specified concretely if the number of variations -// is manageable. -// This approach works well for a small number of variations -// that are known in advance, as you can just list them -// in your effect and you don't need to do the -// binding work explicitly in your C++ code. -// - -VertexShader g_NonUniVS = CompileShader(vs_5_0, VSMain()); -PixelShader g_NonUniPS = CompileShader(ps_5_0, PSMainNonUniform()); - -technique11 FeatureLevel11_g_plasticMaterial -{ - pass - { - SetVertexShader(g_NonUniVS); - SetPixelShader(BindInterfaces(g_NonUniPS, - g_abstractAmbientLighting, - g_abstractDirectLighting, - g_abstractEnvironmentLighting, - g_plasticMaterial)); - } -} - -technique11 FeatureLevel11_g_plasticTexturedMaterial -{ - pass - { - SetVertexShader(g_NonUniVS); - SetPixelShader(BindInterfaces(g_NonUniPS, - g_abstractAmbientLighting, - g_abstractDirectLighting, - g_abstractEnvironmentLighting, - g_plasticTexturedMaterial)); - } -} - -technique11 FeatureLevel11_g_plasticLightingOnlyMaterial -{ - pass - { - SetVertexShader(g_NonUniVS); - SetPixelShader(BindInterfaces(g_NonUniPS, - g_abstractAmbientLighting, - g_abstractDirectLighting, - g_abstractEnvironmentLighting, - g_plasticLightingOnlyMaterial)); - } -} - -technique11 FeatureLevel11_g_roughMaterial -{ - pass - { - SetVertexShader(g_NonUniVS); - SetPixelShader(BindInterfaces(g_NonUniPS, - g_abstractAmbientLighting, - g_abstractDirectLighting, - g_abstractEnvironmentLighting, - g_roughMaterial)); - } -} - -technique11 FeatureLevel11_g_roughTexturedMaterial -{ - pass - { - SetVertexShader(g_NonUniVS); - SetPixelShader(BindInterfaces(g_NonUniPS, - g_abstractAmbientLighting, - g_abstractDirectLighting, - g_abstractEnvironmentLighting, - g_roughTexturedMaterial)); - } -} - -technique11 FeatureLevel11_g_roughLightingOnlyMaterial -{ - pass - { - SetVertexShader(g_NonUniVS); - SetPixelShader(BindInterfaces(g_NonUniPS, - g_abstractAmbientLighting, - g_abstractDirectLighting, - g_abstractEnvironmentLighting, - g_roughLightingOnlyMaterial)); - } -} diff --git a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_LightPSH.h b/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_LightPSH.h deleted file mode 100644 index 6f9a0f4d8..000000000 --- a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_LightPSH.h +++ /dev/null @@ -1,82 +0,0 @@ -//-------------------------------------------------------------------------------------- -// File: DynamicShaderLinkageFX11_LightPSH.h -// -// The pixel shader light header file for the DynamicShaderLinkageFX11 sample. -// -// Copyright (c) Microsoft Corporation. All rights reserved. -//-------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------- -// Interfaces -//-------------------------------------------------------------------------------------- -interface iBaseLight -{ - float3 IlluminateAmbient(float3 vNormal); - - float3 IlluminateDiffuse(float3 vNormal); - - float3 IlluminateSpecular(float3 vNormal, int specularPower ); - -}; - -//-------------------------------------------------------------------------------------- -// Classes -//-------------------------------------------------------------------------------------- -class cAmbientLight : iBaseLight -{ - float3 m_vLightColor; - bool m_bEnable; - - float3 IlluminateAmbient(float3 vNormal); - - float3 IlluminateDiffuse(float3 vNormal) - { - return (float3)0; - } - - float3 IlluminateSpecular(float3 vNormal, int specularPower ) - { - return (float3)0; - } -}; - -class cHemiAmbientLight : cAmbientLight -{ - // inherited float4 m_vLightColor is the SkyColor - float4 m_vGroundColor; - float4 m_vDirUp; - - float3 IlluminateAmbient(float3 vNormal); - -}; - -class cDirectionalLight : cAmbientLight -{ - // inherited float4 m_vLightColor is the LightColor - float4 m_vLightDir; - - float3 IlluminateDiffuse( float3 vNormal ); - - float3 IlluminateSpecular( float3 vNormal, int specularPower ); - -}; - -class cOmniLight : cAmbientLight -{ - float3 m_vLightPosition; - float radius; - - float3 IlluminateDiffuse( float3 vNormal ); - -}; - -class cSpotLight : cAmbientLight -{ - float3 m_vLightPosition; - float3 m_vLightDir; -}; - -class cEnvironmentLight : cAmbientLight -{ - float3 IlluminateSpecular( float3 vNormal, int specularPower ); -}; diff --git a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_MaterialPSH.h b/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_MaterialPSH.h deleted file mode 100644 index cd54a283d..000000000 --- a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_MaterialPSH.h +++ /dev/null @@ -1,103 +0,0 @@ -//-------------------------------------------------------------------------------------- -// File: DynamicShaderLinkageFX11_MaterialPSH.h -// -// The pixel shader material header file for the DynamicShaderLinkageFX11 sample. -// -// Copyright (c) Microsoft Corporation. All rights reserved. -//-------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------- -// Interfaces -//-------------------------------------------------------------------------------------- -interface iBaseMaterial -{ - float3 GetAmbientColor(float2 vTexcoord); - - float3 GetDiffuseColor(float2 vTexcoord); - - int GetSpecularPower(); - -}; - -//-------------------------------------------------------------------------------------- -// Classes -//-------------------------------------------------------------------------------------- -class cBaseMaterial : iBaseMaterial -{ - float3 m_vColor; - int m_iSpecPower; - - float3 GetAmbientColor(float2 vTexcoord) - { - return m_vColor; - } - - float3 GetDiffuseColor(float2 vTexcoord) - { - return (float3)m_vColor; - } - - int GetSpecularPower() - { - return m_iSpecPower; - } - -}; - -class cPlasticMaterial : cBaseMaterial -{ - -}; - -class cPlasticTexturedMaterial : cPlasticMaterial -{ - float3 GetAmbientColor(float2 vTexcoord); - - float3 GetDiffuseColor(float2 vTexcoord); - -}; - -class cPlasticLightingOnlyMaterial : cBaseMaterial -{ - float3 GetAmbientColor(float2 vTexcoord) - { - return (float3)1.0f; - } - - float3 GetDiffuseColor(float2 vTexcoord) - { - return (float3)1.0f; - } - -}; - -class cRoughMaterial : cBaseMaterial -{ - int GetSpecularPower() - { - return m_iSpecPower; - } -}; - -class cRoughTexturedMaterial : cRoughMaterial -{ - float3 GetAmbientColor(float2 vTexcoord); - - float3 GetDiffuseColor(float2 vTexcoord); - -}; - - -class cRoughLightingOnlyMaterial : cRoughMaterial -{ - float3 GetAmbientColor(float2 vTexcoord) - { - return (float3)1.0f; - } - - float3 GetDiffuseColor(float2 vTexcoord) - { - return (float3)1.0f; - } - -}; diff --git a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_PSBuffers.h b/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_PSBuffers.h deleted file mode 100644 index 3b4c528be..000000000 --- a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_PSBuffers.h +++ /dev/null @@ -1,152 +0,0 @@ -//-------------------------------------------------------------------------------------- -// File: DynamicShaderLinkageFX11_LightPSH.hlsl -// -// The pixel shader light source module file for the DynamicShaderLinkageFX11 sample. -// -// Copyright (c) Microsoft Corporation. All rights reserved. -//-------------------------------------------------------------------------------------- - -#include "DynamicShaderLinkageFX11_LightPSH.h" -#include "DynamicShaderLinkageFX11_MaterialPSH.h" - -//-------------------------------------------------------------------------------------- -// Constant Buffers -//-------------------------------------------------------------------------------------- -cbuffer cbPerFrame : register( b0 ) -{ - cAmbientLight g_ambientLight; - cHemiAmbientLight g_hemiAmbientLight; - cDirectionalLight g_directionalLight; - cEnvironmentLight g_environmentLight; - float4 g_vEyeDir; -}; - -cbuffer cbPerPrimitive : register( b1 ) -{ - cPlasticMaterial g_plasticMaterial; - cPlasticTexturedMaterial g_plasticTexturedMaterial; - cPlasticLightingOnlyMaterial g_plasticLightingOnlyMaterial; - cRoughMaterial g_roughMaterial; - cRoughTexturedMaterial g_roughTexturedMaterial; - cRoughLightingOnlyMaterial g_roughLightingOnlyMaterial; -}; - -//-------------------------------------------------------------------------------------- -// Textures and Samplers -//-------------------------------------------------------------------------------------- -Texture2D g_txDiffuse : register( t0 ); -Texture2D g_txNormalMap : register( t1 ); -TextureCube g_txEnvironmentMap : register( t2 ); - -SamplerState g_samLinear : register( s0 ) -{ - Filter = MIN_MAG_MIP_LINEAR; - AddressU = WRAP; - AddressV = WRAP; - AddressW = WRAP; -}; - -//-------------------------------------------------------------------------------------- -// Rasterization State -//-------------------------------------------------------------------------------------- -uint g_fillMode = 0; - -RasterizerState g_rasterizerState[2] -{ -{ - FillMode = SOLID; - MultisampleEnable = true; -}, -{ - FillMode = WIREFRAME; - MultisampleEnable = true; -} -}; - -//-------------------------------------------------------------------------------------- -// Lighting Class Methods -//-------------------------------------------------------------------------------------- -// Ambient Lighting Class Methods -float3 cAmbientLight::IlluminateAmbient(float3 vNormal) -{ - return m_vLightColor * m_bEnable; -} - -float3 cHemiAmbientLight::IlluminateAmbient(float3 vNormal) -{ - float thetha = (dot( vNormal, m_vDirUp.xyz ) + 1.0f) / 2.0f; - - return lerp( m_vGroundColor.xyz, m_vLightColor, thetha) * m_bEnable; -} - -// Directional Light class -float3 cDirectionalLight::IlluminateDiffuse( float3 vNormal ) -{ - float lambert = saturate(dot( vNormal, m_vLightDir.xyz )); - return ((float3)lambert * m_vLightColor * m_bEnable); -} - -float3 cDirectionalLight::IlluminateSpecular( float3 vNormal, int specularPower ) -{ - float3 H = -normalize(g_vEyeDir.xyz) + m_vLightDir.xyz; - float3 halfAngle = normalize( H ); - float specular = pow( max(0,dot( halfAngle, normalize(vNormal) )), specularPower ); - - return ((float3)specular * m_vLightColor * m_bEnable); -} - -// Omni Light Class -float3 cOmniLight::IlluminateDiffuse( float3 vNormal ) -{ - return (float3)0.0f; // TO DO! -} - -// Environment Lighting -float3 cEnvironmentLight::IlluminateSpecular( float3 vNormal, int specularPower ) -{ - // compute reflection vector taking into account a cheap fresnel falloff; - float3 N = normalize(vNormal); - float3 E = normalize(g_vEyeDir.xyz); - float3 R = reflect( E, N ); - float fresnel = 1 - dot( -E, N ); - fresnel = (fresnel * fresnel * fresnel ); - - float3 specular = g_txEnvironmentMap.Sample( g_samLinear, R ).xyz * fresnel; - - return (specular * (float3)m_bEnable); -// return ((float3)fresnel); - -} - -//-------------------------------------------------------------------------------------- -// Material Class Methods -//-------------------------------------------------------------------------------------- -// Plastic Material Methods -float3 cPlasticTexturedMaterial::GetAmbientColor(float2 vTexcoord) -{ - float4 vDiffuse = (float4)1.0f; - vDiffuse = g_txDiffuse.Sample( g_samLinear, vTexcoord ); - return m_vColor * vDiffuse.xyz; -} - -float3 cPlasticTexturedMaterial::GetDiffuseColor(float2 vTexcoord) -{ - float4 vDiffuse = (float4)1.0f; - vDiffuse = g_txDiffuse.Sample( g_samLinear, vTexcoord ); - return m_vColor * vDiffuse.xyz; -} - -// Rough Material Methods -float3 cRoughTexturedMaterial::GetAmbientColor(float2 vTexcoord) -{ - float4 vDiffuse = (float4)1.0f; - vDiffuse = g_txDiffuse.Sample( g_samLinear, vTexcoord ); - return m_vColor * vDiffuse.xyz; -} - -float3 cRoughTexturedMaterial::GetDiffuseColor(float2 vTexcoord) -{ - float4 vDiffuse = (float4)1.0f; - vDiffuse = g_txDiffuse.Sample( g_samLinear, vTexcoord ); - return m_vColor * vDiffuse.xyz; -} diff --git a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_ps.hlsl b/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_ps.hlsl deleted file mode 100644 index 55d206259..000000000 --- a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_ps.hlsl +++ /dev/null @@ -1,113 +0,0 @@ -//TEST_IGNORE_FILE: -//-------------------------------------------------------------------------------------- -// File: DynamicShaderLinkageFX11.psh -// -// The pixel shader header file for the DynamicShaderLinkageFX11 sample. -// -// Copyright (c) Microsoft Corporation. All rights reserved. -//-------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------- -// Header Includes -//-------------------------------------------------------------------------------------- -#include "DynamicShaderLinkageFX11_PSBuffers.h" - -//-------------------------------------------------------------------------------------- -// Input / Output structures -//-------------------------------------------------------------------------------------- -struct PS_INPUT -{ - float4 vPosition : SV_POSITION; - float3 vNormal : NORMAL; - float2 vTexcoord : TEXCOORD0; - float4 vMatrix : TEXCOORD1; -}; - -//-------------------------------------------------------------------------------------- -// Pixel Shader -//-------------------------------------------------------------------------------------- - -// This pixel shader uses several interfaces during its -// work. We show three different ways of providing interface -// bindings for the PS and those have two different -// entry points so we've separated the base PS code -// into a worker routine that's called by the entry -// points. Normally only one technique would be used -// and this layering of entry point and worker would -// not be necessary. -float4 PSMainWorker( iBaseLight ambientLighting, - iBaseLight directLighting, - iBaseLight environmentLighting, - iBaseMaterial material, - PS_INPUT Input ) -{ - // Compute the Ambient term - float3 Ambient = (float3)0.0f; - Ambient = material.GetAmbientColor( Input.vTexcoord ) * ambientLighting.IlluminateAmbient( Input.vNormal ); - - // Accumulate the Diffuse contribution - float3 Diffuse = (float3)0.0f; - - Diffuse += material.GetDiffuseColor( Input.vTexcoord ) * directLighting.IlluminateDiffuse( Input.vNormal ); - - // Compute the Specular contribution - float3 Specular = (float3)0.0f; - Specular += directLighting.IlluminateSpecular( Input.vNormal, material.GetSpecularPower() ); - Specular += environmentLighting.IlluminateSpecular( Input.vNormal, material.GetSpecularPower() ); - - // Accumulate the lighting with saturation - float3 Lighting = saturate( Ambient + Diffuse + Specular); - - return float4(Lighting,1.0f); -} - -// One way to provide bindings for shaders in Effects 11 is -// to use uniform interface parameters. As with non-interface -// uniform parameters you must specify a value for these -// parameters in your CompileShader invocations in the effect. -// You can provide concrete class instances if you want -// to statically specialize your shaders, such as for targets -// that don't support abstract interfaces; or you can provide -// other interfaces that you bind using effect variables. -// Both are shown in this sample's technique passes. -float4 PSMainUniform( uniform iBaseLight ambientLighting, - uniform iBaseLight directLighting, - uniform iBaseLight environmentLighting, - uniform iBaseMaterial material, - PS_INPUT Input ) : SV_Target -{ - return PSMainWorker(ambientLighting, - directLighting, - environmentLighting, - material, - Input); -} - -// Another way to use Effects 11 with interfaces is -// to have non-uniform parameters, which then are -// bound with a BindInterfaces in a technique pass. -// BindInterfaces gives concrete instances to use -// with a shader but does not do static specialization, -// it just saves information for the effect runtime -// to use when setting up the shader to run. -// This lets you share a single shader, compiled with -// interface usage, while still getting the convenience -// of declaring concrete bindings in the effect and -// not needed explicit binding in code via effect -// variable updates. If you have many different -// variations it may be simpler to use bindings -// through effect variables, as then you don't -// need to list every possible binding set in your -// techniques. -float4 PSMainNonUniform( iBaseLight ambientLighting, - iBaseLight directLighting, - iBaseLight environmentLighting, - iBaseMaterial material, - PS_INPUT Input ) : SV_Target -{ - return PSMainWorker(ambientLighting, - directLighting, - environmentLighting, - material, - Input); -} diff --git a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_vs.hlsl b/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_vs.hlsl deleted file mode 100644 index 4791e5786..000000000 --- a/tests/hlsl/dxsdk/DynamicShaderLinkageFX11/DynamicShaderLinkageFX11_vs.hlsl +++ /dev/null @@ -1,65 +0,0 @@ -//TEST_IGNORE_FILE: -//-------------------------------------------------------------------------------------- -// File: DynamicShaderLinkageFX11_VS.hlsl -// -// The vertex shader file for the DynamicShaderLinkageFX11 sample. -// -// Copyright (c) Microsoft Corporation. All rights reserved. -//-------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------- -// Globals -//-------------------------------------------------------------------------------------- -cbuffer cbPerObject : register( b0 ) -{ - float4x4 g_mWorldViewProjection : packoffset( c0 ); - float4x4 g_mWorld : packoffset( c4 ); -}; - -//-------------------------------------------------------------------------------------- -// Input / Output structures -//-------------------------------------------------------------------------------------- -struct VS_INPUT -{ - float4 vPosition : POSITION; - float3 vNormal : NORMAL; - float2 vTexcoord : TEXCOORD0; -}; - -struct VS_OUTPUT -{ - float4 vPosition : SV_POSITION; - float3 vNormal : NORMAL; - float2 vTexcoord0 : TEXCOORD0; - float4 vMatrix : TEXCOORD1; // DEBUG -}; - -//-------------------------------------------------------------------------------------- -// Vertex Shader -//-------------------------------------------------------------------------------------- -// We aliased signed vectors as a unsigned format. -// Need to recover signed values. The values 1.0 and 2.0 -// are slightly inaccurate here. -float3 R10G10B10A2_UNORM_TO_R32G32B32_FLOAT( in float3 vVec ) -{ - vVec *= 2.0f; - return vVec >= 1.0f ? ( vVec - 2.0f ) : vVec; -} - -VS_OUTPUT VSMain( VS_INPUT Input ) -{ - - VS_OUTPUT Output; - float3 tmpNormal; - - Output.vPosition = mul( Input.vPosition, g_mWorldViewProjection ); - - // Expand compressed vectors - tmpNormal = R10G10B10A2_UNORM_TO_R32G32B32_FLOAT( Input.vNormal ); - Output.vNormal = mul( tmpNormal, (float3x3)g_mWorld ); - - Output.vTexcoord0 = Input.vTexcoord; - - Output.vMatrix = (float4)g_mWorld[0]; // DEBUG - return Output; -} |
