This results in a valid format instead of NULL being returned for buffers and any other case where DXGI_FORMAT_UNKNOWN is specified. In some cases invalid use of a buffer or DXGI_FORMAT_UNKNOWN will not result in E_INVALIDARG, and would need to be tested explicitly if proven to be an issue.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/device.c | 8 +------- libs/vkd3d/resource.c | 8 ++++++++ libs/vkd3d/state.c | 4 ++++ libs/vkd3d/utils.c | 1 + tests/d3d12.c | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 661ca1d9..e1e878d1 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -3656,8 +3656,6 @@ static void STDMETHODCALLTYPE d3d12_device_GetCopyableFootprints(ID3D12Device *i UINT *row_counts, UINT64 *row_sizes, UINT64 *total_bytes) { struct d3d12_device *device = impl_from_ID3D12Device(iface); - static const struct vkd3d_format vkd3d_format_unknown - = {DXGI_FORMAT_UNKNOWN, VK_FORMAT_UNDEFINED, 1, 1, 1, 1, 0};
unsigned int i, sub_resource_idx, miplevel_idx, row_count, row_size, row_pitch; unsigned int width, height, depth, plane_count, sub_resources_per_plane; @@ -3678,11 +3676,7 @@ static void STDMETHODCALLTYPE d3d12_device_GetCopyableFootprints(ID3D12Device *i if (total_bytes) *total_bytes = ~(uint64_t)0;
- if (desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) - { - format = &vkd3d_format_unknown; - } - else if (!(format = vkd3d_format_from_d3d12_resource_desc(device, desc, 0))) + if (!(format = vkd3d_format_from_d3d12_resource_desc(device, desc, 0))) { WARN("Invalid format %#x.\n", desc->Format); return; diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index a4d16ee8..14e08b09 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -1589,6 +1589,12 @@ static void d3d12_validate_resource_flags(D3D12_RESOURCE_FLAGS flags) static bool d3d12_resource_validate_texture_format(const D3D12_RESOURCE_DESC *desc, const struct vkd3d_format *format) { + if (desc->Format == DXGI_FORMAT_UNKNOWN) + { + WARN("DXGI_FORMAT_UNKNOWN is invalid for textures.\n"); + return false; + } + if (!vkd3d_format_is_compressed(format)) return true;
@@ -2273,6 +2279,8 @@ static bool vkd3d_create_buffer_view_for_resource(struct d3d12_device *device, } else if ((format = vkd3d_format_from_d3d12_resource_desc(device, &resource->desc, view_format))) { + /* TODO: if view_format is DXGI_FORMAT_UNKNOWN, this is always 1, which + * may not match driver behaviour (return false?). */ element_size = format->byte_count; } else diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 10503a60..b54a6527 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -2328,6 +2328,8 @@ static HRESULT compute_input_layout_offsets(const struct d3d12_device *device, return E_INVALIDARG; }
+ /* TODO: DXGI_FORMAT_UNKNOWN will return a format with byte_count == 1, + * which may not match driver behaviour (return E_INVALIDARG?). */ if (!(format = vkd3d_get_format(device, e->Format, false))) { WARN("Invalid input element format %#x.\n", e->Format); @@ -2816,6 +2818,8 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s const D3D12_INPUT_ELEMENT_DESC *e = &desc->InputLayout.pInputElementDescs[i]; const struct vkd3d_shader_signature_element *signature_element;
+ /* TODO: DXGI_FORMAT_UNKNOWN will succeed here, which may not match + * driver behaviour (return E_INVALIDARG?). */ if (!(format = vkd3d_get_format(device, e->Format, false))) { WARN("Invalid input element format %#x.\n", e->Format); diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c index ec2b4b39..cdb81f67 100644 --- a/libs/vkd3d/utils.c +++ b/libs/vkd3d/utils.c @@ -29,6 +29,7 @@ #define UINT VKD3D_FORMAT_TYPE_UINT static const struct vkd3d_format vkd3d_formats[] = { + {DXGI_FORMAT_UNKNOWN, VK_FORMAT_UNDEFINED, 1, 1, 1, 1}, {DXGI_FORMAT_R32G32B32A32_TYPELESS, VK_FORMAT_R32G32B32A32_SFLOAT, 16, 1, 1, 1, COLOR, 1, TYPELESS}, {DXGI_FORMAT_R32G32B32A32_FLOAT, VK_FORMAT_R32G32B32A32_SFLOAT, 16, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R32G32B32A32_UINT, VK_FORMAT_R32G32B32A32_UINT, 16, 1, 1, 1, COLOR, 1, UINT}, diff --git a/tests/d3d12.c b/tests/d3d12.c index 0702573b..23aab61d 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -1167,7 +1167,7 @@ static void test_format_support(void) memset(&format_support, 0, sizeof(format_support)); hr = ID3D12Device_CheckFeatureSupport(device, D3D12_FEATURE_FORMAT_SUPPORT, &format_support, sizeof(format_support)); - todo ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); todo ok(format_support.Support1 == D3D12_FORMAT_SUPPORT1_BUFFER, "Got unexpected support1 %#x.\n", format_support.Support1); ok(!format_support.Support2 || format_support.Support2 == D3D12_FORMAT_SUPPORT2_TILED,