Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- tests/d3d12.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index 89b1f000..972ec766 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -673,6 +673,21 @@ static bool is_shader_float64_supported(ID3D12Device *device) return options.DoublePrecisionFloatShaderOps; }
+static bool is_output_merger_logic_op_supported(ID3D12Device *device) +{ + D3D12_FEATURE_DATA_D3D12_OPTIONS options; + HRESULT hr; + + if (FAILED(hr = ID3D12Device_CheckFeatureSupport(device, + D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options)))) + { + trace("Failed to check feature support, hr %#x.\n", hr); + return false; + } + + return options.OutputMergerLogicOp; +} + #define create_cb_root_signature(a, b, c, e) create_cb_root_signature_(__LINE__, a, b, c, e) static ID3D12RootSignature *create_cb_root_signature_(unsigned int line, ID3D12Device *device, unsigned int reg_idx, D3D12_SHADER_VISIBILITY shader_visibility, @@ -30895,6 +30910,128 @@ static void test_dual_source_blending(void) destroy_test_context(&context); }
+static void test_output_merger_logic_op(void) +{ + D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc; + ID3D12GraphicsCommandList *command_list; + ID3D12PipelineState *logic_pso; + struct test_context_desc desc; + struct test_context context; + ID3D12CommandQueue *queue; + unsigned int i, do_test; + HRESULT hr; + + static const DWORD ps_code[] = + { +#if 0 + uint4 c0; + + void main(const in float4 position : SV_Position, out uint4 target : SV_Target0) + { + target = c0; + } +#endif + 0x43425844, 0xb1d5d133, 0xbd9958bf, 0xe4a12856, 0x0197481b, 0x00000001, 0x000000e0, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, + 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, + 0x00000011, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, + 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, + }; + static const D3D12_SHADER_BYTECODE ps = {ps_code, sizeof(ps_code)}; + static const uint32_t clear_values[4] = {0xffffffff, 0x00000000, 0xffffffff, 0x00000000}; + static const uint32_t test_values[4] = {0xffffffff, 0xffffffff, 0x00000000, 0x00000000}; + static const struct + { + D3D12_LOGIC_OP logic_op; + unsigned int expected_colour; + } + tests[] = + { + {D3D12_LOGIC_OP_CLEAR, 0x00000000}, + {D3D12_LOGIC_OP_SET, 0xffffffff}, + {D3D12_LOGIC_OP_COPY, 0x0000ffff}, + {D3D12_LOGIC_OP_COPY_INVERTED, 0xffff0000}, + {D3D12_LOGIC_OP_NOOP, 0x00ff00ff}, + {D3D12_LOGIC_OP_INVERT, 0xff00ff00}, + {D3D12_LOGIC_OP_AND, 0x000000ff}, + {D3D12_LOGIC_OP_NAND, 0xffffff00}, + {D3D12_LOGIC_OP_OR, 0x00ffffff}, + {D3D12_LOGIC_OP_NOR, 0xff000000}, + {D3D12_LOGIC_OP_XOR, 0x00ffff00}, + {D3D12_LOGIC_OP_EQUIV, 0xff0000ff}, + {D3D12_LOGIC_OP_AND_REVERSE, 0x0000ff00}, + {D3D12_LOGIC_OP_AND_INVERTED, 0x00ff0000}, + {D3D12_LOGIC_OP_OR_REVERSE, 0xff00ffff}, + {D3D12_LOGIC_OP_OR_INVERTED, 0xffff00ff}, + }; + + memset(&desc, 0, sizeof(desc)); + desc.no_root_signature = true; + desc.ps = &ps; + desc.rt_format = DXGI_FORMAT_R8G8B8A8_UINT; + if (!init_test_context(&context, &desc)) + return; + command_list = context.list; + queue = context.queue; + + if (!is_output_merger_logic_op_supported(context.device)) + { + skip("The device does not support output merger logic ops.\n"); + destroy_test_context(&context); + return; + } + + context.root_signature = create_32bit_constants_root_signature(context.device, + 0, sizeof(clear_values) / sizeof(uint32_t), D3D12_SHADER_VISIBILITY_PIXEL); + + init_pipeline_state_desc(&pso_desc, context.root_signature, + context.render_target_desc.Format, NULL, &ps, NULL); + hr = ID3D12Device_CreateGraphicsPipelineState(context.device, &pso_desc, + &IID_ID3D12PipelineState, (void **)&context.pipeline_state); + ok(hr == S_OK, "Failed to create pipeline, hr %#x.\n", hr); + + pso_desc.BlendState.RenderTarget[0].LogicOpEnable = true; + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + pso_desc.BlendState.RenderTarget[0].LogicOp = tests[i].logic_op; + hr = ID3D12Device_CreateGraphicsPipelineState(context.device, &pso_desc, + &IID_ID3D12PipelineState, (void **)&logic_pso); + ok(hr == S_OK, "Failed to create pipeline, hr %#x.\n", hr); + + for (do_test = 0; do_test < 2; ++do_test) + { + vkd3d_test_set_context(do_test ? "Test %u" : "Clear %u", i); + + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, false, NULL); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); + ID3D12GraphicsCommandList_SetPipelineState(command_list, do_test ? logic_pso : context.pipeline_state); + ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(command_list, 0, 4, + do_test ? test_values : clear_values, 0); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + todo_if(do_test && tests[i].logic_op != D3D12_LOGIC_OP_COPY) + check_sub_resource_uint(context.render_target, 0, queue, command_list, + do_test ? tests[i].expected_colour : 0x00ff00ff, 1); + 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); + } + + ID3D12PipelineState_Release(logic_pso); + } + vkd3d_test_set_context(NULL); + + destroy_test_context(&context); +} + static void test_multisample_rendering(void) { static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; @@ -35273,6 +35410,7 @@ START_TEST(d3d12) run_test(test_command_list_initial_pipeline_state); run_test(test_blend_factor); run_test(test_dual_source_blending); + run_test(test_output_merger_logic_op); run_test(test_multisample_rendering); run_test(test_sample_mask); run_test(test_coverage);
Using vk_logic_op_from_d3d12() from a vkd3d-proton patch by Philip Rebohle.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/state.c | 58 ++++++++++++++++++++++++++++++++++---- libs/vkd3d/vkd3d_private.h | 2 ++ tests/d3d12.c | 1 - 3 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 9e554b44..52400d6b 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -2062,9 +2062,6 @@ static void blend_attachment_from_d3d12(struct VkPipelineColorBlendAttachmentSta vk_desc->colorWriteMask |= VK_COLOR_COMPONENT_B_BIT; if (d3d12_desc->RenderTargetWriteMask & D3D12_COLOR_WRITE_ENABLE_ALPHA) vk_desc->colorWriteMask |= VK_COLOR_COMPONENT_A_BIT; - - if (d3d12_desc->LogicOpEnable) - FIXME("Ignoring LogicOpEnable %#x.\n", d3d12_desc->LogicOpEnable); }
static bool is_dual_source_blending_blend(D3D12_BLEND b) @@ -2174,6 +2171,48 @@ static HRESULT d3d12_graphics_pipeline_state_create_render_pass( return vkd3d_render_pass_cache_find(&device->render_pass_cache, device, &key, vk_render_pass); }
+static VkLogicOp vk_logic_op_from_d3d12(D3D12_LOGIC_OP op) +{ + switch (op) + { + case D3D12_LOGIC_OP_CLEAR: + return VK_LOGIC_OP_CLEAR; + case D3D12_LOGIC_OP_SET: + return VK_LOGIC_OP_SET; + case D3D12_LOGIC_OP_COPY: + return VK_LOGIC_OP_COPY; + case D3D12_LOGIC_OP_COPY_INVERTED: + return VK_LOGIC_OP_COPY_INVERTED; + case D3D12_LOGIC_OP_NOOP: + return VK_LOGIC_OP_NO_OP; + case D3D12_LOGIC_OP_INVERT: + return VK_LOGIC_OP_INVERT; + case D3D12_LOGIC_OP_AND: + return VK_LOGIC_OP_AND; + case D3D12_LOGIC_OP_NAND: + return VK_LOGIC_OP_NAND; + case D3D12_LOGIC_OP_OR: + return VK_LOGIC_OP_OR; + case D3D12_LOGIC_OP_NOR: + return VK_LOGIC_OP_NOR; + case D3D12_LOGIC_OP_XOR: + return VK_LOGIC_OP_XOR; + case D3D12_LOGIC_OP_EQUIV: + return VK_LOGIC_OP_EQUIVALENT; + case D3D12_LOGIC_OP_AND_REVERSE: + return VK_LOGIC_OP_AND_REVERSE; + case D3D12_LOGIC_OP_AND_INVERTED: + return VK_LOGIC_OP_AND_INVERTED; + case D3D12_LOGIC_OP_OR_REVERSE: + return VK_LOGIC_OP_OR_REVERSE; + case D3D12_LOGIC_OP_OR_INVERTED: + return VK_LOGIC_OP_OR_INVERTED; + default: + FIXME("Unhandled logic op %#x.\n", op); + return VK_LOGIC_OP_NO_OP; + } +} + static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *state, struct d3d12_device *device, const D3D12_GRAPHICS_PIPELINE_STATE_DESC *desc) { @@ -2264,6 +2303,15 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s rt_count = ARRAY_SIZE(graphics->blend_attachments); }
+ graphics->om_logic_op_enable = desc->BlendState.RenderTarget[0].LogicOpEnable + && device->feature_options.OutputMergerLogicOp; + graphics->om_logic_op = graphics->om_logic_op_enable + ? vk_logic_op_from_d3d12(desc->BlendState.RenderTarget[0].LogicOp) + : VK_LOGIC_OP_COPY; + if (desc->BlendState.RenderTarget[0].LogicOpEnable && !graphics->om_logic_op_enable) + WARN("The device does not support output merger logic ops. Ignoring logic op %#x.\n", + desc->BlendState.RenderTarget[0].LogicOp); + graphics->null_attachment_mask = 0; for (i = 0; i < rt_count; ++i) { @@ -2973,8 +3021,8 @@ VkPipeline d3d12_pipeline_state_get_or_create_pipeline(struct d3d12_pipeline_sta blend_desc.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; blend_desc.pNext = NULL; blend_desc.flags = 0; - blend_desc.logicOpEnable = VK_FALSE; - blend_desc.logicOp = VK_LOGIC_OP_COPY; + blend_desc.logicOpEnable = graphics->om_logic_op_enable; + blend_desc.logicOp = graphics->om_logic_op; blend_desc.attachmentCount = graphics->rt_count; blend_desc.pAttachments = graphics->blend_attachments; blend_desc.blendConstants[0] = D3D12_DEFAULT_BLEND_FACTOR_RED; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 0b326b11..b5bbb8e5 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -741,6 +741,8 @@ struct d3d12_graphics_pipeline_state size_t instance_divisor_count; size_t attribute_count;
+ bool om_logic_op_enable; + VkLogicOp om_logic_op; VkPipelineColorBlendAttachmentState blend_attachments[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT]; unsigned int rt_count; unsigned int null_attachment_mask; diff --git a/tests/d3d12.c b/tests/d3d12.c index 972ec766..384e978c 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -31017,7 +31017,6 @@ static void test_output_merger_logic_op(void)
transition_resource_state(command_list, context.render_target, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); - todo_if(do_test && tests[i].logic_op != D3D12_LOGIC_OP_COPY) check_sub_resource_uint(context.render_target, 0, queue, command_list, do_test ? tests[i].expected_colour : 0x00ff00ff, 1); reset_command_list(command_list, context.allocator);