mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
libs/vkd3d: Create single default sampler per device.
This commit is contained in:
parent
cfa827b2f8
commit
8cb004bdc4
@ -770,6 +770,18 @@ static HRESULT vkd3d_create_vk_device(struct d3d12_device *device)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT d3d12_device_create_default_sampler(struct d3d12_device *device)
|
||||
{
|
||||
D3D12_STATIC_SAMPLER_DESC sampler_desc;
|
||||
|
||||
memset(&sampler_desc, 0, sizeof(sampler_desc));
|
||||
sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
|
||||
sampler_desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
||||
sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
||||
sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
||||
return vkd3d_create_static_sampler(device, &sampler_desc, &device->vk_default_sampler);
|
||||
}
|
||||
|
||||
static void d3d12_device_init_pipeline_cache(struct d3d12_device *device)
|
||||
{
|
||||
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
|
||||
@ -907,6 +919,7 @@ static ULONG STDMETHODCALLTYPE d3d12_device_Release(ID3D12Device *iface)
|
||||
|
||||
vkd3d_gpu_va_allocator_cleanup(&device->gpu_va_allocator);
|
||||
vkd3d_fence_worker_stop(&device->fence_worker);
|
||||
VK_CALL(vkDestroySampler(device->vk_device, device->vk_default_sampler, NULL));
|
||||
if (device->vk_pipeline_cache)
|
||||
VK_CALL(vkDestroyPipelineCache(device->vk_device, device->vk_pipeline_cache, NULL));
|
||||
VK_CALL(vkDestroyDevice(device->vk_device, NULL));
|
||||
@ -1753,9 +1766,19 @@ static HRESULT d3d12_device_init(struct d3d12_device *device,
|
||||
device->signal_event = create_info->signal_event_pfn;
|
||||
device->wchar_size = create_info->wchar_size;
|
||||
|
||||
if (FAILED(hr = d3d12_device_create_default_sampler(device)))
|
||||
{
|
||||
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
|
||||
ERR("Failed to create default sampler, hr %#x.\n", hr);
|
||||
VK_CALL(vkDestroyDevice(device->vk_device, NULL));
|
||||
vkd3d_instance_destroy(&device->vkd3d_instance);
|
||||
return hr;
|
||||
}
|
||||
|
||||
if (FAILED(hr = vkd3d_fence_worker_start(&device->fence_worker, device)))
|
||||
{
|
||||
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
|
||||
VK_CALL(vkDestroySampler(device->vk_device, device->vk_default_sampler, NULL));
|
||||
VK_CALL(vkDestroyDevice(device->vk_device, NULL));
|
||||
vkd3d_instance_destroy(&device->vkd3d_instance);
|
||||
return hr;
|
||||
|
@ -764,21 +764,10 @@ static HRESULT d3d12_root_signature_init_root_descriptors(struct d3d12_root_sign
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT d3d12_root_signature_create_default_sampler(struct d3d12_root_signature *root_signature,
|
||||
struct d3d12_device *device, unsigned int index, struct vkd3d_descriptor_set_context *context,
|
||||
VkDescriptorSetLayoutBinding *binding)
|
||||
static HRESULT d3d12_root_signature_init_default_sampler(struct d3d12_root_signature *root_signature,
|
||||
struct d3d12_device *device, struct vkd3d_descriptor_set_context *context)
|
||||
{
|
||||
D3D12_STATIC_SAMPLER_DESC sampler_desc;
|
||||
HRESULT hr;
|
||||
|
||||
memset(&sampler_desc, 0, sizeof(sampler_desc));
|
||||
sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
|
||||
sampler_desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
||||
sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
||||
sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
||||
if (FAILED(hr = vkd3d_create_static_sampler(device, &sampler_desc,
|
||||
&root_signature->static_samplers[index])))
|
||||
return hr;
|
||||
VkDescriptorSetLayoutBinding *binding = context->current_binding;
|
||||
|
||||
root_signature->default_sampler.set = context->set_index;
|
||||
root_signature->default_sampler.binding = context->descriptor_binding++;
|
||||
@ -787,7 +776,9 @@ static HRESULT d3d12_root_signature_create_default_sampler(struct d3d12_root_sig
|
||||
binding->descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
|
||||
binding->descriptorCount = 1;
|
||||
binding->stageFlags = VK_SHADER_STAGE_ALL;
|
||||
binding->pImmutableSamplers = &root_signature->static_samplers[index];
|
||||
binding->pImmutableSamplers = &device->vk_default_sampler;
|
||||
|
||||
++context->current_binding;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@ -799,6 +790,7 @@ static HRESULT d3d12_root_signature_init_static_samplers(struct d3d12_root_signa
|
||||
unsigned int i;
|
||||
HRESULT hr;
|
||||
|
||||
assert(root_signature->static_sampler_count == desc->NumStaticSamplers);
|
||||
for (i = 0; i < desc->NumStaticSamplers; ++i)
|
||||
{
|
||||
const D3D12_STATIC_SAMPLER_DESC *s = &desc->pStaticSamplers[i];
|
||||
@ -819,14 +811,6 @@ static HRESULT d3d12_root_signature_init_static_samplers(struct d3d12_root_signa
|
||||
++cur_binding;
|
||||
}
|
||||
|
||||
if (i < root_signature->static_sampler_count)
|
||||
{
|
||||
if (FAILED(hr = d3d12_root_signature_create_default_sampler(root_signature, device,
|
||||
i, context, cur_binding)))
|
||||
return hr;
|
||||
++cur_binding;
|
||||
}
|
||||
|
||||
context->current_binding = cur_binding;
|
||||
return S_OK;
|
||||
}
|
||||
@ -887,6 +871,7 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa
|
||||
VkDescriptorSetLayoutBinding *binding_desc;
|
||||
struct d3d12_root_signature_info info;
|
||||
VkDescriptorSetLayout set_layouts[2];
|
||||
bool needs_default_sampler;
|
||||
HRESULT hr;
|
||||
|
||||
memset(&context, 0, sizeof(context));
|
||||
@ -926,11 +911,11 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa
|
||||
root_signature->root_descriptor_count = info.root_descriptor_count;
|
||||
|
||||
/* An additional sampler is created for SpvOpImageFetch. */
|
||||
if (info.srv_count || info.buffer_srv_count)
|
||||
needs_default_sampler = info.srv_count || info.buffer_srv_count;
|
||||
if (needs_default_sampler)
|
||||
{
|
||||
++info.sampler_count;
|
||||
++info.descriptor_count;
|
||||
++root_signature->static_sampler_count;
|
||||
}
|
||||
|
||||
hr = E_OUTOFMEMORY;
|
||||
@ -979,6 +964,9 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa
|
||||
goto fail;
|
||||
if (FAILED(hr = d3d12_root_signature_init_static_samplers(root_signature, device, desc, &context)))
|
||||
goto fail;
|
||||
if (needs_default_sampler && FAILED(hr = d3d12_root_signature_init_default_sampler(root_signature,
|
||||
device, &context)))
|
||||
goto fail;
|
||||
|
||||
root_signature->main_set = context.set_index;
|
||||
if (context.descriptor_binding)
|
||||
|
@ -589,6 +589,9 @@ struct d3d12_device
|
||||
|
||||
VkPipelineCache vk_pipeline_cache;
|
||||
|
||||
/* A sampler used for SpvOpImageFetch. */
|
||||
VkSampler vk_default_sampler;
|
||||
|
||||
unsigned int direct_queue_family_index;
|
||||
unsigned int copy_queue_family_index;
|
||||
unsigned int compute_queue_family_index;
|
||||
|
Loading…
x
Reference in New Issue
Block a user