Merge pull request #6300 from jakubtomsu/more-import-cleanup

More import cleanup and simplification
This commit is contained in:
Jeroen van Rijn
2026-02-18 12:15:24 +01:00
committed by GitHub
11 changed files with 88 additions and 82 deletions

View File

@@ -1,7 +1,5 @@
package hash
import "base:intrinsics"
@(optimization_mode="favor_size")
crc32 :: proc "contextless" (data: []byte, seed := u32(0)) -> u32 #no_bounds_check {
crc := ~seed

View File

@@ -1,7 +1,6 @@
package hash
import "core:mem"
import "base:intrinsics"
@(optimization_mode="favor_size")
adler32 :: proc "contextless" (data: []byte, seed := u32(1)) -> u32 #no_bounds_check {
@@ -57,14 +56,14 @@ djb2 :: proc "contextless" (data: []byte, seed := u32(5381)) -> u32 {
djbx33a :: proc "contextless" (data: []byte, seed := u32(5381)) -> (result: [16]byte) #no_bounds_check {
state := [4]u32{seed, seed, seed, seed}
s: u32 = 0
for p in data {
state[s] = (state[s] << 5) + state[s] + u32(p) // hash * 33 + u32(b)
s = (s + 1) & 3
}
(^u32le)(&result[0])^ = u32le(state[0])
(^u32le)(&result[4])^ = u32le(state[1])
(^u32le)(&result[8])^ = u32le(state[2])
@@ -160,7 +159,7 @@ murmur32 :: proc "contextless" (data: []byte, seed := u32(0x9747b28c)) -> u32 {
case 1:
k1 ~= u32(tail[0])
k1 *= c1_32
k1 = (k1 << 15) | (k1 >> 17)
k1 = (k1 << 15) | (k1 >> 17)
k1 *= c2_32
h1 ~= k1
}

View File

@@ -3,8 +3,6 @@ package rand
import "base:intrinsics"
import "base:runtime"
import "core:math/bits"
/*
The state for a xoshiro256** pseudorandom generator.
*/
@@ -17,7 +15,7 @@ xoshiro256_random_generator_proc :: proc(data: rawptr, mode: runtime.Random_Gene
read_u64 :: proc "contextless" (r: ^Xoshiro256_Random_State) -> u64 {
// xoshiro256** output function and state transition
result := bits.rotate_left64(r.s[1] * 5, 7) * 9
result := rotate_left64(r.s[1] * 5, 7) * 9
t := r.s[1] << 17
r.s[2] = r.s[2] ~ r.s[0]
@@ -25,9 +23,15 @@ xoshiro256_random_generator_proc :: proc(data: rawptr, mode: runtime.Random_Gene
r.s[1] = r.s[1] ~ r.s[2]
r.s[0] = r.s[0] ~ r.s[3]
r.s[2] = r.s[2] ~ t
r.s[3] = bits.rotate_left64(r.s[3], 45)
r.s[3] = rotate_left64(r.s[3], 45)
return result
rotate_left64 :: proc "contextless" (x: u64, k: int) -> u64 {
n :: 64
s := uint(k) & (n-1)
return x << s | x >> (n-s)
}
}
@(thread_local)

View File

@@ -25,7 +25,6 @@ package net
import "base:runtime"
import "core:bufio"
import "core:io"
import "core:math/rand"
import "core:mem"
import "core:strings"
import "core:time"
@@ -192,7 +191,10 @@ get_dns_records_from_nameservers :: proc(hostname: string, type: DNS_Record_Type
init_dns_configuration()
context.allocator = allocator
id := u16be(rand.uint32())
id: u16be
rand_ok := runtime.random_generator_read_ptr(context.random_generator, &id, size_of(id))
assert(rand_ok, "uninitialized gen/context.random_generator")
dns_packet_buf: [DNS_PACKET_MIN_LEN]byte = ---
dns_packet := make_dns_packet(dns_packet_buf[:], id, hostname, type) or_return

View File

@@ -4,7 +4,7 @@ package directx_d3d11
foreign import "system:d3d11.lib"
import "../dxgi"
import "../d3d_compiler"
import "../d3d_common"
import "core:sys/windows"
IUnknown :: dxgi.IUnknown
@@ -26,9 +26,7 @@ LPCWSTR :: windows.LPCWSTR
RECT :: dxgi.RECT
SIZE :: dxgi.SIZE
IModuleInstance :: d3d_compiler.ID3D11ModuleInstance
IBlob :: d3d_compiler.ID3DBlob
IModule :: d3d_compiler.ID3D11Module
IBlob :: d3d_common.ID3DBlob
@(default_calling_convention="system", link_prefix="D3D11")
foreign d3d11 {
@@ -3569,6 +3567,34 @@ PARAMETER_DESC :: struct {
FirstOutComponent: u32,
}
IModule :: struct #raw_union {
#subtype iunknown: IUnknown,
using id3d11module_vtable: ^IModule_VTable,
}
IModule_VTable :: struct {
using iunknown_vtable: IUnknown_VTable,
CreateInstance: proc "system" (this: ^IModule, pNamespace: LPCSTR, ppModuleInstance: ^^IModuleInstance) -> HRESULT,
}
IModuleInstance :: struct #raw_union {
#subtype iunknown: IUnknown,
using id3d11moduleinstance_vtable: ^IModuleInstance_VTable,
}
IModuleInstance_VTable :: struct {
using iunknown_vtable: IUnknown_VTable,
BindConstantBuffer: proc "system" (this: ^IModuleInstance, uSrcSlot: u32, uDstSlot: u32, cbDstOffset: u32) -> HRESULT,
BindConstantBufferByName: proc "system" (this: ^IModuleInstance, pName: LPCSTR, uDstSlot: u32, cbDstOffset: u32) -> HRESULT,
BindResource: proc "system" (this: ^IModuleInstance, uSrcSlot: u32, uDstSlot: u32, uCount: u32) -> HRESULT,
BindResourceByName: proc "system" (this: ^IModuleInstance, pName: LPCSTR, uDstSlot: u32, uCount: u32) -> HRESULT,
BindSampler: proc "system" (this: ^IModuleInstance, uSrcSlot: u32, uDstSlot: u32, uCount: u32) -> HRESULT,
BindSamplerByName: proc "system" (this: ^IModuleInstance, pName: LPCSTR, uDstSlot: u32, uCount: u32) -> HRESULT,
BindUnorderedAccessView: proc "system" (this: ^IModuleInstance, uSrcSlot: u32, uDstSlot: u32, uCount: u32) -> HRESULT,
BindUnorderedAccessViewByName: proc "system" (this: ^IModuleInstance, pName: LPCSTR, uDstSlot: u32, uCount: u32) -> HRESULT,
BindResourceAsUnorderedAccessView: proc "system" (this: ^IModuleInstance, uSrcSrvSlot: u32, uDstUavSlot: u32, uCount: u32) -> HRESULT,
BindResourceAsUnorderedAccessViewByName: proc "system" (this: ^IModuleInstance, pSrvName: LPCSTR, uDstUavSlot: u32, uCount: u32) -> HRESULT,
}
ID3D11ShaderReflectionType_UUID_STRING :: "6E6FFA6A-9BAE-4613-A51E-91652D508C21"
ID3D11ShaderReflectionType_UUID := &IID{0x6E6FFA6A, 0x9BAE, 0x4613, {0xA5, 0x1E, 0x91, 0x65, 0x2D, 0x50, 0x8C, 0x21}}
IShaderReflectionType :: struct {

View File

@@ -4,7 +4,7 @@ package directx_d3d12
foreign import "system:d3d12.lib"
import "../dxgi"
import "../d3d_compiler"
import "../d3d_common"
import win32 "core:sys/windows"
IUnknown :: dxgi.IUnknown
@@ -26,9 +26,7 @@ RECT :: dxgi.RECT
LPCSTR :: win32.LPCSTR
LPCWSTR :: win32.LPCWSTR
IModuleInstance :: d3d_compiler.ID3D11ModuleInstance
IBlob :: d3d_compiler.ID3DBlob
IModule :: d3d_compiler.ID3D11Module
IBlob :: d3d_common.ID3DBlob
@(default_calling_convention="system", link_prefix="D3D12")
foreign d3d12 {
@@ -1236,7 +1234,7 @@ TRI_STATE :: enum i32 {
UNKNOWN = -1,
FALSE = 0,
TRUE = 1,
}
}
FEATURE_DATA_OPTIONS12 :: struct {
MSPrimitivesPipelineStatisticIncludesCulledPrimitives: TRI_STATE,
@@ -2597,7 +2595,7 @@ IDescriptorHeap_VTable :: struct {
GetDesc: proc "system" (this: ^IDescriptorHeap, desc: ^DESCRIPTOR_HEAP_DESC),
GetCPUDescriptorHandleForHeapStart: proc "system" (this: ^IDescriptorHeap, handle: ^CPU_DESCRIPTOR_HANDLE),
GetGPUDescriptorHandleForHeapStart: proc "system" (this: ^IDescriptorHeap, handle: ^GPU_DESCRIPTOR_HANDLE),
}
}
IQueryHeap_UUID_STRING :: "0d9658ae-ed45-469e-a61d-970ec583cab4"
IQueryHeap_UUID := &IID{0x0d9658ae, 0xed45, 0x469e, {0xa6, 0x1d, 0x97, 0x0e, 0xc5, 0x83, 0xca, 0xb4}}
@@ -5495,7 +5493,7 @@ IGraphicsCommandList7_VTable :: struct {
SHADER_VERSION_TYPE :: enum u32 {
PIXEL_SHADER = 0,
VERTEX_SHADER = 1,
GEOMETRY_SHADER = 2,
GEOMETRY_SHADER = 2,
HULL_SHADER = 3,
DOMAIN_SHADER = 4,

View File

@@ -0,0 +1,25 @@
// Declarations shared between D3D versions.
// Based on d3dcommon.h
package d3d_common
import "core:sys/windows"
IID :: windows.IID
SIZE_T :: windows.SIZE_T
IUnknown :: windows.IUnknown
IUnknown_VTable :: windows.IUnknown_VTable
ID3D10Blob_UUID_STRING :: "8BA5FB08-5195-40E2-AC58-0D989C3A0102"
ID3D10Blob_UUID := &IID{0x8BA5FB08, 0x5195, 0x40E2, {0xAC, 0x58, 0x0D, 0x98, 0x9C, 0x3A, 0x01, 0x02}}
ID3D10Blob :: struct #raw_union {
#subtype iunknown: IUnknown,
using id3d10blob_vtable: ^ID3D10Blob_VTable,
}
ID3D10Blob_VTable :: struct {
using iunknown_vtable: IUnknown_VTable,
GetBufferPointer: proc "system" (this: ^ID3D10Blob) -> rawptr,
GetBufferSize: proc "system" (this: ^ID3D10Blob) -> SIZE_T,
}
ID3DBlob :: ID3D10Blob
ID3DBlob_VTable :: ID3D10Blob_VTable

View File

@@ -7,8 +7,9 @@ import win32 "core:sys/windows"
D3DCOMPILER_DLL_A :: "d3dcompiler_47.dll"
COMPILER_VERSION :: 47
import "../dxgi"
import "../d3d11"
import "../d3d_common"
BOOL :: dxgi.BOOL
IID :: dxgi.IID
@@ -17,6 +18,8 @@ HRESULT :: dxgi.HRESULT
IUnknown :: dxgi.IUnknown
IUnknown_VTable :: dxgi.IUnknown_VTable
ID3DBlob :: d3d_common.ID3DBlob
LPCSTR :: win32.LPCSTR
LPCWSTR :: win32.LPCWSTR
@@ -34,7 +37,7 @@ foreign d3dcompiler {
Disassemble :: proc(pSrcData: rawptr, SrcDataSize: SIZE_T, Flags: u32, szComments: LPCSTR, ppDisassembly: ^^ID3DBlob) -> HRESULT ---
DisassembleRegion :: proc(pSrcData: rawptr, SrcDataSize: SIZE_T, Flags: u32, szComments: LPCSTR, StartByteOffset: SIZE_T, NumInsts: SIZE_T, pFinishByteOffset: ^SIZE_T, ppDisassembly: ^^ID3DBlob) -> HRESULT ---
CreateLinker :: proc(ppLinker: ^^ID3D11Linker) -> HRESULT ---
LoadModule :: proc(pSrcData: rawptr, cbSrcDataSize: SIZE_T, ppModule: ^^ID3D11Module) -> HRESULT ---
LoadModule :: proc(pSrcData: rawptr, cbSrcDataSize: SIZE_T, ppModule: ^^d3d11.IModule) -> HRESULT ---
GetTraceInstructionOffsets :: proc(pSrcData: rawptr, SrcDataSize: SIZE_T, Flags: u32, StartInstIndex: SIZE_T, NumInsts: SIZE_T, pOffsets: ^SIZE_T, pTotalInsts: ^SIZE_T) -> HRESULT ---
GetInputSignatureBlob :: proc(pSrcData: rawptr, SrcDataSize: SIZE_T, ppSignatureBlob: ^^ID3DBlob) -> HRESULT ---
GetOutputSignatureBlob :: proc(pSrcData: rawptr, SrcDataSize: SIZE_T, ppSignatureBlob: ^^ID3DBlob) -> HRESULT ---
@@ -121,29 +124,11 @@ SHADER_MACRO :: struct {
Definition: LPCSTR,
}
ID3D10Blob_UUID_STRING :: "8BA5FB08-5195-40E2-AC58-0D989C3A0102"
ID3D10Blob_UUID := &IID{0x8BA5FB08, 0x5195, 0x40E2, {0xAC, 0x58, 0x0D, 0x98, 0x9C, 0x3A, 0x01, 0x02}}
ID3D10Blob :: struct #raw_union {
#subtype iunknown: IUnknown,
using id3d10blob_vtable: ^ID3D10Blob_VTable,
}
ID3D10Blob_VTable :: struct {
using iunknown_vtable: IUnknown_VTable,
GetBufferPointer: proc "system" (this: ^ID3D10Blob) -> rawptr,
GetBufferSize: proc "system" (this: ^ID3D10Blob) -> SIZE_T,
}
ID3DBlob :: ID3D10Blob
ID3DBlob_VTable :: ID3D10Blob_VTable
INCLUDE_TYPE :: enum i32 {
INCLUDE_LOCAL = 0,
INCLUDE_SYSTEM = 1,
_10_INCLUDE_LOCAL = 0,
_10_INCLUDE_SYSTEM = 1,
INCLUDE_FORCE_DWORD = 2147483647,
}
ID3DInclude :: struct {
@@ -158,43 +143,14 @@ ID3DInclude_VTable :: struct {
D3DCOMPILE_STANDARD_FILE_INCLUDE :: (^ID3DInclude)(uintptr(1))
ID3D11Module :: struct #raw_union {
#subtype iunknown: IUnknown,
using id3d11module_vtable: ^ID3D11Module_VTable,
}
ID3D11Module_VTable :: struct {
using iunknown_vtable: IUnknown_VTable,
CreateInstance: proc "system" (this: ^ID3D11Module, pNamespace: LPCSTR, ppModuleInstance: ^^ID3D11ModuleInstance) -> HRESULT,
}
ID3D11ModuleInstance :: struct #raw_union {
#subtype iunknown: IUnknown,
using id3d11moduleinstance_vtable: ^ID3D11ModuleInstance_VTable,
}
ID3D11ModuleInstance_VTable :: struct {
using iunknown_vtable: IUnknown_VTable,
BindConstantBuffer: proc "system" (this: ^ID3D11ModuleInstance, uSrcSlot: u32, uDstSlot: u32, cbDstOffset: u32) -> HRESULT,
BindConstantBufferByName: proc "system" (this: ^ID3D11ModuleInstance, pName: LPCSTR, uDstSlot: u32, cbDstOffset: u32) -> HRESULT,
BindResource: proc "system" (this: ^ID3D11ModuleInstance, uSrcSlot: u32, uDstSlot: u32, uCount: u32) -> HRESULT,
BindResourceByName: proc "system" (this: ^ID3D11ModuleInstance, pName: LPCSTR, uDstSlot: u32, uCount: u32) -> HRESULT,
BindSampler: proc "system" (this: ^ID3D11ModuleInstance, uSrcSlot: u32, uDstSlot: u32, uCount: u32) -> HRESULT,
BindSamplerByName: proc "system" (this: ^ID3D11ModuleInstance, pName: LPCSTR, uDstSlot: u32, uCount: u32) -> HRESULT,
BindUnorderedAccessView: proc "system" (this: ^ID3D11ModuleInstance, uSrcSlot: u32, uDstSlot: u32, uCount: u32) -> HRESULT,
BindUnorderedAccessViewByName: proc "system" (this: ^ID3D11ModuleInstance, pName: LPCSTR, uDstSlot: u32, uCount: u32) -> HRESULT,
BindResourceAsUnorderedAccessView: proc "system" (this: ^ID3D11ModuleInstance, uSrcSrvSlot: u32, uDstUavSlot: u32, uCount: u32) -> HRESULT,
BindResourceAsUnorderedAccessViewByName: proc "system" (this: ^ID3D11ModuleInstance, pSrvName: LPCSTR, uDstUavSlot: u32, uCount: u32) -> HRESULT,
}
ID3D11Linker :: struct #raw_union {
#subtype iunknown: IUnknown,
using id3d11linker_vtable: ^ID3D11Linker_VTable,
}
ID3D11Linker_VTable :: struct {
using iunknown_vtable: IUnknown_VTable,
Link: proc "system" (this: ^ID3D11Linker, pEntry: ^ID3D11ModuleInstance, pEntryName: LPCSTR, pTargetName: LPCSTR, uFlags: u32, ppShaderBlob: ^^ID3DBlob, ppErrorBuffer: ^^ID3DBlob) -> HRESULT,
UseLibrary: proc "system" (this: ^ID3D11Linker, pLibraryMI: ^ID3D11ModuleInstance) -> HRESULT,
Link: proc "system" (this: ^ID3D11Linker, pEntry: ^d3d11.IModuleInstance, pEntryName: LPCSTR, pTargetName: LPCSTR, uFlags: u32, ppShaderBlob: ^^ID3DBlob, ppErrorBuffer: ^^ID3DBlob) -> HRESULT,
UseLibrary: proc "system" (this: ^ID3D11Linker, pLibraryMI: ^d3d11.IModuleInstance) -> HRESULT,
AddClipPlaneFromCBuffer: proc "system" (this: ^ID3D11Linker, uCBufferSlot: u32, uCBufferEntry: u32) -> HRESULT,
}

View File

@@ -194,7 +194,7 @@ ICompiler :: struct #raw_union {
ICompiler_VTable :: struct {
using iunknown_vtable: IUnknown_VTable,
Compile: proc "system" (
this: ^ICompiler,
this: ^ICompiler,
pSource: ^IBlob,
pSourceName: wstring,
pEntryPoint: wstring,
@@ -206,7 +206,7 @@ ICompiler_VTable :: struct {
pIncludeHandler: ^IIncludeHandler,
ppResult: ^^IOperationResult) -> HRESULT,
Preprocess: proc "system" (
this: ^ICompiler,
this: ^ICompiler,
pSource: ^IBlob,
pSourceName: wstring,
pArguments: [^]wstring,
@@ -303,7 +303,6 @@ DXC_OUT_KIND :: enum u32 {
REFLECTION = 8,
ROOT_SIGNATURE = 9,
EXTRA_OUTPUTS = 10,
FORCE_DWORD = 0xFFFFFFFF,
}
IResult_UUID_STRING :: "58346CDA-DDE7-4497-9461-6F87AF5E0659"

View File

@@ -752,7 +752,6 @@ ALPHA_MODE :: enum i32 {
PREMULTIPLIED = 1,
STRAIGHT = 2,
IGNORE = 3,
FORCE_DWORD = -1,
}

View File

@@ -1,6 +1,6 @@
package miniaudio
import "core:c/libc"
import "core:c"
foreign import lib { LIB }
@@ -48,12 +48,12 @@ log :: struct {
@(default_calling_convention="c", link_prefix="ma_")
foreign lib {
log_callback_init :: proc(onLog: log_callback_proc, pUserData: rawptr) -> log_callback ---
log_init :: proc(pAllocationCallbacks: ^allocation_callbacks, pLog: ^log) -> result ---
log_uninit :: proc(pLog: ^log) ---
log_register_callback :: proc(pLog: ^log, callback: log_callback) -> result ---
log_unregister_callback :: proc(pLog: ^log, callback: log_callback) -> result ---
log_post :: proc(pLog: ^log, level: u32, pMessage: cstring) -> result ---
log_postv :: proc(pLog: ^log, level: u32, pFormat: cstring, args: libc.va_list) -> result ---
log_postv :: proc(pLog: ^log, level: u32, pFormat: cstring, args: c.va_list) -> result ---
log_postf :: proc(pLog: ^log, level: u32, pFormat: cstring, #c_vararg args: ..any) -> result ---
}