Skip to content

Commit af5c3fa

Browse files
committed
GPUDevice: Fix mipmap generation on targets
Mainly DX12 that was broken.
1 parent 9a5eadd commit af5c3fa

File tree

8 files changed

+117
-44
lines changed

8 files changed

+117
-44
lines changed

src/util/d3d12_builders.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ void D3D12::RootSignatureBuilder::SetInputAssemblerFlag()
256256
u32 D3D12::RootSignatureBuilder::Add32BitConstants(u32 shader_reg, u32 num_values, D3D12_SHADER_VISIBILITY visibility)
257257
{
258258
const u32 index = m_desc.NumParameters++;
259+
DebugAssert(index < MAX_PARAMETERS);
259260

260261
m_params[index].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
261262
m_params[index].ShaderVisibility = visibility;
@@ -269,6 +270,7 @@ u32 D3D12::RootSignatureBuilder::Add32BitConstants(u32 shader_reg, u32 num_value
269270
u32 D3D12::RootSignatureBuilder::AddCBVParameter(u32 shader_reg, D3D12_SHADER_VISIBILITY visibility)
270271
{
271272
const u32 index = m_desc.NumParameters++;
273+
DebugAssert(index < MAX_PARAMETERS);
272274

273275
m_params[index].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
274276
m_params[index].ShaderVisibility = visibility;
@@ -281,6 +283,7 @@ u32 D3D12::RootSignatureBuilder::AddCBVParameter(u32 shader_reg, D3D12_SHADER_VI
281283
u32 D3D12::RootSignatureBuilder::AddSRVParameter(u32 shader_reg, D3D12_SHADER_VISIBILITY visibility)
282284
{
283285
const u32 index = m_desc.NumParameters++;
286+
DebugAssert(index < MAX_PARAMETERS);
284287

285288
m_params[index].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
286289
m_params[index].ShaderVisibility = visibility;
@@ -295,6 +298,8 @@ u32 D3D12::RootSignatureBuilder::AddDescriptorTable(D3D12_DESCRIPTOR_RANGE_TYPE
295298
{
296299
const u32 index = m_desc.NumParameters++;
297300
const u32 dr_index = m_num_descriptor_ranges++;
301+
DebugAssert(index < MAX_PARAMETERS);
302+
DebugAssert(dr_index < MAX_DESCRIPTOR_RANGES);
298303

299304
m_descriptor_ranges[dr_index].RangeType = rt;
300305
m_descriptor_ranges[dr_index].NumDescriptors = num_shader_regs;
@@ -310,6 +315,53 @@ u32 D3D12::RootSignatureBuilder::AddDescriptorTable(D3D12_DESCRIPTOR_RANGE_TYPE
310315
return index;
311316
}
312317

318+
u32 D3D12::RootSignatureBuilder::AddStaticSampler(u32 shader_reg, const D3D12_SAMPLER_DESC& sampler_desc,
319+
D3D12_SHADER_VISIBILITY visibility)
320+
{
321+
static constexpr const std::pair<std::array<float, 4>, D3D12_STATIC_BORDER_COLOR> border_color_mapping[] = {
322+
{{{0.0f, 0.0f, 0.0f, 0.0f}}, D3D12_STATIC_BORDER_COLOR_TRANSPARENT_BLACK},
323+
{{{0.0f, 0.0f, 0.0f, 1.0f}}, D3D12_STATIC_BORDER_COLOR_OPAQUE_BLACK},
324+
{{{1.0f, 1.0f, 1.0f, 1.0f}}, D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE},
325+
};
326+
327+
const u32 index = m_desc.NumStaticSamplers++;
328+
DebugAssert(index < MAX_STATIC_SAMPLERS);
329+
m_desc.pStaticSamplers = m_static_samplers.data();
330+
331+
D3D12_STATIC_SAMPLER_DESC& ssdesc = m_static_samplers[index];
332+
ssdesc.Filter = sampler_desc.Filter;
333+
ssdesc.AddressU = sampler_desc.AddressU;
334+
ssdesc.AddressV = sampler_desc.AddressV;
335+
ssdesc.AddressW = sampler_desc.AddressW;
336+
ssdesc.MipLODBias = sampler_desc.MipLODBias;
337+
ssdesc.MaxAnisotropy = sampler_desc.MaxAnisotropy;
338+
ssdesc.ComparisonFunc = sampler_desc.ComparisonFunc;
339+
ssdesc.BorderColor = D3D12_STATIC_BORDER_COLOR_TRANSPARENT_BLACK;
340+
if (sampler_desc.AddressU == D3D12_TEXTURE_ADDRESS_MODE_BORDER ||
341+
sampler_desc.AddressV == D3D12_TEXTURE_ADDRESS_MODE_BORDER ||
342+
sampler_desc.AddressW == D3D12_TEXTURE_ADDRESS_MODE_BORDER)
343+
{
344+
u32 i;
345+
for (i = 0; i < static_cast<u32>(std::size(border_color_mapping)); i++)
346+
{
347+
if (std::memcmp(border_color_mapping[i].first.data(), sampler_desc.BorderColor, sizeof(float) * 4) == 0)
348+
break;
349+
}
350+
if (i == std::size(border_color_mapping))
351+
Panic("Unsupported border color");
352+
else
353+
ssdesc.BorderColor = border_color_mapping[i].second;
354+
}
355+
356+
ssdesc.MinLOD = sampler_desc.MinLOD;
357+
ssdesc.MaxLOD = sampler_desc.MaxLOD;
358+
ssdesc.ShaderRegister = shader_reg;
359+
ssdesc.RegisterSpace = 0;
360+
ssdesc.ShaderVisibility = visibility;
361+
362+
return index;
363+
}
364+
313365
#ifdef ENABLE_GPU_OBJECT_NAMES
314366

315367
void D3D12::SetObjectName(ID3D12Object* object, std::string_view name)

src/util/d3d12_builders.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class RootSignatureBuilder
2222
enum : u32
2323
{
2424
MAX_PARAMETERS = 16,
25-
MAX_DESCRIPTOR_RANGES = 16
25+
MAX_DESCRIPTOR_RANGES = 16,
26+
MAX_STATIC_SAMPLERS = 1,
2627
};
2728

2829
RootSignatureBuilder();
@@ -38,11 +39,13 @@ class RootSignatureBuilder
3839
u32 AddSRVParameter(u32 shader_reg, D3D12_SHADER_VISIBILITY visibility);
3940
u32 AddDescriptorTable(D3D12_DESCRIPTOR_RANGE_TYPE rt, u32 start_shader_reg, u32 num_shader_regs,
4041
D3D12_SHADER_VISIBILITY visibility);
42+
u32 AddStaticSampler(u32 shader_reg, const D3D12_SAMPLER_DESC& sampler_desc, D3D12_SHADER_VISIBILITY visibility);
4143

4244
private:
4345
D3D12_ROOT_SIGNATURE_DESC m_desc{};
4446
std::array<D3D12_ROOT_PARAMETER, MAX_PARAMETERS> m_params{};
4547
std::array<D3D12_DESCRIPTOR_RANGE, MAX_DESCRIPTOR_RANGES> m_descriptor_ranges{};
48+
std::array<D3D12_STATIC_SAMPLER_DESC, MAX_STATIC_SAMPLERS> m_static_samplers{};
4649
u32 m_num_descriptor_ranges = 0;
4750
};
4851

src/util/d3d12_device.cpp

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,28 @@ static u32 s_debug_scope_depth = 0;
6565
#endif
6666

6767
static constexpr const u32 s_mipmap_blit_vs[] = {
68-
0x43425844, 0xe0f571cf, 0x51234ef3, 0x3a6beab4, 0x141cd2ef, 0x00000001, 0x000003ac, 0x00000005, 0x00000034,
69-
0x00000144, 0x00000178, 0x000001d0, 0x00000310, 0x46454452, 0x00000108, 0x00000001, 0x00000068, 0x00000001,
70-
0x0000003c, 0xfffe0500, 0x00008100, 0x000000e0, 0x31314452, 0x0000003c, 0x00000018, 0x00000020, 0x00000028,
71-
0x00000024, 0x0000000c, 0x00000000, 0x0000005c, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
72-
0x00000001, 0x00000001, 0x424f4255, 0x6b636f6c, 0xababab00, 0x0000005c, 0x00000001, 0x00000080, 0x00000010,
73-
0x00000000, 0x00000000, 0x000000a8, 0x00000000, 0x00000010, 0x00000002, 0x000000bc, 0x00000000, 0xffffffff,
74-
0x00000000, 0xffffffff, 0x00000000, 0x72735f75, 0x65725f63, 0x66007463, 0x74616f6c, 0xabab0034, 0x00030001,
75-
0x00040001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000b3, 0x7263694d,
76-
0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x31207265, 0x00312e30,
77-
0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000006, 0x00000001, 0x00000000,
78-
0x00000101, 0x565f5653, 0x65747265, 0x00444978, 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
79-
0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000c03, 0x00000041, 0x00000000, 0x00000001, 0x00000003,
80-
0x00000001, 0x0000000f, 0x43584554, 0x44524f4f, 0x5f565300, 0x69736f50, 0x6e6f6974, 0xababab00, 0x58454853,
81-
0x00000138, 0x00010050, 0x0000004e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000060,
68+
0x43425844, 0x1790f572, 0x2810683a, 0xdff0fe9d, 0x8f210489, 0x00000001, 0x000002e0, 0x00000005, 0x00000034,
69+
0x000000a0, 0x000000d4, 0x0000012c, 0x00000244, 0x46454452, 0x00000064, 0x00000000, 0x00000000, 0x00000000,
70+
0x0000003c, 0xfffe0500, 0x00008100, 0x0000003c, 0x31314452, 0x0000003c, 0x00000018, 0x00000020, 0x00000028,
71+
0x00000024, 0x0000000c, 0x00000000, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
72+
0x6f432072, 0x6c69706d, 0x31207265, 0x00312e30, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
73+
0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978, 0x4e47534f,
74+
0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000c03,
75+
0x00000041, 0x00000000, 0x00000001, 0x00000003, 0x00000001, 0x0000000f, 0x43584554, 0x44524f4f, 0x5f565300,
76+
0x69736f50, 0x6e6f6974, 0xababab00, 0x58454853, 0x00000110, 0x00010050, 0x00000044, 0x0100086a, 0x04000060,
8277
0x00101012, 0x00000000, 0x00000006, 0x03000065, 0x00102032, 0x00000000, 0x04000067, 0x001020f2, 0x00000001,
8378
0x00000001, 0x02000068, 0x00000001, 0x0b00008c, 0x00100012, 0x00000000, 0x00004001, 0x00000001, 0x00004001,
8479
0x00000001, 0x0010100a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100042, 0x00000000, 0x0010100a,
85-
0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086, 0x00000000, 0x0b000032,
86-
0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00208046, 0x00000000,
87-
0x00000000, 0x0f000032, 0x00102032, 0x00000001, 0x00100046, 0x00000000, 0x00004002, 0x40000000, 0xc0000000,
88-
0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x001020c2,
89-
0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x54415453, 0x00000094,
90-
0x00000007, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000000, 0x00000001, 0x00000001, 0x00000000,
80+
0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086, 0x00000000, 0x05000036,
81+
0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x0f000032, 0x00102032, 0x00000001, 0x00100046, 0x00000000,
82+
0x00004002, 0x40000000, 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000,
83+
0x00000000, 0x08000036, 0x001020c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
84+
0x0100003e, 0x54415453, 0x00000094, 0x00000007, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000,
85+
0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
86+
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000001, 0x00000000, 0x00000000,
9187
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
92-
0x00000000, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
93-
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
94-
0x00000000};
88+
0x00000000, 0x00000000, 0x00000000, 0x00000000,
89+
};
9590

9691
static constexpr const u32 s_mipmap_blit_ps[] = {
9792
0x43425844, 0x25500f77, 0x71f24271, 0x5f83f8b8, 0x3f405943, 0x00000001, 0x0000026c, 0x00000005, 0x00000034,
@@ -1786,11 +1781,23 @@ bool D3D12Device::CreateRootSignatures(Error* error)
17861781
D3D12::SetObjectName(rs.Get(), "Compute Multi Texture Pipeline Layout");
17871782
}
17881783

1784+
{
1785+
auto& rs = m_mipmap_render_root_signature;
1786+
rsb.AddDescriptorTable(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 0, 1, D3D12_SHADER_VISIBILITY_PIXEL);
1787+
rsb.AddStaticSampler(0, D3D12Sampler::GetD3DSamplerDesc(GPUSampler::GetLinearConfig()), D3D12_SHADER_VISIBILITY_PIXEL);
1788+
if (!(rs = rsb.Create(error, true)))
1789+
return false;
1790+
D3D12::SetObjectName(rs.Get(), "Render Mipmap Pipeline Layout");
1791+
}
1792+
17891793
return true;
17901794
}
17911795

17921796
void D3D12Device::DestroyRootSignatures()
17931797
{
1798+
for (ComPtr<ID3D12PipelineState>& it : m_mipmap_render_pipelines)
1799+
it.Reset();
1800+
m_mipmap_render_root_signature.Reset();
17941801
m_root_signatures.enumerate([](auto& it) { it.Reset(); });
17951802
}
17961803

@@ -2213,17 +2220,15 @@ void D3D12Device::UnbindTextureBuffer(D3D12TextureBuffer* buf)
22132220
void D3D12Device::RenderTextureMipmap(D3D12Texture* texture, u32 dst_level, u32 dst_width, u32 dst_height,
22142221
u32 src_level, u32 src_width, u32 src_height)
22152222
{
2216-
ID3D12RootSignature* rootsig =
2217-
m_root_signatures[0][static_cast<size_t>(GPUPipeline::Layout::SingleTextureAndPushConstants)].Get();
22182223
ComPtr<ID3D12PipelineState>& pipeline = m_mipmap_render_pipelines[static_cast<size_t>(texture->GetFormat())];
22192224
if (!pipeline)
22202225
{
22212226
D3D12::GraphicsPipelineBuilder gpb;
2222-
gpb.SetRootSignature(rootsig);
2227+
gpb.SetRootSignature(m_mipmap_render_root_signature.Get());
22232228
gpb.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
22242229
gpb.SetRenderTarget(0, texture->GetDXGIFormat());
2225-
gpb.SetVertexShader(s_mipmap_blit_vs, std::size(s_mipmap_blit_vs));
2226-
gpb.SetPixelShader(s_mipmap_blit_ps, std::size(s_mipmap_blit_ps));
2230+
gpb.SetVertexShader(s_mipmap_blit_vs, sizeof(s_mipmap_blit_vs));
2231+
gpb.SetPixelShader(s_mipmap_blit_ps, sizeof(s_mipmap_blit_ps));
22272232
gpb.SetRasterizationState(D3D12_FILL_MODE_SOLID, D3D12_CULL_MODE_NONE, false);
22282233
gpb.SetDepthState(false, false, D3D12_COMPARISON_FUNC_ALWAYS);
22292234
gpb.SetBlendState(0, false, D3D12_BLEND_ZERO, D3D12_BLEND_ONE, D3D12_BLEND_OP_ADD, D3D12_BLEND_ZERO,
@@ -2266,17 +2271,26 @@ void D3D12Device::RenderTextureMipmap(D3D12Texture* texture, u32 dst_level, u32
22662271
}
22672272
}
22682273

2269-
EndRenderPass();
2274+
if (InRenderPass())
2275+
EndRenderPass();
22702276

22712277
// we need a temporary SRV and RTV for each mip level
22722278
// Safe to use the init buffer after exec, because everything will be done with the texture.
22732279
D3D12DescriptorHandle rtv_handle;
22742280
while (!GetRTVHeapManager().Allocate(&rtv_handle))
2281+
{
22752282
SubmitCommandList(false, "Allocate RTV for RenderTextureMipmap()");
2283+
if (m_device_was_lost)
2284+
return;
2285+
}
22762286

22772287
D3D12DescriptorHandle srv_handle;
2278-
while (!GetDescriptorHeapManager().Allocate(&srv_handle))
2279-
SubmitCommandList(false, "Allocate SRV for RenderTextureMipmap()");
2288+
while (!m_command_lists[m_current_command_list].descriptor_allocator.Allocate(1, &srv_handle))
2289+
{
2290+
SubmitCommandList(false, "Allocate SRV/sampler for RenderTextureMipmap()");
2291+
if (m_device_was_lost)
2292+
return;
2293+
}
22802294

22812295
// Setup views. This will be a partial view for the SRV.
22822296
const D3D12_RENDER_TARGET_VIEW_DESC rtv_desc = {.Format = texture->GetDXGIFormat(),
@@ -2317,8 +2331,8 @@ void D3D12Device::RenderTextureMipmap(D3D12Texture* texture, u32 dst_level, u32
23172331
cmdlist->RSSetScissorRects(1, &scissor);
23182332

23192333
cmdlist->SetPipelineState(pipeline.Get());
2334+
cmdlist->SetGraphicsRootSignature(m_mipmap_render_root_signature.Get());
23202335
cmdlist->SetGraphicsRootDescriptorTable(0, srv_handle);
2321-
cmdlist->SetGraphicsRootDescriptorTable(1, static_cast<D3D12Sampler*>(m_linear_sampler)->GetDescriptor());
23222336
cmdlist->DrawInstanced(3, 1, 0, 0);
23232337

23242338
cmdlist->EndRenderPass();
@@ -2335,7 +2349,6 @@ void D3D12Device::RenderTextureMipmap(D3D12Texture* texture, u32 dst_level, u32
23352349
}
23362350

23372351
// Must destroy after current cmdlist.
2338-
DeferDescriptorDestruction(m_descriptor_heap_manager, &srv_handle);
23392352
DeferDescriptorDestruction(m_rtv_heap_manager, &rtv_handle);
23402353

23412354
// Restore for next normal draw.

src/util/d3d12_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ class D3D12Device final : public GPUDevice
363363

364364
D3D12SwapChain* m_current_swap_chain = nullptr;
365365

366+
ComPtr<ID3D12RootSignature> m_mipmap_render_root_signature;
366367
std::array<ComPtr<ID3D12PipelineState>, static_cast<size_t>(GPUTexture::Format::MaxCount)> m_mipmap_render_pipelines =
367368
{};
368369
};

src/util/d3d12_texture.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ std::unique_ptr<GPUTexture> D3D12Device::CreateTexture(u32 width, u32 height, u3
7474
case GPUTexture::Type::RenderTarget:
7575
{
7676
// RT's tend to be larger, so we'll keep them committed for speed.
77-
DebugAssert(levels == 1);
7877
allocationDesc.Flags |= D3D12MA::ALLOCATION_FLAG_COMMITTED;
7978
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
8079
optimized_clear_value.Format = fm.rtv_format;
@@ -566,8 +565,6 @@ void D3D12Texture::Unmap()
566565

567566
void D3D12Texture::GenerateMipmaps()
568567
{
569-
Panic("Not implemented");
570-
571568
for (u32 layer = 0; layer < m_layers; layer++)
572569
{
573570
for (u32 dst_level = 1; dst_level < m_levels; dst_level++)
@@ -718,7 +715,7 @@ void D3D12Sampler::SetDebugName(std::string_view name)
718715

719716
#endif
720717

721-
std::unique_ptr<GPUSampler> D3D12Device::CreateSampler(const GPUSampler::Config& config, Error* error /* = nullptr */)
718+
D3D12_SAMPLER_DESC D3D12Sampler::GetD3DSamplerDesc(const GPUSampler::Config& config)
722719
{
723720
static constexpr std::array<D3D12_TEXTURE_ADDRESS_MODE, static_cast<u8>(GPUSampler::AddressMode::MaxCount)> ta = {{
724721
D3D12_TEXTURE_ADDRESS_MODE_WRAP, // Repeat
@@ -742,7 +739,7 @@ std::unique_ptr<GPUSampler> D3D12Device::CreateSampler(const GPUSampler::Config&
742739
desc.AddressU = ta[static_cast<u8>(config.address_u.GetValue())];
743740
desc.AddressV = ta[static_cast<u8>(config.address_v.GetValue())];
744741
desc.AddressW = ta[static_cast<u8>(config.address_w.GetValue())];
745-
std::memcpy(desc.BorderColor, RGBA8ToFloat(config.border_color).data(), sizeof(desc.BorderColor));
742+
std::memcpy(desc.BorderColor, GPUDevice::RGBA8ToFloat(config.border_color).data(), sizeof(desc.BorderColor));
746743
desc.MinLOD = static_cast<float>(config.min_lod);
747744
desc.MaxLOD = static_cast<float>(config.max_lod);
748745

@@ -758,9 +755,15 @@ std::unique_ptr<GPUSampler> D3D12Device::CreateSampler(const GPUSampler::Config&
758755
desc.MaxAnisotropy = 1;
759756
}
760757

758+
return desc;
759+
}
760+
761+
std::unique_ptr<GPUSampler> D3D12Device::CreateSampler(const GPUSampler::Config& config, Error* error /* = nullptr */)
762+
{
761763
D3D12DescriptorHandle handle;
762764
if (m_sampler_heap_manager.Allocate(&handle)) [[likely]]
763765
{
766+
const D3D12_SAMPLER_DESC desc = D3D12Sampler::GetD3DSamplerDesc(config);
764767
m_device->CreateSampler(&desc, handle);
765768
return std::unique_ptr<GPUSampler>(new D3D12Sampler(handle));
766769
}

src/util/d3d12_texture.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class D3D12Texture final : public GPUTexture
8181
D3D12_RESOURCE_STATES resource_state);
8282

8383
ID3D12GraphicsCommandList4* GetCommandBufferForUpdate();
84-
ID3D12Resource* AllocateUploadStagingBuffer(const void* data, u32 pitch, u32 upload_pitch, u32 width,
85-
u32 height, u32 buffer_size) const;
84+
ID3D12Resource* AllocateUploadStagingBuffer(const void* data, u32 pitch, u32 upload_pitch, u32 width, u32 height,
85+
u32 buffer_size) const;
8686
void ActuallyCommitClear(ID3D12GraphicsCommandList* cmdlist);
8787

8888
ComPtr<ID3D12Resource> m_resource;
@@ -121,6 +121,8 @@ class D3D12Sampler final : public GPUSampler
121121
void SetDebugName(std::string_view name) override;
122122
#endif
123123

124+
static D3D12_SAMPLER_DESC GetD3DSamplerDesc(const GPUSampler::Config& config);
125+
124126
private:
125127
D3D12Sampler(D3D12DescriptorHandle descriptor);
126128

src/util/gpu_texture.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ bool GPUTexture::ValidateConfig(u32 width, u32 height, u32 layers, u32 levels, u
344344
return false;
345345
}
346346

347-
if (levels > 1 && type != Type::Texture)
347+
if (levels > 1 && type == Type::DepthStencil)
348348
{
349-
Error::SetStringView(error, "Mipmaps are not supported on targets.");
349+
Error::SetStringView(error, "Mipmaps are not supported on depth stencil.");
350350
return false;
351351
}
352352

src/util/vulkan_texture.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ std::unique_ptr<VulkanTexture> VulkanTexture::Create(u32 width, u32 height, u32
104104

105105
case Type::RenderTarget:
106106
{
107-
DebugAssert(levels == 1);
108107
ici.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
109108
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
110109
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;

0 commit comments

Comments
 (0)