format aware texture2d copy utility
This commit is contained in:
@@ -27,7 +27,8 @@
|
||||
#define CBSLOT_RENDERER_DISPATCHPARAMS 8
|
||||
#define CBSLOT_RENDERER_VOXELIZER 8
|
||||
#define CBSLOT_RENDERER_TRACED 8
|
||||
#define CBSLOT_RENDERER_BVH 8
|
||||
#define CBSLOT_RENDERER_BVH 8
|
||||
#define CBSLOT_RENDERER_UTILITY 8
|
||||
|
||||
#define CBSLOT_OTHER_EMITTEDPARTICLE 8
|
||||
#define CBSLOT_OTHER_HAIRPARTICLE 8
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef _SHADERINTEROP_UTILITY_H_
|
||||
#define _SHADERINTEROP_UTILITY_H_
|
||||
#include "ShaderInterop.h"
|
||||
|
||||
CBUFFER(CopyTextureCB, CBSLOT_RENDERER_UTILITY)
|
||||
{
|
||||
uint2 xCopyDest;
|
||||
uint2 padding0;
|
||||
};
|
||||
|
||||
#endif //_SHADERINTEROP_UTILITY_H_
|
||||
@@ -70,6 +70,10 @@
|
||||
<FxCompile Include="colorGradePS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
|
||||
</FxCompile>
|
||||
<FxCompile Include="copytexture2Dregion_unorm4CS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
|
||||
</FxCompile>
|
||||
<FxCompile Include="cubeMapPS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
|
||||
</FxCompile>
|
||||
|
||||
@@ -756,6 +756,9 @@
|
||||
<FxCompile Include="raytrace_kickjobsCS.hlsl">
|
||||
<Filter>CS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="copytexture2Dregion_unorm4CS.hlsl">
|
||||
<Filter>CS</Filter>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="PS">
|
||||
|
||||
@@ -246,6 +246,7 @@
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop_GPUSortLib.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop_Ocean.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop_Skinning.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop_Utility.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop_Vulkan.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)TiledDeferredRenderableComponent.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)TiledDeferredRenderableComponent_BindLua.h" />
|
||||
|
||||
@@ -1185,6 +1185,9 @@
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)PathTracingRenderableComponent.h">
|
||||
<Filter>ENGINE\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop_Utility.h">
|
||||
<Filter>ENGINE\Graphics\GPUMapping</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)LUA\lapi.c">
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "globals.hlsli"
|
||||
#include "ShaderInterop_Utility.h"
|
||||
|
||||
TEXTURE2D(input, float4, TEXSLOT_ONDEMAND0);
|
||||
|
||||
RWTEXTURE2D(output, unorm float4, 0);
|
||||
|
||||
[numthreads(8, 8, 1)]
|
||||
void main( uint3 DTid : SV_DispatchThreadID )
|
||||
{
|
||||
output[DTid.xy + xCopyDest] = input[DTid.xy];
|
||||
}
|
||||
@@ -83,6 +83,7 @@ enum CBTYPES
|
||||
CBTYPE_CLOUDGENERATOR,
|
||||
CBTYPE_BVH,
|
||||
CBTYPE_RAYTRACE,
|
||||
CBTYPE_COPYTEXTURE,
|
||||
CBTYPE_LAST
|
||||
};
|
||||
|
||||
@@ -269,6 +270,7 @@ enum CSTYPES
|
||||
CSTYPE_GENERATEMIPCHAIN2D_GAUSSIAN,
|
||||
CSTYPE_GENERATEMIPCHAIN3D_SIMPLEFILTER,
|
||||
CSTYPE_GENERATEMIPCHAIN3D_GAUSSIAN,
|
||||
CSTYPE_COPYTEXTURE2DREGION_UNORM4,
|
||||
CSTYPE_SKINNING,
|
||||
CSTYPE_SKINNING_LDS,
|
||||
CSTYPE_CLOUDGENERATOR,
|
||||
|
||||
+67
-12
@@ -28,6 +28,7 @@
|
||||
#include "ShaderInterop_Skinning.h"
|
||||
#include "ShaderInterop_TracedRendering.h"
|
||||
#include "ShaderInterop_BVH.h"
|
||||
#include "ShaderInterop_Utility.h"
|
||||
#include "wiWidget.h"
|
||||
#include "wiGPUSortLib.h"
|
||||
|
||||
@@ -603,6 +604,9 @@ void wiRenderer::LoadBuffers()
|
||||
bd.ByteWidth = sizeof(BVHCB);
|
||||
GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_BVH]);
|
||||
|
||||
bd.ByteWidth = sizeof(CopyTextureCB);
|
||||
GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_COPYTEXTURE]);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1472,6 +1476,7 @@ void wiRenderer::LoadShaders()
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN2D_GAUSSIAN] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain2D_GaussianCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN3D_SIMPLEFILTER] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain3D_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_GENERATEMIPCHAIN3D_GAUSSIAN] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain3D_GaussianCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_COPYTEXTURE2DREGION_UNORM4] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "copytexture2Dregion_unorm4CS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_SKINNING] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "skinningCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_SKINNING_LDS] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "skinningCS_LDS.cso", wiResourceManager::COMPUTESHADER));
|
||||
computeShaders[CSTYPE_CLOUDGENERATOR] = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cloudGeneratorCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
@@ -1761,6 +1766,7 @@ void wiRenderer::LoadShaders()
|
||||
desc.rs = rasterizers[RSTYPE_FRONT];
|
||||
desc.bs = blendStates[BSTYPE_DECAL];
|
||||
desc.dss = depthStencils[DSSTYPE_DECAL];
|
||||
desc.pt = TRIANGLESTRIP;
|
||||
|
||||
desc.numRTs = 1;
|
||||
desc.RTFormats[0] = RTFormat_gbuffer_0;
|
||||
@@ -6330,6 +6336,56 @@ void wiRenderer::GenerateMipChain(Texture3D* texture, MIPGENFILTER filter, GRAPH
|
||||
GetDevice()->EventEnd(threadID);
|
||||
}
|
||||
|
||||
void wiRenderer::CopyTexture2D_Region(Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY, Texture2D* src, UINT SrcMIP, GRAPHICSTHREAD threadID)
|
||||
{
|
||||
GraphicsDevice* device = GetDevice();
|
||||
|
||||
const TextureDesc& desc_dst = dst->GetDesc();
|
||||
const TextureDesc& desc_src = src->GetDesc();
|
||||
|
||||
assert(desc_dst.BindFlags & BIND_UNORDERED_ACCESS);
|
||||
assert(desc_src.BindFlags & BIND_SHADER_RESOURCE);
|
||||
|
||||
device->EventBegin("CopyTexture2D_Region_UNORM4", threadID);
|
||||
|
||||
device->BindComputePSO(CPSO[CSTYPE_COPYTEXTURE2DREGION_UNORM4], threadID);
|
||||
|
||||
CopyTextureCB cb;
|
||||
cb.xCopyDest.x = DstX;
|
||||
cb.xCopyDest.y = DstY;
|
||||
device->UpdateBuffer(constantBuffers[CBTYPE_COPYTEXTURE], &cb, threadID);
|
||||
|
||||
device->BindConstantBuffer(CS, constantBuffers[CBTYPE_COPYTEXTURE], CB_GETBINDSLOT(CopyTextureCB), threadID);
|
||||
|
||||
//if (SrcMIP > 0)
|
||||
//{
|
||||
// assert(desc_src.MipLevels > SrcMIP);
|
||||
// device->BindResource(CS, src, TEXSLOT_ONDEMAND0, threadID, SrcMIP);
|
||||
//}
|
||||
//else
|
||||
{
|
||||
device->BindResource(CS, src, TEXSLOT_ONDEMAND0, threadID);
|
||||
}
|
||||
|
||||
if (DstMIP > 0)
|
||||
{
|
||||
assert(desc_dst.MipLevels > DstMIP);
|
||||
device->BindUnorderedAccessResourceCS(dst, 0, threadID, DstMIP);
|
||||
}
|
||||
else
|
||||
{
|
||||
device->BindUnorderedAccessResourceCS(dst, 0, threadID);
|
||||
}
|
||||
|
||||
device->Dispatch((UINT)ceilf((float)desc_src.Width / 8.0f), (UINT)ceilf((float)desc_src.Height / 8.0f), 1, threadID);
|
||||
|
||||
device->UnBindUnorderedAccessResources(0, 1, threadID);
|
||||
|
||||
device->EventEnd(threadID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Should I care that usually buffers are not declared here?
|
||||
static GPUBuffer* bvhNodeBuffer = nullptr;
|
||||
static GPUBuffer* bvhAABBBuffer = nullptr;
|
||||
@@ -6851,25 +6907,19 @@ void wiRenderer::DrawTracedScene(Camera* camera, wiGraphicsTypes::Texture2D* res
|
||||
desc.Height = (UINT)bins[0].size.h;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = FORMAT_B8G8R8A8_UNORM;
|
||||
desc.Format = FORMAT_R8G8B8A8_UNORM;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = USAGE_DEFAULT;
|
||||
desc.BindFlags = BIND_SHADER_RESOURCE;
|
||||
desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
device->CreateTexture2D(&desc, nullptr, &atlasTexture);
|
||||
|
||||
for (UINT mip = 0; mip < atlasTexture->GetDesc().MipLevels; ++mip)
|
||||
for (auto& it : storedTextures)
|
||||
{
|
||||
for (auto& it : storedTextures)
|
||||
{
|
||||
if (mip < it.first->GetDesc().MipLevels)
|
||||
{
|
||||
device->CopyTexture2D_Region(atlasTexture, mip, it.second.x >> mip, it.second.y >> mip, it.first, mip, threadID);
|
||||
}
|
||||
}
|
||||
CopyTexture2D_Region(atlasTexture, 0, it.second.x, it.second.y, it.first, 0, threadID);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -7225,14 +7275,18 @@ void wiRenderer::ManageDecalAtlas(GRAPHICSTHREAD threadID)
|
||||
desc.Height = (UINT)bins[0].size.h;
|
||||
desc.MipLevels = 6;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = FORMAT_B8G8R8A8_UNORM; // png decals are loaded into this format! todo: DXT!
|
||||
//desc.Format = FORMAT_R8G8B8A8_UNORM;
|
||||
desc.Format = FORMAT_B8G8R8A8_UNORM; // png decals are loaded into this format! todo: Utility copytexture2d srcMIP!!!
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = USAGE_DEFAULT;
|
||||
desc.BindFlags = BIND_SHADER_RESOURCE;
|
||||
desc.BindFlags = BIND_SHADER_RESOURCE /*| BIND_UNORDERED_ACCESS*/;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
atlasTexture = new Texture2D;
|
||||
atlasTexture->RequestIndependentUnorderedAccessResourcesForMIPs(true);
|
||||
|
||||
device->CreateTexture2D(&desc, nullptr, &atlasTexture);
|
||||
|
||||
for (UINT mip = 0; mip < atlasTexture->GetDesc().MipLevels; ++mip)
|
||||
@@ -7242,6 +7296,7 @@ void wiRenderer::ManageDecalAtlas(GRAPHICSTHREAD threadID)
|
||||
if (mip < it.first->GetDesc().MipLevels)
|
||||
{
|
||||
device->CopyTexture2D_Region(atlasTexture, mip, it.second.x >> mip, it.second.y >> mip, it.first, mip, threadID);
|
||||
//CopyTexture2D_Region(atlasTexture, mip, it.second.x >> mip, it.second.y >> mip, it.first, mip, threadID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,6 +512,9 @@ public:
|
||||
static void GenerateMipChain(wiGraphicsTypes::Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID);
|
||||
static void GenerateMipChain(wiGraphicsTypes::Texture3D* texture, MIPGENFILTER filter, GRAPHICSTHREAD threadID);
|
||||
|
||||
// Performs copy operation even between different texture formats
|
||||
static void CopyTexture2D_Region(wiGraphicsTypes::Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY, wiGraphicsTypes::Texture2D* src, UINT SrcMIP, GRAPHICSTHREAD threadID);
|
||||
|
||||
// dst: Texture2D with unordered access, the output will be written to this
|
||||
// refinementCount: 0: auto select, 1: perfect noise, greater numbers: smoother clouds, slower processing
|
||||
// randomness: random seed
|
||||
|
||||
@@ -186,14 +186,14 @@ Texture2D* wiTextureHelper::wiTextureHelperInstance::getColor(const wiColor& col
|
||||
unsigned char* data = new unsigned char[dataLength];
|
||||
for (int i = 0; i < dataLength; i += 4)
|
||||
{
|
||||
data[i] = color.b;
|
||||
data[i] = color.r;
|
||||
data[i + 1] = color.g;
|
||||
data[i + 2] = color.r;
|
||||
data[i + 2] = color.b;
|
||||
data[i + 3] = color.a;
|
||||
}
|
||||
|
||||
Texture2D* texture = nullptr;
|
||||
if (FAILED(CreateTexture(texture, data, 1, 1, 4, FORMAT_B8G8R8A8_UNORM)))
|
||||
if (FAILED(CreateTexture(texture, data, 1, 1, 4)))
|
||||
{
|
||||
delete[] data;
|
||||
return nullptr;
|
||||
|
||||
Reference in New Issue
Block a user