<commit_before>#include <magma.h>

#define MAGMA_EXTERN
#include <mantle.h>
#include <mantleDbg.h>
#include <mantleWsiWinExt.h>

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#define LOAD(module, function) *(void **)&function = (void *)GetProcAddress(module, #function)
#define FREE(function) function = NULL



static int     g_count  = 0;
static HMODULE g_mantle = NULL;

MAGMA_STDCALL MAGMA_RESULT magmaInit(void) {
	if(g_count++ > 0) {
		return MAGMA_SUCCESS;
	}

	g_mantle = LoadLibrary("mantle64.dll");
	if(!g_mantle) {
		--g_count;
		return MAGMA_ERROR_DLL_NOT_FOUND;
	}

	LOAD(g_mantle, grInitAndEnumerateGpus);
	LOAD(g_mantle, grGetGpuInfo);
	LOAD(g_mantle, grCreateDevice);
	LOAD(g_mantle, grDestroyDevice);

	LOAD(g_mantle, grGetExtensionSupport);
	
	LOAD(g_mantle, grGetDeviceQueue);
	LOAD(g_mantle, grQueueWaitIdle);
	LOAD(g_mantle, grDeviceWaitIdle);
	LOAD(g_mantle, grQueueSubmit);
	LOAD(g_mantle, grQueueSetGlobalMemReferences);

	LOAD(g_mantle, grDestroyObject);
	LOAD(g_mantle, grGetObjectInfo);
	LOAD(g_mantle, grBindObjectMemory);

	LOAD(g_mantle, grCreateCommandBuffer);
	LOAD(g_mantle, grBeginCommandBuffer);
	LOAD(g_mantle, grEndCommandBuffer);
	LOAD(g_mantle, grResetCommandBuffer);

	LOAD(g_mantle, grCmdPrepareMemoryRegions);
	LOAD(g_mantle, grCmdPrepareImages);
	LOAD(g_mantle, grCmdClearColorImage);
	LOAD(g_mantle, grCmdClearColorImageRaw);

	LOAD(g_mantle, grDbgSetValidationLevel);
	LOAD(g_mantle, grDbgRegisterMsgCallback);
	LOAD(g_mantle, grDbgUnregisterMsgCallback);
	LOAD(g_mantle, grDbgSetMessageFilter);
	LOAD(g_mantle, grDbgSetObjectTag);
	LOAD(g_mantle, grDbgSetGlobalOption);
	LOAD(g_mantle, grDbgSetDeviceOption);
	LOAD(g_mantle, grCmdDbgMarkerBegin);
	LOAD(g_mantle, grCmdDbgMarkerEnd);

	LOAD(g_mantle, grWsiWinGetDisplays);
	LOAD(g_mantle, grWsiWinGetDisplayModeList);
	LOAD(g_mantle, grWsiWinTakeFullscreenOwnership);
	LOAD(g_mantle, grWsiWinReleaseFullscreenOwnership);
	LOAD(g_mantle, grWsiWinSetGammaRamp);
	LOAD(g_mantle, grWsiWinWaitForVerticalBlank);
	LOAD(g_mantle, grWsiWinGetScanLine);
	LOAD(g_mantle, grWsiWinCreatePresentableImage);
	LOAD(g_mantle, grWsiWinQueuePresent);
	LOAD(g_mantle, grWsiWinSetMaxQueuedFrames);

	return MAGMA_SUCCESS;
}

MAGMA_STDCALL void magmaTerminate(void) {
	if(g_count == 0 || --g_count > 0) {
		return;
	}

	FREE(grInitAndEnumerateGpus);
	FREE(grGetGpuInfo);
	FREE(grCreateDevice);
	FREE(grDestroyDevice);

	FREE(grGetExtensionSupport);
	
	FREE(grGetDeviceQueue);
	FREE(grQueueWaitIdle);
	FREE(grDeviceWaitIdle);
	FREE(grQueueSubmit);
	FREE(grQueueSetGlobalMemReferences);

	FREE(grDestroyObject);
	FREE(grGetObjectInfo);
	FREE(grBindObjectMemory);

	FREE(grCreateCommandBuffer);<commit_msg>Update magma.c<commit_after>#include <magma.h>

#define MAGMA_EXTERN
#include <mantle.h>
#include <mantleDbg.h>
#include <mantleWsiWinExt.h>

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#define LOAD(module, function) *(void **)&function = (void *)GetProcAddress(module, #function)
#define FREE(function) function = NULL



static int     g_count  = 0;
static HMODULE g_mantle = NULL;

MAGMA_STDCALL MAGMA_RESULT magmaInit(void) {
	if(g_count++ > 0) {
		return MAGMA_SUCCESS;
	}

	g_mantle = LoadLibrary("mantle64.dll");
	if(!g_mantle) {
		--g_count;
		return MAGMA_ERROR_DLL_NOT_FOUND;
	}

	LOAD(g_mantle, grInitAndEnumerateGpus);
	LOAD(g_mantle, grGetGpuInfo);
	LOAD(g_mantle, grCreateDevice);
	LOAD(g_mantle, grDestroyDevice);

	LOAD(g_mantle, grGetExtensionSupport);
	
	LOAD(g_mantle, grGetDeviceQueue);
	LOAD(g_mantle, grQueueWaitIdle);
	LOAD(g_mantle, grDeviceWaitIdle);
	LOAD(g_mantle, grQueueSubmit);
	LOAD(g_mantle, grQueueSetGlobalMemReferences);

	LOAD(g_mantle, grGetMemoryHeapCount);
	LOAD(g_mantle, grGetMemoryHeapInfo);
	LOAD(g_mantle, grAllocMemory);
	LOAD(g_mantle, grFreeMemory);
	LOAD(g_mantle, grSetMemoryPriority);
	LOAD(g_mantle, grMapMemory);
	LOAD(g_mantle, grUnmapMemory);
	LOAD(g_mantle, grRemapVirtualMemoryPages);
	LOAD(g_mantle, grPinSystemMemory);

	LOAD(g_mantle, grDestroyObject);
	LOAD(g_mantle, grGetObjectInfo);
	LOAD(g_mantle, grBindObjectMemory);

	LOAD(g_mantle, grCreateCommandBuffer);
	LOAD(g_mantle, grBeginCommandBuffer);
	LOAD(g_mantle, grEndCommandBuffer);
	LOAD(g_mantle, grResetCommandBuffer);

	LOAD(g_mantle, grCmdPrepareMemoryRegions);
	LOAD(g_mantle, grCmdPrepareImages);
	LOAD(g_mantle, grCmdClearColorImage);
	LOAD(g_mantle, grCmdClearColorImageRaw);

	LOAD(g_mantle, grDbgSetValidationLevel);
	LOAD(g_mantle, grDbgRegisterMsgCallback);
	LOAD(g_mantle, grDbgUnregisterMsgCallback);
	LOAD(g_mantle, grDbgSetMessageFilter);
	LOAD(g_mantle, grDbgSetObjectTag);
	LOAD(g_mantle, grDbgSetGlobalOption);
	LOAD(g_mantle, grDbgSetDeviceOption);
	LOAD(g_mantle, grCmdDbgMarkerBegin);
	LOAD(g_mantle, grCmdDbgMarkerEnd);

	LOAD(g_mantle, grWsiWinGetDisplays);
	LOAD(g_mantle, grWsiWinGetDisplayModeList);
	LOAD(g_mantle, grWsiWinTakeFullscreenOwnership);
	LOAD(g_mantle, grWsiWinReleaseFullscreenOwnership);
	LOAD(g_mantle, grWsiWinSetGammaRamp);
	LOAD(g_mantle, grWsiWinWaitForVerticalBlank);
	LOAD(g_mantle, grWsiWinGetScanLine);
	LOAD(g_mantle, grWsiWinCreatePresentableImage);
	LOAD(g_mantle, grWsiWinQueuePresent);
	LOAD(g_mantle, grWsiWinSetMaxQueuedFrames);

	return MAGMA_SUCCESS;
}

MAGMA_STDCALL void magmaTerminate(void) {
	if(g_count == 0 || --g_count > 0) {
		return;
	}

	FREE(grInitAndEnumerateGpus);
	FREE(grGetGpuInfo);
	FREE(grCreateDevice);
	FREE(grDestroyDevice);

	FREE(grGetExtensionSupport);
	
	FREE(grGetDeviceQueue);
	FREE(grQueueWaitIdle);
	FREE(grDeviceWaitIdle);
	FREE(grQueueSubmit);
	FREE(grQueueSetGlobalMemReferences);

	FREE(grGetMemoryHeapCount);
	FREE(grGetMemoryHeapInfo);
	FREE(grAllocMemory);
	FREE(grFreeMemory);
	FREE(grSetMemoryPriority);
	FREE(grMapMemory);
	FREE(grUnmapMemory);
	FREE(grRemapVirtualMemoryPages);
	FREE(grPinSystemMemory);

	FREE(grDestroyObject);
	FREE(grGetObjectInfo);
	FREE(grBindObjectMemory);

	FREE(grCreateCommandBuffer);
{'fraction_non_alphanumeric': 0.11124260355029586, 'fraction_numerical': 0.002704987320371936, 'mean_word_length': 8.762376237623762, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3334929', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2315, 'n_words': 329}