Skip to content

Commit

Permalink
Finished adding shader wave intrinsics (SM6.0) support. This is still…
Browse files Browse the repository at this point in the history
… experimental and requires DXC.
  • Loading branch information
stanard committed Mar 7, 2017
1 parent edca8be commit 0aebe74
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 1 addition & 3 deletions MiniEngine/Core/GraphicsCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@ static HRESULT EnableExperimentalShaderModels() {
return HRESULT_FROM_WIN32(GetLastError());
}

HRESULT hr = pD3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModelsID, nullptr, nullptr);
FreeLibrary(hRuntime);
return hr;
return pD3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModelsID, nullptr, nullptr);
}
#endif

Expand Down
17 changes: 17 additions & 0 deletions MiniEngine/ModelViewer/CompileSM6Test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
dxc.exe /D_WAVE_OP /Zi /E"main" /Vn"g_pModelViewerPS_SM6" /Tps_6_0 /Fh"ModelViewerPS_SM6.h" /nologo Shaders/ModelViewerPS.hlsl

copy ModelViewerPS_SM6.h ..\Build_VS14\x64\Debug\Output\ModelViewer\CompiledShaders
copy ModelViewerPS_SM6.h ..\Build_VS14\x64\Profile\Output\ModelViewer\CompiledShaders
copy ModelViewerPS_SM6.h ..\Build_VS14\x64\Release\Output\ModelViewer\CompiledShaders

dxc.exe /Zi /E"main" /Vn"g_pModelViewerVS_SM6" /Tvs_6_0 /Fh"ModelViewerVS_SM6.h" /nologo Shaders/ModelViewerVS.hlsl

copy ModelViewerVS_SM6.h ..\Build_VS14\x64\Debug\Output\ModelViewer\CompiledShaders
copy ModelViewerVS_SM6.h ..\Build_VS14\x64\Profile\Output\ModelViewer\CompiledShaders
copy ModelViewerVS_SM6.h ..\Build_VS14\x64\Release\Output\ModelViewer\CompiledShaders

dxc.exe /Zi /E"main" /Vn"g_pDepthViewerVS_SM6" /Tvs_6_0 /Fh"DepthViewerVS_SM6.h" /nologo Shaders/DepthViewerVS.hlsl

copy DepthViewerVS_SM6.h ..\Build_VS14\x64\Debug\Output\ModelViewer\CompiledShaders
copy DepthViewerVS_SM6.h ..\Build_VS14\x64\Profile\Output\ModelViewer\CompiledShaders
copy DepthViewerVS_SM6.h ..\Build_VS14\x64\Release\Output\ModelViewer\CompiledShaders
13 changes: 13 additions & 0 deletions MiniEngine/ModelViewer/ModelViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
#include "GameInput.h"
#include "./ForwardPlusLighting.h"

// To enable wave intrinsics, uncomment this macro and #define DXIL in Core/GraphcisCore.cpp.
// Run CompileSM6Test.bat to compile the relevant shaders with DXC.
//#define _WAVE_OP

#include "CompiledShaders/DepthViewerVS.h"
#include "CompiledShaders/DepthViewerPS.h"
#include "CompiledShaders/ModelViewerVS.h"
#include "CompiledShaders/ModelViewerPS.h"
#ifdef _WAVE_OP
#include "CompiledShaders/DepthViewerVS_SM6.h"
#include "CompiledShaders/ModelViewerVS_SM6.h"
#include "CompiledShaders/ModelViewerPS_SM6.h"
#endif
Expand Down Expand Up @@ -83,6 +86,7 @@ class ModelViewer : public GameCore::IGameApp
GraphicsPSO m_CutoutDepthPSO;
GraphicsPSO m_ModelPSO;
#ifdef _WAVE_OP
GraphicsPSO m_DepthWaveOpsPSO;
GraphicsPSO m_ModelWaveOpsPSO;
#endif
GraphicsPSO m_CutoutModelPSO;
Expand Down Expand Up @@ -180,6 +184,10 @@ void ModelViewer::Startup( void )
m_ModelPSO.Finalize();

#ifdef _WAVE_OP
m_DepthWaveOpsPSO = m_DepthPSO;
m_DepthWaveOpsPSO.SetVertexShader( g_pDepthViewerVS_SM6, sizeof(g_pDepthViewerVS_SM6) );
m_DepthWaveOpsPSO.Finalize();

m_ModelWaveOpsPSO = m_ModelPSO;
m_ModelWaveOpsPSO.SetVertexShader( g_pModelViewerVS_SM6, sizeof(g_pModelViewerVS_SM6) );
m_ModelWaveOpsPSO.SetPixelShader( g_pModelViewerPS_SM6, sizeof(g_pModelViewerPS_SM6) );
Expand Down Expand Up @@ -464,7 +472,12 @@ void ModelViewer::RenderScene( void )
ScopedTimer _prof(L"Opaque", gfxContext);
gfxContext.TransitionResource(g_SceneDepthBuffer, D3D12_RESOURCE_STATE_DEPTH_WRITE, true);
gfxContext.ClearDepth(g_SceneDepthBuffer);

#ifdef _WAVE_OP
gfxContext.SetPipelineState(EnableWaveOps ? m_DepthWaveOpsPSO : m_DepthPSO );
#else
gfxContext.SetPipelineState(m_DepthPSO);
#endif
gfxContext.SetDepthStencilTarget(g_SceneDepthBuffer.GetDSV());
gfxContext.SetViewportAndScissor(m_MainViewport, m_MainScissor);
RenderObjects(gfxContext, m_ViewProjMatrix, kOpaque );
Expand Down
2 changes: 1 addition & 1 deletion MiniEngine/ModelViewer/Shaders/ModelViewerPS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void AntiAliasSpecular( inout float3 texNormal, inout float gloss )
// Apply fresnel to modulate the specular albedo
void FSchlick( inout float3 specular, inout float3 diffuse, float3 lightDir, float3 halfVec )
{
float fresnel = pow(1.0 - dot(lightDir, halfVec), 5.0);
float fresnel = pow(1.0 - saturate(dot(lightDir, halfVec)), 5.0);
specular = lerp(specular, 1, fresnel);
diffuse = lerp(diffuse, 0, fresnel);
}
Expand Down

0 comments on commit 0aebe74

Please sign in to comment.