Scene voxelization on GPU + voxel radiance compute started + general updates

This commit is contained in:
turanszkij
2017-02-25 22:43:18 +01:00
parent c43bce08bc
commit 06a4c9c4a6
28 changed files with 650 additions and 79 deletions
+2 -4
View File
@@ -120,11 +120,7 @@ void MainComponent::run()
}
wiProfiler::GetInstance().EndRange(); // Fixed Update
// Rendering:
wiProfiler::GetInstance().BeginRange("GPU Frame", wiProfiler::DOMAIN_GPU, GRAPHICSTHREAD_IMMEDIATE);
Render();
wiProfiler::GetInstance().EndRange(GRAPHICSTHREAD_IMMEDIATE); // GPU Frame
wiProfiler::GetInstance().EndRange(); // CPU Frame
@@ -157,7 +153,9 @@ void MainComponent::Render()
wiLua::GetGlobal()->Render();
wiRenderer::GetDevice()->LOCK();
wiProfiler::GetInstance().BeginRange("GPU Frame", wiProfiler::DOMAIN_GPU, GRAPHICSTHREAD_IMMEDIATE);
getActiveComponent()->Render();
wiProfiler::GetInstance().EndRange(GRAPHICSTHREAD_IMMEDIATE); // GPU Frame
wiRenderer::GetDevice()->UNLOCK();
}
+12 -1
View File
@@ -16,7 +16,7 @@ RendererWindow::RendererWindow(Renderable3DComponent* component)
wiRenderer::SetToDrawGridHelper(true);
rendererWindow = new wiWindow(GUI, "Renderer Window");
rendererWindow->SetSize(XMFLOAT2(400, 550));
rendererWindow->SetSize(XMFLOAT2(400, 580));
rendererWindow->SetEnabled(true);
GUI->AddWidget(rendererWindow);
@@ -40,6 +40,15 @@ RendererWindow::RendererWindow(Renderable3DComponent* component)
occlusionCullingCheckBox->SetCheck(wiRenderer::GetOcclusionCullingEnabled());
rendererWindow->AddWidget(occlusionCullingCheckBox);
voxelRadianceCheckBox = new wiCheckBox("Voxel Radiance: ");
voxelRadianceCheckBox->SetTooltip("Toggle voxel radiance computation (EXPERIMENTAL).");
voxelRadianceCheckBox->SetPos(XMFLOAT2(x, y += step));
voxelRadianceCheckBox->OnClick([](wiEventArgs args) {
wiRenderer::SetVoxelRadianceEnabled(args.bValue);
});
voxelRadianceCheckBox->SetCheck(wiRenderer::GetVoxelRadianceEnabled());
rendererWindow->AddWidget(voxelRadianceCheckBox);
partitionBoxesCheckBox = new wiCheckBox("SPTree visualizer: ");
partitionBoxesCheckBox->SetTooltip("Visualize the world space partitioning tree as boxes");
partitionBoxesCheckBox->SetPos(XMFLOAT2(x, y += step));
@@ -259,6 +268,8 @@ RendererWindow::~RendererWindow()
SAFE_DELETE(rendererWindow);
SAFE_DELETE(vsyncCheckBox);
SAFE_DELETE(vsyncCheckBox);
SAFE_DELETE(occlusionCullingCheckBox);
SAFE_DELETE(voxelRadianceCheckBox);
SAFE_DELETE(partitionBoxesCheckBox);
SAFE_DELETE(boneLinesCheckBox);
SAFE_DELETE(wireFrameCheckBox);
+1
View File
@@ -19,6 +19,7 @@ public:
wiWindow* rendererWindow;
wiCheckBox* vsyncCheckBox;
wiCheckBox* occlusionCullingCheckBox;
wiCheckBox* voxelRadianceCheckBox;
wiCheckBox* partitionBoxesCheckBox;
wiCheckBox* boneLinesCheckBox;
wiCheckBox* wireFrameCheckBox;
+30 -14
View File
@@ -36,26 +36,28 @@
#define TEXSLOT_SHADOWARRAY_2D 12
#define TEXSLOT_SHADOWARRAY_CUBE 13
#define TEXSLOT_ONDEMAND0 14
#define TEXSLOT_ONDEMAND1 15
#define TEXSLOT_ONDEMAND2 16
#define TEXSLOT_ONDEMAND3 17
#define TEXSLOT_ONDEMAND4 18
#define TEXSLOT_ONDEMAND5 19
#define TEXSLOT_ONDEMAND6 20
#define TEXSLOT_ONDEMAND7 21
#define TEXSLOT_ONDEMAND8 22
#define TEXSLOT_ONDEMAND9 23
#define TEXSLOT_VOXELRADIANCE 14
#define TEXSLOT_ONDEMAND0 15
#define TEXSLOT_ONDEMAND1 16
#define TEXSLOT_ONDEMAND2 17
#define TEXSLOT_ONDEMAND3 18
#define TEXSLOT_ONDEMAND4 19
#define TEXSLOT_ONDEMAND5 20
#define TEXSLOT_ONDEMAND6 21
#define TEXSLOT_ONDEMAND7 22
#define TEXSLOT_ONDEMAND8 23
#define TEXSLOT_ONDEMAND9 24
#define TEXSLOT_ONDEMAND_COUNT (TEXSLOT_ONDEMAND9 - TEXSLOT_ONDEMAND0 + 1)
#define TEXSLOT_LIGHTGRID 24
#define TEXSLOT_LIGHTGRID 25
#define TEXSLOT_COUNT TEXSLOT_LIGHTGRID
#define SBSLOT_BONE 0
#define SBSLOT_TILEFRUSTUMS 24
#define SBSLOT_LIGHTINDEXLIST 25
#define SBSLOT_LIGHTARRAY 26
#define SBSLOT_TILEFRUSTUMS 25
#define SBSLOT_LIGHTINDEXLIST 26
#define SBSLOT_LIGHTARRAY 27
///////////////////////////
@@ -83,6 +85,14 @@
#define RWSTRUCTUREDBUFFER_X(name, type, slot) RWStructuredBuffer< type > name : register(u ## slot)
#define RWSTRUCTUREDBUFFER(name, type, slot) RWSTRUCTUREDBUFFER_X(name, type, slot)
#define TEXTURE1D_X(name, type, slot) Texture1D< type > name : register(t ## slot);
#define TEXTURE1D(name, type, slot) TEXTURE1D_X(name, type, slot)
#define TEXTURE1DARRAY_X(name, type, slot) Texture1DArray< type > name : register(t ## slot);
#define TEXTURE1DARRAY(name, type, slot) TEXTURE1DARRAY_X(name, type, slot)
#define RWTEXTURE1D_X(name, type, slot) RWTexture1D< type > name : register(u ## slot);
#define RWTEXTURE1D(name, type, slot) RWTEXTURE1D_X(name, type, slot)
#define TEXTURE2D_X(name, type, slot) Texture2D< type > name : register(t ## slot);
#define TEXTURE2D(name, type, slot) TEXTURE2D_X(name, type, slot)
#define TEXTURE2DMS_X(name, type, slot) Texture2DMS< type > name : register(t ## slot);
@@ -91,10 +101,16 @@
#define TEXTURE2DARRAY(name, type, slot) TEXTURE2DARRAY_X(name, type, slot)
#define RWTEXTURE2D_X(name, type, slot) RWTexture2D< type > name : register(u ## slot);
#define RWTEXTURE2D(name, type, slot) RWTEXTURE2D_X(name, type, slot)
#define TEXTURECUBE_X(name, type, slot) TextureCube< type > name : register(t ## slot);
#define TEXTURECUBE(name, type, slot) TEXTURECUBE_X(name, type, slot)
#define TEXTURECUBEARRAY_X(name, type, slot) TextureCubeArray< type > name : register(t ## slot);
#define TEXTURECUBEARRAY(name, type, slot) TEXTURECUBEARRAY_X(name, type, slot)
#define TEXTURE3D_X(name, type, slot) Texture3D< type > name : register(t ## slot);
#define TEXTURE3D(name, type, slot) TEXTURE3D_X(name, type, slot)
#define RWTEXTURE3D_X(name, type, slot) RWTexture3D< type > name : register(u ## slot);
#define RWTEXTURE3D(name, type, slot) RWTEXTURE3D_X(name, type, slot)
#endif // _RESOURCEBUFFER_MAPPING_H_
+10
View File
@@ -839,6 +839,16 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="voxelRadianceCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">4.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="vPointLightVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Vertex</ShaderType>
@@ -510,6 +510,9 @@
<FxCompile Include="downsampleDepthBuffer4xPS.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="voxelRadianceCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="PS">
+4 -2
View File
@@ -15,9 +15,11 @@ TEXTURECUBE(texture_env_global, float4, TEXSLOT_ENV_GLOBAL)
TEXTURECUBE(texture_env0, float4, TEXSLOT_ENV0)
TEXTURECUBE(texture_env1, float4, TEXSLOT_ENV1)
TEXTURECUBE(texture_env2, float4, TEXSLOT_ENV2)
TEXTURE2D(texture_decalatlas, float4, TEXSLOT_DECALATLAS)
TEXTURE2DARRAY(texture_shadowarray_2d, float, TEXSLOT_SHADOWARRAY_2D)
TEXTURECUBEARRAY(texture_shadowarray_cube, float, TEXSLOT_SHADOWARRAY_CUBE)
TEXTURE2D(texture_decalatlas, float4, TEXSLOT_DECALATLAS)
TEXTURE3D(texture_voxelradiance, float4, TEXSLOT_VOXELRADIANCE)
TEXTURE2D(texture_0, float4, TEXSLOT_ONDEMAND0)
TEXTURE2D(texture_1, float4, TEXSLOT_ONDEMAND1)
TEXTURE2D(texture_2, float4, TEXSLOT_ONDEMAND2)
@@ -48,7 +50,7 @@ CBUFFER(WorldCB, CBSLOT_RENDERER_WORLD)
float3 g_xWorld_Ambient; float xPadding2_WorldCB;
float3 g_xWorld_Fog; float xPadding3_WorldCB;
float2 g_xWorld_ScreenWidthHeight;
float xPadding4_WorldCB;
float g_xWorld_VoxelRadianceScale;
float xPadding5_WorldCB;
};
CBUFFER(FrameCB, CBSLOT_RENDERER_FRAME)
Binary file not shown.
+21
View File
@@ -110,6 +110,24 @@ inline void Refraction(in float2 ScreenCoord, in float2 normal2D, in float3 bump
color.a = 1;
}
inline void VoxelRadiance(in float3 P, inout float ao)
{
[branch]
if (g_xWorld_VoxelRadianceScale > 0)
{
float3 dim;
float mips;
texture_voxelradiance.GetDimensions(0, dim.x, dim.y, dim.z, mips);
float3 diff = (P - floor(g_xCamera_CamPos)) * g_xWorld_VoxelRadianceScale;
float3 uvw = diff * float3(0.5f, -0.5f, 0.5f) + 0.5f;
float4 radiance = texture_voxelradiance.SampleLevel(sampler_linear_clamp, uvw, 0);
diff = abs(diff);
float blend = pow(saturate(max(diff.x, max(diff.y, diff.z))), 4);
ao *= lerp(radiance.a, 1, blend);
}
}
inline void DirectionalLight(in float3 N, in float3 V, in float3 P, in float3 f0, in float3 albedo, in float roughness,
inout float3 diffuse, out float3 specular)
{
@@ -266,6 +284,9 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
#define OBJECT_PS_LIGHT_TILED \
TiledLighting(pixel, N, V, P, f0, albedo, roughness, diffuse, specular);
#define OBJECT_PS_VOXELRADIANCE \
VoxelRadiance(P, ao);
#define OBJECT_PS_LIGHT_END \
color.rgb = lerp(1, GetAmbientColor() * ao + diffuse, opacity) * albedo + specular;
+2
View File
@@ -17,6 +17,8 @@ float4 main(PixelInputType input) : SV_TARGET
OBJECT_PS_ENVIRONMENTREFLECTIONS
OBJECT_PS_VOXELRADIANCE
OBJECT_PS_LIGHT_END
OBJECT_PS_EMISSIVE
@@ -21,6 +21,8 @@ float4 main(PixelInputType input) : SV_TARGET
OBJECT_PS_ENVIRONMENTREFLECTIONS
OBJECT_PS_VOXELRADIANCE
OBJECT_PS_LIGHT_END
OBJECT_PS_EMISSIVE
@@ -21,6 +21,8 @@ float4 main(PixelInputType input) : SV_TARGET
OBJECT_PS_PLANARREFLECTIONS
OBJECT_PS_VOXELRADIANCE
OBJECT_PS_LIGHT_END
OBJECT_PS_EMISSIVE
@@ -23,6 +23,8 @@ float4 main(PixelInputType input) : SV_TARGET
OBJECT_PS_ENVIRONMENTREFLECTIONS
OBJECT_PS_VOXELRADIANCE
OBJECT_PS_LIGHT_END
OBJECT_PS_EMISSIVE
@@ -17,6 +17,8 @@ float4 main(PixelInputType input) : SV_TARGET
OBJECT_PS_PLANARREFLECTIONS
OBJECT_PS_VOXELRADIANCE
OBJECT_PS_LIGHT_END
OBJECT_PS_EMISSIVE
@@ -21,6 +21,8 @@ float4 main(PixelInputType input) : SV_TARGET
OBJECT_PS_ENVIRONMENTREFLECTIONS
OBJECT_PS_VOXELRADIANCE
OBJECT_PS_LIGHT_END
OBJECT_PS_EMISSIVE
+29
View File
@@ -0,0 +1,29 @@
#include "globals.hlsli"
TEXTURE3D(input, float4, 0);
RWTEXTURE3D(output, float4, 0);
groupshared float4 accumulation[4 * 4 * 4];
[numthreads(4, 4, 4)]
void main( uint3 DTid : SV_DispatchThreadID, uint GroupIndex : SV_GroupIndex )
{
// TODO!
float4 current = input[DTid];
//output[DTid] = 1 - current.aaaa;
accumulation[GroupIndex] = current;
GroupMemoryBarrierWithGroupSync();
float4 avg = 0;
for (uint i = 0; i < 4 * 4 * 4; ++i)
{
avg += accumulation[i];
}
avg /= 4 * 4 * 4;
output[DTid] = 1 - avg.aaaa;
}
+3
View File
@@ -92,6 +92,8 @@ enum TEXTYPES
TEXTYPE_2D_LIGHTGRID_OPAQUE,
TEXTYPE_2D_LIGHTGRID_TRANSPARENT,
TEXTYPE_2D_DEBUGUAV,
TEXTYPE_3D_VOXELSCENE,
TEXTYPE_3D_VOXELRADIANCE,
TEXTYPE_LAST
};
@@ -216,6 +218,7 @@ enum CSTYPES
CSTYPE_TILEDLIGHTCULLING,
CSTYPE_TILEDLIGHTCULLING_DEBUG,
CSTYPE_RESOLVEMSAADEPTHSTENCIL,
CSTYPE_VOXELRADIANCE,
CSTYPE_LAST
};
+23
View File
@@ -355,6 +355,17 @@ namespace wiGraphicsTypes
UINT Count;
UINT Quality;
};
struct Texture1DDesc
{
UINT Width;
UINT MipLevels;
UINT ArraySize;
FORMAT Format;
USAGE Usage;
UINT BindFlags;
UINT CPUAccessFlags;
UINT MiscFlags;
};
struct Texture2DDesc
{
UINT Width;
@@ -368,6 +379,18 @@ namespace wiGraphicsTypes
UINT CPUAccessFlags;
UINT MiscFlags;
};
struct Texture3DDesc
{
UINT Width;
UINT Height;
UINT Depth;
UINT MipLevels;
FORMAT Format;
USAGE Usage;
UINT BindFlags;
UINT CPUAccessFlags;
UINT MiscFlags;
};
struct SamplerDesc
{
FILTER Filter;
+4 -7
View File
@@ -23,12 +23,9 @@ namespace wiGraphicsTypes
GraphicsDevice() :FRAMECOUNT(0), VSYNC(true), SCREENWIDTH(0), SCREENHEIGHT(0), FULLSCREEN(false) {}
virtual HRESULT CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *ppBuffer) = 0;
virtual HRESULT CreateTexture1D() = 0;
virtual HRESULT CreateTexture1D(const Texture1DDesc* pDesc, const SubresourceData *pInitialData, Texture1D **ppTexture1D) = 0;
virtual HRESULT CreateTexture2D(const Texture2DDesc* pDesc, const SubresourceData *pInitialData, Texture2D **ppTexture2D) = 0;
virtual HRESULT CreateTexture3D() = 0;
virtual HRESULT CreateShaderResourceView(Texture2D* pTexture) = 0;
virtual HRESULT CreateRenderTargetView(Texture2D* pTexture) = 0;
virtual HRESULT CreateDepthStencilView(Texture2D* pTexture) = 0;
virtual HRESULT CreateTexture3D(const Texture3DDesc* pDesc, const SubresourceData *pInitialData, Texture3D **ppTexture3D) = 0;
virtual HRESULT CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements,
const void *pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength, VertexLayout *pInputLayout) = 0;
virtual HRESULT CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage* pClassLinkage, VertexShader *pVertexShader) = 0;
@@ -82,8 +79,8 @@ namespace wiGraphicsTypes
///////////////Thread-sensitive////////////////////////
virtual void BindViewports(UINT NumViewports, const ViewPort *pViewports, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0;
virtual void BindRenderTargets(UINT NumViews, Texture2D* const *ppRenderTargetViews, Texture2D* depthStencilTexture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, UINT arrayIndex = 0) = 0;
virtual void ClearRenderTarget(Texture2D* pTexture, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, UINT arrayIndex = 0) = 0;
virtual void BindRenderTargets(UINT NumViews, Texture* const *ppRenderTargets, Texture2D* depthStencilTexture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, UINT arrayIndex = 0) = 0;
virtual void ClearRenderTarget(Texture* pTexture, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, UINT arrayIndex = 0) = 0;
virtual void ClearDepthStencil(Texture2D* pTexture, UINT ClearFlags, FLOAT Depth, UINT8 Stencil, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, UINT arrayIndex = 0) = 0;
virtual void BindResourcePS(const GPUResource* resource, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0;
virtual void BindResourceVS(const GPUResource* resource, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0;
+257 -26
View File
@@ -820,6 +820,20 @@ inline DXGI_FORMAT _ConvertFormat(FORMAT value)
return DXGI_FORMAT_UNKNOWN;
}
inline D3D11_TEXTURE1D_DESC _ConvertTexture1DDesc(const Texture1DDesc* pDesc)
{
D3D11_TEXTURE1D_DESC desc;
desc.Width = pDesc->Width;
desc.MipLevels = pDesc->MipLevels;
desc.ArraySize = pDesc->ArraySize;
desc.Format = _ConvertFormat(pDesc->Format);
desc.Usage = _ConvertUsage(pDesc->Usage);
desc.BindFlags = _ParseBindFlags(pDesc->BindFlags);
desc.CPUAccessFlags = _ParseCPUAccessFlags(pDesc->CPUAccessFlags);
desc.MiscFlags = _ParseResourceMiscFlags(pDesc->MiscFlags);
return desc;
}
inline D3D11_TEXTURE2D_DESC _ConvertTexture2DDesc(const Texture2DDesc* pDesc)
{
D3D11_TEXTURE2D_DESC desc;
@@ -837,6 +851,21 @@ inline D3D11_TEXTURE2D_DESC _ConvertTexture2DDesc(const Texture2DDesc* pDesc)
return desc;
}
inline D3D11_TEXTURE3D_DESC _ConvertTexture3DDesc(const Texture3DDesc* pDesc)
{
D3D11_TEXTURE3D_DESC desc;
desc.Width = pDesc->Width;
desc.Height = pDesc->Height;
desc.Depth = pDesc->Depth;
desc.MipLevels = pDesc->MipLevels;
desc.Format = _ConvertFormat(pDesc->Format);
desc.Usage = _ConvertUsage(pDesc->Usage);
desc.BindFlags = _ParseBindFlags(pDesc->BindFlags);
desc.CPUAccessFlags = _ParseCPUAccessFlags(pDesc->CPUAccessFlags);
desc.MiscFlags = _ParseResourceMiscFlags(pDesc->MiscFlags);
return desc;
}
inline D3D11_SUBRESOURCE_DATA* _ConvertSubresourceData(const SubresourceData* pInitialData)
{
if (pInitialData == nullptr)
@@ -1289,23 +1318,52 @@ inline USAGE _ConvertUsage_Inv(D3D11_USAGE value)
return USAGE_DEFAULT;
}
inline Texture2DDesc _ConvertTexture2DDesc_Inv(const D3D11_TEXTURE2D_DESC* pDesc)
{
Texture2DDesc desc;
desc.Width = pDesc->Width;
desc.Height = pDesc->Height;
desc.MipLevels = pDesc->MipLevels;
desc.ArraySize = pDesc->ArraySize;
desc.Format = _ConvertFormat_Inv(pDesc->Format);
desc.SampleDesc.Count = pDesc->SampleDesc.Count;
desc.SampleDesc.Quality = pDesc->SampleDesc.Quality;
desc.Usage = _ConvertUsage_Inv(pDesc->Usage);
desc.BindFlags = _ParseBindFlags_Inv(pDesc->BindFlags);
desc.CPUAccessFlags = _ParseCPUAccessFlags_Inv(pDesc->CPUAccessFlags);
desc.MiscFlags = _ParseResourceMiscFlags_Inv(pDesc->MiscFlags);
inline Texture1DDesc _ConvertTexture1DDesc_Inv(const D3D11_TEXTURE1D_DESC* pDesc)
{
Texture1DDesc desc;
desc.Width = pDesc->Width;
desc.MipLevels = pDesc->MipLevels;
desc.ArraySize = pDesc->ArraySize;
desc.Format = _ConvertFormat_Inv(pDesc->Format);
desc.Usage = _ConvertUsage_Inv(pDesc->Usage);
desc.BindFlags = _ParseBindFlags_Inv(pDesc->BindFlags);
desc.CPUAccessFlags = _ParseCPUAccessFlags_Inv(pDesc->CPUAccessFlags);
desc.MiscFlags = _ParseResourceMiscFlags_Inv(pDesc->MiscFlags);
return desc;
}
return desc;
}
inline Texture2DDesc _ConvertTexture2DDesc_Inv(const D3D11_TEXTURE2D_DESC* pDesc)
{
Texture2DDesc desc;
desc.Width = pDesc->Width;
desc.Height = pDesc->Height;
desc.MipLevels = pDesc->MipLevels;
desc.ArraySize = pDesc->ArraySize;
desc.Format = _ConvertFormat_Inv(pDesc->Format);
desc.SampleDesc.Count = pDesc->SampleDesc.Count;
desc.SampleDesc.Quality = pDesc->SampleDesc.Quality;
desc.Usage = _ConvertUsage_Inv(pDesc->Usage);
desc.BindFlags = _ParseBindFlags_Inv(pDesc->BindFlags);
desc.CPUAccessFlags = _ParseCPUAccessFlags_Inv(pDesc->CPUAccessFlags);
desc.MiscFlags = _ParseResourceMiscFlags_Inv(pDesc->MiscFlags);
return desc;
}
inline Texture3DDesc _ConvertTexture3DDesc_Inv(const D3D11_TEXTURE3D_DESC* pDesc)
{
Texture3DDesc desc;
desc.Width = pDesc->Width;
desc.Height = pDesc->Height;
desc.Depth = pDesc->Depth;
desc.MipLevels = pDesc->MipLevels;
desc.Format = _ConvertFormat_Inv(pDesc->Format);
desc.Usage = _ConvertUsage_Inv(pDesc->Usage);
desc.BindFlags = _ParseBindFlags_Inv(pDesc->BindFlags);
desc.CPUAccessFlags = _ParseCPUAccessFlags_Inv(pDesc->CPUAccessFlags);
desc.MiscFlags = _ParseResourceMiscFlags_Inv(pDesc->MiscFlags);
return desc;
}
// Local Helpers:
@@ -1595,10 +1653,41 @@ HRESULT GraphicsDevice_DX11::CreateBuffer(const GPUBufferDesc *pDesc, const Subr
return hr;
}
HRESULT GraphicsDevice_DX11::CreateTexture1D()
HRESULT GraphicsDevice_DX11::CreateTexture1D(const Texture1DDesc* pDesc, const SubresourceData *pInitialData, Texture1D **ppTexture1D)
{
// TODO
return E_FAIL;
if ((*ppTexture1D) == nullptr)
{
(*ppTexture1D) = new Texture1D;
}
(*ppTexture1D)->desc = *pDesc;
D3D11_TEXTURE1D_DESC desc = _ConvertTexture1DDesc(&(*ppTexture1D)->desc);
D3D11_SUBRESOURCE_DATA* data = _ConvertSubresourceData(pInitialData);
HRESULT hr = S_OK;
hr = device->CreateTexture1D(&desc, data, &((*ppTexture1D)->texture1D_DX11));
assert(SUCCEEDED(hr) && "Texture1D creation failed!");
if (FAILED(hr))
return hr;
CreateShaderResourceView(*ppTexture1D);
if (desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS)
{
assert((*ppTexture1D)->independentRTVArraySlices == false && "TextureArray UAV not implemented!");
D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
ZeroMemory(&uav_desc, sizeof(uav_desc));
uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE1D;
uav_desc.Texture2D.MipSlice = 0;
hr = device->CreateUnorderedAccessView((*ppTexture1D)->texture1D_DX11, &uav_desc, &(*ppTexture1D)->unorderedAccessView_DX11);
assert(SUCCEEDED(hr) && "UnorderedAccessView of the Texture1D could not be created!");
}
return hr;
}
HRESULT GraphicsDevice_DX11::CreateTexture2D(const Texture2DDesc* pDesc, const SubresourceData *pInitialData, Texture2D **ppTexture2D)
{
@@ -1637,6 +1726,8 @@ HRESULT GraphicsDevice_DX11::CreateTexture2D(const Texture2DDesc* pDesc, const S
if (desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS)
{
assert((*ppTexture2D)->independentRTVArraySlices == false && "TextureArray UAV not implemented!");
D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
ZeroMemory(&uav_desc, sizeof(uav_desc));
uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
@@ -1649,10 +1740,81 @@ HRESULT GraphicsDevice_DX11::CreateTexture2D(const Texture2DDesc* pDesc, const S
return hr;
}
HRESULT GraphicsDevice_DX11::CreateTexture3D()
HRESULT GraphicsDevice_DX11::CreateTexture3D(const Texture3DDesc* pDesc, const SubresourceData *pInitialData, Texture3D **ppTexture3D)
{
// TODO
return E_FAIL;
if ((*ppTexture3D) == nullptr)
{
(*ppTexture3D) = new Texture3D;
}
(*ppTexture3D)->desc = *pDesc;
D3D11_TEXTURE3D_DESC desc = _ConvertTexture3DDesc(&(*ppTexture3D)->desc);
D3D11_SUBRESOURCE_DATA* data = _ConvertSubresourceData(pInitialData);
HRESULT hr = S_OK;
hr = device->CreateTexture3D(&desc, data, &((*ppTexture3D)->texture3D_DX11));
assert(SUCCEEDED(hr) && "Texture3D creation failed!");
if (FAILED(hr))
return hr;
CreateShaderResourceView(*ppTexture3D);
CreateRenderTargetView(*ppTexture3D);
if (desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS)
{
D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
ZeroMemory(&uav_desc, sizeof(uav_desc));
uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D;
uav_desc.Texture3D.MipSlice = 0;
uav_desc.Texture3D.FirstWSlice = 0;
uav_desc.Texture3D.WSize = desc.Depth;
hr = device->CreateUnorderedAccessView((*ppTexture3D)->texture3D_DX11, &uav_desc, &(*ppTexture3D)->unorderedAccessView_DX11);
assert(SUCCEEDED(hr) && "UnorderedAccessView of the Texture2D could not be created!");
}
return hr;
}
HRESULT GraphicsDevice_DX11::CreateShaderResourceView(Texture1D* pTexture)
{
if (pTexture->shaderResourceView_DX11 != nullptr)
{
return E_FAIL;
}
HRESULT hr = E_FAIL;
if (pTexture->desc.BindFlags & D3D11_BIND_SHADER_RESOURCE)
{
UINT arraySize = pTexture->desc.ArraySize;
D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc));
shaderResourceViewDesc.Format = _ConvertFormat(pTexture->desc.Format);
if (arraySize > 1)
{
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
shaderResourceViewDesc.Texture1DArray.FirstArraySlice = 0;
shaderResourceViewDesc.Texture1DArray.ArraySize = arraySize;
shaderResourceViewDesc.Texture1DArray.MostDetailedMip = 0; //from most detailed...
shaderResourceViewDesc.Texture1DArray.MipLevels = -1; //...to least detailed
}
else
{
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
shaderResourceViewDesc.Texture1D.MostDetailedMip = 0; //from most detailed...
shaderResourceViewDesc.Texture1D.MipLevels = -1; //...to least detailed
}
hr = device->CreateShaderResourceView(pTexture->texture1D_DX11, &shaderResourceViewDesc, &pTexture->shaderResourceView_DX11);
assert(SUCCEEDED(hr) && "ShaderResourceView Creation failed!");
}
return hr;
}
HRESULT GraphicsDevice_DX11::CreateShaderResourceView(Texture2D* pTexture)
{
@@ -1745,6 +1907,31 @@ HRESULT GraphicsDevice_DX11::CreateShaderResourceView(Texture2D* pTexture)
return hr;
}
HRESULT GraphicsDevice_DX11::CreateShaderResourceView(Texture3D* pTexture)
{
if (pTexture->shaderResourceView_DX11 != nullptr)
{
return E_FAIL;
}
HRESULT hr = E_FAIL;
if (pTexture->desc.BindFlags & D3D11_BIND_SHADER_RESOURCE)
{
D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc));
shaderResourceViewDesc.Format = _ConvertFormat(pTexture->desc.Format);
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
shaderResourceViewDesc.Texture3D.MostDetailedMip = 0; //from most detailed...
shaderResourceViewDesc.Texture3D.MipLevels = -1; //...to least detailed
hr = device->CreateShaderResourceView(pTexture->texture3D_DX11, &shaderResourceViewDesc, &pTexture->shaderResourceView_DX11);
assert(SUCCEEDED(hr) && "ShaderResourceView Creation failed!");
}
return hr;
}
HRESULT GraphicsDevice_DX11::CreateRenderTargetView(Texture2D* pTexture)
{
if (!pTexture->renderTargetViews_DX11.empty())
@@ -1876,6 +2063,50 @@ HRESULT GraphicsDevice_DX11::CreateRenderTargetView(Texture2D* pTexture)
return hr;
}
HRESULT GraphicsDevice_DX11::CreateRenderTargetView(Texture3D* pTexture)
{
if (!pTexture->renderTargetViews_DX11.empty())
{
return E_FAIL;
}
HRESULT hr = E_FAIL;
if (pTexture->desc.BindFlags & D3D11_BIND_RENDER_TARGET)
{
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
ZeroMemory(&renderTargetViewDesc, sizeof(renderTargetViewDesc));
renderTargetViewDesc.Format = _ConvertFormat(pTexture->desc.Format);
if (pTexture->independentRTVArraySlices)
{
for (UINT i = 0; i < pTexture->GetDesc().Depth; ++i)
{
renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
renderTargetViewDesc.Texture3D.MipSlice = 0;
renderTargetViewDesc.Texture3D.FirstWSlice = i;
renderTargetViewDesc.Texture3D.WSize = 1;
pTexture->renderTargetViews_DX11.push_back(nullptr);
hr = device->CreateRenderTargetView(pTexture->texture3D_DX11, &renderTargetViewDesc, &pTexture->renderTargetViews_DX11[i]);
}
}
else
{
renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
renderTargetViewDesc.Texture3D.MipSlice = 0;
renderTargetViewDesc.Texture3D.FirstWSlice = 0;
renderTargetViewDesc.Texture3D.WSize = pTexture->GetDesc().Depth;
pTexture->renderTargetViews_DX11.push_back(nullptr);
hr = device->CreateRenderTargetView(pTexture->texture3D_DX11, &renderTargetViewDesc, &pTexture->renderTargetViews_DX11[0]);
}
assert(SUCCEEDED(hr) && "RenderTargetView Creation failed!");
}
return hr;
}
HRESULT GraphicsDevice_DX11::CreateDepthStencilView(Texture2D* pTexture)
{
if (!pTexture->depthStencilViews_DX11.empty())
@@ -2279,20 +2510,20 @@ void GraphicsDevice_DX11::BindViewports(UINT NumViewports, const ViewPort *pView
deviceContexts[threadID]->RSSetViewports(NumViewports, pd3dViewPorts);
SAFE_DELETE_ARRAY(pd3dViewPorts);
}
void GraphicsDevice_DX11::BindRenderTargets(UINT NumViews, Texture2D* const *ppRenderTargetViews, Texture2D* depthStencilTexture, GRAPHICSTHREAD threadID, UINT arrayIndex)
void GraphicsDevice_DX11::BindRenderTargets(UINT NumViews, Texture* const *ppRenderTargets, Texture2D* depthStencilTexture, GRAPHICSTHREAD threadID, UINT arrayIndex)
{
ID3D11RenderTargetView* renderTargetViews[8];
ZeroMemory(renderTargetViews, sizeof(renderTargetViews));
for (UINT i = 0; i < min(NumViews, 8); ++i)
{
assert(ppRenderTargetViews[i]->renderTargetViews_DX11.size() > arrayIndex && "Invalid rendertarget arrayIndex!");
renderTargetViews[i] = ppRenderTargetViews[i]->renderTargetViews_DX11[arrayIndex];
assert(ppRenderTargets[i]->renderTargetViews_DX11.size() > arrayIndex && "Invalid rendertarget arrayIndex!");
renderTargetViews[i] = ppRenderTargets[i]->renderTargetViews_DX11[arrayIndex];
}
assert(depthStencilTexture == nullptr || depthStencilTexture->depthStencilViews_DX11.size() > arrayIndex && "Invalid depthstencil arrayIndex!");
ID3D11DepthStencilView* depthStencilView = (depthStencilTexture == nullptr ? nullptr : depthStencilTexture->depthStencilViews_DX11[arrayIndex]);
deviceContexts[threadID]->OMSetRenderTargets(NumViews, renderTargetViews, depthStencilView);
}
void GraphicsDevice_DX11::ClearRenderTarget(Texture2D* pTexture, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID, UINT arrayIndex)
void GraphicsDevice_DX11::ClearRenderTarget(Texture* pTexture, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID, UINT arrayIndex)
{
assert(pTexture->renderTargetViews_DX11.size() > arrayIndex && "Invalid rendertarget arrayIndex!");
deviceContexts[threadID]->ClearRenderTargetView(pTexture->renderTargetViews_DX11[arrayIndex], ColorRGBA);
+12 -7
View File
@@ -38,12 +38,9 @@ namespace wiGraphicsTypes
~GraphicsDevice_DX11();
virtual HRESULT CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *ppBuffer) override;
virtual HRESULT CreateTexture1D() override;
virtual HRESULT CreateTexture1D(const Texture1DDesc* pDesc, const SubresourceData *pInitialData, Texture1D **ppTexture1D) override;
virtual HRESULT CreateTexture2D(const Texture2DDesc* pDesc, const SubresourceData *pInitialData, Texture2D **ppTexture2D) override;
virtual HRESULT CreateTexture3D() override;
virtual HRESULT CreateShaderResourceView(Texture2D* pTexture) override;
virtual HRESULT CreateRenderTargetView(Texture2D* pTexture) override;
virtual HRESULT CreateDepthStencilView(Texture2D* pTexture) override;
virtual HRESULT CreateTexture3D(const Texture3DDesc* pDesc, const SubresourceData *pInitialData, Texture3D **ppTexture3D) override;
virtual HRESULT CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements,
const void *pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength, VertexLayout *pInputLayout) override;
virtual HRESULT CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage* pClassLinkage, VertexShader *pVertexShader) override;
@@ -75,8 +72,8 @@ namespace wiGraphicsTypes
///////////////Thread-sensitive////////////////////////
virtual void BindViewports(UINT NumViewports, const ViewPort *pViewports, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) override;
virtual void BindRenderTargets(UINT NumViews, Texture2D* const *ppRenderTargetViews, Texture2D* depthStencilTexture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, UINT arrayIndex = 0) override;
virtual void ClearRenderTarget(Texture2D* pTexture, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, UINT arrayIndex = 0) override;
virtual void BindRenderTargets(UINT NumViews, Texture* const *ppRenderTargets, Texture2D* depthStencilTexture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, UINT arrayIndex = 0) override;
virtual void ClearRenderTarget(Texture* pTexture, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, UINT arrayIndex = 0) override;
virtual void ClearDepthStencil(Texture2D* pTexture, UINT ClearFlags, FLOAT Depth, UINT8 Stencil, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, UINT arrayIndex = 0) override;
virtual void BindResourcePS(const GPUResource* resource, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) override;
virtual void BindResourceVS(const GPUResource* resource, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) override;
@@ -139,6 +136,14 @@ namespace wiGraphicsTypes
virtual void EventBegin(const string& name, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) override;
virtual void EventEnd(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) override;
virtual void SetMarker(const string& name, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) override;
private:
HRESULT CreateShaderResourceView(Texture1D* pTexture);
HRESULT CreateShaderResourceView(Texture2D* pTexture);
HRESULT CreateShaderResourceView(Texture3D* pTexture);
HRESULT CreateRenderTargetView(Texture2D* pTexture);
HRESULT CreateRenderTargetView(Texture3D* pTexture);
HRESULT CreateDepthStencilView(Texture2D* pTexture);
};
}
+22 -4
View File
@@ -160,10 +160,6 @@ namespace wiGraphicsTypes
{
SAFE_RELEASE(x);
}
for (auto& x : depthStencilViews_DX11)
{
SAFE_RELEASE(x);
}
}
void Texture::RequestIndepententRenderTargetArraySlices(bool value)
{
@@ -182,6 +178,15 @@ namespace wiGraphicsTypes
return independentRTVCubemapFaces;
}
Texture1D::Texture1D() :Texture()
{
SAFE_INIT(texture1D_DX11);
}
Texture1D::~Texture1D()
{
SAFE_RELEASE(texture1D_DX11);
}
Texture2D::Texture2D() :Texture()
{
SAFE_INIT(texture2D_DX11);
@@ -189,6 +194,19 @@ namespace wiGraphicsTypes
Texture2D::~Texture2D()
{
SAFE_RELEASE(texture2D_DX11);
for (auto& x : depthStencilViews_DX11)
{
SAFE_RELEASE(x);
}
}
Texture3D::Texture3D() :Texture()
{
SAFE_INIT(texture3D_DX11);
}
Texture3D::~Texture3D()
{
SAFE_RELEASE(texture3D_DX11);
}
GPUQuery::GPUQuery()
+30 -2
View File
@@ -21,7 +21,9 @@ interface ID3D11RasterizerState;
interface ID3D11ClassLinkage;
interface ID3D11RenderTargetView;
interface ID3D11DepthStencilView;
interface ID3D11Texture1D;
interface ID3D11Texture2D;
interface ID3D11Texture3D;
interface ID3D11Query;
interface ID3D11Predicate;
@@ -230,7 +232,6 @@ namespace wiGraphicsTypes
friend class GraphicsDevice_DX11;
private:
vector<ID3D11RenderTargetView*> renderTargetViews_DX11;
vector<ID3D11DepthStencilView*> depthStencilViews_DX11;
bool independentRTVArraySlices;
bool independentRTVCubemapFaces;
public:
@@ -245,10 +246,24 @@ namespace wiGraphicsTypes
bool IsIndepententRenderTargetCubemapFaces();
};
class Texture1D : public Texture
{
friend class GraphicsDevice_DX11;
private:
ID3D11Texture1D* texture1D_DX11;
Texture1DDesc desc;
public:
Texture1D();
virtual ~Texture1D();
Texture1DDesc GetDesc() const { return desc; }
};
class Texture2D : public Texture
{
friend class GraphicsDevice_DX11;
private:
vector<ID3D11DepthStencilView*> depthStencilViews_DX11;
ID3D11Texture2D* texture2D_DX11;
Texture2DDesc desc;
public:
@@ -258,6 +273,19 @@ namespace wiGraphicsTypes
Texture2DDesc GetDesc() const { return desc; }
};
class Texture3D : public Texture
{
friend class GraphicsDevice_DX11;
private:
ID3D11Texture3D* texture3D_DX11;
Texture3DDesc desc;
public:
Texture3D();
virtual ~Texture3D();
Texture3DDesc GetDesc() const { return desc; }
};
@@ -266,7 +294,7 @@ namespace wiGraphicsTypes
friend class GraphicsDevice_DX11;
private:
vector<ID3D11Query*> resource_DX11;
vector<bool> active;
vector<int> active;
GPUQueryDesc desc;
int async_frameshift;
public:
+4
View File
@@ -10,13 +10,16 @@ void wiProfiler::BeginFrame()
if (!ENABLED)
return;
wiRenderer::GetDevice()->LOCK();
wiRenderer::GetDevice()->QueryBegin(&disjoint, GRAPHICSTHREAD_IMMEDIATE);
wiRenderer::GetDevice()->UNLOCK();
}
void wiProfiler::EndFrame()
{
if (!ENABLED)
return;
wiRenderer::GetDevice()->LOCK();
wiRenderer::GetDevice()->QueryEnd(&disjoint, GRAPHICSTHREAD_IMMEDIATE);
while(!wiRenderer::GetDevice()->QueryRead(&disjoint, GRAPHICSTHREAD_IMMEDIATE));
@@ -43,6 +46,7 @@ void wiProfiler::EndFrame()
}
}
}
wiRenderer::GetDevice()->UNLOCK();
}
void wiProfiler::BeginRange(const std::string& name, PROFILER_DOMAIN domain, GRAPHICSTHREAD threadID)
+2 -2
View File
@@ -183,13 +183,13 @@ void wiRenderTarget::Deactivate(GRAPHICSTHREAD threadID)
void wiRenderTarget::Set(GRAPHICSTHREAD threadID, bool disableColor)
{
wiRenderer::GetDevice()->BindViewports(1, &viewPort, threadID);
wiRenderer::GetDevice()->BindRenderTargets(disableColor ? 0 : numViews, disableColor ? nullptr : renderTargets.data(), (depth ? depth->GetTexture() : nullptr), threadID);
wiRenderer::GetDevice()->BindRenderTargets(disableColor ? 0 : numViews, disableColor ? nullptr : (Texture**)renderTargets.data(), (depth ? depth->GetTexture() : nullptr), threadID);
resolvedMSAAUptodate = false;
}
void wiRenderTarget::Set(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth, bool disableColor)
{
wiRenderer::GetDevice()->BindViewports(1, &viewPort, threadID);
wiRenderer::GetDevice()->BindRenderTargets(disableColor ? 0 : numViews, disableColor ? nullptr : renderTargets.data(), (getDepth ? getDepth->GetTexture() : nullptr), threadID);
wiRenderer::GetDevice()->BindRenderTargets(disableColor ? 0 : numViews, disableColor ? nullptr : (Texture**)renderTargets.data(), (getDepth ? getDepth->GetTexture() : nullptr), threadID);
resolvedMSAAUptodate = false;
}
+161 -7
View File
@@ -55,6 +55,7 @@ Texture2D* wiRenderer::enviroMap,*wiRenderer::colorGrading;
float wiRenderer::GameSpeed=1,wiRenderer::overrideGameSpeed=1;
bool wiRenderer::debugLightCulling = false;
bool wiRenderer::occlusionCulling = true;
bool wiRenderer::voxelRadiance = false;
int wiRenderer::visibleCount;
wiRenderTarget wiRenderer::normalMapRT, wiRenderer::imagesRT, wiRenderer::imagesRTAdd;
Camera *wiRenderer::cam = nullptr, *wiRenderer::refCam = nullptr, *wiRenderer::prevFrameCam = nullptr;
@@ -770,6 +771,7 @@ void wiRenderer::LoadShaders()
computeShaders[CSTYPE_TILEDLIGHTCULLING] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "lightCullingCS.cso", wiResourceManager::COMPUTESHADER));
computeShaders[CSTYPE_TILEDLIGHTCULLING_DEBUG] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "lightCullingCS_DEBUG.cso", wiResourceManager::COMPUTESHADER));
computeShaders[CSTYPE_RESOLVEMSAADEPTHSTENCIL] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "resolveMSAADepthStencilCS.cso", wiResourceManager::COMPUTESHADER));
computeShaders[CSTYPE_VOXELRADIANCE] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelRadianceCS.cso", wiResourceManager::COMPUTESHADER));
hullShaders[HSTYPE_OBJECT] = static_cast<HullShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectHS.cso", wiResourceManager::HULLSHADER));
@@ -1015,7 +1017,6 @@ void wiRenderer::SetUpStates()
dsd.BackFace.StencilPassOp = STENCIL_OP_REPLACE;
dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP;
dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP;
// Create the depth stencil state.
GetDevice()->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_DEFAULT]);
@@ -1033,7 +1034,6 @@ void wiRenderer::SetUpStates()
dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP;
dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP;
dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP;
// Create the depth stencil state.
GetDevice()->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_DIRLIGHT]);
@@ -1051,12 +1051,12 @@ void wiRenderer::SetUpStates()
dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP;
dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP;
dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP;
// Create the depth stencil state.
GetDevice()->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_LIGHT]);
dsd.DepthEnable = false;
dsd.StencilEnable = true;
dsd.DepthFunc = COMPARISON_LESS_EQUAL;
dsd.StencilReadMask = 0xFF;
dsd.StencilWriteMask = 0xFF;
dsd.FrontFace.StencilFunc = COMPARISON_EQUAL;
@@ -1551,6 +1551,12 @@ void wiRenderer::UpdatePerFrameData()
}
void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID)
{
//if(GetDevice()->GetFrameCount() % 30 == 0)
{
VoxelizeScene(threadID);
ComputeVoxelRadiance(threadID);
}
UpdateWorldCB(threadID); // only commits when parameters are changed
UpdateFrameCB(threadID);
@@ -1747,7 +1753,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID)
lightArray[lightCounter].coneAngleCos = cosf(lightArray[lightCounter].coneAngle);
lightArray[lightCounter].directionWS = l->GetDirection();
XMStoreFloat3(&lightArray[lightCounter].directionVS, XMVector3TransformNormal(XMLoadFloat3(&lightArray[lightCounter].directionWS), viewMatrix));
if (l->shadow && l->shadowMap_index >= 0)
if (l->shadow && l->shadowMap_index >= 0 && !l->shadowCam_spotLight.empty())
{
lightArray[lightCounter].shadowMatrix[0] = l->shadowCam_spotLight[0].getVP();
}
@@ -1783,7 +1789,6 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID)
{
x->UpdateRenderData(threadID);
}
}
void wiRenderer::OcclusionCulling_Render(GRAPHICSTHREAD threadID)
{
@@ -3834,6 +3839,100 @@ void wiRenderer::RefreshEnvProbes(GRAPHICSTHREAD threadID)
GetDevice()->EventEnd();
}
static float voxelRadianceScale = 0; // 0 is disabled
void wiRenderer::VoxelizeScene(GRAPHICSTHREAD threadID)
{
if (!GetVoxelRadianceEnabled())
{
voxelRadianceScale = 0;
return;
}
GetDevice()->EventBegin("Voxelize Scene", threadID);
wiProfiler::GetInstance().BeginRange("Voxelize Scene", wiProfiler::DOMAIN_GPU, threadID);
static const int res = 32;
static const float scale = 2.0f;
voxelRadianceScale = 1.0f / (res * scale);
if (textures[TEXTYPE_3D_VOXELSCENE] == nullptr)
{
Texture3DDesc desc;
ZeroMemory(&desc, sizeof(desc));
desc.Width = res;
desc.Height = res;
desc.Depth = res;
desc.MipLevels = 1;
desc.Format = FORMAT_R8G8B8A8_UNORM;
desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE;
desc.Usage = USAGE_DEFAULT;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
textures[TEXTYPE_3D_VOXELSCENE] = new Texture3D;
textures[TEXTYPE_3D_VOXELSCENE]->RequestIndepententRenderTargetArraySlices(true);
HRESULT hr = GetDevice()->CreateTexture3D(&desc, nullptr, (Texture3D**)&textures[TEXTYPE_3D_VOXELSCENE]);
assert(SUCCEEDED(hr));
}
CulledList culledObjects;
CulledCollection culledRenderer;
AABB bbox;
XMFLOAT3 extents = XMFLOAT3(res * scale, res * scale, res * scale);
XMFLOAT3 center = XMFLOAT3(floorf(cam->translation.x), floorf(cam->translation.y), floorf(cam->translation.z));
bbox.createFromHalfWidth(center, extents);
if (spTree != nullptr)
{
spTree->getVisible(bbox, culledObjects);
for (Cullable* object : culledObjects)
{
culledRenderer[((Object*)object)->mesh].push_front((Object*)object);
}
ViewPort VP;
VP.TopLeftX = 0;
VP.TopLeftY = 0;
VP.Width = (float)res;
VP.Height = (float)res;
VP.MinDepth = 0.0f;
VP.MaxDepth = 1.0f;
GetDevice()->BindViewports(1, &VP, threadID);
GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID);
Camera savedCam = *cam;
for (int i = 0; i < res; ++i)
{
GetDevice()->BindRenderTargets(1, &textures[TEXTYPE_3D_VOXELSCENE], nullptr, threadID, i);
static const float color[] = { 0,0,0,0 };
GetDevice()->ClearRenderTarget(textures[TEXTYPE_3D_VOXELSCENE], color, threadID, i);
cam->Clear();
cam->Translate(bbox.getCenter());
XMMATRIX view = XMMatrixLookToLH(XMLoadFloat3(&center), XMVectorSet(0, 0, 1, 0), XMVectorSet(0, 1, 0, 0));
XMStoreFloat4x4(&cam->View, view);
XMMATRIX projection = XMMatrixOrthographicOffCenterLH(-extents.x, extents.x, -extents.y, extents.y, -extents.z + i * scale * 2, -extents.z + (i + 1) * scale * 2);
XMStoreFloat4x4(&cam->Projection, projection);
XMStoreFloat4x4(&cam->VP, XMMatrixMultiply(view, projection));
UpdateCameraCB(cam, threadID);
RenderMeshes(cam->translation, culledRenderer, SHADERTYPE_TEXTURE, RENDERTYPE_OPAQUE, threadID);
}
*cam = savedCam;
UpdateCameraCB(cam, threadID);
}
wiProfiler::GetInstance().EndRange(threadID);
GetDevice()->EventEnd();
}
void wiRenderer::ComputeTiledLightCulling(GRAPHICSTHREAD threadID)
{
wiProfiler::GetInstance().BeginRange("Tiled Light Culling", wiProfiler::DOMAIN_GPU, threadID);
@@ -4028,6 +4127,61 @@ void wiRenderer::ResolveMSAADepthBuffer(Texture2D* dst, Texture2D* src, GRAPHICS
GetDevice()->EventEnd();
}
void wiRenderer::ComputeVoxelRadiance(GRAPHICSTHREAD threadID)
{
if (!GetVoxelRadianceEnabled())
{
return;
}
if (textures[TEXTYPE_3D_VOXELSCENE] == nullptr)
{
assert(0);
return;
}
GetDevice()->EventBegin("Compute Voxel Radiance", threadID);
wiProfiler::GetInstance().BeginRange("Compute Voxel Radiance", wiProfiler::DOMAIN_GPU, threadID);
if (textures[TEXTYPE_3D_VOXELRADIANCE] == nullptr)
{
Texture3DDesc desc;
ZeroMemory(&desc, sizeof(desc));
desc.Width = ((Texture3D*)textures[TEXTYPE_3D_VOXELSCENE])->GetDesc().Width;
desc.Height = ((Texture3D*)textures[TEXTYPE_3D_VOXELSCENE])->GetDesc().Height;
desc.Depth = ((Texture3D*)textures[TEXTYPE_3D_VOXELSCENE])->GetDesc().Depth;
desc.MipLevels = 1;
desc.Format = FORMAT_R8G8B8A8_UNORM;
desc.BindFlags = BIND_UNORDERED_ACCESS | BIND_SHADER_RESOURCE;
desc.Usage = USAGE_DEFAULT;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
textures[TEXTYPE_3D_VOXELRADIANCE] = new Texture3D;
HRESULT hr = GetDevice()->CreateTexture3D(&desc, nullptr, (Texture3D**)&textures[TEXTYPE_3D_VOXELRADIANCE]);
assert(SUCCEEDED(hr));
}
GetDevice()->BindRenderTargets(0, nullptr, nullptr, threadID);
GetDevice()->BindResourceCS(textures[TEXTYPE_3D_VOXELSCENE], 0, threadID);
GetDevice()->BindUnorderedAccessResourceCS(textures[TEXTYPE_3D_VOXELRADIANCE], 0, threadID);
Texture3DDesc desc = ((Texture3D*)textures[TEXTYPE_3D_VOXELRADIANCE])->GetDesc();
GetDevice()->BindCS(computeShaders[CSTYPE_VOXELRADIANCE], threadID);
GetDevice()->Dispatch((UINT)ceilf(desc.Width / 4.f), (UINT)ceilf(desc.Height / 4.f), (UINT)ceilf(desc.Depth / 4.f), threadID);
GetDevice()->BindCS(nullptr, threadID);
GetDevice()->UnBindResources(0, 1, threadID);
GetDevice()->UnBindUnorderedAccessResources(0, 1, threadID);
GetDevice()->BindResourcePS(textures[TEXTYPE_3D_VOXELRADIANCE], TEXSLOT_VOXELRADIANCE, threadID);
wiProfiler::GetInstance().EndRange(threadID);
GetDevice()->EventEnd();
}
void wiRenderer::ManageDecalAtlas(GRAPHICSTHREAD threadID)
{
@@ -4117,6 +4271,7 @@ void wiRenderer::UpdateWorldCB(GRAPHICSTHREAD threadID)
value.mHorizon = world.horizon;
value.mZenith = world.zenith;
value.mScreenWidthHeight = XMFLOAT2((float)GetDevice()->GetScreenWidth(), (float)GetDevice()->GetScreenHeight());
value.mVoxelRadianceScale = voxelRadianceScale;
if (memcmp(&prevcb[threadID], &value, sizeof(WorldCB)) != 0)
{
@@ -4132,7 +4287,7 @@ void wiRenderer::UpdateFrameCB(GRAPHICSTHREAD threadID)
cb.mWindTime = wind.time;
cb.mWindRandomness = wind.randomness;
cb.mWindWaveSize = wind.waveSize;
cb.mWindDirection = wind.direction;
cb.mWindDirection = wind.direction;
cb.mSunLightArrayIndex = GetSunArrayIndex();
auto camera = getCamera();
@@ -4764,7 +4919,6 @@ void wiRenderer::CreateImpostor(Mesh* mesh)
const XMFLOAT3 extents = bbox.getHalfWidth();
if (!mesh->impostorTarget.IsInitialized())
{
// TODO: Validate MRT format mismatch??? (Seems to work on Nvidia GT525M)
mesh->impostorTarget.Initialize(res * 6, res, true, FORMAT_R8G8B8A8_UNORM, 0);
mesh->impostorTarget.Add(FORMAT_R8G8B8A8_UNORM); // normal
mesh->impostorTarget.Add(FORMAT_R8_UNORM); // roughness
+6 -1
View File
@@ -91,7 +91,7 @@ public:
XMFLOAT3 mAmbient; float pad2;
XMFLOAT3 mFog; float pad3;
XMFLOAT2 mScreenWidthHeight;
float pad4;
float mVoxelRadianceScale;
float pad5;
CB_SETBINDSLOT(CBSLOT_RENDERER_WORLD)
@@ -293,6 +293,7 @@ protected:
static bool debugLightCulling;
static bool occlusionCulling;
static bool voxelRadiance;
public:
static string SHADERPATH;
@@ -333,6 +334,8 @@ public:
static bool GetDebugLightCulling() { return debugLightCulling; }
static void SetOcclusionCullingEnabled(bool enabled) { occlusionCulling = enabled; }
static bool GetOcclusionCullingEnabled() { return occlusionCulling; }
static void SetVoxelRadianceEnabled(bool enabled) { voxelRadiance = enabled; }
static bool GetVoxelRadianceEnabled() { return voxelRadiance; }
static bool IsRequestedReflectionRendering() { return requestReflectionRendering; }
static wiGraphicsTypes::Texture2D* GetColorGrading(){return colorGrading;};
static void SetColorGrading(wiGraphicsTypes::Texture2D* tex){colorGrading=tex;};
@@ -411,9 +414,11 @@ public:
static void DrawLensFlares(GRAPHICSTHREAD threadID);
static void DrawDecals(Camera* camera, GRAPHICSTHREAD threadID);
static void RefreshEnvProbes(GRAPHICSTHREAD threadID);
static void VoxelizeScene(GRAPHICSTHREAD threadID);
static void ComputeTiledLightCulling(GRAPHICSTHREAD threadID);
static void ResolveMSAADepthBuffer(wiGraphicsTypes::Texture2D* dst, wiGraphicsTypes::Texture2D* src, GRAPHICSTHREAD threadID);
static void ComputeVoxelRadiance(GRAPHICSTHREAD threadID);
static void ManageDecalAtlas(GRAPHICSTHREAD threadID);
+2 -2
View File
@@ -5,9 +5,9 @@ namespace wiVersion
// main engine core
const int major = 0;
// minor features, major updates
const int minor = 9;
const int minor = 10;
// minor bug fixes, alterations, refactors, updates
const int revision = 70;
const int revision = 0;
long GetVersion()