mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
libs/vkd3d: Add support for static samplers.
We still do not implement any reasonable mapping between D3D registers and Vulkan bindings.
This commit is contained in:
parent
02506b24c4
commit
593a13402d
@ -882,8 +882,11 @@ static VkSamplerAddressMode vk_address_mode_from_d3d12(D3D12_TEXTURE_ADDRESS_MOD
|
||||
}
|
||||
}
|
||||
|
||||
void d3d12_sampler_desc_create_sampler(struct d3d12_sampler_desc *sampler,
|
||||
struct d3d12_device *device, const D3D12_SAMPLER_DESC *desc)
|
||||
static VkResult d3d12_create_sampler(struct d3d12_device *device, D3D12_FILTER filter,
|
||||
D3D12_TEXTURE_ADDRESS_MODE address_u, D3D12_TEXTURE_ADDRESS_MODE address_v,
|
||||
D3D12_TEXTURE_ADDRESS_MODE address_w, float mip_lod_bias, unsigned int max_anisotropy,
|
||||
D3D12_COMPARISON_FUNC comparison_func, float min_lod, float max_lod,
|
||||
VkSampler *vk_sampler)
|
||||
{
|
||||
const struct vkd3d_vk_device_procs *vk_procs;
|
||||
struct VkSamplerCreateInfo sampler_desc;
|
||||
@ -891,6 +894,37 @@ void d3d12_sampler_desc_create_sampler(struct d3d12_sampler_desc *sampler,
|
||||
|
||||
vk_procs = &device->vk_procs;
|
||||
|
||||
if (D3D12_DECODE_FILTER_REDUCTION(filter) == D3D12_FILTER_REDUCTION_TYPE_MINIMUM
|
||||
|| D3D12_DECODE_FILTER_REDUCTION(filter) == D3D12_FILTER_REDUCTION_TYPE_MAXIMUM)
|
||||
FIXME("Min/max reduction mode not supported.\n");
|
||||
|
||||
sampler_desc.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||
sampler_desc.pNext = NULL;
|
||||
sampler_desc.flags = 0;
|
||||
sampler_desc.magFilter = vk_filter_from_d3d12(D3D12_DECODE_MAG_FILTER(filter));
|
||||
sampler_desc.minFilter = vk_filter_from_d3d12(D3D12_DECODE_MIN_FILTER(filter));
|
||||
sampler_desc.mipmapMode = vk_mipmap_mode_from_d3d12(D3D12_DECODE_MIP_FILTER(filter));
|
||||
sampler_desc.addressModeU = vk_address_mode_from_d3d12(address_u);
|
||||
sampler_desc.addressModeV = vk_address_mode_from_d3d12(address_v);
|
||||
sampler_desc.addressModeW = vk_address_mode_from_d3d12(address_w);
|
||||
sampler_desc.mipLodBias = mip_lod_bias;
|
||||
sampler_desc.anisotropyEnable = D3D12_DECODE_IS_ANISOTROPIC_FILTER(filter);
|
||||
sampler_desc.maxAnisotropy = max_anisotropy;
|
||||
sampler_desc.compareEnable = D3D12_DECODE_IS_COMPARISON_FILTER(filter);
|
||||
sampler_desc.compareOp = sampler_desc.compareEnable ? vk_compare_op_from_d3d12(comparison_func) : 0;
|
||||
sampler_desc.minLod = min_lod;
|
||||
sampler_desc.maxLod = max_lod;
|
||||
sampler_desc.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
||||
sampler_desc.unnormalizedCoordinates = VK_FALSE;
|
||||
if ((vr = VK_CALL(vkCreateSampler(device->vk_device, &sampler_desc, NULL, vk_sampler))) < 0)
|
||||
WARN("Failed to create Vulkan sampler, vr %d.\n", vr);
|
||||
|
||||
return vr;
|
||||
}
|
||||
|
||||
void d3d12_sampler_desc_create_sampler(struct d3d12_sampler_desc *sampler,
|
||||
struct d3d12_device *device, const D3D12_SAMPLER_DESC *desc)
|
||||
{
|
||||
d3d12_sampler_desc_destroy(sampler, device);
|
||||
|
||||
if (!desc)
|
||||
@ -899,43 +933,36 @@ void d3d12_sampler_desc_create_sampler(struct d3d12_sampler_desc *sampler,
|
||||
return;
|
||||
}
|
||||
|
||||
if (D3D12_DECODE_FILTER_REDUCTION(desc->Filter) == D3D12_FILTER_REDUCTION_TYPE_MINIMUM
|
||||
|| D3D12_DECODE_FILTER_REDUCTION(desc->Filter) == D3D12_FILTER_REDUCTION_TYPE_MAXIMUM)
|
||||
FIXME("Min/max reduction mode not supported.\n");
|
||||
|
||||
if (desc->AddressU == D3D12_TEXTURE_ADDRESS_MODE_BORDER
|
||||
|| desc->AddressV == D3D12_TEXTURE_ADDRESS_MODE_BORDER
|
||||
|| desc->AddressW == D3D12_TEXTURE_ADDRESS_MODE_BORDER)
|
||||
FIXME("Ignoring border color {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
desc->BorderColor[0], desc->BorderColor[1], desc->BorderColor[2], desc->BorderColor[3]);
|
||||
|
||||
sampler_desc.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||
sampler_desc.pNext = NULL;
|
||||
sampler_desc.flags = 0;
|
||||
sampler_desc.magFilter = vk_filter_from_d3d12(D3D12_DECODE_MAG_FILTER(desc->Filter));
|
||||
sampler_desc.minFilter = vk_filter_from_d3d12(D3D12_DECODE_MIN_FILTER(desc->Filter));
|
||||
sampler_desc.mipmapMode = vk_mipmap_mode_from_d3d12(D3D12_DECODE_MIP_FILTER(desc->Filter));
|
||||
sampler_desc.addressModeU = vk_address_mode_from_d3d12(desc->AddressU);
|
||||
sampler_desc.addressModeV = vk_address_mode_from_d3d12(desc->AddressV);
|
||||
sampler_desc.addressModeW = vk_address_mode_from_d3d12(desc->AddressW);
|
||||
sampler_desc.mipLodBias = desc->MipLODBias;
|
||||
sampler_desc.anisotropyEnable = D3D12_DECODE_IS_ANISOTROPIC_FILTER(desc->Filter);
|
||||
sampler_desc.maxAnisotropy = desc->MaxAnisotropy;
|
||||
sampler_desc.compareEnable = D3D12_DECODE_IS_COMPARISON_FILTER(desc->Filter);
|
||||
sampler_desc.compareOp = sampler_desc.compareEnable ? vk_compare_op_from_d3d12(desc->ComparisonFunc) : 0;
|
||||
sampler_desc.minLod = desc->MinLOD;
|
||||
sampler_desc.maxLod = desc->MaxLOD;
|
||||
sampler_desc.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
||||
sampler_desc.unnormalizedCoordinates = VK_FALSE;
|
||||
if ((vr = VK_CALL(vkCreateSampler(device->vk_device, &sampler_desc, NULL, &sampler->vk_sampler))) < 0)
|
||||
{
|
||||
WARN("Failed to create Vulkan sampler, vr %d.\n", vr);
|
||||
if (d3d12_create_sampler(device, desc->Filter, desc->AddressU,
|
||||
desc->AddressV, desc->AddressW, desc->MipLODBias, desc->MaxAnisotropy,
|
||||
desc->ComparisonFunc, desc->MinLOD, desc->MaxLOD, &sampler->vk_sampler) < 0)
|
||||
return;
|
||||
}
|
||||
|
||||
sampler->magic = VKD3D_DESCRIPTOR_MAGIC_SAMPLER;
|
||||
}
|
||||
|
||||
HRESULT d3d12_device_create_static_sampler(struct d3d12_device *device,
|
||||
const D3D12_STATIC_SAMPLER_DESC *desc, VkSampler *vk_sampler)
|
||||
{
|
||||
VkResult vr;
|
||||
|
||||
if (desc->AddressU == D3D12_TEXTURE_ADDRESS_MODE_BORDER
|
||||
|| desc->AddressV == D3D12_TEXTURE_ADDRESS_MODE_BORDER
|
||||
|| desc->AddressW == D3D12_TEXTURE_ADDRESS_MODE_BORDER)
|
||||
FIXME("Ignoring border %#x.\n", desc->BorderColor);
|
||||
|
||||
vr = d3d12_create_sampler(device, desc->Filter, desc->AddressU,
|
||||
desc->AddressV, desc->AddressW, desc->MipLODBias, desc->MaxAnisotropy,
|
||||
desc->ComparisonFunc, desc->MinLOD, desc->MaxLOD, vk_sampler);
|
||||
return hresult_from_vk_result(vr);
|
||||
}
|
||||
|
||||
/* RTVs */
|
||||
static void d3d12_rtv_desc_destroy(struct d3d12_rtv_desc *rtv, struct d3d12_device *device)
|
||||
{
|
||||
|
@ -70,11 +70,16 @@ static ULONG STDMETHODCALLTYPE d3d12_root_signature_Release(ID3D12RootSignature
|
||||
{
|
||||
struct d3d12_device *device = root_signature->device;
|
||||
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
|
||||
unsigned int i;
|
||||
|
||||
VK_CALL(vkDestroyPipelineLayout(device->vk_device, root_signature->vk_pipeline_layout, NULL));
|
||||
vkd3d_free(root_signature->pool_sizes);
|
||||
VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, root_signature->vk_set_layout, NULL));
|
||||
|
||||
for (i = 0; i < root_signature->static_sampler_count; ++i)
|
||||
VK_CALL(vkDestroySampler(device->vk_device, root_signature->static_samplers[i], NULL));
|
||||
vkd3d_free(root_signature->static_samplers);
|
||||
|
||||
vkd3d_free(root_signature);
|
||||
|
||||
ID3D12Device_Release(&device->ID3D12Device_iface);
|
||||
@ -220,18 +225,17 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa
|
||||
struct VkDescriptorSetLayoutBinding *binding_desc;
|
||||
struct VkDescriptorSetLayoutCreateInfo set_desc;
|
||||
size_t cbv_count = 0, srv_count = 0;
|
||||
unsigned int i;
|
||||
unsigned int i, j;
|
||||
VkResult vr;
|
||||
HRESULT hr;
|
||||
|
||||
root_signature->ID3D12RootSignature_iface.lpVtbl = &d3d12_root_signature_vtbl;
|
||||
root_signature->refcount = 1;
|
||||
|
||||
if (desc->NumStaticSamplers)
|
||||
FIXME("Static samplers not implemented yet.\n");
|
||||
if (desc->Flags)
|
||||
FIXME("Ignoring root signature flags %#x.\n", desc->Flags);
|
||||
|
||||
if (!(binding_desc = vkd3d_calloc(desc->NumParameters, sizeof(*binding_desc))))
|
||||
if (!(binding_desc = vkd3d_calloc(desc->NumParameters + desc->NumStaticSamplers, sizeof(*binding_desc))))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
for (i = 0; i < desc->NumParameters; ++i)
|
||||
@ -293,12 +297,42 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa
|
||||
}
|
||||
}
|
||||
|
||||
root_signature->static_sampler_count = desc->NumStaticSamplers;
|
||||
if (!(root_signature->static_samplers = vkd3d_calloc(root_signature->static_sampler_count,
|
||||
sizeof(*root_signature->static_samplers))))
|
||||
{
|
||||
vkd3d_free(binding_desc);
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
for (j = 0; j < desc->NumStaticSamplers; ++i, ++j)
|
||||
{
|
||||
const D3D12_STATIC_SAMPLER_DESC *s = &desc->pStaticSamplers[j];
|
||||
|
||||
if (s->RegisterSpace)
|
||||
FIXME("Unhandled register space %u for static sampler %u.\n", s->RegisterSpace, j);
|
||||
|
||||
if (FAILED(hr = d3d12_device_create_static_sampler(device, s, &root_signature->static_samplers[j])))
|
||||
{
|
||||
for (i = 0; i < j; ++i)
|
||||
VK_CALL(vkDestroySampler(device->vk_device, root_signature->static_samplers[i], NULL));
|
||||
vkd3d_free(root_signature->static_samplers);
|
||||
vkd3d_free(binding_desc);
|
||||
return hr;
|
||||
}
|
||||
|
||||
binding_desc[i].binding = s->ShaderRegister;
|
||||
binding_desc[i].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
|
||||
binding_desc[i].descriptorCount = 1;
|
||||
binding_desc[i].stageFlags = stage_flags_from_visibility(s->ShaderVisibility);
|
||||
binding_desc[i].pImmutableSamplers = &root_signature->static_samplers[j];
|
||||
}
|
||||
|
||||
set_desc.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||
set_desc.pNext = NULL;
|
||||
set_desc.flags = 0;
|
||||
set_desc.bindingCount = desc->NumParameters;
|
||||
set_desc.bindingCount = desc->NumParameters + desc->NumStaticSamplers;
|
||||
set_desc.pBindings = binding_desc;
|
||||
|
||||
vr = VK_CALL(vkCreateDescriptorSetLayout(device->vk_device, &set_desc, NULL, &root_signature->vk_set_layout));
|
||||
vkd3d_free(binding_desc);
|
||||
if (vr < 0)
|
||||
@ -318,6 +352,9 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa
|
||||
sizeof(*root_signature->pool_sizes))))
|
||||
{
|
||||
VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, root_signature->vk_set_layout, NULL));
|
||||
for (i = 0; i < root_signature->static_sampler_count; ++i)
|
||||
VK_CALL(vkDestroySampler(device->vk_device, root_signature->static_samplers[i], NULL));
|
||||
vkd3d_free(root_signature->static_samplers);
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
@ -346,13 +383,15 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa
|
||||
pipeline_layout_info.pSetLayouts = &root_signature->vk_set_layout;
|
||||
pipeline_layout_info.pushConstantRangeCount = 0;
|
||||
pipeline_layout_info.pPushConstantRanges = NULL;
|
||||
|
||||
if ((vr = VK_CALL(vkCreatePipelineLayout(device->vk_device, &pipeline_layout_info, NULL,
|
||||
&root_signature->vk_pipeline_layout))) < 0)
|
||||
{
|
||||
WARN("Failed to create Vulkan pipeline layout, vr %d.\n", vr);
|
||||
vkd3d_free(root_signature->pool_sizes);
|
||||
VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, root_signature->vk_set_layout, NULL));
|
||||
for (i = 0; i < root_signature->static_sampler_count; ++i)
|
||||
VK_CALL(vkDestroySampler(device->vk_device, root_signature->static_samplers[i], NULL));
|
||||
vkd3d_free(root_signature->static_samplers);
|
||||
return hresult_from_vk_result(vr);
|
||||
}
|
||||
|
||||
|
@ -174,6 +174,8 @@ struct d3d12_sampler_desc
|
||||
|
||||
void d3d12_sampler_desc_create_sampler(struct d3d12_sampler_desc *sampler,
|
||||
struct d3d12_device *device, const D3D12_SAMPLER_DESC *desc) DECLSPEC_HIDDEN;
|
||||
HRESULT d3d12_device_create_static_sampler(struct d3d12_device *device,
|
||||
const D3D12_STATIC_SAMPLER_DESC *desc, VkSampler *vk_sampler) DECLSPEC_HIDDEN;
|
||||
|
||||
struct d3d12_rtv_desc
|
||||
{
|
||||
@ -229,6 +231,9 @@ struct d3d12_root_signature
|
||||
struct VkDescriptorPoolSize *pool_sizes;
|
||||
size_t pool_size_count;
|
||||
|
||||
unsigned int static_sampler_count;
|
||||
VkSampler *static_samplers;
|
||||
|
||||
struct d3d12_device *device;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user