diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 7fc81b52..ffa15a10 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -1538,8 +1538,8 @@ static void STDMETHODCALLTYPE d3d12_command_list_CopyBufferRegion(ID3D12Graphics vk_procs = &list->device->vk_procs; - assert(dst_resource_impl->desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER); - assert(src_resource_impl->desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER); + assert(d3d12_resource_is_buffer(dst_resource_impl)); + assert(d3d12_resource_is_buffer(src_resource_impl)); buffer_copy.srcOffset = src_offset; buffer_copy.dstOffset = dst_offset; @@ -1836,7 +1836,7 @@ static void STDMETHODCALLTYPE d3d12_command_list_ResourceBarrier(ID3D12GraphicsC VK_CALL(vkCmdPipelineBarrier(list->vk_command_buffer, src_stage_mask, dst_stage_mask, 0, 1, &vk_barrier, 0, NULL, 0, NULL)); } - else if (resource->desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) + else if (d3d12_resource_is_buffer(resource)) { VkBufferMemoryBarrier vk_barrier; diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 43dadd04..7c6c5cf7 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -279,7 +279,7 @@ static HRESULT vkd3d_allocate_buffer_memory(struct d3d12_resource *resource, str VkResult vr; HRESULT hr; - assert(resource->desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER); + assert(d3d12_resource_is_buffer(resource)); VK_CALL(vkGetBufferMemoryRequirements(device->vk_device, resource->u.vk_buffer, &memory_requirements)); if (FAILED(hr = vkd3d_allocate_device_memory(device, heap_properties, heap_flags, @@ -471,7 +471,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT return E_INVALIDARG; } - if (resource->desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) + if (!d3d12_resource_is_buffer(resource)) { /* Textures seem to be mappable only on UMA adapters. */ FIXME("Not implemented for textures.\n"); @@ -515,7 +515,7 @@ static void STDMETHODCALLTYPE d3d12_resource_Unmap(ID3D12Resource *iface, UINT s device = resource->device; vk_procs = &device->vk_procs; - if (resource->desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) + if (!d3d12_resource_is_buffer(resource)) { FIXME("Not implemented for textures.\n"); return; @@ -552,6 +552,12 @@ static D3D12_GPU_VIRTUAL_ADDRESS STDMETHODCALLTYPE d3d12_resource_GetGPUVirtualA TRACE("iface %p.\n", iface); + if (!d3d12_resource_is_buffer(resource)) + { + WARN("GPU virtual address for textures is always 0.\n"); + return 0; + } + return resource->u.gpu_address; } @@ -631,7 +637,7 @@ static HRESULT d3d12_committed_resource_init(struct d3d12_resource *resource, st resource->desc = *desc; - if (desc->Dimension != D3D12_RESOURCE_DIMENSION_BUFFER + if (!d3d12_resource_is_buffer(resource) && (heap_properties->Type == D3D12_HEAP_TYPE_UPLOAD || heap_properties->Type == D3D12_HEAP_TYPE_READBACK)) { WARN("Texture cannot be created on a UPLOAD/READBACK heap.\n"); @@ -655,7 +661,7 @@ static HRESULT d3d12_committed_resource_init(struct d3d12_resource *resource, st return E_INVALIDARG; } - if (optimized_clear_value && desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) + if (optimized_clear_value && d3d12_resource_is_buffer(resource)) { WARN("Optimized clear value must be NULL for buffers.\n"); return E_INVALIDARG; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 3adf82d0..9cbf4b08 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -138,6 +138,11 @@ struct d3d12_resource struct d3d12_device *device; }; +static inline bool d3d12_resource_is_buffer(const struct d3d12_resource *resource) +{ + return resource->desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER; +} + HRESULT d3d12_committed_resource_create(struct d3d12_device *device, const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags, const D3D12_RESOURCE_DESC *desc, D3D12_RESOURCE_STATES initial_state, diff --git a/tests/d3d12.c b/tests/d3d12.c index 399f44c1..9affbe35 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -844,6 +844,7 @@ static void test_create_command_queue(void) static void test_create_committed_resource(void) { + D3D12_GPU_VIRTUAL_ADDRESS gpu_address; D3D12_HEAP_PROPERTIES heap_properties; D3D12_RESOURCE_DESC resource_desc; ID3D12Device *device, *tmp_device; @@ -898,6 +899,9 @@ static void test_create_committed_resource(void) check_interface(resource, &IID_ID3D12Pageable, TRUE); check_interface(resource, &IID_ID3D12Resource, TRUE); + gpu_address = ID3D12Resource_GetGPUVirtualAddress(resource); + ok(!gpu_address, "Got unexpected GPU virtual address %#"PRIx64".\n", gpu_address); + refcount = ID3D12Resource_Release(resource); ok(!refcount, "ID3D12Resource has %u references left.\n", (unsigned int)refcount); @@ -953,6 +957,9 @@ static void test_create_committed_resource(void) check_interface(resource, &IID_ID3D12Pageable, TRUE); check_interface(resource, &IID_ID3D12Resource, TRUE); + gpu_address = ID3D12Resource_GetGPUVirtualAddress(resource); + ok(gpu_address, "Got unexpected GPU virtual address %#"PRIx64".\n", gpu_address); + refcount = ID3D12Resource_Release(resource); ok(!refcount, "ID3D12Resource has %u references left.\n", (unsigned int)refcount);