2626
2727#include " GPUTestingEnvironment.hpp"
2828#include " FastRand.hpp"
29+ #include " GraphicsAccessories.hpp"
2930
3031#include " gtest/gtest.h"
3132
@@ -59,24 +60,20 @@ struct AxisSplit
5960 Uint32 Size = 0 ;
6061};
6162
62- AxisSplit GetAxisSplit (Uint32 Dim, Uint32 Split)
63+ AxisSplit GetAxisSplit (Uint32 Dim, Uint32 NumSplits, Uint32 Split)
6364{
64- if (Dim <= 1 )
65- return {0 , 1 };
66-
67- const Uint32 Half = Dim / 2 ;
68- return Split == 0 ?
69- AxisSplit{0 , Half} :
70- AxisSplit{Half, Dim - Half};
65+ return AxisSplit{
66+ Split * (Dim / NumSplits),
67+ Dim / NumSplits,
68+ };
7169}
7270
7371TextureDesc CreateTestTextureDesc (const char * Name,
7472 RESOURCE_DIMENSION Type,
7573 TEXTURE_FORMAT Format,
7674 Uint32 Width,
7775 Uint32 Height,
78- Uint32 ArraySizeOrDepth,
79- Uint32 MipLevels)
76+ Uint32 ArraySizeOrDepth)
8077{
8178 TextureDesc TexDesc;
8279 TexDesc.Name = Name;
@@ -85,7 +82,7 @@ TextureDesc CreateTestTextureDesc(const char* Name,
8582 TexDesc.BindFlags = BIND_SHADER_RESOURCE;
8683 TexDesc.Width = Width;
8784 TexDesc.Height = Height;
88- TexDesc.MipLevels = MipLevels ;
85+ TexDesc.MipLevels = ComputeMipLevelsCount (TexDesc) ;
8986 TexDesc.Usage = USAGE_DEFAULT;
9087
9188 if (Type == RESOURCE_DIM_TEX_3D)
@@ -161,45 +158,42 @@ void RunCopyBufferToTextureTest(const TextureDesc& BaseTexDesc)
161158 auto & Subres = RefSubresources[GetSubresourceIndex (mip, slice)];
162159 Subres.resize (static_cast <size_t >(Mip.MipSize ));
163160
164- const Uint32 MipWidth = Mip.LogicalWidth ;
165- const Uint32 MipHeight = Mip.LogicalHeight ;
166- const Uint32 MipDepth = Mip.Depth ;
167- VERIFY ((MipWidth % FmtAttribs.BlockWidth ) == 0 , " Logical mip width (" , MipWidth, " ) is expected to be a multiple of block width (" , FmtAttribs.BlockWidth , " )" );
168- VERIFY ((MipHeight % FmtAttribs.BlockHeight ) == 0 , " Logical mip height (" , MipHeight, " ) is expected to be a multiple of block height (" , FmtAttribs.BlockHeight , " )" );
161+ VERIFY ((Mip.StorageWidth % FmtAttribs.BlockWidth ) == 0 , " Storage mip width (" , Mip.StorageWidth , " ) is expected to be a multiple of block width (" , FmtAttribs.BlockWidth , " )" );
162+ VERIFY ((Mip.StorageHeight % FmtAttribs.BlockHeight ) == 0 , " Storage mip height (" , Mip.StorageHeight , " ) is expected to be a multiple of block height (" , FmtAttribs.BlockHeight , " )" );
169163
170164 for (Uint8& pixel : Subres)
171165 pixel = static_cast <Uint8>(rnd ());
172166
173- const Uint32 NumXSplits = MipWidth > 1 ? 2u : 1u ;
174- const Uint32 NumYSplits = MipHeight > 1 ? 2u : 1u ;
175- const Uint32 NumZSplits = MipDepth > 1 ? 2u : 1u ;
167+ const Uint32 NumXSplits = Mip. LogicalWidth > FmtAttribs. BlockWidth ? 2u : 1u ;
168+ const Uint32 NumYSplits = Mip. LogicalHeight > FmtAttribs. BlockHeight ? 2u : 1u ;
169+ const Uint32 NumZSplits = Mip. Depth > 1 ? 2u : 1u ;
176170
177171 for (Uint32 zSplit = 0 ; zSplit < NumZSplits; ++zSplit)
178172 {
179- const AxisSplit Z = GetAxisSplit (MipDepth , zSplit);
173+ const AxisSplit Z = GetAxisSplit (Mip. Depth , NumZSplits , zSplit);
180174
181175 for (Uint32 ySplit = 0 ; ySplit < NumYSplits; ++ySplit)
182176 {
183- const AxisSplit Y = GetAxisSplit (MipHeight , ySplit);
177+ const AxisSplit Y = GetAxisSplit (Mip. LogicalHeight , NumYSplits , ySplit);
184178
185179 for (Uint32 xSplit = 0 ; xSplit < NumXSplits; ++xSplit)
186180 {
187- const AxisSplit X = GetAxisSplit (MipWidth , xSplit);
181+ const AxisSplit X = GetAxisSplit (Mip. LogicalWidth , NumXSplits , xSplit);
188182
189183 const Uint64 AlignedOffset = AlignUp (static_cast <Uint64>(UploadData.size ()),
190184 static_cast <Uint64>(TextureUpdateOffsetAlignment));
191185 UploadData.resize (static_cast <size_t >(AlignedOffset));
192186
193- const Uint32 Stride = AlignUp (X.Size / FmtAttribs.BlockWidth * ElementSize, TextureUpdateStrideAlignment);
194- const Uint32 DepthStride = Y.Size / FmtAttribs.BlockHeight * Stride;
187+ const Uint32 Stride = AlignUp (AlignUp ( X.Size , FmtAttribs. BlockWidth ) / FmtAttribs.BlockWidth * ElementSize, TextureUpdateStrideAlignment);
188+ const Uint32 DepthStride = AlignUp ( Y.Size , FmtAttribs. BlockHeight ) / FmtAttribs.BlockHeight * Stride;
195189 const Uint64 SrcOffset = static_cast <Uint64>(UploadData.size ());
196190 const Uint64 RegionSize = static_cast <Uint64>(Z.Size ) * DepthStride;
197191
198192 UploadData.resize (static_cast <size_t >(SrcOffset + RegionSize));
199193
200194 for (Uint32 z = 0 ; z < Z.Size ; ++z)
201195 {
202- for (Uint32 row = 0 ; row < Y.Size / FmtAttribs.BlockHeight ; ++row)
196+ for (Uint32 row = 0 ; row < AlignUp ( Y.Size , FmtAttribs. BlockHeight ) / FmtAttribs.BlockHeight ; ++row)
203197 {
204198 const Uint8* pSrcRow =
205199 &Subres[static_cast <size_t >(
@@ -213,7 +207,7 @@ void RunCopyBufferToTextureTest(const TextureDesc& BaseTexDesc)
213207 static_cast <size_t >(z) * DepthStride +
214208 static_cast <size_t >(row) * Stride;
215209
216- memcpy (pDstRow, pSrcRow, X.Size / FmtAttribs.BlockWidth * ElementSize);
210+ memcpy (pDstRow, pSrcRow, AlignUp ( X.Size , FmtAttribs. BlockWidth ) / FmtAttribs.BlockWidth * ElementSize);
217211 }
218212 }
219213
@@ -311,7 +305,7 @@ void RunCopyBufferToTextureTest(const TextureDesc& BaseTexDesc)
311305
312306 for (Uint32 z = 0 ; z < Mip.Depth ; ++z)
313307 {
314- for (Uint32 row = 0 ; row < Mip.LogicalHeight / FmtAttribs.BlockHeight ; ++row)
308+ for (Uint32 row = 0 ; row < AlignUp ( Mip.LogicalHeight , FmtAttribs. BlockHeight ) / FmtAttribs.BlockHeight ; ++row)
315309 {
316310 const void * pRefRow = &Subres[static_cast <size_t >(z * Mip.DepthSliceSize + row * Mip.RowSize )];
317311 const void * pTexRow =
@@ -340,8 +334,7 @@ TEST(UpdateTextureFromBuffer, Texture2D_RGBA8)
340334 TEX_FORMAT_RGBA8_UNORM,
341335 128 ,
342336 128 ,
343- 1 ,
344- 4 ));
337+ 1 ));
345338}
346339
347340
@@ -353,8 +346,7 @@ TEST(UpdateTextureFromBuffer, Texture2D_BC1)
353346 TEX_FORMAT_BC1_UNORM,
354347 512 ,
355348 512 ,
356- 1 ,
357- 4 ));
349+ 1 ));
358350}
359351
360352TEST (UpdateTextureFromBuffer, Texture2DArray_RGBA8)
@@ -365,7 +357,6 @@ TEST(UpdateTextureFromBuffer, Texture2DArray_RGBA8)
365357 TEX_FORMAT_RGBA8_UNORM,
366358 128 ,
367359 128 ,
368- 4 ,
369360 4 ));
370361}
371362
@@ -378,7 +369,6 @@ TEST(UpdateTextureFromBuffer, Texture2DArray_BC1)
378369 TEX_FORMAT_BC1_UNORM,
379370 512 ,
380371 512 ,
381- 4 ,
382372 4 ));
383373}
384374
@@ -390,8 +380,7 @@ TEST(UpdateTextureFromBuffer, Texture3D_RGBA8)
390380 TEX_FORMAT_RGBA8_UNORM,
391381 128 ,
392382 128 ,
393- 8 ,
394- 4 ));
383+ 8 ));
395384}
396385
397386} // namespace
0 commit comments