All attachments must be at least as large as the framebuffer; using a max operator is not compliant with Vulkan (VUID-VkFramebufferCreateInfo-flags-04533, etc).
From: Hans-Kristian Arntzen post@arntzen-software.no Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/command.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 9f4a4149..e81feea4 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -4517,6 +4517,7 @@ static void STDMETHODCALLTYPE d3d12_command_list_OMSetRenderTargets(ID3D12Graphi BOOL single_descriptor_handle, const D3D12_CPU_DESCRIPTOR_HANDLE *depth_stencil_descriptor) { struct d3d12_command_list *list = impl_from_ID3D12GraphicsCommandList2(iface); + const VkPhysicalDeviceLimits *limits = &list->device->vk_info.device_limits; const struct d3d12_rtv_desc *rtv_desc; const struct d3d12_dsv_desc *dsv_desc; VkFormat prev_dsv_format; @@ -4535,9 +4536,9 @@ static void STDMETHODCALLTYPE d3d12_command_list_OMSetRenderTargets(ID3D12Graphi render_target_descriptor_count = ARRAY_SIZE(list->rtvs); }
- list->fb_width = 0; - list->fb_height = 0; - list->fb_layer_count = 0; + list->fb_width = limits->maxFramebufferWidth; + list->fb_height = limits->maxFramebufferHeight; + list->fb_layer_count = limits->maxFramebufferLayers; for (i = 0; i < render_target_descriptor_count; ++i) { if (single_descriptor_handle) @@ -4567,9 +4568,9 @@ static void STDMETHODCALLTYPE d3d12_command_list_OMSetRenderTargets(ID3D12Graphi }
list->rtvs[i] = view->u.vk_image_view; - list->fb_width = max(list->fb_width, rtv_desc->width); - list->fb_height = max(list->fb_height, rtv_desc->height); - list->fb_layer_count = max(list->fb_layer_count, rtv_desc->layer_count); + list->fb_width = min(list->fb_width, rtv_desc->width); + list->fb_height = min(list->fb_height, rtv_desc->height); + list->fb_layer_count = min(list->fb_layer_count, rtv_desc->layer_count); }
prev_dsv_format = list->dsv_format; @@ -4591,9 +4592,9 @@ static void STDMETHODCALLTYPE d3d12_command_list_OMSetRenderTargets(ID3D12Graphi }
list->dsv = view->u.vk_image_view; - list->fb_width = max(list->fb_width, dsv_desc->width); - list->fb_height = max(list->fb_height, dsv_desc->height); - list->fb_layer_count = max(list->fb_layer_count, dsv_desc->layer_count); + list->fb_width = min(list->fb_width, dsv_desc->width); + list->fb_height = min(list->fb_height, dsv_desc->height); + list->fb_layer_count = min(list->fb_layer_count, dsv_desc->layer_count); list->dsv_format = dsv_desc->format->vk_format; } else
Avoids overflowing vkCreateFramebuffer() later with UINT_MAX layers.
Based on a vkd3d-proton patch by Hans-Kristian Arntzen.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/resource.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 1ca23a90..a562130d 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -3154,6 +3154,7 @@ void d3d12_rtv_desc_create_rtv(struct d3d12_rtv_desc *rtv_desc, struct d3d12_dev { case D3D12_RTV_DIMENSION_TEXTURE2D: vkd3d_desc.miplevel_idx = desc->u.Texture2D.MipSlice; + vkd3d_desc.layer_count = 1; if (desc->u.Texture2D.PlaneSlice) FIXME("Ignoring plane slice %u.\n", desc->u.Texture2D.PlaneSlice); break; @@ -3167,6 +3168,7 @@ void d3d12_rtv_desc_create_rtv(struct d3d12_rtv_desc *rtv_desc, struct d3d12_dev break; case D3D12_RTV_DIMENSION_TEXTURE2DMS: vkd3d_desc.view_type = VK_IMAGE_VIEW_TYPE_2D; + vkd3d_desc.layer_count = 1; break; case D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY: vkd3d_desc.view_type = VK_IMAGE_VIEW_TYPE_2D_ARRAY; @@ -3182,6 +3184,9 @@ void d3d12_rtv_desc_create_rtv(struct d3d12_rtv_desc *rtv_desc, struct d3d12_dev default: FIXME("Unhandled view dimension %#x.\n", desc->ViewDimension); } + + /* Avoid passing down UINT_MAX here since that makes framebuffer logic later rather awkward. */ + vkd3d_desc.layer_count = min(vkd3d_desc.layer_count, resource->desc.DepthOrArraySize - vkd3d_desc.layer_idx); } else if (resource->desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) { @@ -3253,6 +3258,7 @@ void d3d12_dsv_desc_create_dsv(struct d3d12_dsv_desc *dsv_desc, struct d3d12_dev { case D3D12_DSV_DIMENSION_TEXTURE2D: vkd3d_desc.miplevel_idx = desc->u.Texture2D.MipSlice; + vkd3d_desc.layer_count = 1; break; case D3D12_DSV_DIMENSION_TEXTURE2DARRAY: vkd3d_desc.view_type = VK_IMAGE_VIEW_TYPE_2D_ARRAY; @@ -3262,6 +3268,7 @@ void d3d12_dsv_desc_create_dsv(struct d3d12_dsv_desc *dsv_desc, struct d3d12_dev break; case D3D12_DSV_DIMENSION_TEXTURE2DMS: vkd3d_desc.view_type = VK_IMAGE_VIEW_TYPE_2D; + vkd3d_desc.layer_count = 1; break; case D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY: vkd3d_desc.view_type = VK_IMAGE_VIEW_TYPE_2D_ARRAY; @@ -3271,6 +3278,9 @@ void d3d12_dsv_desc_create_dsv(struct d3d12_dsv_desc *dsv_desc, struct d3d12_dev default: FIXME("Unhandled view dimension %#x.\n", desc->ViewDimension); } + + /* Avoid passing down UINT_MAX here since that makes framebuffer logic later rather awkward. */ + vkd3d_desc.layer_count = min(vkd3d_desc.layer_count, resource->desc.DepthOrArraySize - vkd3d_desc.layer_idx); }
assert(d3d12_resource_is_texture(resource));
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/resource.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index a562130d..2589cf5e 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -2924,7 +2924,8 @@ static void vkd3d_create_texture_uav(struct d3d12_desc *descriptor, case D3D12_UAV_DIMENSION_TEXTURE3D: vkd3d_desc.view_type = VK_IMAGE_VIEW_TYPE_3D; vkd3d_desc.miplevel_idx = desc->u.Texture3D.MipSlice; - if (desc->u.Texture3D.FirstWSlice || desc->u.Texture3D.WSize != resource->desc.DepthOrArraySize) + if (desc->u.Texture3D.FirstWSlice || (desc->u.Texture3D.WSize != resource->desc.DepthOrArraySize + && desc->u.Texture3D.WSize != UINT_MAX)) FIXME("Unhandled depth view %u-%u.\n", desc->u.Texture3D.FirstWSlice, desc->u.Texture3D.WSize); break;
Based on a vkd3d-proton patch by Philip Rebohle.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/resource.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 2589cf5e..f6c1851b 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -2924,7 +2924,8 @@ static void vkd3d_create_texture_uav(struct d3d12_desc *descriptor, case D3D12_UAV_DIMENSION_TEXTURE3D: vkd3d_desc.view_type = VK_IMAGE_VIEW_TYPE_3D; vkd3d_desc.miplevel_idx = desc->u.Texture3D.MipSlice; - if (desc->u.Texture3D.FirstWSlice || (desc->u.Texture3D.WSize != resource->desc.DepthOrArraySize + if (desc->u.Texture3D.FirstWSlice || (desc->u.Texture3D.WSize != max(1u, + resource->desc.DepthOrArraySize >> desc->u.Texture3D.MipSlice) && desc->u.Texture3D.WSize != UINT_MAX)) FIXME("Unhandled depth view %u-%u.\n", desc->u.Texture3D.FirstWSlice, desc->u.Texture3D.WSize);
Otherwise, we may end up failing to allocate memory on Tier 1 hardware, and also fail to use dedicated allocations in some cases.
Based on a vkd3d-proton patch by Philip Rebohle.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/resource.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index f6c1851b..e950868b 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -611,7 +611,7 @@ static HRESULT d3d12_heap_init(struct d3d12_heap *heap, if (d3d12_resource_is_buffer(resource)) { hr = vkd3d_allocate_buffer_memory(device, resource->u.vk_buffer, - &heap->desc.Properties, heap->desc.Flags, + &heap->desc.Properties, heap->desc.Flags | D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS, &heap->vk_memory, &heap->vk_memory_type, &vk_memory_size); } else @@ -4004,7 +4004,7 @@ HRESULT vkd3d_init_null_resources(struct vkd3d_null_resources *null_resources, resource_desc.SampleDesc.Count = 1; resource_desc.SampleDesc.Quality = 0; resource_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; - resource_desc.Flags = D3D12_RESOURCE_FLAG_NONE; + resource_desc.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS;
if (FAILED(hr = vkd3d_create_buffer(device, &heap_properties, D3D12_HEAP_FLAG_NONE, &resource_desc, &null_resources->vk_buffer))) @@ -4020,7 +4020,7 @@ HRESULT vkd3d_init_null_resources(struct vkd3d_null_resources *null_resources, &resource_desc, &null_resources->vk_storage_buffer))) goto fail; if (!use_sparse_resources && FAILED(hr = vkd3d_allocate_buffer_memory(device, null_resources->vk_storage_buffer, - &heap_properties, D3D12_HEAP_FLAG_NONE, &null_resources->vk_storage_buffer_memory, NULL, NULL))) + &heap_properties, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS, &null_resources->vk_storage_buffer_memory, NULL, NULL))) goto fail;
/* 2D SRV */
On Fri, 17 Sept 2021 at 17:38, Conor McCarthy cmccarthy@codeweavers.com wrote:
Otherwise, we may end up failing to allocate memory on Tier 1 hardware, and also fail to use dedicated allocations in some cases.
I suppose this patch may end up making sense after some improvements to they way we allocate VRAM. As it is though, I don't think this flag will have any effect.
Part of a vkd3d-proton patch by Hans-Kristian Arntzen.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/command.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index e81feea4..fc06f28d 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -4420,6 +4420,10 @@ static void STDMETHODCALLTYPE d3d12_command_list_IASetVertexBuffers(ID3D12Graphi return; }
+ /* Native drivers appear to ignore this call. Buffer bindings are kept as-is. */ + if (!views) + return; + for (i = 0; i < view_count; ++i) { if (views[i].BufferLocation)
Part of a vkd3d-proton patch by Hans-Kristian Arntzen.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- tests/d3d12.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index 89b1f000..c027d9b7 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -19122,6 +19122,10 @@ static void test_null_vbv(void) vbv[1].SizeInBytes = 0; ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, 0, ARRAY_SIZE(vbv), vbv);
+ /* Call should be ignored. */ + ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, 0, 1, NULL); + ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, 1, 1, NULL); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 4, 4, 0, 0);
transition_resource_state(command_list, context.render_target,
Windows returns E_INVALIDARG at least on AMD and Intel. Psychonaughts 2 attempts to create resources with this argument.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- tests/d3d12.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index c027d9b7..066a4346 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -1774,6 +1774,16 @@ static void test_create_committed_resource(void) ID3D12Resource_Release(resource); resource_desc.MipLevels = 1;
+ resource_desc.SampleDesc.Count = 0; + hr = ID3D12Device_CreateCommittedResource(device, &heap_properties, D3D12_HEAP_FLAG_NONE, + &resource_desc, D3D12_RESOURCE_STATE_RENDER_TARGET, &clear_value, + &IID_ID3D12Resource, (void **)&resource); + todo + ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); + if (SUCCEEDED(hr)) + ID3D12Resource_Release(resource); + resource_desc.SampleDesc.Count = 1; + hr = ID3D12Device_CreateCommittedResource(device, &heap_properties, D3D12_HEAP_FLAG_NONE, &resource_desc, D3D12_RESOURCE_STATE_RENDER_TARGET | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, &clear_value, &IID_ID3D12Resource, (void **)&resource);
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/resource.c | 6 ++++++ tests/d3d12.c | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index e950868b..e6b326e6 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -1681,6 +1681,12 @@ HRESULT d3d12_resource_validate_desc(const D3D12_RESOURCE_DESC *desc, struct d3d /* Fall through. */ case D3D12_RESOURCE_DIMENSION_TEXTURE2D: case D3D12_RESOURCE_DIMENSION_TEXTURE3D: + if (desc->SampleDesc.Count == 0) + { + WARN("Invalid sample count 0.\n"); + return E_INVALIDARG; + } + if (!(format = vkd3d_format_from_d3d12_resource_desc(device, desc, 0))) { WARN("Invalid format %#x.\n", desc->Format); diff --git a/tests/d3d12.c b/tests/d3d12.c index 066a4346..2f81f027 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -1778,10 +1778,7 @@ static void test_create_committed_resource(void) hr = ID3D12Device_CreateCommittedResource(device, &heap_properties, D3D12_HEAP_FLAG_NONE, &resource_desc, D3D12_RESOURCE_STATE_RENDER_TARGET, &clear_value, &IID_ID3D12Resource, (void **)&resource); - todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); - if (SUCCEEDED(hr)) - ID3D12Resource_Release(resource); resource_desc.SampleDesc.Count = 1;
hr = ID3D12Device_CreateCommittedResource(device, &heap_properties, D3D12_HEAP_FLAG_NONE,
UE4, at least in Psychonauts 2, catches failure of this function.
vkd3d-proton at the current head (2b13d06f) sets the timestamps to zero when not compiled in Windows.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/command.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index fc06f28d..2e81feba 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -6146,10 +6146,14 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_queue_GetTimestampFrequency(ID3D1 static HRESULT STDMETHODCALLTYPE d3d12_command_queue_GetClockCalibration(ID3D12CommandQueue *iface, UINT64 *gpu_timestamp, UINT64 *cpu_timestamp) { - FIXME("iface %p, gpu_timestamp %p, cpu_timestamp %p stub!\n", + TRACE("iface %p, gpu_timestamp %p, cpu_timestamp %p.\n", iface, gpu_timestamp, cpu_timestamp);
- return E_NOTIMPL; + WARN("Setting timestamps to zero.\n"); + *gpu_timestamp = 0; + *cpu_timestamp = 0; + + return S_OK; }
static D3D12_COMMAND_QUEUE_DESC * STDMETHODCALLTYPE d3d12_command_queue_GetDesc(ID3D12CommandQueue *iface,