浏览代码

HDRenderPipeline: Change from 16x16 to 32x32 tile size for clustered

- Shader opaque compute doens't work
- Seems that if we disable clustered for forward, the fallback have some
conflict with tiling (not a use mode as the fallback is just a debug
mode but should not happen).
/Branch_Batching2
sebastienlagarde 8 年前
当前提交
20a72b30
共有 11 个文件被更改,包括 65 次插入51 次删除
  1. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  2. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TileLightLoopProducer.cs
  3. 3
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Resources/lightlistbuild-clustered.compute
  4. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute
  5. 62
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  6. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl
  7. 18
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl
  8. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl
  9. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
  10. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
  11. 2
      ProjectSettings/ProjectVersion.txt

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


public readonly GUIContent splitLightEvaluation = new GUIContent("Split light and reflection evaluation", "Toggle");
public readonly GUIContent bigTilePrepass = new GUIContent("Enable big tile prepass", "Toggle");
public readonly GUIContent clustered = new GUIContent("Enable clustered", "Toggle");
public readonly GUIContent disableTileAndCluster = new GUIContent("Disable Tile/clustered", "Toggle");
public readonly GUIContent disableDeferredShadingInCompute = new GUIContent("Disable deferred shading in compute", "Toggle");
public readonly GUIContent enableTileAndCluster = new GUIContent("Enable Tile/clustered", "Toggle");
public readonly GUIContent enableComputeLightEvaluation = new GUIContent("Enable Compute Light Evaluation", "Toggle");
// Sky Settings
public readonly GUIContent skyParams = new GUIContent("Sky Settings");

tilePass.debugViewTilesFlags = EditorGUILayout.MaskField("DebugView Tiles", tilePass.debugViewTilesFlags, styles.tileLightLoopDebugTileFlagStrings);
tilePass.enableSplitLightEvaluation = EditorGUILayout.Toggle(styles.splitLightEvaluation, tilePass.enableSplitLightEvaluation);
tilePass.disableTileAndCluster = EditorGUILayout.Toggle(styles.disableTileAndCluster, tilePass.disableTileAndCluster);
tilePass.disableDeferredShadingInCompute = EditorGUILayout.Toggle(styles.disableDeferredShadingInCompute, tilePass.disableDeferredShadingInCompute);
tilePass.enableTileAndCluster = EditorGUILayout.Toggle(styles.enableTileAndCluster, tilePass.enableTileAndCluster);
tilePass.enableComputeLightEvaluation = EditorGUILayout.Toggle(styles.enableComputeLightEvaluation, tilePass.enableComputeLightEvaluation);
if (EditorGUI.EndChangeCheck())
{

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TileLightLoopProducer.cs


[Serializable]
public class TileSettings
{
public bool enableDrawLightBoundsDebug;
public bool disableTileAndCluster; // For debug / test
public bool disableDeferredShadingInCompute;
public bool enableTileAndCluster; // For debug / test
public bool enableSplitLightEvaluation;
public bool enableComputeLightEvaluation;

public static TileSettings defaultSettings = new TileSettings
{
enableDrawLightBoundsDebug = false,
disableTileAndCluster = false,
disableDeferredShadingInCompute = true,
enableTileAndCluster = true,
enableSplitLightEvaluation = true,
enableComputeLightEvaluation = false,

3
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Resources/lightlistbuild-clustered.compute


#pragma kernel TileLightListGen_DepthRT_MSAA_SrcBigTile LIGHTLISTGEN=TileLightListGen_DepthRT_MSAA_SrcBigTile ENABLE_DEPTH_TEXTURE_BACKPLANE MSAA_ENABLED USE_TWO_PASS_TILED_LIGHTING
#pragma kernel ClearAtomic
#define TILE_SIZE_CLUSTERED 16
#include "ShaderLibrary/common.hlsl"
#include "../ShaderBase.hlsl"
#include "../TilePass.cs.hlsl"

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute


#define LIGHTLOOP_TILE_DIRECT 1
#define LIGHTLOOP_TILE_INDIRECT 1
#define LIGHTLOOP_TILE_ALL 1
#define USE_FPTL_LIGHTLIST 1
//-------------------------------------------------------------------------------------
// Include

62
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


// enable unity's original left-hand shader camera space (right-hand internally in unity).
public static int USE_LEFTHAND_CAMERASPACE = 1;
public static int TILE_SIZE_FPTL = 16;
public static int TILE_SIZE_CLUSTERED = 32;
// flags
public static int IS_CIRCULAR_SPOT_SHAPE = 1;
public static int HAS_COOKIE_TEXTURE = 2;

Material m_SingleDeferredMaterialSRT = null;
Material m_SingleDeferredMaterialMRT = null;
const int k_TileSize = 16;
#if (SHADOWS_ENABLED)
// shadow related stuff
FrameId m_FrameId;

#endif
int GetNumTileX(Camera camera)
int GetNumTileFtplX(Camera camera)
{
return (camera.pixelWidth + (LightDefinitions.TILE_SIZE_FPTL - 1)) / LightDefinitions.TILE_SIZE_FPTL;
}
int GetNumTileFtplY(Camera camera)
{
return (camera.pixelHeight + (LightDefinitions.TILE_SIZE_FPTL - 1)) / LightDefinitions.TILE_SIZE_FPTL;
}
int GetNumTileClusteredX(Camera camera)
return (camera.pixelWidth + (k_TileSize - 1)) / k_TileSize;
return (camera.pixelWidth + (LightDefinitions.TILE_SIZE_CLUSTERED - 1)) / LightDefinitions.TILE_SIZE_CLUSTERED;
int GetNumTileY(Camera camera)
int GetNumTileClusteredY(Camera camera)
return (camera.pixelHeight + (k_TileSize - 1)) / k_TileSize;
return (camera.pixelHeight + (LightDefinitions.TILE_SIZE_CLUSTERED - 1)) / LightDefinitions.TILE_SIZE_CLUSTERED;
}
TileLightLoopProducer.TileSettings m_PassSettings;

public override void AllocResolutionDependentBuffers(int width, int height)
{
var nrTilesX = (width + k_TileSize - 1) / k_TileSize;
var nrTilesY = (height + k_TileSize - 1) / k_TileSize;
var nrTilesX = (width + LightDefinitions.TILE_SIZE_FPTL - 1) / LightDefinitions.TILE_SIZE_FPTL;
var nrTilesY = (height + LightDefinitions.TILE_SIZE_FPTL - 1) / LightDefinitions.TILE_SIZE_FPTL;
var nrTiles = nrTilesX * nrTilesY;
const int capacityUShortsPerTile = 32;
const int dwordsPerTile = (capacityUShortsPerTile + 1) >> 1; // room for 31 lights and a nrLights value.

cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, "g_logBaseBuffer", s_PerTileLogBaseTweak);
}
var numTilesX = GetNumTileX(camera);
var numTilesY = GetNumTileY(camera);
var numTilesX = GetNumTileClusteredX(camera);
var numTilesY = GetNumTileClusteredY(camera);
cmd.DispatchCompute(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, numTilesX, numTilesY, 1);
}

var h = camera.pixelHeight;
var numTilesX = GetNumTileX(camera);
var numTilesY = GetNumTileY(camera);
var numBigTilesX = (w + 63) / 64;
var numBigTilesY = (h + 63) / 64;

cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_vLightList", s_LightList);
if (m_PassSettings.enableBigTilePrepass)
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_vBigTileLightList", s_BigTileLightList);
var numTilesX = GetNumTileFtplX(camera);
var numTilesY = GetNumTileFtplY(camera);
cmd.DispatchCompute(buildPerTileLightListShader, s_GenListPerTileKernel, numTilesX, numTilesY, 1);
}

SetGlobalBuffer("_ShadowDatas", s_shadowDatas);
SetGlobalVectorArray("_DirShadowSplitSpheres", m_lightList.directionalShadowSplitSphereSqr);
SetGlobalInt("_NumTileX", GetNumTileX(camera));
SetGlobalInt("_NumTileY", GetNumTileY(camera));
SetGlobalInt("_NumTileFtplX", GetNumTileFtplX(camera));
SetGlobalInt("_NumTileFtplY", GetNumTileFtplY(camera));
SetGlobalInt("_NumTileClusteredX", GetNumTileClusteredX(camera));
SetGlobalInt("_NumTileClusteredY", GetNumTileClusteredY(camera));
if (m_PassSettings.enableBigTilePrepass)
SetGlobalBuffer("g_vBigTileLightList", s_BigTileLightList);

}
#endif
using (new Utilities.ProfilingSample(m_PassSettings.disableTileAndCluster ? "SinglePass - Deferred Lighting Pass" : "TilePass - Deferred Lighting Pass", renderContext))
using (new Utilities.ProfilingSample(m_PassSettings.enableTileAndCluster ? "TilePass - Deferred Lighting Pass" : "SinglePass - Deferred Lighting Pass", renderContext))
{
var cmd = new CommandBuffer();

// Must be done after setting up the compute shader above.
SetupRenderingForDebug(lightDebugSettings);
if (m_PassSettings.disableTileAndCluster)
if (!m_PassSettings.enableTileAndCluster)
{
// This is a debug brute force renderer to debug tile/cluster which render all the lights
if (outputSplitLightingForSSS)

}
else
{
if (!m_PassSettings.disableDeferredShadingInCompute)
if (m_PassSettings.enableComputeLightEvaluation)
int w = camera.pixelWidth;
int h = camera.pixelHeight;
int numTilesX = GetNumTileX(camera);
int numTilesY = GetNumTileY(camera);
// Pass global parameters to compute shader
// TODO: get rid of this by making global parameters visible to compute shaders
BindGlobalParams(cmd, shadeOpaqueShader, kernel, camera, renderContext);

cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_SkyTexture", skyTexture ? skyTexture : m_DefaultTexture2DArray);
// Since we need the stencil test, the compute path does not currently support SSS.
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "combinedLightingUAV", colorBuffers[0]);
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "combinedLightingUAV", colorBuffers[0]);
int w = camera.pixelWidth;
int h = camera.pixelHeight;
int numTilesX = bUseClusteredForDeferred ? GetNumTileClusteredX(camera) : GetNumTileFtplX(camera);
int numTilesY = bUseClusteredForDeferred ? GetNumTileClusteredY(camera) : GetNumTileFtplY(camera);
cmd.DispatchCompute(shadeOpaqueShader, kernel, numTilesX, numTilesY, 1);
}
else

var cmd = new CommandBuffer();
if (m_PassSettings.disableTileAndCluster)
if (!m_PassSettings.enableTileAndCluster)
{
cmd.name = "Forward pass";
cmd.EnableShaderKeyword("LIGHTLOOP_SINGLE_PASS");

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl


#define MAX_NR_BIGTILE_LIGHTS_PLUSONE (512)
#define VIEWPORT_SCALE_Z (1)
#define USE_LEFTHAND_CAMERASPACE (1)
#define TILE_SIZE_FPTL (16)
#define TILE_SIZE_CLUSTERED (32)
#define IS_CIRCULAR_SPOT_SHAPE (1)
#define HAS_COOKIE_TEXTURE (2)
#define IS_BOX_PROJECTED (4)

18
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl


#include "TilePass.cs.hlsl"
uint _NumTileX;
uint _NumTileY;
// For FPTL
uint _NumTileFtplX;
uint _NumTileFtplY;
#define TILE_SIZE 16 // This is fixed
#define DWORD_PER_TILE 16 // See dwordsPerTile in TilePass.cs, we have roomm for 31 lights and a number of light value all store on 16 bit (ushort)
#ifdef USE_FPTL_LIGHTLIST
#define TILE_SIZE TILE_SIZE_FPTL
#endif
// Don't do a "#else" so we can catch error if including call don't setup thing correctly
#ifdef USE_CLUSTERED_LIGHTLIST
#define TILE_SIZE TILE_SIZE_CLUSTERED
#endif
#define TILE_SIZE_CLUSTERED 16
#define DWORD_PER_TILE 16 // See dwordsPerTile in TilePass.cs, we have roomm for 31 lights and a number of light value all store on 16 bit (ushort)
// these uniforms are only needed for when OPAQUES_ONLY is NOT defined
// but there's a problem with our front-end compilation of compute shaders with multiple kernels causing it to error

//#endif
//#ifdef USE_CLUSTERED_LIGHTLIST
uint _NumTileClusteredX;
uint _NumTileClusteredY;
StructuredBuffer<uint> g_vLayeredOffsetsBuffer; // don't support Buffer yet in unity
StructuredBuffer<float> g_logBaseBuffer; // don't support Buffer yet in unity
//#endif

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl


// Calculate the offset in global light index light for current light category
int GetTileOffset(PositionInputs posInput, uint lightCategory)
{
uint2 tileIndex = posInput.unPositionSS / TILE_SIZE;
return (tileIndex.y + lightCategory * _NumTileY) * _NumTileX + tileIndex.x;
uint2 tileIndex = posInput.unPositionSS / TILE_SIZE_FPTL;
return (tileIndex.y + lightCategory * _NumTileFtplY) * _NumTileFtplX + tileIndex.x;
}
void GetCountAndStartTile(PositionInputs posInput, uint lightCategory, out uint start, out uint lightCount)

float logBase = g_fClustBase;
if (g_isLogBaseBufferEnabled)
{
logBase = g_logBaseBuffer[tileIndex.y * _NumTileX + tileIndex.x];
logBase = g_logBaseBuffer[tileIndex.y * _NumTileClusteredX + tileIndex.x];
const int idx = ((lightCategory * nrClusters + clustIdx) * _NumTileY + tileIndex.y) * _NumTileX + tileIndex.x;
const int idx = ((lightCategory * nrClusters + clustIdx) * _NumTileClusteredY + tileIndex.y) * _NumTileClusteredX + tileIndex.x;
uint dataPair = g_vLayeredOffsetsBuffer[idx];
start = dataPair & 0x7ffffff;
lightCount = (dataPair >> 27) & 31;

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs


public float subsurfaceRadius;
public float thickness;
public int subsurfaceProfile;
public bool enableTransmission;
public bool enableTransmission; // Read from the SSS profile
public Vector3 transmittance;
// Clearcoat

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl


#define DEBUGVIEW_LIT_BSDFDATA_SUBSURFACE_RADIUS (1042)
#define DEBUGVIEW_LIT_BSDFDATA_THICKNESS (1043)
#define DEBUGVIEW_LIT_BSDFDATA_SUBSURFACE_PROFILE (1044)
#define DEBUGVIEW_LIT_BSDFDATA_ENABLE_TRANSMITTANCE (1045)
#define DEBUGVIEW_LIT_BSDFDATA_ENABLE_TRANSMISSION (1045)
#define DEBUGVIEW_LIT_BSDFDATA_TRANSMITTANCE (1046)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_NORMAL_WS (1047)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS (1048)

2
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2017.1.0a1
m_EditorVersion: 2017.1.0a2
正在加载...
取消
保存