@@ -69,6 +69,9 @@ float4 main(v2f IN) : SV_Target0
6969 D3D12_STATIC_SAMPLER_DESC staticSamp = {};
7070 staticSamp.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
7171 staticSamp.AddressU = staticSamp.AddressV = staticSamp.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
72+ // LOD is clamped to 0 since input SRV has multiple mips for subresource-modification
73+ // validation, but only the first one is considered as output result.
74+ staticSamp.MinLOD = staticSamp.MaxLOD = 0 ;
7275 staticSamp.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
7376
7477 ID3D12RootSignaturePtr sig = MakeSig (
@@ -86,11 +89,15 @@ float4 main(v2f IN) : SV_Target0
8689 heap.MemoryPoolPreference = D3D12_MEMORY_POOL_L0;
8790 heap.Type = D3D12_HEAP_TYPE_CUSTOM;
8891
89- uint32_t *texData = new uint32_t [2048 * 2084 ];
92+ const size_t width = 2048 , height = 2048 ;
93+ const UINT subresourceIdx = 8 ;
9094
91- ID3D12ResourcePtr tex = MakeTexture (DXGI_FORMAT_R8G8B8A8_UNORM, 2048 , 2048 )
95+ uint32_t *baseData = new uint32_t [width * height];
96+ uint32_t *subresourceData = new uint32_t [(width * height) >> (2 * subresourceIdx)];
97+
98+ ID3D12ResourcePtr tex = MakeTexture (DXGI_FORMAT_R8G8B8A8_UNORM, width, height)
9299 .CustomHeap (heap)
93- .Mips (1 )
100+ .Mips (12 )
94101 .InitialState (D3D12_RESOURCE_STATE_COMMON);
95102
96103 D3D12_GPU_DESCRIPTOR_HANDLE view =
@@ -102,15 +109,36 @@ float4 main(v2f IN) : SV_Target0
102109
103110 GPUSync ();
104111
105- tex->Map (0 , NULL , NULL );
112+ {
113+ const size_t rowPitch = width * sizeof (uint32_t ), depthPitch = rowPitch * height;
114+
115+ tex->Map (0 , NULL , NULL );
116+
117+ memset (baseData, 0x00 , depthPitch);
118+ tex->WriteToSubresource (0 , NULL , baseData, rowPitch, depthPitch);
119+
120+ D3D12_BOX box = {400 , 400 , 0 , 1600 , 1600 , 1 };
121+ memset (baseData, 0xff , depthPitch);
122+ tex->WriteToSubresource (0 , &box, baseData, rowPitch, depthPitch);
123+
124+ tex->Unmap (0 , NULL );
125+ }
126+
127+ {
128+ const size_t rowPitch = (width >> subresourceIdx) * sizeof (uint32_t ),
129+ depthPitch = rowPitch * (height >> subresourceIdx);
130+
131+ tex->Map (subresourceIdx, NULL , NULL );
132+
133+ memset (subresourceData, 0x00 , depthPitch);
134+ tex->WriteToSubresource (subresourceIdx, NULL , subresourceData, rowPitch, depthPitch);
106135
107- memset (texData, 0 , 2048 * 2048 * sizeof (uint32_t ));
108- tex->WriteToSubresource (0 , NULL , texData, 1024 * 4 , 1024 * 1024 );
109- D3D12_BOX box = {400 , 400 , 0 , 1600 , 1600 , 1 };
110- memset (texData, 0xff , 2048 * 2048 * sizeof (uint32_t ));
111- tex->WriteToSubresource (0 , &box, texData, 1024 * 4 , 1024 * 1024 );
136+ D3D12_BOX box = {1 , 1 , 0 , 7 , 7 , 1 };
137+ memset (subresourceData, 0xff , depthPitch);
138+ tex->WriteToSubresource (subresourceIdx, &box, subresourceData, rowPitch, depthPitch);
112139
113- tex->Unmap (0 , NULL );
140+ tex->Unmap (subresourceIdx, NULL );
141+ }
114142
115143 GPUSync ();
116144
0 commit comments