2018-10-15 23:37:09 +02:00
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#include "kernel/vc4_packet.h"
|
|
|
|
|
2019-05-06 17:58:34 +02:00
|
|
|
#include "QPUassembler/qpu_assembler.h"
|
|
|
|
|
2019-08-25 22:59:18 +02:00
|
|
|
//TODO collect shader performance data
|
|
|
|
//eg number of texture samples etc.
|
|
|
|
//TODO check if shader has flow control and make sure instance also has flow control
|
|
|
|
//TODO make sure instance has threaded fs if shader contains thread switch
|
|
|
|
|
2019-05-06 17:58:34 +02:00
|
|
|
VkResult vkCreateShaderModuleFromRpiAssemblyEXT(VkDevice device, VkRpiShaderModuleAssemblyCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
assert(pCreateInfo);
|
|
|
|
assert(pShaderModule);
|
2019-05-06 17:58:34 +02:00
|
|
|
assert(pCreateInfo->asmStrings);
|
2018-10-15 23:37:09 +02:00
|
|
|
|
2018-11-17 16:53:13 +01:00
|
|
|
_shaderModule* shader = ALLOCATE(sizeof(_shaderModule), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
2018-10-15 23:37:09 +02:00
|
|
|
|
|
|
|
if(!shader)
|
|
|
|
{
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
}
|
|
|
|
|
2019-08-25 22:59:18 +02:00
|
|
|
shader->hasThreadSwitch = 0;
|
|
|
|
|
2019-08-18 18:36:57 +02:00
|
|
|
for(int c = 0; c < RPI_ASSEMBLY_TYPE_MAX; ++c)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2019-05-06 17:58:34 +02:00
|
|
|
if(pCreateInfo->asmStrings[c])
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2019-05-06 17:58:34 +02:00
|
|
|
uint32_t numInstructions = get_num_instructions(pCreateInfo->asmStrings[c]);
|
|
|
|
uint32_t size = sizeof(uint64_t)*numInstructions;
|
|
|
|
//TODO this alloc feels kinda useless, we just copy the data anyway to kernel space
|
|
|
|
//why not map kernel space mem to user space instead?
|
|
|
|
uint64_t* instructions = ALLOCATE(size, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
|
|
|
if(!instructions)
|
|
|
|
{
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
}
|
2019-08-29 22:31:49 +02:00
|
|
|
|
|
|
|
//need to create a temporary copy as the assembly algorithm is destructive
|
|
|
|
uint32_t stringLength = strlen(pCreateInfo->asmStrings[c]);
|
|
|
|
char* tmpShaderStr = ALLOCATE(stringLength+1, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
|
|
|
memcpy(tmpShaderStr, pCreateInfo->asmStrings[c], stringLength+1);
|
|
|
|
|
|
|
|
assemble_qpu_asm(tmpShaderStr, instructions);
|
|
|
|
|
|
|
|
FREE(tmpShaderStr);
|
|
|
|
|
2019-05-06 17:58:34 +02:00
|
|
|
shader->bos[c] = vc4_bo_alloc_shader(controlFd, instructions, &size);
|
|
|
|
|
|
|
|
//TODO if debug...
|
2019-09-20 12:04:58 +02:00
|
|
|
for(uint64_t d = 0; d < numInstructions; ++d)
|
2019-05-06 17:58:34 +02:00
|
|
|
{
|
2019-09-20 12:04:58 +02:00
|
|
|
printf("%#llx ", instructions[d]);
|
|
|
|
disassemble_qpu_asm(instructions[d]);
|
2019-05-06 17:58:34 +02:00
|
|
|
}
|
|
|
|
|
2019-09-20 12:04:58 +02:00
|
|
|
for(uint64_t d = 0; d < numInstructions; ++d)
|
2019-08-25 22:59:18 +02:00
|
|
|
{
|
2019-09-20 12:04:58 +02:00
|
|
|
uint64_t s = (instructions[d] & (0xfll << 60)) >> 60;
|
|
|
|
if(s == 2ll)
|
2019-08-25 22:59:18 +02:00
|
|
|
{
|
|
|
|
shader->hasThreadSwitch = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-21 00:05:19 +02:00
|
|
|
shader->numVaryings = 0;
|
|
|
|
for(uint64_t d = 0; d < numInstructions; ++d)
|
|
|
|
{
|
|
|
|
unsigned is_sem = ((instructions[d] & (0x7fll << 57)) >> 57) == 0x74;
|
|
|
|
unsigned sig_bits = ((instructions[d] & (0xfll << 60)) >> 60);
|
|
|
|
|
|
|
|
//if it's an ALU instruction
|
|
|
|
if(!is_sem && sig_bits != 14 && sig_bits != 15)
|
|
|
|
{
|
|
|
|
unsigned raddr_a = ((instructions[d] & (0x3fll << 18)) >> 18);
|
|
|
|
unsigned raddr_b = ((instructions[d] & (0x3fll << 12)) >> 12);
|
|
|
|
|
|
|
|
if(raddr_a == 35)
|
|
|
|
{
|
|
|
|
shader->numVaryings++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//don't count small immediates
|
|
|
|
if(sig_bits != 13 && raddr_b == 35)
|
|
|
|
{
|
|
|
|
shader->numVaryings++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-06 17:58:34 +02:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
FREE(instructions);
|
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
shader->sizes[c] = size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shader->bos[c] = 0;
|
2019-05-06 17:58:34 +02:00
|
|
|
shader->sizes[c] = 0;
|
2018-10-15 23:37:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 18:36:57 +02:00
|
|
|
shader->numMappings = pCreateInfo->numMappings;
|
|
|
|
|
|
|
|
if(pCreateInfo->numMappings > 0)
|
|
|
|
{
|
|
|
|
shader->mappings = ALLOCATE(sizeof(VkRpiAssemblyMappingEXT)*pCreateInfo->numMappings, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
|
|
|
|
|
|
|
if(!shader->mappings)
|
|
|
|
{
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(shader->mappings, pCreateInfo->mappings, sizeof(VkRpiAssemblyMappingEXT)*pCreateInfo->numMappings);
|
|
|
|
}
|
|
|
|
|
2018-10-15 23:37:09 +02:00
|
|
|
*pShaderModule = shader;
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateShaderModule
|
|
|
|
*/
|
|
|
|
VkResult vkCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule)
|
|
|
|
{
|
2019-09-08 00:30:52 +02:00
|
|
|
UNSUPPORTED(vkCreateShaderModule);
|
2018-10-15 23:37:09 +02:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
|
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
|
|
|
|
_shaderModule* shader = shaderModule;
|
|
|
|
|
2019-02-09 17:18:15 +01:00
|
|
|
if(shader)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2019-08-18 18:36:57 +02:00
|
|
|
for(int c = 0; c < RPI_ASSEMBLY_TYPE_MAX; ++c)
|
2018-10-15 23:37:09 +02:00
|
|
|
{
|
2019-02-09 17:18:15 +01:00
|
|
|
if(shader->bos[c])
|
|
|
|
{
|
|
|
|
vc4_bo_free(controlFd, shader->bos[c], 0, shader->sizes[c]);
|
|
|
|
}
|
2018-10-15 23:37:09 +02:00
|
|
|
}
|
2019-08-18 18:36:57 +02:00
|
|
|
|
|
|
|
if(shader->numMappings>0)
|
|
|
|
{
|
|
|
|
FREE(shader->mappings);
|
|
|
|
}
|
|
|
|
|
2019-02-10 00:53:32 +01:00
|
|
|
FREE(shader);
|
2018-10-15 23:37:09 +02:00
|
|
|
}
|
|
|
|
}
|