Compare commits

...

2 Commits

Author SHA1 Message Date
Joshua Ashton 07e22a13d0 vkd3d: Fix potential lack of null termination on cache blob versions
The Git sha's are 7 characters long, but this may change if we tag a release that has a name.
Ensure this is null terminated to shut up a compiler warning.

Signed-off-by: Joshua Ashton <joshua@froggi.es>
2020-10-04 18:28:42 +01:00
Joshua Ashton 31edccd237 vkd3d: Migrate version to a header
Signed-off-by: Joshua Ashton <joshua@froggi.es>
2020-10-04 18:13:31 +01:00
5 changed files with 15 additions and 12 deletions

View File

@ -36,14 +36,13 @@ static VkResult vkd3d_create_pipeline_cache(struct d3d12_device *device,
}
#define VKD3D_CACHE_BLOB_VERSION MAKE_MAGIC('V','K','B',1)
#define VKD3D_CACHE_BUILD_SIZE 8
struct vkd3d_pipeline_blob
{
uint32_t version;
uint32_t vendor_id;
uint32_t device_id;
char vkd3d_build[VKD3D_CACHE_BUILD_SIZE];
char vkd3d_build[VKD3D_BUILD_SIZE];
uint8_t cache_uuid[VK_UUID_SIZE];
uint8_t vk_blob[];
};
@ -71,7 +70,7 @@ HRESULT vkd3d_create_pipeline_cache_from_d3d12_desc(struct d3d12_device *device,
/* Check the vkd3d build since the shader compiler itself may change,
* and the driver since that will affect the generated pipeline cache */
if (strncmp(blob->vkd3d_build, vkd3d_build, VKD3D_CACHE_BUILD_SIZE) ||
if (strncmp(blob->vkd3d_build, vkd3d_build, VKD3D_BUILD_SIZE) ||
memcmp(blob->cache_uuid, device_properties->pipelineCacheUUID, VK_UUID_SIZE))
return D3D12_ERROR_DRIVER_VERSION_MISMATCH;
@ -107,7 +106,8 @@ VkResult vkd3d_serialize_pipeline_state(const struct d3d12_pipeline_state *state
blob->version = VKD3D_CACHE_BLOB_VERSION;
blob->vendor_id = device_properties->vendorID;
blob->device_id = device_properties->deviceID;
strncpy(blob->vkd3d_build, vkd3d_build, VKD3D_CACHE_BUILD_SIZE);
strncpy(blob->vkd3d_build, vkd3d_build, VKD3D_BUILD_SIZE);
blob->vkd3d_build[VKD3D_BUILD_MAX_LENGTH] = '\0';
memcpy(blob->cache_uuid, device_properties->pipelineCacheUUID, VK_UUID_SIZE);
if (state->vk_pso_cache)
@ -182,7 +182,7 @@ struct vkd3d_serialized_pipeline_library
uint32_t vendor_id;
uint32_t device_id;
uint32_t pipeline_count;
char vkd3d_build[VKD3D_CACHE_BUILD_SIZE];
char vkd3d_build[VKD3D_BUILD_SIZE];
uint8_t cache_uuid[VK_UUID_SIZE];
uint8_t data[];
};
@ -551,7 +551,8 @@ static HRESULT STDMETHODCALLTYPE d3d12_pipeline_library_Serialize(d3d12_pipeline
header->vendor_id = device_properties->vendorID;
header->device_id = device_properties->deviceID;
header->pipeline_count = pipeline_library->map.used_count;
strncpy(header->vkd3d_build, vkd3d_build, VKD3D_CACHE_BUILD_SIZE);
strncpy(header->vkd3d_build, vkd3d_build, VKD3D_BUILD_SIZE);
header->vkd3d_build[VKD3D_BUILD_MAX_LENGTH] = '\0';
memcpy(header->cache_uuid, device_properties->pipelineCacheUUID, VK_UUID_SIZE);
for (i = 0; i < pipeline_library->map.entry_count; i++)
@ -643,7 +644,7 @@ static HRESULT d3d12_pipeline_library_read_blob(struct d3d12_pipeline_library *p
if (header->device_id != device_properties->deviceID || header->vendor_id != device_properties->vendorID)
return D3D12_ERROR_ADAPTER_NOT_FOUND;
if (strncmp(header->vkd3d_build, vkd3d_build, VKD3D_CACHE_BUILD_SIZE) ||
if (strncmp(header->vkd3d_build, vkd3d_build, VKD3D_BUILD_SIZE) ||
memcmp(header->cache_uuid, device_properties->pipelineCacheUUID, VK_UUID_SIZE))
return D3D12_ERROR_DRIVER_VERSION_MISMATCH;

View File

@ -31,6 +31,7 @@
#include "vkd3d.h"
#include "vkd3d_shader.h"
#include "vkd3d_version.h"
#include "vkd3d_threads.h"
#include "vkd3d_platform.h"
#include "vkd3d_swapchain_factory.h"
@ -2084,8 +2085,6 @@ HRESULT vkd3d_load_vk_instance_procs(struct vkd3d_vk_instance_procs *procs,
HRESULT vkd3d_load_vk_device_procs(struct vkd3d_vk_device_procs *procs,
const struct vkd3d_vk_instance_procs *parent_procs, VkDevice device) DECLSPEC_HIDDEN;
extern const char vkd3d_build[];
VkResult vkd3d_set_vk_object_name_utf8(struct d3d12_device *device, uint64_t vk_object,
VkObjectType vk_object_type, const char *name) DECLSPEC_HIDDEN;
HRESULT vkd3d_set_vk_object_name(struct d3d12_device *device, uint64_t vk_object,

View File

@ -93,8 +93,8 @@ endif
vkd3d_version = vcs_tag(
command : ['git', 'describe', '--always', '--dirty=+'],
input : 'vkd3d_version.c.in',
output : 'vkd3d_version.c')
input : 'vkd3d_version.h.in',
output : 'vkd3d_version.h')
dxil_spirv = subproject('dxil-spirv')
dxil_spirv_dep = dxil_spirv.get_variable('dxil_spirv_dep')

View File

@ -1 +0,0 @@
const char vkd3d_build[] = "@VCS_TAG@";

4
vkd3d_version.h.in Normal file
View File

@ -0,0 +1,4 @@
#define VKD3D_BUILD_SIZE 8
#define VKD3D_BUILD_MAX_LENGTH (VKD3D_BUILD_SIZE - 1)
static const char vkd3d_build[VKD3D_BUILD_SIZE] = "@VCS_TAG@";