Skip to content

Commit a63bad2

Browse files
GPUUploadManager: add Format parameter to ScheduleTextureUpdateInfo
1 parent a1684cb commit a63bad2

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

Graphics/GraphicsTools/interface/GPUUploadManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ struct ScheduleTextureUpdateInfo
379379
/// Otherwise, this texture will be used as the destination for the copy operation
380380
ITexture* pDstTexture DEFAULT_INITIALIZER(nullptr);
381381

382+
/// Destination texture format, used when pDstTexture is null.
383+
TEXTURE_FORMAT Format DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN);
384+
382385
/// State transition mode for the destination texture. This parameter is ignored if CopyTexture/CopyD3D11Texture callback is provided,
383386
/// and the callback is expected to perform any necessary state transitions itself.
384387
RESOURCE_STATE_TRANSITION_MODE DstTextureTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_TRANSITION);

Graphics/GraphicsTools/src/GPUUploadManagerImpl.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,12 @@ bool GPUUploadManagerImpl::Page::ScheduleTextureUpdate(const ScheduleTextureUpda
411411
}
412412
else if (m_pStagingAtlas)
413413
{
414-
const TextureFormatAttribs& FmtAttribs = GetTextureFormatAttribs(UpdateInfo.pDstTexture->GetDesc().Format);
414+
const TEXTURE_FORMAT Format = UpdateInfo.pDstTexture != nullptr ?
415+
UpdateInfo.pDstTexture->GetDesc().Format :
416+
UpdateInfo.Format;
417+
VERIFY_EXPR(Format != TEX_FORMAT_UNKNOWN);
418+
419+
const TextureFormatAttribs& FmtAttribs = GetTextureFormatAttribs(Format);
415420

416421
DynamicAtlasManager::Region Region = m_pStagingAtlas->Allocate(
417422
AlignUp(UpdateInfo.DstBox.Width(), FmtAttribs.BlockWidth),
@@ -440,7 +445,12 @@ bool GPUUploadManagerImpl::Page::ScheduleTextureUpdate(const ScheduleTextureUpda
440445
}
441446
else if (UpdateInfo.pSrcData != nullptr)
442447
{
443-
const TextureFormatAttribs& FmtAttribs = GetTextureFormatAttribs(UpdateInfo.pDstTexture->GetDesc().Format);
448+
const TEXTURE_FORMAT Format = UpdateInfo.pDstTexture != nullptr ?
449+
UpdateInfo.pDstTexture->GetDesc().Format :
450+
UpdateInfo.Format;
451+
VERIFY_EXPR(Format != TEX_FORMAT_UNKNOWN);
452+
453+
const TextureFormatAttribs& FmtAttribs = GetTextureFormatAttribs(Format);
444454
const Uint32 NumRows = AlignUp(UpdateInfo.DstBox.Height(), FmtAttribs.BlockHeight) / FmtAttribs.BlockHeight;
445455
for (Uint32 DepthSlice = 0; DepthSlice < UpdateInfo.DstBox.Depth(); ++DepthSlice)
446456
{
@@ -1100,14 +1110,15 @@ void GPUUploadManagerImpl::ScheduleBufferUpdate(const ScheduleBufferUpdateInfo&
11001110

11011111
void GPUUploadManagerImpl::ScheduleTextureUpdate(const ScheduleTextureUpdateInfo& UpdateInfo)
11021112
{
1103-
if (UpdateInfo.pDstTexture == nullptr)
1113+
const TEXTURE_FORMAT Format = UpdateInfo.pDstTexture != nullptr ?
1114+
UpdateInfo.pDstTexture->GetDesc().Format :
1115+
UpdateInfo.Format;
1116+
if (Format == TEX_FORMAT_UNKNOWN)
11041117
{
1105-
DEV_ERROR("Dst texture must not be null");
1118+
DEV_ERROR("If pDstTexture is null, a valid format must be specified in ScheduleTextureUpdateInfo.Format");
11061119
return;
11071120
}
11081121

1109-
const TextureDesc& TexDesc = UpdateInfo.pDstTexture->GetDesc();
1110-
11111122
struct ScheduleUpdateData
11121123
{
11131124
const ScheduleTextureUpdateInfo& UpdateInfo;
@@ -1117,15 +1128,15 @@ void GPUUploadManagerImpl::ScheduleTextureUpdate(const ScheduleTextureUpdateInfo
11171128
ScheduleUpdateData UpdateData{
11181129
UpdateInfo,
11191130
!m_pTextureStreams ?
1120-
GetBufferToTextureCopyInfo(TexDesc.Format, UpdateInfo.DstBox, m_TextureUpdateStrideAlignment) :
1131+
GetBufferToTextureCopyInfo(Format, UpdateInfo.DstBox, m_TextureUpdateStrideAlignment) :
11211132
BufferToTextureCopyInfo{},
11221133
!m_pTextureStreams ?
11231134
m_TextureUpdateOffsetAlignment :
11241135
0,
11251136
};
11261137

11271138
UploadStream* pStream = m_pTextureStreams ?
1128-
m_pTextureStreams->GetStreamForFormat(UpdateData.UpdateInfo.pContext, TexDesc.Format) :
1139+
m_pTextureStreams->GetStreamForFormat(UpdateData.UpdateInfo.pContext, Format) :
11291140
&GetStreamForUpdateSize(static_cast<Uint32>(UpdateData.CopyInfo.MemorySize));
11301141
if (pStream == nullptr)
11311142
{

Tests/DiligentCoreAPITest/src/GPUUploadManagerTest.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,15 @@ void TestTextureUpdates(TEXTURE_FORMAT Format, RESOURCE_DIMENSION Type, Uint32 F
816816
for (Uint32 x = 0; x < Mip.LogicalWidth; x += UpdateWidth)
817817
{
818818
ScheduleTextureUpdateInfo UpdateInfo;
819-
UpdateInfo.pContext = pContext;
820-
UpdateInfo.pDstTexture = pTexture;
819+
UpdateInfo.pContext = pContext;
820+
if (Flags & TEST_TEXTURE_UPDATES_FLAGS_USE_COPY_CALLBACK)
821+
{
822+
UpdateInfo.Format = Format;
823+
}
824+
else
825+
{
826+
UpdateInfo.pDstTexture = pTexture;
827+
}
821828

822829
Box& DstBox{UpdateInfo.DstBox};
823830
DstBox.MinX = x;

0 commit comments

Comments
 (0)