Predicate arguments which are only non-zero in bit 32 or higher are not supported. Predicates will not be applied to clear and copy commands because Vulkan does not support predication of these command classes.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/command.c | 63 +++++++++++++++++++++++++++++++++++++- libs/vkd3d/device.c | 12 ++++++++ libs/vkd3d/vkd3d_private.h | 3 ++ libs/vkd3d/vulkan_procs.h | 4 +++ 4 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 75556f5..32534e5 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -2288,6 +2288,8 @@ static void d3d12_command_list_reset_state(struct d3d12_command_list *list,
list->xfb_enabled = false;
+ list->is_predicated = false; + list->current_framebuffer = VK_NULL_HANDLE; list->current_pipeline = VK_NULL_HANDLE; list->pso_render_pass = VK_NULL_HANDLE; @@ -4910,8 +4912,67 @@ static void STDMETHODCALLTYPE d3d12_command_list_ResolveQueryData(ID3D12Graphics static void STDMETHODCALLTYPE d3d12_command_list_SetPredication(ID3D12GraphicsCommandList1 *iface, ID3D12Resource *buffer, UINT64 aligned_buffer_offset, D3D12_PREDICATION_OP operation) { - FIXME("iface %p, buffer %p, aligned_buffer_offset %#"PRIx64", operation %#x stub!\n", + struct d3d12_command_list *list = impl_from_ID3D12GraphicsCommandList1(iface); + const struct vkd3d_vulkan_info *vk_info = &list->device->vk_info; + struct d3d12_resource *resource = unsafe_impl_from_ID3D12Resource(buffer); + const struct vkd3d_vk_device_procs *vk_procs; + + TRACE("iface %p, buffer %p, aligned_buffer_offset %#"PRIx64", operation %#x.\n", iface, buffer, aligned_buffer_offset, operation); + + if (!vk_info->EXT_conditional_rendering) + { + FIXME("Vulkan conditional rendering extension not present. Conditional rendering not supported.\n"); + return; + } + + vk_procs = &list->device->vk_procs; + + if (resource) + { + VkConditionalRenderingBeginInfoEXT cond_info; + if (aligned_buffer_offset & (sizeof(UINT64) - 1)) + { + WARN("Unaligned predicate argument buffer offset.\n"); + return; + } + if (!d3d12_resource_is_buffer(resource)) + { + WARN("Predicate arguments must be stored in a buffer.\n"); + return; + } + + FIXME("Predication doesn't support clear and copy commands, and predication " + "values are treated as 32-bit values.\n"); + cond_info.sType = VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT; + cond_info.pNext = NULL; + cond_info.buffer = resource->u.vk_buffer; + cond_info.offset = aligned_buffer_offset; + switch (operation) + { + case D3D12_PREDICATION_OP_EQUAL_ZERO: + cond_info.flags = 0; + break; + case D3D12_PREDICATION_OP_NOT_EQUAL_ZERO: + cond_info.flags = VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT; + break; + default: + WARN("Unknown predication op %#x.\n", operation); + return; + } + + /* Must end any current predication before beginning a new one */ + if (list->is_predicated) + VK_CALL(vkCmdEndConditionalRenderingEXT(list->vk_command_buffer)); + + VK_CALL(vkCmdBeginConditionalRenderingEXT(list->vk_command_buffer, &cond_info)); + list->is_predicated = true; + } + else + { + VK_CALL(vkCmdEndConditionalRenderingEXT(list->vk_command_buffer)); + list->is_predicated = false; + } }
static void STDMETHODCALLTYPE d3d12_command_list_SetMarker(ID3D12GraphicsCommandList1 *iface, diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index fa10bb8..217c1c8 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -142,6 +142,7 @@ static const struct vkd3d_optional_extension_info optional_device_extensions[] = {VK_KHR_MAINTENANCE3_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, KHR_maintenance3)}, {VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, KHR_push_descriptor)}, /* EXT extensions */ + {VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, EXT_conditional_rendering)}, {VK_EXT_DEBUG_MARKER_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, EXT_debug_marker)}, {VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, EXT_depth_clip_enable)}, {VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, EXT_descriptor_indexing)}, @@ -673,6 +674,7 @@ struct vkd3d_physical_device_info VkPhysicalDeviceProperties2KHR properties2;
/* features */ + VkPhysicalDeviceConditionalRenderingFeaturesEXT conditional_rendering_features; VkPhysicalDeviceDepthClipEnableFeaturesEXT depth_clip_features; VkPhysicalDeviceDescriptorIndexingFeaturesEXT descriptor_indexing_features; VkPhysicalDeviceTransformFeedbackFeaturesEXT xfb_features; @@ -684,6 +686,7 @@ struct vkd3d_physical_device_info static void vkd3d_physical_device_info_init(struct vkd3d_physical_device_info *info, struct d3d12_device *device) { const struct vkd3d_vk_instance_procs *vk_procs = &device->vkd3d_instance->vk_procs; + VkPhysicalDeviceConditionalRenderingFeaturesEXT *conditional_rendering_features; VkPhysicalDeviceDescriptorIndexingPropertiesEXT *descriptor_indexing_properties; VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *vertex_divisor_properties; VkPhysicalDeviceDescriptorIndexingFeaturesEXT *descriptor_indexing_features; @@ -696,6 +699,7 @@ static void vkd3d_physical_device_info_init(struct vkd3d_physical_device_info *i struct vkd3d_vulkan_info *vulkan_info = &device->vk_info;
memset(info, 0, sizeof(*info)); + conditional_rendering_features = &info->conditional_rendering_features; depth_clip_features = &info->depth_clip_features; descriptor_indexing_features = &info->descriptor_indexing_features; descriptor_indexing_properties = &info->descriptor_indexing_properties; @@ -705,7 +709,9 @@ static void vkd3d_physical_device_info_init(struct vkd3d_physical_device_info *i xfb_features = &info->xfb_features; xfb_properties = &info->xfb_properties;
+ conditional_rendering_features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT; depth_clip_features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT; + depth_clip_features->pNext = conditional_rendering_features; descriptor_indexing_features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT; descriptor_indexing_features->pNext = depth_clip_features; xfb_features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT; @@ -999,6 +1005,7 @@ static void vkd3d_trace_physical_device_limits(const struct vkd3d_physical_devic
static void vkd3d_trace_physical_device_features(const struct vkd3d_physical_device_info *info) { + const VkPhysicalDeviceConditionalRenderingFeaturesEXT *conditional_rendering_features; const VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *divisor_features; const VkPhysicalDeviceDescriptorIndexingFeaturesEXT *descriptor_indexing; const VkPhysicalDeviceDepthClipEnableFeaturesEXT *depth_clip_features; @@ -1109,6 +1116,10 @@ static void vkd3d_trace_physical_device_features(const struct vkd3d_physical_dev TRACE(" runtimeDescriptorArray: %#x.\n", descriptor_indexing->runtimeDescriptorArray);
+ conditional_rendering_features = &info->conditional_rendering_features; + TRACE(" VkPhysicalDeviceConditionalRenderingFeaturesEXT:\n"); + TRACE(" conditionalRendering: %#x.\n", conditional_rendering_features->conditionalRendering); + depth_clip_features = &info->depth_clip_features; TRACE(" VkPhysicalDeviceDepthClipEnableFeaturesEXT:\n"); TRACE(" depthClipEnable: %#x.\n", depth_clip_features->depthClipEnable); @@ -1337,6 +1348,7 @@ static HRESULT vkd3d_init_device_caps(struct d3d12_device *device, *user_extension_supported, vulkan_info, "device", device->vkd3d_instance->config_flags & VKD3D_CONFIG_FLAG_VULKAN_DEBUG);
+ vulkan_info->EXT_conditional_rendering = physical_device_info->conditional_rendering_features.conditionalRendering; vulkan_info->EXT_depth_clip_enable = physical_device_info->depth_clip_features.depthClipEnable;
if (get_spec_version(vk_extensions, count, VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME) >= 3) diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 3af8a95..e0d563f 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -97,6 +97,7 @@ struct vkd3d_vulkan_info bool KHR_maintenance3; bool KHR_push_descriptor; /* EXT device extensions */ + bool EXT_conditional_rendering; bool EXT_debug_marker; bool EXT_depth_clip_enable; bool EXT_descriptor_indexing; @@ -907,6 +908,8 @@ struct d3d12_command_list
bool xfb_enabled;
+ bool is_predicated; + VkFramebuffer current_framebuffer; VkPipeline current_pipeline; VkRenderPass pso_render_pass; diff --git a/libs/vkd3d/vulkan_procs.h b/libs/vkd3d/vulkan_procs.h index a55fb07..702cfd2 100644 --- a/libs/vkd3d/vulkan_procs.h +++ b/libs/vkd3d/vulkan_procs.h @@ -192,6 +192,10 @@ VK_DEVICE_EXT_PFN(vkGetDescriptorSetLayoutSupportKHR) /* VK_KHR_push_descriptor */ VK_DEVICE_EXT_PFN(vkCmdPushDescriptorSetKHR)
+/* VK_EXT_conditional_rendering */ +VK_DEVICE_EXT_PFN(vkCmdBeginConditionalRenderingEXT) +VK_DEVICE_EXT_PFN(vkCmdEndConditionalRenderingEXT) + /* VK_EXT_debug_marker */ VK_DEVICE_EXT_PFN(vkDebugMarkerSetObjectNameEXT)
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- tests/d3d12.c | 363 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 363 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index 81fb26a..6a67536 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -30470,6 +30470,368 @@ static void test_early_depth_stencil_tests(void) destroy_test_context(&context); }
+static void prepare_instanced_draw(ID3D12GraphicsCommandList *command_list, struct test_context *context) +{ + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context->rtv, FALSE, NULL); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context->root_signature); + ID3D12GraphicsCommandList_SetPipelineState(command_list, context->pipeline_state); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context->viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context->scissor_rect); +} + +static void test_conditional_rendering(void) +{ + D3D12_ROOT_SIGNATURE_DESC root_signature_desc; + ID3D12GraphicsCommandList *command_list; + ID3D12CommandSignature *command_signature; + ID3D12RootSignature *root_signature; + D3D12_ROOT_PARAMETER root_parameters[2]; + struct test_context context; + ID3D12CommandQueue *queue; + ID3D12Resource *conditions; + ID3D12Resource *buffer, *cb; + ID3D12Resource *texture, *texture_copy; + ID3D12PipelineState *pipeline_state; + struct resource_readback rb; + uint32_t value; + HRESULT hr; + int i; + + static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f}; + static const uint64_t predicate_args[] = {0, 1, (uint64_t)1 << 32}; + + static const D3D12_DRAW_ARGUMENTS draw_args = {3, 1, 0, 0}; + static const uint32_t r8g8b8a8_data[] = {0x28384858, 0x39495969}; + static const D3D12_SUBRESOURCE_DATA copy_data[] = + { + {&r8g8b8a8_data[0], sizeof(r8g8b8a8_data[0]), sizeof(r8g8b8a8_data[0])}, + {&r8g8b8a8_data[1], sizeof(r8g8b8a8_data[1]), sizeof(r8g8b8a8_data[1])} + }; + + static const DWORD cs_code[] = + { +#if 0 + cbuffer cb + { + unsigned int offset; + unsigned int value; + }; + + RWByteAddressBuffer b; + + [numthreads(1, 1, 1)] + void main() + { + b.Store(4 * offset, value); + } +#endif + 0x43425844, 0xaadc5460, 0x88c27e90, 0x2acacf4e, 0x4e06019a, 0x00000001, 0x000000d8, 0x00000003, + 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000084, 0x00050050, 0x00000021, 0x0100086a, + 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x02000068, + 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x08000029, 0x00100012, 0x00000000, + 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x080000a6, 0x0011e012, 0x00000000, + 0x0010000a, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, + }; + struct + { + uint32_t offset; + uint32_t value; + uint32_t uav_offset; + } + input = {0, 4, 0}; + static const uint32_t init_value = 0xdeadbeef; + + if (!init_test_context(&context, NULL)) + return; + command_list = context.list; + queue = context.queue; + + conditions = create_default_buffer(context.device, sizeof(predicate_args), + D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COPY_DEST); + upload_buffer_data(conditions, 0, sizeof(predicate_args), &predicate_args, queue, command_list); + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, conditions, + D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PREDICATION); + + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + + /* Skip draw on zero */ + prepare_instanced_draw(command_list, &context); + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, 0, D3D12_PREDICATION_OP_EQUAL_ZERO); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + check_sub_resource_uint(context.render_target, 0, queue, command_list, 0xffffffff, 0); + + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); + + /* Skip draw on non-zero */ + prepare_instanced_draw(command_list, &context); + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, sizeof(uint64_t), D3D12_PREDICATION_OP_NOT_EQUAL_ZERO); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); + /* Don't reset predication to test automatic reset on next SetPredication() call */ + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + check_sub_resource_uint(context.render_target, 0, queue, command_list, 0xffffffff, 0); + + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); + + /* Skip clear on zero */ + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, 0, D3D12_PREDICATION_OP_EQUAL_ZERO); + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, green, 0, NULL); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + get_texture_readback_with_command_list(context.render_target, 0, &rb, queue, command_list); + todo check_readback_data_uint(&rb, NULL, 0xffffffff, 0); + release_resource_readback(&rb); + + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); + + /* Draw on zero */ + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + prepare_instanced_draw(command_list, &context); + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, 0, D3D12_PREDICATION_OP_NOT_EQUAL_ZERO); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + check_sub_resource_uint(context.render_target, 0, queue, command_list, 0xff00ff00, 0); + + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); + + /* Draw on non-zero */ + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + prepare_instanced_draw(command_list, &context); + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, sizeof(uint64_t), D3D12_PREDICATION_OP_EQUAL_ZERO); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + check_sub_resource_uint(context.render_target, 0, queue, command_list, 0xff00ff00, 0); + + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); + + /* 64-bit conditional 0x100000000 - fails due to Vulkan 32-bit values */ + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + prepare_instanced_draw(command_list, &context); + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, 2 * sizeof(uint64_t), D3D12_PREDICATION_OP_NOT_EQUAL_ZERO); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + get_texture_readback_with_command_list(context.render_target, 0, &rb, queue, command_list); + todo check_readback_data_uint(&rb, NULL, 0xffffffff, 0); + release_resource_readback(&rb); + reset_command_list(command_list, context.allocator); + + /* ExecuteIndirect */ + buffer = create_upload_buffer(context.device, sizeof(draw_args), &draw_args); + + command_signature = create_command_signature(context.device, D3D12_INDIRECT_ARGUMENT_TYPE_DRAW); + + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + prepare_instanced_draw(command_list, &context); + /* skip */ + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, 0, D3D12_PREDICATION_OP_EQUAL_ZERO); + ID3D12GraphicsCommandList_ExecuteIndirect(command_list, command_signature, 1, buffer, 0, NULL, 0); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + check_sub_resource_uint(context.render_target, 0, queue, command_list, 0xffffffff, 0); + + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); + + prepare_instanced_draw(command_list, &context); + /* draw */ + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, 0, D3D12_PREDICATION_OP_NOT_EQUAL_ZERO); + ID3D12GraphicsCommandList_ExecuteIndirect(command_list, command_signature, 1, buffer, 0, NULL, 0); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + check_sub_resource_uint(context.render_target, 0, queue, command_list, 0xff00ff00, 0); + + ID3D12Resource_Release(buffer); + ID3D12CommandSignature_Release(command_signature); + reset_command_list(command_list, context.allocator); + + /* CopyResource */ + texture = create_default_texture(context.device, + 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D12_RESOURCE_STATE_COPY_DEST); + upload_texture_data(texture, ©_data[0], 1, queue, command_list); + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, texture, + D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE); + + texture_copy = create_default_texture(context.device, + 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D12_RESOURCE_STATE_COPY_DEST); + upload_texture_data(texture_copy, ©_data[1], 1, queue, command_list); + reset_command_list(command_list, context.allocator); + + /* skip */ + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, 0, D3D12_PREDICATION_OP_EQUAL_ZERO); + ID3D12GraphicsCommandList_CopyResource(command_list, texture_copy, texture); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, texture_copy, + D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE); + + get_texture_readback_with_command_list(texture_copy, 0, &rb, queue, command_list); + todo check_readback_data_uint(&rb, NULL, r8g8b8a8_data[1], 0); + release_resource_readback(&rb); + + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, texture_copy, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST); + + /* copy */ + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, 0, D3D12_PREDICATION_OP_NOT_EQUAL_ZERO); + ID3D12GraphicsCommandList_CopyResource(command_list, texture_copy, texture); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, texture_copy, + D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE); + + check_sub_resource_uint(texture_copy, 0, queue, command_list, r8g8b8a8_data[0], 0); + + /* ResolveSubresource */ + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, texture_copy, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST); + upload_texture_data(texture_copy, ©_data[1], 1, queue, command_list); + + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, texture_copy, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RESOLVE_DEST); + transition_resource_state(command_list, texture, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RESOLVE_SOURCE); + + /* skip */ + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, 0, D3D12_PREDICATION_OP_EQUAL_ZERO); + ID3D12GraphicsCommandList_ResolveSubresource(command_list, + texture_copy, 0, texture, 0, DXGI_FORMAT_R8G8B8A8_UNORM); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, texture_copy, + D3D12_RESOURCE_STATE_RESOLVE_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE); + + get_texture_readback_with_command_list(texture_copy, 0, &rb, queue, command_list); + todo check_readback_data_uint(&rb, NULL, r8g8b8a8_data[1], 0); + release_resource_readback(&rb); + + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, texture_copy, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RESOLVE_DEST); + + /* resolve */ + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, 0, D3D12_PREDICATION_OP_NOT_EQUAL_ZERO); + ID3D12GraphicsCommandList_ResolveSubresource(command_list, + texture_copy, 0, texture, 0, DXGI_FORMAT_R8G8B8A8_UNORM); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_resource_state(command_list, texture_copy, + D3D12_RESOURCE_STATE_RESOLVE_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE); + + check_sub_resource_uint(texture_copy, 0, queue, command_list, r8g8b8a8_data[0], 0); + + reset_command_list(command_list, context.allocator); + + /* Dispatch */ + cb = create_upload_buffer(context.device, sizeof(input), &input); + + buffer = create_default_buffer(context.device, 512, + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_DEST); + upload_buffer_data(buffer, 0, sizeof(uint32_t), &init_value, queue, command_list); + reset_command_list(command_list, context.allocator); + transition_sub_resource_state(command_list, buffer, 0, + D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + + root_parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; + root_parameters[0].Descriptor.ShaderRegister = 0; + root_parameters[0].Descriptor.RegisterSpace = 0; + root_parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + root_parameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV; + root_parameters[1].Descriptor.ShaderRegister = 0; + root_parameters[1].Descriptor.RegisterSpace = 0; + root_parameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + memset(&root_signature_desc, 0, sizeof(root_signature_desc)); + root_signature_desc.NumParameters = 2; + root_signature_desc.pParameters = root_parameters; + hr = create_root_signature(context.device, &root_signature_desc, &root_signature); + ok(hr == S_OK, "Failed to create root signature, hr %#x.\n", hr); + + pipeline_state = create_compute_pipeline_state(context.device, root_signature, + shader_bytecode(cs_code, sizeof(cs_code))); + + for (i = 0; i < 2; ++i) + { + ID3D12GraphicsCommandList_SetPipelineState(command_list, pipeline_state); + ID3D12GraphicsCommandList_SetComputeRootSignature(command_list, root_signature); + ID3D12GraphicsCommandList_SetComputeRootConstantBufferView(command_list, + 0, ID3D12Resource_GetGPUVirtualAddress(cb)); + ID3D12GraphicsCommandList_SetComputeRootUnorderedAccessView(command_list, + 1, ID3D12Resource_GetGPUVirtualAddress(buffer)); + ID3D12GraphicsCommandList_SetPredication(command_list, conditions, i * sizeof(uint64_t), + D3D12_PREDICATION_OP_EQUAL_ZERO); + ID3D12GraphicsCommandList_Dispatch(command_list, 1, 1, 1); + ID3D12GraphicsCommandList_SetPredication(command_list, NULL, 0, 0); + + transition_sub_resource_state(command_list, buffer, 0, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); + + get_buffer_readback_with_command_list(buffer, DXGI_FORMAT_R32_UINT, &rb, queue, command_list); + value = get_readback_uint(&rb, 0, 0, 0); + ok(value == (!i ? init_value : input.value), "Got %#x, expected %#x.\n", value, input.value); + release_resource_readback(&rb); + reset_command_list(command_list, context.allocator); + + transition_sub_resource_state(command_list, buffer, 0, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + } + + ID3D12Resource_Release(texture); + ID3D12Resource_Release(texture_copy); + ID3D12Resource_Release(conditions); + ID3D12Resource_Release(cb); + ID3D12Resource_Release(buffer); + ID3D12RootSignature_Release(root_signature); + ID3D12PipelineState_Release(pipeline_state); + destroy_test_context(&context); +} + START_TEST(d3d12) { parse_args(argc, argv); @@ -30629,4 +30991,5 @@ START_TEST(d3d12) run_test(test_queue_wait); run_test(test_graphics_compute_queue_synchronization); run_test(test_early_depth_stencil_tests); + run_test(test_conditional_rendering); }