mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
fix(venus): lower the guest's SPIR-V to 1.3 for the phone's shader compiler (#2587)
* fix(venus): lower the guest's SPIR-V to 1.3 for the phone's shader compiler * fix(venus): lower SPIR-V to 1.3 for Mali drivers * fix(venus): keep the SPIR-V cap valid and scoped to active layers Cap inline compute pipeline code too, leave the shader hooks off when the layer is turned off, strip clip and cull distances only where they are emulated, and leave modules alone whose capabilities, decorations or OpSelect results need a newer version or an undeclared extension. * fix(venus): keep application pipeline chains read-only and check non-semantic imports Inline stage code is handed to the driver through a copy of the stage's pNext chain instead of being written into the application's create info, pipeline hooks return VK_ERROR_OUT_OF_HOST_MEMORY when their allocations fail, and a NonSemantic import is only lowered to SPIR-V 1.3 when the module declares SPV_KHR_non_semantic_info. * fix(venus): preserve valid pipeline and shader behavior * fix(venus): lower compatible read-only shader parameters * fix(venus): install SPIR-V 1.3 lowering hooks on Vulkan 1.2+ devices or emulated gaps
This commit is contained in:
1 parent
bc11653c15
commit
6de3c59d7c
7 files changed
+1183
-101
No files matched your search
@@ -615,6 +615,7 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physical_dev
|
||||
inst->GetPhysicalDeviceMemoryProperties(physical_device, &dev->memory_properties);
|
||||
VkPhysicalDeviceProperties properties;
|
||||
inst->GetPhysicalDeviceProperties(physical_device, &properties);
|
||||
dev->active = inst->active && (requested != 0 || properties.apiVersion >= VK_API_VERSION_1_2);
|
||||
uint32_t components = properties.limits.maxVertexOutputComponents;
|
||||
if (properties.limits.maxFragmentInputComponents < components)
|
||||
components = properties.limits.maxFragmentInputComponents;
|
||||
@@ -672,15 +673,18 @@ struct hook {
|
||||
const char *name;
|
||||
PFN_vkVoidFunction function;
|
||||
uint32_t gaps;
|
||||
bool always;
|
||||
};
|
||||
|
||||
#define HOOK(name, gaps) {"vk" #name, (PFN_vkVoidFunction)name, gaps}
|
||||
#define HOOK_ALIAS(name, alias, gaps) {"vk" #alias, (PFN_vkVoidFunction)name, gaps}
|
||||
#define HOOK(name, gaps) {"vk" #name, (PFN_vkVoidFunction)name, gaps, false}
|
||||
#define HOOK_ALIAS(name, alias, gaps) {"vk" #alias, (PFN_vkVoidFunction)name, gaps, false}
|
||||
#define HOOK_ALWAYS(name) {"vk" #name, (PFN_vkVoidFunction)name, 0, true}
|
||||
|
||||
static const struct hook device_hooks[] = {
|
||||
HOOK(CreateShaderModule, GAPS_SHADER | GAP_DUAL_SRC_BLEND),
|
||||
HOOK(DestroyShaderModule, GAPS_SHADER | GAP_DUAL_SRC_BLEND),
|
||||
HOOK(CreateGraphicsPipelines, GAPS_PIPELINE),
|
||||
HOOK_ALWAYS(CreateShaderModule),
|
||||
HOOK_ALWAYS(DestroyShaderModule),
|
||||
HOOK_ALWAYS(CreateGraphicsPipelines),
|
||||
HOOK_ALWAYS(CreateComputePipelines),
|
||||
HOOK(CmdSetViewport, GAP_MULTI_VIEWPORT),
|
||||
HOOK(CmdSetScissor, GAP_MULTI_VIEWPORT),
|
||||
HOOK(CmdSetViewportWithCount, GAP_MULTI_VIEWPORT),
|
||||
@@ -756,7 +760,8 @@ static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice devic
|
||||
if (!next)
|
||||
return NULL;
|
||||
for (size_t i = 0; i < sizeof(device_hooks) / sizeof(device_hooks[0]); i++) {
|
||||
if ((dev->emulated & device_hooks[i].gaps) && !strcmp(name, device_hooks[i].name))
|
||||
bool installed = device_hooks[i].always ? dev->active : (dev->emulated & device_hooks[i].gaps) != 0;
|
||||
if (installed && !strcmp(name, device_hooks[i].name))
|
||||
return device_hooks[i].function;
|
||||
}
|
||||
return next;
|
||||
|
||||
@@ -89,6 +89,7 @@ struct instance {
|
||||
X(CreateShaderModule) \
|
||||
X(DestroyShaderModule) \
|
||||
X(CreateGraphicsPipelines) \
|
||||
X(CreateComputePipelines) \
|
||||
X(CmdSetViewport) \
|
||||
X(CmdSetScissor) \
|
||||
X(CmdSetViewportWithCount) \
|
||||
@@ -145,6 +146,7 @@ struct device {
|
||||
void *key;
|
||||
VkDevice handle;
|
||||
PFN_vkGetDeviceProcAddr gdpa;
|
||||
bool active;
|
||||
/* The gaps the application enabled a made-up feature for. */
|
||||
uint32_t emulated;
|
||||
/* Locations a clip distance varying may use, from the vertex output and fragment input limits. */
|
||||
@@ -185,6 +187,8 @@ struct spirv_code {
|
||||
bool spirv_uses_distances(const uint32_t *words, size_t count);
|
||||
/* The module with clip and cull distances taken out; false when it cannot be rewritten. */
|
||||
bool spirv_strip_distances(const uint32_t *words, size_t count, struct spirv_code *out);
|
||||
uint32_t spirv_version(const uint32_t *words, size_t count);
|
||||
bool spirv_cap_version(const uint32_t *words, size_t count, struct spirv_code *out);
|
||||
bool spirv_uses_dual_source(const uint32_t *words, size_t count);
|
||||
bool spirv_strip_dual_source(const uint32_t *words, size_t count, struct spirv_code *out);
|
||||
|
||||
@@ -213,6 +217,9 @@ VKAPI_ATTR void VKAPI_CALL DestroyShaderModule(VkDevice device, VkShaderModule m
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device, VkPipelineCache cache, uint32_t count,
|
||||
const VkGraphicsPipelineCreateInfo *infos,
|
||||
const VkAllocationCallbacks *allocator, VkPipeline *pipelines);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateComputePipelines(VkDevice device, VkPipelineCache cache, uint32_t count,
|
||||
const VkComputePipelineCreateInfo *infos,
|
||||
const VkAllocationCallbacks *allocator, VkPipeline *pipelines);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetViewport(VkCommandBuffer cmd, uint32_t first, uint32_t count,
|
||||
const VkViewport *viewports);
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetScissor(VkCommandBuffer cmd, uint32_t first, uint32_t count,
|
||||
|
||||
+204
-94
@@ -5,6 +5,13 @@
|
||||
|
||||
#define HANDLE(h) ((uint64_t)(uintptr_t)(h))
|
||||
#define MAX_STAGES 8
|
||||
#define MAX_LINKS 8
|
||||
|
||||
static void log_spirv_version(const char *what, const uint32_t *words, size_t count)
|
||||
{
|
||||
uint32_t version = spirv_version(words, count);
|
||||
layer_log("shader module: SPIR-V %u.%u %s (%zu words)", (version >> 16) & 0xff, (version >> 8) & 0xff, what, count);
|
||||
}
|
||||
|
||||
/* A module with distances goes to the driver without them; its original stays here, for the
|
||||
* pipeline that can emulate its clip distances. */
|
||||
@@ -12,49 +19,57 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateShaderModule(VkDevice device, const VkShade
|
||||
const VkAllocationCallbacks *allocator, VkShaderModule *module)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
VkShaderModuleCreateInfo copy = *info;
|
||||
size_t count = info->codeSize / sizeof(uint32_t);
|
||||
struct spirv_code capped = {0};
|
||||
bool have_capped = spirv_cap_version(info->pCode, count, &capped);
|
||||
if (have_capped)
|
||||
log_spirv_version("lowered to 1.3", info->pCode, count);
|
||||
else if (spirv_version(info->pCode, count) > 0x00010300u)
|
||||
log_spirv_version("left as it is", info->pCode, count);
|
||||
const uint32_t *code = have_capped ? capped.words : info->pCode;
|
||||
size_t words = have_capped ? capped.count : count;
|
||||
|
||||
struct spirv_code single = {0};
|
||||
if ((dev->emulated & GAP_DUAL_SRC_BLEND) && spirv_uses_dual_source(info->pCode, count)) {
|
||||
if (spirv_strip_dual_source(info->pCode, count, &single)) {
|
||||
copy.pCode = single.words;
|
||||
copy.codeSize = single.count * sizeof(uint32_t);
|
||||
count = single.count;
|
||||
if ((dev->emulated & GAP_DUAL_SRC_BLEND) && spirv_uses_dual_source(code, words)) {
|
||||
if (spirv_strip_dual_source(code, words, &single)) {
|
||||
code = single.words;
|
||||
words = single.count;
|
||||
} else {
|
||||
layer_log("could not take the second blend source out of a shader module");
|
||||
}
|
||||
}
|
||||
if (!(dev->emulated & GAPS_SHADER) || !spirv_uses_distances(copy.pCode, count)) {
|
||||
VkResult result = dev->CreateShaderModule(device, ©, allocator, module);
|
||||
free(single.words);
|
||||
return result;
|
||||
}
|
||||
|
||||
struct spirv_code stripped;
|
||||
if (!spirv_strip_distances(copy.pCode, count, &stripped)) {
|
||||
layer_log("could not take the clip and cull distances out of a shader module");
|
||||
VkResult result = dev->CreateShaderModule(device, ©, allocator, module);
|
||||
free(single.words);
|
||||
return result;
|
||||
struct spirv_code stripped = {0};
|
||||
bool have_stripped = false;
|
||||
if ((dev->emulated & GAPS_SHADER) && spirv_uses_distances(code, words)) {
|
||||
have_stripped = spirv_strip_distances(code, words, &stripped);
|
||||
if (!have_stripped)
|
||||
layer_log("could not take the clip and cull distances out of a shader module");
|
||||
}
|
||||
struct spirv_code *original = malloc(sizeof(*original));
|
||||
original->count = count;
|
||||
original->words = malloc(copy.codeSize);
|
||||
memcpy(original->words, copy.pCode, copy.codeSize);
|
||||
free(single.words);
|
||||
copy.pCode = stripped.words;
|
||||
copy.codeSize = stripped.count * sizeof(uint32_t);
|
||||
if (!have_stripped && code == info->pCode)
|
||||
return dev->CreateShaderModule(device, info, allocator, module);
|
||||
|
||||
VkShaderModuleCreateInfo copy = *info;
|
||||
copy.pCode = have_stripped ? stripped.words : code;
|
||||
copy.codeSize = (have_stripped ? stripped.count : words) * sizeof(uint32_t);
|
||||
VkResult result = dev->CreateShaderModule(device, ©, allocator, module);
|
||||
free(stripped.words);
|
||||
if (result != VK_SUCCESS) {
|
||||
free(original->words);
|
||||
free(original);
|
||||
if (result != VK_SUCCESS || !have_stripped) {
|
||||
free(capped.words);
|
||||
free(single.words);
|
||||
free(stripped.words);
|
||||
return result;
|
||||
}
|
||||
|
||||
struct spirv_code *original = malloc(sizeof(*original));
|
||||
original->count = words;
|
||||
original->words = malloc(words * sizeof(uint32_t));
|
||||
memcpy(original->words, code, words * sizeof(uint32_t));
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
map_put(&dev->shader_modules, HANDLE(*module), original);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
free(capped.words);
|
||||
free(single.words);
|
||||
free(stripped.words);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -76,9 +91,10 @@ struct stage_code {
|
||||
const uint32_t *words;
|
||||
size_t count;
|
||||
/* The application's own, when the code comes inline in the stage. */
|
||||
VkShaderModuleCreateInfo *inline_info;
|
||||
const VkShaderModuleCreateInfo *inline_info;
|
||||
/* A module whose distances were already taken out at creation. */
|
||||
bool stripped_module;
|
||||
struct spirv_code capped;
|
||||
};
|
||||
|
||||
static void find_stage_code(struct device *dev, const VkPipelineShaderStageCreateInfo *stage, struct stage_code *code)
|
||||
@@ -86,9 +102,16 @@ static void find_stage_code(struct device *dev, const VkPipelineShaderStageCreat
|
||||
memset(code, 0, sizeof(*code));
|
||||
for (const VkBaseInStructure *s = stage->pNext; s; s = s->pNext) {
|
||||
if (s->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO) {
|
||||
code->inline_info = (VkShaderModuleCreateInfo *)s;
|
||||
code->inline_info = (const VkShaderModuleCreateInfo *)s;
|
||||
code->words = code->inline_info->pCode;
|
||||
code->count = code->inline_info->codeSize / sizeof(uint32_t);
|
||||
if (spirv_cap_version(code->words, code->count, &code->capped)) {
|
||||
log_spirv_version("lowered to 1.3", code->words, code->count);
|
||||
code->words = code->capped.words;
|
||||
code->count = code->capped.count;
|
||||
} else if (spirv_version(code->words, code->count) > 0x00010300u) {
|
||||
log_spirv_version("left as it is", code->words, code->count);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -104,6 +127,15 @@ static void find_stage_code(struct device *dev, const VkPipelineShaderStageCreat
|
||||
}
|
||||
}
|
||||
|
||||
union stage_link {
|
||||
VkBaseInStructure base;
|
||||
VkDebugUtilsObjectNameInfoEXT name;
|
||||
VkPipelineRobustnessCreateInfo robustness;
|
||||
VkPipelineShaderStageModuleIdentifierCreateInfoEXT identifier;
|
||||
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo subgroup;
|
||||
VkShaderModuleValidationCacheCreateInfoEXT validation_cache;
|
||||
};
|
||||
|
||||
struct pipeline_rewrite {
|
||||
VkPipelineRasterizationStateCreateInfo rasterization;
|
||||
VkPipelineColorBlendStateCreateInfo blend;
|
||||
@@ -116,12 +148,71 @@ struct pipeline_rewrite {
|
||||
struct spirv_code code[MAX_STAGES];
|
||||
struct spirv_code single[MAX_STAGES];
|
||||
VkShaderModule temporary[MAX_STAGES];
|
||||
/* Rewritten where they are, when they are not first in their stage's chain. */
|
||||
VkShaderModuleCreateInfo *in_place[MAX_STAGES];
|
||||
const uint32_t *in_place_code[MAX_STAGES];
|
||||
size_t in_place_size[MAX_STAGES];
|
||||
union stage_link links[MAX_STAGES][MAX_LINKS];
|
||||
};
|
||||
|
||||
static size_t link_size(VkStructureType type)
|
||||
{
|
||||
switch (type) {
|
||||
case VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT:
|
||||
return sizeof(VkDebugUtilsObjectNameInfoEXT);
|
||||
case VK_STRUCTURE_TYPE_PIPELINE_ROBUSTNESS_CREATE_INFO:
|
||||
return sizeof(VkPipelineRobustnessCreateInfo);
|
||||
case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_MODULE_IDENTIFIER_CREATE_INFO_EXT:
|
||||
return sizeof(VkPipelineShaderStageModuleIdentifierCreateInfoEXT);
|
||||
case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO:
|
||||
return sizeof(VkPipelineShaderStageRequiredSubgroupSizeCreateInfo);
|
||||
case VK_STRUCTURE_TYPE_SHADER_MODULE_VALIDATION_CACHE_CREATE_INFO_EXT:
|
||||
return sizeof(VkShaderModuleValidationCacheCreateInfoEXT);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static bool link_inline_code(VkPipelineShaderStageCreateInfo *stage, struct pipeline_rewrite *rw,
|
||||
const struct stage_code *code, uint32_t i)
|
||||
{
|
||||
union stage_link *links = rw->links[i];
|
||||
const VkBaseInStructure **next = (const VkBaseInStructure **)&stage->pNext;
|
||||
uint32_t used = 0;
|
||||
for (const VkBaseInStructure *s = stage->pNext; s != (const VkBaseInStructure *)code->inline_info;
|
||||
s = s->pNext) {
|
||||
size_t size = link_size(s->sType);
|
||||
if (!size || used == MAX_LINKS)
|
||||
return false;
|
||||
memcpy(&links[used], s, size);
|
||||
*next = &links[used].base;
|
||||
next = (const VkBaseInStructure **)&links[used].base.pNext;
|
||||
used++;
|
||||
}
|
||||
rw->modules[i] = *code->inline_info;
|
||||
rw->modules[i].pCode = rw->code[i].words;
|
||||
rw->modules[i].codeSize = rw->code[i].count * sizeof(uint32_t);
|
||||
*next = (const VkBaseInStructure *)&rw->modules[i];
|
||||
return true;
|
||||
}
|
||||
|
||||
static void use_stage_code(struct device *dev, VkPipelineShaderStageCreateInfo *stage, struct pipeline_rewrite *rw,
|
||||
const struct stage_code *code, uint32_t i)
|
||||
{
|
||||
const struct spirv_code *out = &rw->code[i];
|
||||
if (code->inline_info) {
|
||||
const void *app_chain = stage->pNext;
|
||||
if (!link_inline_code(stage, rw, code, i)) {
|
||||
stage->pNext = app_chain;
|
||||
layer_log("could not rewrite a pipeline stage's inline shader code");
|
||||
}
|
||||
} else {
|
||||
VkShaderModuleCreateInfo module_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
||||
.codeSize = out->count * sizeof(uint32_t),
|
||||
.pCode = out->words,
|
||||
};
|
||||
if (dev->CreateShaderModule(dev->handle, &module_info, NULL, &rw->temporary[i]) == VK_SUCCESS)
|
||||
stage->module = rw->temporary[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void use_code(struct device *dev, VkGraphicsPipelineCreateInfo *info, struct pipeline_rewrite *rw,
|
||||
const struct stage_code *code, uint32_t i)
|
||||
{
|
||||
@@ -129,27 +220,7 @@ static void use_code(struct device *dev, VkGraphicsPipelineCreateInfo *info, str
|
||||
memcpy(rw->stages, info->pStages, info->stageCount * sizeof(*rw->stages));
|
||||
info->pStages = rw->stages;
|
||||
}
|
||||
const struct spirv_code *out = &rw->code[i];
|
||||
if (code->inline_info && rw->stages[i].pNext == code->inline_info) {
|
||||
rw->modules[i] = *code->inline_info;
|
||||
rw->modules[i].pCode = out->words;
|
||||
rw->modules[i].codeSize = out->count * sizeof(uint32_t);
|
||||
rw->stages[i].pNext = &rw->modules[i];
|
||||
} else if (code->inline_info) {
|
||||
rw->in_place[i] = code->inline_info;
|
||||
rw->in_place_code[i] = code->inline_info->pCode;
|
||||
rw->in_place_size[i] = code->inline_info->codeSize;
|
||||
code->inline_info->pCode = out->words;
|
||||
code->inline_info->codeSize = out->count * sizeof(uint32_t);
|
||||
} else {
|
||||
VkShaderModuleCreateInfo module_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
||||
.codeSize = out->count * sizeof(uint32_t),
|
||||
.pCode = out->words,
|
||||
};
|
||||
if (dev->CreateShaderModule(dev->handle, &module_info, NULL, &rw->temporary[i]) == VK_SUCCESS)
|
||||
rw->stages[i].module = rw->temporary[i];
|
||||
}
|
||||
use_stage_code(dev, &rw->stages[i], rw, code, i);
|
||||
}
|
||||
|
||||
static int stage_index(const VkGraphicsPipelineCreateInfo *info, VkShaderStageFlagBits stage)
|
||||
@@ -174,6 +245,7 @@ static void rewrite_shaders(struct device *dev, VkGraphicsPipelineCreateInfo *in
|
||||
struct stage_code code[MAX_STAGES];
|
||||
bool uses[MAX_STAGES];
|
||||
bool any = false;
|
||||
bool distances = (dev->emulated & GAPS_SHADER) != 0;
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
find_stage_code(dev, &info->pStages[i], &code[i]);
|
||||
if ((dev->emulated & GAP_DUAL_SRC_BLEND) && code[i].inline_info &&
|
||||
@@ -185,40 +257,40 @@ static void rewrite_shaders(struct device *dev, VkGraphicsPipelineCreateInfo *in
|
||||
layer_log("could not take the second blend source out of a pipeline's shader");
|
||||
}
|
||||
}
|
||||
uses[i] = (dev->emulated & GAPS_SHADER) && code[i].words && spirv_uses_distances(code[i].words, code[i].count);
|
||||
any |= uses[i] || rw->single[i].words;
|
||||
uses[i] = distances && code[i].words && spirv_uses_distances(code[i].words, code[i].count);
|
||||
any |= uses[i];
|
||||
}
|
||||
if (!any)
|
||||
return;
|
||||
|
||||
int producer = stage_index(info, VK_SHADER_STAGE_GEOMETRY_BIT);
|
||||
if (producer < 0)
|
||||
producer = stage_index(info, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
|
||||
if (producer < 0)
|
||||
producer = stage_index(info, VK_SHADER_STAGE_VERTEX_BIT);
|
||||
int consumer = stage_index(info, VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
bool emulate = (dev->emulated & GAP_CLIP_DISTANCE) && producer >= 0 && consumer >= 0 && uses[producer] &&
|
||||
code[consumer].words;
|
||||
for (uint32_t i = 0; i < n && emulate; i++) {
|
||||
if ((int)i != producer && (int)i != consumer && uses[i])
|
||||
emulate = false;
|
||||
}
|
||||
if (emulate) {
|
||||
struct clip_info produced, consumed;
|
||||
spirv_clip_info(code[producer].words, code[producer].count, CLIP_PRODUCER, &produced);
|
||||
spirv_clip_info(code[consumer].words, code[consumer].count, CLIP_CONSUMER, &consumed);
|
||||
uint32_t location = produced.locations_used > consumed.locations_used ? produced.locations_used
|
||||
: consumed.locations_used;
|
||||
emulate = produced.has_clip && location != UINT32_MAX &&
|
||||
location + produced.clip_count <= dev->max_varying_locations &&
|
||||
spirv_emulate_clip(code[producer].words, code[producer].count, CLIP_PRODUCER, location,
|
||||
produced.clip_count, &rw->code[producer]) &&
|
||||
spirv_emulate_clip(code[consumer].words, code[consumer].count, CLIP_CONSUMER, location,
|
||||
produced.clip_count, &rw->code[consumer]);
|
||||
if (!emulate) {
|
||||
free(rw->code[producer].words);
|
||||
free(rw->code[consumer].words);
|
||||
rw->code[producer] = rw->code[consumer] = (struct spirv_code){0};
|
||||
if (any) {
|
||||
int producer = stage_index(info, VK_SHADER_STAGE_GEOMETRY_BIT);
|
||||
if (producer < 0)
|
||||
producer = stage_index(info, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
|
||||
if (producer < 0)
|
||||
producer = stage_index(info, VK_SHADER_STAGE_VERTEX_BIT);
|
||||
int consumer = stage_index(info, VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
bool emulate = (dev->emulated & GAP_CLIP_DISTANCE) && producer >= 0 && consumer >= 0 && uses[producer] &&
|
||||
code[consumer].words;
|
||||
for (uint32_t i = 0; i < n && emulate; i++) {
|
||||
if ((int)i != producer && (int)i != consumer && uses[i])
|
||||
emulate = false;
|
||||
}
|
||||
if (emulate) {
|
||||
struct clip_info produced, consumed;
|
||||
spirv_clip_info(code[producer].words, code[producer].count, CLIP_PRODUCER, &produced);
|
||||
spirv_clip_info(code[consumer].words, code[consumer].count, CLIP_CONSUMER, &consumed);
|
||||
uint32_t location = produced.locations_used > consumed.locations_used ? produced.locations_used
|
||||
: consumed.locations_used;
|
||||
emulate = produced.has_clip && location != UINT32_MAX &&
|
||||
location + produced.clip_count <= dev->max_varying_locations &&
|
||||
spirv_emulate_clip(code[producer].words, code[producer].count, CLIP_PRODUCER, location,
|
||||
produced.clip_count, &rw->code[producer]) &&
|
||||
spirv_emulate_clip(code[consumer].words, code[consumer].count, CLIP_CONSUMER, location,
|
||||
produced.clip_count, &rw->code[consumer]);
|
||||
if (!emulate) {
|
||||
free(rw->code[producer].words);
|
||||
free(rw->code[consumer].words);
|
||||
rw->code[producer] = rw->code[consumer] = (struct spirv_code){0};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,8 +303,13 @@ static void rewrite_shaders(struct device *dev, VkGraphicsPipelineCreateInfo *in
|
||||
rw->code[i] = rw->single[i];
|
||||
rw->single[i] = (struct spirv_code){0};
|
||||
}
|
||||
if (!rw->code[i].words && code[i].capped.words) {
|
||||
rw->code[i] = code[i].capped;
|
||||
code[i].capped.words = NULL;
|
||||
}
|
||||
if (rw->code[i].words)
|
||||
use_code(dev, info, rw, &code[i], i);
|
||||
free(code[i].capped.words);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,8 +406,7 @@ static void rewrite_pipeline(struct device *dev, VkGraphicsPipelineCreateInfo *i
|
||||
if (rw->attachments)
|
||||
info->pColorBlendState = &rw->blend;
|
||||
}
|
||||
if (dev->emulated & (GAPS_SHADER | GAP_DUAL_SRC_BLEND))
|
||||
rewrite_shaders(dev, info, rw);
|
||||
rewrite_shaders(dev, info, rw);
|
||||
}
|
||||
|
||||
static void undo_rewrite(struct device *dev, struct pipeline_rewrite *rw)
|
||||
@@ -338,10 +414,6 @@ static void undo_rewrite(struct device *dev, struct pipeline_rewrite *rw)
|
||||
if (rw->clip_prev)
|
||||
rw->clip_prev->pNext = rw->clip_node;
|
||||
for (uint32_t i = 0; i < MAX_STAGES; i++) {
|
||||
if (rw->in_place[i]) {
|
||||
rw->in_place[i]->pCode = rw->in_place_code[i];
|
||||
rw->in_place[i]->codeSize = rw->in_place_size[i];
|
||||
}
|
||||
if (rw->temporary[i] != VK_NULL_HANDLE)
|
||||
dev->DestroyShaderModule(dev->handle, rw->temporary[i], NULL);
|
||||
free(rw->code[i].words);
|
||||
@@ -355,8 +427,15 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device, VkPipeli
|
||||
const VkAllocationCallbacks *allocator, VkPipeline *pipelines)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
VkGraphicsPipelineCreateInfo *copies = malloc(count * sizeof(*copies));
|
||||
VkGraphicsPipelineCreateInfo *copies = calloc(count, sizeof(*copies));
|
||||
struct pipeline_rewrite *rewrites = calloc(count, sizeof(*rewrites));
|
||||
if (count && (!copies || !rewrites)) {
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
pipelines[i] = VK_NULL_HANDLE;
|
||||
free(copies);
|
||||
free(rewrites);
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
copies[i] = infos[i];
|
||||
rewrite_pipeline(dev, &copies[i], &rewrites[i]);
|
||||
@@ -369,6 +448,37 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device, VkPipeli
|
||||
return result;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL CreateComputePipelines(VkDevice device, VkPipelineCache cache, uint32_t count,
|
||||
const VkComputePipelineCreateInfo *infos,
|
||||
const VkAllocationCallbacks *allocator, VkPipeline *pipelines)
|
||||
{
|
||||
struct device *dev = device_from_handle(device);
|
||||
VkComputePipelineCreateInfo *copies = calloc(count, sizeof(*copies));
|
||||
struct pipeline_rewrite *rewrites = calloc(count, sizeof(*rewrites));
|
||||
if (count && (!copies || !rewrites)) {
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
pipelines[i] = VK_NULL_HANDLE;
|
||||
free(copies);
|
||||
free(rewrites);
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
copies[i] = infos[i];
|
||||
struct stage_code code;
|
||||
find_stage_code(dev, &copies[i].stage, &code);
|
||||
if (code.capped.words) {
|
||||
rewrites[i].code[0] = code.capped;
|
||||
use_stage_code(dev, &copies[i].stage, &rewrites[i], &code, 0);
|
||||
}
|
||||
}
|
||||
VkResult result = dev->CreateComputePipelines(device, cache, count, copies, allocator, pipelines);
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
undo_rewrite(dev, &rewrites[i]);
|
||||
free(rewrites);
|
||||
free(copies);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* The driver has one viewport and one scissor; anything past the first is left out. */
|
||||
VKAPI_ATTR void VKAPI_CALL CmdSetViewport(VkCommandBuffer cmd, uint32_t first, uint32_t count,
|
||||
const VkViewport *viewports)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#define OPCODE(word) ((word) & 0xffffu)
|
||||
#define LENGTH(word) ((word) >> 16)
|
||||
#define VERSION_1_3 0x00010300u
|
||||
#define VERSION_1_4 0x00010400u
|
||||
|
||||
struct words {
|
||||
@@ -103,6 +104,7 @@ static bool declares_result_second(uint32_t op)
|
||||
case SpvOpUndef:
|
||||
case SpvOpVariable:
|
||||
case SpvOpFunction:
|
||||
case SpvOpFunctionParameter:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -875,3 +877,300 @@ bool spirv_emulate_clip(const uint32_t *words, size_t count, enum clip_role role
|
||||
unload(&m);
|
||||
return done;
|
||||
}
|
||||
|
||||
struct newer_feature {
|
||||
uint32_t value;
|
||||
const char *extension;
|
||||
const char *alternative;
|
||||
};
|
||||
|
||||
#define PHYSICAL_STORAGE_BUFFER "SPV_EXT_physical_storage_buffer", "SPV_KHR_physical_storage_buffer"
|
||||
|
||||
static const struct newer_feature newer_opcodes[] = {
|
||||
{SpvOpCopyLogical, NULL, NULL},
|
||||
{SpvOpPtrEqual, NULL, NULL},
|
||||
{SpvOpPtrNotEqual, NULL, NULL},
|
||||
{SpvOpPtrDiff, NULL, NULL},
|
||||
{SpvOpDemoteToHelperInvocation, "SPV_EXT_demote_to_helper_invocation", NULL},
|
||||
{SpvOpSDot, "SPV_KHR_integer_dot_product", NULL},
|
||||
{SpvOpUDot, "SPV_KHR_integer_dot_product", NULL},
|
||||
{SpvOpSUDot, "SPV_KHR_integer_dot_product", NULL},
|
||||
{SpvOpSDotAccSat, "SPV_KHR_integer_dot_product", NULL},
|
||||
{SpvOpUDotAccSat, "SPV_KHR_integer_dot_product", NULL},
|
||||
{SpvOpSUDotAccSat, "SPV_KHR_integer_dot_product", NULL},
|
||||
{SpvOpDecorateString, "SPV_GOOGLE_decorate_string", "SPV_GOOGLE_hlsl_functionality1"},
|
||||
{SpvOpMemberDecorateString, "SPV_GOOGLE_decorate_string", "SPV_GOOGLE_hlsl_functionality1"},
|
||||
};
|
||||
|
||||
static const struct newer_feature newer_capabilities[] = {
|
||||
{SpvCapabilityShaderLayer, NULL, NULL},
|
||||
{SpvCapabilityShaderViewportIndex, NULL, NULL},
|
||||
{SpvCapabilityUniformDecoration, NULL, NULL},
|
||||
{SpvCapabilityStorageBuffer8BitAccess, "SPV_KHR_8bit_storage", NULL},
|
||||
{SpvCapabilityUniformAndStorageBuffer8BitAccess, "SPV_KHR_8bit_storage", NULL},
|
||||
{SpvCapabilityStoragePushConstant8, "SPV_KHR_8bit_storage", NULL},
|
||||
{SpvCapabilityDenormPreserve, "SPV_KHR_float_controls", NULL},
|
||||
{SpvCapabilityDenormFlushToZero, "SPV_KHR_float_controls", NULL},
|
||||
{SpvCapabilitySignedZeroInfNanPreserve, "SPV_KHR_float_controls", NULL},
|
||||
{SpvCapabilityRoundingModeRTE, "SPV_KHR_float_controls", NULL},
|
||||
{SpvCapabilityRoundingModeRTZ, "SPV_KHR_float_controls", NULL},
|
||||
{SpvCapabilityShaderNonUniform, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityRuntimeDescriptorArray, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityInputAttachmentArrayDynamicIndexing, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityUniformTexelBufferArrayDynamicIndexing, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityStorageTexelBufferArrayDynamicIndexing, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityUniformBufferArrayNonUniformIndexing, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilitySampledImageArrayNonUniformIndexing, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityStorageBufferArrayNonUniformIndexing, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityStorageImageArrayNonUniformIndexing, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityInputAttachmentArrayNonUniformIndexing, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityUniformTexelBufferArrayNonUniformIndexing, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityStorageTexelBufferArrayNonUniformIndexing, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvCapabilityVulkanMemoryModel, "SPV_KHR_vulkan_memory_model", NULL},
|
||||
{SpvCapabilityVulkanMemoryModelDeviceScope, "SPV_KHR_vulkan_memory_model", NULL},
|
||||
{SpvCapabilityPhysicalStorageBufferAddresses, PHYSICAL_STORAGE_BUFFER},
|
||||
{SpvCapabilityDemoteToHelperInvocation, "SPV_EXT_demote_to_helper_invocation", NULL},
|
||||
{SpvCapabilityDotProductInputAll, "SPV_KHR_integer_dot_product", NULL},
|
||||
{SpvCapabilityDotProductInput4x8Bit, "SPV_KHR_integer_dot_product", NULL},
|
||||
{SpvCapabilityDotProductInput4x8BitPacked, "SPV_KHR_integer_dot_product", NULL},
|
||||
{SpvCapabilityDotProduct, "SPV_KHR_integer_dot_product", NULL},
|
||||
};
|
||||
|
||||
static const struct newer_feature newer_decorations[] = {
|
||||
{SpvDecorationUniformId, NULL, NULL},
|
||||
{SpvDecorationNoSignedWrap, "SPV_KHR_no_integer_wrap_decoration", NULL},
|
||||
{SpvDecorationNoUnsignedWrap, "SPV_KHR_no_integer_wrap_decoration", NULL},
|
||||
{SpvDecorationNonUniform, "SPV_EXT_descriptor_indexing", NULL},
|
||||
{SpvDecorationRestrictPointer, PHYSICAL_STORAGE_BUFFER},
|
||||
{SpvDecorationAliasedPointer, PHYSICAL_STORAGE_BUFFER},
|
||||
{SpvDecorationCounterBuffer, "SPV_GOOGLE_hlsl_functionality1", NULL},
|
||||
{SpvDecorationUserSemantic, "SPV_GOOGLE_hlsl_functionality1", NULL},
|
||||
};
|
||||
|
||||
#define NEWER_LOOP_CONTROLS \
|
||||
(SpvLoopControlMinIterationsMask | SpvLoopControlMaxIterationsMask | SpvLoopControlIterationMultipleMask | \
|
||||
SpvLoopControlPeelCountMask | SpvLoopControlPartialCountMask)
|
||||
#define NEWER_IMAGE_OPERANDS \
|
||||
(SpvImageOperandsSignExtendMask | SpvImageOperandsZeroExtendMask | SpvImageOperandsNontemporalMask)
|
||||
|
||||
static bool declares_extension(const struct module *m, const char *name)
|
||||
{
|
||||
if (!name)
|
||||
return false;
|
||||
size_t size = strlen(name) + 1;
|
||||
for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) {
|
||||
uint32_t length = LENGTH(m->w[i]);
|
||||
if (OPCODE(m->w[i]) == SpvOpExtension && (length - 1) * sizeof(uint32_t) >= size &&
|
||||
!memcmp(&m->w[i + 1], name, size))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool names_prefix(const uint32_t *words, uint32_t count, const char *prefix)
|
||||
{
|
||||
size_t size = strlen(prefix);
|
||||
return count * sizeof(uint32_t) > size && !memcmp(words, prefix, size);
|
||||
}
|
||||
|
||||
static bool available_in_1_3(const struct module *m, const struct newer_feature *features, size_t count,
|
||||
uint32_t value)
|
||||
{
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (features[i].value == value)
|
||||
return declares_extension(m, features[i].extension) || declares_extension(m, features[i].alternative);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#define AVAILABLE(m, table, value) available_in_1_3(m, table, sizeof(table) / sizeof(table[0]), value)
|
||||
|
||||
static bool declares_capability(const struct module *m, uint32_t capability)
|
||||
{
|
||||
for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) {
|
||||
if (OPCODE(m->w[i]) == SpvOpCapability && LENGTH(m->w[i]) >= 2 && m->w[i + 1] == capability)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint32_t image_operands_at(uint32_t op)
|
||||
{
|
||||
switch (op) {
|
||||
case SpvOpImageWrite:
|
||||
return 4;
|
||||
case SpvOpImageSampleImplicitLod:
|
||||
case SpvOpImageSampleExplicitLod:
|
||||
case SpvOpImageSampleProjImplicitLod:
|
||||
case SpvOpImageSampleProjExplicitLod:
|
||||
case SpvOpImageFetch:
|
||||
case SpvOpImageRead:
|
||||
case SpvOpImageSparseSampleImplicitLod:
|
||||
case SpvOpImageSparseSampleExplicitLod:
|
||||
case SpvOpImageSparseSampleProjImplicitLod:
|
||||
case SpvOpImageSparseSampleProjExplicitLod:
|
||||
case SpvOpImageSparseFetch:
|
||||
case SpvOpImageSparseRead:
|
||||
return 5;
|
||||
case SpvOpImageSampleDrefImplicitLod:
|
||||
case SpvOpImageSampleDrefExplicitLod:
|
||||
case SpvOpImageSampleProjDrefImplicitLod:
|
||||
case SpvOpImageSampleProjDrefExplicitLod:
|
||||
case SpvOpImageGather:
|
||||
case SpvOpImageDrefGather:
|
||||
case SpvOpImageSparseSampleDrefImplicitLod:
|
||||
case SpvOpImageSparseSampleDrefExplicitLod:
|
||||
case SpvOpImageSparseSampleProjDrefImplicitLod:
|
||||
case SpvOpImageSparseSampleProjDrefExplicitLod:
|
||||
case SpvOpImageSparseGather:
|
||||
case SpvOpImageSparseDrefGather:
|
||||
return 6;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t memory_access_words(uint32_t mask)
|
||||
{
|
||||
uint32_t words = 1;
|
||||
if (mask & SpvMemoryAccessAlignedMask)
|
||||
words++;
|
||||
if (mask & SpvMemoryAccessMakePointerAvailableMask)
|
||||
words++;
|
||||
if (mask & SpvMemoryAccessMakePointerVisibleMask)
|
||||
words++;
|
||||
return words;
|
||||
}
|
||||
|
||||
static bool selects_scalar_vector_or_pointer(const struct module *m, uint32_t type)
|
||||
{
|
||||
size_t d = definition(m, type);
|
||||
if (!d)
|
||||
return false;
|
||||
switch (OPCODE(m->w[d])) {
|
||||
case SpvOpTypeBool:
|
||||
case SpvOpTypeInt:
|
||||
case SpvOpTypeFloat:
|
||||
case SpvOpTypeVector:
|
||||
case SpvOpTypePointer:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool valid_in_1_3(const struct module *m, size_t i)
|
||||
{
|
||||
uint32_t op = OPCODE(m->w[i]);
|
||||
uint32_t length = LENGTH(m->w[i]);
|
||||
if (!AVAILABLE(m, newer_opcodes, op))
|
||||
return false;
|
||||
switch (op) {
|
||||
case SpvOpMemoryModel:
|
||||
return length >= 3 && m->w[i + 2] == SpvMemoryModelGLSL450;
|
||||
case SpvOpCapability:
|
||||
return length >= 2 && AVAILABLE(m, newer_capabilities, m->w[i + 1]);
|
||||
case SpvOpExecutionModeId:
|
||||
return length >= 3 && m->w[i + 2] != SpvExecutionModeLocalSizeId;
|
||||
case SpvOpDecorate:
|
||||
case SpvOpDecorateId:
|
||||
case SpvOpDecorateString:
|
||||
if (length < 3 || !AVAILABLE(m, newer_decorations, m->w[i + 2]))
|
||||
return false;
|
||||
if (m->w[i + 2] == SpvDecorationNonWritable) {
|
||||
size_t d = definition(m, m->w[i + 1]);
|
||||
if (!d || (OPCODE(m->w[d]) == SpvOpVariable &&
|
||||
(LENGTH(m->w[d]) < 4 || m->w[d + 3] == SpvStorageClassPrivate ||
|
||||
m->w[d + 3] == SpvStorageClassFunction)))
|
||||
return false;
|
||||
if (OPCODE(m->w[d]) == SpvOpFunctionParameter) {
|
||||
size_t type = LENGTH(m->w[d]) >= 3 ? definition(m, m->w[d + 1]) : 0;
|
||||
if (!type || OPCODE(m->w[type]) != SpvOpTypePointer || LENGTH(m->w[type]) < 4 ||
|
||||
m->w[type + 2] == SpvStorageClassPrivate || m->w[type + 2] == SpvStorageClassFunction)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
case SpvOpMemberDecorate:
|
||||
case SpvOpMemberDecorateString:
|
||||
return length >= 4 && AVAILABLE(m, newer_decorations, m->w[i + 3]);
|
||||
case SpvOpLoopMerge:
|
||||
return length >= 4 && !(m->w[i + 3] & NEWER_LOOP_CONTROLS);
|
||||
case SpvOpSelect:
|
||||
return length >= 6 && selects_scalar_vector_or_pointer(m, m->w[i + 1]);
|
||||
case SpvOpSpecConstantOp:
|
||||
return length >= 5 && (m->w[i + 3] != SpvOpUConvert ||
|
||||
declares_capability(m, SpvCapabilityKernel) ||
|
||||
declares_extension(m, "SPV_AMD_gpu_shader_int16"));
|
||||
case SpvOpExtInstImport:
|
||||
return length >= 3 && (!names_prefix(&m->w[i + 2], length - 2, "NonSemantic.") ||
|
||||
declares_extension(m, "SPV_KHR_non_semantic_info"));
|
||||
case SpvOpCopyMemory:
|
||||
case SpvOpCopyMemorySized: {
|
||||
uint32_t at = op == SpvOpCopyMemory ? 3 : 4;
|
||||
return length <= at || at + memory_access_words(m->w[i + at]) >= length;
|
||||
}
|
||||
default: {
|
||||
uint32_t at = image_operands_at(op);
|
||||
return !at || length <= at || !(m->w[i + at] & NEWER_IMAGE_OPERANDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool variable_storage(const struct module *m, uint32_t id, uint32_t *storage)
|
||||
{
|
||||
size_t d = definition(m, id);
|
||||
if (!d || OPCODE(m->w[d]) != SpvOpVariable)
|
||||
return false;
|
||||
*storage = m->w[d + 3];
|
||||
return true;
|
||||
}
|
||||
|
||||
static void trim_entry_interfaces(struct module *m)
|
||||
{
|
||||
for (size_t i = 5; i < m->first_declaration; i += LENGTH(m->w[i])) {
|
||||
if (OPCODE(m->w[i]) != SpvOpEntryPoint)
|
||||
continue;
|
||||
uint32_t length = LENGTH(m->w[i]);
|
||||
if (length < 4)
|
||||
continue;
|
||||
uint32_t first = 3 + string_words(&m->w[i + 3], length - 3);
|
||||
for (uint32_t k = first; k < length; k++) {
|
||||
uint32_t id = m->w[i + k];
|
||||
uint32_t storage;
|
||||
if (id < m->original_bound && variable_storage(m, id, &storage) &&
|
||||
storage != SpvStorageClassInput && storage != SpvStorageClassOutput)
|
||||
m->interface_remove[id] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
uint32_t spirv_version(const uint32_t *words, size_t count)
|
||||
{
|
||||
if (count < 5 || words[0] != SpvMagicNumber)
|
||||
return 0;
|
||||
return words[1];
|
||||
}
|
||||
|
||||
bool spirv_cap_version(const uint32_t *words, size_t count, struct spirv_code *out)
|
||||
{
|
||||
if (count < 5 || words[0] != SpvMagicNumber || words[1] <= VERSION_1_3)
|
||||
return false;
|
||||
struct module m;
|
||||
if (!load(&m, words, count))
|
||||
return false;
|
||||
for (size_t i = 5; i < m.count; i += LENGTH(m.w[i])) {
|
||||
if (!valid_in_1_3(&m, i)) {
|
||||
unload(&m);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (size_t i = 5; i < m.count; i += LENGTH(m.w[i])) {
|
||||
if (OPCODE(m.w[i]) == SpvOpTerminateInvocation)
|
||||
m.w[i] = (LENGTH(m.w[i]) << 16) | SpvOpKill;
|
||||
}
|
||||
trim_entry_interfaces(&m);
|
||||
m.w[1] = VERSION_1_3;
|
||||
bool done = finish(&m, out);
|
||||
unload(&m);
|
||||
return done;
|
||||
}
|
||||
Reference in new issue
Block a user