diff --git a/QPUassembler/qpu_assembler.c b/QPUassembler/qpu_assembler.c index 9d272ad..3822a3f 100644 --- a/QPUassembler/qpu_assembler.c +++ b/QPUassembler/qpu_assembler.c @@ -713,7 +713,7 @@ void parse_op(char** str, qpu_alu_type* type, qpu_op_add* op_add, qpu_op_mul* op *str += 1; } -void parse_args_alu(char** str, qpu_mux* in_a, qpu_mux* in_b, uint8_t* raddr_a, uint8_t* raddr_b, uint8_t is_si) +void parse_args_alu(char** str, qpu_mux* in_a, qpu_mux* in_b, qpu_raddr* raddr_a, qpu_raddr* raddr_b, uint8_t is_si) { char* arg = strtok(*str, " \n\v\f\r\t,"); @@ -835,7 +835,7 @@ void parse_args_sem(char** str, uint8_t* sem, uint32_t* imm32) *str += 1; } -void parse_args_branch(char** str, uint32_t* imm32, qpu_branch_cond* branch_cond, uint8_t* raddr_a) +void parse_args_branch(char** str, uint32_t* imm32, qpu_branch_cond* branch_cond, qpu_raddr* raddr_a) { char* arg = strtok(*str, " \n\v\f\r\t,"); @@ -973,8 +973,8 @@ void assemble_qpu_asm(char* str, uint64_t* instructions) qpu_cond cond_add = QPU_COND_NEVER; qpu_waddr waddr_add = QPU_W_NOP; qpu_waddr waddr_mul = QPU_W_NOP; - qpu_waddr raddr_a = QPU_R_NOP; - qpu_waddr raddr_b = QPU_R_NOP; + qpu_raddr raddr_a = QPU_R_NOP; + qpu_raddr raddr_b = QPU_R_NOP; uint8_t pack_unpack_select = 0; uint8_t pack_mode = QPU_PACK_A_NOP; qpu_unpack unpack_mode = QPU_UNPACK_NOP; diff --git a/driver/ConsecutivePoolAllocator.c b/driver/ConsecutivePoolAllocator.c index 71ebaf5..062cc45 100644 --- a/driver/ConsecutivePoolAllocator.c +++ b/driver/ConsecutivePoolAllocator.c @@ -5,7 +5,7 @@ #include #include -ConsecutivePoolAllocator createConsecutivePoolAllocator(char* b, unsigned bs, unsigned s) +ConsecutivePoolAllocator createConsecutivePoolAllocator(void* b, unsigned bs, unsigned s) { assert(b); //only allocated memory assert(bs >= sizeof(void*)); //we need to be able to store @@ -15,7 +15,7 @@ ConsecutivePoolAllocator createConsecutivePoolAllocator(char* b, unsigned bs, un ConsecutivePoolAllocator pa = { .buf = b, - .nextFreeBlock = (uint32_t*)b, + .nextFreeBlock = b, .blockSize = bs, .size = s, .numFreeBlocks = s / bs @@ -120,7 +120,7 @@ uint32_t consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlock pa->numFreeBlocks -= numBlocks; - return (char*)ptr - pa->buf; + return (char*)ptr - (char*)pa->buf; } //free numBlocks consecutive memory @@ -228,7 +228,7 @@ uint32_t consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMe pa->numFreeBlocks -= 1; - return (char*)currentMem - pa->buf; + return (char*)currentMem - (char*)pa->buf; } prevPtr = listPtr; diff --git a/driver/ConsecutivePoolAllocator.h b/driver/ConsecutivePoolAllocator.h index 0386b52..b0b3a59 100644 --- a/driver/ConsecutivePoolAllocator.h +++ b/driver/ConsecutivePoolAllocator.h @@ -10,14 +10,14 @@ extern "C" { typedef struct ConsecutivePoolAllocator { - char* buf; //preallocated buffer - uint32_t* nextFreeBlock; + void* buf; //preallocated buffer + void* nextFreeBlock; unsigned blockSize; unsigned size; //size is exact multiple of block size unsigned numFreeBlocks; } ConsecutivePoolAllocator; -ConsecutivePoolAllocator createConsecutivePoolAllocator(char* b, unsigned bs, unsigned s); +ConsecutivePoolAllocator createConsecutivePoolAllocator(void* b, unsigned bs, unsigned s); void destroyConsecutivePoolAllocator(ConsecutivePoolAllocator* pa); uint32_t consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlocks); void consecutivePoolFree(ConsecutivePoolAllocator* pa, void* p, uint32_t numBlocks); diff --git a/driver/ControlListUtil.c b/driver/ControlListUtil.c index 3c8cdd9..bdd6580 100644 --- a/driver/ControlListUtil.c +++ b/driver/ControlListUtil.c @@ -54,7 +54,7 @@ void clInsertNewCLMarker(ControlList* cl, assert(shaderRecCL); assert(uniformsCL); - CLMarker marker = {}; + CLMarker marker = {0}; marker.memGuard = 0xDDDDDDDD; marker.handlesBufOffset = 0; marker.shaderRecBufOffset = 0; @@ -63,13 +63,13 @@ void clInsertNewCLMarker(ControlList* cl, marker.numDrawCallsSubmitted = 0; //close current marker - if(cl->currMarkerOffset != -1 && !((CLMarker*)getCPAptrFromOffset(cl->CPA, cl->currMarkerOffset))->size) + if(cl->currMarkerOffset != ~0u && !((CLMarker*)getCPAptrFromOffset(cl->CPA, cl->currMarkerOffset))->size) { clCloseCurrentMarker(cl, handlesCL, shaderRecCL, shaderRecCount, uniformsCL); } //if this is not the first marker - if(cl->currMarkerOffset != -1) + if(cl->currMarkerOffset != ~0u) { CLMarker* currMarker = getCPAptrFromOffset(cl->CPA, cl->currMarkerOffset); marker.handlesBufOffset = currMarker->handlesBufOffset + currMarker->handlesSize; @@ -79,7 +79,7 @@ void clInsertNewCLMarker(ControlList* cl, } *(CLMarker*)getCPAptrFromOffset(cl->CPA, cl->nextFreeByteOffset) = marker; - if(cl->currMarkerOffset != -1) + if(cl->currMarkerOffset != ~0u) { ((CLMarker*)getCPAptrFromOffset(cl->CPA, cl->currMarkerOffset))->nextMarkerOffset = (cl->nextFreeByteOffset - cl->offset); } @@ -102,7 +102,7 @@ void clCloseCurrentMarker(ControlList* cl, ControlList* handlesCL, ControlList* currMarker->shaderRecCount = shaderRecCount - currMarker->shaderRecCount; //update shader rec count to reflect added shader recs } -void clInsertData(ControlList* cl, uint32_t size, uint8_t* data) +void clInsertData(ControlList* cl, uint32_t size, void* data) { assert(cl); assert(cl->CPA); diff --git a/driver/ControlListUtil.h b/driver/ControlListUtil.h index 1fe2d77..5a62bd7 100644 --- a/driver/ControlListUtil.h +++ b/driver/ControlListUtil.h @@ -93,7 +93,7 @@ void clInsertNewCLMarker(ControlList* cl, uint32_t shaderRecCount, ControlList* uniformsCL); void clCloseCurrentMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, uint32_t shaderRecCount, ControlList* uniformsCL); -void clInsertData(ControlList* cl, uint32_t size, uint8_t* data); +void clInsertData(ControlList* cl, uint32_t size, void* data); void clInsertUniformConstant(ControlList* cl, uint32_t data); void clInsertUniformXYScale(ControlList* cl, float data); void clInsertUniformZOffset(ControlList* cl, float data); diff --git a/driver/PoolAllocator.c b/driver/PoolAllocator.c index a8ca6e4..25ddfd3 100644 --- a/driver/PoolAllocator.c +++ b/driver/PoolAllocator.c @@ -4,7 +4,7 @@ #include -PoolAllocator createPoolAllocator(char* b, unsigned bs, unsigned s) +PoolAllocator createPoolAllocator(void* b, unsigned bs, unsigned s) { assert(b); //only allocated memory assert(bs >= sizeof(void*)); //we need to be able to store @@ -14,7 +14,7 @@ PoolAllocator createPoolAllocator(char* b, unsigned bs, unsigned s) PoolAllocator pa = { .buf = b, - .nextFreeBlock = (uint32_t*)b, + .nextFreeBlock = b, .blockSize = bs, .size = s }; @@ -55,7 +55,7 @@ void* poolAllocate(PoolAllocator* pa) void* ret = pa->nextFreeBlock; //set next free block to the one the current next points to - pa->nextFreeBlock = (uint32_t*)*pa->nextFreeBlock; + pa->nextFreeBlock = *(uint32_t*)pa->nextFreeBlock; return ret; } diff --git a/driver/PoolAllocator.h b/driver/PoolAllocator.h index e8f9787..2ac40d1 100644 --- a/driver/PoolAllocator.h +++ b/driver/PoolAllocator.h @@ -10,13 +10,13 @@ extern "C" { typedef struct PoolAllocator { - char* buf; //preallocated buffer - uint32_t* nextFreeBlock; + void* buf; //preallocated buffer + void* nextFreeBlock; unsigned blockSize; unsigned size; //size is exact multiple of block size } PoolAllocator; -PoolAllocator createPoolAllocator(char* b, unsigned bs, unsigned s); +PoolAllocator createPoolAllocator(void* b, unsigned bs, unsigned s); void destroyPoolAllocator(PoolAllocator* pa); void* poolAllocate(PoolAllocator* pa); void poolFree(PoolAllocator* pa, void* p); diff --git a/driver/command.c b/driver/command.c index fbb746d..b2d1e8c 100644 --- a/driver/command.c +++ b/driver/command.c @@ -54,8 +54,6 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateCommandPool)( int consecutiveBlockNumber = 512; int consecutivePoolSize = consecutiveBlockNumber * consecutiveBlockSize; - static int counter = 0; - //if(pCreateInfo->flags & VK_COMMAND_POOL_CREATE_TRANSIENT_BIT) { //use pool allocator @@ -106,7 +104,7 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkAllocateCommandBuffers)( //if(cp->usePoolAllocator) { - for(int c = 0; c < pAllocateInfo->commandBufferCount; ++c) + for(uint32_t c = 0; c < pAllocateInfo->commandBufferCount; ++c) { pCommandBuffers[c] = poolAllocate(&cp->pa); @@ -153,25 +151,25 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkAllocateCommandBuffers)( pCommandBuffers[c]->perfmonID = 0; - if(pCommandBuffers[c]->binCl.offset == -1) + if(pCommandBuffers[c]->binCl.offset == ~0u) { res = VK_ERROR_OUT_OF_HOST_MEMORY; break; } - if(pCommandBuffers[c]->handlesCl.offset == -1) + if(pCommandBuffers[c]->handlesCl.offset == ~0u) { res = VK_ERROR_OUT_OF_HOST_MEMORY; break; } - if(pCommandBuffers[c]->shaderRecCl.offset == -1) + if(pCommandBuffers[c]->shaderRecCl.offset == ~0u) { res = VK_ERROR_OUT_OF_HOST_MEMORY; break; } - if(pCommandBuffers[c]->uniformsCl.offset == -1) + if(pCommandBuffers[c]->uniformsCl.offset == ~0u) { res = VK_ERROR_OUT_OF_HOST_MEMORY; break; @@ -183,7 +181,7 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkAllocateCommandBuffers)( { //if(cp->usePoolAllocator) { - for(int c = 0; c < pAllocateInfo->commandBufferCount; ++c) + for(uint32_t c = 0; c < pAllocateInfo->commandBufferCount; ++c) { consecutivePoolFree(&cp->cpa, getCPAptrFromOffset(&cp->cpa, pCommandBuffers[c]->binCl.offset), pCommandBuffers[c]->binCl.numBlocks); consecutivePoolFree(&cp->cpa, getCPAptrFromOffset(&cp->cpa, pCommandBuffers[c]->handlesCl.offset), pCommandBuffers[c]->handlesCl.numBlocks); @@ -283,423 +281,426 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkQueueSubmit)( assert(queue); - //TODO this is incorrect - //see sync.c - //TODO: deal with pSubmits->pWaitDstStageMask - for(int c = 0; c < pSubmits->waitSemaphoreCount; ++c) + for(uint32_t z = 0; z < submitCount; ++z) { - sem_wait((sem_t*)pSubmits->pWaitSemaphores[c]); - } + const VkSubmitInfo* submitInfo = &pSubmits[z]; - for(int c = 0; c < pSubmits->commandBufferCount; ++c) - { - if(pSubmits->pCommandBuffers[c]->state == CMDBUF_STATE_EXECUTABLE) + //TODO this is incorrect + //see sync.c + //TODO: deal with pSubmits->pWaitDstStageMask + for(uint32_t c = 0; c < submitInfo->waitSemaphoreCount; ++c) { - pSubmits->pCommandBuffers[c]->state = CMDBUF_STATE_PENDING; - } - } - - for(int c = 0; c < pSubmits->commandBufferCount; ++c) - { - VkCommandBuffer cmdbuf = pSubmits->pCommandBuffers[c]; - - if(cmdbuf->binCl.currMarkerOffset == -1) - { - //no markers recorded yet, skip - continue; + sem_wait((sem_t*)submitInfo->pWaitSemaphores[c]); } - //first entry is assumed to be a marker - CLMarker* marker = getCPAptrFromOffset(cmdbuf->binCl.CPA, cmdbuf->binCl.offset); - - //a command buffer may contain multiple render passes - //and commands outside render passes such as clear commands - //each of these corresponds to a control list submit - - //submit each separate control list - while(marker) + for(uint32_t c = 0; c < submitInfo->commandBufferCount; ++c) { - assert(marker->memGuard == 0xDDDDDDDD); - - struct drm_vc4_submit_cl submitCl = + if(submitInfo->pCommandBuffers[c]->state == CMDBUF_STATE_EXECUTABLE) { - .color_read.hindex = ~0, - .zs_read.hindex = ~0, - .color_write.hindex = ~0, - .msaa_color_write.hindex = ~0, - .zs_write.hindex = ~0, - .msaa_zs_write.hindex = ~0, - }; - - _image* writeImage = marker->writeImage; - _image* readImage = marker->readImage; - _image* writeDepthStencilImage = marker->writeDepthStencilImage; - _image* readDepthStencilImage = marker->readDepthStencilImage; - _image* writeMSAAimage = marker->writeMSAAimage; - _image* writeMSAAdepthStencilImage = marker->writeMSAAdepthStencilImage; - uint32_t performResolve = marker->performResolve; - uint32_t readMSAAimage = marker->readMSAAimage; - uint32_t readMSAAdepthStencilImage = marker->readMSAAdepthStencilImage; - - //This should not result in an insertion! - clFit(cmdbuf, &cmdbuf->handlesCl, 4 * 6); //just to be safe - uint32_t writeImageIdx = writeImage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBufOffset + cmdbuf->handlesCl.offset, marker->handlesSize, writeImage->boundMem->bo) : 0; - uint32_t readImageIdx = readImage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBufOffset + cmdbuf->handlesCl.offset, marker->handlesSize, readImage->boundMem->bo) : 0; - uint32_t writeDepthStencilImageIdx = writeDepthStencilImage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBufOffset + cmdbuf->handlesCl.offset, marker->handlesSize, writeDepthStencilImage->boundMem->bo) : 0; - uint32_t readDepthStencilImageIdx = readDepthStencilImage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBufOffset + cmdbuf->handlesCl.offset, marker->handlesSize, readDepthStencilImage->boundMem->bo) : 0; - uint32_t writeMSAAimageIdx = writeMSAAimage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesSize, marker->handlesBufOffset + cmdbuf->handlesCl.offset, writeMSAAimage->boundMem->bo) : 0; - uint32_t writeMSAAdepthStencilImageIdx = writeMSAAdepthStencilImage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBufOffset + cmdbuf->handlesCl.offset, marker->handlesSize, writeMSAAdepthStencilImage->boundMem->bo) : 0; - - submitCl.clear_color[0] = 0; - submitCl.clear_color[1] = 0; - submitCl.clear_z = 0; - submitCl.clear_s = 0; - - //fill out submit cl fields - if(writeImage) - { - uint32_t tiling = writeImage->tiling; - - if(marker->mipLevel > 0) - { - tiling = writeImage->levelTiling[marker->mipLevel]; - } - - submitCl.color_write.hindex = writeImageIdx; - submitCl.color_write.offset = marker->writeImageOffset + writeImage->boundOffset; - submitCl.color_write.flags = 0; - submitCl.color_write.bits = - VC4_SET_FIELD(getRenderTargetFormatVC4(writeImage->format), VC4_RENDER_CONFIG_FORMAT) | - VC4_SET_FIELD(tiling, VC4_RENDER_CONFIG_MEMORY_FORMAT); - - if(performResolve) - { - submitCl.color_write.bits |= VC4_RENDER_CONFIG_MS_MODE_4X | VC4_RENDER_CONFIG_DECIMATE_MODE_4X; - } + submitInfo->pCommandBuffers[c]->state = CMDBUF_STATE_PENDING; } - - if(writeMSAAimage) - { - uint32_t tiling = writeMSAAimage->tiling; - - if(marker->mipLevel > 0) - { - tiling = writeMSAAimage->levelTiling[marker->mipLevel]; - } - - submitCl.msaa_color_write.hindex = writeMSAAimageIdx; - submitCl.msaa_color_write.offset = marker->writeMSAAimageOffset + writeMSAAimage->boundOffset; - submitCl.msaa_color_write.flags = 0; - submitCl.msaa_color_write.bits = VC4_RENDER_CONFIG_MS_MODE_4X | - VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_COLOR, VC4_LOADSTORE_TILE_BUFFER_BUFFER) | - VC4_SET_FIELD(tiling, VC4_LOADSTORE_TILE_BUFFER_TILING) | - VC4_SET_FIELD(getRenderTargetFormatVC4(writeMSAAimage->format), VC4_LOADSTORE_TILE_BUFFER_FORMAT); - } - - if(readImage) - { - uint32_t tiling = readImage->tiling; - - if(marker->mipLevel > 0) - { - tiling = readImage->levelTiling[marker->mipLevel]; - } - - submitCl.color_read.hindex = readImageIdx; - submitCl.color_read.offset = marker->readImageOffset + readImage->boundOffset; - submitCl.color_read.flags = readMSAAimage ? VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES : 0; - submitCl.color_read.bits = - VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_COLOR, VC4_LOADSTORE_TILE_BUFFER_BUFFER) | - VC4_SET_FIELD(tiling, VC4_LOADSTORE_TILE_BUFFER_TILING) | - VC4_SET_FIELD(getRenderTargetFormatVC4(readImage->format), VC4_LOADSTORE_TILE_BUFFER_FORMAT); - } - - if(writeDepthStencilImage) - { - uint32_t tiling = writeDepthStencilImage->tiling; - - if(marker->mipLevel > 0) - { - tiling = writeDepthStencilImage->levelTiling[marker->mipLevel]; - } - - submitCl.zs_write.hindex = writeDepthStencilImageIdx; - submitCl.zs_write.offset = marker->writeDepthStencilImageOffset + writeDepthStencilImage->boundOffset; - submitCl.zs_write.flags = 0; - submitCl.zs_write.bits = - VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_ZS, VC4_LOADSTORE_TILE_BUFFER_BUFFER) | - VC4_SET_FIELD(tiling, VC4_LOADSTORE_TILE_BUFFER_TILING); - } - - if(writeMSAAdepthStencilImage) - { - uint32_t tiling = writeMSAAdepthStencilImage->tiling; - - if(marker->mipLevel > 0) - { - tiling = writeMSAAdepthStencilImage->levelTiling[marker->mipLevel]; - } - - submitCl.msaa_zs_write.hindex = writeMSAAdepthStencilImageIdx; - submitCl.msaa_zs_write.offset = marker->writeMSAAdepthStencilImageOffset + writeMSAAdepthStencilImage->boundOffset; - submitCl.msaa_zs_write.flags = 0; - submitCl.msaa_zs_write.bits = VC4_RENDER_CONFIG_MS_MODE_4X | - VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_ZS, VC4_LOADSTORE_TILE_BUFFER_BUFFER) | - VC4_SET_FIELD(tiling, VC4_LOADSTORE_TILE_BUFFER_TILING); - } - - if(readDepthStencilImage) - { - uint32_t tiling = readDepthStencilImage->tiling; - - if(marker->mipLevel > 0) - { - tiling = readDepthStencilImage->levelTiling[marker->mipLevel]; - } - - submitCl.zs_read.hindex = readDepthStencilImageIdx; - submitCl.zs_read.offset = marker->readDepthStencilImageOffset + readDepthStencilImage->boundOffset; - submitCl.zs_read.flags = readMSAAdepthStencilImage ? VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES : 0; - submitCl.zs_read.bits = - VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_ZS, VC4_LOADSTORE_TILE_BUFFER_BUFFER) | - VC4_SET_FIELD(tiling, VC4_LOADSTORE_TILE_BUFFER_TILING); - } - - submitCl.clear_color[0] = marker->clearColor[0]; - submitCl.clear_color[1] = marker->clearColor[1]; - - submitCl.clear_z = marker->clearDepth; //0...1 -> 0...0xffffff - submitCl.clear_s = marker->clearStencil; //0...0xff - - -// fprintf(stderr, "submitCl.clear_color[0]: %u\n", submitCl.clear_color[0]); -// fprintf(stderr, "submitCl.clear_color[1]: %u\n", submitCl.clear_color[1]); -// fprintf(stderr, "submitCl.clear_z: %u\n", submitCl.clear_z); -// fprintf(stderr, "submitCl.clear_s: %u\n", submitCl.clear_s); - - submitCl.min_x_tile = 0; - submitCl.min_y_tile = 0; - - uint32_t tileSizeW = 64; - uint32_t tileSizeH = 64; - - uint32_t widthInTiles = 0, heightInTiles = 0; - uint32_t width = 0, height = 0, bpp = 0; - - width = marker->width; - height = marker->height; - - if(writeImage) - { - bpp = getFormatBpp(writeImage->format); - } - else if(writeMSAAimage) - { - bpp = getFormatBpp(writeMSAAimage->format); - } - - if(bpp == 64) - { - tileSizeH >>= 1; - } - - if(performResolve || writeMSAAimage || writeMSAAdepthStencilImage) - { - tileSizeW >>= 1; - tileSizeH >>= 1; - } - - widthInTiles = divRoundUp(width, tileSizeW); - heightInTiles = divRoundUp(height, tileSizeH); - - //pad width if rendering to miplevel - if(marker->mipLevel > 0) - { - width = getPow2Pad(width); - width = width < 4 ? 4 : width; - } - - submitCl.max_x_tile = widthInTiles - 1; - submitCl.max_y_tile = heightInTiles - 1; - submitCl.width = width; - submitCl.height = height; - submitCl.flags |= marker->flags; - - submitCl.bo_handles = getCPAptrFromOffset(cmdbuf->handlesCl.CPA, marker->handlesBufOffset + cmdbuf->handlesCl.offset); - submitCl.bin_cl = ((uint8_t*)marker) + sizeof(CLMarker); - submitCl.shader_rec = getCPAptrFromOffset(cmdbuf->shaderRecCl.CPA, marker->shaderRecBufOffset + cmdbuf->shaderRecCl.offset); - submitCl.uniforms = getCPAptrFromOffset(cmdbuf->uniformsCl.CPA, marker->uniformsBufOffset + cmdbuf->uniformsCl.offset); - - if(marker->perfmonID) - { - uint32_t perfmonSelector = 0; - uint32_t* perfmonIDptr = (uint32_t*)marker->perfmonID; - - if(pSubmits->pNext) - { - VkPerformanceQuerySubmitInfoKHR* perfQuerySubmitInfo = pSubmits->pNext; - perfmonSelector = perfQuerySubmitInfo->counterPassIndex; - } - - submitCl.perfmonid = *(perfmonIDptr + perfmonSelector); - } - - //marker not closed yet - //close here - if(!marker->size) - { - clCloseCurrentMarker(&cmdbuf->binCl, &cmdbuf->handlesCl, &cmdbuf->shaderRecCl, cmdbuf->shaderRecCount, &cmdbuf->uniformsCl); - } - - submitCl.bo_handle_count = marker->handlesSize / 4; - submitCl.bin_cl_size = marker->size; - submitCl.shader_rec_size = marker->shaderRecSize; - submitCl.shader_rec_count = marker->shaderRecCount; - submitCl.uniforms_size = marker->uniformsSize; - - /** - printf("BCL:\n"); - uint8_t* mem = malloc(marker->size); - memcpy(mem, marker+1, marker->size); - clDump(mem, marker->size); - free(mem); - - printf("BO handles: "); - for(int d = 0; d < marker->handlesSize / 4; ++d) - { - printf("%u ", *(((uint32_t*)getCPAptrFromOffset(cmdbuf->handlesCl.CPA, marker->handlesBufOffset + cmdbuf->handlesCl.offset))+d)); - } - printf("\nUniforms: "); - for(int d = 0; d < marker->uniformsSize / 4; ++d) - { - printf("%i ", *(((uint32_t*)getCPAptrFromOffset(cmdbuf->uniformsCl.CPA, marker->uniformsBufOffset + cmdbuf->uniformsCl.offset))+d)); - } - printf("\nShader recs: "); - uint8_t* ptr = getCPAptrFromOffset(cmdbuf->shaderRecCl.CPA, marker->shaderRecBufOffset + cmdbuf->shaderRecCl.offset + (3 + 3) * 4); - for(int d = 0; d < marker->shaderRecCount; ++d) - { - uint8_t flags = *ptr; - uint8_t fragmentShaderIsSingleThreaded = flags & (1 << 0); - uint8_t pointSizeIncludedInShadedVertexData = (flags & (1 << 1)) >> 1; - uint8_t enableClipping = (flags & (1 << 2)) >> 2; - ptr += 2; - - uint8_t fragmentNumberOfUniforms = *ptr; ptr++; - uint8_t fragmentNumberOfVaryings = *ptr; ptr++; - uint32_t fragmentShaderCodeAddress = *(uint32_t*)ptr; ptr+=4; - uint32_t fragmentShaderUniformAddress = *(uint32_t*)ptr; ptr+=4; - - uint16_t vertexNumberOfUniforms = *(uint16_t*)ptr; ptr+=2; - uint8_t vertexAttribSelectBits = *ptr; ptr++; - uint8_t vertexAttribTotalSize = *ptr; ptr++; - uint32_t vertexShaderCodeAddress = *(uint32_t*)ptr; ptr+=4; - uint32_t vertexShaderUniformAddress = *(uint32_t*)ptr; ptr+=4; - - uint16_t coordNumberOfUniforms = *(uint16_t*)ptr; ptr+=2; - uint8_t coordAttribSelectBits = *ptr; ptr++; - uint8_t coordAttribTotalSize = *ptr; ptr++; - uint32_t coordShaderCodeAddress = *(uint32_t*)ptr; ptr+=4; - uint32_t coordShaderUniformAddress = *(uint32_t*)ptr; ptr+=4; - - printf("\nfragmentShaderIsSingleThreaded: %i", fragmentShaderIsSingleThreaded); - printf("\npointSizeIncludedInShadedVertexData: %i", pointSizeIncludedInShadedVertexData); - printf("\nenableClipping: %i", enableClipping); - - printf("\nfragmentNumberOfUniforms: %i", fragmentNumberOfUniforms); - printf("\nfragmentNumberOfVaryings: %i", fragmentNumberOfVaryings); - printf("\nfragmentShaderCodeAddress: %i", fragmentShaderCodeAddress); - printf("\nfragmentShaderUniformAddress: %i", fragmentShaderUniformAddress); - - printf("\nvertexNumberOfUniforms: %i", vertexNumberOfUniforms); - printf("\nvertexAttribSelectBits: %i", vertexAttribSelectBits); - printf("\nvertexAttribTotalSize: %i", vertexAttribTotalSize); - printf("\nvertexShaderCodeAddress: %i", vertexShaderCodeAddress); - printf("\nvertexShaderUniformAddress: %i", vertexShaderUniformAddress); - - printf("\ncoordNumberOfUniforms: %i", coordNumberOfUniforms); - printf("\ncoordAttribSelectBits: %i", coordAttribSelectBits); - printf("\ncoordAttribTotalSize: %i", coordAttribTotalSize); - printf("\ncoordShaderCodeAddress: %i", coordShaderCodeAddress); - printf("\ncoordShaderUniformAddress: %i", coordShaderUniformAddress); - - uint8_t numAttribs = 0; - for(uint8_t e = 0; e < 8; ++e) - { - numAttribs += (vertexAttribSelectBits & (1 << e)) >> e; - } - - printf("\nnumattribs: %i", numAttribs); - for(uint8_t e = 0; e < numAttribs; ++e) - { - uint32_t attribBaseAddress = *(uint32_t*)ptr; ptr+=4; - uint8_t attribNumBytes = *ptr; ptr++; - uint8_t attribStride = *ptr; ptr++; - uint8_t attribVsVPMOffset = *ptr; ptr++; - uint8_t attribCsVPMOffset = *ptr; ptr++; - - printf("\nattrib \#%i", e); - printf("\nattribBaseAddress: %i", attribBaseAddress); - printf("\nattribNumBytes: %i", attribNumBytes); - printf("\nattribStride: %i", attribStride); - printf("\nattribVsVPMOffset: %i", attribVsVPMOffset); - printf("\nattribCsVPMOffset: %i", attribCsVPMOffset); - } - } - printf("\nwidth height: %u, %u\n", submitCl.width, submitCl.height); - printf("tile min/max: %u,%u %u,%u\n", submitCl.min_x_tile, submitCl.min_y_tile, submitCl.max_x_tile, submitCl.max_y_tile); - printf("color read surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.color_read.hindex, submitCl.color_read.offset, submitCl.color_read.bits, submitCl.color_read.flags); - printf("color write surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.color_write.hindex, submitCl.color_write.offset, submitCl.color_write.bits, submitCl.color_write.flags); - printf("zs read surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.zs_read.hindex, submitCl.zs_read.offset, submitCl.zs_read.bits, submitCl.zs_read.flags); - printf("zs write surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.zs_write.hindex, submitCl.zs_write.offset, submitCl.zs_write.bits, submitCl.zs_write.flags); - printf("msaa color write surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.msaa_color_write.hindex, submitCl.msaa_color_write.offset, submitCl.msaa_color_write.bits, submitCl.msaa_color_write.flags); - printf("msaa zs write surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.msaa_zs_write.hindex, submitCl.msaa_zs_write.offset, submitCl.msaa_zs_write.bits, submitCl.msaa_zs_write.flags); - printf("clear color packed rgba %u %u\n", submitCl.clear_color[0], submitCl.clear_color[1]); - printf("clear z %u\n", submitCl.clear_z); - printf("clear s %u\n", submitCl.clear_s); - printf("flags %u\n", submitCl.flags); - printf("perfmonID %u\n", submitCl.perfmonid); - /**/ - - assert(marker->numDrawCallsSubmitted <= VC4_HW_2116_COUNT); - - assert(submitCl.bo_handle_count > 0); - - sem_wait(queue->seqnoSem); - { - //submit ioctl - vc4_cl_submit(controlFd, &submitCl, &queue->lastEmitSeqno, &queue->lastFinishedSeqno); - } - sem_post(queue->seqnoSem); - - //see if it's a sync bug - //uint64_t timeout = WAIT_TIMEOUT_INFINITE; - //vc4_seqno_wait(controlFd, &lastFinishedSeqno, queue->lastEmitSeqno, &timeout); - - //advance in linked list - marker = marker->nextMarkerOffset == -1 ? 0 : getCPAptrFromOffset(cmdbuf->binCl.CPA, marker->nextMarkerOffset + cmdbuf->binCl.offset); } - //CPAdebugPrint(cmdbuf->binCl.CPA); - } - - for(int c = 0; c < pSubmits->commandBufferCount; ++c) - { - if(pSubmits->pCommandBuffers[c]->state == CMDBUF_STATE_PENDING) + for(uint32_t c = 0; c < submitInfo->commandBufferCount; ++c) { - if(pSubmits->pCommandBuffers[c]->usageFlags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) + VkCommandBuffer cmdbuf = submitInfo->pCommandBuffers[c]; + + if(cmdbuf->binCl.currMarkerOffset == ~0u) { - pSubmits->pCommandBuffers[c]->state = CMDBUF_STATE_INVALID; + //no markers recorded yet, skip + continue; } - else + + //first entry is assumed to be a marker + CLMarker* marker = getCPAptrFromOffset(cmdbuf->binCl.CPA, cmdbuf->binCl.offset); + + //a command buffer may contain multiple render passes + //and commands outside render passes such as clear commands + //each of these corresponds to a control list submit + + //submit each separate control list + while(marker) { - pSubmits->pCommandBuffers[c]->state = CMDBUF_STATE_EXECUTABLE; + assert(marker->memGuard == 0xDDDDDDDD); + + struct drm_vc4_submit_cl submitCl = + { + .color_read.hindex = ~0, + .zs_read.hindex = ~0, + .color_write.hindex = ~0, + .msaa_color_write.hindex = ~0, + .zs_write.hindex = ~0, + .msaa_zs_write.hindex = ~0, + }; + + _image* writeImage = marker->writeImage; + _image* readImage = marker->readImage; + _image* writeDepthStencilImage = marker->writeDepthStencilImage; + _image* readDepthStencilImage = marker->readDepthStencilImage; + _image* writeMSAAimage = marker->writeMSAAimage; + _image* writeMSAAdepthStencilImage = marker->writeMSAAdepthStencilImage; + uint32_t performResolve = marker->performResolve; + uint32_t readMSAAimage = marker->readMSAAimage; + uint32_t readMSAAdepthStencilImage = marker->readMSAAdepthStencilImage; + + //This should not result in an insertion! + clFit(&cmdbuf->handlesCl, 4 * 6); //just to be safe + uint32_t writeImageIdx = writeImage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBufOffset + cmdbuf->handlesCl.offset, marker->handlesSize, writeImage->boundMem->bo) : 0; + uint32_t readImageIdx = readImage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBufOffset + cmdbuf->handlesCl.offset, marker->handlesSize, readImage->boundMem->bo) : 0; + uint32_t writeDepthStencilImageIdx = writeDepthStencilImage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBufOffset + cmdbuf->handlesCl.offset, marker->handlesSize, writeDepthStencilImage->boundMem->bo) : 0; + uint32_t readDepthStencilImageIdx = readDepthStencilImage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBufOffset + cmdbuf->handlesCl.offset, marker->handlesSize, readDepthStencilImage->boundMem->bo) : 0; + uint32_t writeMSAAimageIdx = writeMSAAimage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesSize, marker->handlesBufOffset + cmdbuf->handlesCl.offset, writeMSAAimage->boundMem->bo) : 0; + uint32_t writeMSAAdepthStencilImageIdx = writeMSAAdepthStencilImage ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBufOffset + cmdbuf->handlesCl.offset, marker->handlesSize, writeMSAAdepthStencilImage->boundMem->bo) : 0; + + submitCl.clear_color[0] = 0; + submitCl.clear_color[1] = 0; + submitCl.clear_z = 0; + submitCl.clear_s = 0; + + //fill out submit cl fields + if(writeImage) + { + uint32_t tiling = writeImage->tiling; + + if(marker->mipLevel > 0) + { + tiling = writeImage->levelTiling[marker->mipLevel]; + } + + submitCl.color_write.hindex = writeImageIdx; + submitCl.color_write.offset = marker->writeImageOffset + writeImage->boundOffset; + submitCl.color_write.flags = 0; + submitCl.color_write.bits = + VC4_SET_FIELD(getRenderTargetFormatVC4(writeImage->format), VC4_RENDER_CONFIG_FORMAT) | + VC4_SET_FIELD(tiling, VC4_RENDER_CONFIG_MEMORY_FORMAT); + + if(performResolve) + { + submitCl.color_write.bits |= VC4_RENDER_CONFIG_MS_MODE_4X | VC4_RENDER_CONFIG_DECIMATE_MODE_4X; + } + } + + if(writeMSAAimage) + { + uint32_t tiling = writeMSAAimage->tiling; + + if(marker->mipLevel > 0) + { + tiling = writeMSAAimage->levelTiling[marker->mipLevel]; + } + + submitCl.msaa_color_write.hindex = writeMSAAimageIdx; + submitCl.msaa_color_write.offset = marker->writeMSAAimageOffset + writeMSAAimage->boundOffset; + submitCl.msaa_color_write.flags = 0; + submitCl.msaa_color_write.bits = VC4_RENDER_CONFIG_MS_MODE_4X | + VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_COLOR, VC4_LOADSTORE_TILE_BUFFER_BUFFER) | + VC4_SET_FIELD(tiling, VC4_LOADSTORE_TILE_BUFFER_TILING) | + VC4_SET_FIELD(getRenderTargetFormatVC4(writeMSAAimage->format), VC4_LOADSTORE_TILE_BUFFER_FORMAT); + } + + if(readImage) + { + uint32_t tiling = readImage->tiling; + + if(marker->mipLevel > 0) + { + tiling = readImage->levelTiling[marker->mipLevel]; + } + + submitCl.color_read.hindex = readImageIdx; + submitCl.color_read.offset = marker->readImageOffset + readImage->boundOffset; + submitCl.color_read.flags = readMSAAimage ? VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES : 0; + submitCl.color_read.bits = + VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_COLOR, VC4_LOADSTORE_TILE_BUFFER_BUFFER) | + VC4_SET_FIELD(tiling, VC4_LOADSTORE_TILE_BUFFER_TILING) | + VC4_SET_FIELD(getRenderTargetFormatVC4(readImage->format), VC4_LOADSTORE_TILE_BUFFER_FORMAT); + } + + if(writeDepthStencilImage) + { + uint32_t tiling = writeDepthStencilImage->tiling; + + if(marker->mipLevel > 0) + { + tiling = writeDepthStencilImage->levelTiling[marker->mipLevel]; + } + + submitCl.zs_write.hindex = writeDepthStencilImageIdx; + submitCl.zs_write.offset = marker->writeDepthStencilImageOffset + writeDepthStencilImage->boundOffset; + submitCl.zs_write.flags = 0; + submitCl.zs_write.bits = + VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_ZS, VC4_LOADSTORE_TILE_BUFFER_BUFFER) | + VC4_SET_FIELD(tiling, VC4_LOADSTORE_TILE_BUFFER_TILING); + } + + if(writeMSAAdepthStencilImage) + { + uint32_t tiling = writeMSAAdepthStencilImage->tiling; + + if(marker->mipLevel > 0) + { + tiling = writeMSAAdepthStencilImage->levelTiling[marker->mipLevel]; + } + + submitCl.msaa_zs_write.hindex = writeMSAAdepthStencilImageIdx; + submitCl.msaa_zs_write.offset = marker->writeMSAAdepthStencilImageOffset + writeMSAAdepthStencilImage->boundOffset; + submitCl.msaa_zs_write.flags = 0; + submitCl.msaa_zs_write.bits = VC4_RENDER_CONFIG_MS_MODE_4X | + VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_ZS, VC4_LOADSTORE_TILE_BUFFER_BUFFER) | + VC4_SET_FIELD(tiling, VC4_LOADSTORE_TILE_BUFFER_TILING); + } + + if(readDepthStencilImage) + { + uint32_t tiling = readDepthStencilImage->tiling; + + if(marker->mipLevel > 0) + { + tiling = readDepthStencilImage->levelTiling[marker->mipLevel]; + } + + submitCl.zs_read.hindex = readDepthStencilImageIdx; + submitCl.zs_read.offset = marker->readDepthStencilImageOffset + readDepthStencilImage->boundOffset; + submitCl.zs_read.flags = readMSAAdepthStencilImage ? VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES : 0; + submitCl.zs_read.bits = + VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_ZS, VC4_LOADSTORE_TILE_BUFFER_BUFFER) | + VC4_SET_FIELD(tiling, VC4_LOADSTORE_TILE_BUFFER_TILING); + } + + submitCl.clear_color[0] = marker->clearColor[0]; + submitCl.clear_color[1] = marker->clearColor[1]; + + submitCl.clear_z = marker->clearDepth; //0...1 -> 0...0xffffff + submitCl.clear_s = marker->clearStencil; //0...0xff + + + // fprintf(stderr, "submitCl.clear_color[0]: %u\n", submitCl.clear_color[0]); + // fprintf(stderr, "submitCl.clear_color[1]: %u\n", submitCl.clear_color[1]); + // fprintf(stderr, "submitCl.clear_z: %u\n", submitCl.clear_z); + // fprintf(stderr, "submitCl.clear_s: %u\n", submitCl.clear_s); + + submitCl.min_x_tile = 0; + submitCl.min_y_tile = 0; + + uint32_t tileSizeW = 64; + uint32_t tileSizeH = 64; + + uint32_t widthInTiles = 0, heightInTiles = 0; + uint32_t width = 0, height = 0, bpp = 0; + + width = marker->width; + height = marker->height; + + if(writeImage) + { + bpp = getFormatBpp(writeImage->format); + } + else if(writeMSAAimage) + { + bpp = getFormatBpp(writeMSAAimage->format); + } + + if(bpp == 64) + { + tileSizeH >>= 1; + } + + if(performResolve || writeMSAAimage || writeMSAAdepthStencilImage) + { + tileSizeW >>= 1; + tileSizeH >>= 1; + } + + widthInTiles = divRoundUp(width, tileSizeW); + heightInTiles = divRoundUp(height, tileSizeH); + + //pad width if rendering to miplevel + if(marker->mipLevel > 0) + { + width = getPow2Pad(width); + width = width < 4 ? 4 : width; + } + + submitCl.max_x_tile = widthInTiles - 1; + submitCl.max_y_tile = heightInTiles - 1; + submitCl.width = width; + submitCl.height = height; + submitCl.flags |= marker->flags; + + submitCl.bo_handles = getCPAptrFromOffset(cmdbuf->handlesCl.CPA, marker->handlesBufOffset + cmdbuf->handlesCl.offset); + submitCl.bin_cl = ((uint8_t*)marker) + sizeof(CLMarker); + submitCl.shader_rec = getCPAptrFromOffset(cmdbuf->shaderRecCl.CPA, marker->shaderRecBufOffset + cmdbuf->shaderRecCl.offset); + submitCl.uniforms = getCPAptrFromOffset(cmdbuf->uniformsCl.CPA, marker->uniformsBufOffset + cmdbuf->uniformsCl.offset); + + if(marker->perfmonID) + { + uint32_t perfmonSelector = 0; + uint32_t* perfmonIDptr = (uint32_t*)marker->perfmonID; + + if(submitInfo->pNext) + { + const VkPerformanceQuerySubmitInfoKHR* perfQuerySubmitInfo = submitInfo->pNext; + perfmonSelector = perfQuerySubmitInfo->counterPassIndex; + } + + submitCl.perfmonid = *(perfmonIDptr + perfmonSelector); + } + + //marker not closed yet + //close here + if(!marker->size) + { + clCloseCurrentMarker(&cmdbuf->binCl, &cmdbuf->handlesCl, &cmdbuf->shaderRecCl, cmdbuf->shaderRecCount, &cmdbuf->uniformsCl); + } + + submitCl.bo_handle_count = marker->handlesSize / 4; + submitCl.bin_cl_size = marker->size; + submitCl.shader_rec_size = marker->shaderRecSize; + submitCl.shader_rec_count = marker->shaderRecCount; + submitCl.uniforms_size = marker->uniformsSize; + + /** + printf("BCL:\n"); + uint8_t* mem = malloc(marker->size); + memcpy(mem, marker+1, marker->size); + clDump(mem, marker->size); + free(mem); + + printf("BO handles: "); + for(int d = 0; d < marker->handlesSize / 4; ++d) + { + printf("%u ", *(((uint32_t*)getCPAptrFromOffset(cmdbuf->handlesCl.CPA, marker->handlesBufOffset + cmdbuf->handlesCl.offset))+d)); + } + printf("\nUniforms: "); + for(int d = 0; d < marker->uniformsSize / 4; ++d) + { + printf("%i ", *(((uint32_t*)getCPAptrFromOffset(cmdbuf->uniformsCl.CPA, marker->uniformsBufOffset + cmdbuf->uniformsCl.offset))+d)); + } + printf("\nShader recs: "); + uint8_t* ptr = getCPAptrFromOffset(cmdbuf->shaderRecCl.CPA, marker->shaderRecBufOffset + cmdbuf->shaderRecCl.offset + (3 + 3) * 4); + for(int d = 0; d < marker->shaderRecCount; ++d) + { + uint8_t flags = *ptr; + uint8_t fragmentShaderIsSingleThreaded = flags & (1 << 0); + uint8_t pointSizeIncludedInShadedVertexData = (flags & (1 << 1)) >> 1; + uint8_t enableClipping = (flags & (1 << 2)) >> 2; + ptr += 2; + + uint8_t fragmentNumberOfUniforms = *ptr; ptr++; + uint8_t fragmentNumberOfVaryings = *ptr; ptr++; + uint32_t fragmentShaderCodeAddress = *(uint32_t*)ptr; ptr+=4; + uint32_t fragmentShaderUniformAddress = *(uint32_t*)ptr; ptr+=4; + + uint16_t vertexNumberOfUniforms = *(uint16_t*)ptr; ptr+=2; + uint8_t vertexAttribSelectBits = *ptr; ptr++; + uint8_t vertexAttribTotalSize = *ptr; ptr++; + uint32_t vertexShaderCodeAddress = *(uint32_t*)ptr; ptr+=4; + uint32_t vertexShaderUniformAddress = *(uint32_t*)ptr; ptr+=4; + + uint16_t coordNumberOfUniforms = *(uint16_t*)ptr; ptr+=2; + uint8_t coordAttribSelectBits = *ptr; ptr++; + uint8_t coordAttribTotalSize = *ptr; ptr++; + uint32_t coordShaderCodeAddress = *(uint32_t*)ptr; ptr+=4; + uint32_t coordShaderUniformAddress = *(uint32_t*)ptr; ptr+=4; + + printf("\nfragmentShaderIsSingleThreaded: %i", fragmentShaderIsSingleThreaded); + printf("\npointSizeIncludedInShadedVertexData: %i", pointSizeIncludedInShadedVertexData); + printf("\nenableClipping: %i", enableClipping); + + printf("\nfragmentNumberOfUniforms: %i", fragmentNumberOfUniforms); + printf("\nfragmentNumberOfVaryings: %i", fragmentNumberOfVaryings); + printf("\nfragmentShaderCodeAddress: %i", fragmentShaderCodeAddress); + printf("\nfragmentShaderUniformAddress: %i", fragmentShaderUniformAddress); + + printf("\nvertexNumberOfUniforms: %i", vertexNumberOfUniforms); + printf("\nvertexAttribSelectBits: %i", vertexAttribSelectBits); + printf("\nvertexAttribTotalSize: %i", vertexAttribTotalSize); + printf("\nvertexShaderCodeAddress: %i", vertexShaderCodeAddress); + printf("\nvertexShaderUniformAddress: %i", vertexShaderUniformAddress); + + printf("\ncoordNumberOfUniforms: %i", coordNumberOfUniforms); + printf("\ncoordAttribSelectBits: %i", coordAttribSelectBits); + printf("\ncoordAttribTotalSize: %i", coordAttribTotalSize); + printf("\ncoordShaderCodeAddress: %i", coordShaderCodeAddress); + printf("\ncoordShaderUniformAddress: %i", coordShaderUniformAddress); + + uint8_t numAttribs = 0; + for(uint8_t e = 0; e < 8; ++e) + { + numAttribs += (vertexAttribSelectBits & (1 << e)) >> e; + } + + printf("\nnumattribs: %i", numAttribs); + for(uint8_t e = 0; e < numAttribs; ++e) + { + uint32_t attribBaseAddress = *(uint32_t*)ptr; ptr+=4; + uint8_t attribNumBytes = *ptr; ptr++; + uint8_t attribStride = *ptr; ptr++; + uint8_t attribVsVPMOffset = *ptr; ptr++; + uint8_t attribCsVPMOffset = *ptr; ptr++; + + printf("\nattrib \#%i", e); + printf("\nattribBaseAddress: %i", attribBaseAddress); + printf("\nattribNumBytes: %i", attribNumBytes); + printf("\nattribStride: %i", attribStride); + printf("\nattribVsVPMOffset: %i", attribVsVPMOffset); + printf("\nattribCsVPMOffset: %i", attribCsVPMOffset); + } + } + printf("\nwidth height: %u, %u\n", submitCl.width, submitCl.height); + printf("tile min/max: %u,%u %u,%u\n", submitCl.min_x_tile, submitCl.min_y_tile, submitCl.max_x_tile, submitCl.max_y_tile); + printf("color read surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.color_read.hindex, submitCl.color_read.offset, submitCl.color_read.bits, submitCl.color_read.flags); + printf("color write surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.color_write.hindex, submitCl.color_write.offset, submitCl.color_write.bits, submitCl.color_write.flags); + printf("zs read surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.zs_read.hindex, submitCl.zs_read.offset, submitCl.zs_read.bits, submitCl.zs_read.flags); + printf("zs write surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.zs_write.hindex, submitCl.zs_write.offset, submitCl.zs_write.bits, submitCl.zs_write.flags); + printf("msaa color write surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.msaa_color_write.hindex, submitCl.msaa_color_write.offset, submitCl.msaa_color_write.bits, submitCl.msaa_color_write.flags); + printf("msaa zs write surf: hindex, offset, bits, flags %u %u %u %u\n", submitCl.msaa_zs_write.hindex, submitCl.msaa_zs_write.offset, submitCl.msaa_zs_write.bits, submitCl.msaa_zs_write.flags); + printf("clear color packed rgba %u %u\n", submitCl.clear_color[0], submitCl.clear_color[1]); + printf("clear z %u\n", submitCl.clear_z); + printf("clear s %u\n", submitCl.clear_s); + printf("flags %u\n", submitCl.flags); + printf("perfmonID %u\n", submitCl.perfmonid); + /**/ + + assert(marker->numDrawCallsSubmitted <= VC4_HW_2116_COUNT); + + assert(submitCl.bo_handle_count > 0); + + { + //submit ioctl + vc4_cl_submit(controlFd, &submitCl, &queue->lastEmitSeqno, &queue->lastFinishedSeqno); + } + + //see if it's a sync bug + //uint64_t timeout = WAIT_TIMEOUT_INFINITE; + //vc4_seqno_wait(controlFd, &lastFinishedSeqno, queue->lastEmitSeqno, &timeout); + + //advance in linked list + marker = marker->nextMarkerOffset == ~0u ? 0 : getCPAptrFromOffset(cmdbuf->binCl.CPA, marker->nextMarkerOffset + cmdbuf->binCl.offset); + } + + //CPAdebugPrint(cmdbuf->binCl.CPA); + } + + for(uint32_t c = 0; c < submitInfo->commandBufferCount; ++c) + { + if(submitInfo->pCommandBuffers[c]->state == CMDBUF_STATE_PENDING) + { + if(submitInfo->pCommandBuffers[c]->usageFlags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) + { + submitInfo->pCommandBuffers[c]->state = CMDBUF_STATE_INVALID; + } + else + { + submitInfo->pCommandBuffers[c]->state = CMDBUF_STATE_EXECUTABLE; + } } } - } - for(int c = 0; c < pSubmits->signalSemaphoreCount; ++c) - { - sem_post((sem_t*)pSubmits->pSignalSemaphores[c]); + for(uint32_t c = 0; c < submitInfo->signalSemaphoreCount; ++c) + { + sem_post((sem_t*)submitInfo->pSignalSemaphores[c]); + } } _fence* f = fence; @@ -730,7 +731,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkFreeCommandBuffers)( _commandPool* cp = (_commandPool*)commandPool; - for(int c = 0; c < commandBufferCount; ++c) + for(uint32_t c = 0; c < commandBufferCount; ++c) { if(pCommandBuffers[c]) { @@ -838,6 +839,8 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkResetCommandPool)( //TODO reset flag --> free all pool resources PROFILEEND(RPIFUNC(vkResetCommandPool)); + + return VK_SUCCESS; } /* @@ -914,6 +917,8 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkResetCommandBuffer)( commandBuffer->perfmonID = 0; PROFILEEND(RPIFUNC(vkResetCommandBuffer)); + + return VK_SUCCESS; } VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdExecuteCommands)( diff --git a/driver/common.c b/driver/common.c index 7053e88..23f1248 100644 --- a/driver/common.c +++ b/driver/common.c @@ -182,9 +182,9 @@ uint32_t packVec4IntoABGR8(const float rgba[4]) return res; } -int findInstanceExtension(char* name) +int findInstanceExtension(const char* name) { - for(int c = 0; c < numInstanceExtensions; ++c) + for(uint32_t c = 0; c < numInstanceExtensions; ++c) { if(strcmp(instanceExtensions[c].extensionName, name) == 0) { @@ -195,9 +195,9 @@ int findInstanceExtension(char* name) return -1; } -int findDeviceExtension(char* name) +int findDeviceExtension(const char* name) { - for(int c = 0; c < numDeviceExtensions; ++c) + for(uint32_t c = 0; c < numDeviceExtensions; ++c) { if(strcmp(deviceExtensions[c].extensionName, name) == 0) { @@ -531,17 +531,17 @@ uint32_t ulog2(uint32_t v) return ret; } -void clFit(VkCommandBuffer cb, ControlList* cl, uint32_t commandSize) +void clFit(ControlList* cl, uint32_t commandSize) { if(!clHasEnoughSpace(cl, commandSize)) { uint32_t currSize = cl->nextFreeByteOffset - cl->offset; uint32_t currMarkerOffset = cl->currMarkerOffset - cl->offset; - cl->offset = consecutivePoolReAllocate(cl->CPA, getCPAptrFromOffset(cl->CPA, cl->offset), cl->numBlocks); assert(cl->offset != -1); + cl->offset = consecutivePoolReAllocate(cl->CPA, getCPAptrFromOffset(cl->CPA, cl->offset), cl->numBlocks); assert(cl->offset != ~0u); cl->nextFreeByteOffset = cl->offset + currSize; cl->numBlocks++; - cl->currMarkerOffset = cl->currMarkerOffset == -1 ? -1 : cl->offset + currMarkerOffset; - if(cl->currMarkerOffset != -1) + cl->currMarkerOffset = cl->currMarkerOffset == ~0u ? ~0u : cl->offset + currMarkerOffset; + if(cl->currMarkerOffset != ~0u) { assert(((CLMarker*)getCPAptrFromOffset(cl->CPA, cl->currMarkerOffset))->memGuard == 0xDDDDDDDD); } diff --git a/driver/common.h b/driver/common.h index e85b481..6796fd6 100644 --- a/driver/common.h +++ b/driver/common.h @@ -63,7 +63,6 @@ typedef struct VkQueue_T uint64_t lastEmitSeqno; uint64_t lastFinishedSeqno; _device* dev; - struct sem_t* seqnoSem; } _queue; typedef struct VkCommandPool_T @@ -134,7 +133,7 @@ typedef struct VkDevice_T VkPhysicalDeviceFeatures enabledFeatures; _physicalDevice* dev; _queue* queues[numQueueFamilies]; - int numQueues[numQueueFamilies]; + uint32_t numQueues[numQueueFamilies]; //emulation resources VkBuffer emulFsqVertexBuffer; @@ -548,8 +547,8 @@ typedef struct VkDisplayModeKHR_T uint32_t getFormatBpp(VkFormat f); uint32_t packVec4IntoABGR8(const float rgba[4]); void createImageBO(_image* i); -int findInstanceExtension(char* name); -int findDeviceExtension(char* name); +int findInstanceExtension(const char* name); +int findDeviceExtension(const char* name); uint32_t isLTformat(uint32_t bpp, uint32_t width, uint32_t height); void getUTileDimensions(uint32_t bpp, uint32_t* tileW, uint32_t* tileH); uint32_t roundUp(uint32_t numToRound, uint32_t multiple); @@ -583,7 +582,7 @@ uint8_t getTextureDataType(VkFormat format); uint8_t getMinFilterType(VkFilter minFilter, VkSamplerMipmapMode mipFilter);//, float maxLod); uint8_t getWrapMode(VkSamplerAddressMode mode); uint32_t getRenderTargetFormatVC4(VkFormat format); -void clFit(VkCommandBuffer cb, ControlList* cl, uint32_t commandSize); +void clFit(ControlList* cl, uint32_t commandSize); void clDump(void* cl, uint32_t size); void setupEmulationResources(VkDevice device); void setupClearEmulationResources(VkDevice device); diff --git a/driver/copy.c b/driver/copy.c index 51ea5cd..ff4c84b 100644 --- a/driver/copy.c +++ b/driver/copy.c @@ -42,24 +42,24 @@ void createFullscreenQuad(VkDevice device, VkBuffer* fsqVertexBuffer, VkDeviceMe { //create fsq vertex buffer unsigned vboSize = sizeof(float) * 4 * 3 * 2; //4 * 3 x vec2 - VkBufferCreateInfo ci = {}; + VkBufferCreateInfo ci = {0}; ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; ci.size = vboSize; ci.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; - VkResult res = RPIFUNC(vkCreateBuffer)(device, &ci, 0, fsqVertexBuffer); + RPIFUNC(vkCreateBuffer)(device, &ci, 0, fsqVertexBuffer); RPIFUNC(vkGetBufferMemoryRequirements)(device, *fsqVertexBuffer, &mr); VkPhysicalDeviceMemoryProperties pdmp; RPIFUNC(vkGetPhysicalDeviceMemoryProperties)(((_device*)device)->dev, &pdmp); - VkMemoryAllocateInfo mai = {}; + VkMemoryAllocateInfo mai = {0}; mai.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; mai.allocationSize = mr.size; mai.memoryTypeIndex = getMemoryTypeIndex(pdmp, mr.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - res = RPIFUNC(vkAllocateMemory)(device, &mai, 0, fsqVertexBufferMemory); + RPIFUNC(vkAllocateMemory)(device, &mai, 0, fsqVertexBufferMemory); float vertices[] = { @@ -73,11 +73,11 @@ void createFullscreenQuad(VkDevice device, VkBuffer* fsqVertexBuffer, VkDeviceMe }; void* data; - res = RPIFUNC(vkMapMemory)(device, *fsqVertexBufferMemory, 0, mr.size, 0, &data); + RPIFUNC(vkMapMemory)(device, *fsqVertexBufferMemory, 0, mr.size, 0, &data); memcpy(data, vertices, vboSize); RPIFUNC(vkUnmapMemory)(device, *fsqVertexBufferMemory); - res = RPIFUNC(vkBindBufferMemory)(device, *fsqVertexBuffer, *fsqVertexBufferMemory, 0); + RPIFUNC(vkBindBufferMemory)(device, *fsqVertexBuffer, *fsqVertexBufferMemory, 0); } } @@ -89,7 +89,7 @@ void createDescriptorPool(VkDevice device, VkDescriptorPool* descriptorPool) descriptorPoolSizes[1].descriptorCount = 2048; descriptorPoolSizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - VkDescriptorPoolCreateInfo descriptorPoolCI = {}; + VkDescriptorPoolCreateInfo descriptorPoolCI = {0}; descriptorPoolCI.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; descriptorPoolCI.poolSizeCount = 2; descriptorPoolCI.pPoolSizes = descriptorPoolSizes; @@ -106,13 +106,13 @@ void createDescriptorSetLayouts(VkDevice device, VkDescriptorSetLayout* bufferDs assert(textureDsl); //create blit dsl - VkDescriptorSetLayoutBinding setLayoutBinding = {}; + VkDescriptorSetLayoutBinding setLayoutBinding = {0}; setLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; setLayoutBinding.binding = 0; setLayoutBinding.descriptorCount = 1; setLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; - VkDescriptorSetLayoutCreateInfo descriptorLayoutCI = {}; + VkDescriptorSetLayoutCreateInfo descriptorLayoutCI = {0}; descriptorLayoutCI.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; descriptorLayoutCI.bindingCount = 1; descriptorLayoutCI.pBindings = &setLayoutBinding; @@ -125,7 +125,7 @@ void createDescriptorSetLayouts(VkDevice device, VkDescriptorSetLayout* bufferDs void createSampler(VkDevice device, VkSampler* nearestTextureSampler, VkSampler* linearTextureSampler) { - VkSamplerCreateInfo sampler = {}; + VkSamplerCreateInfo sampler = {0}; sampler.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; sampler.magFilter = VK_FILTER_NEAREST; sampler.minFilter = VK_FILTER_NEAREST; @@ -160,7 +160,7 @@ void createRendertarget(VkDevice device, uint32_t baseLayer, uint32_t baseMip, u format = VK_FORMAT_R8G8B8A8_UNORM; } - VkImageViewCreateInfo view = {}; + VkImageViewCreateInfo view = {0}; view.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view.viewType = VK_IMAGE_VIEW_TYPE_2D; view.format = format; @@ -176,7 +176,7 @@ void createRendertarget(VkDevice device, uint32_t baseLayer, uint32_t baseMip, u view.image = textureImage; RPIFUNC(vkCreateImageView)(device, &view, 0, textureView); - VkAttachmentDescription attachmentDescription = {}; + VkAttachmentDescription attachmentDescription = {0}; attachmentDescription.format = format; attachmentDescription.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; @@ -188,7 +188,7 @@ void createRendertarget(VkDevice device, uint32_t baseLayer, uint32_t baseMip, u VkAttachmentReference colorReference = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL }; - VkSubpassDescription subpassDescription = {}; + VkSubpassDescription subpassDescription = {0}; subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpassDescription.colorAttachmentCount = 1; subpassDescription.pColorAttachments = &colorReference; @@ -210,7 +210,7 @@ void createRendertarget(VkDevice device, uint32_t baseLayer, uint32_t baseMip, u dependencies[1].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT; - VkRenderPassCreateInfo renderPassInfo = {}; + VkRenderPassCreateInfo renderPassInfo = {0}; renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; renderPassInfo.attachmentCount = 1; renderPassInfo.pAttachments = &attachmentDescription; @@ -223,7 +223,7 @@ void createRendertarget(VkDevice device, uint32_t baseLayer, uint32_t baseMip, u VkImageView attachments = *textureView; - VkFramebufferCreateInfo framebufferCreateInfo = {}; + VkFramebufferCreateInfo framebufferCreateInfo = {0}; framebufferCreateInfo.renderPass = *offscreenRenderPass; framebufferCreateInfo.attachmentCount = 1; framebufferCreateInfo.pAttachments = &attachments; @@ -265,32 +265,32 @@ void createPipeline(VkDevice device, uint32_t needTexcoords, uint32_t numVertUni vertexInputAttributeDescription[1].format = VK_FORMAT_R32G32_SFLOAT; } - VkPipelineVertexInputStateCreateInfo vertexInputInfo = {}; + VkPipelineVertexInputStateCreateInfo vertexInputInfo = {0}; vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; vertexInputInfo.vertexAttributeDescriptionCount = needTexcoords ? 2 : 1; vertexInputInfo.pVertexAttributeDescriptions = vertexInputAttributeDescription; vertexInputInfo.vertexBindingDescriptionCount = 1; vertexInputInfo.pVertexBindingDescriptions = &vertexInputBindingDescription; - VkPipelineInputAssemblyStateCreateInfo pipelineIACreateInfo = {}; + VkPipelineInputAssemblyStateCreateInfo pipelineIACreateInfo = {0}; pipelineIACreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; pipelineIACreateInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - VkPipelineRasterizationStateCreateInfo rastCreateInfo = {}; + VkPipelineRasterizationStateCreateInfo rastCreateInfo = {0}; rastCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; rastCreateInfo.polygonMode = VK_POLYGON_MODE_FILL; rastCreateInfo.cullMode = VK_CULL_MODE_NONE; rastCreateInfo.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; rastCreateInfo.lineWidth = 1.0f; - VkPipelineMultisampleStateCreateInfo pipelineMSCreateInfo = {}; + VkPipelineMultisampleStateCreateInfo pipelineMSCreateInfo = {0}; pipelineMSCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - VkPipelineColorBlendAttachmentState blendAttachState = {}; + VkPipelineColorBlendAttachmentState blendAttachState = {0}; blendAttachState.colorWriteMask = 0xf; blendAttachState.blendEnable = false; - VkPipelineColorBlendStateCreateInfo blendCreateInfo = {}; + VkPipelineColorBlendStateCreateInfo blendCreateInfo = {0}; blendCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; blendCreateInfo.attachmentCount = 1; blendCreateInfo.pAttachments = &blendAttachState; @@ -320,7 +320,7 @@ void createPipeline(VkDevice device, uint32_t needTexcoords, uint32_t numVertUni shaderStageCreateInfo[1].module = blitShaderModule; shaderStageCreateInfo[1].pName = "main"; - VkPipelineLayoutCreateInfo pipelineLayoutCI = {}; + VkPipelineLayoutCreateInfo pipelineLayoutCI = {0}; pipelineLayoutCI.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipelineLayoutCI.setLayoutCount = 1; pipelineLayoutCI.pSetLayouts = &blitDsl; @@ -330,17 +330,17 @@ void createPipeline(VkDevice device, uint32_t needTexcoords, uint32_t numVertUni VkDynamicState dynState = VK_DYNAMIC_STATE_VIEWPORT; - VkPipelineDynamicStateCreateInfo pdsci = {}; + VkPipelineDynamicStateCreateInfo pdsci = {0}; pdsci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; pdsci.dynamicStateCount = 1; pdsci.pDynamicStates = &dynState; - VkPipelineViewportStateCreateInfo pvsci = {}; + VkPipelineViewportStateCreateInfo pvsci = {0}; pvsci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; pvsci.viewportCount = 0; pvsci.scissorCount = 0; - VkGraphicsPipelineCreateInfo pipelineInfo = {}; + VkGraphicsPipelineCreateInfo pipelineInfo = {0}; pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipelineInfo.stageCount = 2; pipelineInfo.pStages = &shaderStageCreateInfo[0]; @@ -356,7 +356,7 @@ void createPipeline(VkDevice device, uint32_t needTexcoords, uint32_t numVertUni pipelineInfo.pDepthStencilState = &depthStencilState; pipelineInfo.layout = *blitPipelineLayout; - VkResult res = RPIFUNC(vkCreateGraphicsPipelines)(device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, blitPipeline); + RPIFUNC(vkCreateGraphicsPipelines)(device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, blitPipeline); } void createBufferToTextureShaderModule(VkDevice device, VkShaderModule* blitShaderModule) @@ -507,11 +507,6 @@ void createBufferToTextureShaderModule(VkDevice device, VkShaderModule* blitShad "sig_unlock_score ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;" "\0"; - char* blit_asm_strings[] = - { - (char*)cs_asm_code, (char*)vs_asm_code, (char*)blit_fs_asm_code, 0 - }; - VkRpiAssemblyMappingEXT vertexMappings[] = { //vertex shader uniforms { @@ -600,7 +595,7 @@ void createBufferToTextureShaderModule(VkDevice device, VkShaderModule* blitShad VkRpiAssemblyMappingEXT* asm_mappings[4] = {}; uint32_t asm_mappings_sizes[4] = {}; - VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {}; + VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {0}; shaderModuleCreateInfo.instructions = asm_ptrs; shaderModuleCreateInfo.numInstructions = asm_sizes; shaderModuleCreateInfo.mappings = asm_mappings; @@ -645,7 +640,7 @@ void createBufferToTextureShaderModule(VkDevice device, VkShaderModule* blitShad //words start here spirv[5] = 1 << 16; - VkShaderModuleCreateInfo smci = {}; + VkShaderModuleCreateInfo smci = {0}; smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; smci.codeSize = sizeof(uint32_t)*6; smci.pCode = spirv; @@ -800,11 +795,6 @@ void createTextureToTextureShaderModule(VkDevice device, VkShaderModule* blitSha "sig_unlock_score ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;" "\0"; - char* blit_asm_strings[] = - { - (char*)cs_asm_code, (char*)vs_asm_code, (char*)sample_fs_asm_code, 0 - }; - VkRpiAssemblyMappingEXT vertexMappings[] = { //vertex shader uniforms { @@ -902,7 +892,7 @@ void createTextureToTextureShaderModule(VkDevice device, VkShaderModule* blitSha VkRpiAssemblyMappingEXT* asm_mappings[4] = {}; uint32_t asm_mappings_sizes[4] = {}; - VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {}; + VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {0}; shaderModuleCreateInfo.instructions = asm_ptrs; shaderModuleCreateInfo.numInstructions = asm_sizes; shaderModuleCreateInfo.mappings = asm_mappings; @@ -947,7 +937,7 @@ void createTextureToTextureShaderModule(VkDevice device, VkShaderModule* blitSha //words start here spirv[5] = 1 << 16; - VkShaderModuleCreateInfo smci = {}; + VkShaderModuleCreateInfo smci = {0}; smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; smci.codeSize = sizeof(uint32_t)*6; smci.pCode = spirv; @@ -1001,7 +991,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdCopyBufferToImage)( uint32_t pixelBpp = getFormatBpp(img->format); VkBufferView texelBufferView; - VkBufferViewCreateInfo bvci = {}; + VkBufferViewCreateInfo bvci = {0}; bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; bvci.buffer = buf; bvci.format = img->format; @@ -1017,14 +1007,14 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdCopyBufferToImage)( VkPipelineLayout blitPipelineLayout; //create blit descriptor set - VkDescriptorSetAllocateInfo allocInfo = {}; + VkDescriptorSetAllocateInfo allocInfo = {0}; allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; allocInfo.descriptorPool = device->emulDescriptorPool; allocInfo.descriptorSetCount = 1; allocInfo.pSetLayouts = &device->emulBufferDsl; RPIFUNC(vkAllocateDescriptorSets)(device, &allocInfo, &blitDescriptorSet); - VkWriteDescriptorSet writeDescriptorSet = {}; + VkWriteDescriptorSet writeDescriptorSet = {0}; writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writeDescriptorSet.dstSet = blitDescriptorSet; writeDescriptorSet.dstBinding = 0; @@ -1042,7 +1032,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdCopyBufferToImage)( .color = { 1.0f, 0.0f, 1.0f, 1.0f } }; - VkRenderPassBeginInfo renderPassInfo = {}; + VkRenderPassBeginInfo renderPassInfo = {0}; renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; renderPassInfo.renderArea.offset.x = 0; renderPassInfo.renderArea.offset.y = 0; @@ -1057,7 +1047,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdCopyBufferToImage)( RPIFUNC(vkCmdBindPipeline)(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, blitPipeline); - VkViewport vp = {}; + VkViewport vp = {0}; vp.x = 0.0f; vp.y = 0.0f; vp.width = (float)width; @@ -1154,7 +1144,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdBlitImage)( VkPipelineLayout blitPipelineLayout; VkSampler mipSampler; - VkSamplerCreateInfo samplerCI = {}; + VkSamplerCreateInfo samplerCI = {0}; samplerCI.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; samplerCI.magFilter = filter == VK_FILTER_LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; samplerCI.minFilter = filter == VK_FILTER_LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; @@ -1166,9 +1156,8 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdBlitImage)( samplerCI.compareOp = VK_COMPARE_OP_NEVER; samplerCI.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; RPIFUNC(vkCreateSampler)(device, &samplerCI, 0, &mipSampler); - _sampler* s = mipSampler; - VkImageViewCreateInfo view = {}; + VkImageViewCreateInfo view = {0}; view.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; view.viewType = VK_IMAGE_VIEW_TYPE_2D; view.format = srcImg->format; @@ -1181,7 +1170,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdBlitImage)( RPIFUNC(vkCreateImageView)(device, &view, 0, &srcTextureView); //create blit descriptor set - VkDescriptorSetAllocateInfo allocInfo = {}; + VkDescriptorSetAllocateInfo allocInfo = {0}; allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; allocInfo.descriptorPool = device->emulDescriptorPool; allocInfo.descriptorSetCount = 1; @@ -1193,7 +1182,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdBlitImage)( imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; imageInfo.sampler = mipSampler; - VkWriteDescriptorSet writeDescriptorSet = {}; + VkWriteDescriptorSet writeDescriptorSet = {0}; writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writeDescriptorSet.dstSet = blitDescriptorSet; writeDescriptorSet.dstBinding = 0; @@ -1211,7 +1200,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdBlitImage)( .color = { 1.0f, 0.0f, 1.0f, 1.0f } }; - VkRenderPassBeginInfo renderPassInfo = {}; + VkRenderPassBeginInfo renderPassInfo = {0}; renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; renderPassInfo.renderArea.offset.x = 0; renderPassInfo.renderArea.offset.y = 0; @@ -1226,7 +1215,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdBlitImage)( RPIFUNC(vkCmdBindPipeline)(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, blitPipeline); - VkViewport vp = {}; + VkViewport vp = {0}; vp.x = (float)pRegions[c].dstOffsets[0].x; vp.y = (float)pRegions[c].dstOffsets[0].y; vp.width = (float)dstWidth; diff --git a/driver/descriptorSet.c b/driver/descriptorSet.c index add6c40..3b578fe 100644 --- a/driver/descriptorSet.c +++ b/driver/descriptorSet.c @@ -47,6 +47,9 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateDescriptorPool)( case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: texelBufferDescriptorCount += pCreateInfo->pPoolSizes[c].descriptorCount; break; + default: + assert(0); + break; } } @@ -154,6 +157,9 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkAllocateDescriptorSets)( case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: texelBufferDescriptorCount += dsl->bindings[d].descriptorCount; break; + default: + assert(0); + break; } } @@ -219,6 +225,9 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkAllocateDescriptorSets)( ds->texelBufferDescriptors[texelBufferDescriptorCounter].stageFlags = dsl->bindings[d].stageFlags; texelBufferDescriptorCounter += dsl->bindings[d].descriptorCount; break; + default: + assert(0); + break; } } } @@ -326,6 +335,11 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkUpdateDescriptorSets)( } break; } + default: + { + assert(0); + break; + } } } @@ -506,6 +520,8 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateDescriptorUpdateTemplate)( PROFILESTART(RPIFUNC(vkCreateDescriptorUpdateTemplate)); //TODO PROFILEEND(RPIFUNC(vkCreateDescriptorUpdateTemplate)); + + return VK_SUCCESS; } VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkDestroyDescriptorUpdateTemplate)( diff --git a/driver/device.c b/driver/device.c index c1392e2..ec4bb83 100644 --- a/driver/device.c +++ b/driver/device.c @@ -123,10 +123,10 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkEnumerateDeviceExtensionProperties)( return VK_SUCCESS; } - int arraySize = *pPropertyCount; - int elementsWritten = min(numDeviceExtensions, arraySize); + uint32_t arraySize = *pPropertyCount; + uint32_t elementsWritten = min(numDeviceExtensions, arraySize); - for(int c = 0; c < elementsWritten; ++c) + for(uint32_t c = 0; c < elementsWritten; ++c) { pProperties[c] = deviceExtensions[c]; } @@ -199,10 +199,10 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkEnumeratePhysicalDeviceQueueFamilyPerfo return VK_SUCCESS; } - int arraySize = *pCounterCount; - int elementsWritten = min(numPerformanceCounterTypes, arraySize); + uint32_t arraySize = *pCounterCount; + uint32_t elementsWritten = min(numPerformanceCounterTypes, arraySize); - for(int c = 0; c < elementsWritten; ++c) + for(uint32_t c = 0; c < elementsWritten; ++c) { pCounters[c] = performanceCounterTypes[c]; pCounterDescriptions[c] = performanceCounterDescriptions[c]; @@ -260,7 +260,7 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateDevice)( assert(pCreateInfo); //check for enabled extensions - for(int c = 0; c < pCreateInfo->enabledExtensionCount; ++c) + for(uint32_t c = 0; c < pCreateInfo->enabledExtensionCount; ++c) { int findres = findDeviceExtension(pCreateInfo->ppEnabledExtensionNames[c]); if(findres == -1) @@ -276,7 +276,7 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateDevice)( if(requestedFeatures) { - for(int c = 0; c < numFeatures; ++c) + for(uint32_t c = 0; c < numFeatures; ++c) { if(requestedFeatures[c] && !supportedFeatures[c]) { @@ -299,7 +299,7 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateDevice)( (*pDevice)->numEnabledExtensions = 0; - for(int c = 0; c < pCreateInfo->enabledExtensionCount; ++c) + for(uint32_t c = 0; c < pCreateInfo->enabledExtensionCount; ++c) { int findres = findDeviceExtension(pCreateInfo->ppEnabledExtensionNames[c]); if(findres > -1) @@ -311,7 +311,7 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateDevice)( if(requestedFeatures) { - for(int c = 0; c < numFeatures; ++c) + for(uint32_t c = 0; c < numFeatures; ++c) { if(requestedFeatures[c] && !supportedFeatures[c]) { @@ -330,14 +330,14 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateDevice)( //layers ignored per spec //pCreateInfo->enabledLayerCount - for(int c = 0; c < numQueueFamilies; ++c) + for(uint32_t c = 0; c < numQueueFamilies; ++c) { (*pDevice)->queues[c] = 0; } if(pCreateInfo->queueCreateInfoCount > 0) { - for(int c = 0; c < pCreateInfo->queueCreateInfoCount; ++c) + for(uint32_t c = 0; c < pCreateInfo->queueCreateInfoCount; ++c) { (*pDevice)->queues[pCreateInfo->pQueueCreateInfos[c].queueFamilyIndex] = ALLOCATE(sizeof(_queue)*pCreateInfo->pQueueCreateInfos[c].queueCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); @@ -347,17 +347,13 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateDevice)( return VK_ERROR_OUT_OF_HOST_MEMORY; } - for(int d = 0; d < pCreateInfo->pQueueCreateInfos[c].queueCount; ++d) + for(uint32_t d = 0; d < pCreateInfo->pQueueCreateInfos[c].queueCount; ++d) { _queue* q = &(*pDevice)->queues[pCreateInfo->pQueueCreateInfos[c].queueFamilyIndex][d]; q->lastEmitSeqno = 0; q->lastFinishedSeqno = 0; q->dev = *pDevice; - q->seqnoSem = ALLOCATE(sizeof(sem_t), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); - sem_init(q->seqnoSem, 0, 0); - sem_post(q->seqnoSem); - set_loader_magic_value(&q->loaderData); } @@ -430,11 +426,10 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkDestroyDevice)( if(dev) { - for(int c = 0; c < numQueueFamilies; ++c) + for(uint32_t c = 0; c < numQueueFamilies; ++c) { - for(int d = 0; d < dev->numQueues[c]; ++d) + for(uint32_t d = 0; d < dev->numQueues[c]; ++d) { - FREE(dev->queues[d]->seqnoSem); FREE(dev->queues[d]); } } @@ -547,7 +542,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkGetPhysicalDeviceProperties2)( VkPhysicalDeviceDriverPropertiesKHR* ptr = pProperties->pNext; if(ptr->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR) { - ptr->driverID = 0x525049564b; //RPIVK in hex + ptr->driverID = 0x5250564b; //RPVK in hex const char* driverName = "RPi VK"; const char* driverInfo = ""; //TODO maybe version number, git info? strcpy(ptr->driverName, driverName); diff --git a/driver/draw.c b/driver/draw.c index dddc9dd..483d9d8 100644 --- a/driver/draw.c +++ b/driver/draw.c @@ -55,7 +55,7 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) //if(cb->lineWidthDirty) { //Line width - clFit(commandBuffer, &commandBuffer->binCl, V3D21_LINE_WIDTH_length); + clFit(&commandBuffer->binCl, V3D21_LINE_WIDTH_length); clInsertLineWidth(&commandBuffer->binCl, cb->graphicsPipeline->lineWidth); cb->lineWidthDirty = 0; @@ -64,7 +64,7 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) //if(cb->viewportDirty) { //Clip Window - clFit(commandBuffer, &commandBuffer->binCl, V3D21_CLIP_WINDOW_length); + clFit(&commandBuffer->binCl, V3D21_CLIP_WINDOW_length); clInsertClipWindow(&commandBuffer->binCl, vp.width, vp.height, @@ -73,11 +73,11 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) //Vulkan conventions, Y flipped [1...-1] bottom->top //Clipper XY Scaling - clFit(commandBuffer, &commandBuffer->binCl, V3D21_CLIPPER_XY_SCALING_length); + clFit(&commandBuffer->binCl, V3D21_CLIPPER_XY_SCALING_length); clInsertClipperXYScaling(&commandBuffer->binCl, (float)(vp.width) * 0.5f * 16.0f, 1.0f * (float)(vp.height) * 0.5f * 16.0f); //Viewport Offset - clFit(commandBuffer, &commandBuffer->binCl, V3D21_VIEWPORT_OFFSET_length); + clFit(&commandBuffer->binCl, V3D21_VIEWPORT_OFFSET_length); clInsertViewPortOffset(&commandBuffer->binCl, vp.width * 0.5f + vp.x, vp.height * 0.5f + vp.y); cb->viewportDirty = 0; @@ -86,7 +86,7 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) //if(cb->depthBiasDirty || cb->depthBoundsDirty) { //Configuration Bits - clFit(commandBuffer, &commandBuffer->binCl, V3D21_CONFIGURATION_BITS_length); + clFit(&commandBuffer->binCl, V3D21_CONFIGURATION_BITS_length); clInsertConfigurationBits(&commandBuffer->binCl, 1, //earlyz updates enable cb->graphicsPipeline->depthTestEnable, //earlyz enable @@ -102,7 +102,7 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) !(cb->graphicsPipeline->cullMode & VK_CULL_MODE_BACK_BIT), //enable back facing primitives !(cb->graphicsPipeline->cullMode & VK_CULL_MODE_FRONT_BIT)); //enable front facing primitives - clFit(commandBuffer, &commandBuffer->binCl, V3D21_DEPTH_OFFSET_length); + clFit(&commandBuffer->binCl, V3D21_DEPTH_OFFSET_length); float depthBiasConstant = cb->graphicsPipeline->depthBiasConstantFactor; float depthBiasSlope = cb->graphicsPipeline->depthBiasSlopeFactor; @@ -122,7 +122,7 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) //Vulkan conventions, we expect the resulting NDC space Z axis to be in range [0...1] close->far //cb->graphicsPipeline->minDepthBounds; //Clipper Z Scale and Offset - clFit(commandBuffer, &commandBuffer->binCl, V3D21_CLIPPER_Z_SCALE_AND_OFFSET_length); + clFit(&commandBuffer->binCl, V3D21_CLIPPER_Z_SCALE_AND_OFFSET_length); //offset, scale float scale = vp.maxDepth - vp.minDepth; float offset = vp.minDepth; @@ -133,16 +133,16 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) } //Point size - clFit(commandBuffer, &commandBuffer->binCl, V3D21_POINT_SIZE_length); + clFit(&commandBuffer->binCl, V3D21_POINT_SIZE_length); clInsertPointSize(&commandBuffer->binCl, 1.0f); //TODO? //Flat Shade Flags - clFit(commandBuffer, &commandBuffer->binCl, V3D21_FLAT_SHADE_FLAGS_length); + clFit(&commandBuffer->binCl, V3D21_FLAT_SHADE_FLAGS_length); clInsertFlatShadeFlags(&commandBuffer->binCl, 0); //GL Shader State - clFit(commandBuffer, &commandBuffer->binCl, V3D21_GL_SHADER_STATE_length); + clFit(&commandBuffer->binCl, V3D21_GL_SHADER_STATE_length); clInsertShaderState(&commandBuffer->binCl, 0, //shader state record address 0, //extended shader state record @@ -200,7 +200,7 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) }; commandBuffer->shaderRecCount++; - clFit(commandBuffer, &commandBuffer->shaderRecCl, 12 * sizeof(uint32_t) + 104 + 8 * 32); + clFit(&commandBuffer->shaderRecCl, 12 * sizeof(uint32_t) + 104 + 8 * 32); ControlList relocCl = commandBuffer->shaderRecCl; uint32_t attribCount = 0; @@ -237,12 +237,12 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) //number of attribs //3 is the number of type of possible shaders - for(int c = 0; c < (3 + attribCount)*4; ++c) + for(uint32_t c = 0; c < (3 + attribCount)*4; ++c) { clInsertNop(&commandBuffer->shaderRecCl); } - clFit(commandBuffer, &commandBuffer->handlesCl, (3 + 8)*4); + clFit(&commandBuffer->handlesCl, (3 + 8)*4); clInsertShaderRecord(&commandBuffer->shaderRecCl, &relocCl, &commandBuffer->handlesCl, @@ -365,11 +365,11 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) di += mapping.descriptorArrayElement; //emit reloc for texture BO - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, di->imageView->image->boundMem->bo); //emit tex bo reloc index - clFit(commandBuffer, &commandBuffer->uniformsCl, 4); + clFit(&commandBuffer->uniformsCl, 4); clInsertData(&commandBuffer->uniformsCl, 4, &idx); numFragUniformReads++; @@ -384,11 +384,11 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) db += mapping.descriptorArrayElement; //emit reloc for BO - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, db->buffer->boundMem->bo); //emit bo reloc index - clFit(commandBuffer, &commandBuffer->uniformsCl, 4); + clFit(&commandBuffer->uniformsCl, 4); clInsertData(&commandBuffer->uniformsCl, 4, &idx); numFragUniformReads++; @@ -401,11 +401,11 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) dtb += mapping.descriptorArrayElement; //emit reloc for BO - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, dtb->bufferView->buffer->boundMem->bo); //emit bo reloc index - clFit(commandBuffer, &commandBuffer->uniformsCl, 4); + clFit(&commandBuffer->uniformsCl, 4); clInsertData(&commandBuffer->uniformsCl, 4, &idx); numFragUniformReads++; @@ -428,7 +428,7 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) { numFragUniformReads++; - clFit(commandBuffer, &commandBuffer->uniformsCl, 4); + clFit(&commandBuffer->uniformsCl, 4); clInsertData(&commandBuffer->uniformsCl, 4, cb->pushConstantBufferPixel + mapping.resourceOffset); } else if(mapping.mappingType == VK_RPI_ASSEMBLY_MAPPING_TYPE_DESCRIPTOR) @@ -493,7 +493,7 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) numFragUniformReads += size >> 2; //emit tex parameters - clFit(commandBuffer, &commandBuffer->uniformsCl, size); + clFit(&commandBuffer->uniformsCl, size); clInsertData(&commandBuffer->uniformsCl, size, params); } } @@ -517,7 +517,7 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) { numVertUniformReads++; - clFit(commandBuffer, &commandBuffer->uniformsCl, 4); + clFit(&commandBuffer->uniformsCl, 4); clInsertData(&commandBuffer->uniformsCl, 4, cb->pushConstantBufferVertex + mapping.resourceOffset); } else if(mapping.mappingType == VK_RPI_ASSEMBLY_MAPPING_TYPE_DESCRIPTOR) @@ -549,7 +549,7 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) { numCoordUniformReads++; - clFit(commandBuffer, &commandBuffer->uniformsCl, 4); + clFit(&commandBuffer->uniformsCl, 4); clInsertData(&commandBuffer->uniformsCl, 4, cb->pushConstantBufferVertex + mapping.resourceOffset); } else if(mapping.mappingType == VK_RPI_ASSEMBLY_MAPPING_TYPE_DESCRIPTOR) @@ -591,7 +591,7 @@ void RPIFUNC(vkCmdDraw)(VkCommandBuffer commandBuffer, uint32_t vertexCount, uin _commandBuffer* cb = commandBuffer; //Submit draw call: vertex Array Primitives - clFit(commandBuffer, &commandBuffer->binCl, V3D21_VERTEX_ARRAY_PRIMITIVES_length); + clFit(&commandBuffer->binCl, V3D21_VERTEX_ARRAY_PRIMITIVES_length); clInsertVertexArrayPrimitives(&commandBuffer->binCl, firstVertex, vertexCount, getPrimitiveMode(cb->graphicsPipeline->topology)); ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->numDrawCallsSubmitted++; @@ -623,13 +623,13 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdDrawIndexed)( _commandBuffer* cb = commandBuffer; - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, cb->indexBuffer->boundMem->bo); clInsertGEMRelocations(&commandBuffer->binCl, idx, 0); //Submit draw call: vertex Array Primitives - clFit(commandBuffer, &commandBuffer->binCl, V3D21_VERTEX_ARRAY_PRIMITIVES_length); + clFit(&commandBuffer->binCl, V3D21_VERTEX_ARRAY_PRIMITIVES_length); clInsertIndexedPrimitiveList(&commandBuffer->binCl, maxIndex, //max index diff --git a/driver/fifo.c b/driver/fifo.c index 4a7cd1a..374f359 100644 --- a/driver/fifo.c +++ b/driver/fifo.c @@ -1,5 +1,7 @@ #include "fifo.h" +#include + #if defined (__cplusplus) extern "C" { #endif diff --git a/driver/instance.c b/driver/instance.c index 1d05194..7c309e7 100644 --- a/driver/instance.c +++ b/driver/instance.c @@ -5,9 +5,9 @@ #include "declarations.h" #if EXPOSE_DRIVER == 0 - #define RETFUNC(f) if(!strcmp(pName, #f)) return &rpi_##f + #define RETFUNC(f) if(!strcmp(pName, #f)) return (PFN_vkVoidFunction)&rpi_##f #else - #define RETFUNC(f) if(!strcmp(pName, #f)) return &f + #define RETFUNC(f) if(!strcmp(pName, #f)) return (PFN_vkVoidFunction)&f #endif static uint32_t loaderVersion = -1; @@ -24,7 +24,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName) { - if(loaderVersion == -1) + if(loaderVersion == ~0u) { //dealing with legacy ICD loader, as vk_icdNegotiateLoaderICDInterfaceVersion has not been called loaderVersion = 1; @@ -74,10 +74,10 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkEnumerateInstanceExtensionProperties)( return VK_SUCCESS; } - int arraySize = *pPropertyCount; - int elementsWritten = min(numInstanceExtensions, arraySize); + uint32_t arraySize = *pPropertyCount; + uint32_t elementsWritten = min(numInstanceExtensions, arraySize); - for(int c = 0; c < elementsWritten; ++c) + for(uint32_t c = 0; c < elementsWritten; ++c) { pProperties[c] = instanceExtensions[c]; } @@ -131,7 +131,7 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateInstance)( assert(pCreateInfo->ppEnabledExtensionNames); } - for(int c = 0; c < pCreateInfo->enabledExtensionCount; ++c) + for(uint32_t c = 0; c < pCreateInfo->enabledExtensionCount; ++c) { int findres = findInstanceExtension(pCreateInfo->ppEnabledExtensionNames[c]); if(findres > -1) diff --git a/driver/kernelInterface.c b/driver/kernelInterface.c index 2c373e5..0f3146b 100644 --- a/driver/kernelInterface.c +++ b/driver/kernelInterface.c @@ -2,7 +2,7 @@ #include "kernelInterface.h" #include -atomic_int refCounter = 0; +static atomic_int refCounter = 0; int controlFd = 0; //int renderFd = 0; @@ -26,7 +26,7 @@ int openIoctl() } }*/ - ++refCounter; + refCounter++; return 0; } @@ -486,7 +486,7 @@ void vc4_bo_label(int fd, uint32_t bo, const char* name) assert(fd); assert(bo); - char* str = name; + const char* str = name; if(!str) str = ""; struct drm_vc4_label_bo label = { @@ -690,12 +690,12 @@ void vc4_print_hang_state(int fd) fprintf(stderr, "ct0ra0: %u, ct1ra0: %u\n", arg.ct0ra0, arg.ct1ra0); fprintf(stderr, "bpca: %u, bpcs: %u\n", arg.bpca, arg.bpcs); fprintf(stderr, "bpoa: %u, bpos: %u\n", arg.bpoa, arg.bpos); - fprintf(stderr, "vpmbase: %u: %u\n", arg.vpmbase); - fprintf(stderr, "dbge: %u: %u\n", arg.dbge); - fprintf(stderr, "fdbgo: %u: %u\n", arg.fdbgo); - fprintf(stderr, "fdbgb: %u: %u\n", arg.fdbgb); - fprintf(stderr, "fdbgr: %u: %u\n", arg.fdbgr); - fprintf(stderr, "fdbgs: %u: %u\n", arg.fdbgs); - fprintf(stderr, "errstat: %u: %u\n", arg.errstat); + fprintf(stderr, "vpmbase: %u\n", arg.vpmbase); + fprintf(stderr, "dbge: %u\n", arg.dbge); + fprintf(stderr, "fdbgo: %u\n", arg.fdbgo); + fprintf(stderr, "fdbgb: %u\n", arg.fdbgb); + fprintf(stderr, "fdbgr: %u\n", arg.fdbgr); + fprintf(stderr, "fdbgs: %u\n", arg.fdbgs); + fprintf(stderr, "errstat: %u\n", arg.errstat); } } diff --git a/driver/memory.c b/driver/memory.c index a2ecf33..20d00a6 100644 --- a/driver/memory.c +++ b/driver/memory.c @@ -41,20 +41,20 @@ void RPIFUNC(vkGetPhysicalDeviceMemoryProperties)(VkPhysicalDevice physicalDevic //printf("%i\n", amount); //all heaps share the same memory - for(int c = 0; c < numMemoryHeaps; ++c) + for(uint32_t c = 0; c < numMemoryHeaps; ++c) { memoryHeaps[c].size = amount * 1000; //kB to B } } pMemoryProperties->memoryTypeCount = numMemoryTypes; - for(int c = 0; c < numMemoryTypes; ++c) + for(uint32_t c = 0; c < numMemoryTypes; ++c) { pMemoryProperties->memoryTypes[c] = memoryTypes[c]; } pMemoryProperties->memoryHeapCount = numMemoryHeaps; - for(int c = 0; c < numMemoryHeaps; ++c) + for(uint32_t c = 0; c < numMemoryHeaps; ++c) { pMemoryProperties->memoryHeaps[c] = memoryHeaps[c]; } diff --git a/driver/modeset.c b/driver/modeset.c index 5e7f3ee..c2c159f 100644 --- a/driver/modeset.c +++ b/driver/modeset.c @@ -87,7 +87,7 @@ void modeset_enum_displays(int fd, uint32_t* numDisplays, modeset_display* displ uint32_t tmpNumDisplays = 0; modeset_display tmpDisplays[16]; - for(uint32_t c = 0; c < resPtr->count_connectors; ++c) + for(int c = 0; c < resPtr->count_connectors; ++c) { drmModeConnectorPtr connPtr = drmModeGetConnector(fd, resPtr->connectors[c]); @@ -138,7 +138,7 @@ void modeset_enum_modes_for_display(int fd, uint32_t display, uint32_t* numModes uint32_t tmpNumModes = 0; modeset_display_mode tmpModes[1024]; - for(uint32_t c = 0; c < connPtr->count_modes; ++c) + for(int c = 0; c < connPtr->count_modes; ++c) { uint32_t found = 0; for(uint32_t d = 0; d < tmpNumModes; ++d) @@ -296,7 +296,7 @@ void modeset_create_surface_for_mode(int fd, uint32_t display, uint32_t mode, mo // TODO if we were to output to multiple displays, we'd need to make sure we don't use a CRTC // that we'd be using to drive the other screen - for(uint32_t c = 0; c < connPtr->count_encoders; ++c) + for(int c = 0; c < connPtr->count_encoders; ++c) { drmModeEncoderPtr encPtr = drmModeGetEncoder(fd, connPtr->encoders[c]); @@ -526,7 +526,7 @@ void modeset_debug_print(int fd) printf("res max width %i height %i\n", resPtr->max_width, resPtr->max_height); printf("\ncrtc count %i\n", resPtr->count_crtcs); - for(uint32_t c = 0; c < resPtr->count_crtcs; ++c) + for(int c = 0; c < resPtr->count_crtcs; ++c) { drmModeCrtcPtr tmpCrtcPtr = drmModeGetCrtc(fd, resPtr->crtcs[c]); printf("crtc id %i, buffer id %i\n", tmpCrtcPtr->crtc_id, tmpCrtcPtr->buffer_id); @@ -534,7 +534,7 @@ void modeset_debug_print(int fd) } printf("\nfb count %i\n", resPtr->count_fbs); - for(uint32_t c = 0; c < resPtr->count_fbs; ++c) + for(int c = 0; c < resPtr->count_fbs; ++c) { drmModeFBPtr tmpFBptr = drmModeGetFB(fd, resPtr->fbs[c]); printf("fb id %i, handle %i\n", tmpFBptr->fb_id, tmpFBptr->handle); @@ -542,7 +542,7 @@ void modeset_debug_print(int fd) } printf("\nencoder count %i\n", resPtr->count_encoders); - for(uint32_t c = 0; c < resPtr->count_encoders; ++c) + for(int c = 0; c < resPtr->count_encoders; ++c) { drmModeEncoderPtr tmpEncoderPtr = drmModeGetEncoder(fd, resPtr->encoders[c]); printf("encoder id %i, crtc id %i\n", tmpEncoderPtr->encoder_id, tmpEncoderPtr->crtc_id); @@ -570,7 +570,7 @@ void modeset_debug_print(int fd) } printf("\nconnector count %i\n", resPtr->count_connectors); - for(uint32_t c = 0; c < resPtr->count_connectors; ++c) + for(int c = 0; c < resPtr->count_connectors; ++c) { drmModeConnectorPtr tmpConnPtr = drmModeGetConnector(fd, resPtr->connectors[c]); printf("connector id %i, encoder id %i\n", tmpConnPtr->connector_id, tmpConnPtr->encoder_id); diff --git a/driver/pipeline.c b/driver/pipeline.c index 665cca6..ef0074a 100644 --- a/driver/pipeline.c +++ b/driver/pipeline.c @@ -29,6 +29,7 @@ void RPIFUNC(vkCmdBindPipeline)(VkCommandBuffer commandBuffer, VkPipelineBindPoi PROFILEEND(RPIFUNC(vkCmdBindPipeline)); } +/** //multiple attachments void patchShaderDepthStencilBlending(uint64_t** instructions, uint32_t* size, const VkPipelineDepthStencilStateCreateInfo* dsi, const VkPipelineColorBlendAttachmentState* bas, const VkAllocationCallbacks* pAllocator) { @@ -176,6 +177,7 @@ void patchShaderDepthStencilBlending(uint64_t** instructions, uint32_t* size, co *instructions = tmp; *size = newSize; } +/**/ /* * https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateGraphicsPipelines @@ -196,7 +198,7 @@ VkResult RPIFUNC(vkCreateGraphicsPipelines)(VkDevice device, VkPipelineCache pip //TODO flags - for(int c = 0; c < createInfoCount; ++c) + for(uint32_t c = 0; c < createInfoCount; ++c) { _pipeline* pip = ALLOCATE(sizeof(_pipeline), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if(!pip) @@ -208,7 +210,7 @@ VkResult RPIFUNC(vkCreateGraphicsPipelines)(VkDevice device, VkPipelineCache pip memset(pip->names, 0, sizeof(char*)*6); memset(pip->modules, 0, sizeof(_shaderModule*)*6); - for(int d = 0; d < pCreateInfos[c].stageCount; ++d) + for(uint32_t d = 0; d < pCreateInfos[c].stageCount; ++d) { uint32_t idx = ulog2(pCreateInfos[c].pStages[d].stage); pip->modules[idx] = pCreateInfos[c].pStages[d].module; diff --git a/driver/profiler.c b/driver/profiler.c index 3bbc0da..7032380 100644 --- a/driver/profiler.c +++ b/driver/profiler.c @@ -124,7 +124,7 @@ void profilePrintResults() int32_t numFunctions = 0; //insertion sort, linear search - for(int32_t c = 0; c < globalProfiler->funcDatabase.maxData; ++c) + for(uint32_t c = 0; c < globalProfiler->funcDatabase.maxData; ++c) { if(!globalProfiler->funcDatabase.elements[c].data) { diff --git a/driver/renderpass.c b/driver/renderpass.c index ddfd761..7ccaf77 100644 --- a/driver/renderpass.c +++ b/driver/renderpass.c @@ -131,7 +131,7 @@ void RPIFUNC(vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRender } - clFit(commandBuffer, &commandBuffer->binCl, sizeof(CLMarker)); + clFit(&commandBuffer->binCl, sizeof(CLMarker)); clInsertNewCLMarker(&commandBuffer->binCl, &cb->handlesCl, &cb->shaderRecCl, cb->shaderRecCount, &cb->uniformsCl); CLMarker* currMarker = getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset); currMarker->writeImage = writeImage; @@ -199,37 +199,37 @@ void RPIFUNC(vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRender if(writeImage) { - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, writeImage->boundMem->bo); } if(readImage) { - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, readImage->boundMem->bo); } if(writeDepthStencilImage) { - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, writeDepthStencilImage->boundMem->bo); } if(readDepthStencilImage) { - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, readDepthStencilImage->boundMem->bo); } if(writeMSAAimage) { - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, writeMSAAimage->boundMem->bo); } if(writeMSAAdepthStencilImage) { - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, writeMSAAdepthStencilImage->boundMem->bo); } @@ -264,7 +264,7 @@ void RPIFUNC(vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRender width = width < 4 ? 4 : width; } - clFit(commandBuffer, &commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length); + clFit(&commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length); clInsertTileBinningModeConfiguration(&commandBuffer->binCl, 0, //double buffer in non ms mode 0, //tile allocation block size @@ -281,7 +281,7 @@ void RPIFUNC(vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRender //which are what is used when a primitive is binned to a tile to //figure out what new state packets need to be written to that tile's //command list. - clFit(commandBuffer, &commandBuffer->binCl, V3D21_START_TILE_BINNING_length); + clFit(&commandBuffer->binCl, V3D21_START_TILE_BINNING_length); clInsertStartTileBinning(&commandBuffer->binCl); ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->perfmonID = cb->perfmonID; @@ -311,9 +311,9 @@ void RPIFUNC(vkCmdEndRenderPass)(VkCommandBuffer commandBuffer) //until the FLUSH completes. //The FLUSH caps all of our bin lists with a //VC4_PACKET_RETURN. - clFit(commandBuffer, &cb->binCl, V3D21_INCREMENT_SEMAPHORE_length); + clFit(&cb->binCl, V3D21_INCREMENT_SEMAPHORE_length); clInsertIncrementSemaphore(&cb->binCl); - clFit(commandBuffer, &cb->binCl, V3D21_FLUSH_length); + clFit(&cb->binCl, V3D21_FLUSH_length); clInsertFlush(&cb->binCl); cb->currRenderPass = 0; @@ -362,7 +362,7 @@ VkResult RPIFUNC(vkCreateRenderPass)(VkDevice device, const VkRenderPassCreateIn return VK_ERROR_OUT_OF_HOST_MEMORY; } - for(int c = 0; c < rp->numSubpasses; ++c) + for(uint32_t c = 0; c < rp->numSubpasses; ++c) { rp->subpasses[c].flags = pCreateInfo->pSubpasses[c].flags; rp->subpasses[c].pipelineBindPoint = pCreateInfo->pSubpasses[c].pipelineBindPoint; @@ -479,7 +479,7 @@ void RPIFUNC(vkDestroyRenderPass)(VkDevice device, VkRenderPass renderPass, cons { FREE(rp->subpassDependencies); - for(int c = 0; c < rp->numSubpasses; ++c) + for(uint32_t c = 0; c < rp->numSubpasses; ++c) { FREE(rp->subpasses[c].pInputAttachments); FREE(rp->subpasses[c].pColorAttachments); diff --git a/driver/stateChange.c b/driver/stateChange.c index 054a35f..d40f761 100644 --- a/driver/stateChange.c +++ b/driver/stateChange.c @@ -203,7 +203,7 @@ void createClearShaderModule(VkDevice device, VkShaderModule* blitShaderModule, VkRpiAssemblyMappingEXT* asm_mappings[4] = {}; uint32_t asm_mappings_sizes[4] = {}; - VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {}; + VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {0}; shaderModuleCreateInfo.instructions = asm_ptrs; shaderModuleCreateInfo.numInstructions = asm_sizes; shaderModuleCreateInfo.mappings = asm_mappings; @@ -251,7 +251,7 @@ void createClearShaderModule(VkDevice device, VkShaderModule* blitShaderModule, //words start here spirv[5] = 1 << 16; - VkShaderModuleCreateInfo smci = {}; + VkShaderModuleCreateInfo smci = {0}; smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; smci.codeSize = sizeof(uint32_t)*6; smci.pCode = spirv; @@ -296,32 +296,32 @@ void createClearPipeline(VkDevice device, VkPipelineDepthStencilStateCreateInfo* vertexInputAttributeDescription[0].format = VK_FORMAT_R32G32_SFLOAT; } - VkPipelineVertexInputStateCreateInfo vertexInputInfo = {}; + VkPipelineVertexInputStateCreateInfo vertexInputInfo = {0}; vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; vertexInputInfo.vertexAttributeDescriptionCount = 1; vertexInputInfo.pVertexAttributeDescriptions = vertexInputAttributeDescription; vertexInputInfo.vertexBindingDescriptionCount = 1; vertexInputInfo.pVertexBindingDescriptions = &vertexInputBindingDescription; - VkPipelineInputAssemblyStateCreateInfo pipelineIACreateInfo = {}; + VkPipelineInputAssemblyStateCreateInfo pipelineIACreateInfo = {0}; pipelineIACreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; pipelineIACreateInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - VkPipelineRasterizationStateCreateInfo rastCreateInfo = {}; + VkPipelineRasterizationStateCreateInfo rastCreateInfo = {0}; rastCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; rastCreateInfo.polygonMode = VK_POLYGON_MODE_FILL; rastCreateInfo.cullMode = VK_CULL_MODE_NONE; rastCreateInfo.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; rastCreateInfo.lineWidth = 1.0f; - VkPipelineMultisampleStateCreateInfo pipelineMSCreateInfo = {}; + VkPipelineMultisampleStateCreateInfo pipelineMSCreateInfo = {0}; pipelineMSCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; - VkPipelineColorBlendAttachmentState blendAttachState = {}; + VkPipelineColorBlendAttachmentState blendAttachState = {0}; blendAttachState.colorWriteMask = 0xf; blendAttachState.blendEnable = false; - VkPipelineColorBlendStateCreateInfo blendCreateInfo = {}; + VkPipelineColorBlendStateCreateInfo blendCreateInfo = {0}; blendCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; blendCreateInfo.attachmentCount = 1; blendCreateInfo.pAttachments = &blendAttachState; @@ -347,7 +347,7 @@ void createClearPipeline(VkDevice device, VkPipelineDepthStencilStateCreateInfo* shaderStageCreateInfo[1].module = blitShaderModule; shaderStageCreateInfo[1].pName = "main"; - VkPipelineLayoutCreateInfo pipelineLayoutCI = {}; + VkPipelineLayoutCreateInfo pipelineLayoutCI = {0}; pipelineLayoutCI.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipelineLayoutCI.setLayoutCount = 1; pipelineLayoutCI.pSetLayouts = &blitDsl; @@ -357,17 +357,17 @@ void createClearPipeline(VkDevice device, VkPipelineDepthStencilStateCreateInfo* VkDynamicState dynState = VK_DYNAMIC_STATE_VIEWPORT; - VkPipelineDynamicStateCreateInfo pdsci = {}; + VkPipelineDynamicStateCreateInfo pdsci = {0}; pdsci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; pdsci.dynamicStateCount = 1; pdsci.pDynamicStates = &dynState; - VkPipelineViewportStateCreateInfo pvsci = {}; + VkPipelineViewportStateCreateInfo pvsci = {0}; pvsci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; pvsci.viewportCount = 0; pvsci.scissorCount = 0; - VkGraphicsPipelineCreateInfo pipelineInfo = {}; + VkGraphicsPipelineCreateInfo pipelineInfo = {0}; pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipelineInfo.stageCount = 2; pipelineInfo.pStages = &shaderStageCreateInfo[0]; @@ -383,7 +383,7 @@ void createClearPipeline(VkDevice device, VkPipelineDepthStencilStateCreateInfo* pipelineInfo.pDepthStencilState = dsState; pipelineInfo.layout = *blitPipelineLayout; - VkResult res = RPIFUNC(vkCreateGraphicsPipelines)(device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, blitPipeline); + RPIFUNC(vkCreateGraphicsPipelines)(device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, blitPipeline); } void createClearDescriptorSetLayouts(VkDevice device, VkDescriptorSetLayout* bufferDsl) @@ -391,7 +391,7 @@ void createClearDescriptorSetLayouts(VkDevice device, VkDescriptorSetLayout* buf assert(device); assert(bufferDsl); - VkDescriptorSetLayoutCreateInfo descriptorLayoutCI = {}; + VkDescriptorSetLayoutCreateInfo descriptorLayoutCI = {0}; descriptorLayoutCI.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; descriptorLayoutCI.bindingCount = 0; descriptorLayoutCI.pBindings = 0; @@ -463,7 +463,7 @@ void RPIFUNC(vkCmdBindVertexBuffers)(VkCommandBuffer commandBuffer, uint32_t fir _commandBuffer* cb = commandBuffer; - for(int c = 0; c < bindingCount; ++c) + for(uint32_t c = 0; c < bindingCount; ++c) { cb->vertexBuffers[firstBinding + c] = pBuffers[c]; cb->vertexBufferOffsets[firstBinding + c] = pOffsets[c]; @@ -511,16 +511,16 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearColorImage)( assert(i->usageBits & VK_IMAGE_USAGE_TRANSFER_DST_BIT); { //Simplest case: just submit a job to clear the image - clFit(commandBuffer, &commandBuffer->binCl, sizeof(CLMarker)); + clFit(&commandBuffer->binCl, sizeof(CLMarker)); clInsertNewCLMarker(&commandBuffer->binCl, &commandBuffer->handlesCl, &commandBuffer->shaderRecCl, commandBuffer->shaderRecCount, &commandBuffer->uniformsCl); ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->writeImage = i; //insert reloc for render target - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->handlesBufOffset + commandBuffer->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->handlesSize, i->boundMem->bo); - clFit(commandBuffer, &commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length); + clFit(&commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length); clInsertTileBinningModeConfiguration(&commandBuffer->binCl, 0, //double buffer in non ms mode 0, //tile allocation block size @@ -537,7 +537,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearColorImage)( //which are what is used when a primitive is binned to a tile to //figure out what new state packets need to be written to that tile's //command list. - clFit(commandBuffer, &commandBuffer->binCl, V3D21_START_TILE_BINNING_length); + clFit(&commandBuffer->binCl, V3D21_START_TILE_BINNING_length); clInsertStartTileBinning(&commandBuffer->binCl); //Increment the semaphore indicating that binning is done and @@ -545,9 +545,9 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearColorImage)( //until the FLUSH completes. //The FLUSH caps all of our bin lists with a //VC4_PACKET_RETURN. - clFit(commandBuffer, &commandBuffer->binCl, V3D21_INCREMENT_SEMAPHORE_length); + clFit(&commandBuffer->binCl, V3D21_INCREMENT_SEMAPHORE_length); clInsertIncrementSemaphore(&commandBuffer->binCl); - clFit(commandBuffer, &commandBuffer->binCl, V3D21_FLUSH_length); + clFit(&commandBuffer->binCl, V3D21_FLUSH_length); clInsertFlush(&commandBuffer->binCl); ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->clearColor[0] = ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->clearColor[1] = packVec4IntoABGR8(pColor->float32); @@ -595,16 +595,16 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearDepthStencilImage)( assert(i->usageBits & VK_IMAGE_USAGE_TRANSFER_DST_BIT); { //Simplest case: just submit a job to clear the image - clFit(commandBuffer, &commandBuffer->binCl, sizeof(CLMarker)); + clFit(&commandBuffer->binCl, sizeof(CLMarker)); clInsertNewCLMarker(&commandBuffer->binCl, &commandBuffer->handlesCl, &commandBuffer->shaderRecCl, commandBuffer->shaderRecCount, &commandBuffer->uniformsCl); ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->writeDepthStencilImage = i; //insert reloc for render target - clFit(commandBuffer, &commandBuffer->handlesCl, 4); + clFit(&commandBuffer->handlesCl, 4); clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->handlesBufOffset + commandBuffer->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->handlesSize, i->boundMem->bo); - clFit(commandBuffer, &commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length); + clFit(&commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length); clInsertTileBinningModeConfiguration(&commandBuffer->binCl, 0, //double buffer in non ms mode 0, //tile allocation block size @@ -621,7 +621,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearDepthStencilImage)( //which are what is used when a primitive is binned to a tile to //figure out what new state packets need to be written to that tile's //command list. - clFit(commandBuffer, &commandBuffer->binCl, V3D21_START_TILE_BINNING_length); + clFit(&commandBuffer->binCl, V3D21_START_TILE_BINNING_length); clInsertStartTileBinning(&commandBuffer->binCl); //Increment the semaphore indicating that binning is done and @@ -629,9 +629,9 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearDepthStencilImage)( //until the FLUSH completes. //The FLUSH caps all of our bin lists with a //VC4_PACKET_RETURN. - clFit(commandBuffer, &commandBuffer->binCl, V3D21_INCREMENT_SEMAPHORE_length); + clFit(&commandBuffer->binCl, V3D21_INCREMENT_SEMAPHORE_length); clInsertIncrementSemaphore(&commandBuffer->binCl); - clFit(commandBuffer, &commandBuffer->binCl, V3D21_FLUSH_length); + clFit(&commandBuffer->binCl, V3D21_FLUSH_length); clInsertFlush(&commandBuffer->binCl); ((CLMarker*)getCPAptrFromOffset(commandBuffer->binCl.CPA, commandBuffer->binCl.currMarkerOffset))->clearDepth = (uint32_t)(pDepthStencil->depth * 0xffffff) & 0xffffff; @@ -708,7 +708,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearAttachments)( VkPipeline blitPipeline; VkPipelineLayout blitPipelineLayout; - VkPipelineDepthStencilStateCreateInfo dsci = {}; + VkPipelineDepthStencilStateCreateInfo dsci = {0}; dsci.depthCompareOp = VK_COMPARE_OP_ALWAYS; dsci.depthTestEnable = 1; dsci.depthWriteEnable = clearDepth; @@ -748,7 +748,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearAttachments)( for(uint32_t d = 0; d < rectCount; ++d) { - VkViewport vp = {}; + VkViewport vp = {0}; vp.x = pRects[d].rect.offset.x; vp.y = pRects[d].rect.offset.y; vp.width = pRects[d].rect.extent.width; diff --git a/driver/sync.c b/driver/sync.c index 37b5ed1..e601eb8 100644 --- a/driver/sync.c +++ b/driver/sync.c @@ -179,17 +179,17 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdPipelineBarrier)( //VK_IMAGE_LAYOUT_PRESENT_SRC_KHR //VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR - for(int c = 0; c < memoryBarrierCount; ++c) + for(uint32_t c = 0; c < memoryBarrierCount; ++c) { //TODO } - for(int c = 0; c < bufferMemoryBarrierCount; ++c) + for(uint32_t c = 0; c < bufferMemoryBarrierCount; ++c) { //TODO } - for(int c = 0; c < imageMemoryBarrierCount; ++c) + for(uint32_t c = 0; c < imageMemoryBarrierCount; ++c) { _image* i = pImageMemoryBarriers[c].image; @@ -217,9 +217,9 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkDeviceWaitIdle)( assert(device); - for(int c = 0; c < numQueueFamilies; ++c) + for(uint32_t c = 0; c < numQueueFamilies; ++c) { - for(int d = 0; d < device->numQueues[c]; ++d) + for(uint32_t d = 0; d < device->numQueues[c]; ++d) { uint64_t lastFinishedSeqno; uint64_t timeout = WAIT_TIMEOUT_INFINITE; diff --git a/driver/wsi.c b/driver/wsi.c index 76a3ee9..e59d25a 100644 --- a/driver/wsi.c +++ b/driver/wsi.c @@ -31,10 +31,10 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkGetPhysicalDeviceDisplayPropertiesKHR)( return VK_SUCCESS; } - int arraySize = *pPropertyCount; - int elementsWritten = min(numDisplays, arraySize); + uint32_t arraySize = *pPropertyCount; + uint32_t elementsWritten = min(numDisplays, arraySize); - for(int c = 0; c < elementsWritten; ++c) + for(uint32_t c = 0; c < elementsWritten; ++c) { pProperties[c].display = displays[c].connectorID; //fprintf(stderr, "display id %i\n", pProperties[c].display ); @@ -83,10 +83,10 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkGetDisplayModePropertiesKHR)( return VK_SUCCESS; } - int arraySize = *pPropertyCount; - int elementsWritten = min(numModes, arraySize); + uint32_t arraySize = *pPropertyCount; + uint32_t elementsWritten = min(numModes, arraySize); - for(int c = 0; c < elementsWritten; ++c) + for(uint32_t c = 0; c < elementsWritten; ++c) { _displayMode mode = { modes[c].connectorID, modes[c].modeID }; memcpy(&pProperties[c].displayMode, &mode, sizeof(_displayMode)); @@ -127,6 +127,8 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateDisplayPlaneSurfaceKHR)( *pSurface = surface; PROFILEEND(RPIFUNC(vkCreateDisplayPlaneSurfaceKHR)); + + return VK_SUCCESS; } /* @@ -281,10 +283,10 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkGetPhysicalDeviceSurfacePresentModesKHR return VK_SUCCESS; } - int arraySize = *pPresentModeCount; - int elementsWritten = min(numSupportedPresentModes, arraySize); + uint32_t arraySize = *pPresentModeCount; + uint32_t elementsWritten = min(numSupportedPresentModes, arraySize); - for(int c = 0; c < elementsWritten; ++c) + for(uint32_t c = 0; c < elementsWritten; ++c) { pPresentModes[c] = supportedPresentModes[c]; } @@ -345,11 +347,11 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateSwapchainKHR)( s->numImages = pCreateInfo->minImageCount; s->surface = pCreateInfo->surface; - for(int c = 0; c < pCreateInfo->minImageCount; ++c) + for(uint32_t c = 0; c < pCreateInfo->minImageCount; ++c) { s->inFlight[c] = 0; - VkImageCreateInfo imageCreateInfo = {}; + VkImageCreateInfo imageCreateInfo = {0}; imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imageCreateInfo.imageType = VK_IMAGE_TYPE_2D; imageCreateInfo.format = pCreateInfo->imageFormat; @@ -385,7 +387,7 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateSwapchainKHR)( VkMemoryAllocateInfo ai; ai.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ai.allocationSize = mr.size; - for(int d = 0; d < numMemoryTypes; ++d) + for(uint32_t d = 0; d < numMemoryTypes; ++d) { if(memoryTypes[d].propertyFlags == mr.memoryTypeBits) { @@ -437,10 +439,10 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkGetSwapchainImagesKHR)( return VK_SUCCESS; } - int arraySize = *pSwapchainImageCount; - int elementsWritten = min(s->numImages, arraySize); + uint32_t arraySize = *pSwapchainImageCount; + uint32_t elementsWritten = min(s->numImages, arraySize); - for(int c = 0; c < elementsWritten; ++c) + for(uint32_t c = 0; c < elementsWritten; ++c) { pSwapchainImages[c] = &s->images[c]; } @@ -555,12 +557,12 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkQueuePresentKHR)( assert(pPresentInfo); //wait for semaphore in present info set by submit ioctl to make sure cls are flushed - for(int c = 0; c < pPresentInfo->waitSemaphoreCount; ++c) + for(uint32_t c = 0; c < pPresentInfo->waitSemaphoreCount; ++c) { sem_wait((sem_t*)pPresentInfo->pWaitSemaphores[c]); } - for(int c = 0; c < pPresentInfo->swapchainCount; ++c) + for(uint32_t c = 0; c < pPresentInfo->swapchainCount; ++c) { _swapchain* s = pPresentInfo->pSwapchains[c]; modeset_present(controlFd, &s->images[pPresentInfo->pImageIndices[c]], s->surface, queue->lastEmitSeqno); @@ -595,7 +597,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkDestroySwapchainKHR)( if(s) { - for(int c = 0; c < s->numImages; ++c) + for(uint32_t c = 0; c < s->numImages; ++c) { RPIFUNC(vkFreeMemory)(device, s->images[c].boundMem, 0); modeset_destroy_fb(controlFd, &s->images[c]);