adding command list Vulkan support

This commit is contained in:
2024-11-17 10:52:29 +01:00
parent 0b417483f3
commit d8b14d1a7e
29 changed files with 716 additions and 186 deletions

View File

@@ -2,7 +2,8 @@
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <Pulse.h>
#include "PulseInternal.h"
@@ -25,36 +26,41 @@ static const PulseCheckBackendSupportPFN backends_supports[] = {
PULSE_NULLPTR
};
struct
{
char file[1024];
char function[1024];
PulseErrorType type;
int line;
} last_error = { .file = { 0 }, .function = { 0 }, .type = PULSE_ERROR_NONE, .line = -1 };
static PulseErrorType last_error = PULSE_ERROR_NONE;
void PulseSetInternalErrorBackend(PulseErrorType error, const char* file, const char* function, int line)
void PulseSetInternalError(PulseErrorType error)
{
strcpy(last_error.file, file);
strcpy(last_error.function, function);
last_error.type = error;
last_error.line = line;
last_error = error;
}
void PulseLogErrorBackend(PulseBackend backend, PulseErrorType error, const char* file, const char* function, int line)
#define LOG_MESSAGE_MAX_LENGTH 4096
void PulseLogBackend(PulseBackend backend, PulseDebugMessageSeverity type, const char* message, const char* file, const char* function, int line, ...)
{
(void)file; // May be used later
if(backend == PULSE_NULL_HANDLE)
return;
if(!backend->PFN_UserDebugCallback)
return;
}
void PulseLogWarningBackend(PulseBackend backend, PulseWarningType warning, const char* file, const char* function, int line)
{
}
va_list argptr;
va_start(argptr, line);
void PulseLogInfoBackend(PulseBackend backend, const char* message, const char* file, const char* function, int line)
{
char complete_message[LOG_MESSAGE_MAX_LENGTH] = { 0 };
int shift = 0;
if(type != PULSE_DEBUG_MESSAGE_SEVERITY_INFO)
{
shift = snprintf(complete_message, LOG_MESSAGE_MAX_LENGTH, "[%s:%d] ", function, line);
if(backend->debug_level == PULSE_PARANOID_DEBUG && type == PULSE_DEBUG_MESSAGE_SEVERITY_WARNING)
type = PULSE_DEBUG_MESSAGE_SEVERITY_ERROR;
if(shift == -1)
shift = 0;
}
vsnprintf(complete_message + shift, LOG_MESSAGE_MAX_LENGTH - shift, message, argptr);
backend->PFN_UserDebugCallback(type, complete_message);
va_end(argptr);
}
static PulseBackendFlags PulseSelectBackend(PulseBackendFlags backend_candidates, PulseShaderFormatsFlags shader_formats_used)
@@ -74,10 +80,6 @@ static PulseBackendFlags PulseSelectBackend(PulseBackendFlags backend_candidates
return PULSE_BACKEND_INVALID;
}
static const char* PulseVerbaliseErrorType(PulseErrorType error)
{
}
static PulseBackend PulseGetBackendFromFlag(PulseBackendBits flag)
{
switch(flag)
@@ -86,7 +88,7 @@ static PulseBackend PulseGetBackendFromFlag(PulseBackendBits flag)
case PULSE_BACKEND_VULKAN: return &VulkanDriver;
#endif
#ifdef PULSE_ENABLE_D3D11_BACKEND
case PULSE_BACKEND_VULKAN: return &D3D11Driver;
case PULSE_BACKEND_D3D11: return &D3D11Driver;
#endif
default: break;
@@ -106,6 +108,7 @@ PULSE_API PulseBackend PulseLoadBackend(PulseBackendFlags backend_candidates, Pu
if(!backend->PFN_LoadBackend(debug_level))
return PULSE_NULL_HANDLE;
backend->PFN_UserDebugCallback = PULSE_NULLPTR;
backend->debug_level = debug_level;
return (PulseBackend)backend;
}
@@ -115,6 +118,12 @@ PULSE_API void PulseUnloadBackend(PulseBackend backend)
backend->PFN_UnloadBackend(backend);
}
PULSE_API PulseBackendFlags PulseGetBackendType(PulseBackend backend)
{
PULSE_CHECK_HANDLE_RETVAL(backend, PULSE_BACKEND_INVALID);
return backend->backend;
}
PULSE_API bool PulseSupportsBackend(PulseBackendFlags backend_candidates, PulseShaderFormatsFlags shader_formats_used)
{
if((backend_candidates & PULSE_BACKEND_INVALID) != 0)
@@ -133,3 +142,27 @@ PULSE_API void PulseSetDebugCallback(PulseBackend backend, PulseDebugCallbackPFN
PULSE_CHECK_HANDLE(backend);
backend->PFN_UserDebugCallback = callback;
}
PULSE_API PulseErrorType PulseGetLastErrorType()
{
PulseErrorType error = last_error;
last_error = PULSE_ERROR_NONE;
return error;
}
PULSE_API const char* PulseVerbaliseErrorType(PulseErrorType error)
{
switch(error)
{
case PULSE_ERROR_NONE: return "no error";
case PULSE_ERROR_BACKENDS_CANDIDATES_SHADER_FORMAT_MISMATCH: return "no backend candidates support the required shader formats";
case PULSE_ERROR_INITIALIZATION_FAILED: return "initialization of an object could not be completed for implementation-specific reasons";
case PULSE_ERROR_CPU_ALLOCATION_FAILED: return "an internal CPU allocation failed";
case PULSE_ERROR_DEVICE_ALLOCATION_FAILED: return "a device allocation failed";
case PULSE_ERROR_DEVICE_LOST: return "device has been lost";
case PULSE_ERROR_INVALID_INTERNAL_POINTER: return "invalid internal pointer";
default: return "invalid error type";
};
return PULSE_NULLPTR; // To avoid warnings, should be unreachable
}