From 22fc702270398ba9c94f147defe94f97e1befb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrea=20Palmat=C3=A8?= Date: Mon, 11 May 2026 20:09:25 +0200 Subject: [PATCH] ogles2_vk: fix proc-addr ABI, SPIR-V endianness, varying linkage, VkFormat 37, VMA limits --- loader/Makefile | 1 + ogles2_icd/Makefile | 1 + ogles2_icd/Makefile.cross | 3 +- ogles2_icd/include/ogles2vk_internal.h | 6 + ogles2_icd/src/ogles2vk_cmdbuf.c | 8 +- ogles2_icd/src/ogles2vk_exec.c | 171 ++++++++++++++----------- ogles2_icd/src/ogles2vk_main.c | 24 ++++ ogles2_icd/src/ogles2vk_shader.c | 12 +- ogles2_icd/src/ogles2vk_spirv2glsl.c | 50 ++++++++ software_icd/Makefile | 1 + software_icd/Makefile.cross | 2 +- software_icd/include/swvk_internal.h | 6 + software_icd/src/swvk_cmdbuf.c | 24 ++-- software_icd/src/swvk_descriptor.c | 32 ++--- software_icd/src/swvk_device.c | 4 +- software_icd/src/swvk_draw.c | 42 +++--- software_icd/src/swvk_instance.c | 6 +- software_icd/src/swvk_main.c | 8 +- software_icd/src/swvk_memory.c | 4 +- software_icd/src/swvk_pipeline.c | 6 - software_icd/src/swvk_spirv.c | 16 +-- software_icd/src/swvk_wsi.c | 10 +- 22 files changed, 270 insertions(+), 167 deletions(-) diff --git a/loader/Makefile b/loader/Makefile index 5d87db3..49d2a6e 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -8,6 +8,7 @@ CC = ppc-amigaos-gcc CFLAGS = -mcrt=newlib -O2 -Wall -Iinclude -Iinclude/include_h \ -D__NOLIBBASE__ -D__NOGLOBALIFACE__ LDFLAGS = -mcrt=newlib -nostartfiles +DEBUG := SOURCES = src/loader_main.c src/loader_dispatch.c src/loader_icd.c src/loader_wsi.c TARGET = ../build/vulkan.library diff --git a/ogles2_icd/Makefile b/ogles2_icd/Makefile index f924a36..81c6f9c 100644 --- a/ogles2_icd/Makefile +++ b/ogles2_icd/Makefile @@ -10,6 +10,7 @@ CC = ppc-amigaos-gcc CFLAGS = -mcrt=newlib -O2 -Wall \ -D__NOLIBBASE__ -D__NOGLOBALIFACE__ LDFLAGS = -mcrt=newlib -nostartfiles +DEBUG := TARGET = ../build/ogles2_vk.library diff --git a/ogles2_icd/Makefile.cross b/ogles2_icd/Makefile.cross index 5ec46f3..f9a7160 100644 --- a/ogles2_icd/Makefile.cross +++ b/ogles2_icd/Makefile.cross @@ -9,6 +9,7 @@ CFLAGS = -mcrt=newlib -O2 -mstrict-align $(DEBUG) -Iinclude -Wall \ -D__NOLIBBASE__ -D__NOGLOBALIFACE__ LDFLAGS = -mcrt=newlib -nostartfiles DEBUG := + SDK = /usr/ppc-amigaos/SDK/include/include_h SPVC_DIR = external/spirv-cross SPVC_SRCS = spirv_cfg.cpp spirv_cross_parsed_ir.cpp spirv_cross.cpp \ @@ -96,6 +97,6 @@ $(TARGET): clean: - rm -f build/swvk_*.o build/software_vk.library + rm -f build/* diff --git a/ogles2_icd/include/ogles2vk_internal.h b/ogles2_icd/include/ogles2vk_internal.h index bdfef74..2a1b97c 100644 --- a/ogles2_icd/include/ogles2vk_internal.h +++ b/ogles2_icd/include/ogles2vk_internal.h @@ -14,6 +14,12 @@ #include #include +#ifdef DEBUG +#define D(x) IExec->DebugPrintF x +#else +#define D(x) do {} while(0) +#endif + /*------------------------------------------------------------------------ ** Version info **----------------------------------------------------------------------*/ diff --git a/ogles2_icd/src/ogles2vk_cmdbuf.c b/ogles2_icd/src/ogles2vk_cmdbuf.c index 97f0f31..0aef822 100644 --- a/ogles2_icd/src/ogles2vk_cmdbuf.c +++ b/ogles2_icd/src/ogles2vk_cmdbuf.c @@ -24,8 +24,8 @@ static OGLES2VKCommand *ogles2vk_CmdAppend(OGLES2VKCommandBuffer *cmd, OGLES2VKC { if (cmd->commandCount >= OGLES2VK_MAX_COMMANDS) { - IExec->DebugPrintF("[ogles2_vk] WARNING: command buffer full (%u/%u)\n", - (unsigned)cmd->commandCount, (unsigned)OGLES2VK_MAX_COMMANDS); + D(("[ogles2_vk] WARNING: command buffer full (%u/%u)\n", + (unsigned)cmd->commandCount, (unsigned)OGLES2VK_MAX_COMMANDS)); return NULL; } @@ -167,8 +167,8 @@ VkResult ogles2vk_EndCommandBuffer(VkCommandBuffer commandBuffer) OGLES2VKCommandBuffer *cmd = (OGLES2VKCommandBuffer *)commandBuffer; cmd->recording = 0; - IExec->DebugPrintF("[ogles2_vk] Command buffer recorded: %lu commands\n", - (unsigned long)cmd->commandCount); + D(("[ogles2_vk] Command buffer recorded: %lu commands\n", + (unsigned long)cmd->commandCount)); return VK_SUCCESS; } diff --git a/ogles2_icd/src/ogles2vk_exec.c b/ogles2_icd/src/ogles2vk_exec.c index a531241..d36a9d5 100644 --- a/ogles2_icd/src/ogles2vk_exec.c +++ b/ogles2_icd/src/ogles2vk_exec.c @@ -284,7 +284,13 @@ int ogles2vk_InitOGLES2Context(OGLES2VKDevice *dev, void *window) { if (!dev || !IOGLES2 || !window) { - IExec->DebugPrintF("[ogles2_vk] InitOGLES2: missing dev/IOGLES2/window\n"); + /* Pinpoint which dependency is missing — the previous catch-all + ** message hid whether IOGLES2 failed to load or whether the surface + ** never received a window handle. */ + D(("[ogles2_vk] InitOGLES2 missing: dev=0x%08lx IOGLES2=0x%08lx window=0x%08lx\n", + (unsigned long)(uintptr_t)dev, + (unsigned long)(uintptr_t)IOGLES2, + (unsigned long)(uintptr_t)window)); return 0; } @@ -303,8 +309,8 @@ int ogles2vk_InitOGLES2Context(OGLES2VKDevice *dev, void *window) void *ctx = IOGLES2->aglCreateContext2((uint32 *)&errCode, ctxTags); if (!ctx) { - IExec->DebugPrintF("[ogles2_vk] aglCreateContext2 failed (err=%lu)\n", - (unsigned long)errCode); + D(("[ogles2_vk] aglCreateContext2 failed (err=%lu)\n", + (unsigned long)errCode)); return 0; } @@ -312,9 +318,11 @@ int ogles2vk_InitOGLES2Context(OGLES2VKDevice *dev, void *window) dev->glContext = ctx; /* Query renderer name */ +#ifdef DEBUG const char *renderer = IOGLES2->glGetString(0x1F01); /* GL_RENDERER */ - IExec->DebugPrintF("[ogles2_vk] OGLES2 context created: %s\n", - renderer ? renderer : "unknown"); + D(("[ogles2_vk] OGLES2 context created: %s\n", + renderer ? renderer : "unknown")); +#endif /* Set initial GL state */ IOGLES2->glDisable(GL_DEPTH_TEST); @@ -335,7 +343,7 @@ void ogles2vk_ShutdownOGLES2Context(OGLES2VKDevice *dev) IOGLES2->aglDestroyContext(dev->glContext); dev->glContext = NULL; - IExec->DebugPrintF("[ogles2_vk] OGLES2 context destroyed\n"); + D(("[ogles2_vk] OGLES2 context destroyed\n")); } /****************************************************************************/ @@ -368,7 +376,7 @@ static int ogles2vk_EnsureShadersCompiled(OGLES2VKPipeline *pipe) if (!pipe->vertShader || !pipe->fragShader) { - IExec->DebugPrintF("[ogles2_vk] Pipeline missing vert or frag shader\n"); + D(("[ogles2_vk] Pipeline missing vert or frag shader\n")); return 0; } @@ -385,7 +393,7 @@ static int ogles2vk_EnsureShadersCompiled(OGLES2VKPipeline *pipe) pipe->vertShader->wordCount, pipe->vertShader->codeSize, 1, vr) && vr->glsl) { - IExec->DebugPrintF("[ogles2_vk] SPIRV-Cross vert GLSL:\n%s\n", vr->glsl); + D(("[ogles2_vk] SPIRV-Cross vert GLSL:\n%s\n", vr->glsl)); const char *src = vr->glsl; IOGLES2->glShaderSource(vs, 1, &src, NULL); IOGLES2->glCompileShader(vs); @@ -395,7 +403,7 @@ static int ogles2vk_EnsureShadersCompiled(OGLES2VKPipeline *pipe) { char log[512] = {0}; IOGLES2->glGetShaderInfoLog(vs, sizeof(log)-1, NULL, log); - IExec->DebugPrintF("[ogles2_vk] GLSL vert compile error: %s\n", log); + D(("[ogles2_vk] GLSL vert compile error: %s\n", log)); } } @@ -403,14 +411,14 @@ static int ogles2vk_EnsureShadersCompiled(OGLES2VKPipeline *pipe) { char log[512] = {0}; IOGLES2->glGetShaderInfoLog(vs, sizeof(log)-1, NULL, log); - IExec->DebugPrintF("[ogles2_vk] Vert shader FAILED: %s\n", log); + D(("[ogles2_vk] Vert shader FAILED: %s\n", log)); IOGLES2->glDeleteShader(vs); return 0; } pipe->vertShader->glShader = vs; - IExec->DebugPrintF("[ogles2_vk] Vertex shader compiled (GL %lu)\n", - (unsigned long)vs); + D(("[ogles2_vk] Vertex shader compiled (GL %lu)\n", + (unsigned long)vs)); } /* Compile fragment shader via SPIRV-Cross transpiler (if not already done) */ @@ -426,7 +434,7 @@ static int ogles2vk_EnsureShadersCompiled(OGLES2VKPipeline *pipe) pipe->fragShader->wordCount, pipe->fragShader->codeSize, 0, fr) && fr->glsl) { - IExec->DebugPrintF("[ogles2_vk] SPIRV-Cross frag GLSL:\n%s\n", fr->glsl); + D(("[ogles2_vk] SPIRV-Cross frag GLSL:\n%s\n", fr->glsl)); const char *src = fr->glsl; IOGLES2->glShaderSource(fs, 1, &src, NULL); IOGLES2->glCompileShader(fs); @@ -436,7 +444,7 @@ static int ogles2vk_EnsureShadersCompiled(OGLES2VKPipeline *pipe) { char log[512] = {0}; IOGLES2->glGetShaderInfoLog(fs, sizeof(log)-1, NULL, log); - IExec->DebugPrintF("[ogles2_vk] GLSL frag compile error: %s\n", log); + D(("[ogles2_vk] GLSL frag compile error: %s\n", log)); } } @@ -444,14 +452,14 @@ static int ogles2vk_EnsureShadersCompiled(OGLES2VKPipeline *pipe) { char log[512] = {0}; IOGLES2->glGetShaderInfoLog(fs, sizeof(log)-1, NULL, log); - IExec->DebugPrintF("[ogles2_vk] Frag shader FAILED: %s\n", log); + D(("[ogles2_vk] Frag shader FAILED: %s\n", log)); IOGLES2->glDeleteShader(fs); return 0; } pipe->fragShader->glShader = fs; - IExec->DebugPrintF("[ogles2_vk] Fragment shader compiled (GL %lu)\n", - (unsigned long)fs); + D(("[ogles2_vk] Fragment shader compiled (GL %lu)\n", + (unsigned long)fs)); } /* Link program */ @@ -469,14 +477,14 @@ static int ogles2vk_EnsureShadersCompiled(OGLES2VKPipeline *pipe) { char log[512] = {0}; IOGLES2->glGetProgramInfoLog(prog, sizeof(log)-1, NULL, log); - IExec->DebugPrintF("[ogles2_vk] Program link error: %s\n", log); + D(("[ogles2_vk] Program link error: %s\n", log)); IOGLES2->glDeleteProgram(prog); return 0; } pipe->glProgram = prog; - IExec->DebugPrintF("[ogles2_vk] Shader program linked (GL %lu)\n", - (unsigned long)prog); + D(("[ogles2_vk] Shader program linked (GL %lu)\n", + (unsigned long)prog)); /* Use cached transpile results from shader modules (survive across pipelines) */ OGLES2VKTranspileResult *vertResult = &pipe->vertShader->transpile; @@ -507,10 +515,10 @@ static int ogles2vk_EnsureShadersCompiled(OGLES2VKPipeline *pipe) } pipe->pcArraySize = pcResult->pcArraySize; - IExec->DebugPrintF("[ogles2_vk] Push constant array '%s': loc=%ld size=%lu vec4s\n", + D(("[ogles2_vk] Push constant array '%s': loc=%ld size=%lu vec4s\n", pcResult->pcArrayName, (long)pipe->pcArrayLoc, - (unsigned long)pipe->pcArraySize); + (unsigned long)pipe->pcArraySize)); } } @@ -528,11 +536,11 @@ static int ogles2vk_EnsureShadersCompiled(OGLES2VKPipeline *pipe) uint32_t idx = pipe->samplerCount++; pipe->samplerLocs[idx] = IOGLES2->glGetUniformLocation(prog, sr->samplers[i].name); - IExec->DebugPrintF("[ogles2_vk] Sampler '%s' (set=%u bind=%u): loc=%ld\n", + D(("[ogles2_vk] Sampler '%s' (set=%u bind=%u): loc=%ld\n", sr->samplers[i].name, (unsigned)sr->samplers[i].set, (unsigned)sr->samplers[i].binding, - (long)pipe->samplerLocs[idx]); + (long)pipe->samplerLocs[idx])); } } } @@ -555,8 +563,8 @@ static uint32_t ogles2vk_MapTopology(VkPrimitiveTopology topology) case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: return GL_TRIANGLE_STRIP; case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: return GL_TRIANGLE_FAN; default: - IExec->DebugPrintF("[ogles2_vk] Unsupported topology %u, defaulting to TRIANGLES\n", - (unsigned)topology); + D(("[ogles2_vk] Unsupported topology %u, defaulting to TRIANGLES\n", + (unsigned)topology)); return GL_TRIANGLES; } } @@ -565,10 +573,13 @@ static uint32_t ogles2vk_MapTopology(VkPrimitiveTopology topology) /* VkFormat -> GL vertex attribute mapping */ /****************************************************************************/ -static int ogles2vk_FormatToAttrib(VkFormat format, int32 *outSize, uint32_t *outType) +static int ogles2vk_FormatToAttrib(VkFormat format, int32 *outSize, uint32_t *outType, uint8_t *outNormalized) { + *outNormalized = GL_FALSE; switch (format) { + /* 32-bit float (only float formats present in the project's reduced + ** vulkan_core.h alongside R8G8B8A8_UNORM). */ case VK_FORMAT_R32_SFLOAT: *outSize = 1; *outType = GL_FLOAT; return 1; case VK_FORMAT_R32G32_SFLOAT: @@ -577,9 +588,16 @@ static int ogles2vk_FormatToAttrib(VkFormat format, int32 *outSize, uint32_t *ou *outSize = 3; *outType = GL_FLOAT; return 1; case VK_FORMAT_R32G32B32A32_SFLOAT: *outSize = 4; *outType = GL_FLOAT; return 1; + + /* 8-bit unsigned normalised RGBA — ImGui packs vertex colour as 4 bytes + ** in this format (format value 37). Without this case the driver + ** rejects every ImGui draw call. */ + case VK_FORMAT_R8G8B8A8_UNORM: + *outSize = 4; *outType = GL_UNSIGNED_BYTE; *outNormalized = GL_TRUE; return 1; + default: - IExec->DebugPrintF("[ogles2_vk] Unsupported vertex format %u\n", - (unsigned)format); + D(("[ogles2_vk] Unsupported vertex format %lu\n", + (unsigned long)format)); return 0; } } @@ -595,8 +613,8 @@ static int32_t ogles2vk_MapFilter(VkFilter filter) case VK_FILTER_NEAREST: return GL_NEAREST; case VK_FILTER_LINEAR: return GL_LINEAR; default: - IExec->DebugPrintF("[ogles2_vk] Unsupported filter %u, defaulting to LINEAR\n", - (unsigned)filter); + D(("[ogles2_vk] Unsupported filter %u, defaulting to LINEAR\n", + (unsigned)filter)); return GL_LINEAR; } } @@ -609,8 +627,8 @@ static int32_t ogles2vk_MapAddressMode(VkSamplerAddressMode mode) case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT: return GL_MIRRORED_REPEAT; case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE: return GL_CLAMP_TO_EDGE; default: - IExec->DebugPrintF("[ogles2_vk] Unsupported address mode %u, defaulting to REPEAT\n", - (unsigned)mode); + D(("[ogles2_vk] Unsupported address mode %u, defaulting to REPEAT\n", + (unsigned)mode)); return GL_REPEAT; } } @@ -674,8 +692,8 @@ static uint32_t ogles2vk_MapDepthFunc(VkCompareOp op) case VK_COMPARE_OP_GREATER_OR_EQUAL: return 0x0206; /* GL_GEQUAL */ case VK_COMPARE_OP_ALWAYS: return 0x0207; /* GL_ALWAYS */ default: - IExec->DebugPrintF("[ogles2_vk] Unsupported compare op %u, defaulting to LESS\n", - (unsigned)op); + D(("[ogles2_vk] Unsupported compare op %u, defaulting to LESS\n", + (unsigned)op)); return GL_LESS; } } @@ -782,7 +800,7 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c } else { - IExec->DebugPrintF("[ogles2_vk] Pipeline not ready, draw skipped\n"); + D(("[ogles2_vk] Pipeline not ready, draw skipped\n")); } } break; @@ -867,7 +885,7 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c if (!boundIndexBuffer || !boundIndexBuffer->boundMemory || !boundIndexBuffer->boundMemory->data) { - IExec->DebugPrintF("[ogles2_vk] DrawIndexed: no index buffer bound\n"); + D(("[ogles2_vk] DrawIndexed: no index buffer bound\n")); break; } @@ -885,7 +903,7 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c /* Guard against integer overflow */ if (idxCount > 0x7FFFFFFFU / idxSize) { - IExec->DebugPrintF("[ogles2_vk] DrawIndexed: index count too large\n"); + D(("[ogles2_vk] DrawIndexed: index count too large\n")); break; } @@ -893,7 +911,7 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c if (boundIndexBuffer->boundOffset + boundIndexOffset >= boundIndexBuffer->boundMemory->size) { - IExec->DebugPrintF("[ogles2_vk] DrawIndexed: offset past end of memory\n"); + D(("[ogles2_vk] DrawIndexed: offset past end of memory\n")); break; } @@ -908,10 +926,10 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c if (ibRequired > ibAvail) { - IExec->DebugPrintF("[ogles2_vk] DrawIndexed: index buffer overflow " + D(("[ogles2_vk] DrawIndexed: index buffer overflow " "(need %lu, have %lu)\n", (unsigned long)ibRequired, - (unsigned long)ibAvail); + (unsigned long)ibAvail)); break; } } @@ -963,8 +981,8 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c if (!img->boundMemory || !img->boundMemory->data) { - IExec->DebugPrintF("[ogles2_vk] Texture s%u b%u: no bound memory\n", - (unsigned)s, (unsigned)b); + D(("[ogles2_vk] Texture s%u b%u: no bound memory\n", + (unsigned)s, (unsigned)b)); continue; } @@ -975,10 +993,10 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c img->format != VK_FORMAT_B8G8R8A8_UNORM && img->format != VK_FORMAT_B8G8R8A8_SRGB) { - IExec->DebugPrintF("[ogles2_vk] Texture s%u b%u: " + D(("[ogles2_vk] Texture s%u b%u: " "unsupported format %u, skipping\n", (unsigned)s, (unsigned)b, - (unsigned)img->format); + (unsigned)img->format)); continue; } @@ -987,12 +1005,12 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c * img->height * bpp; if (img->boundOffset + texDataSize > img->boundMemory->size) { - IExec->DebugPrintF("[ogles2_vk] Texture s%u b%u: " + D(("[ogles2_vk] Texture s%u b%u: " "data overflow (%lu + %lu > %lu)\n", (unsigned)s, (unsigned)b, (unsigned long)img->boundOffset, (unsigned long)texDataSize, - (unsigned long)img->boundMemory->size); + (unsigned long)img->boundMemory->size)); continue; } @@ -1002,10 +1020,10 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c /* Prevent GL texture leak: check capacity before creating */ if (glTextureCount >= OGLES2VK_MAX_BOUND_TEXTURES) { - IExec->DebugPrintF("[ogles2_vk] Texture s%u b%u: " + D(("[ogles2_vk] Texture s%u b%u: " "max texture units reached (%u)\n", (unsigned)s, (unsigned)b, - (unsigned)OGLES2VK_MAX_BOUND_TEXTURES); + (unsigned)OGLES2VK_MAX_BOUND_TEXTURES)); continue; } @@ -1014,9 +1032,9 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c IOGLES2->glGenTextures(1, (uint32 *)&glTex); if (!glTex) { - IExec->DebugPrintF("[ogles2_vk] glGenTextures failed " + D(("[ogles2_vk] glGenTextures failed " "for s%u b%u\n", - (unsigned)s, (unsigned)b); + (unsigned)s, (unsigned)b)); continue; } @@ -1051,8 +1069,8 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c } else { - IExec->DebugPrintF("[ogles2_vk] Sampler at texUnit %u: " - "no stored location\n", (unsigned)texUnit); + D(("[ogles2_vk] Sampler at texUnit %u: " + "no stored location\n", (unsigned)texUnit)); } if (glTextureCount < OGLES2VK_MAX_BOUND_TEXTURES) @@ -1084,16 +1102,16 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c if (binding >= OGLES2VK_MAX_VERTEX_BINDINGS || !boundVBs[binding]) { - IExec->DebugPrintF("[ogles2_vk] VB binding %u: no buffer bound\n", - (unsigned)binding); + D(("[ogles2_vk] VB binding %u: no buffer bound\n", + (unsigned)binding)); continue; } OGLES2VKBuffer *buf = boundVBs[binding]; if (!buf->boundMemory || !buf->boundMemory->data) { - IExec->DebugPrintF("[ogles2_vk] VB binding %u: buffer has no memory\n", - (unsigned)binding); + D(("[ogles2_vk] VB binding %u: buffer has no memory\n", + (unsigned)binding)); continue; } @@ -1102,8 +1120,8 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c /* Validate that offsets are within memory allocation */ if (buf->boundOffset + vbOffset >= buf->boundMemory->size) { - IExec->DebugPrintF("[ogles2_vk] VB binding %u: offset past end of memory\n", - (unsigned)binding); + D(("[ogles2_vk] VB binding %u: offset past end of memory\n", + (unsigned)binding)); continue; } @@ -1133,8 +1151,8 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c IOGLES2->glGenBuffers(1, (uint32 *)&vbo); if (!vbo) { - IExec->DebugPrintF("[ogles2_vk] glGenBuffers failed for binding %u\n", - (unsigned)binding); + D(("[ogles2_vk] glGenBuffers failed for binding %u\n", + (unsigned)binding)); continue; } @@ -1155,11 +1173,12 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c int32 components; uint32_t glType; - if (!ogles2vk_FormatToAttrib(attr->format, &components, &glType)) + uint8_t glNormalized; + if (!ogles2vk_FormatToAttrib(attr->format, &components, &glType, &glNormalized)) continue; IOGLES2->glVertexAttribPointer( - attr->location, components, glType, GL_FALSE, + attr->location, components, glType, glNormalized, (int32)stride, (const void *)(uintptr_t)attr->offset); IOGLES2->glEnableVertexAttribArray(attr->location); @@ -1198,8 +1217,8 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c IOGLES2->glGenBuffers(1, (uint32 *)&glIBO); if (!glIBO) { - IExec->DebugPrintF("[ogles2_vk] DrawIndexed: glGenBuffers " - "failed for IBO\n"); + D(("[ogles2_vk] DrawIndexed: glGenBuffers " + "failed for IBO\n")); break; } @@ -1296,8 +1315,8 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c } vbDirty = 1; - IExec->DebugPrintF("[ogles2_vk] BindVertexBuffers: first=%u count=%u\n", - (unsigned)first, (unsigned)count); + D(("[ogles2_vk] BindVertexBuffers: first=%u count=%u\n", + (unsigned)first, (unsigned)count)); break; } @@ -1308,15 +1327,15 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c if (boundIndexType != VK_INDEX_TYPE_UINT16 && boundIndexType != VK_INDEX_TYPE_UINT32) { - IExec->DebugPrintF("[ogles2_vk] BindIndexBuffer: unsupported " + D(("[ogles2_vk] BindIndexBuffer: unsupported " "type %u, defaulting to UINT32\n", - (unsigned)boundIndexType); + (unsigned)boundIndexType)); boundIndexType = VK_INDEX_TYPE_UINT32; } - IExec->DebugPrintF("[ogles2_vk] BindIndexBuffer: type=%s offset=%lu\n", + D(("[ogles2_vk] BindIndexBuffer: type=%s offset=%lu\n", boundIndexType == VK_INDEX_TYPE_UINT16 ? "UINT16" : "UINT32", - (unsigned long)boundIndexOffset); + (unsigned long)boundIndexOffset)); break; case OGLES2VK_CMD_BIND_DESCRIPTOR_SETS: @@ -1326,8 +1345,8 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c for (uint32_t s = 0; s < count && (first + s) < OGLES2VK_MAX_DESCRIPTOR_SETS; s++) boundDescSets[first + s] = (OGLES2VKDescriptorSet *)c->bindDescriptorSets.sets[s]; - IExec->DebugPrintF("[ogles2_vk] BindDescriptorSets: first=%u count=%u\n", - (unsigned)first, (unsigned)count); + D(("[ogles2_vk] BindDescriptorSets: first=%u count=%u\n", + (unsigned)first, (unsigned)count)); break; } @@ -1443,7 +1462,7 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c } else { - IExec->DebugPrintF("[ogles2_vk] CopyBuffer: out of bounds\n"); + D(("[ogles2_vk] CopyBuffer: out of bounds\n")); } } break; @@ -1581,7 +1600,7 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c } else { - IExec->DebugPrintF("[ogles2_vk] FillBuffer: out of bounds\n"); + D(("[ogles2_vk] FillBuffer: out of bounds\n")); } } break; @@ -1602,7 +1621,7 @@ void ogles2vk_ExecuteCommandBuffer(OGLES2VKDevice *dev, OGLES2VKCommandBuffer *c } else { - IExec->DebugPrintF("[ogles2_vk] UpdateBuffer: out of bounds\n"); + D(("[ogles2_vk] UpdateBuffer: out of bounds\n")); } } break; diff --git a/ogles2_icd/src/ogles2vk_main.c b/ogles2_icd/src/ogles2vk_main.c index dc47d6e..ca21229 100644 --- a/ogles2_icd/src/ogles2vk_main.c +++ b/ogles2_icd/src/ogles2vk_main.c @@ -299,6 +299,30 @@ static void _discover_gpu(void) g_physDevice.properties.limits.maxVertexInputAttributes = 16; g_physDevice.properties.limits.maxVertexInputBindings = 8; + /* + * Allocation / alignment limits — VMA queries these during init AND on + * every allocation to round sizes / pick block layout. With the prior + * memset() they stayed 0, which made VMA's internal + * `min(blockSize, heapSize) % bufferImageGranularity` math divide by + * zero (or compute alignment 0), causing vmaCreateImage to bail out + * with VK_ERROR_OUT_OF_DEVICE_MEMORY before ever calling + * vkAllocateMemory. These conservative defaults match typical desktop + * GPUs and let VMA proceed. + */ + g_physDevice.properties.limits.bufferImageGranularity = 1024; + g_physDevice.properties.limits.nonCoherentAtomSize = 64; + g_physDevice.properties.limits.minMemoryMapAlignment = 64; + g_physDevice.properties.limits.minUniformBufferOffsetAlignment = 256; + g_physDevice.properties.limits.minStorageBufferOffsetAlignment = 256; + g_physDevice.properties.limits.minTexelBufferOffsetAlignment = 16; + g_physDevice.properties.limits.optimalBufferCopyOffsetAlignment = 4; + g_physDevice.properties.limits.optimalBufferCopyRowPitchAlignment = 4; + g_physDevice.properties.limits.maxMemoryAllocationCount = 4096; + g_physDevice.properties.limits.maxSamplerAllocationCount = 4096; + g_physDevice.properties.limits.maxStorageBufferRange = 0x80000000u; /* 2 GB */ + g_physDevice.properties.limits.maxUniformBufferRange = 65536; + g_physDevice.properties.limits.sparseAddressSpaceSize = 0; + /* Query W3D Nova capabilities where available */ { uint32 maxTexW = (uint32)IW3DNova->W3DN_Query(gpuList, W3DN_Q_MAXTEXWIDTH); diff --git a/ogles2_icd/src/ogles2vk_shader.c b/ogles2_icd/src/ogles2vk_shader.c index 4115c5d..f683dbc 100644 --- a/ogles2_icd/src/ogles2vk_shader.c +++ b/ogles2_icd/src/ogles2vk_shader.c @@ -54,8 +54,8 @@ VkResult ogles2vk_CreateShaderModule(VkDevice device, uint32_t magic = pCreateInfo->pCode[0]; if (magic != SPV_MAGIC_LE && magic != SPV_MAGIC_BE) { - IExec->DebugPrintF("[ogles2_vk] Invalid SPIR-V magic: 0x%08lx\n", - (unsigned long)magic); + D(("[ogles2_vk] Invalid SPIR-V magic: 0x%08lx\n", + (unsigned long)magic)); return VK_ERROR_INITIALIZATION_FAILED; } @@ -90,10 +90,10 @@ VkResult ogles2vk_CreateShaderModule(VkDevice device, *pShaderModule = (VkShaderModule)(uintptr_t)mod; - IExec->DebugPrintF("[ogles2_vk] Shader module created (%lu words, magic=0x%02x%02x%02x%02x)\n", + D(("[ogles2_vk] Shader module created (%lu words, magic=0x%02x%02x%02x%02x)\n", (unsigned long)wordCount, ((uint8_t *)mod->codeOrig)[0], ((uint8_t *)mod->codeOrig)[1], - ((uint8_t *)mod->codeOrig)[2], ((uint8_t *)mod->codeOrig)[3]); + ((uint8_t *)mod->codeOrig)[2], ((uint8_t *)mod->codeOrig)[3])); return VK_SUCCESS; } @@ -372,9 +372,9 @@ VkResult ogles2vk_CreateGraphicsPipelines(VkDevice device, pPipelines[i] = (VkPipeline)(uintptr_t)pipe; - IExec->DebugPrintF("[ogles2_vk] Pipeline created (vert=%s frag=%s)\n", + D(("[ogles2_vk] Pipeline created (vert=%s frag=%s)\n", pipe->vertShader ? "yes" : "no", - pipe->fragShader ? "yes" : "no"); + pipe->fragShader ? "yes" : "no")); } return VK_SUCCESS; diff --git a/ogles2_icd/src/ogles2vk_spirv2glsl.c b/ogles2_icd/src/ogles2vk_spirv2glsl.c index e1f7ff7..fef1304 100644 --- a/ogles2_icd/src/ogles2vk_spirv2glsl.c +++ b/ogles2_icd/src/ogles2vk_spirv2glsl.c @@ -656,6 +656,23 @@ int ogles2vk_SPIRV2GLSL(const uint32_t *leCode, uint32_t wordCount, spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_EMIT_PUSH_CONSTANT_AS_UNIFORM_BUFFER, SPVC_TRUE); + /* + * Force flattened in/out blocks. Without this, SPIRV-Cross emits the + * struct-typed varyings produced by glslang directly: + * out struct { vec4 Color; vec2 UV; } Out; // vertex + * in struct { vec4 Color; vec2 UV; } In; // fragment + * Warp3D Nova's GLSL ES linker matches varyings by name, so `Out.Color` + * (vertex output) and `In.Color` (fragment input) never match and the + * program fails to link with: "Fragment shader has input In.Color, but + * the previous shader pipeline stage doesn't." + * + * With FLATTEN_IO_BLOCKS the struct is decomposed into discrete varyings + * sharing identical names across stages (derived from the field, not the + * block instance), so the linker's name match succeeds. + */ + spvc_compiler_options_set_bool(options, + SPVC_COMPILER_OPTION_GLSL_FORCE_FLATTENED_IO_BLOCKS, SPVC_TRUE); + if (spvc_compiler_install_compiler_options(compiler, options) != SPVC_SUCCESS) goto cleanup; @@ -722,6 +739,39 @@ int ogles2vk_SPIRV2GLSL(const uint32_t *leCode, uint32_t wordCount, } } + /* + * Step 6b: Rename interface block variables to "vary" in BOTH stages. + * + * Even with FORCE_FLATTENED_IO_BLOCKS, SPIRV-Cross prefixes the emitted + * field names with the original block instance name from the SPIR-V + * (`Out` in vertex glsl, `In` in fragment glsl). Result: + * vertex : out vec4 Out_Color; out vec2 Out_UV; + * fragment : in vec4 In_Color; in vec2 In_UV; + * Warp3D Nova links varyings by name so the names don't match. + * + * Force both stages to use the same instance name. After renaming both + * the vertex output block and the fragment input block to "vary", + * SPIRV-Cross emits matching `vary_Color` / `vary_UV` symbols and the + * GLSL ES linker succeeds. + */ + for (int iface = 0; iface < 2; ++iface) + { + spvc_resource_type rtype = (iface == 0) + ? SPVC_RESOURCE_TYPE_STAGE_INPUT + : SPVC_RESOURCE_TYPE_STAGE_OUTPUT; + const spvc_reflected_resource *list = NULL; + size_t count = 0; + if (spvc_resources_get_resource_list_for_type(resources, rtype, &list, &count) != SPVC_SUCCESS) + continue; + for (size_t i = 0; i < count; i++) + { + spvc_type t = spvc_compiler_get_type_handle(compiler, list[i].type_id); + spvc_basetype bt = spvc_type_get_basetype(t); + if (bt == SPVC_BASETYPE_STRUCT) + spvc_compiler_set_name(compiler, list[i].id, "vary"); + } + } + /* Step 7: Compile to GLSL */ if (spvc_compiler_compile(compiler, &glslSource) != SPVC_SUCCESS) { diff --git a/software_icd/Makefile b/software_icd/Makefile index 0020aaa..455be1e 100644 --- a/software_icd/Makefile +++ b/software_icd/Makefile @@ -8,6 +8,7 @@ CC = ppc-amigaos-gcc CFLAGS = -mcrt=newlib -O2 -Wall \ -D__NOLIBBASE__ -D__NOGLOBALIFACE__ LDFLAGS = -mcrt=newlib -nostartfiles +DEBUG := SOURCES = src/swvk_main.c src/swvk_instance.c src/swvk_device.c \ src/swvk_memory.c src/swvk_buffer.c \ diff --git a/software_icd/Makefile.cross b/software_icd/Makefile.cross index 13219f7..9072d43 100644 --- a/software_icd/Makefile.cross +++ b/software_icd/Makefile.cross @@ -82,6 +82,6 @@ $(TARGET): clean: - rm -f build/swvk_*.o build/software_vk.library + rm -f build/* diff --git a/software_icd/include/swvk_internal.h b/software_icd/include/swvk_internal.h index c2fb505..182c297 100644 --- a/software_icd/include/swvk_internal.h +++ b/software_icd/include/swvk_internal.h @@ -14,6 +14,12 @@ #include #include +#ifdef DEBUG +#define D(x) IExec->DebugPrintF x +#else +#define D(x) do {} while (0) +#endif + /*------------------------------------------------------------------------ ** Version info **----------------------------------------------------------------------*/ diff --git a/software_icd/src/swvk_cmdbuf.c b/software_icd/src/swvk_cmdbuf.c index 1092885..83e7087 100644 --- a/software_icd/src/swvk_cmdbuf.c +++ b/software_icd/src/swvk_cmdbuf.c @@ -132,8 +132,8 @@ VkResult swvk_EndCommandBuffer(VkCommandBuffer commandBuffer) cmd->recording = 0; - IExec->DebugPrintF("[software_vk] Command buffer recorded: %lu commands\n", - (unsigned long)cmd->commandCount); + D(("[software_vk] Command buffer recorded: %lu commands\n", + (unsigned long)cmd->commandCount)); return VK_SUCCESS; } @@ -146,8 +146,8 @@ static SWVKCommand *swvk_CmdAppend(SWVKCommandBuffer *cmd, SWVKCommandType type) { if (cmd->commandCount >= SWVK_MAX_COMMANDS) { - IExec->DebugPrintF("[software_vk] WARNING: command buffer full (%u/%u), command dropped\n", - (unsigned)cmd->commandCount, (unsigned)SWVK_MAX_COMMANDS); + D(("[software_vk] WARNING: command buffer full (%u/%u), command dropped\n", + (unsigned)cmd->commandCount, (unsigned)SWVK_MAX_COMMANDS)); return NULL; } @@ -284,8 +284,8 @@ void swvk_CmdPushConstants(VkCommandBuffer commandBuffer, /* Bounds check */ if (offset + size > SWVK_MAX_PUSH_CONSTANT_SIZE) { - IExec->DebugPrintF("[software_vk] WARNING: push constants exceed max size (%u + %u > %u)\n", - (unsigned)offset, (unsigned)size, (unsigned)SWVK_MAX_PUSH_CONSTANT_SIZE); + D(("[software_vk] WARNING: push constants exceed max size (%u + %u > %u)\n", + (unsigned)offset, (unsigned)size, (unsigned)SWVK_MAX_PUSH_CONSTANT_SIZE)); return; } @@ -312,9 +312,9 @@ void swvk_CmdBindVertexBuffers(VkCommandBuffer commandBuffer, /* Bounds check */ if (firstBinding + bindingCount > SWVK_MAX_VERTEX_BINDINGS) { - IExec->DebugPrintF("[software_vk] WARNING: vertex binding out of range (%u + %u > %u)\n", + D(("[software_vk] WARNING: vertex binding out of range (%u + %u > %u)\n", (unsigned)firstBinding, (unsigned)bindingCount, - (unsigned)SWVK_MAX_VERTEX_BINDINGS); + (unsigned)SWVK_MAX_VERTEX_BINDINGS)); return; } @@ -744,8 +744,8 @@ void swvk_CmdUpdateBuffer(VkCommandBuffer commandBuffer, /* Clamp to inline storage limit */ if (dataSize > 64) { - IExec->DebugPrintF("[software_vk] WARNING: CmdUpdateBuffer dataSize %lu exceeds 64 byte limit\n", - (unsigned long)dataSize); + D(("[software_vk] WARNING: CmdUpdateBuffer dataSize %lu exceeds 64 byte limit\n", + (unsigned long)dataSize)); dataSize = 64; } @@ -785,9 +785,9 @@ void swvk_CmdBindDescriptorSets(VkCommandBuffer commandBuffer, /* Bounds check */ if (firstSet + descriptorSetCount > SWVK_MAX_DESCRIPTOR_SETS) { - IExec->DebugPrintF("[software_vk] WARNING: descriptor set out of range (%u + %u > %u)\n", + D(("[software_vk] WARNING: descriptor set out of range (%u + %u > %u)\n", (unsigned)firstSet, (unsigned)descriptorSetCount, - (unsigned)SWVK_MAX_DESCRIPTOR_SETS); + (unsigned)SWVK_MAX_DESCRIPTOR_SETS)); return; } diff --git a/software_icd/src/swvk_descriptor.c b/software_icd/src/swvk_descriptor.c index 2cc270d..f1d7dd6 100644 --- a/software_icd/src/swvk_descriptor.c +++ b/software_icd/src/swvk_descriptor.c @@ -47,11 +47,11 @@ VkResult swvk_CreateSampler(VkDevice device, *pSampler = (VkSampler)(uintptr_t)sampler; - IExec->DebugPrintF("[software_vk] Sampler created: mag=%lu, min=%lu, addrU=%lu, addrV=%lu\n", + D(("[software_vk] Sampler created: mag=%lu, min=%lu, addrU=%lu, addrV=%lu\n", (unsigned long)sampler->magFilter, (unsigned long)sampler->minFilter, (unsigned long)sampler->addressModeU, - (unsigned long)sampler->addressModeV); + (unsigned long)sampler->addressModeV)); return VK_SUCCESS; } @@ -96,8 +96,8 @@ VkResult swvk_CreateDescriptorSetLayout(VkDevice device, layout->bindingCount = pCreateInfo->bindingCount; if (layout->bindingCount > SWVK_MAX_DESCRIPTOR_BINDINGS) { - IExec->DebugPrintF("[software_vk] WARNING: descriptor bindings clamped (%u > %u)\n", - (unsigned)layout->bindingCount, (unsigned)SWVK_MAX_DESCRIPTOR_BINDINGS); + D(("[software_vk] WARNING: descriptor bindings clamped (%u > %u)\n", + (unsigned)layout->bindingCount, (unsigned)SWVK_MAX_DESCRIPTOR_BINDINGS)); layout->bindingCount = SWVK_MAX_DESCRIPTOR_BINDINGS; } @@ -109,8 +109,8 @@ VkResult swvk_CreateDescriptorSetLayout(VkDevice device, *pSetLayout = (VkDescriptorSetLayout)(uintptr_t)layout; - IExec->DebugPrintF("[software_vk] Descriptor set layout created: %lu bindings\n", - (unsigned long)layout->bindingCount); + D(("[software_vk] Descriptor set layout created: %lu bindings\n", + (unsigned long)layout->bindingCount)); return VK_SUCCESS; } @@ -156,8 +156,8 @@ VkResult swvk_CreateDescriptorPool(VkDevice device, *pDescriptorPool = (VkDescriptorPool)(uintptr_t)pool; - IExec->DebugPrintF("[software_vk] Descriptor pool created: maxSets=%lu\n", - (unsigned long)pool->maxSets); + D(("[software_vk] Descriptor pool created: maxSets=%lu\n", + (unsigned long)pool->maxSets)); return VK_SUCCESS; } @@ -235,8 +235,8 @@ VkResult swvk_AllocateDescriptorSets(VkDevice device, pDescriptorSets[i] = (VkDescriptorSet)(uintptr_t)set; } - IExec->DebugPrintF("[software_vk] Allocated %lu descriptor sets\n", - (unsigned long)pAllocateInfo->descriptorSetCount); + D(("[software_vk] Allocated %lu descriptor sets\n", + (unsigned long)pAllocateInfo->descriptorSetCount)); return VK_SUCCESS; } @@ -290,8 +290,8 @@ void swvk_UpdateDescriptorSets(VkDevice device, if (binding >= SWVK_MAX_DESCRIPTOR_BINDINGS) { - IExec->DebugPrintF("[software_vk] WARNING: descriptor binding %lu out of range\n", - (unsigned long)binding); + D(("[software_vk] WARNING: descriptor binding %lu out of range\n", + (unsigned long)binding)); continue; } @@ -313,10 +313,10 @@ void swvk_UpdateDescriptorSets(VkDevice device, set->bindings[binding].offset = write->pBufferInfo[0].offset; set->bindings[binding].range = write->pBufferInfo[0].range; - IExec->DebugPrintF("[software_vk] Descriptor set binding %lu: buffer, offset=%lu, range=%lu\n", + D(("[software_vk] Descriptor set binding %lu: buffer, offset=%lu, range=%lu\n", (unsigned long)binding, (unsigned long)write->pBufferInfo[0].offset, - (unsigned long)write->pBufferInfo[0].range); + (unsigned long)write->pBufferInfo[0].range)); } /* For combined image sampler descriptors */ @@ -329,8 +329,8 @@ void swvk_UpdateDescriptorSets(VkDevice device, set->bindings[binding].sampler = (SWVKSampler *)(uintptr_t)imgInfo->sampler; - IExec->DebugPrintF("[software_vk] Descriptor set binding %lu: combined image sampler\n", - (unsigned long)binding); + D(("[software_vk] Descriptor set binding %lu: combined image sampler\n", + (unsigned long)binding)); } } } diff --git a/software_icd/src/swvk_device.c b/software_icd/src/swvk_device.c index e538de5..754130c 100644 --- a/software_icd/src/swvk_device.c +++ b/software_icd/src/swvk_device.c @@ -50,7 +50,7 @@ VkResult swvk_CreateDevice(VkPhysicalDevice physicalDevice, *pDevice = (VkDevice)dev; - IExec->DebugPrintF("[software_vk] Device created\n"); + D(("[software_vk] Device created\n")); return VK_SUCCESS; } @@ -63,7 +63,7 @@ void swvk_DestroyDevice(VkDevice device, if (device != VK_NULL_HANDLE) { IExec->FreeVec((APTR)device); - IExec->DebugPrintF("[software_vk] Device destroyed\n"); + D(("[software_vk] Device destroyed\n")); } } diff --git a/software_icd/src/swvk_draw.c b/software_icd/src/swvk_draw.c index 90d800f..73a9f1d 100644 --- a/software_icd/src/swvk_draw.c +++ b/software_icd/src/swvk_draw.c @@ -932,8 +932,8 @@ static void swvk_ExecuteDraw(SWVKRenderState *rs, const SWVKCommand *cmd) /* Guard against integer overflow in allocation size */ if (vertexCount > 0xFFFFFFFFU / sizeof(SWVKVertexOutput)) { - IExec->DebugPrintF("[software_vk] vertexCount overflow: %lu\n", - (unsigned long)vertexCount); + D(("[software_vk] vertexCount overflow: %lu\n", + (unsigned long)vertexCount)); return; } @@ -964,7 +964,7 @@ static void swvk_ExecuteDraw(SWVKRenderState *rs, const SWVKCommand *cmd) vertState = rs->cachedVertState; if (!vertState) { - IExec->DebugPrintF("[software_vk] WARNING: vertState alloc failed\n"); + D(("[software_vk] WARNING: vertState alloc failed\n")); IExec->FreeVec(verts); return; } @@ -974,8 +974,8 @@ static void swvk_ExecuteDraw(SWVKRenderState *rs, const SWVKCommand *cmd) { if (swvk_RunVertexShader(rs->pipeline, firstVertex + i, &verts[i], vertState, rs) != 0) { - IExec->DebugPrintF("[software_vk] Vertex shader failed at vertex %lu\n", - (unsigned long)(firstVertex + i)); + D(("[software_vk] Vertex shader failed at vertex %lu\n", + (unsigned long)(firstVertex + i))); IExec->FreeVec(verts); return; } @@ -998,7 +998,7 @@ static void swvk_ExecuteDraw(SWVKRenderState *rs, const SWVKCommand *cmd) } fragState = rs->cachedFragState; if (!fragState) - IExec->DebugPrintF("[software_vk] WARNING: fragState alloc failed\n"); + D(("[software_vk] WARNING: fragState alloc failed\n")); } /* Rasterise primitives using effective topology (pipeline or dynamic) */ @@ -1060,7 +1060,7 @@ static void swvk_ExecuteDrawIndexed(SWVKRenderState *rs, const SWVKCommand *cmd) /* Validate index buffer */ if (!rs->indexBuffer || !rs->indexBuffer->boundMemory || !rs->indexBuffer->boundMemory->data) { - IExec->DebugPrintF("[software_vk] DrawIndexed: no index buffer bound\n"); + D(("[software_vk] DrawIndexed: no index buffer bound\n")); return; } @@ -1074,15 +1074,15 @@ static void swvk_ExecuteDrawIndexed(SWVKRenderState *rs, const SWVKCommand *cmd) VkDeviceSize requiredIBSize = (VkDeviceSize)(firstIndex + indexCount) * indexSize; if (ibuf->boundOffset + rs->indexOffset + requiredIBSize > ibuf->boundMemory->size) { - IExec->DebugPrintF("[software_vk] DrawIndexed: index buffer overflow\n"); + D(("[software_vk] DrawIndexed: index buffer overflow\n")); return; } /* Guard against integer overflow in allocation size */ if (indexCount > 0xFFFFFFFFU / sizeof(SWVKVertexOutput)) { - IExec->DebugPrintF("[software_vk] DrawIndexed: indexCount overflow: %lu\n", - (unsigned long)indexCount); + D(("[software_vk] DrawIndexed: indexCount overflow: %lu\n", + (unsigned long)indexCount)); return; } @@ -1111,7 +1111,7 @@ static void swvk_ExecuteDrawIndexed(SWVKRenderState *rs, const SWVKCommand *cmd) vertState = rs->cachedVertState; if (!vertState) { - IExec->DebugPrintF("[software_vk] WARNING: vertState alloc failed (indexed)\n"); + D(("[software_vk] WARNING: vertState alloc failed (indexed)\n")); IExec->FreeVec(verts); return; } @@ -1140,8 +1140,8 @@ static void swvk_ExecuteDrawIndexed(SWVKRenderState *rs, const SWVKCommand *cmd) if (swvk_RunVertexShader(rs->pipeline, vertIdx, &verts[i], vertState, rs) != 0) { - IExec->DebugPrintF("[software_vk] Vertex shader failed at indexed vertex %lu (idx=%lu)\n", - (unsigned long)i, (unsigned long)vertIdx); + D(("[software_vk] Vertex shader failed at indexed vertex %lu (idx=%lu)\n", + (unsigned long)i, (unsigned long)vertIdx)); IExec->FreeVec(verts); return; } @@ -1164,7 +1164,7 @@ static void swvk_ExecuteDrawIndexed(SWVKRenderState *rs, const SWVKCommand *cmd) } fragState = rs->cachedFragState; if (!fragState) - IExec->DebugPrintF("[software_vk] WARNING: fragState alloc failed (indexed)\n"); + D(("[software_vk] WARNING: fragState alloc failed (indexed)\n")); } /* Rasterise primitives using effective topology (pipeline or dynamic) */ @@ -1424,7 +1424,7 @@ static void swvk_ExecuteCommandBuffer(SWVKCommandBuffer *cmdbuf) } else { - IExec->DebugPrintF("[software_vk] WARNING: CmdCopyBuffer out of bounds\n"); + D(("[software_vk] WARNING: CmdCopyBuffer out of bounds\n")); } } break; @@ -1628,7 +1628,7 @@ static void swvk_ExecuteCommandBuffer(SWVKCommandBuffer *cmdbuf) } else { - IExec->DebugPrintF("[software_vk] WARNING: CmdFillBuffer out of bounds\n"); + D(("[software_vk] WARNING: CmdFillBuffer out of bounds\n")); } } break; @@ -1649,7 +1649,7 @@ static void swvk_ExecuteCommandBuffer(SWVKCommandBuffer *cmdbuf) } else { - IExec->DebugPrintF("[software_vk] WARNING: CmdUpdateBuffer out of bounds\n"); + D(("[software_vk] WARNING: CmdUpdateBuffer out of bounds\n")); } } break; @@ -1755,8 +1755,8 @@ VkResult swvk_QueueSubmit(VkQueue queue, if (cmdbuf) { - IExec->DebugPrintF("[software_vk] Executing command buffer (%lu commands)\n", - (unsigned long)cmdbuf->commandCount); + D(("[software_vk] Executing command buffer (%lu commands)\n", + (unsigned long)cmdbuf->commandCount)); swvk_ExecuteCommandBuffer(cmdbuf); } } @@ -1795,8 +1795,8 @@ VkResult swvk_QueueSubmit2(VkQueue queue, if (cmdbuf) { - IExec->DebugPrintF("[software_vk] QueueSubmit2: executing command buffer (%lu commands)\n", - (unsigned long)cmdbuf->commandCount); + D(("[software_vk] QueueSubmit2: executing command buffer (%lu commands)\n", + (unsigned long)cmdbuf->commandCount)); swvk_ExecuteCommandBuffer(cmdbuf); } } diff --git a/software_icd/src/swvk_instance.c b/software_icd/src/swvk_instance.c index ebdeb35..ee223a1 100644 --- a/software_icd/src/swvk_instance.c +++ b/software_icd/src/swvk_instance.c @@ -253,9 +253,9 @@ VkResult swvk_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, *pInstance = (VkInstance)inst; - IExec->DebugPrintF("[software_vk] Instance created (API %lu.%lu)\n", + D(("[software_vk] Instance created (API %lu.%lu)\n", (unsigned long)VK_API_VERSION_MAJOR(inst->apiVersion), - (unsigned long)VK_API_VERSION_MINOR(inst->apiVersion)); + (unsigned long)VK_API_VERSION_MINOR(inst->apiVersion))); return VK_SUCCESS; } @@ -268,7 +268,7 @@ void swvk_DestroyInstance(VkInstance instance, if (instance != VK_NULL_HANDLE) { IExec->FreeVec((APTR)instance); - IExec->DebugPrintF("[software_vk] Instance destroyed\n"); + D(("[software_vk] Instance destroyed\n")); } } diff --git a/software_icd/src/swvk_main.c b/software_icd/src/swvk_main.c index aef2b92..401c8ed 100644 --- a/software_icd/src/swvk_main.c +++ b/software_icd/src/swvk_main.c @@ -223,8 +223,8 @@ static struct Library *_lib_Init(struct Library *libBase, BPTR seglist, return NULL; } - IExec->DebugPrintF("[software_vk] Initialized v%ld.%ld\n", - (long)LIBVER, (long)LIBREV); + D(("[software_vk] Initialized v%ld.%ld\n", + (long)LIBVER, (long)LIBREV)); return (struct Library *)base; } @@ -1241,8 +1241,8 @@ static VkResult APICALL _icd_NegotiateLoaderICDInterfaceVersion( if (*pSupportedVersion > 3) *pSupportedVersion = 3; - IExec->DebugPrintF("[software_vk] Negotiated ICD interface version %lu\n", - (unsigned long)*pSupportedVersion); + D(("[software_vk] Negotiated ICD interface version %lu\n", + (unsigned long)*pSupportedVersion)); return VK_SUCCESS; } diff --git a/software_icd/src/swvk_memory.c b/software_icd/src/swvk_memory.c index f08a583..e282f7c 100644 --- a/software_icd/src/swvk_memory.c +++ b/software_icd/src/swvk_memory.c @@ -63,8 +63,8 @@ VkResult swvk_AllocateMemory(VkDevice device, *pMemory = (VkDeviceMemory)(uintptr_t)mem; - IExec->DebugPrintF("[software_vk] Memory allocated: %lu bytes\n", - (unsigned long)pAllocateInfo->allocationSize); + D(("[software_vk] Memory allocated: %lu bytes\n", + (unsigned long)pAllocateInfo->allocationSize)); return VK_SUCCESS; } diff --git a/software_icd/src/swvk_pipeline.c b/software_icd/src/swvk_pipeline.c index c50e33e..13d5a7e 100644 --- a/software_icd/src/swvk_pipeline.c +++ b/software_icd/src/swvk_pipeline.c @@ -16,12 +16,6 @@ #include "swvk_internal.h" #include "swvk_spirv.h" -#ifdef DEBUG -#define D(x) IExec->DebugPrintF x -#else -#define D(x) do {} while (0) -#endif - /****************************************************************************/ /* Shader module creation */ /****************************************************************************/ diff --git a/software_icd/src/swvk_spirv.c b/software_icd/src/swvk_spirv.c index 1f7c32e..0f733dd 100644 --- a/software_icd/src/swvk_spirv.c +++ b/software_icd/src/swvk_spirv.c @@ -157,8 +157,8 @@ int spv_ParseModule(SpvModule *module, const uint32_t *code, uint32_t wordCount) /* Validate magic number (already byte-swapped) */ if (code[0] != SPV_MAGIC_NUMBER) { - IExec->DebugPrintF("[software_vk] SPIR-V magic mismatch: 0x%08lx\n", - (unsigned long)code[0]); + D(("[software_vk] SPIR-V magic mismatch: 0x%08lx\n", + (unsigned long)code[0])); return -1; } @@ -497,10 +497,10 @@ int spv_ParseModule(SpvModule *module, const uint32_t *code, uint32_t wordCount) pc += wc; } - IExec->DebugPrintF("[software_vk] SPIR-V parsed: %lu words, bound=%lu, entry=%lu\n", + D(("[software_vk] SPIR-V parsed: %lu words, bound=%lu, entry=%lu\n", (unsigned long)wordCount, (unsigned long)module->bound, - (unsigned long)module->entryPointId); + (unsigned long)module->entryPointId)); return (module->entryPointId != 0) ? 0 : -1; } @@ -4797,10 +4797,10 @@ void spv_BuildTemplate(SpvModule *mod) mod->templateBuilt = 1; - IExec->DebugPrintF("[software_vk] Template built: bound=%lu (%lu bytes values + %lu bytes ptrs)\n", + D(("[software_vk] Template built: bound=%lu (%lu bytes values + %lu bytes ptrs)\n", (unsigned long)bound, (unsigned long)(bound * sizeof(SpvValue)), - (unsigned long)(bound * sizeof(SpvPointer))); + (unsigned long)(bound * sizeof(SpvPointer)))); } void spv_FreeTemplate(SpvModule *mod) @@ -5799,8 +5799,8 @@ int spv_CompileProgram(SpvModule *module) /* Build template state for fast invocation setup */ spv_BuildTemplate(module); - IExec->DebugPrintF("[software_vk] SPIR-V compiled: %lu instructions\n", - (unsigned long)prog->instrCount); + D(("[software_vk] SPIR-V compiled: %lu instructions\n", + (unsigned long)prog->instrCount)); return 0; } diff --git a/software_icd/src/swvk_wsi.c b/software_icd/src/swvk_wsi.c index 7b8b25d..5b31ed4 100644 --- a/software_icd/src/swvk_wsi.c +++ b/software_icd/src/swvk_wsi.c @@ -46,7 +46,7 @@ static int swvk_OpenGraphics(void) GraphicsBase = IExec->OpenLibrary("graphics.library", 54); if (!GraphicsBase) { - IExec->DebugPrintF("[software_vk] Cannot open graphics.library\n"); + D(("[software_vk] Cannot open graphics.library\n")); return 0; } @@ -56,7 +56,7 @@ static int swvk_OpenGraphics(void) { IExec->CloseLibrary(GraphicsBase); GraphicsBase = NULL; - IExec->DebugPrintF("[software_vk] Cannot get graphics interface\n"); + D(("[software_vk] Cannot get graphics interface\n")); return 0; } @@ -313,9 +313,9 @@ VkResult swvk_CreateSwapchainKHR( *pSwapchain = (VkSwapchainKHR)(uintptr_t)sc; - IExec->DebugPrintF("[software_vk] Swapchain created: %lux%lu, %lu images\n", + D(("[software_vk] Swapchain created: %lux%lu, %lu images\n", (unsigned long)sc->width, (unsigned long)sc->height, - (unsigned long)sc->imageCount); + (unsigned long)sc->imageCount)); return VK_SUCCESS; @@ -362,7 +362,7 @@ void swvk_DestroySwapchainKHR(VkDevice device, IExec->FreeVec(sc); - IExec->DebugPrintF("[software_vk] Swapchain destroyed\n"); + D(("[software_vk] Swapchain destroyed\n")); } VkResult swvk_GetSwapchainImagesKHR(VkDevice device,