diff --git a/Kinc/.clangd b/Kinc/.clangd deleted file mode 100644 index 532ac77..0000000 --- a/Kinc/.clangd +++ /dev/null @@ -1,2 +0,0 @@ -CompileFlags: - Add: [-D,KINC_EDITOR_SUPPORT, -Wall] \ No newline at end of file diff --git a/Kinc/Backends/Audio2/DirectSound/Sources/kinc/backend/DirectSound.cpp b/Kinc/Backends/Audio2/DirectSound/Sources/kinc/backend/DirectSound.cpp index beeabb1..cf2bcc6 100644 --- a/Kinc/Backends/Audio2/DirectSound/Sources/kinc/backend/DirectSound.cpp +++ b/Kinc/Backends/Audio2/DirectSound/Sources/kinc/backend/DirectSound.cpp @@ -6,6 +6,8 @@ #include +#include + namespace { IDirectSound8 *dsound = nullptr; IDirectSoundBuffer *dbuffer = nullptr; @@ -19,7 +21,6 @@ namespace { const int gap = 10 * 1024; DWORD writePos = gap; - void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = nullptr; kinc_a2_buffer_t a2_buffer; } @@ -30,12 +31,15 @@ void kinc_a2_init() { return; } + kinc_a2_internal_init(); initialized = true; a2_buffer.read_location = 0; a2_buffer.write_location = 0; a2_buffer.data_size = 128 * 1024; - a2_buffer.data = new uint8_t[a2_buffer.data_size]; + a2_buffer.channel_count = 2; + a2_buffer.channels[0] = new float[a2_buffer.data_size]; + a2_buffer.channels[1] = new float[a2_buffer.data_size]; kinc_microsoft_affirm(DirectSoundCreate8(nullptr, &dsound, nullptr)); // TODO (DK) only for the main window? @@ -61,25 +65,29 @@ void kinc_a2_init() { kinc_microsoft_affirm(dsound->CreateSoundBuffer(&bufferDesc, &dbuffer, nullptr)); DWORD size1; - uint8_t *buffer1; + uint8_t *buffer1 = NULL; kinc_microsoft_affirm(dbuffer->Lock(writePos, gap, (void **)&buffer1, &size1, nullptr, nullptr, 0)); - for (int i = 0; i < gap; ++i) + assert(buffer1 != NULL); + for (DWORD i = 0; i < size1; ++i) { buffer1[i] = 0; + } kinc_microsoft_affirm(dbuffer->Unlock(buffer1, size1, nullptr, 0)); kinc_microsoft_affirm(dbuffer->Play(0, 0, DSBPLAY_LOOPING)); } -void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) { - a2_callback = kinc_a2_audio_callback; +uint32_t kinc_a2_samples_per_second(void) { + return samplesPerSecond; } namespace { - void copySample(uint8_t *buffer, DWORD &index) { - float value = *(float *)&a2_buffer.data[a2_buffer.read_location]; - a2_buffer.read_location += 4; - if (a2_buffer.read_location >= a2_buffer.data_size) { - a2_buffer.read_location = 0; + void copySample(uint8_t *buffer, DWORD &index, bool left) { + float value = *(float *)&a2_buffer.channels[left ? 0 : 1][a2_buffer.read_location]; + if (!left) { + a2_buffer.read_location += 1; + if (a2_buffer.read_location >= a2_buffer.data_size) { + a2_buffer.read_location = 0; + } } *(int16_t *)&buffer[index] = static_cast(value * 32767); index += 2; @@ -92,47 +100,49 @@ void kinc_a2_update() { kinc_microsoft_affirm(dbuffer->GetCurrentPosition(&playPosition, &writePosition)); int dif; - if (writePos >= writePosition) + if (writePos >= writePosition) { dif = writePos - writePosition; - else - dif = dsize - writePosition + writePos; - - if (dif < gap) - return; - if (writePos + gap >= dsize) { - if (playPosition >= writePos || playPosition <= gap) - return; - if (writePosition >= writePos || writePosition <= gap) - return; } else { - if (playPosition >= writePos && playPosition <= writePos + gap) - return; - if (writePosition >= writePos && writePosition <= writePos + gap) - return; + dif = dsize - writePosition + writePos; } - a2_callback(&a2_buffer, gap / 2); + if (dif < gap) { + return; + } + if (writePos + gap >= dsize) { + if (playPosition >= writePos || playPosition <= gap) { + return; + } + if (writePosition >= writePos || writePosition <= gap) { + return; + } + } + else { + if (playPosition >= writePos && playPosition <= writePos + gap) { + return; + } + if (writePosition >= writePos && writePosition <= writePos + gap) { + return; + } + } - DWORD size1, size2; - uint8_t *buffer1, *buffer2; - kinc_microsoft_affirm(dbuffer->Lock(writePos, gap, (void **)&buffer1, &size1, (void **)&buffer2, &size2, 0)); + kinc_a2_internal_callback(&a2_buffer, (uint32_t)(gap / 4)); + + DWORD size1; + uint8_t *buffer1; + kinc_microsoft_affirm(dbuffer->Lock(writePos, gap, (void **)&buffer1, &size1, NULL, NULL, 0)); for (DWORD i = 0; i < size1 - (bitsPerSample / 8 - 1);) { - copySample(buffer1, i); + copySample(buffer1, i, ((writePos + i) / 2) % 2 == 0); } writePos += size1; - if (buffer2 != nullptr) { - for (DWORD i = 0; i < size2 - (bitsPerSample / 8 - 1);) { - copySample(buffer2, i); - } - writePos = size2; - } - kinc_microsoft_affirm(dbuffer->Unlock(buffer1, size1, buffer2, size2)); + kinc_microsoft_affirm(dbuffer->Unlock(buffer1, size1, NULL, 0)); - if (writePos >= dsize) + if (writePos >= dsize) { writePos -= dsize; + } } void kinc_a2_shutdown() { diff --git a/Kinc/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c b/Kinc/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c index 079a07f..d80c782 100644 --- a/Kinc/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c +++ b/Kinc/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c @@ -7,6 +7,9 @@ // Windows 7 #define WINVER 0x0601 +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif #define _WIN32_WINNT 0x0601 #define NOATOM @@ -16,7 +19,7 @@ #define NOCTLMGR #define NODEFERWINDOWPOS #define NODRAWTEXT -//#define NOGDI +// #define NOGDI #define NOGDICAPMASKS #define NOHELP #define NOICONS @@ -28,7 +31,7 @@ #define NOMENUS #define NOMETAFILE #define NOMINMAX -//#define NOMSG +// #define NOMSG #define NONLS #define NOOPENFILE #define NOPROFILER @@ -40,7 +43,7 @@ #define NOSYSCOMMANDS #define NOSYSMETRICS #define NOTEXTMETRIC -//#define NOUSER +// #define NOUSER #define NOVIRTUALKEYCODES #define NOWH #define NOWINMESSAGES @@ -53,6 +56,7 @@ #include #include +#ifndef __MINGW32__ // MIDL_INTERFACE("1CB9AD4C-DBFA-4c32-B178-C2F568A703B2") DEFINE_GUID(IID_IAudioClient, 0x1CB9AD4C, 0xDBFA, 0x4c32, 0xB1, 0x78, 0xC2, 0xF5, 0x68, 0xA7, 0x03, 0xB2); // MIDL_INTERFACE("F294ACFC-3146-4483-A7BF-ADDCA7C260E2") @@ -61,9 +65,9 @@ DEFINE_GUID(IID_IAudioRenderClient, 0xF294ACFC, 0x3146, 0x4483, 0xA7, 0xBF, 0xAD DEFINE_GUID(IID_IMMDeviceEnumerator, 0xA95664D2, 0x9614, 0x4F35, 0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36, 0x17, 0xE6); // DECLSPEC_UUID("BCDE0395-E52F-467C-8E3D-C4579291692E") DEFINE_GUID(CLSID_MMDeviceEnumerator, 0xBCDE0395, 0xE52F, 0x467C, 0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E); +#endif // based on the implementation in soloud and Microsoft sample code -static volatile void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = NULL; static kinc_a2_buffer_t a2_buffer; static IMMDeviceEnumerator *deviceEnumerator; @@ -71,11 +75,15 @@ static IMMDevice *device; static IAudioClient *audioClient = NULL; static IAudioRenderClient *renderClient = NULL; static HANDLE bufferEndEvent = 0; -static HANDLE audioProcessingDoneEvent; static UINT32 bufferFrames; static WAVEFORMATEX requestedFormat; static WAVEFORMATEX *closestFormat; static WAVEFORMATEX *format; +static uint32_t samples_per_second = 44100; + +uint32_t kinc_a2_samples_per_second(void) { + return samples_per_second; +} static bool initDefaultDevice() { if (renderClient != NULL) { @@ -130,10 +138,12 @@ static bool initDefaultDevice() { return false; } - kinc_a2_samples_per_second = format->nSamplesPerSec; - a2_buffer.format.samples_per_second = kinc_a2_samples_per_second; - a2_buffer.format.bits_per_sample = 16; - a2_buffer.format.channels = 2; + uint32_t old_samples_per_second = samples_per_second; + samples_per_second = format->nSamplesPerSec; + if (samples_per_second != old_samples_per_second) { + kinc_a2_internal_sample_rate_callback(); + } + a2_buffer.channel_count = 2; bufferFrames = 0; kinc_microsoft_affirm(audioClient->lpVtbl->GetBufferSize(audioClient, &bufferFrames)); @@ -152,22 +162,6 @@ static bool initDefaultDevice() { } } -static void copyS16Sample(int16_t *buffer) { - float value = *(float *)&a2_buffer.data[a2_buffer.read_location]; - a2_buffer.read_location += 4; - if (a2_buffer.read_location >= a2_buffer.data_size) - a2_buffer.read_location = 0; - *buffer = (int16_t)(value * 32767); -} - -static void copyFloatSample(float *buffer) { - float value = *(float *)&a2_buffer.data[a2_buffer.read_location]; - a2_buffer.read_location += 4; - if (a2_buffer.read_location >= a2_buffer.data_size) - a2_buffer.read_location = 0; - *buffer = value; -} - static void submitEmptyBuffer(unsigned frames) { BYTE *buffer = NULL; HRESULT result = renderClient->lpVtbl->GetBuffer(renderClient, frames, &buffer); @@ -180,31 +174,53 @@ static void submitEmptyBuffer(unsigned frames) { result = renderClient->lpVtbl->ReleaseBuffer(renderClient, frames, 0); } +static void restartAudio() { + initDefaultDevice(); + submitEmptyBuffer(bufferFrames); + audioClient->lpVtbl->Start(audioClient); +} + +static void copyS16Sample(int16_t *left, int16_t *right) { + float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location]; + float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location]; + a2_buffer.read_location += 1; + if (a2_buffer.read_location >= a2_buffer.data_size) { + a2_buffer.read_location = 0; + } + *left = (int16_t)(left_value * 32767); + *right = (int16_t)(right_value * 32767); +} + +static void copyFloatSample(float *left, float *right) { + float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location]; + float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location]; + a2_buffer.read_location += 1; + if (a2_buffer.read_location >= a2_buffer.data_size) { + a2_buffer.read_location = 0; + } + *left = left_value; + *right = right_value; +} + static void submitBuffer(unsigned frames) { BYTE *buffer = NULL; HRESULT result = renderClient->lpVtbl->GetBuffer(renderClient, frames, &buffer); if (FAILED(result)) { if (result == AUDCLNT_E_DEVICE_INVALIDATED) { - initDefaultDevice(); - submitEmptyBuffer(bufferFrames); - audioClient->lpVtbl->Start(audioClient); + restartAudio(); } return; } - if (a2_callback != NULL) { - a2_callback(&a2_buffer, frames * 2); - memset(buffer, 0, frames * format->nBlockAlign); + if (kinc_a2_internal_callback(&a2_buffer, frames)) { if (format->wFormatTag == WAVE_FORMAT_PCM) { for (UINT32 i = 0; i < frames; ++i) { - copyS16Sample((int16_t *)&buffer[i * format->nBlockAlign]); - copyS16Sample((int16_t *)&buffer[i * format->nBlockAlign + 2]); + copyS16Sample((int16_t *)&buffer[i * format->nBlockAlign], (int16_t *)&buffer[i * format->nBlockAlign + 2]); } } else { for (UINT32 i = 0; i < frames; ++i) { - copyFloatSample((float *)&buffer[i * format->nBlockAlign]); - copyFloatSample((float *)&buffer[i * format->nBlockAlign + 4]); + copyFloatSample((float *)&buffer[i * format->nBlockAlign], (float *)&buffer[i * format->nBlockAlign + 4]); } } } @@ -215,9 +231,7 @@ static void submitBuffer(unsigned frames) { result = renderClient->lpVtbl->ReleaseBuffer(renderClient, frames, 0); if (FAILED(result)) { if (result == AUDCLNT_E_DEVICE_INVALIDATED) { - initDefaultDevice(); - submitEmptyBuffer(bufferFrames); - audioClient->lpVtbl->Start(audioClient); + restartAudio(); } } } @@ -225,15 +239,13 @@ static void submitBuffer(unsigned frames) { static DWORD WINAPI audioThread(LPVOID ignored) { submitBuffer(bufferFrames); audioClient->lpVtbl->Start(audioClient); - while (WAIT_OBJECT_0 != WaitForSingleObject(audioProcessingDoneEvent, 0)) { + while (1) { WaitForSingleObject(bufferEndEvent, INFINITE); UINT32 padding = 0; HRESULT result = audioClient->lpVtbl->GetCurrentPadding(audioClient, &padding); if (FAILED(result)) { if (result == AUDCLNT_E_DEVICE_INVALIDATED) { - initDefaultDevice(); - submitEmptyBuffer(bufferFrames); - audioClient->lpVtbl->Start(audioClient); + restartAudio(); } continue; } @@ -252,15 +264,15 @@ void kinc_a2_init() { return; } + kinc_a2_internal_init(); initialized = true; a2_buffer.read_location = 0; a2_buffer.write_location = 0; a2_buffer.data_size = 128 * 1024; - a2_buffer.data = (uint8_t *)malloc(a2_buffer.data_size); - - audioProcessingDoneEvent = CreateEvent(0, FALSE, FALSE, 0); - kinc_affirm(audioProcessingDoneEvent != 0); + a2_buffer.channel_count = 2; + a2_buffer.channels[0] = (float *)malloc(a2_buffer.data_size * sizeof(float)); + a2_buffer.channels[1] = (float *)malloc(a2_buffer.data_size * sizeof(float)); kinc_windows_co_initialize(); kinc_microsoft_affirm(CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &IID_IMMDeviceEnumerator, (void **)&deviceEnumerator)); @@ -270,10 +282,6 @@ void kinc_a2_init() { } } -void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) { - a2_callback = kinc_a2_audio_callback; -} - void kinc_a2_update() {} #define SAFE_RELEASE(punk) \ diff --git a/Kinc/Backends/Audio2/WASAPI_WinRT/Sources/kinc/backend/WASAPI.winrt.cpp b/Kinc/Backends/Audio2/WASAPI_WinRT/Sources/kinc/backend/WASAPI.winrt.cpp index c909014..c320851 100644 --- a/Kinc/Backends/Audio2/WASAPI_WinRT/Sources/kinc/backend/WASAPI.winrt.cpp +++ b/Kinc/Backends/Audio2/WASAPI_WinRT/Sources/kinc/backend/WASAPI.winrt.cpp @@ -9,15 +9,13 @@ #include #include #include -#ifdef KORE_WINRT +#ifdef KINC_WINDOWSAPP #include #endif #include #include -using namespace Kore; - -#ifdef KORE_WINRT +#ifdef KINC_WINDOWSAPP using namespace ::Microsoft::WRL; using namespace Windows::Media::Devices; using namespace Windows::Storage::Streams; @@ -40,7 +38,6 @@ template void SafeRelease(__deref_inout_opt T **ppT) { // based on the implementation in soloud and Microsoft sample code namespace { kinc_thread_t thread; - void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = nullptr; kinc_a2_buffer_t a2_buffer; IMMDeviceEnumerator *deviceEnumerator; @@ -48,16 +45,16 @@ namespace { IAudioClient *audioClient = NULL; IAudioRenderClient *renderClient = NULL; HANDLE bufferEndEvent = 0; - HANDLE audioProcessingDoneEvent; UINT32 bufferFrames; WAVEFORMATEX requestedFormat; WAVEFORMATEX *closestFormat; WAVEFORMATEX *format; + static uint32_t samples_per_second = 44100; bool initDefaultDevice(); void audioThread(LPVOID); -#ifdef KORE_WINRT +#ifdef KINC_WINDOWSAPP class AudioRenderer : public RuntimeClass, FtmBase, IActivateAudioInterfaceCompletionHandler> { public: STDMETHOD(ActivateCompleted)(IActivateAudioInterfaceAsyncOperation *operation) { @@ -77,7 +74,7 @@ namespace { #endif bool initDefaultDevice() { -#ifdef KORE_WINRT +#ifdef KINC_WINDOWSAPP HRESULT hr = S_OK; #else if (renderClient != NULL) { @@ -132,8 +129,12 @@ namespace { return false; } - kinc_a2_samples_per_second = format->nSamplesPerSec; - a2_buffer.format.samples_per_second = kinc_a2_samples_per_second; + uint32_t old_samples_per_second = samples_per_second; + samples_per_second = format->nSamplesPerSec; + if (samples_per_second != old_samples_per_second) { + kinc_a2_internal_sample_rate_callback(); + } + a2_buffer.channel_count = 2; bufferFrames = 0; kinc_microsoft_affirm(audioClient->GetBufferSize(&bufferFrames)); @@ -152,18 +153,26 @@ namespace { } } - void copyS16Sample(s16 *buffer) { - float value = *(float *)&a2_buffer.data[a2_buffer.read_location]; - a2_buffer.read_location += 4; - if (a2_buffer.read_location >= a2_buffer.data_size) a2_buffer.read_location = 0; - *buffer = (s16)(value * 32767); + void copyS16Sample(int16_t *left, int16_t *right) { + float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location]; + float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location]; + a2_buffer.read_location += 1; + if (a2_buffer.read_location >= a2_buffer.data_size) { + a2_buffer.read_location = 0; + } + *left = (int16_t)(left_value * 32767); + *right = (int16_t)(right_value * 32767); } - void copyFloatSample(float *buffer) { - float value = *(float *)&a2_buffer.data[a2_buffer.read_location]; - a2_buffer.read_location += 4; - if (a2_buffer.read_location >= a2_buffer.data_size) a2_buffer.read_location = 0; - *buffer = value; + void copyFloatSample(float *left, float *right) { + float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location]; + float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location]; + a2_buffer.read_location += 1; + if (a2_buffer.read_location >= a2_buffer.data_size) { + a2_buffer.read_location = 0; + } + *left = left_value; + *right = right_value; } void submitEmptyBuffer(unsigned frames) { @@ -190,19 +199,15 @@ namespace { return; } - if (a2_callback != nullptr) { - a2_callback(&a2_buffer, frames * 2); - memset(buffer, 0, frames * format->nBlockAlign); + if (kinc_a2_internal_callback(&a2_buffer, frames)) { if (format->wFormatTag == WAVE_FORMAT_PCM) { for (UINT32 i = 0; i < frames; ++i) { - copyS16Sample((s16 *)&buffer[i * format->nBlockAlign]); - copyS16Sample((s16 *)&buffer[i * format->nBlockAlign + 2]); + copyS16Sample((int16_t *)&buffer[i * format->nBlockAlign], (int16_t *)&buffer[i * format->nBlockAlign + 2]); } } else { for (UINT32 i = 0; i < frames; ++i) { - copyFloatSample((float *)&buffer[i * format->nBlockAlign]); - copyFloatSample((float *)&buffer[i * format->nBlockAlign + 4]); + copyFloatSample((float *)&buffer[i * format->nBlockAlign], (float *)&buffer[i * format->nBlockAlign + 4]); } } } @@ -223,7 +228,7 @@ namespace { void audioThread(LPVOID) { submitBuffer(bufferFrames); audioClient->Start(); - while (WAIT_OBJECT_0 != WaitForSingleObject(audioProcessingDoneEvent, 0)) { + while (true) { WaitForSingleObject(bufferEndEvent, INFINITE); UINT32 padding = 0; HRESULT result = audioClient->GetCurrentPadding(&padding); @@ -242,7 +247,7 @@ namespace { } // namespace -#ifndef KORE_WINRT +#ifndef KINC_WINDOWSAPP extern "C" void kinc_windows_co_initialize(void); #endif @@ -253,17 +258,17 @@ void kinc_a2_init() { return; } + kinc_a2_internal_init(); initialized = true; a2_buffer.read_location = 0; a2_buffer.write_location = 0; a2_buffer.data_size = 128 * 1024; - a2_buffer.data = (uint8_t *)malloc(a2_buffer.data_size); + a2_buffer.channel_count = 2; + a2_buffer.channels[0] = (float *)malloc(a2_buffer.data_size * sizeof(float)); + a2_buffer.channels[1] = (float *)malloc(a2_buffer.data_size * sizeof(float)); - audioProcessingDoneEvent = CreateEvent(0, FALSE, FALSE, 0); - kinc_affirm(audioProcessingDoneEvent != 0); - -#ifdef KORE_WINRT +#ifdef KINC_WINDOWSAPP renderer = Make(); IActivateAudioInterfaceAsyncOperation *asyncOp; @@ -281,8 +286,8 @@ void kinc_a2_init() { #endif } -void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) { - a2_callback = kinc_a2_audio_callback; +uint32_t kinc_a2_samples_per_second(void) { + return samples_per_second; } void kinc_a2_update() {} diff --git a/Kinc/Backends/Audio3/A3onA2/Sources/kinc/backend/Audio.cpp b/Kinc/Backends/Audio3/A3onA2/Sources/kinc/backend/Audio.cpp index 16874e3..2d5e260 100644 --- a/Kinc/Backends/Audio3/A3onA2/Sources/kinc/backend/Audio.cpp +++ b/Kinc/Backends/Audio3/A3onA2/Sources/kinc/backend/Audio.cpp @@ -7,7 +7,7 @@ namespace { const int channelCount = 64; Audio3::Channel channels[channelCount]; - void callback(int samples) { + void callback(uint32_t samples) { for (int i = 0; i < channelCount; ++i) { channels[i].callback(samples); } @@ -16,14 +16,17 @@ namespace { for (int i = 0; i < channelCount; ++i) { value += *(float *)&channels[i].buffer.data[Audio2::buffer.readLocation]; channels[i].buffer.readLocation += 4; - if (channels[i].buffer.readLocation >= channels[i].buffer.dataSize) + if (channels[i].buffer.readLocation >= channels[i].buffer.dataSize) { channels[i].buffer.readLocation = 0; + } } - *(float *)&Audio2::buffer.data[Audio2::buffer.writeLocation] = value; - Audio2::buffer.writeLocation += 4; - if (Audio2::buffer.writeLocation >= Audio2::buffer.dataSize) + *(float *)&Audio2::buffer.channels[0][Audio2::buffer.writeLocation] = value; + *(float *)&Audio2::buffer.channels[1][Audio2::buffer.writeLocation] = value; + Audio2::buffer.writeLocation += 1; + if (Audio2::buffer.writeLocation >= Audio2::buffer.dataSize) { Audio2::buffer.writeLocation = 0; + } } } } diff --git a/Kinc/Backends/Audio3/A3onA2/Sources/kinc/backend/TextToSpeech.winrt.cpp b/Kinc/Backends/Audio3/A3onA2/Sources/kinc/backend/TextToSpeech.winrt.cpp index 442ecb5..4cdaea1 100644 --- a/Kinc/Backends/Audio3/A3onA2/Sources/kinc/backend/TextToSpeech.winrt.cpp +++ b/Kinc/Backends/Audio3/A3onA2/Sources/kinc/backend/TextToSpeech.winrt.cpp @@ -1,4 +1,4 @@ -#ifdef KORE_WINDOWSAPP +#ifdef KINC_WINDOWSAPP #include #include diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/GL/glew.c b/Kinc/Backends/Graphics3/OpenGL1/Sources/GL/glew.c index 4eb8e54..afdd6c3 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/GL/glew.c +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/GL/glew.c @@ -29,7 +29,7 @@ ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF ** THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #if defined(GLEW_OSMESA) diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ComputeImpl.cpp b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ComputeImpl.cpp index 7cbce22..4912dfc 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ComputeImpl.cpp +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ComputeImpl.cpp @@ -7,7 +7,7 @@ using namespace Kore; -#if defined(KORE_WINDOWS) || (defined(KORE_LINUX) && defined(GL_VERSION_4_3)) || (defined(KORE_ANDROID) && defined(GL_ES_VERSION_3_1)) +#if defined(KINC_WINDOWS) || (defined(KINC_LINUX) && defined(GL_VERSION_4_3)) || (defined(KINC_ANDROID) && defined(GL_ES_VERSION_3_1)) #define HAS_COMPUTE #endif diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/IndexBufferImpl.cpp b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/IndexBufferImpl.cpp index da34914..42df64f 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/IndexBufferImpl.cpp +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/IndexBufferImpl.cpp @@ -12,7 +12,7 @@ Graphics3::IndexBuffer::IndexBuffer(int indexCount) : IndexBufferImpl(indexCount glGenBuffers(1, &bufferId); glCheckErrors(); data = new int[indexCount]; -#if defined(KORE_ANDROID) || defined(KORE_PI) +#if defined(KINC_ANDROID) || defined(KINC_RASPBERRY_PI) shortData = new u16[indexCount]; #endif } @@ -27,13 +27,13 @@ int *Graphics3::IndexBuffer::lock() { } void Graphics3::IndexBuffer::unlock() { -#if defined(KORE_ANDROID) || defined(KORE_PI) +#if defined(KINC_ANDROID) || defined(KINC_RASPBERRY_PI) for (int i = 0; i < myCount; ++i) shortData[i] = (u16)data[i]; #endif glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId); glCheckErrors(); -#if defined(KORE_ANDROID) || defined(KORE_PI) +#if defined(KINC_ANDROID) || defined(KINC_RASPBERRY_PI) glBufferData(GL_ELEMENT_ARRAY_BUFFER, myCount * 2, shortData, GL_STATIC_DRAW); glCheckErrors(); #else diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/IndexBufferImpl.h b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/IndexBufferImpl.h index fd673ed..2e718ec 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/IndexBufferImpl.h +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/IndexBufferImpl.h @@ -11,7 +11,7 @@ namespace Kore { IndexBufferImpl(int count); void unset(); -#if defined(KORE_ANDROID) || defined(KORE_PI) +#if defined(KINC_ANDROID) || defined(KINC_RASPBERRY_PI) u16 *shortData; #endif int *data; diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/OpenGL.cpp b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/OpenGL.cpp index f33b11a..a9c6a0c 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/OpenGL.cpp +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/OpenGL.cpp @@ -7,11 +7,11 @@ #include #include -#ifdef KORE_IOS +#ifdef KINC_IOS #include #endif -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #define WIN32_LEAN_AND_MEAN @@ -25,13 +25,13 @@ using namespace Kore; namespace Kore { -#if !defined(KORE_IOS) && !defined(KORE_ANDROID) +#if !defined(KINC_IOS) && !defined(KINC_ANDROID) extern bool programUsesTessellation; #endif } namespace { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS HINSTANCE instance = 0; HDC deviceContexts[10] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}; HGLRC glContexts[10] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}; @@ -57,13 +57,13 @@ namespace { mat4 world; } g_wvpTransform; -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 void *glesDrawBuffers; #endif } void Graphics3::destroy(int windowId) { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS if (glContexts[windowId]) { if (!wglMakeCurrent(nullptr, nullptr)) { // MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); @@ -88,7 +88,7 @@ void Graphics3::destroy(int windowId) { #undef CreateWindow -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS namespace Kore { namespace System { extern int currentDeviceId; @@ -96,12 +96,12 @@ namespace Kore { } #endif -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS void Graphics3::setup() {} #endif void Graphics3::init(int windowId, int depthBufferBits, int stencilBufferBits, bool vsync) { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS HWND windowHandle = (HWND)System::windowHandle(windowId); #ifndef VR_RIFT @@ -195,7 +195,7 @@ void Graphics3::init(int windowId, int depthBufferBits, int stencilBufferBits, b } #endif -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS if (windowId == 0) { // TODO (DK) check if we actually want vsync if (wglSwapIntervalEXT != nullptr) @@ -203,11 +203,11 @@ void Graphics3::init(int windowId, int depthBufferBits, int stencilBufferBits, b } #endif -#if defined(KORE_IOS) +#if defined(KINC_IOS) glGenVertexArraysOES(1, &arrayId[windowId]); -#elif defined(KORE_MACOS) +#elif defined(KINC_MACOS) glGenVertexArraysAPPLE(1, &arrayId[windowId]); -#elif !defined(KORE_ANDROID) && !defined(KORE_EMSCRIPTEN) && !defined(KORE_TIZEN) && !defined(KORE_PI) +#elif !defined(KINC_ANDROID) && !defined(KINC_EMSCRIPTEN) && !defined(KINC_RASPBERRY_PI) glGenVertexArrays(1, &arrayId[windowId]); #endif glCheckErrors(); @@ -218,7 +218,7 @@ void Graphics3::init(int windowId, int depthBufferBits, int stencilBufferBits, b _renderTargetHeight = _height; renderToBackbuffer = true; -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 glesDrawBuffers = (void *)eglGetProcAddress("glDrawBuffers"); #endif } @@ -313,8 +313,8 @@ void Graphics3::drawIndexedVertices() { } void Graphics3::drawIndexedVertices(int start, int count) { -#ifdef KORE_OPENGL_ES -#if defined(KORE_ANDROID) || defined(KORE_PI) +#ifdef KINC_OPENGL_ES +#if defined(KINC_ANDROID) || defined(KINC_RASPBERRY_PI) glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (void *)(start * sizeof(GL_UNSIGNED_SHORT))); #else glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, (void *)(start * sizeof(GL_UNSIGNED_INT))); @@ -329,18 +329,18 @@ void Graphics3::drawIndexedVertices(int start, int count) { } void Graphics3::swapBuffers(int contextId) { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS ::SwapBuffers(deviceContexts[contextId]); #else System::swapBuffers(contextId); #endif } -#ifdef KORE_IOS +#ifdef KINC_IOS void beginGL(); #endif -#if defined(KORE_WINDOWS) +#if defined(KINC_WINDOWS) void Graphics3::makeCurrent(int contextId) { wglMakeCurrent(deviceContexts[contextId], glContexts[contextId]); } @@ -363,11 +363,11 @@ void Graphics3::begin(int contextId) { glViewport(0, 0, _width, _height); -#ifdef KORE_IOS +#ifdef KINC_IOS beginGL(); #endif -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID // if rendered to a texture, strange things happen if the backbuffer is not cleared glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); @@ -477,7 +477,7 @@ void Graphics3::setStencilParameters(ZCompareMode compareMode, StencilAction bot //#endif }*/ -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS void Graphics3::clearCurrent() { wglMakeCurrent(nullptr, nullptr); } @@ -508,7 +508,7 @@ void Graphics3::clear(uint flags, uint color, float depth, int stencil) { glDepthMask(GL_TRUE); glCheckErrors(); } -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glClearDepthf(depth); #else glClearDepth(depth); @@ -1029,9 +1029,9 @@ void Graphics3::setRenderTarget(RenderTarget *texture, int num, int additionalTa GLenum buffers[16]; for (int i = 0; i <= additionalTargets; ++i) buffers[i] = GL_COLOR_ATTACHMENT0 + i; -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 ((void (*)(GLsizei, GLenum *))glesDrawBuffers)(additionalTargets + 1, buffers); -#elif !defined(KORE_OPENGL_ES) +#elif !defined(KINC_OPENGL_ES) glDrawBuffers(additionalTargets + 1, buffers); #endif } diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ProgramImpl.cpp b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ProgramImpl.cpp index db3be28..622c052 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ProgramImpl.cpp +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ProgramImpl.cpp @@ -148,8 +148,8 @@ void Graphics4::Program::link(VertexStructure **structures, int count) { delete[] errormessage; } -#ifndef KORE_OPENGL_ES -#ifndef KORE_LINUX +#ifndef KINC_OPENGL_ES +#ifndef KINC_LINUX /* if (tessellationControlShader != nullptr) { glPatchParameteri(GL_PATCH_VERTICES, 3); glCheckErrors(); @@ -159,7 +159,7 @@ void Graphics4::Program::link(VertexStructure **structures, int count) { } void Graphics4::Program::set() { -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES programUsesTessellation = tessellationControlShader != nullptr; #endif glUseProgram(programId); diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/RenderTargetImpl.cpp b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/RenderTargetImpl.cpp index 6f05460..e36e162 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/RenderTargetImpl.cpp +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/RenderTargetImpl.cpp @@ -4,7 +4,7 @@ #include #include #include -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID #include #endif using namespace Kore; @@ -36,8 +36,8 @@ namespace { } bool nonPow2RenderTargetsSupported() { -#ifdef KORE_OPENGL_ES -#ifdef KORE_ANDROID +#ifdef KINC_OPENGL_ES +#ifdef KINC_ANDROID if (ndk_helper::GLContext::GetInstance()->GetGLVersion() >= 3.0) return true; else @@ -53,7 +53,7 @@ namespace { void RenderTargetImpl::setupDepthStencil(int depthBufferBits, int stencilBufferBits, int width, int height) { if (depthBufferBits > 0 && stencilBufferBits > 0) { -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES GLenum internalFormat = GL_DEPTH24_STENCIL8_OES; #else GLenum internalFormat; @@ -69,7 +69,7 @@ void RenderTargetImpl::setupDepthStencil(int depthBufferBits, int stencilBufferB // glCheckErrors(); // glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, width, height); // glCheckErrors(); - // #ifdef KORE_OPENGL_ES + // #ifdef KINC_OPENGL_ES // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthRenderbuffer); // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthRenderbuffer); // #else @@ -90,7 +90,7 @@ void RenderTargetImpl::setupDepthStencil(int depthBufferBits, int stencilBufferB glCheckErrors(); glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer); glCheckErrors(); -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _depthTexture, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, _depthTexture, 0); #else @@ -160,23 +160,23 @@ Graphics3::RenderTarget::RenderTarget(int width, int height, int depthBufferBits glCheckErrors(); switch (format) { -#ifndef KORE_MACOS +#ifndef KINC_MACOS case Target128BitFloat: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_EXT, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, 0); #else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, 0); #endif break; case Target64BitFloat: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_EXT, texWidth, texHeight, 0, GL_RGBA, GL_HALF_FLOAT, 0); #else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, texWidth, texHeight, 0, GL_RGBA, GL_HALF_FLOAT, 0); #endif break; case Target16BitDepth: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); #endif diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/TextureImpl.cpp b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/TextureImpl.cpp index 6b558b9..aaa8bd9 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/TextureImpl.cpp +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/TextureImpl.cpp @@ -26,7 +26,7 @@ namespace { case Graphics3::Image::RGB24: return GL_RGB; case Graphics3::Image::Grey8: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES return GL_LUMINANCE; #else return GL_RED; @@ -49,7 +49,7 @@ namespace { case Graphics3::Image::RGB24: return GL_RGB; case Graphics3::Image::Grey8: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES return GL_LUMINANCE; #else return GL_RED; @@ -187,14 +187,14 @@ void Graphics3::Texture::init(const char *format, bool readable) { u8 *conversionBuffer = nullptr; if (compressed) { -#if defined(KORE_IOS) +#if defined(KINC_IOS) texWidth = Kore::max(texWidth, texHeight); texHeight = Kore::max(texWidth, texHeight); if (texWidth < 8) texWidth = 8; if (texHeight < 8) texHeight = 8; -#elif defined(KORE_ANDROID) +#elif defined(KINC_ANDROID) texWidth = width; texHeight = height; #endif @@ -204,7 +204,7 @@ void Graphics3::Texture::init(const char *format, bool readable) { convertImageToPow2(this->format, (u8 *)data, width, height, conversionBuffer, texWidth, texHeight); } -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID external_oes = false; #endif @@ -219,9 +219,9 @@ void Graphics3::Texture::init(const char *format, bool readable) { bool isHdr = convertedType == GL_FLOAT; if (compressed) { -#ifdef KORE_IOS +#ifdef KINC_IOS glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, texWidth, texHeight, 0, texWidth * texHeight / 2, data); -// #elif defined(KORE_ANDROID) +// #elif defined(KINC_ANDROID) // u8 blockX = internalFormat >> 8; // u8 blockY = internalFormat & 0xff; // glCompressedTexImage2D(GL_TEXTURE_2D, 0, astcFormat(blockX, blockY), texWidth, texHeight, 0, dataSize, data); @@ -263,7 +263,7 @@ void Graphics3::Texture::init(const char *format, bool readable) { } Graphics3::Texture::Texture(int width, int height, Image::Format format, bool readable) : Image(width, height, format, readable) { -#ifdef KORE_IOS +#ifdef KINC_IOS texWidth = width; texHeight = height; #else @@ -278,7 +278,7 @@ Graphics3::Texture::Texture(int width, int height, Image::Format format, bool re #endif // conversionBuffer = new u8[texWidth * texHeight * 4]; -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID external_oes = false; #endif @@ -324,7 +324,7 @@ Graphics3::Texture::Texture(int width, int height, int depth, Graphics3::Image:: #endif } -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID Texture::Texture(unsigned texid) : Image(1023, 684, Image::RGBA32, false) { texture = texid; external_oes = true; @@ -342,7 +342,7 @@ void Graphics3::Texture::_set(TextureUnit unit) { GLenum target = depth > 1 ? GL_TEXTURE_3D : GL_TEXTURE_2D; glActiveTexture(GL_TEXTURE0 + unit.unit); glCheckErrors(); -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID if (external_oes) { glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture); glCheckErrors(); @@ -408,7 +408,7 @@ void Graphics3::Texture::clear(int x, int y, int z, int width, int height, int d #endif } -#ifdef KORE_IOS +#ifdef KINC_IOS void Texture::upload(u8 *data) { glBindTexture(GL_TEXTURE_2D, texture); glCheckErrors(); diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/TextureImpl.h b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/TextureImpl.h index f0b1826..f9783c1 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/TextureImpl.h +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/TextureImpl.h @@ -17,7 +17,7 @@ namespace Kore { // static TreeMap images; public: unsigned int texture; -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID bool external_oes; #endif diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/VertexBufferImpl.h b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/VertexBufferImpl.h index 8ae1ffa..a6171fe 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/VertexBufferImpl.h +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/VertexBufferImpl.h @@ -15,7 +15,7 @@ namespace Kore { int myCount; int myStride; uint bufferId; - // #if defined KORE_ANDROID || defined KORE_EMSCRIPTEN || defined KORE_TIZEN + // #if defined KINC_ANDROID || defined KINC_EMSCRIPTEN Graphics4::VertexStructure structure; // #endif int instanceDataStepRate; diff --git a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ogl.h b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ogl.h index 46f4a9f..559da66 100644 --- a/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ogl.h +++ b/Kinc/Backends/Graphics3/OpenGL1/Sources/kinc/backend/ogl.h @@ -1,37 +1,37 @@ #pragma once -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #include #endif -#ifdef KORE_MACOS +#ifdef KINC_MACOS #include #include #endif -#ifdef KORE_IOS +#ifdef KINC_IOS #import #import #import #endif -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID #include -#if KORE_ANDROID_API >= 18 +#if KINC_ANDROID_API >= 18 #include #endif #include #include #endif -#ifdef KORE_EMSCRIPTEN +#ifdef KINC_EMSCRIPTEN #define GL_GLEXT_PROTOTYPES #define EGL_EGLEXT_PROTOTYPES #include #endif -#ifdef KORE_LINUX +#ifdef KINC_LINUX #include #include #define GL_GLEXT_PROTOTYPES @@ -40,20 +40,16 @@ #include #endif -#ifdef KORE_PI +#ifdef KINC_RASPBERRY_PI // #define GL_GLEXT_PROTOTYPES #include "EGL/egl.h" #include "EGL/eglext.h" #include "GLES2/gl2.h" #endif -#ifdef KORE_TIZEN -#include -#endif - #include -#if defined(NDEBUG) || defined(KORE_OSX) || defined(KORE_IOS) || defined(KORE_ANDROID) || 1 // Calling glGetError too early means trouble +#if defined(NDEBUG) || defined(KINC_OSX) || defined(KINC_IOS) || defined(KINC_ANDROID) || 1 // Calling glGetError too early means trouble #define glCheckErrors() \ {} #else diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/VrInterface_Oculus.cpp b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/VrInterface_Oculus.cpp index 92abb75..c4a5a68 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/VrInterface_Oculus.cpp +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/VrInterface_Oculus.cpp @@ -1,4 +1,4 @@ -#ifdef KORE_OCULUS +#ifdef KINC_OCULUS #include diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.c b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.c deleted file mode 100644 index da77150..0000000 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.c +++ /dev/null @@ -1,384 +0,0 @@ -#include "graphics4/Direct3D11.h" - -#include -#include -#include -#include - -#include - -#define NOMINMAX - -#ifdef KORE_WINDOWSAPP -#include -#else -#pragma warning(disable : 4005) -#include -#endif - -#include - -static uint8_t constantsMemory[1024 * 4]; - -static int getMultipleOf16(int value) { - int ret = 16; - while (ret < value) - ret += 16; - return ret; -} - -static void setInt(uint8_t *constants, uint32_t offset, uint32_t size, int value) { - if (size == 0) - return; - int *ints = (int *)&constants[offset]; - ints[0] = value; -} - -static void setFloat(uint8_t *constants, uint32_t offset, uint32_t size, float value) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value; -} - -static void setFloat2(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; -} - -static void setFloat3(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2, float value3) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; - floats[2] = value3; -} - -static void setFloat4(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2, float value3, float value4) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; - floats[2] = value3; - floats[3] = value4; -} - -static void setFloats(uint8_t *constants, uint32_t offset, uint32_t size, uint8_t columns, uint8_t rows, float *values, int count) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - if (columns == 4 && rows == 4) { - for (int i = 0; i < count / 16 && i < (int)size / 4; ++i) { - for (int y = 0; y < 4; ++y) { - for (int x = 0; x < 4; ++x) { - floats[i * 16 + x + y * 4] = values[i * 16 + y + x * 4]; - } - } - } - } - else if (columns == 3 && rows == 3) { - for (int i = 0; i < count / 9 && i < (int)size / 3; ++i) { - for (int y = 0; y < 4; ++y) { - for (int x = 0; x < 4; ++x) { - floats[i * 12 + x + y * 4] = values[i * 9 + y + x * 3]; - } - } - } - } - else if (columns == 2 && rows == 2) { - for (int i = 0; i < count / 4 && i < (int)size / 2; ++i) { - for (int y = 0; y < 4; ++y) { - for (int x = 0; x < 4; ++x) { - floats[i * 8 + x + y * 4] = values[i * 4 + y + x * 2]; - } - } - } - } - else { - for (int i = 0; i < count && i * 4 < (int)size; ++i) { - floats[i] = values[i]; - } - } -} - -static void setBool(uint8_t *constants, uint32_t offset, uint32_t size, bool value) { - if (size == 0) - return; - int *ints = (int *)&constants[offset]; - ints[0] = value ? 1 : 0; -} - -static void setMatrix4(uint8_t *constants, uint32_t offset, uint32_t size, kinc_matrix4x4_t *value) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - for (int y = 0; y < 4; ++y) { - for (int x = 0; x < 4; ++x) { - floats[x + y * 4] = kinc_matrix4x4_get(value, y, x); - } - } -} - -static void setMatrix3(uint8_t *constants, uint32_t offset, uint32_t size, kinc_matrix3x3_t *value) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - for (int y = 0; y < 3; ++y) { - for (int x = 0; x < 3; ++x) { - floats[x + y * 4] = kinc_matrix3x3_get(value, y, x); - } - } -} - -void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int length) { - unsigned index = 0; - uint8_t *data = (uint8_t *)_data; - -#ifndef KINC_KONG - memset(&shader->impl.attributes, 0, sizeof(shader->impl.attributes)); - int attributesCount = data[index++]; - for (int i = 0; i < attributesCount; ++i) { - unsigned char name[256]; - for (unsigned i2 = 0; i2 < 255; ++i2) { - name[i2] = data[index++]; - if (name[i2] == 0) - break; - } - shader->impl.attributes[i].hash = kinc_internal_hash_name(name); - shader->impl.attributes[i].index = data[index++]; - } - - memset(&shader->impl.textures, 0, sizeof(shader->impl.textures)); - uint8_t texCount = data[index++]; - for (unsigned i = 0; i < texCount; ++i) { - unsigned char name[256]; - for (unsigned i2 = 0; i2 < 255; ++i2) { - name[i2] = data[index++]; - if (name[i2] == 0) - break; - } - shader->impl.textures[i].hash = kinc_internal_hash_name(name); - shader->impl.textures[i].index = data[index++]; - } - - memset(&shader->impl.constants, 0, sizeof(shader->impl.constants)); - uint8_t constantCount = data[index++]; - shader->impl.constantsSize = 0; - for (unsigned i = 0; i < constantCount; ++i) { - unsigned char name[256]; - for (unsigned i2 = 0; i2 < 255; ++i2) { - name[i2] = data[index++]; - if (name[i2] == 0) - break; - } - kinc_compute_internal_shader_constant_t constant; - constant.hash = kinc_internal_hash_name(name); - constant.offset = *(uint32_t *)&data[index]; - index += 4; - constant.size = *(uint32_t *)&data[index]; - index += 4; - constant.columns = data[index]; - index += 1; - constant.rows = data[index]; - index += 1; - - shader->impl.constants[i] = constant; - shader->impl.constantsSize = constant.offset + constant.size; - } -#endif - - shader->impl.length = (int)(length - index); - shader->impl.data = (uint8_t *)malloc(shader->impl.length); - assert(shader->impl.data != NULL); - memcpy(shader->impl.data, &data[index], shader->impl.length); - - HRESULT hr = - dx_ctx.device->lpVtbl->CreateComputeShader(dx_ctx.device, shader->impl.data, shader->impl.length, NULL, (ID3D11ComputeShader **)&shader->impl.shader); - - if (hr != S_OK) { - kinc_log(KINC_LOG_LEVEL_WARNING, "Could not initialize compute shader."); - return; - } - -#ifndef KINC_KONG - D3D11_BUFFER_DESC desc; - desc.ByteWidth = getMultipleOf16(shader->impl.constantsSize); - desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; - desc.StructureByteStride = 0; - kinc_microsoft_affirm(dx_ctx.device->lpVtbl->CreateBuffer(dx_ctx.device, &desc, NULL, &shader->impl.constantBuffer)); -#endif -} - -void kinc_compute_shader_destroy(kinc_compute_shader_t *shader) {} - -static kinc_compute_internal_shader_constant_t *findConstant(kinc_compute_internal_shader_constant_t *constants, uint32_t hash) { - for (int i = 0; i < 64; ++i) { - if (constants[i].hash == hash) { - return &constants[i]; - } - } - return NULL; -} - -static kinc_internal_hash_index_t *findTextureUnit(kinc_internal_hash_index_t *units, uint32_t hash) { - for (int i = 0; i < 64; ++i) { - if (units[i].hash == hash) { - return &units[i]; - } - } - return NULL; -} - -#ifndef KINC_KONG -kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_constant_location_t location; - - uint32_t hash = kinc_internal_hash_name((unsigned char *)name); - - kinc_compute_internal_shader_constant_t *constant = findConstant(shader->impl.constants, hash); - if (constant == NULL) { - location.impl.offset = 0; - location.impl.size = 0; - location.impl.columns = 0; - location.impl.rows = 0; - } - else { - location.impl.offset = constant->offset; - location.impl.size = constant->size; - location.impl.columns = constant->columns; - location.impl.rows = constant->rows; - } - - if (location.impl.size == 0) { - kinc_log(KINC_LOG_LEVEL_WARNING, "Uniform %s not found.", name); - } - - return location; -} - -kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name) { - char unitName[64]; - int unitOffset = 0; - size_t len = strlen(name); - if (len > 63) - len = 63; - strncpy(unitName, name, len + 1); - if (unitName[len - 1] == ']') { // Check for array - mySampler[2] - unitOffset = (int)(unitName[len - 2] - '0'); // Array index is unit offset - unitName[len - 3] = 0; // Strip array from name - } - - uint32_t hash = kinc_internal_hash_name((unsigned char *)unitName); - - kinc_compute_texture_unit_t unit; - kinc_internal_hash_index_t *vertexUnit = findTextureUnit(shader->impl.textures, hash); - if (vertexUnit == NULL) { - unit.impl.unit = -1; -#ifndef NDEBUG - static int notFoundCount = 0; - if (notFoundCount < 10) { - kinc_log(KINC_LOG_LEVEL_WARNING, "Sampler %s not found.", unitName); - ++notFoundCount; - } - else if (notFoundCount == 10) { - kinc_log(KINC_LOG_LEVEL_WARNING, "Giving up on sampler not found messages.", unitName); - ++notFoundCount; - } -#endif - } - else { - unit.impl.unit = vertexUnit->index + unitOffset; - } - return unit; -} -#endif - -void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value) { - setBool(constantsMemory, location.impl.offset, location.impl.size, value); -} - -void kinc_compute_set_int(kinc_compute_constant_location_t location, int value) { - setInt(constantsMemory, location.impl.offset, location.impl.size, value); -} - -void kinc_compute_set_float(kinc_compute_constant_location_t location, float value) { - setFloat(constantsMemory, location.impl.offset, location.impl.size, value); -} - -void kinc_compute_set_float2(kinc_compute_constant_location_t location, float value1, float value2) { - setFloat2(constantsMemory, location.impl.offset, location.impl.size, value1, value2); -} - -void kinc_compute_set_float3(kinc_compute_constant_location_t location, float value1, float value2, float value3) { - setFloat3(constantsMemory, location.impl.offset, location.impl.size, value1, value2, value3); -} - -void kinc_compute_set_float4(kinc_compute_constant_location_t location, float value1, float value2, float value3, float value4) { - setFloat4(constantsMemory, location.impl.offset, location.impl.size, value1, value2, value3, value4); -} - -void kinc_compute_set_floats(kinc_compute_constant_location_t location, float *values, int count) { - setFloats(constantsMemory, location.impl.offset, location.impl.size, location.impl.columns, location.impl.rows, values, count); -} - -void kinc_compute_set_matrix4(kinc_compute_constant_location_t location, kinc_matrix4x4_t *value) { - setMatrix4(constantsMemory, location.impl.offset, location.impl.size, value); -} - -void kinc_compute_set_matrix3(kinc_compute_constant_location_t location, kinc_matrix3x3_t *value) { - setMatrix3(constantsMemory, location.impl.offset, location.impl.size, value); -} - -void kinc_compute_set_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture, kinc_compute_access_t access) { - ID3D11ShaderResourceView *nullView = NULL; - dx_ctx.context->lpVtbl->PSSetShaderResources(dx_ctx.context, 0, 1, &nullView); - - dx_ctx.context->lpVtbl->CSSetUnorderedAccessViews(dx_ctx.context, unit.impl.unit, 1, &texture->impl.computeView, NULL); -} - -void kinc_compute_set_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *texture, kinc_compute_access_t access) {} - -void kinc_compute_set_sampled_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture) {} - -void kinc_compute_set_sampled_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target) {} - -void kinc_compute_set_sampled_depth_from_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target) {} - -void kinc_compute_set_texture_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} - -void kinc_compute_set_texture_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} - -void kinc_compute_set_texture3d_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} - -void kinc_compute_set_texture3d_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} - -void kinc_compute_set_shader(kinc_compute_shader_t *shader) { - dx_ctx.context->lpVtbl->CSSetShader(dx_ctx.context, (ID3D11ComputeShader *)shader->impl.shader, NULL, 0); -#ifndef KINC_KONG - dx_ctx.context->lpVtbl->UpdateSubresource(dx_ctx.context, (ID3D11Resource *)shader->impl.constantBuffer, 0, NULL, constantsMemory, 0, 0); - dx_ctx.context->lpVtbl->CSSetConstantBuffers(dx_ctx.context, 0, 1, &shader->impl.constantBuffer); -#endif -} - -void kinc_compute(int x, int y, int z) { - dx_ctx.context->lpVtbl->Dispatch(dx_ctx.context, x, y, z); - - ID3D11UnorderedAccessView *nullView = NULL; - dx_ctx.context->lpVtbl->CSSetUnorderedAccessViews(dx_ctx.context, 0, 1, &nullView, NULL); -} diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h index 7ba75b6..885c10c 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -21,7 +20,7 @@ #include #include -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #else int antialiasingSamples(void) { @@ -29,16 +28,25 @@ int antialiasingSamples(void) { } #endif -#ifdef KORE_WINDOWSAPP +#ifdef KINC_WINDOWSAPP IUnknown *kinc_winapp_internal_get_window(void); #endif -#ifdef KORE_HOLOLENS +#ifdef KINC_HOLOLENS #include "DeviceResources.winrt.h" #include "Hololens.winrt.h" #include #endif +// MinGW workaround for missing defines +#ifndef D3D11_MIN_DEPTH +#define D3D11_MIN_DEPTH (0.0f) +#endif + +#ifndef D3D11_MAX_DEPTH +#define D3D11_MAX_DEPTH (1.0f) +#endif + extern kinc_g4_pipeline_t *currentPipeline; extern float currentBlendFactor[4]; extern bool needPipelineRebind; @@ -51,7 +59,7 @@ bool kinc_internal_scissoring = false; // static bool vsync; static D3D_FEATURE_LEVEL featureLevel; -// #ifdef KORE_WINDOWSAPP +// #ifdef KINC_WINDOWSAPP // static IDXGISwapChain1 *swapChain = NULL; // #else // static IDXGISwapChain *swapChain = NULL; @@ -160,7 +168,7 @@ static void createBackbuffer(struct dx_window *window, int antialiasingSamples) &window->depthStencilView)); } -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS static bool isWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor) { OSVERSIONINFOEXW osvi = {sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0}; DWORDLONG const dwlConditionMask = @@ -193,7 +201,7 @@ static bool isWindows10OrGreater(void) { void kinc_g4_internal_init(void) { D3D_FEATURE_LEVEL featureLevels[] = { -#ifdef KORE_WINDOWSAPP +#ifdef KINC_WINDOWSAPP D3D_FEATURE_LEVEL_11_1, #endif D3D_FEATURE_LEVEL_11_0, @@ -207,7 +215,7 @@ void kinc_g4_internal_init(void) { #endif IDXGIAdapter *adapter = NULL; -#ifdef KORE_HOLOLENS +#ifdef KINC_HOLOLENS adapter = holographicFrameController->getCompatibleDxgiAdapter().Get(); #endif HRESULT result = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, @@ -217,8 +225,8 @@ void kinc_g4_internal_init(void) { if (result == E_FAIL || result == DXGI_ERROR_SDK_COMPONENT_MISSING) { kinc_log(KINC_LOG_LEVEL_WARNING, "%s", "Failed to create device with D3D11_CREATE_DEVICE_DEBUG, trying without"); flags &= ~D3D11_CREATE_DEVICE_DEBUG; - result = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, - &dx_ctx.device, &featureLevel, &dx_ctx.context); + result = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, &dx_ctx.device, + &featureLevel, &dx_ctx.context); } #endif @@ -240,7 +248,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil struct dx_window *window = &dx_ctx.windows[windowId]; // TODO: make WindowsApp actually work again -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS window->hwnd = kinc_windows_window_handle(windowId); #endif window->depth_bits = depthBufferBits; @@ -264,7 +272,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil swapChainDesc.BufferCount = 2; // use two buffers to enable flip effect swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; // DXGI_SCALING_NONE; -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS if (isWindows10OrGreater()) { swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; //(DXGI_SWAP_EFFECT) _DXGI_SWAP_EFFECT_FLIP_DISCARD; @@ -326,7 +334,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil rtbd.SrcBlendAlpha = D3D11_BLEND_ONE; rtbd.DestBlendAlpha = D3D11_BLEND_ZERO; rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD; -#ifdef KORE_WINDOWSAPP +#ifdef KINC_WINDOWSAPP rtbd.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; #else rtbd.RenderTargetWriteMask = D3D10_COLOR_WRITE_ENABLE_ALL; @@ -465,7 +473,7 @@ void kinc_g4_begin(int windowId) { createBackbuffer(window, kinc_g4_antialiasing_samples()); } kinc_g4_restore_render_target(); - // #ifdef KORE_WINDOWSAPP + // #ifdef KINC_WINDOWSAPP // // TODO (DK) do i need to do something here? // dx_ctx.context->lpVtbl->OMSetRenderTargets(dx_ctx.context, 1, &renderTargetView, depthStencilView); // #endif @@ -731,6 +739,7 @@ void kinc_g4_set_int(kinc_g4_constant_location_t location, int value) { setInt(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value); setInt(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value); setInt(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value); + setInt(computeConstants, location.impl.computeOffset, location.impl.computeSize, value); } void kinc_g4_set_int2(kinc_g4_constant_location_t location, int value1, int value2) { @@ -739,6 +748,7 @@ void kinc_g4_set_int2(kinc_g4_constant_location_t location, int value1, int valu setInt2(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value1, value2); setInt2(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value1, value2); setInt2(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value1, value2); + setInt2(computeConstants, location.impl.computeOffset, location.impl.computeSize, value1, value2); } void kinc_g4_set_int3(kinc_g4_constant_location_t location, int value1, int value2, int value3) { @@ -747,6 +757,7 @@ void kinc_g4_set_int3(kinc_g4_constant_location_t location, int value1, int valu setInt3(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value1, value2, value3); setInt3(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value1, value2, value3); setInt3(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value1, value2, value3); + setInt3(computeConstants, location.impl.computeOffset, location.impl.computeSize, value1, value2, value3); } void kinc_g4_set_int4(kinc_g4_constant_location_t location, int value1, int value2, int value3, int value4) { @@ -755,6 +766,7 @@ void kinc_g4_set_int4(kinc_g4_constant_location_t location, int value1, int valu setInt4(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value1, value2, value3, value4); setInt4(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value1, value2, value3, value4); setInt4(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value1, value2, value3, value4); + setInt4(computeConstants, location.impl.computeOffset, location.impl.computeSize, value1, value2, value3, value4); } void kinc_g4_set_ints(kinc_g4_constant_location_t location, int *values, int count) { @@ -767,6 +779,7 @@ void kinc_g4_set_ints(kinc_g4_constant_location_t location, int *values, int cou count); setInts(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, location.impl.tessControlColumns, location.impl.tessControlRows, values, count); + setInts(computeConstants, location.impl.computeOffset, location.impl.computeSize, location.impl.computeColumns, location.impl.computeRows, values, count); } void kinc_g4_set_float(kinc_g4_constant_location_t location, float value) { @@ -775,6 +788,7 @@ void kinc_g4_set_float(kinc_g4_constant_location_t location, float value) { setFloat(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value); setFloat(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value); setFloat(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value); + setFloat(computeConstants, location.impl.computeOffset, location.impl.computeSize, value); } void kinc_g4_set_float2(kinc_g4_constant_location_t location, float value1, float value2) { @@ -783,6 +797,7 @@ void kinc_g4_set_float2(kinc_g4_constant_location_t location, float value1, floa setFloat2(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value1, value2); setFloat2(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value1, value2); setFloat2(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value1, value2); + setFloat2(computeConstants, location.impl.computeOffset, location.impl.computeSize, value1, value2); } void kinc_g4_set_float3(kinc_g4_constant_location_t location, float value1, float value2, float value3) { @@ -791,6 +806,7 @@ void kinc_g4_set_float3(kinc_g4_constant_location_t location, float value1, floa setFloat3(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value1, value2, value3); setFloat3(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value1, value2, value3); setFloat3(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value1, value2, value3); + setFloat3(computeConstants, location.impl.computeOffset, location.impl.computeSize, value1, value2, value3); } void kinc_g4_set_float4(kinc_g4_constant_location_t location, float value1, float value2, float value3, float value4) { @@ -799,6 +815,7 @@ void kinc_g4_set_float4(kinc_g4_constant_location_t location, float value1, floa setFloat4(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value1, value2, value3, value4); setFloat4(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value1, value2, value3, value4); setFloat4(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value1, value2, value3, value4); + setFloat4(computeConstants, location.impl.computeOffset, location.impl.computeSize, value1, value2, value3, value4); } void kinc_g4_set_floats(kinc_g4_constant_location_t location, float *values, int count) { @@ -811,6 +828,7 @@ void kinc_g4_set_floats(kinc_g4_constant_location_t location, float *values, int count); setFloats(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, location.impl.tessControlColumns, location.impl.tessControlRows, values, count); + setFloats(computeConstants, location.impl.computeOffset, location.impl.computeSize, location.impl.computeColumns, location.impl.computeRows, values, count); } void kinc_g4_set_bool(kinc_g4_constant_location_t location, bool value) { @@ -819,6 +837,7 @@ void kinc_g4_set_bool(kinc_g4_constant_location_t location, bool value) { setBool(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value); setBool(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value); setBool(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value); + setBool(computeConstants, location.impl.computeOffset, location.impl.computeSize, value); } void kinc_g4_set_matrix4(kinc_g4_constant_location_t location, kinc_matrix4x4_t *value) { @@ -827,6 +846,7 @@ void kinc_g4_set_matrix4(kinc_g4_constant_location_t location, kinc_matrix4x4_t setMatrix4(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value); setMatrix4(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value); setMatrix4(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value); + setMatrix4(computeConstants, location.impl.computeOffset, location.impl.computeSize, value); } void kinc_g4_set_matrix3(kinc_g4_constant_location_t location, kinc_matrix3x3_t *value) { @@ -835,6 +855,7 @@ void kinc_g4_set_matrix3(kinc_g4_constant_location_t location, kinc_matrix3x3_t setMatrix3(geometryConstants, location.impl.geometryOffset, location.impl.geometrySize, value); setMatrix3(tessEvalConstants, location.impl.tessEvalOffset, location.impl.tessEvalSize, value); setMatrix3(tessControlConstants, location.impl.tessControlOffset, location.impl.tessControlSize, value); + setMatrix3(computeConstants, location.impl.computeOffset, location.impl.computeSize, value); } void kinc_g4_set_texture_magnification_filter(kinc_g4_texture_unit_t unit, kinc_g4_texture_filter_t filter) { @@ -863,6 +884,8 @@ void kinc_g4_set_texture_magnification_filter(kinc_g4_texture_unit_t unit, kinc_ case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; break; + default: + break; } break; case KINC_G4_TEXTURE_FILTER_LINEAR: @@ -883,6 +906,8 @@ void kinc_g4_set_texture_magnification_filter(kinc_g4_texture_unit_t unit, kinc_ case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; break; + default: + break; } break; case KINC_G4_TEXTURE_FILTER_ANISOTROPIC: @@ -927,6 +952,8 @@ void kinc_g4_set_texture_minification_filter(kinc_g4_texture_unit_t unit, kinc_g case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; break; + default: + break; } break; case KINC_G4_TEXTURE_FILTER_LINEAR: @@ -948,11 +975,15 @@ void kinc_g4_set_texture_minification_filter(kinc_g4_texture_unit_t unit, kinc_g case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; break; + default: + break; } break; case KINC_G4_TEXTURE_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_ANISOTROPIC; break; + default: + break; } lastSamplers[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]].Filter = d3d11filter; @@ -995,6 +1026,8 @@ void kinc_g4_set_texture_mipmap_filter(kinc_g4_texture_unit_t unit, kinc_g4_mipm case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_ANISOTROPIC; break; + default: + break; } break; case KINC_G4_MIPMAP_FILTER_LINEAR: @@ -1018,6 +1051,8 @@ void kinc_g4_set_texture_mipmap_filter(kinc_g4_texture_unit_t unit, kinc_g4_mipm case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_ANISOTROPIC; break; + default: + break; } break; } @@ -1171,19 +1206,11 @@ void kinc_g4_set_index_buffer(kinc_g4_index_buffer_t *buffer) { kinc_internal_g4_index_buffer_set(buffer); } -#ifdef KINC_KONG -void kinc_internal_texture_set(kinc_g4_texture_t *texture, uint32_t unit); - -void kinc_g4_set_texture(uint32_t unit, kinc_g4_texture_t *texture) { - kinc_internal_texture_set(texture, unit); -} -#else void kinc_internal_texture_set(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit); void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) { kinc_internal_texture_set(texture, unit); } -#endif void kinc_internal_texture_set_image(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit); @@ -1303,10 +1330,3 @@ bool kinc_g4_supports_non_pow2_textures(void) { bool kinc_g4_render_targets_inverted_y(void) { return false; } - -#ifdef KINC_KONG -void kinc_g4_set_constant_buffer(uint32_t id, struct kinc_g4_constant_buffer *buffer) { - dx_ctx.context->lpVtbl->VSSetConstantBuffers(dx_ctx.context, id, 1, &buffer->impl.buffer); - dx_ctx.context->lpVtbl->PSSetConstantBuffers(dx_ctx.context, id, 1, &buffer->impl.buffer); -} -#endif diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/ShaderHash.c.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/ShaderHash.c.h index c1114a1..bfbd458 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/ShaderHash.c.h +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/ShaderHash.c.h @@ -4,7 +4,7 @@ uint32_t kinc_internal_hash_name(unsigned char *str) { unsigned long hash = 5381; int c; - while (c = *str++) { + while ((c = *str++)) { hash = hash * 33 ^ c; } return hash; diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/compute.c.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/compute.c.h new file mode 100644 index 0000000..1ce5d2f --- /dev/null +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/compute.c.h @@ -0,0 +1,195 @@ +#include "Direct3D11.h" + +#include +#include +#include +#include + +#include + +#include + +static int getMultipleOf16(int value) { + int ret = 16; + while (ret < value) + ret += 16; + return ret; +} + +void kinc_g4_compute_shader_init(kinc_g4_compute_shader *shader, void *_data, int length) { + unsigned index = 0; + uint8_t *data = (uint8_t *)_data; + + memset(&shader->impl.attributes, 0, sizeof(shader->impl.attributes)); + int attributesCount = data[index++]; + for (int i = 0; i < attributesCount; ++i) { + unsigned char name[256]; + for (unsigned i2 = 0; i2 < 255; ++i2) { + name[i2] = data[index++]; + if (name[i2] == 0) + break; + } + shader->impl.attributes[i].hash = kinc_internal_hash_name(name); + shader->impl.attributes[i].index = data[index++]; + } + + memset(&shader->impl.textures, 0, sizeof(shader->impl.textures)); + uint8_t texCount = data[index++]; + for (unsigned i = 0; i < texCount; ++i) { + unsigned char name[256]; + for (unsigned i2 = 0; i2 < 255; ++i2) { + name[i2] = data[index++]; + if (name[i2] == 0) + break; + } + shader->impl.textures[i].hash = kinc_internal_hash_name(name); + shader->impl.textures[i].index = data[index++]; + } + + memset(&shader->impl.constants, 0, sizeof(shader->impl.constants)); + uint8_t constantCount = data[index++]; + shader->impl.constantsSize = 0; + for (unsigned i = 0; i < constantCount; ++i) { + unsigned char name[256]; + for (unsigned i2 = 0; i2 < 255; ++i2) { + name[i2] = data[index++]; + if (name[i2] == 0) + break; + } + kinc_g4_compute_internal_shader_constant constant; + constant.hash = kinc_internal_hash_name(name); + constant.offset = *(uint32_t *)&data[index]; + index += 4; + constant.size = *(uint32_t *)&data[index]; + index += 4; + constant.columns = data[index]; + index += 1; + constant.rows = data[index]; + index += 1; + + shader->impl.constants[i] = constant; + shader->impl.constantsSize = constant.offset + constant.size; + } + + shader->impl.length = (int)(length - index); + shader->impl.data = (uint8_t *)malloc(shader->impl.length); + assert(shader->impl.data != NULL); + memcpy(shader->impl.data, &data[index], shader->impl.length); + + HRESULT hr = + dx_ctx.device->lpVtbl->CreateComputeShader(dx_ctx.device, shader->impl.data, shader->impl.length, NULL, (ID3D11ComputeShader **)&shader->impl.shader); + + if (hr != S_OK) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Could not initialize compute shader."); + return; + } + + D3D11_BUFFER_DESC desc; + desc.ByteWidth = getMultipleOf16(shader->impl.constantsSize); + desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + kinc_microsoft_affirm(dx_ctx.device->lpVtbl->CreateBuffer(dx_ctx.device, &desc, NULL, &shader->impl.constantBuffer)); +} + +void kinc_g4_compute_shader_destroy(kinc_g4_compute_shader *shader) {} + +static kinc_g4_compute_internal_shader_constant *compute_findConstant(kinc_g4_compute_internal_shader_constant *constants, uint32_t hash) { + for (int i = 0; i < 64; ++i) { + if (constants[i].hash == hash) { + return &constants[i]; + } + } + return NULL; +} + +static kinc_internal_hash_index_t *compute_findTextureUnit(kinc_internal_hash_index_t *units, uint32_t hash) { + for (int i = 0; i < 64; ++i) { + if (units[i].hash == hash) { + return &units[i]; + } + } + return NULL; +} + +kinc_g4_constant_location_t kinc_g4_compute_shader_get_constant_location(kinc_g4_compute_shader *shader, const char *name) { + kinc_g4_constant_location_t location = {0}; + + uint32_t hash = kinc_internal_hash_name((unsigned char *)name); + + kinc_g4_compute_internal_shader_constant *constant = compute_findConstant(shader->impl.constants, hash); + if (constant == NULL) { + location.impl.computeOffset = 0; + location.impl.computeSize = 0; + location.impl.computeColumns = 0; + location.impl.computeRows = 0; + } + else { + location.impl.computeOffset = constant->offset; + location.impl.computeSize = constant->size; + location.impl.computeColumns = constant->columns; + location.impl.computeRows = constant->rows; + } + + if (location.impl.computeSize == 0) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Uniform %s not found.", name); + } + + return location; +} + +kinc_g4_texture_unit_t kinc_g4_compute_shader_get_texture_unit(kinc_g4_compute_shader *shader, const char *name) { + char unitName[64]; + int unitOffset = 0; + size_t len = strlen(name); + if (len > 63) { + len = 63; + } + strncpy(unitName, name, len + 1); + if (unitName[len - 1] == ']') { // Check for array - mySampler[2] + unitOffset = (int)(unitName[len - 2] - '0'); // Array index is unit offset + unitName[len - 3] = 0; // Strip array from name + } + + uint32_t hash = kinc_internal_hash_name((unsigned char *)unitName); + + kinc_g4_texture_unit_t unit; + for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) { + unit.stages[i] = -1; + } + + kinc_internal_hash_index_t *compute_unit = compute_findTextureUnit(shader->impl.textures, hash); + if (compute_unit == NULL) { + unit.stages[KINC_G4_SHADER_TYPE_COMPUTE] = -1; +#ifndef NDEBUG + static int notFoundCount = 0; + if (notFoundCount < 10) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Sampler %s not found.", unitName); + ++notFoundCount; + } + else if (notFoundCount == 10) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Giving up on sampler not found messages.", unitName); + ++notFoundCount; + } +#endif + } + else { + unit.stages[KINC_G4_SHADER_TYPE_COMPUTE] = compute_unit->index + unitOffset; + } + return unit; +} + +void kinc_g4_set_compute_shader(kinc_g4_compute_shader *shader) { + dx_ctx.context->lpVtbl->CSSetShader(dx_ctx.context, (ID3D11ComputeShader *)shader->impl.shader, NULL, 0); + dx_ctx.context->lpVtbl->UpdateSubresource(dx_ctx.context, (ID3D11Resource *)shader->impl.constantBuffer, 0, NULL, computeConstants, 0, 0); + dx_ctx.context->lpVtbl->CSSetConstantBuffers(dx_ctx.context, 0, 1, &shader->impl.constantBuffer); +} + +void kinc_g4_compute(int x, int y, int z) { + dx_ctx.context->lpVtbl->Dispatch(dx_ctx.context, x, y, z); + + ID3D11UnorderedAccessView *nullView = NULL; + dx_ctx.context->lpVtbl->CSSetUnorderedAccessViews(dx_ctx.context, 0, 1, &nullView, NULL); +} diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/compute.h similarity index 54% rename from Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.h rename to Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/compute.h index c263892..ce4fc5d 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/compute.h +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/compute.h @@ -8,37 +8,36 @@ extern "C" { struct ID3D11Buffer; -typedef struct { +typedef struct kinc_g4_compute_constant_location_impl { uint32_t offset; uint32_t size; uint8_t columns; uint8_t rows; -} kinc_compute_constant_location_impl_t; +} kinc_g4_compute_constant_location_impl; -typedef struct { +typedef struct kinc_g4_compute_texture_unit_impl { int unit; -} kinc_compute_texture_unit_impl_t; +} kinc_g4_compute_texture_unit_impl; -typedef struct { +typedef struct kinc_g4_compute_internal_shader_constant { uint32_t hash; uint32_t offset; uint32_t size; uint8_t columns; uint8_t rows; -} kinc_compute_internal_shader_constant_t; +} kinc_g4_compute_internal_shader_constant; -typedef struct { -#ifndef KINC_KONG - kinc_compute_internal_shader_constant_t constants[64]; +typedef struct kinc_g4_compute_shader_impl { + kinc_g4_compute_internal_shader_constant constants[64]; int constantsSize; kinc_internal_hash_index_t attributes[64]; kinc_internal_hash_index_t textures[64]; struct ID3D11Buffer *constantBuffer; -#endif + void *shader; uint8_t *data; int length; -} kinc_compute_shader_impl_t; +} kinc_g4_compute_shader_impl; #ifdef __cplusplus } diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/constantbuffer.c.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/constantbuffer.c.h deleted file mode 100644 index fb6b9c7..0000000 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/constantbuffer.c.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifdef KINC_KONG - -#include - -void kinc_g4_constant_buffer_init(kinc_g4_constant_buffer *buffer, size_t size) { - buffer->impl.size = size; - buffer->impl.last_start = 0; - buffer->impl.last_size = size; - - D3D11_BUFFER_DESC desc; - desc.ByteWidth = (UINT)get_multiple_of_16(size); - desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - desc.Usage = D3D11_USAGE_DYNAMIC; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - desc.MiscFlags = 0; - desc.StructureByteStride = 0; - kinc_microsoft_affirm(dx_ctx.device->lpVtbl->CreateBuffer(dx_ctx.device, &desc, NULL, &buffer->impl.buffer)); -} - -void kinc_g4_constant_buffer_destroy(kinc_g4_constant_buffer *buffer) { - buffer->impl.buffer->lpVtbl->Release(buffer->impl.buffer); -} - -uint8_t *kinc_g4_constant_buffer_lock_all(kinc_g4_constant_buffer *buffer) { - return kinc_g4_constant_buffer_lock(buffer, 0, kinc_g4_constant_buffer_size(buffer)); -} - -uint8_t *kinc_g4_constant_buffer_lock(kinc_g4_constant_buffer *buffer, size_t start, size_t size) { - buffer->impl.last_start = start; - buffer->impl.last_size = size; - - D3D11_MAPPED_SUBRESOURCE mapped_resource; - memset(&mapped_resource, 0, sizeof(D3D11_MAPPED_SUBRESOURCE)); - dx_ctx.context->lpVtbl->Map(dx_ctx.context, (ID3D11Resource *)buffer->impl.buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource); - uint8_t *data = (uint8_t *)mapped_resource.pData; - return &data[start]; -} - -void kinc_g4_constant_buffer_unlock_all(kinc_g4_constant_buffer *buffer) { - kinc_g4_constant_buffer_unlock(buffer, buffer->impl.last_size); -} - -void kinc_g4_constant_buffer_unlock(kinc_g4_constant_buffer *buffer, size_t count) { - dx_ctx.context->lpVtbl->Unmap(dx_ctx.context, (ID3D11Resource *)buffer->impl.buffer, 0); -} - -size_t kinc_g4_constant_buffer_size(kinc_g4_constant_buffer *buffer) { - return buffer->impl.size; -} - -#endif diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/constantbuffer.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/constantbuffer.h deleted file mode 100644 index 1381fac..0000000 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/constantbuffer.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#ifdef KINC_KONG - -struct ID3D11Buffer; - -typedef struct kinc_g4_constant_buffer_impl { - struct ID3D11Buffer *buffer; - size_t size; - size_t last_start; - size_t last_size; -} kinc_g4_constant_buffer_impl; - -#endif diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/d3d11unit.c b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/d3d11unit.c index 281c27b..68dd402 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/d3d11unit.c +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/d3d11unit.c @@ -1,5 +1,8 @@ // Windows 7 #define WINVER 0x0601 +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif #define _WIN32_WINNT 0x0601 #define NOATOM @@ -21,7 +24,7 @@ #define NOMENUS #define NOMETAFILE #define NOMINMAX -//#define NOMSG +// #define NOMSG #define NONLS #define NOOPENFILE #define NOPROFILER @@ -33,7 +36,7 @@ #define NOSYSCOMMANDS #define NOSYSMETRICS #define NOTEXTMETRIC -//#define NOUSER +// #define NOUSER #define NOVIRTUALKEYCODES #define NOWH #define NOWINMESSAGES @@ -45,7 +48,7 @@ #include -#ifdef KORE_WINDOWSAPP +#ifdef KINC_WINDOWSAPP #include #else #pragma warning(disable : 4005) @@ -65,6 +68,7 @@ static uint8_t fragmentConstants[1024 * 4]; static uint8_t geometryConstants[1024 * 4]; static uint8_t tessControlConstants[1024 * 4]; static uint8_t tessEvalConstants[1024 * 4]; +static uint8_t computeConstants[1024 * 4]; static D3D11_COMPARISON_FUNC get_comparison(kinc_g4_compare_mode_t compare) { switch (compare) { @@ -98,7 +102,7 @@ static size_t get_multiple_of_16(size_t value) { #include "Direct3D11.c.h" #include "ShaderHash.c.h" -#include "constantbuffer.c.h" +#include "compute.c.h" #include "indexbuffer.c.h" #include "pipeline.c.h" #include "rendertarget.c.h" diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/indexbuffer.c.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/indexbuffer.c.h index b2c5cb7..a3d843c 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/indexbuffer.c.h +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/indexbuffer.c.h @@ -1,4 +1,4 @@ -#include +#include void kinc_g4_index_buffer_init(kinc_g4_index_buffer_t *buffer, int count, kinc_g4_index_buffer_format_t format, kinc_g4_usage_t usage) { buffer->impl.count = count; diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h index 78a07c6..7f12f31 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h @@ -1,7 +1,6 @@ #include #include #include -#include #include kinc_g4_pipeline_t *currentPipeline = NULL; @@ -91,7 +90,6 @@ static D3D11_STENCIL_OP get_stencil_action(kinc_g4_stencil_action_t action) { } void kinc_internal_set_constants(void) { -#ifndef KINC_KONG if (currentPipeline->vertex_shader->impl.constantsSize > 0) { dx_ctx.context->lpVtbl->UpdateSubresource(dx_ctx.context, (ID3D11Resource *)currentPipeline->impl.vertexConstantBuffer, 0, NULL, vertexConstants, 0, 0); dx_ctx.context->lpVtbl->VSSetConstantBuffers(dx_ctx.context, 0, 1, ¤tPipeline->impl.vertexConstantBuffer); @@ -116,7 +114,6 @@ void kinc_internal_set_constants(void) { 0); dx_ctx.context->lpVtbl->DSSetConstantBuffers(dx_ctx.context, 0, 1, ¤tPipeline->impl.tessEvalConstantBuffer); } -#endif } void kinc_g4_pipeline_init(struct kinc_g4_pipeline *state) { @@ -211,7 +208,6 @@ void kinc_internal_pipeline_rebind() { } } -#ifndef KINC_KONG static kinc_internal_shader_constant_t *findConstant(kinc_internal_shader_constant_t *constants, uint32_t hash) { for (int i = 0; i < 64; ++i) { if (constants[i].hash == hash) { @@ -258,7 +254,7 @@ void kinc_g4_pipeline_get_constant_locations(kinc_g4_pipeline_t *state, kinc_g4_ } kinc_g4_constant_location_t kinc_g4_pipeline_get_constant_location(struct kinc_g4_pipeline *state, const char *name) { - kinc_g4_constant_location_t location; + kinc_g4_constant_location_t location = {0}; uint32_t hash = kinc_internal_hash_name((unsigned char *)name); @@ -371,7 +367,6 @@ kinc_g4_texture_unit_t kinc_g4_pipeline_get_texture_unit(struct kinc_g4_pipeline return unit; } -#endif static char stringCache[1024]; static int stringCacheIndex = 0; @@ -436,7 +431,6 @@ static void createRenderTargetBlendDesc(struct kinc_g4_pipeline *pipe, D3D11_REN } void kinc_g4_pipeline_compile(struct kinc_g4_pipeline *state) { -#ifndef KINC_KONG if (state->vertex_shader->impl.constantsSize > 0) { D3D11_BUFFER_DESC desc; desc.ByteWidth = (UINT)get_multiple_of_16(state->vertex_shader->impl.constantsSize); @@ -487,7 +481,6 @@ void kinc_g4_pipeline_compile(struct kinc_g4_pipeline *state) { desc.StructureByteStride = 0; kinc_microsoft_affirm(dx_ctx.device->lpVtbl->CreateBuffer(dx_ctx.device, &desc, NULL, &state->impl.tessEvalConstantBuffer)); } -#endif int all = 0; for (int stream = 0; state->input_layout[stream] != NULL; ++stream) { @@ -501,21 +494,16 @@ void kinc_g4_pipeline_compile(struct kinc_g4_pipeline *state) { } } -#ifndef KINC_KONG bool used[usedCount]; for (int i = 0; i < usedCount; ++i) used[i] = false; for (int i = 0; i < 64; ++i) { used[state->vertex_shader->impl.attributes[i].index] = true; } -#endif + stringCacheIndex = 0; D3D11_INPUT_ELEMENT_DESC *vertexDesc = (D3D11_INPUT_ELEMENT_DESC *)alloca(sizeof(D3D11_INPUT_ELEMENT_DESC) * all); -#ifdef KINC_KONG -#define getAttributeLocation(a, b, c) index -#endif - int i = 0; for (int stream = 0; state->input_layout[stream] != NULL; ++stream) { for (int index = 0; index < state->input_layout[stream]->size; ++index) { @@ -788,6 +776,8 @@ void kinc_g4_pipeline_compile(struct kinc_g4_pipeline *state) { } break; } + default: + break; } } } diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/rendertarget.c.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/rendertarget.c.h index 9e6e102..34cce52 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/rendertarget.c.h +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/rendertarget.c.h @@ -373,17 +373,6 @@ void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget) { renderTarget->impl.textureSample->lpVtbl->Release(renderTarget->impl.textureSample); } -#ifdef KINC_KONG -void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, uint32_t unit) { - if (renderTarget->impl.textureSample != renderTarget->impl.textureRender) { - dx_ctx.context->lpVtbl->ResolveSubresource(dx_ctx.context, (ID3D11Resource *)renderTarget->impl.textureSample, 0, - (ID3D11Resource *)renderTarget->impl.textureRender, 0, DXGI_FORMAT_R8G8B8A8_UNORM); - } - - dx_ctx.context->lpVtbl->PSSetShaderResources(dx_ctx.context, unit, 1, - renderTarget->isDepthAttachment ? &renderTarget->impl.depthStencilSRV : &renderTarget->impl.renderTargetSRV); -} -#else void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) { if (unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] < 0 && unit.stages[KINC_G4_SHADER_TYPE_VERTEX] < 0) return; @@ -405,7 +394,6 @@ void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderT : &renderTarget->impl.renderTargetSRV); } } -#endif void kinc_g4_render_target_use_depth_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) { if (unit.stages[KINC_G4_SHADER_TYPE_VERTEX] >= 0) { diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.c.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.c.h index af95869..70671d5 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.c.h +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.c.h @@ -12,7 +12,6 @@ void kinc_g4_shader_init(kinc_g4_shader_t *shader, const void *_data, size_t len uint8_t *data = (uint8_t *)_data; shader->impl.type = (int)type; -#ifndef KINC_KONG memset(&shader->impl.attributes, 0, sizeof(shader->impl.attributes)); int attributesCount = data[index++]; for (int i = 0; i < attributesCount; ++i) { @@ -63,7 +62,6 @@ void kinc_g4_shader_init(kinc_g4_shader_t *shader, const void *_data, size_t len shader->impl.constants[i] = constant; shader->impl.constantsSize = constant.offset + constant.size; } -#endif shader->impl.length = (int)(length - index); shader->impl.data = (uint8_t *)malloc(shader->impl.length); diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.h index 2e56b6d..691f919 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.h +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/shader.h @@ -18,12 +18,11 @@ typedef struct { } kinc_internal_shader_constant_t; typedef struct { -#ifndef KINC_KONG kinc_internal_shader_constant_t constants[64]; int constantsSize; kinc_internal_hash_index_t attributes[64]; kinc_internal_hash_index_t textures[64]; -#endif + void *shader; uint8_t *data; int length; @@ -41,6 +40,8 @@ typedef struct { uint32_t tessEvalSize; uint32_t tessControlOffset; uint32_t tessControlSize; + uint32_t computeOffset; + uint32_t computeSize; uint8_t vertexColumns; uint8_t vertexRows; uint8_t fragmentColumns; @@ -51,6 +52,8 @@ typedef struct { uint8_t tessEvalRows; uint8_t tessControlColumns; uint8_t tessControlRows; + uint8_t computeColumns; + uint8_t computeRows; } kinc_g4_constant_location_impl_t; #ifdef __cplusplus diff --git a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/texture.c.h b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/texture.c.h index 730e663..dbda2f4 100644 --- a/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/texture.c.h +++ b/Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/texture.c.h @@ -207,16 +207,8 @@ void kinc_internal_texture_unmipmap(kinc_g4_texture_t *texture) { texture->impl.hasMipmaps = false; } -#ifdef KINC_KONG -void kinc_internal_texture_set(kinc_g4_texture_t *texture, uint32_t unit) { - dx_ctx.context->lpVtbl->PSSetShaderResources(dx_ctx.context, unit, 1, &texture->impl.view); - - texture->impl.stage = unit; - setTextures[unit] = texture; -} -#else void kinc_internal_texture_set(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit) { - if (unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] < 0 && unit.stages[KINC_G4_SHADER_TYPE_VERTEX] < 0) + if (unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] < 0 && unit.stages[KINC_G4_SHADER_TYPE_VERTEX] < 0 && unit.stages[KINC_G4_SHADER_TYPE_COMPUTE] < 0) return; if (unit.stages[KINC_G4_SHADER_TYPE_VERTEX] >= 0) { @@ -227,13 +219,19 @@ void kinc_internal_texture_set(kinc_g4_texture_t *texture, kinc_g4_texture_unit_ dx_ctx.context->lpVtbl->PSSetShaderResources(dx_ctx.context, unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT], 1, &texture->impl.view); } - texture->impl.stage = unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] >= 0 ? unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] : unit.stages[KINC_G4_SHADER_TYPE_VERTEX]; - setTextures[texture->impl.stage] = texture; + if (unit.stages[KINC_G4_SHADER_TYPE_COMPUTE] >= 0) { + dx_ctx.context->lpVtbl->PSSetShaderResources(dx_ctx.context, unit.stages[KINC_G4_SHADER_TYPE_COMPUTE], 1, &texture->impl.view); + } + + if (unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] >= 0 || unit.stages[KINC_G4_SHADER_TYPE_VERTEX] >= 0) { + texture->impl.stage = + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] >= 0 ? unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] : unit.stages[KINC_G4_SHADER_TYPE_VERTEX]; + setTextures[texture->impl.stage] = texture; + } } -#endif void kinc_internal_texture_set_image(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit) { - if (unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] < 0) + if (unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] < 0 && unit.stages[KINC_G4_SHADER_TYPE_VERTEX] < 0 && unit.stages[KINC_G4_SHADER_TYPE_COMPUTE] < 0) return; if (texture->impl.computeView == NULL) { @@ -246,8 +244,25 @@ void kinc_internal_texture_set_image(kinc_g4_texture_t *texture, kinc_g4_texture kinc_microsoft_affirm( dx_ctx.device->lpVtbl->CreateUnorderedAccessView(dx_ctx.device, (ID3D11Resource *)texture->impl.texture3D, &du, &texture->impl.computeView)); } - dx_ctx.context->lpVtbl->OMSetRenderTargetsAndUnorderedAccessViews(dx_ctx.context, 0, NULL, NULL, unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT], 1, - &texture->impl.computeView, NULL); + + if (unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT] >= 0) { + ID3D11ShaderResourceView *nullView = NULL; + dx_ctx.context->lpVtbl->PSSetShaderResources(dx_ctx.context, 0, 1, &nullView); + + dx_ctx.context->lpVtbl->CSSetUnorderedAccessViews(dx_ctx.context, unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT], 1, &texture->impl.computeView, NULL); + } + if (unit.stages[KINC_G4_SHADER_TYPE_VERTEX] >= 0) { + ID3D11ShaderResourceView *nullView = NULL; + dx_ctx.context->lpVtbl->PSSetShaderResources(dx_ctx.context, 0, 1, &nullView); + + dx_ctx.context->lpVtbl->CSSetUnorderedAccessViews(dx_ctx.context, unit.stages[KINC_G4_SHADER_TYPE_VERTEX], 1, &texture->impl.computeView, NULL); + } + if (unit.stages[KINC_G4_SHADER_TYPE_COMPUTE] >= 0) { + ID3D11ShaderResourceView *nullView = NULL; + dx_ctx.context->lpVtbl->PSSetShaderResources(dx_ctx.context, 0, 1, &nullView); + + dx_ctx.context->lpVtbl->CSSetUnorderedAccessViews(dx_ctx.context, unit.stages[KINC_G4_SHADER_TYPE_COMPUTE], 1, &texture->impl.computeView, NULL); + } } void kinc_internal_texture_unset(kinc_g4_texture_t *texture) { diff --git a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/compute.cpp b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/compute.cpp deleted file mode 100644 index 22c3b46..0000000 --- a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/compute.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -#include - -void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *source, int length) {} - -void kinc_compute_shader_destroy(kinc_compute_shader_t *shader) {} - -kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_constant_location_t location = {0}; - return location; -} - -kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_texture_unit_t unit = {0}; - return unit; -} - -void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value) {} - -void kinc_compute_set_int(kinc_compute_constant_location_t location, int value) {} - -void kinc_compute_set_float(kinc_compute_constant_location_t location, float value) {} - -void kinc_compute_set_float2(kinc_compute_constant_location_t location, float value1, float value2) {} - -void kinc_compute_set_float3(kinc_compute_constant_location_t location, float value1, float value2, float value3) {} - -void kinc_compute_set_float4(kinc_compute_constant_location_t location, float value1, float value2, float value3, float value4) {} - -void kinc_compute_set_floats(kinc_compute_constant_location_t location, float *values, int count) {} - -void kinc_compute_set_matrix4(kinc_compute_constant_location_t location, kinc_matrix4x4_t *value) {} - -void kinc_compute_set_matrix3(kinc_compute_constant_location_t location, kinc_matrix3x3_t *value) {} - -void kinc_compute_set_texture(kinc_compute_texture_unit_t unit, kinc_g4_texture_t *texture, kinc_compute_access_t access) {} - -void kinc_compute_set_render_target(kinc_compute_texture_unit_t unit, kinc_g4_render_target_t *target, kinc_compute_access_t access) {} - -void kinc_compute_set_sampled_texture(kinc_compute_texture_unit_t unit, kinc_g4_texture_t *texture) {} - -void kinc_compute_set_sampled_render_target(kinc_compute_texture_unit_t unit, kinc_g4_render_target_t *target) {} - -void kinc_compute_set_sampled_depth_from_render_target(kinc_compute_texture_unit_t unit, kinc_g4_render_target_t *target) {} - -void kinc_compute_set_texture_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} - -void kinc_compute_set_texture3d_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} - -void kinc_compute_set_texture_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture3d_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} - -void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} - -void kinc_compute_set_shader(kinc_compute_shader_t *shader) {} - -void kinc_compute(int x, int y, int z) {} diff --git a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/compute.h b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/compute.h deleted file mode 100644 index bf8d1da..0000000 --- a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/compute.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - int nothing; -} kinc_compute_constant_location_impl_t; - -typedef struct { - int nothing; -} kinc_compute_texture_unit_impl_t; - -typedef struct { - int nothing; -} kinc_compute_internal_shader_constant_t; - -typedef struct { - int nothing; -} kinc_compute_shader_impl_t; - -#ifdef __cplusplus -} -#endif diff --git a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/Direct3D9.cpp b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/Direct3D9.cpp index d808363..238f814 100644 --- a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/Direct3D9.cpp +++ b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/Direct3D9.cpp @@ -161,7 +161,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil return; } -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS // TODO (DK) convert depthBufferBits + stencilBufferBits to: d3dpp.AutoDepthStencilFormat = D3DFMT_D24X8; D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); @@ -201,7 +201,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device); // d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device); -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS // if (System::hasShowWindowFlag(/*windowId*/)) { ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); @@ -210,7 +210,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil initDeviceStates(); -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS if (fullscreen) { // hz = d3dpp.FullScreen_RefreshRateInHz; D3DDISPLAYMODE mode; @@ -719,19 +719,11 @@ void kinc_g4_set_index_buffer(kinc_g4_index_buffer_t *buffer) { kinc_internal_g4_index_buffer_set(buffer); } -#ifdef KINC_KONG -void kinc_internal_texture_set(kinc_g4_texture_t *texture, uint32_t unit); - -void kinc_g4_set_texture(uint32_t unit, struct kinc_g4_texture *texture) { - kinc_internal_texture_set(texture, unit); -} -#else void kinc_internal_texture_set(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit); void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture) { kinc_internal_texture_set(texture, unit); } -#endif void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture) {} diff --git a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/compute.cpp b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/compute.cpp new file mode 100644 index 0000000..a120b75 --- /dev/null +++ b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/compute.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +void kinc_g4_compute_shader_init(kinc_g4_compute_shader *shader, void *source, int length) {} + +void kinc_g4_compute_shader_destroy(kinc_g4_compute_shader *shader) {} + +kinc_g4_constant_location_t kinc_g4_compute_shader_get_constant_location(kinc_g4_compute_shader *shader, const char *name) { + kinc_g4_constant_location_t location = {0}; + return location; +} + +kinc_g4_texture_unit_t kinc_g4_compute_shader_get_texture_unit(kinc_g4_compute_shader *shader, const char *name) { + kinc_g4_texture_unit_t unit = {0}; + return unit; +} + +void kinc_g4_set_compute_shader(kinc_g4_compute_shader *shader) {} + +void kinc_g4_compute(int x, int y, int z) {} diff --git a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/compute.h b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/compute.h new file mode 100644 index 0000000..39b0453 --- /dev/null +++ b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/compute.h @@ -0,0 +1,13 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct kinc_g4_compute_shader_impl { + int nothing; +} kinc_g4_compute_shader_impl; + +#ifdef __cplusplus +} +#endif diff --git a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.cpp b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.cpp deleted file mode 100644 index b5e8a1d..0000000 --- a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef KINC_KONG - -#include - -#include "Direct3D9.h" - -void kinc_g4_constant_buffer_init(kinc_g4_constant_buffer *buffer, size_t size) { - buffer->impl.size = size; - buffer->impl.last_start = 0; - buffer->impl.last_size = size; -} - -void kinc_g4_constant_buffer_destroy(kinc_g4_constant_buffer *buffer) {} - -uint8_t *kinc_g4_constant_buffer_lock_all(kinc_g4_constant_buffer *buffer) { - return NULL; -} - -uint8_t *kinc_g4_constant_buffer_lock(kinc_g4_constant_buffer *buffer, size_t start, size_t size) { - buffer->impl.last_start = start; - buffer->impl.last_size = size; - - return NULL; -} - -void kinc_g4_constant_buffer_unlock_all(kinc_g4_constant_buffer *buffer) {} - -void kinc_g4_constant_buffer_unlock(kinc_g4_constant_buffer *buffer, size_t count) {} - -size_t kinc_g4_constant_buffer_size(kinc_g4_constant_buffer *buffer) { - return buffer->impl.size; -} - -#endif diff --git a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.h b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.h deleted file mode 100644 index ac7b3ac..0000000 --- a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/constantbuffer.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#ifdef KINC_KONG - -typedef struct kinc_g4_constant_buffer_impl { - size_t size; - size_t last_start; - size_t last_size; -} kinc_g4_constant_buffer_impl; - -#endif diff --git a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/rendertarget.cpp b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/rendertarget.cpp index 9f7ed56..391f152 100644 --- a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/rendertarget.cpp +++ b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/rendertarget.cpp @@ -90,17 +90,6 @@ void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget) { } } -#ifdef KINC_KONG -void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, uint32_t unit) { - if (renderTarget->impl.antialiasing) { - IDirect3DSurface9 *surface; - renderTarget->impl.colorTexture->GetSurfaceLevel(0, &surface); - kinc_microsoft_affirm(device->StretchRect(renderTarget->impl.colorSurface, nullptr, surface, nullptr, D3DTEXF_NONE)); - surface->Release(); - } - device->SetTexture(unit, renderTarget->isDepthAttachment ? renderTarget->impl.depthTexture : renderTarget->impl.colorTexture); -} -#else void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) { if (renderTarget->impl.antialiasing) { IDirect3DSurface9 *surface; @@ -111,7 +100,6 @@ void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderT device->SetTexture(unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT], renderTarget->isDepthAttachment ? renderTarget->impl.depthTexture : renderTarget->impl.colorTexture); } -#endif void kinc_g4_render_target_set_depth_stencil_from(kinc_g4_render_target_t *renderTarget, kinc_g4_render_target_t *source) { renderTarget->impl.depthTexture = source->impl.depthTexture; diff --git a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/texture.cpp b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/texture.cpp index c827aa0..02a5145 100644 --- a/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/texture.cpp +++ b/Kinc/Backends/Graphics4/Direct3D9/Sources/kinc/backend/graphics4/texture.cpp @@ -67,19 +67,11 @@ void kinc_g4_texture_destroy(kinc_g4_texture_t *texture) { texture->impl.texture->Release(); } -#ifdef KINC_KONG -void kinc_internal_texture_set(kinc_g4_texture_t *texture, uint32_t unit) { - kinc_microsoft_affirm(device->SetTexture(unit, texture->impl.texture)); - texture->impl.stage = unit; - setTextures[texture->impl.stage] = texture; -} -#else void kinc_internal_texture_set(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit) { kinc_microsoft_affirm(device->SetTexture(unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT], texture->impl.texture)); texture->impl.stage = unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]; setTextures[texture->impl.stage] = texture; } -#endif void kinc_internal_texture_unset(struct kinc_g4_texture *texture) { if (setTextures[texture->impl.stage] == texture) { diff --git a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h index 88c6e36..129baf5 100644 --- a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h +++ b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -16,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +34,7 @@ bool waitAfterNextDraw = false; static kinc_g5_constant_buffer_t vertexConstantBuffer; static kinc_g5_constant_buffer_t fragmentConstantBuffer; +static kinc_g5_constant_buffer_t computeConstantBuffer; #define constantBufferSize 4096 #define constantBufferMultiply 100 static int constantBufferIndex = 0; @@ -57,8 +58,10 @@ static struct { int currentBuffer; kinc_g5_render_target_t framebuffers[bufferCount]; + bool render_targets_initialized; kinc_g4_render_target_t *current_render_targets[renderTargetCount]; int current_render_target_count; + int depth_buffer_bits; bool resized; } windows[16] = {0}; @@ -70,6 +73,7 @@ static int current_window; typedef struct render_state { kinc_g5_pipeline_t *pipeline; + kinc_g5_compute_shader *compute_shader; kinc_g5_index_buffer_t *index_buffer; @@ -109,6 +113,7 @@ typedef struct render_state { uint8_t vertex_constant_data[constantBufferSize]; uint8_t fragment_constant_data[constantBufferSize]; + uint8_t compute_constant_data[constantBufferSize]; } render_state; static render_state current_state; @@ -127,14 +132,15 @@ void kinc_g4_on_g5_internal_restore_render_target(void) { void kinc_g4_internal_init_window(int window, int depthBufferBits, int stencilBufferBits, bool vsync) { kinc_g5_internal_init_window(window, depthBufferBits, stencilBufferBits, vsync); + windows[window].render_targets_initialized = false; + windows[window].depth_buffer_bits = depthBufferBits; + kinc_g5_command_list_init(&commandList); windows[window].currentBuffer = -1; - for (int i = 0; i < bufferCount; ++i) { - kinc_g5_render_target_init_framebuffer(&windows[window].framebuffers[i], kinc_window_width(window), kinc_window_height(window), - KINC_G5_RENDER_TARGET_FORMAT_32BIT, depthBufferBits, 0); - } + kinc_g5_constant_buffer_init(&vertexConstantBuffer, constantBufferSize * constantBufferMultiply); kinc_g5_constant_buffer_init(&fragmentConstantBuffer, constantBufferSize * constantBufferMultiply); + kinc_g5_constant_buffer_init(&computeConstantBuffer, constantBufferSize * constantBufferMultiply); // to support doing work after kinc_g4_end and before kinc_g4_begin kinc_g5_command_list_begin(&commandList); @@ -156,24 +162,32 @@ void kinc_g4_on_g5_internal_set_samplers(int count, kinc_g5_texture_unit_t *text } } -static void startDraw(void) { +static void startDraw(bool compute) { if ((constantBufferIndex + 1) >= constantBufferMultiply || waitAfterNextDraw) { memcpy(current_state.vertex_constant_data, vertexConstantBuffer.data, constantBufferSize); memcpy(current_state.fragment_constant_data, fragmentConstantBuffer.data, constantBufferSize); + memcpy(current_state.compute_constant_data, computeConstantBuffer.data, constantBufferSize); } kinc_g5_constant_buffer_unlock(&vertexConstantBuffer); kinc_g5_constant_buffer_unlock(&fragmentConstantBuffer); + kinc_g5_constant_buffer_unlock(&computeConstantBuffer); kinc_g4_on_g5_internal_set_samplers(current_state.texture_count, current_state.texture_units); kinc_g4_on_g5_internal_set_samplers(current_state.render_target_count, current_state.render_target_units); kinc_g4_on_g5_internal_set_samplers(current_state.depth_render_target_count, current_state.depth_render_target_units); - kinc_g5_command_list_set_vertex_constant_buffer(&commandList, &vertexConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize); - kinc_g5_command_list_set_fragment_constant_buffer(&commandList, &fragmentConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize); + if (compute) { + kinc_g5_command_list_set_compute_constant_buffer(&commandList, &computeConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize); + } + else { + kinc_g5_command_list_set_vertex_constant_buffer(&commandList, &vertexConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize); + kinc_g5_command_list_set_fragment_constant_buffer(&commandList, &fragmentConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize); + } } -static void endDraw(void) { +static void endDraw(bool compute) { ++constantBufferIndex; + if (constantBufferIndex >= constantBufferMultiply || waitAfterNextDraw) { kinc_g5_command_list_end(&commandList); kinc_g5_command_list_execute(&commandList); @@ -194,6 +208,12 @@ static void endDraw(void) { if (current_state.pipeline != NULL) { kinc_g5_command_list_set_pipeline(&commandList, current_state.pipeline); } + if (current_state.compute_shader != NULL) { +#ifndef KINC_METAL + // Metal still has some trouble switching between graphics and compute encoders + kinc_g5_command_list_set_compute_shader(&commandList, current_state.compute_shader); +#endif + } if (current_state.index_buffer != NULL) { kinc_g5_command_list_set_index_buffer(&commandList, current_state.index_buffer); } @@ -223,49 +243,53 @@ static void endDraw(void) { kinc_g5_command_list_set_texture_from_render_target_depth(&commandList, current_state.depth_render_target_units[i], current_state.depth_render_targets[i]); } + constantBufferIndex = 0; waitAfterNextDraw = false; kinc_g5_constant_buffer_lock(&vertexConstantBuffer, 0, constantBufferSize); kinc_g5_constant_buffer_lock(&fragmentConstantBuffer, 0, constantBufferSize); + kinc_g5_constant_buffer_lock(&computeConstantBuffer, 0, constantBufferSize); memcpy(vertexConstantBuffer.data, current_state.vertex_constant_data, constantBufferSize); memcpy(fragmentConstantBuffer.data, current_state.fragment_constant_data, constantBufferSize); + memcpy(computeConstantBuffer.data, current_state.compute_constant_data, constantBufferSize); } else { kinc_g5_constant_buffer_lock(&vertexConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize); kinc_g5_constant_buffer_lock(&fragmentConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize); + kinc_g5_constant_buffer_lock(&computeConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize); } } void kinc_g4_draw_indexed_vertices(void) { - startDraw(); + startDraw(false); kinc_g5_command_list_draw_indexed_vertices(&commandList); - endDraw(); + endDraw(false); } void kinc_g4_draw_indexed_vertices_from_to(int start, int count) { - startDraw(); + startDraw(false); kinc_g5_command_list_draw_indexed_vertices_from_to(&commandList, start, count); - endDraw(); + endDraw(false); } void kinc_g4_draw_indexed_vertices_from_to_from(int start, int count, int vertex_offset) { - startDraw(); + startDraw(false); kinc_g5_command_list_draw_indexed_vertices_from_to_from(&commandList, start, count, vertex_offset); - endDraw(); + endDraw(false); } void kinc_g4_draw_indexed_vertices_instanced(int instanceCount) { - startDraw(); + startDraw(false); kinc_g5_command_list_draw_indexed_vertices_instanced(&commandList, instanceCount); - endDraw(); + endDraw(false); } void kinc_g4_draw_indexed_vertices_instanced_from_to(int instanceCount, int start, int count) { - startDraw(); + startDraw(false); kinc_g5_command_list_draw_indexed_vertices_instanced_from_to(&commandList, instanceCount, start, count); - endDraw(); + endDraw(false); } void kinc_g4_clear(unsigned flags, unsigned color, float depth, int stencil) { @@ -287,6 +311,15 @@ void kinc_g4_clear(unsigned flags, unsigned color, float depth, int stencil) { bool first_run = true; void kinc_g4_begin(int window) { + if (!windows[window].render_targets_initialized) { + for (int i = 0; i < bufferCount; ++i) { + kinc_g5_render_target_init_framebuffer(&windows[window].framebuffers[i], kinc_window_width(window), kinc_window_height(window), + KINC_G5_RENDER_TARGET_FORMAT_32BIT, windows[window].depth_buffer_bits, 0); + } + + windows[window].render_targets_initialized = true; + } + // to support doing work after kinc_g4_end and before kinc_g4_begin kinc_g5_command_list_end(&commandList); kinc_g5_command_list_execute(&commandList); @@ -297,6 +330,7 @@ void kinc_g4_begin(int window) { bool resized = windows[window].resized; if (resized) { + kinc_g5_command_list_wait_for_execution_to_finish(&commandList); for (int i = 0; i < bufferCount; ++i) { kinc_g5_render_target_destroy(&windows[current_window].framebuffers[i]); } @@ -317,6 +351,7 @@ void kinc_g4_begin(int window) { windows[current_window].current_render_target_count = 1; current_state.pipeline = NULL; + current_state.compute_shader = NULL; current_state.index_buffer = NULL; for (int i = 0; i < MAX_VERTEX_BUFFERS; ++i) { current_state.vertex_buffers[i] = NULL; @@ -339,7 +374,7 @@ void kinc_g4_begin(int window) { // constantBufferIndex = 0; // kinc_g5_constant_buffer_lock(&vertexConstantBuffer, 0, constantBufferSize); // kinc_g5_constant_buffer_lock(&fragmentConstantBuffer, 0, constantBufferSize); - endDraw(); + endDraw(false); kinc_g5_command_list_framebuffer_to_render_target_barrier(&commandList, &windows[current_window].framebuffers[windows[current_window].currentBuffer]); kinc_g4_restore_render_target(); @@ -373,6 +408,7 @@ void kinc_g4_disable_scissor(void) { void kinc_g4_end(int window) { kinc_g5_constant_buffer_unlock(&vertexConstantBuffer); kinc_g5_constant_buffer_unlock(&fragmentConstantBuffer); + kinc_g5_constant_buffer_unlock(&computeConstantBuffer); kinc_g5_command_list_render_target_to_framebuffer_barrier(&commandList, &windows[current_window].framebuffers[windows[current_window].currentBuffer]); kinc_g5_command_list_end(&commandList); @@ -405,21 +441,53 @@ void kinc_g4_set_int(kinc_g4_constant_location_t location, int value) { kinc_g5_constant_buffer_set_int(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value); if (location.impl._location.impl.fragmentOffset >= 0) kinc_g5_constant_buffer_set_int(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_int(&computeConstantBuffer, location.impl._location.impl.computeOffset, value); } -void kinc_g4_set_int2(kinc_g4_constant_location_t location, int value1, int value2) {} +void kinc_g4_set_int2(kinc_g4_constant_location_t location, int value1, int value2) { + if (location.impl._location.impl.vertexOffset >= 0) + kinc_g5_constant_buffer_set_int2(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value1, value2); + if (location.impl._location.impl.fragmentOffset >= 0) + kinc_g5_constant_buffer_set_int2(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value1, value2); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_int2(&computeConstantBuffer, location.impl._location.impl.computeOffset, value1, value2); +} -void kinc_g4_set_int3(kinc_g4_constant_location_t location, int value1, int value2, int value3) {} +void kinc_g4_set_int3(kinc_g4_constant_location_t location, int value1, int value2, int value3) { + if (location.impl._location.impl.vertexOffset >= 0) + kinc_g5_constant_buffer_set_int3(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value1, value2, value3); + if (location.impl._location.impl.fragmentOffset >= 0) + kinc_g5_constant_buffer_set_int3(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value1, value2, value3); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_int3(&computeConstantBuffer, location.impl._location.impl.computeOffset, value1, value2, value3); +} -void kinc_g4_set_int4(kinc_g4_constant_location_t location, int value1, int value2, int value3, int value4) {} +void kinc_g4_set_int4(kinc_g4_constant_location_t location, int value1, int value2, int value3, int value4) { + if (location.impl._location.impl.vertexOffset >= 0) + kinc_g5_constant_buffer_set_int4(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value1, value2, value3, value4); + if (location.impl._location.impl.fragmentOffset >= 0) + kinc_g5_constant_buffer_set_int4(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value1, value2, value3, value4); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_int4(&computeConstantBuffer, location.impl._location.impl.computeOffset, value1, value2, value3, value4); +} -void kinc_g4_set_ints(kinc_g4_constant_location_t location, int *values, int count) {} +void kinc_g4_set_ints(kinc_g4_constant_location_t location, int *values, int count) { + if (location.impl._location.impl.vertexOffset >= 0) + kinc_g5_constant_buffer_set_ints(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, values, count); + if (location.impl._location.impl.fragmentOffset >= 0) + kinc_g5_constant_buffer_set_ints(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, values, count); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_ints(&computeConstantBuffer, location.impl._location.impl.computeOffset, values, count); +} void kinc_g4_set_float(kinc_g4_constant_location_t location, float value) { if (location.impl._location.impl.vertexOffset >= 0) kinc_g5_constant_buffer_set_float(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value); if (location.impl._location.impl.fragmentOffset >= 0) kinc_g5_constant_buffer_set_float(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_float(&computeConstantBuffer, location.impl._location.impl.computeOffset, value); } void kinc_g4_set_float2(kinc_g4_constant_location_t location, float value1, float value2) { @@ -427,6 +495,8 @@ void kinc_g4_set_float2(kinc_g4_constant_location_t location, float value1, floa kinc_g5_constant_buffer_set_float2(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value1, value2); if (location.impl._location.impl.fragmentOffset >= 0) kinc_g5_constant_buffer_set_float2(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value1, value2); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_float2(&computeConstantBuffer, location.impl._location.impl.computeOffset, value1, value2); } void kinc_g4_set_float3(kinc_g4_constant_location_t location, float value1, float value2, float value3) { @@ -434,6 +504,8 @@ void kinc_g4_set_float3(kinc_g4_constant_location_t location, float value1, floa kinc_g5_constant_buffer_set_float3(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value1, value2, value3); if (location.impl._location.impl.fragmentOffset >= 0) kinc_g5_constant_buffer_set_float3(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value1, value2, value3); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_float3(&computeConstantBuffer, location.impl._location.impl.computeOffset, value1, value2, value3); } void kinc_g4_set_float4(kinc_g4_constant_location_t location, float value1, float value2, float value3, float value4) { @@ -441,6 +513,8 @@ void kinc_g4_set_float4(kinc_g4_constant_location_t location, float value1, floa kinc_g5_constant_buffer_set_float4(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value1, value2, value3, value4); if (location.impl._location.impl.fragmentOffset >= 0) kinc_g5_constant_buffer_set_float4(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value1, value2, value3, value4); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_float4(&computeConstantBuffer, location.impl._location.impl.computeOffset, value1, value2, value3, value4); } void kinc_g4_set_floats(kinc_g4_constant_location_t location, float *values, int count) { @@ -448,6 +522,8 @@ void kinc_g4_set_floats(kinc_g4_constant_location_t location, float *values, int kinc_g5_constant_buffer_set_floats(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, values, count); if (location.impl._location.impl.fragmentOffset >= 0) kinc_g5_constant_buffer_set_floats(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, values, count); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_floats(&computeConstantBuffer, location.impl._location.impl.computeOffset, values, count); } void kinc_g4_set_bool(kinc_g4_constant_location_t location, bool value) { @@ -455,6 +531,8 @@ void kinc_g4_set_bool(kinc_g4_constant_location_t location, bool value) { kinc_g5_constant_buffer_set_bool(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value); if (location.impl._location.impl.fragmentOffset >= 0) kinc_g5_constant_buffer_set_bool(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_bool(&computeConstantBuffer, location.impl._location.impl.computeOffset, value); } void kinc_g4_set_matrix4(kinc_g4_constant_location_t location, kinc_matrix4x4_t *value) { @@ -462,6 +540,8 @@ void kinc_g4_set_matrix4(kinc_g4_constant_location_t location, kinc_matrix4x4_t kinc_g5_constant_buffer_set_matrix4(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value); if (location.impl._location.impl.fragmentOffset >= 0) kinc_g5_constant_buffer_set_matrix4(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_matrix4(&computeConstantBuffer, location.impl._location.impl.computeOffset, value); } void kinc_g4_set_matrix3(kinc_g4_constant_location_t location, kinc_matrix3x3_t *value) { @@ -469,6 +549,8 @@ void kinc_g4_set_matrix3(kinc_g4_constant_location_t location, kinc_matrix3x3_t kinc_g5_constant_buffer_set_matrix3(&vertexConstantBuffer, location.impl._location.impl.vertexOffset, value); if (location.impl._location.impl.fragmentOffset >= 0) kinc_g5_constant_buffer_set_matrix3(&fragmentConstantBuffer, location.impl._location.impl.fragmentOffset, value); + if (location.impl._location.impl.computeOffset >= 0) + kinc_g5_constant_buffer_set_matrix3(&computeConstantBuffer, location.impl._location.impl.computeOffset, value); } void kinc_g4_set_texture_addressing(kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) { @@ -622,38 +704,6 @@ void kinc_g4_set_index_buffer(kinc_g4_index_buffer_t *buffer) { kinc_g5_command_list_set_index_buffer(&commandList, g5_index_buffer); } -#ifdef KINC_KONG -void kinc_g4_set_texture(uint32_t unit, kinc_g4_texture_t *texture) { - if (!texture->impl._uploaded) { - kinc_g5_command_list_upload_texture(&commandList, &texture->impl._texture); - texture->impl._uploaded = true; - } - - assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT); - kinc_g5_texture_unit_t g5_unit = {0}; - for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) { - g5_unit.stages[i] = unit; - } - - bool found = false; - for (int i = 0; i < current_state.texture_count; ++i) { - if (kinc_g5_texture_unit_equals(¤t_state.texture_units[i], &g5_unit)) { - current_state.textures[i] = &texture->impl._texture; - current_state.texture_units[i] = g5_unit; - found = true; - break; - } - } - if (!found) { - assert(current_state.texture_count < MAX_TEXTURES); - current_state.textures[current_state.texture_count] = &texture->impl._texture; - current_state.texture_units[current_state.texture_count] = g5_unit; - current_state.texture_count += 1; - } - - kinc_g5_command_list_set_texture(&commandList, g5_unit, &texture->impl._texture); -} -#else void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) { if (!texture->impl._uploaded) { kinc_g5_command_list_upload_texture(&commandList, &texture->impl._texture); @@ -682,9 +732,30 @@ void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture kinc_g5_command_list_set_texture(&commandList, g5_unit, &texture->impl._texture); } -#endif -void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) {} +void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) { + assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT); + kinc_g5_texture_unit_t g5_unit; + memcpy(&g5_unit.stages[0], &unit.stages[0], KINC_G5_SHADER_TYPE_COUNT * sizeof(int)); + + bool found = false; + for (int i = 0; i < current_state.texture_count; ++i) { + if (kinc_g5_texture_unit_equals(¤t_state.texture_units[i], &g5_unit)) { + current_state.textures[i] = &texture->impl._texture; + current_state.texture_units[i] = g5_unit; + found = true; + break; + } + } + if (!found) { + assert(current_state.texture_count < MAX_TEXTURES); + current_state.textures[current_state.texture_count] = &texture->impl._texture; + current_state.texture_units[current_state.texture_count] = g5_unit; + current_state.texture_count += 1; + } + + kinc_g5_command_list_set_image_texture(&commandList, g5_unit, &texture->impl._texture); +} int kinc_g4_max_bound_textures(void) { return kinc_g5_max_bound_textures(); @@ -743,38 +814,6 @@ bool kinc_g4_render_targets_inverted_y(void) { return kinc_g5_render_targets_inverted_y(); } -#ifdef KINC_KONG -void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *render_target, uint32_t unit) { - if (render_target->impl.state != KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE) { - kinc_g5_command_list_render_target_to_texture_barrier(&commandList, &render_target->impl._renderTarget); - render_target->impl.state = KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE; - } - - assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT); - kinc_g5_texture_unit_t g5_unit = {0}; - for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) { - g5_unit.stages[i] = unit; - } - - bool found = false; - for (int i = 0; i < current_state.render_target_count; ++i) { - if (kinc_g5_texture_unit_equals(¤t_state.render_target_units[i], &g5_unit)) { - current_state.render_targets[i] = &render_target->impl._renderTarget; - current_state.render_target_units[i] = g5_unit; - found = true; - break; - } - } - if (!found) { - assert(current_state.render_target_count < MAX_TEXTURES); - current_state.render_targets[current_state.render_target_count] = &render_target->impl._renderTarget; - current_state.render_target_units[current_state.render_target_count] = g5_unit; - current_state.render_target_count += 1; - } - - kinc_g5_command_list_set_texture_from_render_target(&commandList, g5_unit, &render_target->impl._renderTarget); -} -#else void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *render_target, kinc_g4_texture_unit_t unit) { if (render_target->impl.state != KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE) { kinc_g5_command_list_render_target_to_texture_barrier(&commandList, &render_target->impl._renderTarget); @@ -803,7 +842,6 @@ void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *render_ kinc_g5_command_list_set_texture_from_render_target(&commandList, g5_unit, &render_target->impl._renderTarget); } -#endif void kinc_g4_render_target_use_depth_as_texture(kinc_g4_render_target_t *render_target, kinc_g4_texture_unit_t unit) { if (render_target->impl.state != KINC_INTERNAL_RENDER_TARGET_STATE_TEXTURE) { @@ -834,8 +872,14 @@ void kinc_g4_render_target_use_depth_as_texture(kinc_g4_render_target_t *render_ kinc_g5_command_list_set_texture_from_render_target_depth(&commandList, g5_unit, &render_target->impl._renderTarget); } -#ifdef KINC_KONG -void kinc_g4_set_constant_buffer(uint32_t id, struct kinc_g4_constant_buffer *buffer) { - kinc_g5_command_list_set_vertex_constant_buffer(&commandList, &buffer->impl.buffer, 0, kinc_g5_constant_buffer_size(&buffer->impl.buffer)); +void kinc_g4_set_compute_shader(kinc_g4_compute_shader *shader) { + kinc_g5_compute_shader *g5_shader = &shader->impl.shader; + current_state.compute_shader = g5_shader; + kinc_g5_command_list_set_compute_shader(&commandList, g5_shader); +} + +void kinc_g4_compute(int x, int y, int z) { + startDraw(true); + kinc_g5_command_list_compute(&commandList, x, y, z); + endDraw(true); } -#endif diff --git a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/compute.c.h b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/compute.c.h new file mode 100644 index 0000000..db2b94f --- /dev/null +++ b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/compute.c.h @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +extern kinc_g5_command_list_t commandList; + +void kinc_g4_compute_shader_init(kinc_g4_compute_shader *shader, void *source, int length) { + kinc_g5_compute_shader_init(&shader->impl.shader, source, length); +} + +void kinc_g4_compute_shader_destroy(kinc_g4_compute_shader *shader) { + kinc_g5_compute_shader_destroy(&shader->impl.shader); +} + +kinc_g4_constant_location_t kinc_g4_compute_shader_get_constant_location(kinc_g4_compute_shader *shader, const char *name) { + kinc_g4_constant_location_t location; + location.impl._location = kinc_g5_compute_shader_get_constant_location(&shader->impl.shader, name); + return location; +} + +kinc_g4_texture_unit_t kinc_g4_compute_shader_get_texture_unit(kinc_g4_compute_shader *shader, const char *name) { + kinc_g5_texture_unit_t g5_unit = kinc_g5_compute_shader_get_texture_unit(&shader->impl.shader, name); + kinc_g4_texture_unit_t g4_unit = {0}; + for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) { + g4_unit.stages[i] = g5_unit.stages[i]; + } + return g4_unit; +} diff --git a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/compute.h b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/compute.h new file mode 100644 index 0000000..3911d0e --- /dev/null +++ b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/compute.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +typedef struct kinc_g4_compute_shader_impl { + kinc_g5_compute_shader shader; +} kinc_g4_compute_shader_impl; diff --git a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.c.h b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.c.h deleted file mode 100644 index ff6d9d0..0000000 --- a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.c.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifdef KINC_KONG - -#include - -void kinc_g4_constant_buffer_init(kinc_g4_constant_buffer *buffer, size_t size) { - kinc_g5_constant_buffer_init(&buffer->impl.buffer, (int)size); -} - -void kinc_g4_constant_buffer_destroy(kinc_g4_constant_buffer *buffer) { - kinc_g5_constant_buffer_destroy(&buffer->impl.buffer); -} - -uint8_t *kinc_g4_constant_buffer_lock_all(kinc_g4_constant_buffer *buffer) { - kinc_g5_constant_buffer_lock_all(&buffer->impl.buffer); - return buffer->impl.buffer.data; -} - -uint8_t *kinc_g4_constant_buffer_lock(kinc_g4_constant_buffer *buffer, size_t start, size_t size) { - kinc_g5_constant_buffer_lock(&buffer->impl.buffer, (int)start, (int)size); - return buffer->impl.buffer.data; -} - -void kinc_g4_constant_buffer_unlock_all(kinc_g4_constant_buffer *buffer) { - kinc_g5_constant_buffer_unlock(&buffer->impl.buffer); -} - -void kinc_g4_constant_buffer_unlock(kinc_g4_constant_buffer *buffer, size_t count) { - kinc_g5_constant_buffer_unlock(&buffer->impl.buffer); -} - -size_t kinc_g4_constant_buffer_size(kinc_g4_constant_buffer *buffer) { - return kinc_g5_constant_buffer_size(&buffer->impl.buffer); -} - -#endif diff --git a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.h b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.h deleted file mode 100644 index f42b620..0000000 --- a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/constantbuffer.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#ifdef KINC_KONG - -#include - -typedef struct kinc_g4_constant_buffer_impl { - kinc_g5_constant_buffer_t buffer; -} kinc_g4_constant_buffer_impl; - -#endif diff --git a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/g4ong5unit.c b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/g4ong5unit.c index 76911e5..7e0660c 100644 --- a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/g4ong5unit.c +++ b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/g4ong5unit.c @@ -1,11 +1,11 @@ #include "samplers.c.h" #include "G4.c.h" -#include "constantbuffer.c.h" +#include "compute.c.h" #include "indexbuffer.c.h" #include "pipeline.c.h" #include "rendertarget.c.h" #include "shader.c.h" #include "texture.c.h" #include "texturearray.c.h" -#include "vertexbuffer.c.h" +#include "vertexbuffer.c.h" \ No newline at end of file diff --git a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/pipeline.c.h b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/pipeline.c.h index 5aac59c..d73a650 100644 --- a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/pipeline.c.h +++ b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/pipeline.c.h @@ -13,7 +13,6 @@ void kinc_g4_pipeline_destroy(kinc_g4_pipeline_t *pipe) { kinc_g5_pipeline_destroy(&pipe->impl._pipeline); } -#ifndef KINC_KONG kinc_g4_constant_location_t kinc_g4_pipeline_get_constant_location(kinc_g4_pipeline_t *pipe, const char *name) { kinc_g4_constant_location_t location; location.impl._location = kinc_g5_pipeline_get_constant_location(&pipe->impl._pipeline, name); @@ -29,7 +28,6 @@ kinc_g4_texture_unit_t kinc_g4_pipeline_get_texture_unit(kinc_g4_pipeline_t *pip return g4_unit; } -#endif void kinc_g4_pipeline_compile(kinc_g4_pipeline_t *pipe) { for (int i = 0; i < 16; ++i) { diff --git a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/shader.c.h b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/shader.c.h index 9ef1c6d..20d8969 100644 --- a/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/shader.c.h +++ b/Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/shader.c.h @@ -25,9 +25,9 @@ int kinc_g4_shader_init_from_source(kinc_g4_shader_t *shader, const char *source const char *system = "ios"; #endif -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN const char *target = "spirv"; -#elif defined(KORE_METAL) +#elif defined(KINC_METAL) const char *target = "metal"; #else const char *target = "d3d11"; diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/GL/glew.c b/Kinc/Backends/Graphics4/OpenGL/Sources/GL/glew.c index 4694c7d..04ee79d 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/GL/glew.c +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/GL/glew.c @@ -31,7 +31,7 @@ */ #include -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #if defined(GLEW_OSMESA) diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/compute.c b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/compute.c deleted file mode 100644 index fdc9a01..0000000 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/compute.c +++ /dev/null @@ -1,451 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#if defined(KORE_WINDOWS) || (defined(KORE_LINUX) && defined(GL_VERSION_4_3)) || (defined(KORE_ANDROID) && defined(GL_ES_VERSION_3_1)) -#define HAS_COMPUTE -bool kinc_internal_gl_has_compute = true; -#else -bool kinc_internal_gl_has_compute = false; -#endif - -#ifdef HAS_COMPUTE -static int convertInternalImageFormat(kinc_image_format_t format) { - switch (format) { - case KINC_IMAGE_FORMAT_RGBA128: - return GL_RGBA32F; - case KINC_IMAGE_FORMAT_RGBA64: - return GL_RGBA16F; - case KINC_IMAGE_FORMAT_RGBA32: - default: - return GL_RGBA8; - case KINC_IMAGE_FORMAT_A32: - return GL_R32F; - case KINC_IMAGE_FORMAT_A16: - return GL_R16F; - case KINC_IMAGE_FORMAT_GREY8: - return GL_R8; - } -} - -static int convertInternalRTFormat(kinc_g4_render_target_format_t format) { - switch (format) { - case KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT: - return GL_RGBA16F; - case KINC_G4_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT: - return GL_R32F; - case KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT: - return GL_RGBA32F; - case KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH: - return GL_DEPTH_COMPONENT16; - case KINC_G4_RENDER_TARGET_FORMAT_8BIT_RED: - return GL_RED; - case KINC_G4_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT: - return GL_R16F; - case KINC_G4_RENDER_TARGET_FORMAT_32BIT: - default: - return GL_RGBA; - } -} - -static void setTextureAddressingInternal(GLenum target, kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, - kinc_g4_texture_addressing_t addressing) { - glActiveTexture(GL_TEXTURE0 + unit.impl.unit); - GLenum texDir = dir == KINC_G4_TEXTURE_DIRECTION_U ? GL_TEXTURE_WRAP_S : (KINC_G4_TEXTURE_DIRECTION_V ? GL_TEXTURE_WRAP_T : GL_TEXTURE_WRAP_R); - switch (addressing) { - case KINC_G4_TEXTURE_ADDRESSING_CLAMP: - glTexParameteri(target, texDir, GL_CLAMP_TO_EDGE); - break; - case KINC_G4_TEXTURE_ADDRESSING_REPEAT: - default: - glTexParameteri(target, texDir, GL_REPEAT); - break; - } - glCheckErrors(); -} - -static void setTextureMagnificationFilterInternal(GLenum target, kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) { - glActiveTexture(GL_TEXTURE0 + unit.impl.unit); - switch (filter) { - case KINC_G4_TEXTURE_FILTER_POINT: - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - break; - case KINC_G4_TEXTURE_FILTER_LINEAR: - case KINC_G4_TEXTURE_FILTER_ANISOTROPIC: - default: - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - break; - } - glCheckErrors(); -} - -static kinc_g4_texture_filter_t minFilters[32] = {KINC_G4_TEXTURE_FILTER_POINT}; -static kinc_g4_mipmap_filter_t mipFilters[32] = {KINC_G4_MIPMAP_FILTER_NONE}; - -static void setMinMipFilters(GLenum target, int unit) { - glActiveTexture(GL_TEXTURE0 + unit); - switch (minFilters[unit]) { - case KINC_G4_TEXTURE_FILTER_POINT: - switch (mipFilters[unit]) { - case KINC_G4_MIPMAP_FILTER_NONE: - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - break; - case KINC_G4_MIPMAP_FILTER_POINT: - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); - break; - case KINC_G4_MIPMAP_FILTER_LINEAR: - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); - break; - } - break; - case KINC_G4_TEXTURE_FILTER_LINEAR: - case KINC_G4_TEXTURE_FILTER_ANISOTROPIC: - switch (mipFilters[unit]) { - case KINC_G4_MIPMAP_FILTER_NONE: - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - break; - case KINC_G4_MIPMAP_FILTER_POINT: - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - break; - case KINC_G4_MIPMAP_FILTER_LINEAR: - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - break; - } - if (minFilters[unit] == KINC_G4_TEXTURE_FILTER_ANISOTROPIC) { - float maxAniso = 0.0f; - glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAniso); - glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAniso); - } - break; - } - glCheckErrors(); -} -#endif - -void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *source, int length) { - shader->impl._length = length; - shader->impl.textureCount = 0; - shader->impl._source = (char *)malloc(sizeof(char) * (length + 1)); - for (int i = 0; i < length; ++i) { - shader->impl._source[i] = ((char *)source)[i]; - } - shader->impl._source[length] = 0; - -#ifdef HAS_COMPUTE - shader->impl._id = glCreateShader(GL_COMPUTE_SHADER); - glCheckErrors(); - glShaderSource(shader->impl._id, 1, (const GLchar **)&shader->impl._source, NULL); - glCompileShader(shader->impl._id); - - int result; - glGetShaderiv(shader->impl._id, GL_COMPILE_STATUS, &result); - if (result != GL_TRUE) { - int length; - glGetShaderiv(shader->impl._id, GL_INFO_LOG_LENGTH, &length); - char *errormessage = (char *)malloc(sizeof(char) * length); - glGetShaderInfoLog(shader->impl._id, length, NULL, errormessage); - kinc_log(KINC_LOG_LEVEL_ERROR, "GLSL compiler error: %s\n", errormessage); - free(errormessage); - } - - shader->impl._programid = glCreateProgram(); - glAttachShader(shader->impl._programid, shader->impl._id); - glLinkProgram(shader->impl._programid); - - glGetProgramiv(shader->impl._programid, GL_LINK_STATUS, &result); - if (result != GL_TRUE) { - int length; - glGetProgramiv(shader->impl._programid, GL_INFO_LOG_LENGTH, &length); - char *errormessage = (char *)malloc(sizeof(char) * length); - glGetProgramInfoLog(shader->impl._programid, length, NULL, errormessage); - kinc_log(KINC_LOG_LEVEL_ERROR, "GLSL linker error: %s\n", errormessage); - free(errormessage); - } -#endif - - // TODO: Get rid of allocations - shader->impl.textures = (char **)malloc(sizeof(char *) * 16); - for (int i = 0; i < 16; ++i) { - shader->impl.textures[i] = (char *)malloc(sizeof(char) * 128); - shader->impl.textures[i][0] = 0; - } - shader->impl.textureValues = (int *)malloc(sizeof(int) * 16); -} - -void kinc_compute_shader_destroy(kinc_compute_shader_t *shader) { - free(shader->impl._source); - shader->impl._source = NULL; -#ifdef HAS_COMPUTE - glDeleteProgram(shader->impl._programid); - glDeleteShader(shader->impl._id); -#endif -} -kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_constant_location_t location; -#ifdef HAS_COMPUTE - location.impl.location = glGetUniformLocation(shader->impl._programid, name); - location.impl.type = GL_FLOAT; - GLint count = 0; - glGetProgramiv(shader->impl._programid, GL_ACTIVE_UNIFORMS, &count); - char arrayName[1024]; - strcpy(arrayName, name); - strcat(arrayName, "[0]"); - for (GLint i = 0; i < count; ++i) { - GLenum type; - char uniformName[1024]; - GLsizei length; - GLint size; - glGetActiveUniform(shader->impl._programid, i, 1024 - 1, &length, &size, &type, uniformName); - if (strcmp(uniformName, name) == 0 || strcmp(uniformName, arrayName) == 0) { - location.impl.type = type; - break; - } - } - glCheckErrors(); - if (location.impl.location < 0) { - kinc_log(KINC_LOG_LEVEL_WARNING, "Uniform %s not found.", name); - } -#endif - return location; -} - -static int findTexture(kinc_compute_shader_t *shader, const char *name) { - for (int index = 0; index < shader->impl.textureCount; ++index) { - if (strcmp(shader->impl.textures[index], name) == 0) return index; - } - return -1; -} - -kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name) { - int index = findTexture(shader, name); - if (index < 0) { - int location = glGetUniformLocation(shader->impl._programid, name); - glCheckErrors(); - index = shader->impl.textureCount; - shader->impl.textureValues[index] = location; - strcpy(shader->impl.textures[index], name); - ++shader->impl.textureCount; - } - kinc_compute_texture_unit_t unit; - unit.impl.unit = index; - return unit; -} - -void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value) { -#ifdef HAS_COMPUTE - glUniform1i(location.impl.location, value ? 1 : 0); - glCheckErrors(); -#endif -} - -void kinc_compute_set_int(kinc_compute_constant_location_t location, int value) { -#ifdef HAS_COMPUTE - glUniform1i(location.impl.location, value); - glCheckErrors(); -#endif -} - -void kinc_compute_set_float(kinc_compute_constant_location_t location, float value) { -#ifdef HAS_COMPUTE - glUniform1f(location.impl.location, value); - glCheckErrors(); -#endif -} - -void kinc_compute_set_float2(kinc_compute_constant_location_t location, float value1, float value2) { -#ifdef HAS_COMPUTE - glUniform2f(location.impl.location, value1, value2); - glCheckErrors(); -#endif -} - -void kinc_compute_set_float3(kinc_compute_constant_location_t location, float value1, float value2, float value3) { -#ifdef HAS_COMPUTE - glUniform3f(location.impl.location, value1, value2, value3); - glCheckErrors(); -#endif -} - -void kinc_compute_set_float4(kinc_compute_constant_location_t location, float value1, float value2, float value3, float value4) { -#ifdef HAS_COMPUTE - glUniform4f(location.impl.location, value1, value2, value3, value4); - glCheckErrors(); -#endif -} - -void kinc_compute_set_floats(kinc_compute_constant_location_t location, float *values, int count) { -#ifdef HAS_COMPUTE - switch (location.impl.type) { - case GL_FLOAT_VEC2: - glUniform2fv(location.impl.location, count / 2, values); - break; - case GL_FLOAT_VEC3: - glUniform3fv(location.impl.location, count / 3, values); - break; - case GL_FLOAT_VEC4: - glUniform4fv(location.impl.location, count / 4, values); - break; - case GL_FLOAT_MAT4: - glUniformMatrix4fv(location.impl.location, count / 16, false, values); - break; - default: - glUniform1fv(location.impl.location, count, values); - break; - } - glCheckErrors(); -#endif -} - -void kinc_compute_set_matrix4(kinc_compute_constant_location_t location, kinc_matrix4x4_t *value) { -#ifdef HAS_COMPUTE - glUniformMatrix4fv(location.impl.location, 1, GL_FALSE, &value->m[0]); - glCheckErrors(); -#endif -} - -void kinc_compute_set_matrix3(kinc_compute_constant_location_t location, kinc_matrix3x3_t *value) { -#ifdef HAS_COMPUTE - glUniformMatrix3fv(location.impl.location, 1, GL_FALSE, &value->m[0]); - glCheckErrors(); -#endif -} - -void kinc_compute_set_buffer(kinc_shader_storage_buffer_t *buffer, int index) { -#ifdef HAS_COMPUTE - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, index, buffer->impl.bufferId); - glCheckErrors(); -#endif -} - -void kinc_compute_set_texture(kinc_compute_texture_unit_t unit, kinc_g4_texture_t *texture, kinc_compute_access_t access) { -#ifdef HAS_COMPUTE - glActiveTexture(GL_TEXTURE0 + unit.impl.unit); - glCheckErrors(); - GLenum glaccess = access == KINC_COMPUTE_ACCESS_READ ? GL_READ_ONLY : (access == KINC_COMPUTE_ACCESS_WRITE ? GL_WRITE_ONLY : GL_READ_WRITE); - glBindImageTexture(unit.impl.unit, texture->impl.texture, 0, GL_FALSE, 0, glaccess, convertInternalImageFormat(texture->format)); - glCheckErrors(); -#endif -} - -void kinc_compute_set_render_target(kinc_compute_texture_unit_t unit, kinc_g4_render_target_t *texture, kinc_compute_access_t access) { -#ifdef HAS_COMPUTE - glActiveTexture(GL_TEXTURE0 + unit.impl.unit); - glCheckErrors(); - GLenum glaccess = access == KINC_COMPUTE_ACCESS_READ ? GL_READ_ONLY : (access == KINC_COMPUTE_ACCESS_WRITE ? GL_WRITE_ONLY : GL_READ_WRITE); - glBindImageTexture(unit.impl.unit, texture->impl._texture, 0, GL_FALSE, 0, glaccess, - convertInternalRTFormat((kinc_g4_render_target_format_t)texture->impl.format)); - glCheckErrors(); -#endif -} - -void kinc_compute_set_sampled_texture(kinc_compute_texture_unit_t unit, kinc_g4_texture_t *texture) { -#ifdef HAS_COMPUTE - glActiveTexture(GL_TEXTURE0 + unit.impl.unit); - glCheckErrors(); - GLenum gltarget = texture->tex_depth > 1 ? GL_TEXTURE_3D : GL_TEXTURE_2D; - glBindTexture(gltarget, texture->impl.texture); - glCheckErrors(); -#endif -} - -void kinc_compute_set_sampled_render_target(kinc_compute_texture_unit_t unit, kinc_g4_render_target_t *target) { -#ifdef HAS_COMPUTE - glActiveTexture(GL_TEXTURE0 + unit.impl.unit); - glCheckErrors(); - glBindTexture(target->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, target->impl._texture); - glCheckErrors(); -#endif -} - -void kinc_compute_set_sampled_depth_from_render_target(kinc_compute_texture_unit_t unit, kinc_g4_render_target_t *target) { -#ifdef HAS_COMPUTE - glActiveTexture(GL_TEXTURE0 + unit.impl.unit); - glCheckErrors(); - glBindTexture(target->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, target->impl._depthTexture); - glCheckErrors(); -#endif -} - -void kinc_compute_set_texture_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) { -#ifdef HAS_COMPUTE - setTextureAddressingInternal(GL_TEXTURE_2D, unit, dir, addressing); -#endif -} - -void kinc_compute_set_texture3d_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) { -#ifdef HAS_COMPUTE - setTextureAddressingInternal(GL_TEXTURE_3D, unit, dir, addressing); -#endif -} - -void kinc_compute_set_texture_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) { -#ifdef HAS_COMPUTE - setTextureMagnificationFilterInternal(GL_TEXTURE_2D, unit, filter); -#endif -} - -void kinc_compute_set_texture3d_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) { -#ifdef HAS_COMPUTE - setTextureMagnificationFilterInternal(GL_TEXTURE_3D, unit, filter); -#endif -} - -void kinc_compute_set_texture_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) { -#ifdef HAS_COMPUTE - minFilters[unit.impl.unit] = filter; - setMinMipFilters(GL_TEXTURE_2D, unit.impl.unit); -#endif -} - -void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) { -#ifdef HAS_COMPUTE - minFilters[unit.impl.unit] = filter; - setMinMipFilters(GL_TEXTURE_3D, unit.impl.unit); -#endif -} - -void kinc_compute_set_texture_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) { -#ifdef HAS_COMPUTE - mipFilters[unit.impl.unit] = filter; - setMinMipFilters(GL_TEXTURE_2D, unit.impl.unit); -#endif -} - -void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) { -#ifdef HAS_COMPUTE - mipFilters[unit.impl.unit] = filter; - setMinMipFilters(GL_TEXTURE_3D, unit.impl.unit); -#endif -} - -void kinc_compute_set_shader(kinc_compute_shader_t *shader) { -#ifdef HAS_COMPUTE - glUseProgram(shader->impl._programid); - glCheckErrors(); - - for (int index = 0; index < shader->impl.textureCount; ++index) { - glUniform1i(shader->impl.textureValues[index], index); - glCheckErrors(); - } -#endif -} - -void kinc_compute(int x, int y, int z) { -#ifdef HAS_COMPUTE - glDispatchCompute(x, y, z); - glCheckErrors(); - glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); - glCheckErrors(); - glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); - glCheckErrors(); -#endif -} diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/compute.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/compute.h deleted file mode 100644 index 6ccdf2e..0000000 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/compute.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -typedef struct { - int location; - unsigned int type; -} kinc_compute_constant_location_impl_t; - -typedef struct { - int unit; -} kinc_compute_texture_unit_impl_t; - -typedef struct { - // int findTexture(const char* name); - char **textures; - int *textureValues; - int textureCount; - unsigned _id; - unsigned _programid; - char *_source; - int _length; -} kinc_compute_shader_impl_t; diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.c.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.c.h index 0e7392a..1f484ad 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.c.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.c.h @@ -7,7 +7,6 @@ #include -#include #include #include #include @@ -23,7 +22,7 @@ #include "OpenGLWindow.h" -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #endif @@ -31,11 +30,11 @@ #include #include -#ifdef KORE_IOS +#ifdef KINC_IOS #include #endif -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #define WIN32_LEAN_AND_MEAN @@ -65,13 +64,13 @@ #define GL_COMPARE_REF_TO_TEXTURE 0x884E #endif -#if !defined(KORE_IOS) && !defined(KORE_ANDROID) +#if !defined(KINC_IOS) && !defined(KINC_ANDROID) bool Kinc_Internal_ProgramUsesTessellation; #endif bool Kinc_Internal_SupportsConservativeRaster = false; bool Kinc_Internal_SupportsDepthTexture = true; -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 void *glesVertexAttribDivisor; GL_APICALL void (*GL_APIENTRY glesGenQueries)(GLsizei n, GLuint *ids); @@ -81,13 +80,17 @@ GL_APICALL void (*GL_APIENTRY glesEndQuery)(GLenum target); GL_APICALL void (*GL_APIENTRY glesGetQueryObjectuiv)(GLuint id, GLenum pname, GLuint *params); #endif -#if defined(KORE_WINDOWS) && !defined(NDEBUG) +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) +GL_APICALL void (*GL_APIENTRY glesDrawElementsBaseVertex)(GLenum mode, GLsizei count, GLenum type, void *indices, GLint basevertex) = NULL; +#endif + +#if defined(KINC_WINDOWS) && !defined(NDEBUG) static void __stdcall debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { kinc_log(KINC_LOG_LEVEL_INFO, "OpenGL: %s", message); } #endif -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS static HINSTANCE instance = 0; #endif @@ -104,7 +107,7 @@ static int maxColorAttachments; static kinc_g4_pipeline_t *lastPipeline = NULL; -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 static void *glesDrawBuffers; static void *glesDrawElementsInstanced; #endif @@ -113,16 +116,19 @@ static int texModesU[256]; static int texModesV[256]; void kinc_internal_resize(int window, int width, int height) { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS Kinc_Internal_resizeWindowRenderTarget(window, width, height); #endif glViewport(0, 0, width, height); } +#ifdef __cplusplus +extern "C" { +#endif void kinc_internal_change_framebuffer(int window, kinc_framebuffer_options_t *frame) { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS if (window == 0) { -#ifdef KORE_VR +#ifdef KINC_VR frame->vertical_sync = false; #endif if (wglSwapIntervalEXT != NULL) @@ -130,6 +136,9 @@ void kinc_internal_change_framebuffer(int window, kinc_framebuffer_options_t *fr } #endif } +#ifdef __cplusplus +} +#endif #ifdef KINC_EGL static EGLDisplay egl_display = EGL_NO_DISPLAY; @@ -184,7 +193,7 @@ void kinc_g4_internal_destroy_window(int window) { #ifdef KINC_EGL kinc_egl_destroy_window(window); #endif -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS if (Kinc_Internal_windows[window].glContext) { assert(wglMakeCurrent(NULL, NULL)); assert(wglDeleteContext(Kinc_Internal_windows[window].glContext)); @@ -206,7 +215,7 @@ void kinc_g4_internal_destroy_window(int window) { void kinc_g4_internal_init() { #ifdef KINC_EGL -#if !defined(KORE_OPENGL_ES) +#if !defined(KINC_OPENGL_ES) eglBindAPI(EGL_OPENGL_API); #else eglBindAPI(EGL_OPENGL_ES_API); @@ -235,21 +244,21 @@ EGLNativeWindowType kinc_egl_get_native_window(EGLDisplay, EGLConfig, int); extern bool kinc_internal_opengl_force_16bit_index_buffer; -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES int gles_version = 2; #endif void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencilBufferBits, bool vsync) { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS Kinc_Internal_initWindowsGLContext(windowId, depthBufferBits, stencilBufferBits); #endif #ifdef KINC_EGL kinc_egl_init_window(windowId); #endif -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS if (windowId == 0) { -#ifdef KORE_VR +#ifdef KINC_VR vsync = false; #endif if (wglSwapIntervalEXT != NULL) @@ -259,7 +268,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil renderToBackbuffer = true; -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 glesDrawBuffers = (void *)eglGetProcAddress("glDrawBuffers"); glesDrawElementsInstanced = (void *)eglGetProcAddress("glDrawElementsInstanced"); glesVertexAttribDivisor = (void *)eglGetProcAddress("glVertexAttribDivisor"); @@ -271,12 +280,16 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil glesGetQueryObjectuiv = (void *)eglGetProcAddress("glGetQueryObjectuiv"); #endif -#if defined(KORE_WINDOWS) && !defined(NDEBUG) +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) + glesDrawElementsBaseVertex = (void *)eglGetProcAddress("glDrawElementsBaseVertex"); +#endif + +#if defined(KINC_WINDOWS) && !defined(NDEBUG) glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback(debugCallback, NULL); #endif -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES int extensions = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &extensions); if (glGetError() != GL_NO_ERROR) { @@ -290,7 +303,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil maxColorAttachments = 8; #endif -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES { int major = -1; glGetIntegerv(GL_MAJOR_VERSION, &major); @@ -310,7 +323,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil lastPipeline = NULL; -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES int major = -1, minor = -1; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor); @@ -327,7 +340,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil int gl_version = major * 100 + minor * 10; #endif -#if defined(KORE_LINUX) || defined(KORE_MACOS) +#if defined(KINC_LINUX) || defined(KINC_MACOS) if (gl_version >= 300) { unsigned vertexArray; glGenVertexArrays(1, &vertexArray); @@ -339,7 +352,7 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil } bool kinc_window_vsynced(int window) { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS return wglGetSwapIntervalEXT(); #else return true; @@ -451,7 +464,7 @@ void kinc_g4_draw_indexed_vertices_from_to(int start, int count) { GLenum type = sixteen ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT; void *_start = sixteen ? (void *)(start * sizeof(uint16_t)) : (void *)(start * sizeof(uint32_t)); -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES if (Kinc_Internal_ProgramUsesTessellation) { glDrawElements(GL_PATCHES, count, type, _start); glCheckErrors(); @@ -460,7 +473,7 @@ void kinc_g4_draw_indexed_vertices_from_to(int start, int count) { #endif glDrawElements(GL_TRIANGLES, count, type, _start); glCheckErrors(); -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES } #endif } @@ -469,8 +482,20 @@ void kinc_g4_draw_indexed_vertices_from_to_from(int start, int count, int vertex bool sixteen = Kinc_Internal_CurrentIndexBuffer->impl.format == KINC_G4_INDEX_BUFFER_FORMAT_16BIT || kinc_internal_opengl_force_16bit_index_buffer; GLenum type = sixteen ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT; void *_start = sixteen ? (void *)(start * sizeof(uint16_t)) : (void *)(start * sizeof(uint32_t)); -#ifdef KORE_OPENGL_ES - glDrawElements(GL_TRIANGLES, count, type, _start); +#ifdef KINC_OPENGL_ES +#ifdef KINC_ANDROID + if (glesDrawElementsBaseVertex != NULL) { + glesDrawElementsBaseVertex(GL_TRIANGLES, count, type, _start, vertex_offset); + } + else { +#endif + if (vertex_offset != 0) { + kinc_log(KINC_LOG_LEVEL_WARNING, "BaseVertex used but not supported"); + } + glDrawElements(GL_TRIANGLES, count, type, _start); +#ifdef KINC_ANDROID + } +#endif glCheckErrors(); #else if (Kinc_Internal_ProgramUsesTessellation) { @@ -492,12 +517,12 @@ void kinc_g4_draw_indexed_vertices_instanced_from_to(int instanceCount, int star bool sixteen = Kinc_Internal_CurrentIndexBuffer->impl.format == KINC_G4_INDEX_BUFFER_FORMAT_16BIT || kinc_internal_opengl_force_16bit_index_buffer; GLenum type = sixteen ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT; void *_start = sixteen ? (void *)(start * sizeof(uint16_t)) : (void *)(start * sizeof(uint32_t)); -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 ((void (*)(GLenum, GLsizei, GLenum, void *, GLsizei))glesDrawElementsInstanced)(GL_TRIANGLES, count, type, _start, instanceCount); -#elif defined(KORE_OPENGL_ES) && defined(KORE_WASM) +#elif defined(KINC_OPENGL_ES) && defined(KINC_WASM) glDrawElementsInstanced(GL_TRIANGLES, count, type, _start, instanceCount); glCheckErrors(); -#elif !defined(KORE_OPENGL_ES) +#elif !defined(KINC_OPENGL_ES) if (Kinc_Internal_ProgramUsesTessellation) { glDrawElementsInstanced(GL_PATCHES, count, type, _start, instanceCount); glCheckErrors(); @@ -509,11 +534,11 @@ void kinc_g4_draw_indexed_vertices_instanced_from_to(int instanceCount, int star #endif } -#ifdef KORE_MACOS +#ifdef KINC_MACOS void swapBuffersMac(int window); #endif -#ifdef KORE_IOS +#ifdef KINC_IOS void swapBuffersiOS(); #endif @@ -529,7 +554,7 @@ void kinc_egl_init() { // clang-format off const EGLint attribs[] = { - #if !defined(KORE_OPENGL_ES) + #if !defined(KINC_OPENGL_ES) EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, #else EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, @@ -552,7 +577,7 @@ void kinc_egl_init() { if (!num_configs) { // clang-format off const EGLint attribs[] = { - #if !defined(KORE_OPENGL_ES) + #if !defined(KINC_OPENGL_ES) EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, #else EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, @@ -575,7 +600,7 @@ void kinc_egl_init() { kinc_log(KINC_LOG_LEVEL_ERROR, "Unable to choose EGL config"); } -#if !defined(KORE_OPENGL_ES) +#if !defined(KINC_OPENGL_ES) EGLint gl_versions[][2] = {{4, 6}, {4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2}, {3, 1}, {3, 0}, {2, 1}, {2, 0}}; bool gl_initialized = false; for (int i = 0; i < sizeof(gl_versions) / sizeof(EGLint) / 2; ++i) { @@ -649,7 +674,7 @@ void kinc_egl_destroy_window(int window) { #endif bool kinc_g4_swap_buffers() { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS for (int i = 9; i >= 0; --i) { if (Kinc_Internal_windows[i].deviceContext != NULL) { wglMakeCurrent(Kinc_Internal_windows[i].deviceContext, Kinc_Internal_windows[i].glContext); @@ -678,15 +703,15 @@ bool kinc_g4_swap_buffers() { EGL_CHECK_ERROR() } } -#elif defined(KORE_MACOS) +#elif defined(KINC_MACOS) swapBuffersMac(0); -#elif defined(KORE_IOS) +#elif defined(KINC_IOS) swapBuffersiOS(); #endif return true; } -#ifdef KORE_IOS +#ifdef KINC_IOS int kinc_ios_gl_framebuffer = -1; void beginGL(); @@ -699,12 +724,12 @@ void kinc_g4_begin(int window) { eglMakeCurrent(egl_display, kinc_egl_windows[window].surface, kinc_egl_windows[window].surface, egl_context); EGL_CHECK_ERROR() #endif -#ifdef KORE_IOS +#ifdef KINC_IOS beginGL(); #endif kinc_g4_restore_render_target(); glCheckErrors(); -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID // if rendered to a texture, strange things happen if the backbuffer is not cleared glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); @@ -720,12 +745,7 @@ static bool scissor_on = false; void kinc_g4_scissor(int x, int y, int width, int height) { scissor_on = true; glEnable(GL_SCISSOR_TEST); - if (renderToBackbuffer) { - glScissor(x, _renderTargetHeight - y - height, width, height); - } - else { - glScissor(x, y, width, height); - } + glScissor(x, _renderTargetHeight - y - height, width, height); } void kinc_g4_disable_scissor() { @@ -749,7 +769,7 @@ void kinc_g4_clear(unsigned flags, unsigned color, float depth, int stencil) { glDepthMask(GL_TRUE); glCheckErrors(); } -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glClearDepthf(depth); #else glClearDepth(depth); @@ -791,19 +811,11 @@ void kinc_g4_set_index_buffer(kinc_g4_index_buffer_t *indexBuffer) { void Kinc_G4_Internal_TextureImageSet(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit); -#ifdef KINC_KONG -void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, uint32_t unit); - -void kinc_g4_set_texture(uint32_t unit, kinc_g4_texture_t *texture) { - Kinc_G4_Internal_TextureSet(texture, unit); -} -#else void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit); void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) { Kinc_G4_Internal_TextureSet(texture, unit); } -#endif void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) { Kinc_G4_Internal_TextureImageSet(texture, unit); @@ -826,7 +838,7 @@ static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t u texDir = GL_TEXTURE_WRAP_T; break; case KINC_G4_TEXTURE_DIRECTION_W: -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES texDir = GL_TEXTURE_WRAP_R; #endif break; @@ -874,15 +886,6 @@ static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t u glCheckErrors(); } -#ifdef KINC_KONG -int Kinc_G4_Internal_TextureAddressingU(uint32_t unit) { - return texModesU[unit]; -} - -int Kinc_G4_Internal_TextureAddressingV(uint32_t unit) { - return texModesV[unit]; -} -#else int Kinc_G4_Internal_TextureAddressingU(kinc_g4_texture_unit_t unit) { return texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]]; } @@ -890,14 +893,13 @@ int Kinc_G4_Internal_TextureAddressingU(kinc_g4_texture_unit_t unit) { int Kinc_G4_Internal_TextureAddressingV(kinc_g4_texture_unit_t unit) { return texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]]; } -#endif void kinc_g4_set_texture_addressing(kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) { setTextureAddressingInternal(GL_TEXTURE_2D, unit, dir, addressing); } void kinc_g4_set_texture3d_addressing(kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) { -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES setTextureAddressingInternal(GL_TEXTURE_3D, unit, dir, addressing); #endif } @@ -922,7 +924,7 @@ void kinc_g4_set_texture_magnification_filter(kinc_g4_texture_unit_t texunit, ki } void kinc_g4_set_texture3d_magnification_filter(kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) { -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES setTextureMagnificationFilterInternal(GL_TEXTURE_3D, texunit, filter); #endif } @@ -974,7 +976,7 @@ void kinc_g4_set_texture_minification_filter(kinc_g4_texture_unit_t texunit, kin void kinc_g4_set_texture3d_minification_filter(kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) { minFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter; -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES setMinMipFilters(GL_TEXTURE_3D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]); #endif } @@ -986,7 +988,7 @@ void kinc_g4_set_texture_mipmap_filter(kinc_g4_texture_unit_t texunit, kinc_g4_m void kinc_g4_set_texture3d_mipmap_filter(kinc_g4_texture_unit_t texunit, kinc_g4_mipmap_filter_t filter) { mipFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter; -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES setMinMipFilters(GL_TEXTURE_3D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]); #endif } @@ -1052,7 +1054,7 @@ void kinc_g4_set_cubemap_lod(kinc_g4_texture_unit_t unit, float lod_min_clamp, f void kinc_g4_set_render_targets(kinc_g4_render_target_t **targets, int count) { glBindFramebuffer(GL_FRAMEBUFFER, targets[0]->impl._framebuffer); glCheckErrors(); -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES if (targets[0]->isCubeMap) glFramebufferTexture(GL_FRAMEBUFFER, targets[0]->isDepthAttachment ? GL_DEPTH_ATTACHMENT : GL_COLOR_ATTACHMENT0, targets[0]->impl._texture, 0); // Layered @@ -1072,9 +1074,9 @@ void kinc_g4_set_render_targets(kinc_g4_render_target_t **targets, int count) { GLenum buffers[16]; for (int i = 0; i < count; ++i) buffers[i] = GL_COLOR_ATTACHMENT0 + i; -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 ((void (*)(GLsizei, GLenum *))glesDrawBuffers)(count, buffers); -#elif !defined(KORE_OPENGL_ES) || defined(KORE_EMSCRIPTEN) || defined(KORE_WASM) +#elif !defined(KINC_OPENGL_ES) || defined(KINC_EMSCRIPTEN) || defined(KINC_WASM) glDrawBuffers(count, buffers); #endif glCheckErrors(); @@ -1099,7 +1101,7 @@ void kinc_g4_set_render_target_face(kinc_g4_render_target_t *texture, int face) } void kinc_g4_restore_render_target() { -#ifdef KORE_IOS +#ifdef KINC_IOS glBindFramebuffer(GL_FRAMEBUFFER, kinc_ios_gl_framebuffer); #else glBindFramebuffer(GL_FRAMEBUFFER, GL_NONE); @@ -1112,14 +1114,14 @@ void kinc_g4_restore_render_target() { _renderTargetHeight = h; renderToBackbuffer = true; glCheckErrors(); -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS Kinc_Internal_setWindowRenderTarget(currentWindow); #endif } -#if (defined(KORE_OPENGL) && !defined(KORE_PI) && !defined(KORE_ANDROID)) || (defined(KORE_ANDROID) && KORE_ANDROID_API >= 18) +#if (defined(KINC_OPENGL) && !defined(KINC_RASPBERRY_PI) && !defined(KINC_ANDROID)) || (defined(KINC_ANDROID) && KINC_ANDROID_API >= 18) bool kinc_g4_init_occlusion_query(unsigned *occlusionQuery) { -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 if (gles_version >= 3 && glesGenQueries) { glesGenQueries(1, occlusionQuery); } @@ -1130,7 +1132,7 @@ bool kinc_g4_init_occlusion_query(unsigned *occlusionQuery) { } void kinc_g4_delete_occlusion_query(unsigned occlusionQuery) { -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 if (gles_version >= 3 && glesGenQueries) { glesDeleteQueries(1, &occlusionQuery); } @@ -1139,14 +1141,14 @@ void kinc_g4_delete_occlusion_query(unsigned occlusionQuery) { #endif } -#if defined(KORE_OPENGL_ES) +#if defined(KINC_OPENGL_ES) #define SAMPLES_PASSED GL_ANY_SAMPLES_PASSED #else #define SAMPLES_PASSED GL_SAMPLES_PASSED #endif void kinc_g4_render_occlusion_query(unsigned occlusionQuery, int triangles) { -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 if (gles_version >= 3 && glesGenQueries) { glesBeginQuery(SAMPLES_PASSED, occlusionQuery); glDrawArrays(GL_TRIANGLES, 0, triangles); @@ -1163,7 +1165,7 @@ void kinc_g4_render_occlusion_query(unsigned occlusionQuery, int triangles) { bool kinc_g4_are_query_results_available(unsigned occlusionQuery) { unsigned available = 0; -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 if (gles_version >= 3 && glesGetQueryObjectuiv) { glesGetQueryObjectuiv(occlusionQuery, GL_QUERY_RESULT_AVAILABLE, &available); } @@ -1174,7 +1176,7 @@ bool kinc_g4_are_query_results_available(unsigned occlusionQuery) { } void kinc_g4_get_query_results(unsigned occlusionQuery, unsigned *pixelCount) { -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 if (gles_version >= 3 && glesGetQueryObjectuiv) { glesGetQueryObjectuiv(occlusionQuery, GL_QUERY_RESULT, pixelCount); } @@ -1235,8 +1237,8 @@ int Kinc_G4_Internal_StencilFunc(kinc_g4_compare_mode_t mode) { extern bool kinc_internal_gl_has_compute; bool kinc_g4_supports_instanced_rendering() { -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) -#if KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) +#if KINC_ANDROID_API >= 18 return glesDrawElementsInstanced != NULL; #else return false; @@ -1264,14 +1266,3 @@ bool kinc_g4_supports_non_pow2_textures() { bool kinc_g4_render_targets_inverted_y(void) { return true; } - -#ifdef KINC_KONG -void kinc_g4_set_constant_buffer(uint32_t id, struct kinc_g4_constant_buffer *buffer) { - glBindBufferBase(GL_UNIFORM_BUFFER, id, buffer->impl.buffer); -} - -void kinc_g4_internal_opengl_setup_uniform_block(unsigned program, const char *name, unsigned binding) { - unsigned index = glGetUniformBlockIndex(program, name); - glUniformBlockBinding(program, index, binding); -} -#endif diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.h index 9d88cf7..029ccae 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGL.h @@ -8,13 +8,8 @@ extern "C" { #endif -#ifdef KINC_KONG -int Kinc_G4_Internal_TextureAddressingU(uint32_t unit); -int Kinc_G4_Internal_TextureAddressingV(uint32_t unit); -#else int Kinc_G4_Internal_TextureAddressingU(kinc_g4_texture_unit_t unit); int Kinc_G4_Internal_TextureAddressingV(kinc_g4_texture_unit_t unit); -#endif int Kinc_G4_Internal_StencilFunc(kinc_g4_compare_mode_t mode); #ifdef __cplusplus diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGLWindow.c.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGLWindow.c.h index 3cd8fa7..ffe13f6 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGLWindow.c.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGLWindow.c.h @@ -1,4 +1,4 @@ -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include "OpenGLWindow.h" #include diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGLWindow.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGLWindow.h index 4b88df7..909b2fb 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGLWindow.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/OpenGLWindow.h @@ -1,6 +1,6 @@ #pragma once -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #define WIN32_LEAN_AND_MEAN #define NOMINMAX #include diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/ShaderStorageBufferImpl.c.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/ShaderStorageBufferImpl.c.h index c825aec..7c21341 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/ShaderStorageBufferImpl.c.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/ShaderStorageBufferImpl.c.h @@ -2,7 +2,7 @@ #include -#if defined(KORE_WINDOWS) || (defined(KORE_LINUX) && defined(GL_VERSION_4_3)) || (defined(KORE_ANDROID) && defined(GL_ES_VERSION_3_1)) +#if defined(KINC_WINDOWS) || (defined(KINC_LINUX) && defined(GL_VERSION_4_3)) || (defined(KINC_ANDROID) && defined(GL_ES_VERSION_3_1)) #define HAS_COMPUTE #endif diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/VrInterface.c.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/VrInterface.c.h index 95a15d3..c5ba76f 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/VrInterface.c.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/VrInterface.c.h @@ -1,4 +1,4 @@ -#ifdef KORE_OCULUS +#ifdef KINC_OCULUS #include #include diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/compute.c.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/compute.c.h new file mode 100644 index 0000000..567e9ba --- /dev/null +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/compute.c.h @@ -0,0 +1,202 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#if defined(KINC_WINDOWS) || (defined(KINC_LINUX) && defined(GL_VERSION_4_3)) || (defined(KINC_ANDROID) && defined(GL_ES_VERSION_3_1)) +#define HAS_COMPUTE +bool kinc_internal_gl_has_compute = true; +#else +bool kinc_internal_gl_has_compute = false; +#endif + +#ifdef HAS_COMPUTE +static int convertInternalImageFormat(kinc_image_format_t format) { + switch (format) { + case KINC_IMAGE_FORMAT_RGBA128: + return GL_RGBA32F; + case KINC_IMAGE_FORMAT_RGBA64: + return GL_RGBA16F; + case KINC_IMAGE_FORMAT_RGBA32: + default: + return GL_RGBA8; + case KINC_IMAGE_FORMAT_A32: + return GL_R32F; + case KINC_IMAGE_FORMAT_A16: + return GL_R16F; + case KINC_IMAGE_FORMAT_GREY8: + return GL_R8; + } +} + +static int convertInternalRTFormat(kinc_g4_render_target_format_t format) { + switch (format) { + case KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT: + return GL_RGBA16F; + case KINC_G4_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT: + return GL_R32F; + case KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT: + return GL_RGBA32F; + case KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH: + return GL_DEPTH_COMPONENT16; + case KINC_G4_RENDER_TARGET_FORMAT_8BIT_RED: + return GL_RED; + case KINC_G4_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT: + return GL_R16F; + case KINC_G4_RENDER_TARGET_FORMAT_32BIT: + default: + return GL_RGBA; + } +} +#endif + +void kinc_g4_compute_shader_init(kinc_g4_compute_shader *shader, void *source, int length) { + shader->impl._length = length; + shader->impl.textureCount = 0; + shader->impl._source = (char *)malloc(sizeof(char) * (length + 1)); + for (int i = 0; i < length; ++i) { + shader->impl._source[i] = ((char *)source)[i]; + } + shader->impl._source[length] = 0; + +#ifdef HAS_COMPUTE + shader->impl._id = glCreateShader(GL_COMPUTE_SHADER); + glCheckErrors(); + glShaderSource(shader->impl._id, 1, (const GLchar **)&shader->impl._source, NULL); + glCompileShader(shader->impl._id); + + int result; + glGetShaderiv(shader->impl._id, GL_COMPILE_STATUS, &result); + if (result != GL_TRUE) { + int length; + glGetShaderiv(shader->impl._id, GL_INFO_LOG_LENGTH, &length); + char *errormessage = (char *)malloc(sizeof(char) * length); + glGetShaderInfoLog(shader->impl._id, length, NULL, errormessage); + kinc_log(KINC_LOG_LEVEL_ERROR, "GLSL compiler error: %s\n", errormessage); + free(errormessage); + } + + shader->impl._programid = glCreateProgram(); + glAttachShader(shader->impl._programid, shader->impl._id); + glLinkProgram(shader->impl._programid); + + glGetProgramiv(shader->impl._programid, GL_LINK_STATUS, &result); + if (result != GL_TRUE) { + int length; + glGetProgramiv(shader->impl._programid, GL_INFO_LOG_LENGTH, &length); + char *errormessage = (char *)malloc(sizeof(char) * length); + glGetProgramInfoLog(shader->impl._programid, length, NULL, errormessage); + kinc_log(KINC_LOG_LEVEL_ERROR, "GLSL linker error: %s\n", errormessage); + free(errormessage); + } +#endif + + // TODO: Get rid of allocations + shader->impl.textures = (char **)malloc(sizeof(char *) * 16); + for (int i = 0; i < 16; ++i) { + shader->impl.textures[i] = (char *)malloc(sizeof(char) * 128); + shader->impl.textures[i][0] = 0; + } + shader->impl.textureValues = (int *)malloc(sizeof(int) * 16); +} + +void kinc_g4_compute_shader_destroy(kinc_g4_compute_shader *shader) { + free(shader->impl._source); + shader->impl._source = NULL; +#ifdef HAS_COMPUTE + glDeleteProgram(shader->impl._programid); + glDeleteShader(shader->impl._id); +#endif +} +kinc_g4_constant_location_t kinc_g4_compute_shader_get_constant_location(kinc_g4_compute_shader *shader, const char *name) { + kinc_g4_constant_location_t location; +#ifdef HAS_COMPUTE + location.impl.location = glGetUniformLocation(shader->impl._programid, name); + location.impl.type = GL_FLOAT; + GLint count = 0; + glGetProgramiv(shader->impl._programid, GL_ACTIVE_UNIFORMS, &count); + char arrayName[1024]; + strcpy(arrayName, name); + strcat(arrayName, "[0]"); + for (GLint i = 0; i < count; ++i) { + GLenum type; + char uniformName[1024]; + GLsizei length; + GLint size; + glGetActiveUniform(shader->impl._programid, i, 1024 - 1, &length, &size, &type, uniformName); + if (strcmp(uniformName, name) == 0 || strcmp(uniformName, arrayName) == 0) { + location.impl.type = type; + break; + } + } + glCheckErrors(); + if (location.impl.location < 0) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Uniform %s not found.", name); + } +#endif + return location; +} + +static int compute_findTexture(kinc_g4_compute_shader *shader, const char *name) { + for (int index = 0; index < shader->impl.textureCount; ++index) { + if (strcmp(shader->impl.textures[index], name) == 0) + return index; + } + return -1; +} + +kinc_g4_texture_unit_t kinc_g4_compute_shader_get_texture_unit(kinc_g4_compute_shader *shader, const char *name) { + int index = compute_findTexture(shader, name); + if (index < 0) { + int location = glGetUniformLocation(shader->impl._programid, name); + glCheckErrors(); + index = shader->impl.textureCount; + shader->impl.textureValues[index] = location; + strcpy(shader->impl.textures[index], name); + ++shader->impl.textureCount; + } + kinc_g4_texture_unit_t unit; + for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) { + unit.stages[i] = -1; + } + unit.stages[KINC_G4_SHADER_TYPE_COMPUTE] = index; + return unit; +} + +void kinc_g4_set_shader_storage_buffer(kinc_shader_storage_buffer_t *buffer, int index) { +#ifdef HAS_COMPUTE + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, index, buffer->impl.bufferId); + glCheckErrors(); +#endif +} + +void kinc_g4_set_compute_shader(kinc_g4_compute_shader *shader) { +#ifdef HAS_COMPUTE + glUseProgram(shader->impl._programid); + glCheckErrors(); + + for (int index = 0; index < shader->impl.textureCount; ++index) { + glUniform1i(shader->impl.textureValues[index], index); + glCheckErrors(); + } +#endif +} + +void kinc_g4_compute(int x, int y, int z) { +#ifdef HAS_COMPUTE + glDispatchCompute(x, y, z); + glCheckErrors(); + glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); + glCheckErrors(); + glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); + glCheckErrors(); +#endif +} diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/compute.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/compute.h new file mode 100644 index 0000000..32328f3 --- /dev/null +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/compute.h @@ -0,0 +1,20 @@ +#pragma once + +typedef struct kinc_g4_compute_constant_location_impl { + int location; + unsigned int type; +} kinc_g4_compute_constant_location_impl; + +typedef struct kinc_g4_compute_texture_unit_impl { + int unit; +} kinc_g4_compute_texture_unit_impl; + +typedef struct kinc_g4_compute_shader_impl { + char **textures; + int *textureValues; + int textureCount; + unsigned _id; + unsigned _programid; + char *_source; + int _length; +} kinc_g4_compute_shader_impl; diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/constantbuffer.c.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/constantbuffer.c.h deleted file mode 100644 index f613f41..0000000 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/constantbuffer.c.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifdef KINC_KONG - -#include - -void kinc_g4_constant_buffer_init(kinc_g4_constant_buffer *buffer, size_t size) { - buffer->impl.size = size; - buffer->impl.last_start = 0; - buffer->impl.last_size = size; - - buffer->impl.data = malloc(size); - - buffer->impl.buffer = 0; - glGenBuffers(1, &buffer->impl.buffer); - glBindBuffer(GL_UNIFORM_BUFFER, buffer->impl.buffer); - glBufferData(GL_UNIFORM_BUFFER, size, NULL, GL_DYNAMIC_DRAW); - glBindBuffer(GL_UNIFORM_BUFFER, 0); -} - -void kinc_g4_constant_buffer_destroy(kinc_g4_constant_buffer *buffer) { - free(buffer->impl.data); - buffer->impl.data = NULL; - - glDeleteBuffers(1, &buffer->impl.buffer); - buffer->impl.buffer = 0; -} - -uint8_t *kinc_g4_constant_buffer_lock_all(kinc_g4_constant_buffer *buffer) { - return kinc_g4_constant_buffer_lock(buffer, 0, kinc_g4_constant_buffer_size(buffer)); -} - -uint8_t *kinc_g4_constant_buffer_lock(kinc_g4_constant_buffer *buffer, size_t start, size_t size) { - buffer->impl.last_start = start; - buffer->impl.last_size = size; - - uint8_t *data = (uint8_t *)buffer->impl.data; - return &data[start]; -} - -void kinc_g4_constant_buffer_unlock_all(kinc_g4_constant_buffer *buffer) { - kinc_g4_constant_buffer_unlock(buffer, buffer->impl.last_size); -} - -void kinc_g4_constant_buffer_unlock(kinc_g4_constant_buffer *buffer, size_t count) { - glBindBuffer(GL_UNIFORM_BUFFER, buffer->impl.buffer); - glBufferSubData(GL_UNIFORM_BUFFER, buffer->impl.last_start, buffer->impl.last_size, buffer->impl.data); - glBindBuffer(GL_UNIFORM_BUFFER, 0); -} - -size_t kinc_g4_constant_buffer_size(kinc_g4_constant_buffer *buffer) { - return buffer->impl.size; -} - -#endif diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/constantbuffer.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/constantbuffer.h deleted file mode 100644 index 67f25c5..0000000 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/constantbuffer.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#ifdef KINC_KONG - -#include - -typedef struct kinc_g4_constant_buffer_impl { - unsigned buffer; - void *data; - size_t size; - size_t last_start; - size_t last_size; -} kinc_g4_constant_buffer_impl; - -#endif diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/ogl.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/ogl.h index 11e4bf2..3c0f6c2 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/ogl.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/ogl.h @@ -1,44 +1,44 @@ #pragma once -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #include #endif -#ifdef KORE_MACOS +#ifdef KINC_MACOS #include #include #endif -#ifdef KORE_IOS +#ifdef KINC_IOS #import #import #import #endif -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID #include -#if KORE_ANDROID_API >= 18 +#if KINC_ANDROID_API >= 18 #include #endif #include #include #endif -#ifdef KORE_EMSCRIPTEN +#ifdef KINC_EMSCRIPTEN #define GL_GLEXT_PROTOTYPES #define EGL_EGLEXT_PROTOTYPES #include #endif -#ifdef KORE_LINUX +#ifdef KINC_LINUX #define GL_GLEXT_PROTOTYPES #include #include #endif -#ifdef KORE_PI +#ifdef KINC_RASPBERRY_PI // #define GL_GLEXT_PROTOTYPES #include "GLES2/gl2.h" @@ -46,11 +46,7 @@ #include "EGL/eglext.h" #endif -#ifdef KORE_TIZEN -#include -#endif - -#ifdef KORE_WASM +#ifdef KINC_WASM #include #endif diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/openglunit.c b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/openglunit.c index cb8f04f..bf53c74 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/openglunit.c +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/openglunit.c @@ -7,7 +7,7 @@ static int kinc_internal_opengl_max_vertex_attribute_arrays = 0; #include "OpenGLWindow.c.h" #include "ShaderStorageBufferImpl.c.h" #include "VrInterface.c.h" -#include "constantbuffer.c.h" +#include "compute.c.h" #include "indexbuffer.c.h" #include "pipeline.c.h" #include "rendertarget.c.h" diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/pipeline.c.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/pipeline.c.h index c659c1f..0ab9f18 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/pipeline.c.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/pipeline.c.h @@ -15,7 +15,7 @@ #include #include -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES bool Kinc_Internal_ProgramUsesTessellation = false; #endif extern bool Kinc_Internal_SupportsConservativeRaster; @@ -125,7 +125,7 @@ static int toGlShader(kinc_g4_shader_type_t type) { return GL_VERTEX_SHADER; case KINC_G4_SHADER_TYPE_FRAGMENT: return GL_FRAGMENT_SHADER; -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES case KINC_G4_SHADER_TYPE_GEOMETRY: return GL_GEOMETRY_SHADER; case KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL: @@ -157,7 +157,7 @@ static void compileShader(unsigned *id, const char *source, size_t length, kinc_ void kinc_g4_pipeline_compile(kinc_g4_pipeline_t *state) { compileShader(&state->vertex_shader->impl._glid, state->vertex_shader->impl.source, state->vertex_shader->impl.length, KINC_G4_SHADER_TYPE_VERTEX); compileShader(&state->fragment_shader->impl._glid, state->fragment_shader->impl.source, state->fragment_shader->impl.length, KINC_G4_SHADER_TYPE_FRAGMENT); -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES if (state->geometry_shader != NULL) { compileShader(&state->geometry_shader->impl._glid, state->geometry_shader->impl.source, state->geometry_shader->impl.length, KINC_G4_SHADER_TYPE_GEOMETRY); @@ -173,7 +173,7 @@ void kinc_g4_pipeline_compile(kinc_g4_pipeline_t *state) { #endif glAttachShader(state->impl.programId, state->vertex_shader->impl._glid); glAttachShader(state->impl.programId, state->fragment_shader->impl._glid); -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES if (state->geometry_shader != NULL) { glAttachShader(state->impl.programId, state->geometry_shader->impl._glid); } @@ -214,8 +214,8 @@ void kinc_g4_pipeline_compile(kinc_g4_pipeline_t *state) { free(errormessage); } -#ifndef KORE_OPENGL_ES -#ifndef KORE_LINUX +#ifndef KINC_OPENGL_ES +#ifndef KINC_LINUX if (state->tessellation_control_shader != NULL) { glPatchParameteri(GL_PATCH_VERTICES, 3); glCheckErrors(); @@ -225,7 +225,7 @@ void kinc_g4_pipeline_compile(kinc_g4_pipeline_t *state) { } void kinc_g4_internal_set_pipeline(kinc_g4_pipeline_t *pipeline) { -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES Kinc_Internal_ProgramUsesTessellation = pipeline->tessellation_control_shader != NULL; #endif glUseProgram(pipeline->impl.programId); @@ -257,7 +257,7 @@ void kinc_g4_internal_set_pipeline(kinc_g4_pipeline_t *pipeline) { pipeline->stencil_read_mask); } -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glColorMask(pipeline->color_write_mask_red[0], pipeline->color_write_mask_green[0], pipeline->color_write_mask_blue[0], pipeline->color_write_mask_alpha[0]); #else diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/rendertarget.c.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/rendertarget.c.h index faa29e0..207701e 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/rendertarget.c.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/rendertarget.c.h @@ -51,12 +51,12 @@ static int getPower2(int i) { return pow2(power); } -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES extern int gles_version; #endif bool kinc_opengl_internal_nonPow2RenderTargetsSupported() { -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES return gles_version >= 3; #else return true; @@ -66,9 +66,9 @@ bool kinc_opengl_internal_nonPow2RenderTargetsSupported() { static void setupDepthStencil(kinc_g4_render_target_t *renderTarget, GLenum texType, int depthBufferBits, int stencilBufferBits, int width, int height) { if (depthBufferBits > 0 && stencilBufferBits > 0) { renderTarget->impl._hasDepth = true; -#if defined(KORE_OPENGL_ES) && !defined(KORE_PI) && !defined(KORE_EMSCRIPTEN) +#if defined(KINC_OPENGL_ES) && !defined(KINC_RASPBERRY_PI) && !defined(KINC_EMSCRIPTEN) GLenum internalFormat = GL_DEPTH24_STENCIL8_OES; -#elif defined(KORE_OPENGL_ES) +#elif defined(KINC_OPENGL_ES) GLenum internalFormat = 0x88F0; // GL_DEPTH24_STENCIL8_OES #else GLenum internalFormat; @@ -84,7 +84,7 @@ static void setupDepthStencil(kinc_g4_render_target_t *renderTarget, GLenum texT // glCheckErrors(); // glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, width, height); // glCheckErrors(); - // #ifdef KORE_OPENGL_ES + // #ifdef KINC_OPENGL_ES // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthRenderbuffer); // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthRenderbuffer); // #else @@ -105,7 +105,7 @@ static void setupDepthStencil(kinc_g4_render_target_t *renderTarget, GLenum texT glCheckErrors(); glBindFramebuffer(GL_FRAMEBUFFER, renderTarget->impl._framebuffer); glCheckErrors(); -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, texType, renderTarget->impl._depthTexture, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, texType, renderTarget->impl._depthTexture, 0); #else @@ -132,7 +132,7 @@ static void setupDepthStencil(kinc_g4_render_target_t *renderTarget, GLenum texT glCheckErrors(); glBindTexture(texType, renderTarget->impl._depthTexture); glCheckErrors(); -#if defined(KORE_EMSCRIPTEN) || defined(KORE_WASM) +#if defined(KINC_EMSCRIPTEN) || defined(KINC_WASM) GLint format = GL_DEPTH_COMPONENT16; #else GLint format = depthBufferBits == 16 ? GL_DEPTH_COMPONENT16 : GL_DEPTH_COMPONENT; @@ -188,28 +188,28 @@ void kinc_g4_render_target_init_with_multisampling(kinc_g4_render_target_t *rend switch (format) { case KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_EXT, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RGBA, GL_FLOAT, 0); #else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RGBA, GL_FLOAT, 0); #endif break; case KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_EXT, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RGBA, GL_HALF_FLOAT, 0); #else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RGBA, GL_HALF_FLOAT, 0); #endif break; case KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); #endif glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, renderTarget->texWidth, renderTarget->texHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0); break; case KINC_G4_RENDER_TARGET_FORMAT_8BIT_RED: -#ifdef KORE_IOS +#ifdef KINC_IOS glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RED, GL_UNSIGNED_BYTE, 0); #else glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RED, GL_UNSIGNED_BYTE, 0); @@ -236,7 +236,7 @@ void kinc_g4_render_target_init_with_multisampling(kinc_g4_render_target_t *rend if (format == KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH) { glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, renderTarget->impl._texture, 0); -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); #endif @@ -290,7 +290,7 @@ void kinc_g4_render_target_init_cube_with_multisampling(kinc_g4_render_target_t switch (format) { case KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES for (int i = 0; i < 6; i++) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA32F_EXT, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RGBA, GL_FLOAT, 0); #else @@ -299,7 +299,7 @@ void kinc_g4_render_target_init_cube_with_multisampling(kinc_g4_render_target_t #endif break; case KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES for (int i = 0; i < 6; i++) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA16F_EXT, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RGBA, GL_HALF_FLOAT, 0); #else @@ -308,7 +308,7 @@ void kinc_g4_render_target_init_cube_with_multisampling(kinc_g4_render_target_t #endif break; case KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH: -#ifdef KORE_OPENGL_ES +#ifdef KINC_OPENGL_ES glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); #endif @@ -332,7 +332,7 @@ void kinc_g4_render_target_init_cube_with_multisampling(kinc_g4_render_target_t if (format == KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH) { renderTarget->isDepthAttachment = true; -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES glDrawBuffer(GL_NONE); glCheckErrors(); glReadBuffer(GL_NONE); @@ -359,21 +359,12 @@ void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget) { glDeleteFramebuffers(1, framebuffers); } -#ifdef KINC_KONG -void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, uint32_t unit) { - glActiveTexture(GL_TEXTURE0 + unit); - glCheckErrors(); - glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._texture); - glCheckErrors(); -} -#else void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) { glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]); glCheckErrors(); glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._texture); glCheckErrors(); } -#endif void kinc_g4_render_target_use_depth_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) { glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]); diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/texture.c.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/texture.c.h index cf3b225..539e7d3 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/texture.c.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/texture.c.h @@ -111,7 +111,7 @@ static int convertInternalFormat(kinc_image_format_t format) { case KINC_IMAGE_FORMAT_RGBA32: return GL_RGBA8; default: -#ifdef KORE_IOS +#ifdef KINC_IOS return GL_RGBA; #else // #ifdef GL_BGRA @@ -127,7 +127,7 @@ static int convertInternalFormat(kinc_image_format_t format) { case KINC_IMAGE_FORMAT_A16: return GL_R16F_EXT; case KINC_IMAGE_FORMAT_GREY8: -#ifdef KORE_IOS +#ifdef KINC_IOS return GL_RED; #else return GL_R8; @@ -256,7 +256,7 @@ static void convertImageToPow2(kinc_image_format_t format, uint8_t *from, int fw void kinc_g4_texture_init_from_image(kinc_g4_texture_t *texture, kinc_image_t *image) { texture->format = image->format; bool toPow2; -#ifdef KORE_IOS +#ifdef KINC_IOS texture->tex_width = image->width; texture->tex_height = image->height; toPow2 = false; @@ -297,7 +297,7 @@ void kinc_g4_texture_init_from_image(kinc_g4_texture_t *texture, kinc_image_t *i break; } -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID texture->impl.external_oes = false; #endif @@ -313,7 +313,7 @@ void kinc_g4_texture_init_from_image(kinc_g4_texture_t *texture, kinc_image_t *i switch (image->compression) { case KINC_IMAGE_COMPRESSION_PVRTC: -#ifdef KORE_IOS +#ifdef KINC_IOS glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, texture->tex_width, texture->tex_height, 0, texture->tex_width * texture->tex_height / 2, image->data); #endif @@ -325,7 +325,7 @@ void kinc_g4_texture_init_from_image(kinc_g4_texture_t *texture, kinc_image_t *i break; } case KINC_IMAGE_COMPRESSION_DXT5: -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, texture->tex_width, texture->tex_height, 0, image->data_size, image->data); #endif break; @@ -371,12 +371,12 @@ void kinc_g4_texture_init_from_image(kinc_g4_texture_t *texture, kinc_image_t *i void kinc_g4_texture_init_from_image3d(kinc_g4_texture_t *texture, kinc_image_t *image) { texture->format = image->format; -#ifndef KORE_OPENGL_ES // Requires GLES 3.0 +#ifndef KINC_OPENGL_ES // Requires GLES 3.0 texture->tex_width = image->width; texture->tex_height = image->height; texture->tex_depth = image->depth; -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID external_oes = false; #endif @@ -424,7 +424,7 @@ void kinc_g4_texture_init_from_image3d(kinc_g4_texture_t *texture, kinc_image_t } void kinc_g4_texture_init(kinc_g4_texture_t *texture, int width, int height, kinc_image_format_t format) { -#ifdef KORE_IOS +#ifdef KINC_IOS texture->tex_width = width; texture->tex_height = height; #else @@ -441,7 +441,7 @@ void kinc_g4_texture_init(kinc_g4_texture_t *texture, int width, int height, kin texture->format = format; // conversionBuffer = new u8[texWidth * texHeight * 4]; -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID texture->impl.external_oes = false; #endif @@ -467,7 +467,7 @@ void kinc_g4_texture_init(kinc_g4_texture_t *texture, int width, int height, kin } void kinc_g4_texture_init3d(kinc_g4_texture_t *texture, int width, int height, int depth, kinc_image_format_t format) { -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES texture->tex_width = width; texture->tex_height = height; texture->tex_depth = depth; @@ -488,7 +488,7 @@ void kinc_g4_texture_init3d(kinc_g4_texture_t *texture, int width, int height, i #endif } -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID void kinc_g4_texture_init_from_id(kinc_g4_texture_t *texture, unsigned texid) { texture->impl.texture = texid; texture->impl.external_oes = true; @@ -503,33 +503,15 @@ void kinc_g4_texture_destroy(kinc_g4_texture_t *texture) { glFlush(); } -#ifdef KINC_KONG -void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, uint32_t unit) { - GLenum target = texture->tex_depth > 1 ? GL_TEXTURE_3D : GL_TEXTURE_2D; - glActiveTexture(GL_TEXTURE0 + unit); - glCheckErrors(); -#ifdef KORE_ANDROID - if (texture->impl.external_oes) { - glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->impl.texture); - glCheckErrors(); - } - else { - glBindTexture(target, texture->impl.texture); - glCheckErrors(); - } -#else - glBindTexture(target, texture->impl.texture); - glCheckErrors(); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, Kinc_G4_Internal_TextureAddressingU(unit)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, Kinc_G4_Internal_TextureAddressingV(unit)); -#endif -} -#else void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit) { GLenum target = texture->tex_depth > 1 ? GL_TEXTURE_3D : GL_TEXTURE_2D; - glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]); + for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) { + if (unit.stages[i] >= 0) { + glActiveTexture(GL_TEXTURE0 + unit.stages[i]); + } + } glCheckErrors(); -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID if (texture->impl.external_oes) { glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->impl.texture); glCheckErrors(); @@ -545,11 +527,14 @@ void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, kinc_g4_texture_uni glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, Kinc_G4_Internal_TextureAddressingV(unit)); #endif } -#endif void Kinc_G4_Internal_TextureImageSet(kinc_g4_texture_t *texture, kinc_g4_texture_unit_t unit) { -#if defined(KORE_WINDOWS) || (defined(KORE_LINUX) && defined(GL_VERSION_4_4)) - glBindImageTexture(unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT], texture->impl.texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, convertInternalFormat(texture->format)); +#if defined(KINC_WINDOWS) || (defined(KINC_LINUX) && defined(GL_VERSION_4_4)) + for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) { + if (unit.stages[i] >= 0) { + glBindImageTexture(unit.stages[i], texture->impl.texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, convertInternalFormat(texture->format)); + } + } glCheckErrors(); #endif } @@ -585,7 +570,7 @@ void kinc_g4_texture_unlock(kinc_g4_texture_t *texture) { glBindTexture(target, texture->impl.texture); glCheckErrors(); if (texture->tex_depth > 1) { -#ifndef KORE_OPENGL_ES +#ifndef KINC_OPENGL_ES glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, texture->tex_width, texture->tex_height, texture->tex_depth, convertFormat(texture->format), convertType(texture->format), texdata); #endif @@ -609,7 +594,7 @@ void kinc_g4_texture_clear(kinc_g4_texture_t *texture, int x, int y, int z, int #endif } -#if defined(KORE_IOS) || defined(KORE_MACOS) +#if defined(KINC_IOS) || defined(KINC_MACOS) void kinc_g4_texture_upload(kinc_g4_texture_t *texture, uint8_t *data, int stride) { glBindTexture(GL_TEXTURE_2D, texture->impl.texture); glCheckErrors(); diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/texture.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/texture.h index 4b6d41e..b4cd56c 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/texture.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/texture.h @@ -8,7 +8,7 @@ extern "C" { typedef struct { unsigned int texture; -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID bool external_oes; #endif uint8_t pixfmt; diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/vertexbuffer.c.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/vertexbuffer.c.h index ced5299..483dbb0 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/vertexbuffer.c.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/vertexbuffer.c.h @@ -11,7 +11,7 @@ extern kinc_g4_index_buffer_t *Kinc_Internal_CurrentIndexBuffer; static kinc_g4_vertex_buffer_t *currentVertexBuffer = NULL; -#if defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18 +#if defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18 void *glesVertexAttribDivisor; #endif @@ -120,7 +120,7 @@ int kinc_g4_vertex_buffer_stride(kinc_g4_vertex_buffer_t *buffer) { return buffer->impl.myStride; } -#if !defined(KORE_OPENGL_ES) || (defined(KORE_OPENGL_ES) && defined(KORE_WASM)) || (defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18) +#if !defined(KINC_OPENGL_ES) || (defined(KINC_OPENGL_ES) && defined(KINC_WASM)) || (defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18) static bool attribDivisorUsed = false; #endif @@ -253,14 +253,14 @@ int Kinc_G4_Internal_SetVertexAttributes(kinc_g4_vertex_buffer_t *buffer, int of glCheckErrors(); glVertexAttribPointer(offset + actualIndex, 4, type, false, buffer->impl.myStride, (void *)(int64_t)(internaloffset + addonOffset)); glCheckErrors(); -#if !defined(KORE_OPENGL_ES) || (defined(KORE_OPENGL_ES) && defined(KORE_WASM)) +#if !defined(KINC_OPENGL_ES) || (defined(KINC_OPENGL_ES) && defined(KINC_WASM)) if (attribDivisorUsed || buffer->impl.instanceDataStepRate != 0) { attribDivisorUsed = true; glVertexAttribDivisor(offset + actualIndex, buffer->impl.instanceDataStepRate); glCheckErrors(); } #endif -#if (defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18) +#if (defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18) if (attribDivisorUsed || buffer->impl.instanceDataStepRate != 0) { attribDivisorUsed = true; ((void (*)(GLuint, GLuint))glesVertexAttribDivisor)(offset + actualIndex, buffer->impl.instanceDataStepRate); @@ -277,14 +277,14 @@ int Kinc_G4_Internal_SetVertexAttributes(kinc_g4_vertex_buffer_t *buffer, int of glCheckErrors(); glVertexAttribPointer(offset + actualIndex, size, type, type == GL_FLOAT ? false : true, buffer->impl.myStride, (void *)(int64_t)internaloffset); glCheckErrors(); -#if !defined(KORE_OPENGL_ES) || (defined(KORE_OPENGL_ES) && defined(KORE_WASM)) +#if !defined(KINC_OPENGL_ES) || (defined(KINC_OPENGL_ES) && defined(KINC_WASM)) if (attribDivisorUsed || buffer->impl.instanceDataStepRate != 0) { attribDivisorUsed = true; glVertexAttribDivisor(offset + actualIndex, buffer->impl.instanceDataStepRate); glCheckErrors(); } #endif -#if (defined(KORE_OPENGL_ES) && defined(KORE_ANDROID) && KORE_ANDROID_API >= 18) +#if (defined(KINC_OPENGL_ES) && defined(KINC_ANDROID) && KINC_ANDROID_API >= 18) if (attribDivisorUsed || buffer->impl.instanceDataStepRate != 0) { attribDivisorUsed = true; ((void (*)(GLuint, GLuint))glesVertexAttribDivisor)(offset + actualIndex, buffer->impl.instanceDataStepRate); diff --git a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/vertexbuffer.h b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/vertexbuffer.h index 780f500..46820a2 100644 --- a/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/vertexbuffer.h +++ b/Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/vertexbuffer.h @@ -15,7 +15,7 @@ typedef struct { unsigned bufferId; int sectionStart; int sectionSize; - // #if defined KORE_ANDROID || defined KORE_EMSCRIPTEN || defined KORE_TIZEN + // #if defined KINC_ANDROID || defined KINC_EMSCRIPTEN kinc_g4_vertex_structure_t structure; // #endif int instanceDataStepRate; diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h index 4732637..ca4bc8b 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h @@ -7,12 +7,12 @@ #include #include #include -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #undef CreateWindow #endif #include -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #endif #include @@ -42,8 +42,8 @@ ID3D12DescriptorHeap* cbvHeap;*/ extern "C" { ID3D12CommandQueue *commandQueue; -#ifdef KORE_DIRECT3D_HAS_NO_SWAPCHAIN -ID3D12Resource *swapChainRenderTargets[QUEUE_SLOT_COUNT]; +#ifdef KINC_DIRECT3D_HAS_NO_SWAPCHAIN +ID3D12Resource *swapChainRenderTargets[KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT]; #else // IDXGISwapChain *swapChain; #endif @@ -54,7 +54,7 @@ ID3D12Resource *swapChainRenderTargets[QUEUE_SLOT_COUNT]; // int window->new_width; // int window->new_height; -#ifndef KORE_WINDOWS +#ifndef KINC_WINDOWS #define DXGI_SWAP_CHAIN_DESC DXGI_SWAP_CHAIN_DESC1 #define IDXGISwapChain IDXGISwapChain1 #endif @@ -62,15 +62,15 @@ ID3D12Resource *swapChainRenderTargets[QUEUE_SLOT_COUNT]; struct RenderEnvironment { ID3D12Device *device; ID3D12CommandQueue *queue; -#ifdef KORE_DIRECT3D_HAS_NO_SWAPCHAIN - ID3D12Resource *renderTargets[QUEUE_SLOT_COUNT]; +#ifdef KINC_DIRECT3D_HAS_NO_SWAPCHAIN + ID3D12Resource *renderTargets[KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT]; #else IDXGISwapChain *swapChain; #endif }; -#ifndef KORE_WINDOWS -#ifdef KORE_DIRECT3D_HAS_NO_SWAPCHAIN +#ifndef KINC_WINDOWS +#ifdef KINC_DIRECT3D_HAS_NO_SWAPCHAIN extern "C" void createSwapChain(struct RenderEnvironment *env, int bufferCount); #else extern "C" void createSwapChain(struct RenderEnvironment *env, const DXGI_SWAP_CHAIN_DESC1 *desc); @@ -83,16 +83,16 @@ extern bool bilinearFiltering; // ID3D12DescriptorHeap* renderTargetDescriptorHeap; // static UINT64 window->current_fence_value; -// static UINT64 window->current_fence_value[QUEUE_SLOT_COUNT]; -// static HANDLE window->frame_fence_events[QUEUE_SLOT_COUNT]; -// static ID3D12Fence *window->frame_fences[QUEUE_SLOT_COUNT]; +// static UINT64 window->current_fence_value[KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT]; +// static HANDLE window->frame_fence_events[KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT]; +// static ID3D12Fence *window->frame_fences[KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT]; static ID3D12Fence *uploadFence; static ID3D12GraphicsCommandList *initCommandList; static ID3D12CommandAllocator *initCommandAllocator; extern "C" struct RenderEnvironment createDeviceAndSwapChainHelper(D3D_FEATURE_LEVEL minimumFeatureLevel, const struct DXGI_SWAP_CHAIN_DESC *swapChainDesc) { struct RenderEnvironment result = {0}; -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS kinc_microsoft_affirm(D3D12CreateDevice(NULL, minimumFeatureLevel, IID_PPV_ARGS(&result.device))); D3D12_COMMAND_QUEUE_DESC queueDesc = {}; @@ -107,8 +107,8 @@ extern "C" struct RenderEnvironment createDeviceAndSwapChainHelper(D3D_FEATURE_L DXGI_SWAP_CHAIN_DESC swapChainDescCopy = *swapChainDesc; kinc_microsoft_affirm(dxgiFactory->CreateSwapChain((IUnknown *)result.queue, &swapChainDescCopy, &result.swapChain)); #else -#ifdef KORE_DIRECT3D_HAS_NO_SWAPCHAIN - createSwapChain(&result, QUEUE_SLOT_COUNT); +#ifdef KINC_DIRECT3D_HAS_NO_SWAPCHAIN + createSwapChain(&result, KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT); #else createSwapChain(&result, swapChainDesc); #endif @@ -157,7 +157,7 @@ extern "C" void setupSwapChain(struct dx_window *window) { window->current_fence_value = 0; - for (int i = 0; i < QUEUE_SLOT_COUNT; ++i) { + for (int i = 0; i < KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT; ++i) { window->frame_fence_events[i] = CreateEvent(NULL, FALSE, FALSE, NULL); window->fence_values[i] = 0; device->CreateFence(window->current_fence_value, D3D12_FENCE_FLAG_NONE, IID_GRAPHICS_PPV_ARGS(&window->frame_fences[i])); @@ -167,7 +167,7 @@ extern "C" void setupSwapChain(struct dx_window *window) { //**createRenderTargetView(); } -#ifdef KORE_CONSOLE +#ifdef KINC_CONSOLE extern "C" void createDeviceAndSwapChain(struct dx_window *window); #else static void createDeviceAndSwapChain(struct dx_window *window) { @@ -180,7 +180,7 @@ static void createDeviceAndSwapChain(struct dx_window *window) { struct DXGI_SWAP_CHAIN_DESC swapChainDesc; ZeroMemory(&swapChainDesc, sizeof(swapChainDesc)); - swapChainDesc.BufferCount = QUEUE_SLOT_COUNT; + swapChainDesc.BufferCount = KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT; swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferDesc.Width = window->width; @@ -286,7 +286,7 @@ static void createComputeRootSignature() { ID3DBlob *rootBlob; ID3DBlob *errorBlob; - D3D12_ROOT_PARAMETER parameters[3] = {}; + D3D12_ROOT_PARAMETER parameters[4] = {}; D3D12_DESCRIPTOR_RANGE range; range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; @@ -299,21 +299,32 @@ static void createComputeRootSignature() { parameters[0].DescriptorTable.NumDescriptorRanges = 1; parameters[0].DescriptorTable.pDescriptorRanges = ⦥ + D3D12_DESCRIPTOR_RANGE uav_range; + uav_range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV; + uav_range.NumDescriptors = (UINT)KINC_INTERNAL_G5_TEXTURE_COUNT; + uav_range.BaseShaderRegister = 0; + uav_range.RegisterSpace = 0; + uav_range.OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND; + parameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; + parameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + parameters[1].DescriptorTable.NumDescriptorRanges = 1; + parameters[1].DescriptorTable.pDescriptorRanges = &uav_range; + D3D12_DESCRIPTOR_RANGE range2; range2.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER; range2.NumDescriptors = (UINT)KINC_INTERNAL_G5_TEXTURE_COUNT; range2.BaseShaderRegister = 0; range2.RegisterSpace = 0; range2.OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND; - parameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; - parameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - parameters[1].DescriptorTable.NumDescriptorRanges = 1; - parameters[1].DescriptorTable.pDescriptorRanges = &range2; - - parameters[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; + parameters[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; parameters[2].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - parameters[2].Descriptor.ShaderRegister = 0; - parameters[2].Descriptor.RegisterSpace = 0; + parameters[2].DescriptorTable.NumDescriptorRanges = 1; + parameters[2].DescriptorTable.pDescriptorRanges = &range2; + + parameters[3].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; + parameters[3].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + parameters[3].Descriptor.ShaderRegister = 0; + parameters[3].Descriptor.RegisterSpace = 0; D3D12_STATIC_SAMPLER_DESC samplers[KINC_INTERNAL_G5_TEXTURE_COUNT * 2]; for (int i = 0; i < KINC_INTERNAL_G5_TEXTURE_COUNT; ++i) { @@ -348,7 +359,7 @@ static void createComputeRootSignature() { } D3D12_ROOT_SIGNATURE_DESC descRootSignature; - descRootSignature.NumParameters = 3; + descRootSignature.NumParameters = 4; descRootSignature.pParameters = parameters; descRootSignature.NumStaticSamplers = 0; descRootSignature.pStaticSamplers = NULL; @@ -387,23 +398,23 @@ static void initialize(struct dx_window *window) { } static void shutdown() { - for (int i = 0; i < QUEUE_SLOT_COUNT; ++i) { + for (int i = 0; i < KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT; ++i) { // waitForFence(window->frame_fences[i], window->current_fence_value[i], window->frame_fence_events[i]); } - for (int i = 0; i < QUEUE_SLOT_COUNT; ++i) { + for (int i = 0; i < KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT; ++i) { // CloseHandle(window->frame_fence_events[i]); } } -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS static void initWindow(struct dx_window *window, int windowIndex) { HWND hwnd = kinc_windows_window_handle(windowIndex); DXGI_SWAP_CHAIN_DESC swapChainDesc; ZeroMemory(&swapChainDesc, sizeof(swapChainDesc)); - swapChainDesc.BufferCount = QUEUE_SLOT_COUNT; + swapChainDesc.BufferCount = KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT; swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferDesc.Width = kinc_window_width(windowIndex); @@ -413,7 +424,7 @@ static void initWindow(struct dx_window *window, int windowIndex) { swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; swapChainDesc.Windowed = true; - IDXGIFactory4 *dxgiFactory; + IDXGIFactory4 *dxgiFactory = NULL; kinc_microsoft_affirm(CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory))); kinc_microsoft_affirm(dxgiFactory->CreateSwapChain((IUnknown *)commandQueue, &swapChainDesc, &window->swapChain)); @@ -425,7 +436,7 @@ static void initWindow(struct dx_window *window, int windowIndex) { void kinc_g5_internal_destroy_window(int window) {} void kinc_g5_internal_destroy() { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS if (device) { device->Release(); device = NULL; @@ -434,7 +445,7 @@ void kinc_g5_internal_destroy() { } void kinc_g5_internal_init() { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #ifdef _DEBUG ID3D12Debug *debugController = NULL; if (D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)) == S_OK) { @@ -480,7 +491,7 @@ void kinc_g5_internal_init_window(int windowIndex, int depthBufferBits, int sten window->vsync = verticalSync; window->width = window->new_width = kinc_window_width(windowIndex); window->height = window->new_height = kinc_window_height(windowIndex); -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS initWindow(window, windowIndex); #else HWND hwnd = NULL; @@ -495,7 +506,7 @@ int kinc_g5_max_bound_textures(void) { return D3D12_COMMONSHADER_SAMPLER_SLOT_COUNT; } -#ifndef KORE_WINDOWS +#ifndef KINC_WINDOWS extern "C" void kinc_internal_wait_for_frame(); #endif @@ -506,37 +517,37 @@ void kinc_g5_begin(kinc_g5_render_target_t *renderTarget, int windowId) { return; began = true; -#ifndef KORE_WINDOWS +#ifndef KINC_WINDOWS kinc_internal_wait_for_frame(); #endif struct dx_window *window = &dx_ctx.windows[windowId]; dx_ctx.current_window = windowId; - window->current_backbuffer = (window->current_backbuffer + 1) % QUEUE_SLOT_COUNT; - - if (window->new_width != window->width || window->new_height != window->height) { -#ifndef KORE_DIRECT3D_HAS_NO_SWAPCHAIN - kinc_microsoft_affirm(window->swapChain->ResizeBuffers(QUEUE_SLOT_COUNT, window->new_width, window->new_height, DXGI_FORMAT_R8G8B8A8_UNORM, 0)); -#endif - setupSwapChain(window); - window->width = window->new_width; - window->height = window->new_height; - window->current_backbuffer = 0; - } + window->current_backbuffer = (window->current_backbuffer + 1) % KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT; const UINT64 fenceValue = window->current_fence_value; commandQueue->Signal(window->frame_fences[window->current_backbuffer], fenceValue); window->fence_values[window->current_backbuffer] = fenceValue; ++window->current_fence_value; -#ifdef KORE_WINDOWSAPP +#ifdef KINC_WINDOWSAPP context->OMSetRenderTargets(1, &renderTargetView, depthStencilView); #endif waitForFence(window->frame_fences[window->current_backbuffer], window->fence_values[window->current_backbuffer], window->frame_fence_events[window->current_backbuffer]); + if (window->new_width != window->width || window->new_height != window->height) { +#ifndef KINC_DIRECT3D_HAS_NO_SWAPCHAIN + kinc_microsoft_affirm(window->swapChain->ResizeBuffers(0, window->new_width, window->new_height, DXGI_FORMAT_R8G8B8A8_UNORM, 0)); +#endif + setupSwapChain(window); + window->width = window->new_width; + window->height = window->new_height; + window->current_backbuffer = 0; + } + // static const float clearColor[] = {0.042f, 0.042f, 0.042f, 1}; // commandList->ClearRenderTargetView(GetCPUDescriptorHandle(renderTargetDescriptorHeap), clearColor, 0, nullptr); @@ -572,7 +583,7 @@ extern "C" void kinc_internal_resize(int windowId, int width, int height) { extern "C" void kinc_internal_change_framebuffer(int window, kinc_framebuffer_options_t *frame) {} -#ifndef KORE_DIRECT3D_HAS_NO_SWAPCHAIN +#ifndef KINC_DIRECT3D_HAS_NO_SWAPCHAIN bool kinc_g5_swap_buffers() { for (int i = 0; i < MAXIMUM_WINDOWS; i++) { struct dx_window *window = &dx_ctx.windows[i]; diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/ShaderHash.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/ShaderHash.c.h index c1114a1..bfbd458 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/ShaderHash.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/ShaderHash.c.h @@ -4,7 +4,7 @@ uint32_t kinc_internal_hash_name(unsigned char *str) { unsigned long hash = 5381; int c; - while (c = *str++) { + while ((c = *str++)) { hash = hash * 33 ^ c; } return hash; diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/commandlist.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/commandlist.c.h index 163e2cc..f8750e6 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/commandlist.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/commandlist.c.h @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -54,6 +55,8 @@ void kinc_g5_internal_reset_textures(struct kinc_g5_command_list *list); void kinc_g5_command_list_begin(struct kinc_g5_command_list *list) { assert(!list->impl.open); + compute_pipeline_set = false; + if (list->impl.fence_value > 0) { waitForFence(list->impl.fence, list->impl.fence_value, list->impl.fence_event); list->impl._commandAllocator->Reset(); @@ -158,7 +161,7 @@ void kinc_g5_command_list_render_target_to_texture_barrier(struct kinc_g5_comman void kinc_g5_command_list_set_vertex_constant_buffer(struct kinc_g5_command_list *list, kinc_g5_constant_buffer_t *buffer, int offset, size_t size) { assert(list->impl.open); -#ifdef KORE_DXC +#ifdef KINC_DXC if (list->impl._currentPipeline->impl.vertexConstantsSize > 0) { if (list->impl._currentPipeline->impl.textures > 0) { list->impl._commandList->SetGraphicsRootConstantBufferView(2, buffer->impl.constant_buffer->GetGPUVirtualAddress() + offset); @@ -174,8 +177,7 @@ void kinc_g5_command_list_set_vertex_constant_buffer(struct kinc_g5_command_list void kinc_g5_command_list_set_fragment_constant_buffer(struct kinc_g5_command_list *list, kinc_g5_constant_buffer_t *buffer, int offset, size_t size) { assert(list->impl.open); - -#ifdef KORE_DXC +#ifdef KINC_DXC if (list->impl._currentPipeline->impl.fragmentConstantsSize > 0) { list->impl._commandList->SetGraphicsRootConstantBufferView(3, buffer->impl.constant_buffer->GetGPUVirtualAddress() + offset); } @@ -184,6 +186,18 @@ void kinc_g5_command_list_set_fragment_constant_buffer(struct kinc_g5_command_li #endif } +void kinc_g5_command_list_set_compute_constant_buffer(struct kinc_g5_command_list *list, kinc_g5_constant_buffer_t *buffer, int offset, size_t size) { + assert(list->impl.open); + +#ifdef KINC_DXC + if (list->impl._currentPipeline->impl.fragmentConstantsSize > 0) { + list->impl._commandList->SetGraphicsRootConstantBufferView(3, buffer->impl.constant_buffer->GetGPUVirtualAddress() + offset); + } +#else + list->impl._commandList->SetComputeRootConstantBufferView(3, buffer->impl.constant_buffer->GetGPUVirtualAddress() + offset); +#endif +} + void kinc_g5_command_list_draw_indexed_vertices(struct kinc_g5_command_list *list) { kinc_g5_command_list_draw_indexed_vertices_from_to(list, 0, list->impl._indexCount); } @@ -297,10 +311,8 @@ void kinc_g5_command_list_set_pipeline(struct kinc_g5_command_list *list, kinc_g list->impl._currentPipeline = pipeline; list->impl._commandList->SetPipelineState(pipeline->impl.pso); - for (int i = 0; i < KINC_INTERNAL_G5_TEXTURE_COUNT; ++i) { - list->impl.currentRenderTargets[i] = NULL; - list->impl.currentTextures[i] = NULL; - } + compute_pipeline_set = false; + kinc_g5_internal_setConstants(list, list->impl._currentPipeline); } @@ -378,7 +390,7 @@ void kinc_g5_command_list_upload_texture(kinc_g5_command_list_t *list, kinc_g5_t } D3D12_RESOURCE_DESC Desc = texture->impl.image->GetDesc(); - ID3D12Device *device; + ID3D12Device *device = NULL; texture->impl.image->GetDevice(IID_GRAPHICS_PPV_ARGS(&device)); D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint; device->GetCopyableFootprints(&Desc, 0, 1, 0, &footprint, NULL, NULL, NULL); @@ -409,7 +421,7 @@ void kinc_g5_command_list_upload_texture(kinc_g5_command_list_t *list, kinc_g5_t } } -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) static int d3d12_textureAlignment() { return D3D12_TEXTURE_DATA_PITCH_ALIGNMENT; } @@ -507,6 +519,19 @@ void kinc_g5_command_list_get_render_target_pixels(kinc_g5_command_list_t *list, render_target->impl.renderTargetReadback->Unmap(0, NULL); } +void kinc_g5_internal_set_compute_constants(kinc_g5_command_list_t *commandList); + +void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_g5_compute_shader *shader) { + list->impl._commandList->SetPipelineState(shader->impl.pso); + compute_pipeline_set = true; + + for (int i = 0; i < KINC_INTERNAL_G5_TEXTURE_COUNT; ++i) { + list->impl.currentRenderTargets[i] = NULL; + list->impl.currentTextures[i] = NULL; + } + kinc_g5_internal_set_compute_constants(list); +} + void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) { assert(list->impl.open); list->impl._commandList->Dispatch(x, y, z); @@ -521,6 +546,9 @@ void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_text else if (unit.stages[KINC_G5_SHADER_TYPE_VERTEX] >= 0) { kinc_g5_internal_texture_set(list, texture, unit.stages[KINC_G5_SHADER_TYPE_VERTEX]); } + else if (unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] >= 0) { + kinc_g5_internal_texture_set(list, texture, unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]); + } kinc_g5_internal_set_textures(list); } @@ -540,7 +568,18 @@ bool kinc_g5_command_list_init_occlusion_query(kinc_g5_command_list_t *list, uns return false; } -void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) {} +void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { + if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { + kinc_g5_internal_texture_set(list, texture, unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]); + } + else if (unit.stages[KINC_G5_SHADER_TYPE_VERTEX] >= 0) { + kinc_g5_internal_texture_set(list, texture, unit.stages[KINC_G5_SHADER_TYPE_VERTEX]); + } + else if (unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] >= 0) { + kinc_g5_internal_texture_set(list, texture, unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]); + } + kinc_g5_internal_set_textures(list); +} void kinc_g5_command_list_delete_occlusion_query(kinc_g5_command_list_t *list, unsigned occlusionQuery) {} diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/compute.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/compute.c.h index 5990583..a92d7c8 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/compute.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/compute.c.h @@ -1,130 +1,12 @@ -#include +#include -#include #include #include #include #include -static uint8_t constantsMemory[1024 * 4]; - -static int getMultipleOf16(int value) { - int ret = 16; - while (ret < value) - ret += 16; - return ret; -} - -static void setInt(uint8_t *constants, uint32_t offset, uint32_t size, int value) { - if (size == 0) - return; - int *ints = (int *)&constants[offset]; - ints[0] = value; -} - -static void setFloat(uint8_t *constants, uint32_t offset, uint32_t size, float value) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value; -} - -static void setFloat2(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; -} - -static void setFloat3(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2, float value3) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; - floats[2] = value3; -} - -static void setFloat4(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2, float value3, float value4) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; - floats[2] = value3; - floats[3] = value4; -} - -static void setFloats(uint8_t *constants, uint32_t offset, uint32_t size, uint8_t columns, uint8_t rows, float *values, int count) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - if (columns == 4 && rows == 4) { - for (int i = 0; i < count / 16 && i < (int)size / 4; ++i) { - for (int y = 0; y < 4; ++y) { - for (int x = 0; x < 4; ++x) { - floats[i * 16 + x + y * 4] = values[i * 16 + y + x * 4]; - } - } - } - } - else if (columns == 3 && rows == 3) { - for (int i = 0; i < count / 9 && i < (int)size / 3; ++i) { - for (int y = 0; y < 4; ++y) { - for (int x = 0; x < 4; ++x) { - floats[i * 12 + x + y * 4] = values[i * 9 + y + x * 3]; - } - } - } - } - else if (columns == 2 && rows == 2) { - for (int i = 0; i < count / 4 && i < (int)size / 2; ++i) { - for (int y = 0; y < 4; ++y) { - for (int x = 0; x < 4; ++x) { - floats[i * 8 + x + y * 4] = values[i * 4 + y + x * 2]; - } - } - } - } - else { - for (int i = 0; i < count && i * 4 < (int)size; ++i) { - floats[i] = values[i]; - } - } -} - -static void setBool(uint8_t *constants, uint32_t offset, uint32_t size, bool value) { - if (size == 0) - return; - int *ints = (int *)&constants[offset]; - ints[0] = value ? 1 : 0; -} - -static void setMatrix4(uint8_t *constants, uint32_t offset, uint32_t size, kinc_matrix4x4_t *value) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - for (int y = 0; y < 4; ++y) { - for (int x = 0; x < 4; ++x) { - floats[x + y * 4] = kinc_matrix4x4_get(value, y, x); - } - } -} - -static void setMatrix3(uint8_t *constants, uint32_t offset, uint32_t size, kinc_matrix3x3_t *value) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - for (int y = 0; y < 3; ++y) { - for (int x = 0; x < 3; ++x) { - floats[x + y * 4] = kinc_matrix3x3_get(value, y, x); - } - } -} - -void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int length) { +void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *_data, int length) { unsigned index = 0; uint8_t *data = (uint8_t *)_data; @@ -166,9 +48,9 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le } kinc_compute_internal_shader_constant_t constant; constant.hash = kinc_internal_hash_name(name); - constant.offset = *(uint32_t *)&data[index]; + memcpy(&constant.offset, &data[index], sizeof(constant.offset)); index += 4; - constant.size = *(uint32_t *)&data[index]; + memcpy(&constant.size, &data[index], sizeof(constant.size)); index += 4; constant.columns = data[index]; index += 1; @@ -187,6 +69,7 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le D3D12_COMPUTE_PIPELINE_STATE_DESC desc = {0}; desc.CS.BytecodeLength = shader->impl.length; desc.CS.pShaderBytecode = shader->impl.data; + desc.pRootSignature = globalComputeRootSignature; HRESULT hr = device->CreateComputePipelineState(&desc, IID_GRAPHICS_PPV_ARGS(&shader->impl.pso)); if (hr != S_OK) { @@ -198,7 +81,12 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le // &shader->impl.constantBuffer)); } -void kinc_compute_shader_destroy(kinc_compute_shader_t *shader) {} +void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader) { + if (shader->impl.pso != NULL) { + shader->impl.pso->Release(); + shader->impl.pso = NULL; + } +} static kinc_compute_internal_shader_constant_t *findComputeConstant(kinc_compute_internal_shader_constant_t *constants, uint32_t hash) { for (int i = 0; i < 64; ++i) { @@ -218,33 +106,29 @@ static kinc_internal_hash_index_t *findComputeTextureUnit(kinc_internal_hash_ind return NULL; } -kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_constant_location_t location; +kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_location(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_constant_location_t location = {0}; uint32_t hash = kinc_internal_hash_name((unsigned char *)name); kinc_compute_internal_shader_constant_t *constant = findComputeConstant(shader->impl.constants, hash); if (constant == NULL) { - location.impl.offset = 0; - location.impl.size = 0; - location.impl.columns = 0; - location.impl.rows = 0; + location.impl.computeOffset = 0; + location.impl.computeSize = 0; } else { - location.impl.offset = constant->offset; - location.impl.size = constant->size; - location.impl.columns = constant->columns; - location.impl.rows = constant->rows; + location.impl.computeOffset = constant->offset; + location.impl.computeSize = constant->size; } - if (location.impl.size == 0) { + if (location.impl.computeSize == 0) { kinc_log(KINC_LOG_LEVEL_WARNING, "Uniform %s not found.", name); } return location; } -kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name) { +kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_shader *shader, const char *name) { char unitName[64]; int unitOffset = 0; size_t len = strlen(name); @@ -258,10 +142,12 @@ kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_sh uint32_t hash = kinc_internal_hash_name((unsigned char *)unitName); - kinc_compute_texture_unit_t unit; - kinc_internal_hash_index_t *vertexUnit = findComputeTextureUnit(shader->impl.textures, hash); - if (vertexUnit == NULL) { - unit.impl.unit = -1; + kinc_g5_texture_unit_t unit; + for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) { + unit.stages[i] = -1; + } + kinc_internal_hash_index_t *computeUnit = findComputeTextureUnit(shader->impl.textures, hash); + if (computeUnit == NULL) { #ifndef NDEBUG static int notFoundCount = 0; if (notFoundCount < 10) { @@ -275,90 +161,7 @@ kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_sh #endif } else { - unit.impl.unit = vertexUnit->index + unitOffset; + unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] = computeUnit->index + unitOffset; } return unit; } - -void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value) { - setBool(constantsMemory, location.impl.offset, location.impl.size, value); -} - -void kinc_compute_set_int(kinc_compute_constant_location_t location, int value) { - setInt(constantsMemory, location.impl.offset, location.impl.size, value); -} - -void kinc_compute_set_float(kinc_compute_constant_location_t location, float value) { - setFloat(constantsMemory, location.impl.offset, location.impl.size, value); -} - -void kinc_compute_set_float2(kinc_compute_constant_location_t location, float value1, float value2) { - setFloat2(constantsMemory, location.impl.offset, location.impl.size, value1, value2); -} - -void kinc_compute_set_float3(kinc_compute_constant_location_t location, float value1, float value2, float value3) { - setFloat3(constantsMemory, location.impl.offset, location.impl.size, value1, value2, value3); -} - -void kinc_compute_set_float4(kinc_compute_constant_location_t location, float value1, float value2, float value3, float value4) { - setFloat4(constantsMemory, location.impl.offset, location.impl.size, value1, value2, value3, value4); -} - -void kinc_compute_set_floats(kinc_compute_constant_location_t location, float *values, int count) { - setFloats(constantsMemory, location.impl.offset, location.impl.size, location.impl.columns, location.impl.rows, values, count); -} - -void kinc_compute_set_matrix4(kinc_compute_constant_location_t location, kinc_matrix4x4_t *value) { - setMatrix4(constantsMemory, location.impl.offset, location.impl.size, value); -} - -void kinc_compute_set_matrix3(kinc_compute_constant_location_t location, kinc_matrix3x3_t *value) { - setMatrix3(constantsMemory, location.impl.offset, location.impl.size, value); -} - -void kinc_compute_set_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture, kinc_compute_access_t access) { - // ID3D12ShaderResourceView *nullView = nullptr; - // context->PSSetShaderResources(0, 1, &nullView); - - // context->CSSetUnorderedAccessViews(unit.impl.unit, 1, &texture->impl.computeView, nullptr); -} - -void kinc_compute_set_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *texture, kinc_compute_access_t access) {} - -void kinc_compute_set_sampled_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture) {} - -void kinc_compute_set_sampled_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target) {} - -void kinc_compute_set_sampled_depth_from_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target) {} - -void kinc_compute_set_texture_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} - -void kinc_compute_set_texture_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} - -void kinc_compute_set_texture3d_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} - -void kinc_compute_set_texture3d_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} - -void kinc_compute_set_shader(kinc_compute_shader_t *shader) { - ID3D12GraphicsCommandList *command_list = NULL; - command_list->SetPipelineState(shader->impl.pso); - - // context->UpdateSubresource(shader->impl.constantBuffer, 0, nullptr, constantsMemory, 0, 0); - // context->CSSetConstantBuffers(0, 1, &shader->impl.constantBuffer); -} - -void kinc_compute(int x, int y, int z) { - ID3D12GraphicsCommandList *command_list = NULL; - // context->Dispatch(x, y, z); - - // ID3D11UnorderedAccessView *nullView = nullptr; - // context->CSSetUnorderedAccessViews(0, 1, &nullView, nullptr); -} diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/compute.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/compute.h similarity index 65% rename from Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/compute.h rename to Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/compute.h index c921f57..8e3f1e2 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/compute.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/compute.h @@ -6,20 +6,6 @@ extern "C" { #endif -struct ID3D12Buffer; -struct ID3D12PipelineState; - -typedef struct { - uint32_t offset; - uint32_t size; - uint8_t columns; - uint8_t rows; -} kinc_compute_constant_location_impl_t; - -typedef struct { - int unit; -} kinc_compute_texture_unit_impl_t; - typedef struct { uint32_t hash; uint32_t offset; @@ -28,7 +14,7 @@ typedef struct { uint8_t rows; } kinc_compute_internal_shader_constant_t; -typedef struct { +typedef struct kinc_g5_compute_shader_impl { kinc_compute_internal_shader_constant_t constants[64]; int constantsSize; kinc_internal_hash_index_t attributes[64]; @@ -37,7 +23,7 @@ typedef struct { int length; struct ID3D12Buffer *constantBuffer; struct ID3D12PipelineState *pso; -} kinc_compute_shader_impl_t; +} kinc_g5_compute_shader_impl; #ifdef __cplusplus } diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/constantbuffer.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/constantbuffer.c.h index 9c0654e..5b16ba7 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/constantbuffer.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/constantbuffer.c.h @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12mini.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12mini.h index 6014838..91f229a 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12mini.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12mini.h @@ -32,16 +32,16 @@ struct D3D12Rect { long bottom; }; -#define QUEUE_SLOT_COUNT 2 +#define KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT 2 struct dx_window { -#ifndef KORE_DIRECT3D_HAS_NO_SWAPCHAIN +#ifndef KINC_DIRECT3D_HAS_NO_SWAPCHAIN struct IDXGISwapChain *swapChain; #endif UINT64 current_fence_value; - UINT64 fence_values[QUEUE_SLOT_COUNT]; - HANDLE frame_fence_events[QUEUE_SLOT_COUNT]; - struct ID3D12Fence *frame_fences[QUEUE_SLOT_COUNT]; + UINT64 fence_values[KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT]; + HANDLE frame_fence_events[KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT]; + struct ID3D12Fence *frame_fences[KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT]; int width; int height; int new_width; @@ -51,6 +51,8 @@ struct dx_window { int window_index; }; +struct dx_window *kinc_dx_current_window(); + #ifdef __cplusplus } #endif diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12unit.cpp b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12unit.cpp index acb67bb..cb90ce7 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12unit.cpp +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12unit.cpp @@ -2,6 +2,9 @@ // Windows 7 #define WINVER 0x0601 +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif #define _WIN32_WINNT 0x0601 #define NOATOM @@ -43,12 +46,12 @@ #define NOWINSTYLES #define WIN32_LEAN_AND_MEAN -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #else #include #endif -#ifdef KORE_DIRECT3D_HAS_NO_SWAPCHAIN +#ifdef KINC_DIRECT3D_HAS_NO_SWAPCHAIN struct DXGI_SWAP_CHAIN_DESC1; #else #include @@ -78,10 +81,12 @@ struct dx_ctx { static struct dx_ctx dx_ctx = {0}; -inline struct dx_window *kinc_dx_current_window() { +struct dx_window *kinc_dx_current_window() { return &dx_ctx.windows[dx_ctx.current_window]; } +static bool compute_pipeline_set = false; + #include #include #include @@ -98,4 +103,4 @@ inline struct dx_window *kinc_dx_current_window() { #include "sampler.c.h" #include "shader.c.h" #include "texture.c.h" -#include "vertexbuffer.c.h" \ No newline at end of file +#include "vertexbuffer.c.h" diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/indexbuffer.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/indexbuffer.c.h index 8438590..07c2262 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/indexbuffer.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/indexbuffer.c.h @@ -58,8 +58,13 @@ void kinc_g5_index_buffer_init(kinc_g5_index_buffer_t *buffer, int count, kinc_g } void kinc_g5_index_buffer_destroy(kinc_g5_index_buffer_t *buffer) { - buffer->impl.index_buffer->Release(); + if (buffer->impl.index_buffer != NULL) { + buffer->impl.index_buffer->Release(); + buffer->impl.index_buffer = NULL; + } + buffer->impl.upload_buffer->Release(); + buffer->impl.upload_buffer = NULL; } static int kinc_g5_internal_index_buffer_stride(kinc_g5_index_buffer_t *buffer) { diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/pipeline.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/pipeline.c.h index 5016786..e375fa0 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/pipeline.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/pipeline.c.h @@ -30,8 +30,7 @@ void kinc_g5_internal_setConstants(kinc_g5_command_list_t *commandList, kinc_g5_ } */ - commandList->impl._commandList->SetPipelineState(pipeline->impl.pso); -#ifdef KORE_DXC +#ifdef KINC_DXC // commandList->SetGraphicsRootSignature(pipeline->impl.rootSignature); commandList->impl._commandList->SetGraphicsRootSignature(globalRootSignature); #else @@ -43,6 +42,36 @@ void kinc_g5_internal_setConstants(kinc_g5_command_list_t *commandList, kinc_g5_ } } +void kinc_g5_internal_set_compute_constants(kinc_g5_command_list_t *commandList) { + /*if (currentProgram->vertexShader->constantsSize > 0) { + context->UpdateSubresource(currentProgram->vertexConstantBuffer, 0, nullptr, vertexConstants, 0, 0); + context->VSSetConstantBuffers(0, 1, ¤tProgram->vertexConstantBuffer); + } + if (currentProgram->fragmentShader->constantsSize > 0) { + context->UpdateSubresource(currentProgram->fragmentConstantBuffer, 0, nullptr, fragmentConstants, 0, 0); + context->PSSetConstantBuffers(0, 1, ¤tProgram->fragmentConstantBuffer); + } + if (currentProgram->geometryShader != nullptr && currentProgram->geometryShader->constantsSize > 0) { + context->UpdateSubresource(currentProgram->geometryConstantBuffer, 0, nullptr, geometryConstants, 0, 0); + context->GSSetConstantBuffers(0, 1, ¤tProgram->geometryConstantBuffer); + } + if (currentProgram->tessControlShader != nullptr && currentProgram->tessControlShader->constantsSize > 0) { + context->UpdateSubresource(currentProgram->tessControlConstantBuffer, 0, nullptr, tessControlConstants, 0, 0); + context->HSSetConstantBuffers(0, 1, ¤tProgram->tessControlConstantBuffer); + } + if (currentProgram->tessEvalShader != nullptr && currentProgram->tessEvalShader->constantsSize > 0) { + context->UpdateSubresource(currentProgram->tessEvalConstantBuffer, 0, nullptr, tessEvalConstants, 0, 0); + context->DSSetConstantBuffers(0, 1, ¤tProgram->tessEvalConstantBuffer); + } + */ + + commandList->impl._commandList->SetComputeRootSignature(globalComputeRootSignature); + + // if (pipeline->impl.textures > 0) { + kinc_g5_internal_set_textures(commandList); + //} +} + void kinc_g5_pipeline_init(kinc_g5_pipeline_t *pipe) { kinc_g5_internal_pipeline_init(pipe); } @@ -264,7 +293,7 @@ static DXGI_FORMAT convert_format(kinc_g5_render_target_format_t format) { return DXGI_FORMAT_R8_UNORM; case KINC_G5_RENDER_TARGET_FORMAT_32BIT: default: -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS return DXGI_FORMAT_R8G8B8A8_UNORM; #else return DXGI_FORMAT_B8G8R8A8_UNORM; @@ -302,11 +331,7 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) { for (int stream = 0; pipe->inputLayout[stream] != NULL; ++stream) { for (int i = 0; i < pipe->inputLayout[stream]->size; ++i) { vertexDesc[curAttr].SemanticName = "TEXCOORD"; -#ifdef KINC_KONG - vertexDesc[curAttr].SemanticIndex = i; -#else vertexDesc[curAttr].SemanticIndex = findAttribute(pipe->vertexShader, pipe->inputLayout[stream]->elements[i].name).attribute; -#endif vertexDesc[curAttr].InputSlot = stream; vertexDesc[curAttr].AlignedByteOffset = (i == 0) ? 0 : D3D12_APPEND_ALIGNED_ELEMENT; vertexDesc[curAttr].InputSlotClass = @@ -422,13 +447,15 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) { case KINC_G4_VERTEX_DATA_U32_4X: vertexDesc[curAttr].Format = DXGI_FORMAT_R32G32B32A32_UINT; break; + default: + break; } curAttr++; } } HRESULT hr = S_OK; -#ifdef KORE_DXC +#ifdef KINC_DXC // hr = device->CreateRootSignature(0, pipe->vertexShader->impl.data, pipe->vertexShader->impl.length, IID_GRAPHICS_PPV_ARGS(&pipe->impl.rootSignature)); if (hr != S_OK) { kinc_log(KINC_LOG_LEVEL_WARNING, "Could not create root signature."); @@ -444,7 +471,7 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) { psoDesc.VS.pShaderBytecode = pipe->vertexShader->impl.data; psoDesc.PS.BytecodeLength = pipe->fragmentShader->impl.length; psoDesc.PS.pShaderBytecode = pipe->fragmentShader->impl.data; -#ifdef KORE_DXC +#ifdef KINC_DXC // psoDesc.pRootSignature = pipe->impl.rootSignature; psoDesc.pRootSignature = globalRootSignature; #else @@ -530,62 +557,3 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) { kinc_log(KINC_LOG_LEVEL_WARNING, "Could not create pipeline."); } } - -void kinc_g5_compute_pipeline_init(kinc_g5_compute_pipeline_t *pipeline) { - kinc_g5_internal_compute_pipeline_init(pipeline); - pipeline->impl.pso = NULL; -} - -void kinc_g5_compute_pipeline_destroy(kinc_g5_compute_pipeline_t *pipeline) { - if (pipeline->impl.pso != NULL) { - pipeline->impl.pso->Release(); - pipeline->impl.pso = NULL; - } -} - -void kinc_g5_compute_pipeline_compile(kinc_g5_compute_pipeline_t *pipeline) { - HRESULT hr; -#ifdef KORE_DXC - /*hr = device->CreateRootSignature(0, pipe->vertexShader->impl.data, pipe->vertexShader->impl.length, IID_GRAPHICS_PPV_ARGS(&pipe->impl.rootSignature)); - if (hr != S_OK) { - kinc_log(KINC_LOG_LEVEL_WARNING, "Could not create root signature."); - } - pipe->impl.vertexConstantsSize = pipe->vertexShader->impl.constantsSize; - pipe->impl.fragmentConstantsSize = pipe->fragmentShader->impl.constantsSize;*/ -#endif - - D3D12_COMPUTE_PIPELINE_STATE_DESC psoDesc = {0}; - psoDesc.CS.BytecodeLength = pipeline->compute_shader->impl.length; - psoDesc.CS.pShaderBytecode = pipeline->compute_shader->impl.data; -#ifdef KORE_DXC - // psoDesc.pRootSignature = pipe->impl.rootSignature; -#else - psoDesc.pRootSignature = globalComputeRootSignature; -#endif - - hr = device->CreateComputePipelineState(&psoDesc, IID_GRAPHICS_PPV_ARGS(&pipeline->impl.pso)); - if (hr != S_OK) { - kinc_log(KINC_LOG_LEVEL_WARNING, "Could not create pipeline."); - } -} - -kinc_g5_constant_location_t kinc_g5_compute_pipeline_get_constant_location(kinc_g5_compute_pipeline_t *pipeline, const char *name) { - kinc_g5_constant_location_t location = {0}; - - { - ShaderConstant constant = findConstant(pipeline->compute_shader, name); - location.impl.computeOffset = constant.offset; - location.impl.computeSize = constant.size; - } - - return location; -} - -kinc_g5_texture_unit_t kinc_g5_compute_pipeline_get_texture_unit(kinc_g5_compute_pipeline_t *pipeline, const char *name) { - kinc_g5_texture_unit_t unit; - ShaderTexture texture = findTexture(pipeline->compute_shader, name); - if (texture.texture != -1) { - unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] = texture.texture; - } - return unit; -} diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/pipeline.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/pipeline.h index 4d012d5..1fbea86 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/pipeline.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/pipeline.h @@ -14,7 +14,7 @@ struct ID3D12RootSignature; typedef struct { struct ID3D12PipelineState *pso; -#ifdef KORE_DXC +#ifdef KINC_DXC // struct ID3D12RootSignature *rootSignature; int vertexConstantsSize; int fragmentConstantsSize; @@ -32,7 +32,7 @@ typedef struct { typedef struct { struct ID3D12PipelineState *pso; -#ifdef KORE_DXC +#ifdef KINC_DXC struct ID3D12RootSignature *rootSignature; int vertexConstantsSize; int fragmentConstantsSize; @@ -68,6 +68,7 @@ typedef struct { } AttributeLocation5Impl; struct kinc_g5_pipeline; +struct kinc_g5_command_list; void kinc_g5_internal_setConstants(struct kinc_g5_command_list *commandList, struct kinc_g5_pipeline *pipeline); diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/raytrace.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/raytrace.c.h index 26252a8..31f2f3e 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/raytrace.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/raytrace.c.h @@ -1,4 +1,4 @@ -#ifndef KORE_XBOX_ONE +#ifndef KINC_XBOX_ONE #include @@ -26,7 +26,8 @@ void kinc_raytrace_pipeline_init(kinc_raytrace_pipeline_t *pipeline, kinc_g5_com kinc_g5_constant_buffer_t *constant_buffer) { pipeline->_constant_buffer = constant_buffer; // Descriptor heap - D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = {0}; + D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc; + ZeroMemory(&descriptorHeapDesc, sizeof(descriptorHeapDesc)); // Allocate a heap for 3 descriptors: // 2 - bottom and top level acceleration structure // 1 - raytracing output texture SRV @@ -72,7 +73,8 @@ void kinc_raytrace_pipeline_init(kinc_raytrace_pipeline_t *pipeline, kinc_g5_com device->CreateRootSignature(1, blob->GetBufferPointer(), blob->GetBufferSize(), IID_GRAPHICS_PPV_ARGS(&dxrRootSignature)); // Pipeline - D3D12_STATE_OBJECT_DESC raytracingPipeline = {0}; + D3D12_STATE_OBJECT_DESC raytracingPipeline; + ZeroMemory(&raytracingPipeline, sizeof(raytracingPipeline)); raytracingPipeline.Type = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE; D3D12_SHADER_BYTECODE shaderBytecode = {0}; @@ -130,7 +132,8 @@ void kinc_raytrace_pipeline_init(kinc_raytrace_pipeline_t *pipeline, kinc_g5_com { UINT size = shaderIdSize + constant_buffer->impl.mySize; UINT shaderRecordSize = (size + (align - 1)) & ~(align - 1); - D3D12_RESOURCE_DESC bufferDesc = {0}; + D3D12_RESOURCE_DESC bufferDesc; + ZeroMemory(&bufferDesc, sizeof(bufferDesc)); bufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; bufferDesc.Width = shaderRecordSize; bufferDesc.Height = 1; @@ -140,7 +143,8 @@ void kinc_raytrace_pipeline_init(kinc_raytrace_pipeline_t *pipeline, kinc_g5_com bufferDesc.SampleDesc.Count = 1; bufferDesc.SampleDesc.Quality = 0; bufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; - D3D12_HEAP_PROPERTIES uploadHeapProperties = {0}; + D3D12_HEAP_PROPERTIES uploadHeapProperties; + ZeroMemory(&uploadHeapProperties, sizeof(uploadHeapProperties)); uploadHeapProperties.Type = D3D12_HEAP_TYPE_UPLOAD; uploadHeapProperties.CreationNodeMask = 1; uploadHeapProperties.VisibleNodeMask = 1; @@ -168,7 +172,8 @@ void kinc_raytrace_pipeline_init(kinc_raytrace_pipeline_t *pipeline, kinc_g5_com { UINT size = shaderIdSize; UINT shaderRecordSize = (size + (align - 1)) & ~(align - 1); - D3D12_RESOURCE_DESC bufferDesc = {0}; + D3D12_RESOURCE_DESC bufferDesc; + ZeroMemory(&bufferDesc, sizeof(bufferDesc)); bufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; bufferDesc.Width = shaderRecordSize; bufferDesc.Height = 1; @@ -178,7 +183,8 @@ void kinc_raytrace_pipeline_init(kinc_raytrace_pipeline_t *pipeline, kinc_g5_com bufferDesc.SampleDesc.Count = 1; bufferDesc.SampleDesc.Quality = 0; bufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; - D3D12_HEAP_PROPERTIES uploadHeapProperties = {0}; + D3D12_HEAP_PROPERTIES uploadHeapProperties; + ZeroMemory(&uploadHeapProperties, sizeof(uploadHeapProperties)); uploadHeapProperties.Type = D3D12_HEAP_TYPE_UPLOAD; uploadHeapProperties.CreationNodeMask = 1; uploadHeapProperties.VisibleNodeMask = 1; @@ -199,7 +205,8 @@ void kinc_raytrace_pipeline_init(kinc_raytrace_pipeline_t *pipeline, kinc_g5_com { UINT size = shaderIdSize; UINT shaderRecordSize = (size + (align - 1)) & ~(align - 1); - D3D12_RESOURCE_DESC bufferDesc = {0}; + D3D12_RESOURCE_DESC bufferDesc; + ZeroMemory(&bufferDesc, sizeof(bufferDesc)); bufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; bufferDesc.Width = shaderRecordSize; bufferDesc.Height = 1; @@ -209,7 +216,8 @@ void kinc_raytrace_pipeline_init(kinc_raytrace_pipeline_t *pipeline, kinc_g5_com bufferDesc.SampleDesc.Count = 1; bufferDesc.SampleDesc.Quality = 0; bufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; - D3D12_HEAP_PROPERTIES uploadHeapProperties = {0}; + D3D12_HEAP_PROPERTIES uploadHeapProperties; + ZeroMemory(&uploadHeapProperties, sizeof(uploadHeapProperties)); uploadHeapProperties.Type = D3D12_HEAP_TYPE_UPLOAD; uploadHeapProperties.CreationNodeMask = 1; uploadHeapProperties.VisibleNodeMask = 1; @@ -272,7 +280,8 @@ void kinc_raytrace_acceleration_structure_init(kinc_raytrace_acceleration_struct { UINT64 tlSize = topLevelPrebuildInfo.ScratchDataSizeInBytes; UINT64 blSize = bottomLevelPrebuildInfo.ScratchDataSizeInBytes; - D3D12_RESOURCE_DESC bufferDesc = {0}; + D3D12_RESOURCE_DESC bufferDesc; + ZeroMemory(&bufferDesc, sizeof(bufferDesc)); bufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; bufferDesc.Width = tlSize > blSize ? tlSize : blSize; bufferDesc.Height = 1; @@ -283,7 +292,8 @@ void kinc_raytrace_acceleration_structure_init(kinc_raytrace_acceleration_struct bufferDesc.SampleDesc.Quality = 0; bufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; bufferDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; - D3D12_HEAP_PROPERTIES uploadHeapProperties = {0}; + D3D12_HEAP_PROPERTIES uploadHeapProperties; + ZeroMemory(&uploadHeapProperties, sizeof(uploadHeapProperties)); uploadHeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT; uploadHeapProperties.CreationNodeMask = 1; uploadHeapProperties.VisibleNodeMask = 1; @@ -343,7 +353,8 @@ void kinc_raytrace_acceleration_structure_init(kinc_raytrace_acceleration_struct instanceDesc.InstanceMask = 1; instanceDesc.AccelerationStructure = accel->impl.bottom_level_accel->GetGPUVirtualAddress(); - D3D12_RESOURCE_DESC bufferDesc = {0}; + D3D12_RESOURCE_DESC bufferDesc; + ZeroMemory(&bufferDesc, sizeof(bufferDesc)); bufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; bufferDesc.Width = sizeof(instanceDesc); bufferDesc.Height = 1; diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/raytrace.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/raytrace.h index 230eac2..25ccebd 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/raytrace.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/raytrace.h @@ -8,15 +8,15 @@ struct ID3D12StateObject; struct ID3D12Resource; typedef struct { - ID3D12StateObject *dxr_state; - ID3D12Resource *raygen_shader_table; - ID3D12Resource *miss_shader_table; - ID3D12Resource *hitgroup_shader_table; + struct ID3D12StateObject *dxr_state; + struct ID3D12Resource *raygen_shader_table; + struct ID3D12Resource *miss_shader_table; + struct ID3D12Resource *hitgroup_shader_table; } kinc_raytrace_pipeline_impl_t; typedef struct { - ID3D12Resource *bottom_level_accel; - ID3D12Resource *top_level_accel; + struct ID3D12Resource *bottom_level_accel; + struct ID3D12Resource *top_level_accel; } kinc_raytrace_acceleration_structure_impl_t; #ifdef __cplusplus diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/rendertarget.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/rendertarget.c.h index 4bd68b7..10dd9c9 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/rendertarget.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/rendertarget.c.h @@ -1,15 +1,15 @@ #include "rendertarget.h" -#include -#include #include +#include +#include -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #endif -#ifdef KORE_DIRECT3D_HAS_NO_SWAPCHAIN -extern ID3D12Resource *swapChainRenderTargets[QUEUE_SLOT_COUNT]; +#ifdef KINC_DIRECT3D_HAS_NO_SWAPCHAIN +extern ID3D12Resource *swapChainRenderTargets[KINC_INTERNAL_D3D12_SWAP_CHAIN_COUNT]; #endif static void WaitForFence(ID3D12Fence *fence, UINT64 completionValue, HANDLE waitEvent) { @@ -45,7 +45,7 @@ static DXGI_FORMAT convertFormat(kinc_g5_render_target_format_t format) { return DXGI_FORMAT_R8_UNORM; case KINC_G5_RENDER_TARGET_FORMAT_32BIT: default: -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS return DXGI_FORMAT_R8G8B8A8_UNORM; #else return DXGI_FORMAT_B8G8R8A8_UNORM; @@ -93,34 +93,48 @@ static void render_target_init(kinc_g5_render_target_t *render_target, int width texResourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; texResourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; - HRESULT result = device->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &texResourceDesc, D3D12_RESOURCE_STATE_RENDER_TARGET, &clearValue, - IID_GRAPHICS_PPV_ARGS(&render_target->impl.renderTarget)); - if (result != S_OK) { - for (int i = 0; i < 10; ++i) { - kinc_memory_emergency(); - result = device->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &texResourceDesc, D3D12_RESOURCE_STATE_RENDER_TARGET, &clearValue, - IID_GRAPHICS_PPV_ARGS(&render_target->impl.renderTarget)); - if (result == S_OK) { - break; - } - } - } - - D3D12_RENDER_TARGET_VIEW_DESC view; - // const D3D12_RESOURCE_DESC resourceDesc = render_target->impl.renderTarget->lpVtbl->GetDesc(render_target->impl.renderTarget); - view.Format = dxgiFormat; - view.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; - view.Texture2D.MipSlice = 0; - view.Texture2D.PlaneSlice = 0; - D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {}; heapDesc.NumDescriptors = 1; heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; - device->CreateDescriptorHeap(&heapDesc, IID_GRAPHICS_PPV_ARGS(&render_target->impl.renderTargetDescriptorHeap)); + kinc_microsoft_affirm(device->CreateDescriptorHeap(&heapDesc, IID_GRAPHICS_PPV_ARGS(&render_target->impl.renderTargetDescriptorHeap))); - device->CreateRenderTargetView(render_target->impl.renderTarget, &view, - render_target->impl.renderTargetDescriptorHeap->GetCPUDescriptorHandleForHeapStart()); + if (framebuffer_index >= 0) { +#ifdef KINC_DIRECT3D_HAS_NO_SWAPCHAIN + render_target->impl.renderTarget = swapChainRenderTargets[framebuffer_index]; +#else + IDXGISwapChain *swapChain = kinc_dx_current_window()->swapChain; + kinc_microsoft_affirm(swapChain->GetBuffer(framebuffer_index, IID_PPV_ARGS(&render_target->impl.renderTarget))); + wchar_t buffer[128]; + wsprintf(buffer, L"Backbuffer (index %i)", framebuffer_index); + render_target->impl.renderTarget->SetName(buffer); +#endif + createRenderTargetView(render_target->impl.renderTarget, render_target->impl.renderTargetDescriptorHeap, dxgiFormat); + } + else { + HRESULT result = device->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &texResourceDesc, D3D12_RESOURCE_STATE_RENDER_TARGET, + &clearValue, IID_GRAPHICS_PPV_ARGS(&render_target->impl.renderTarget)); + if (result != S_OK) { + for (int i = 0; i < 10; ++i) { + kinc_memory_emergency(); + result = device->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &texResourceDesc, D3D12_RESOURCE_STATE_RENDER_TARGET, + &clearValue, IID_GRAPHICS_PPV_ARGS(&render_target->impl.renderTarget)); + if (result == S_OK) { + break; + } + } + } + + D3D12_RENDER_TARGET_VIEW_DESC view; + // const D3D12_RESOURCE_DESC resourceDesc = render_target->impl.renderTarget->lpVtbl->GetDesc(render_target->impl.renderTarget); + view.Format = dxgiFormat; + view.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; + view.Texture2D.MipSlice = 0; + view.Texture2D.PlaneSlice = 0; + + device->CreateRenderTargetView(render_target->impl.renderTarget, &view, + render_target->impl.renderTargetDescriptorHeap->GetCPUDescriptorHandleForHeapStart()); + } D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = {}; descriptorHeapDesc.NumDescriptors = 1; @@ -129,9 +143,10 @@ static void render_target_init(kinc_g5_render_target_t *render_target, int width descriptorHeapDesc.NodeMask = 0; descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; - device->CreateDescriptorHeap(&descriptorHeapDesc, IID_GRAPHICS_PPV_ARGS(&render_target->impl.srvDescriptorHeap)); + kinc_microsoft_affirm(device->CreateDescriptorHeap(&descriptorHeapDesc, IID_GRAPHICS_PPV_ARGS(&render_target->impl.srvDescriptorHeap))); - D3D12_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc = {0}; + D3D12_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; + ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc)); shaderResourceViewDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; shaderResourceViewDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; shaderResourceViewDesc.Format = dxgiFormat; @@ -147,7 +162,7 @@ static void render_target_init(kinc_g5_render_target_t *render_target, int width dsvHeapDesc.NumDescriptors = 1; dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV; dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; - device->CreateDescriptorHeap(&dsvHeapDesc, IID_GRAPHICS_PPV_ARGS(&render_target->impl.depthStencilDescriptorHeap)); + kinc_microsoft_affirm(device->CreateDescriptorHeap(&dsvHeapDesc, IID_GRAPHICS_PPV_ARGS(&render_target->impl.depthStencilDescriptorHeap))); D3D12_RESOURCE_DESC depthTexture; depthTexture.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; @@ -196,9 +211,10 @@ static void render_target_init(kinc_g5_render_target_t *render_target, int width srvDepthHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; srvDepthHeapDesc.NodeMask = 0; srvDepthHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; - device->CreateDescriptorHeap(&srvDepthHeapDesc, IID_GRAPHICS_PPV_ARGS(&render_target->impl.srvDepthDescriptorHeap)); + kinc_microsoft_affirm(device->CreateDescriptorHeap(&srvDepthHeapDesc, IID_GRAPHICS_PPV_ARGS(&render_target->impl.srvDepthDescriptorHeap))); - D3D12_SHADER_RESOURCE_VIEW_DESC srvDepthViewDesc = {0}; + D3D12_SHADER_RESOURCE_VIEW_DESC srvDepthViewDesc; + ZeroMemory(&srvDepthViewDesc, sizeof(srvDepthViewDesc)); srvDepthViewDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; srvDepthViewDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; srvDepthViewDesc.Format = DXGI_FORMAT_R32_FLOAT; @@ -225,19 +241,6 @@ static void render_target_init(kinc_g5_render_target_t *render_target, int width render_target->impl.viewport.Height = (float)height; render_target->impl.viewport.MinDepth = 0.0f; render_target->impl.viewport.MaxDepth = 1.0f; - - if (framebuffer_index >= 0) { -#ifdef KORE_DIRECT3D_HAS_NO_SWAPCHAIN - render_target->impl.renderTarget = swapChainRenderTargets[framebuffer_index]; -#else - IDXGISwapChain *swapChain = kinc_dx_current_window()->swapChain; - swapChain->GetBuffer(framebuffer_index, IID_PPV_ARGS(&render_target->impl.renderTarget)); - wchar_t buffer[128]; - wsprintf(buffer, L"Backbuffer (index %i)", framebuffer_index); - render_target->impl.renderTarget->SetName(buffer); -#endif - createRenderTargetView(render_target->impl.renderTarget, render_target->impl.renderTargetDescriptorHeap, dxgiFormat); - } } void kinc_g5_render_target_init_with_multisampling(kinc_g5_render_target_t *target, int width, int height, kinc_g5_render_target_format_t format, diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/shader.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/shader.c.h index a7c83b2..d585614 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/shader.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/shader.c.h @@ -10,7 +10,6 @@ void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *_data, size_t len unsigned index = 0; uint8_t *data = (uint8_t *)_data; -#ifndef KINC_KONG int attributesCount = data[index++]; for (int i = 0; i < attributesCount; ++i) { char name[64]; @@ -46,18 +45,17 @@ void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *_data, size_t len break; } ShaderConstant constant; - constant.offset = *(uint32_t *)&data[index]; + memcpy(&constant.offset, &data[index], sizeof(constant.offset)); index += 4; - constant.size = *(uint32_t *)&data[index]; + memcpy(&constant.size, &data[index], sizeof(constant.size)); index += 4; -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS index += 2; // columns and rows #endif strcpy(constant.name, name); shader->impl.constants[i] = constant; shader->impl.constantsSize = constant.offset + constant.size; } -#endif shader->impl.length = (int)length - index; shader->impl.data = (uint8_t *)malloc(shader->impl.length); @@ -79,6 +77,8 @@ void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *_data, size_t len case KINC_G5_SHADER_TYPE_TESSELLATION_EVALUATION: // Microsoft::affirm(device->CreateDomainShader(this->data, this->length, nullptr, (ID3D11DomainShader**)&shader)); break; + default: + break; } } diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/shader.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/shader.h index 9f29f62..ccb1cbd 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/shader.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/shader.h @@ -26,6 +26,7 @@ typedef struct { ShaderAttribute attributes[32]; ShaderTexture textures[32]; int texturesCount; + void *shader; uint8_t *data; int length; diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/texture.c.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/texture.c.h index 40f88c9..f992a40 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/texture.c.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/texture.c.h @@ -10,7 +10,7 @@ static const int heapSize = 1024; -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) /*static int d3d12_textureAlignment() { return D3D12_TEXTURE_DATA_PITCH_ALIGNMENT; }*/ @@ -30,7 +30,6 @@ static inline UINT64 GetRequiredIntermediateSize(ID3D12Resource *destinationReso D3D12_RESOURCE_DESC desc = destinationResource->GetDesc(); UINT64 requiredSize = 0; device->GetCopyableFootprints(&desc, FirstSubresource, NumSubresources, 0, NULL, NULL, NULL, &requiredSize); - device->Release(); return requiredSize; } @@ -80,7 +79,14 @@ static int formatByteSize(kinc_image_format_t format) { } void kinc_g5_internal_set_textures(kinc_g5_command_list_t *list) { - if (list->impl.currentRenderTargets[0] != NULL || list->impl.currentTextures[0] != NULL) { + int texture_count = 0; + for (int i = 0; i < KINC_INTERNAL_G5_TEXTURE_COUNT; ++i) { + if ((list->impl.currentRenderTargets[i] != NULL || list->impl.currentTextures[i] != NULL) && list->impl.current_samplers[i] != NULL) { + texture_count += 1; + } + } + + if (texture_count > 0) { int srvStep = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); int samplerStep = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); @@ -94,15 +100,15 @@ void kinc_g5_internal_set_textures(kinc_g5_command_list_t *list) { samplerGpu.ptr += list->impl.heapIndex * samplerStep; for (int i = 0; i < KINC_INTERNAL_G5_TEXTURE_COUNT; ++i) { + D3D12_CPU_DESCRIPTOR_HANDLE srvCpu = list->impl.srvHeap->GetCPUDescriptorHandleForHeapStart(); + D3D12_CPU_DESCRIPTOR_HANDLE samplerCpu = list->impl.samplerHeap->GetCPUDescriptorHandleForHeapStart(); + srvCpu.ptr += list->impl.heapIndex * srvStep; + samplerCpu.ptr += list->impl.heapIndex * samplerStep; + ++list->impl.heapIndex; + if ((list->impl.currentRenderTargets[i] != NULL || list->impl.currentTextures[i] != NULL) && list->impl.current_samplers[i] != NULL) { ID3D12DescriptorHeap *samplerDescriptorHeap = list->impl.current_samplers[i]->impl.sampler_heap; - D3D12_CPU_DESCRIPTOR_HANDLE srvCpu = list->impl.srvHeap->GetCPUDescriptorHandleForHeapStart(); - D3D12_CPU_DESCRIPTOR_HANDLE samplerCpu = list->impl.samplerHeap->GetCPUDescriptorHandleForHeapStart(); - srvCpu.ptr += list->impl.heapIndex * srvStep; - samplerCpu.ptr += list->impl.heapIndex * samplerStep; - ++list->impl.heapIndex; - if (list->impl.currentRenderTargets[i] != NULL) { bool is_depth = list->impl.currentRenderTargets[i]->impl.stage_depth == i; D3D12_CPU_DESCRIPTOR_HANDLE sourceCpu = @@ -119,12 +125,43 @@ void kinc_g5_internal_set_textures(kinc_g5_command_list_t *list) { D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); } } + else { + D3D12_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; + ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc)); + shaderResourceViewDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; + shaderResourceViewDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + shaderResourceViewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + shaderResourceViewDesc.Texture2D.MipLevels = 1; + shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; + shaderResourceViewDesc.Texture2D.ResourceMinLODClamp = 0.0f; + device->CreateShaderResourceView(NULL, &shaderResourceViewDesc, srvCpu); + + D3D12_SAMPLER_DESC samplerDesc; + ZeroMemory(&samplerDesc, sizeof(D3D12_SAMPLER_DESC)); + samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT; + samplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP; + samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP; + samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP; + samplerDesc.MinLOD = 0.0f; + samplerDesc.MaxLOD = 1.0f; + samplerDesc.MipLODBias = 0.0f; + samplerDesc.MaxAnisotropy = 1; + samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL; + device->CreateSampler(&samplerDesc, samplerCpu); + } } ID3D12DescriptorHeap *heaps[2] = {list->impl.srvHeap, list->impl.samplerHeap}; list->impl._commandList->SetDescriptorHeaps(2, heaps); - list->impl._commandList->SetGraphicsRootDescriptorTable(0, srvGpu); - list->impl._commandList->SetGraphicsRootDescriptorTable(1, samplerGpu); + if (compute_pipeline_set) { + list->impl._commandList->SetComputeRootDescriptorTable(0, srvGpu); + list->impl._commandList->SetComputeRootDescriptorTable(1, srvGpu); + list->impl._commandList->SetComputeRootDescriptorTable(2, samplerGpu); + } + else { + list->impl._commandList->SetGraphicsRootDescriptorTable(0, srvGpu); + list->impl._commandList->SetGraphicsRootDescriptorTable(1, samplerGpu); + } } } @@ -240,7 +277,8 @@ void kinc_g5_texture_init_from_image(kinc_g5_texture_t *texture, kinc_image_t *i device->CreateDescriptorHeap(&descriptorHeapDesc, IID_GRAPHICS_PPV_ARGS(&texture->impl.srvDescriptorHeap)); - D3D12_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc = {0}; + D3D12_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; + ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc)); shaderResourceViewDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; shaderResourceViewDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; shaderResourceViewDesc.Format = d3dformat; @@ -330,7 +368,8 @@ void create_texture(struct kinc_g5_texture *texture, int width, int height, kinc texture->impl.stride = (int)ceilf(uploadBufferSize / (float)(height * d3d12_textureAlignment())) * d3d12_textureAlignment(); - D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = {0}; + D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc; + ZeroMemory(&descriptorHeapDesc, sizeof(descriptorHeapDesc)); descriptorHeapDesc.NumDescriptors = 1; descriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; diff --git a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/texture.h b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/texture.h index 7f56125..d125062 100644 --- a/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/texture.h +++ b/Kinc/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/texture.h @@ -22,6 +22,7 @@ typedef struct { } Texture5Impl; struct kinc_g5_texture; +struct kinc_g5_command_list; void kinc_g5_internal_set_textures(struct kinc_g5_command_list *commandList); void kinc_g5_internal_texture_set(struct kinc_g5_command_list *commandList, struct kinc_g5_texture *texture, int unit); diff --git a/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/PIXEvents.h b/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/PIXEvents.h new file mode 100644 index 0000000..52dd8bc --- /dev/null +++ b/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/PIXEvents.h @@ -0,0 +1,1578 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// Don't include this file directly - use pix3.h + +#pragma once + +#ifndef _PixEvents_H_ +#define _PixEvents_H_ + +#ifndef _PIX3_H_ +# error Do not include this file directly - use pix3.h +#endif + +#include "PIXEventsCommon.h" + +#if _MSC_VER < 1800 +# error This version of pix3.h is only supported on Visual Studio 2013 or higher +#elif _MSC_VER < 1900 +# ifndef constexpr // Visual Studio 2013 doesn't support constexpr +# define constexpr +# define PIX3__DEFINED_CONSTEXPR +# endif +#endif + + // Xbox does not support CPU events for retail scenarios +#if defined(USE_PIX) || !defined(PIX_XBOX) +#define PIX_CONTEXT_EMIT_CPU_EVENTS +#endif + +namespace PIXEventsDetail +{ + inline void PIXCopyEventArguments(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit) + { + // nothing + UNREFERENCED_PARAMETER(destination); + UNREFERENCED_PARAMETER(limit); + } + + template + void PIXCopyEventArguments(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, ARG const& arg, ARGS const&... args) + { + PIXCopyEventArgument(destination, limit, arg); + PIXCopyEventArguments(destination, limit, args...); + } + + template + void PIXCopyStringArguments(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, ARG const& arg, ARGS const&... args) + { + PIXCopyStringArgument(destination, limit, arg); + PIXCopyEventArguments(destination, limit, args...); + } + + template + void PIXCopyStringArgumentsWithContext(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, void* context, ARG const& arg, ARGS const&... args) + { +#ifdef PIX_XBOX + UNREFERENCED_PARAMETER(context); + PIXCopyStringArgument(destination, limit, arg); + PIXCopyEventArguments(destination, limit, args...); +#else + PIXCopyEventArgument(destination, limit, context); + PIXCopyStringArgument(destination, limit, arg); + PIXCopyEventArguments(destination, limit, args...); +#endif + } + + inline UINT8 PIXGetEventSize(const UINT64* end, const UINT64* start) + { + const UINT64 actualEventSize = end - start; + + return static_cast(actualEventSize > PIXEventsSizeMax ? PIXEventsSizeMax : actualEventSize); + } + + template + inline UINT8 PIXEncodeStringIsAnsi() + { + return PIX_EVENT_METADATA_NONE; + } + + template<> + inline UINT8 PIXEncodeStringIsAnsi() + { + return PIX_EVENT_METADATA_STRING_IS_ANSI; + } + + template<> + inline UINT8 PIXEncodeStringIsAnsi() + { + return PIX_EVENT_METADATA_STRING_IS_ANSI; + } + + template + __declspec(noinline) void PIXBeginEventAllocate(PIXEventsThreadInfo* threadInfo, UINT64 color, STR formatString, ARGS... args) + { + UINT64 time = PIXEventsReplaceBlock(threadInfo, false); + if (!time) + return; + + UINT64* destination = threadInfo->destination; + UINT64* limit = threadInfo->biasedLimit; + if (destination >= limit) + return; + + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64* eventDestination = destination++; + *destination++ = color; + + PIXCopyStringArguments(destination, limit, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_HAS_COLOR | + PIXEncodeStringIsAnsi(); + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + + template + void PIXBeginEvent(UINT64 color, STR formatString, ARGS... args) + { + PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo(); + UINT64* limit = threadInfo->biasedLimit; + if (limit != nullptr) + { + UINT64* destination = threadInfo->destination; + if (destination < limit) + { + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64 time = PIXGetTimestampCounter(); + UINT64* eventDestination = destination++; + *destination++ = color; + + PIXCopyStringArguments(destination, limit, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_HAS_COLOR | + PIXEncodeStringIsAnsi(); + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + else + { + PIXBeginEventAllocate(threadInfo, color, formatString, args...); + } + } + } + + template + __declspec(noinline) void PIXBeginEventAllocate(PIXEventsThreadInfo* threadInfo, UINT8 color, STR formatString, ARGS... args) + { + UINT64 time = PIXEventsReplaceBlock(threadInfo, false); + if (!time) + return; + + UINT64* destination = threadInfo->destination; + UINT64* limit = threadInfo->biasedLimit; + if (destination >= limit) + return; + + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64* eventDestination = destination++; + + PIXCopyStringArguments(destination, limit, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIXEncodeStringIsAnsi() | + PIXEncodeIndexColor(color); + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + + template + void PIXBeginEvent(UINT8 color, STR formatString, ARGS... args) + { + PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo(); + UINT64* limit = threadInfo->biasedLimit; + if (limit != nullptr) + { + UINT64* destination = threadInfo->destination; + if (destination < limit) + { + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64 time = PIXGetTimestampCounter(); + UINT64* eventDestination = destination++; + + PIXCopyStringArguments(destination, limit, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIXEncodeStringIsAnsi() | + PIXEncodeIndexColor(color); + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + else + { + PIXBeginEventAllocate(threadInfo, color, formatString, args...); + } + } + } + + template + __declspec(noinline) void PIXSetMarkerAllocate(PIXEventsThreadInfo* threadInfo, UINT64 color, STR formatString, ARGS... args) + { + UINT64 time = PIXEventsReplaceBlock(threadInfo, false); + if (!time) + return; + + UINT64* destination = threadInfo->destination; + UINT64* limit = threadInfo->biasedLimit; + + if (destination >= limit) + return; + + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64* eventDestination = destination++; + *destination++ = color; + + PIXCopyStringArguments(destination, limit, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIXEncodeStringIsAnsi() | + PIX_EVENT_METADATA_HAS_COLOR; + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + + template + void PIXSetMarker(UINT64 color, STR formatString, ARGS... args) + { + PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo(); + UINT64* limit = threadInfo->biasedLimit; + if (limit != nullptr) + { + UINT64* destination = threadInfo->destination; + if (destination < limit) + { + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64 time = PIXGetTimestampCounter(); + UINT64* eventDestination = destination++; + *destination++ = color; + + PIXCopyStringArguments(destination, limit, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIXEncodeStringIsAnsi() | + PIX_EVENT_METADATA_HAS_COLOR; + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + else + { + PIXSetMarkerAllocate(threadInfo, color, formatString, args...); + } + } + } + + template + __declspec(noinline) void PIXSetMarkerAllocate(PIXEventsThreadInfo* threadInfo, UINT8 color, STR formatString, ARGS... args) + { + UINT64 time = PIXEventsReplaceBlock(threadInfo, false); + if (!time) + return; + + UINT64* destination = threadInfo->destination; + UINT64* limit = threadInfo->biasedLimit; + + if (destination >= limit) + return; + + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64* eventDestination = destination++; + + PIXCopyStringArguments(destination, limit, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIXEncodeStringIsAnsi() | + PIXEncodeIndexColor(color); + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + + template + void PIXSetMarker(UINT8 color, STR formatString, ARGS... args) + { + PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo(); + UINT64* limit = threadInfo->biasedLimit; + if (limit != nullptr) + { + UINT64* destination = threadInfo->destination; + if (destination < limit) + { + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64 time = PIXGetTimestampCounter(); + UINT64* eventDestination = destination++; + + PIXCopyStringArguments(destination, limit, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIXEncodeStringIsAnsi() | + PIXEncodeIndexColor(color); + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + else + { + PIXSetMarkerAllocate(threadInfo, color, formatString, args...); + } + } + } + + template + __declspec(noinline) void PIXBeginEventOnContextCpuAllocate(UINT64*& eventDestination, UINT8& eventSize, PIXEventsThreadInfo* threadInfo, void* context, UINT64 color, STR formatString, ARGS... args) + { + UINT64 time = PIXEventsReplaceBlock(threadInfo, false); + if (!time) + { + eventDestination = nullptr; + return; + } + + UINT64* destination = threadInfo->destination; + UINT64* limit = threadInfo->biasedLimit; + + if (destination >= limit) + { + eventDestination = nullptr; + return; + } + + limit += PIXEventsSafeFastCopySpaceQwords; + eventDestination = destination++; + *destination++ = color; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIX_EVENT_METADATA_HAS_COLOR; + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + + template + void PIXBeginEventOnContextCpu(UINT64*& eventDestination, UINT8& eventSize, void* context, UINT64 color, STR formatString, ARGS... args) + { + PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo(); + UINT64* limit = threadInfo->biasedLimit; + if (limit == nullptr) + { + eventDestination = nullptr; + return; + } + + UINT64* destination = threadInfo->destination; + if (destination < limit) + { + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64 time = PIXGetTimestampCounter(); + eventDestination = destination++; + *destination++ = color; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIX_EVENT_METADATA_HAS_COLOR; + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + else + { + PIXBeginEventOnContextCpuAllocate(eventDestination, eventSize, threadInfo, context, color, formatString, args...); + } + } + + template + void PIXBeginEvent(CONTEXT* context, UINT64 color, STR formatString, ARGS... args) + { + UINT64* destination = nullptr; + UINT8 eventSize = 0u; + +#ifdef PIX_CONTEXT_EMIT_CPU_EVENTS + PIXBeginEventOnContextCpu(destination, eventSize, context, color, formatString, args...); +#endif + +#ifdef PIX_USE_GPU_MARKERS_V2 + if (destination != nullptr) + { + PIXInsertTimingMarkerOnContextForBeginEvent(context, PIXEvent_BeginEvent, static_cast(destination), eventSize * sizeof(UINT64)); + } + else +#endif + { + UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords]; + +#ifdef PIX_USE_GPU_MARKERS_V2 + destination = buffer; + UINT64* limit = buffer + PIXEventsGraphicsRecordSpaceQwords - PIXEventsReservedTailSpaceQwords; + + UINT64* eventDestination = destination++; + *destination++ = color; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = 0ull; + + eventSize = static_cast(destination - buffer); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIX_EVENT_METADATA_HAS_COLOR; + *eventDestination = PIXEncodeEventInfo(0, PIXEvent_BeginEvent, eventSize, eventMetadata); + PIXInsertGPUMarkerOnContextForBeginEvent(context, PIXEvent_BeginEvent, static_cast(buffer), static_cast(reinterpret_cast(destination) - reinterpret_cast(buffer))); +#else + destination = PixEventsLegacy::EncodeBeginEventForContext(buffer, color, formatString, args...); + PIXBeginGPUEventOnContext(context, static_cast(buffer), static_cast(reinterpret_cast(destination) - reinterpret_cast(buffer))); +#endif + } + } + + template + __declspec(noinline) void PIXBeginEventOnContextCpuAllocate(UINT64*& eventDestination, UINT8& eventSize, PIXEventsThreadInfo* threadInfo, void* context, UINT8 color, STR formatString, ARGS... args) + { + UINT64 time = PIXEventsReplaceBlock(threadInfo, false); + if (!time) + { + eventDestination = nullptr; + return; + } + + UINT64* destination = threadInfo->destination; + UINT64* limit = threadInfo->biasedLimit; + + if (destination >= limit) + { + eventDestination = nullptr; + return; + } + + limit += PIXEventsSafeFastCopySpaceQwords; + eventDestination = destination++; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIXEncodeIndexColor(color); + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + + template + void PIXBeginEventOnContextCpu(UINT64*& eventDestination, UINT8& eventSize, void* context, UINT8 color, STR formatString, ARGS... args) + { + PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo(); + UINT64* limit = threadInfo->biasedLimit; + if (limit == nullptr) + { + eventDestination = nullptr; + return; + } + + UINT64* destination = threadInfo->destination; + if (destination < limit) + { + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64 time = PIXGetTimestampCounter(); + eventDestination = destination++; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIXEncodeIndexColor(color); + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_BeginEvent, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + else + { + PIXBeginEventOnContextCpuAllocate(eventDestination, eventSize, threadInfo, context, color, formatString, args...); + } + } + + template + void PIXBeginEvent(CONTEXT* context, UINT8 color, STR formatString, ARGS... args) + { + UINT64* destination = nullptr; + UINT8 eventSize = 0u; + +#ifdef PIX_CONTEXT_EMIT_CPU_EVENTS + PIXBeginEventOnContextCpu(destination, eventSize, context, color, formatString, args...); +#endif + +#ifdef PIX_USE_GPU_MARKERS_V2 + if (destination != nullptr) + { + PIXInsertTimingMarkerOnContextForBeginEvent(context, PIXEvent_BeginEvent, static_cast(destination), eventSize * sizeof(UINT64)); + } + else +#endif + { + UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords]; + +#ifdef PIX_USE_GPU_MARKERS_V2 + destination = buffer; + UINT64* limit = buffer + PIXEventsGraphicsRecordSpaceQwords - PIXEventsReservedTailSpaceQwords; + + UINT64* eventDestination = destination++; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = 0ull; + + eventSize = static_cast(destination - buffer); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIXEncodeIndexColor(color); + *eventDestination = PIXEncodeEventInfo(0, PIXEvent_BeginEvent, eventSize, eventMetadata); + + PIXInsertGPUMarkerOnContextForBeginEvent(context, PIXEvent_BeginEvent, static_cast(buffer), static_cast(reinterpret_cast(destination) - reinterpret_cast(buffer))); +#else + destination = PixEventsLegacy::EncodeBeginEventForContext(buffer, color, formatString, args...); + PIXBeginGPUEventOnContext(context, static_cast(buffer), static_cast(reinterpret_cast(destination) - reinterpret_cast(buffer))); +#endif + } + } + + template + __declspec(noinline) void PIXSetMarkerOnContextCpuAllocate(UINT64*& eventDestination, UINT8& eventSize, PIXEventsThreadInfo* threadInfo, void* context, UINT64 color, STR formatString, ARGS... args) + { + UINT64 time = PIXEventsReplaceBlock(threadInfo, false); + if (!time) + { + eventDestination = nullptr; + return; + } + + UINT64* destination = threadInfo->destination; + UINT64* limit = threadInfo->biasedLimit; + + if (destination >= limit) + { + eventDestination = nullptr; + return; + } + + limit += PIXEventsSafeFastCopySpaceQwords; + eventDestination = destination++; + *destination++ = color; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIX_EVENT_METADATA_HAS_COLOR; + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + + template + void PIXSetMarkerOnContextCpu(UINT64*& eventDestination, UINT8& eventSize, void* context, UINT64 color, STR formatString, ARGS... args) + { + PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo(); + UINT64* limit = threadInfo->biasedLimit; + if (limit == nullptr) + { + eventDestination = nullptr; + return; + } + + UINT64* destination = threadInfo->destination; + if (destination < limit) + { + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64 time = PIXGetTimestampCounter(); + eventDestination = destination++; + *destination++ = color; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIX_EVENT_METADATA_HAS_COLOR; + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + else + { + PIXSetMarkerOnContextCpuAllocate(eventDestination, eventSize, threadInfo, context, color, formatString, args...); + } + } + + template + void PIXSetMarker(CONTEXT* context, UINT64 color, STR formatString, ARGS... args) + { + UINT64* destination = nullptr; + UINT8 eventSize = 0u; + +#ifdef PIX_CONTEXT_EMIT_CPU_EVENTS + PIXSetMarkerOnContextCpu(destination, eventSize, context, color, formatString, args...); +#endif + +#ifdef PIX_USE_GPU_MARKERS_V2 + if (destination != nullptr) + { + PIXInsertTimingMarkerOnContextForSetMarker(context, PIXEvent_SetMarker, static_cast(destination), eventSize * sizeof(UINT64)); + } + else +#endif + { + UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords]; + +#ifdef PIX_USE_GPU_MARKERS_V2 + destination = buffer; + UINT64* limit = buffer + PIXEventsGraphicsRecordSpaceQwords - PIXEventsReservedTailSpaceQwords; + + UINT64* eventDestination = destination++; + *destination++ = color; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = 0ull; + + eventSize = static_cast(destination - buffer); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIX_EVENT_METADATA_HAS_COLOR; + *eventDestination = PIXEncodeEventInfo(0, PIXEvent_SetMarker, eventSize, eventMetadata); + PIXInsertGPUMarkerOnContextForSetMarker(context, PIXEvent_SetMarker, static_cast(buffer), static_cast(reinterpret_cast(destination) - reinterpret_cast(buffer))); +#else + destination = PixEventsLegacy::EncodeSetMarkerForContext(buffer, color, formatString, args...); + PIXSetGPUMarkerOnContext(context, static_cast(buffer), static_cast(reinterpret_cast(destination) - reinterpret_cast(buffer))); +#endif + } + } + + template + __declspec(noinline) void PIXSetMarkerOnContextCpuAllocate(UINT64*& eventDestination, UINT8& eventSize, PIXEventsThreadInfo* threadInfo, void* context, UINT8 color, STR formatString, ARGS... args) + { + UINT64 time = PIXEventsReplaceBlock(threadInfo, false); + if (!time) + { + eventDestination = nullptr; + return; + } + + UINT64* destination = threadInfo->destination; + UINT64* limit = threadInfo->biasedLimit; + + if (destination >= limit) + { + eventDestination = nullptr; + return; + } + + limit += PIXEventsSafeFastCopySpaceQwords; + eventDestination = destination++; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIXEncodeIndexColor(color); + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + + template + void PIXSetMarkerOnContextCpu(UINT64*& eventDestination, UINT8& eventSize, void* context, UINT8 color, STR formatString, ARGS... args) + { + PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo(); + UINT64* limit = threadInfo->biasedLimit; + if (limit == nullptr) + { + eventDestination = nullptr; + return; + } + + UINT64* destination = threadInfo->destination; + if (destination < limit) + { + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64 time = PIXGetTimestampCounter(); + eventDestination = destination++; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = PIXEventsBlockEndMarker; + + eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIXEncodeIndexColor(color); + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_SetMarker, eventSize, eventMetadata); + + threadInfo->destination = destination; + } + else + { + PIXSetMarkerOnContextCpuAllocate(eventDestination, eventSize, threadInfo, context, color, formatString, args...); + } + } + + template + void PIXSetMarker(CONTEXT* context, UINT8 color, STR formatString, ARGS... args) + { + UINT64* destination = nullptr; + UINT8 eventSize = 0u; + +#ifdef PIX_CONTEXT_EMIT_CPU_EVENTS + PIXSetMarkerOnContextCpu(destination, eventSize, context, color, formatString, args...); +#endif + +#ifdef PIX_USE_GPU_MARKERS_V2 + if (destination != nullptr) + { + PIXInsertTimingMarkerOnContextForSetMarker(context, PIXEvent_SetMarker, static_cast(destination), eventSize * sizeof(UINT64)); + } + else +#endif + { + UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords]; + +#ifdef PIX_USE_GPU_MARKERS_V2 + destination = buffer; + UINT64* limit = buffer + PIXEventsGraphicsRecordSpaceQwords - PIXEventsReservedTailSpaceQwords; + + UINT64* eventDestination = destination++; + + PIXCopyStringArgumentsWithContext(destination, limit, context, formatString, args...); + *destination = 0ull; + + eventSize = static_cast(destination - buffer); + const UINT8 eventMetadata = + PIX_EVENT_METADATA_ON_CONTEXT | + PIXEncodeStringIsAnsi() | + PIXEncodeIndexColor(color); + *eventDestination = PIXEncodeEventInfo(0, PIXEvent_SetMarker, eventSize, eventMetadata); + PIXInsertGPUMarkerOnContextForSetMarker(context, PIXEvent_SetMarker, static_cast(buffer), static_cast(reinterpret_cast(destination) - reinterpret_cast(buffer))); +#else + destination = PixEventsLegacy::EncodeSetMarkerForContext(buffer, color, formatString, args...); + PIXSetGPUMarkerOnContext(context, static_cast(buffer), static_cast(reinterpret_cast(destination) - reinterpret_cast(buffer))); +#endif + } + } + + __declspec(noinline) inline void PIXEndEventAllocate(PIXEventsThreadInfo* threadInfo) + { + UINT64 time = PIXEventsReplaceBlock(threadInfo, true); + if (!time) + return; + + UINT64* destination = threadInfo->destination; + UINT64* limit = threadInfo->biasedLimit; + + if (destination >= limit) + return; + + limit += PIXEventsSafeFastCopySpaceQwords; + const UINT8 eventSize = 1; + const UINT8 eventMetadata = PIX_EVENT_METADATA_NONE; + *destination++ = PIXEncodeEventInfo(time, PIXEvent_EndEvent, eventSize, eventMetadata); + *destination = PIXEventsBlockEndMarker; + + threadInfo->destination = destination; + } + + inline void PIXEndEvent() + { + PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo(); + UINT64* limit = threadInfo->biasedLimit; + if (limit != nullptr) + { + UINT64* destination = threadInfo->destination; + if (destination < limit) + { + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64 time = PIXGetTimestampCounter(); + const UINT8 eventSize = 1; + const UINT8 eventMetadata = PIX_EVENT_METADATA_NONE; + *destination++ = PIXEncodeEventInfo(time, PIXEvent_EndEvent, eventSize, eventMetadata); + *destination = PIXEventsBlockEndMarker; + + threadInfo->destination = destination; + } + else + { + PIXEndEventAllocate(threadInfo); + } + } + } + + __declspec(noinline) inline UINT64* PIXEndEventOnContextCpuAllocate(PIXEventsThreadInfo* threadInfo, void* context) + { + UINT64 time = PIXEventsReplaceBlock(threadInfo, true); + if (!time) + return nullptr; + + UINT64* destination = threadInfo->destination; + UINT64* limit = threadInfo->biasedLimit; + + if (destination >= limit) + return nullptr; + + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64* eventDestination = destination++; +#ifdef PIX_XBOX + UNREFERENCED_PARAMETER(context); +#else + PIXCopyEventArgument(destination, limit, context); +#endif + * destination = PIXEventsBlockEndMarker; + + const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = PIX_EVENT_METADATA_ON_CONTEXT; + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_EndEvent, eventSize, eventMetadata); + + threadInfo->destination = destination; + + return eventDestination; + } + + inline UINT64* PIXEndEventOnContextCpu(void* context) + { + PIXEventsThreadInfo* threadInfo = PIXGetThreadInfo(); + UINT64* limit = threadInfo->biasedLimit; + if (limit != nullptr) + { + UINT64* destination = threadInfo->destination; + if (destination < limit) + { + limit += PIXEventsSafeFastCopySpaceQwords; + UINT64 time = PIXGetTimestampCounter(); + UINT64* eventDestination = destination++; +#ifndef PIX_XBOX + PIXCopyEventArgument(destination, limit, context); +#endif + * destination = PIXEventsBlockEndMarker; + + const UINT8 eventSize = PIXGetEventSize(destination, threadInfo->destination); + const UINT8 eventMetadata = PIX_EVENT_METADATA_ON_CONTEXT; + *eventDestination = PIXEncodeEventInfo(time, PIXEvent_EndEvent, eventSize, eventMetadata); + + threadInfo->destination = destination; + + return eventDestination; + } + else + { + return PIXEndEventOnContextCpuAllocate(threadInfo, context); + } + } + + return nullptr; + } + + template + void PIXEndEvent(CONTEXT* context) + { + UINT64* destination = nullptr; +#ifdef PIX_CONTEXT_EMIT_CPU_EVENTS + destination = PIXEndEventOnContextCpu(context); +#endif + +#ifdef PIX_USE_GPU_MARKERS_V2 + if (destination != nullptr) + { + PIXInsertTimingMarkerOnContextForEndEvent(context, PIXEvent_EndEvent); + } + else +#endif + { +#ifdef PIX_USE_GPU_MARKERS_V2 + UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords]; + destination = buffer; + + UINT64* eventDestination = destination++; + + const UINT8 eventSize = static_cast(destination - buffer); + const UINT8 eventMetadata = PIX_EVENT_METADATA_NONE; + *eventDestination = PIXEncodeEventInfo(0, PIXEvent_EndEvent, eventSize, eventMetadata); + PIXInsertGPUMarkerOnContextForEndEvent(context, PIXEvent_EndEvent, static_cast(buffer), static_cast(reinterpret_cast(destination) - reinterpret_cast(buffer))); +#else + PIXEndGPUEventOnContext(context); +#endif + } + } +} + +#if defined(USE_PIX) + +template +void PIXBeginEvent(UINT64 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(color, formatString, args...); +} + +template +void PIXBeginEvent(UINT64 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(color, formatString, args...); +} + +template +void PIXBeginEvent(UINT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(UINT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(INT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(INT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(DWORD color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(DWORD color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(UINT8 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(color, formatString, args...); +} + +template +void PIXBeginEvent(UINT8 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(color, formatString, args...); +} + +template +void PIXSetMarker(UINT64 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(color, formatString, args...); +} + +template +void PIXSetMarker(UINT64 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(color, formatString, args...); +} + +template +void PIXSetMarker(UINT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(UINT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(INT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(INT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(DWORD color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(DWORD color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(UINT8 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(color, formatString, args...); +} + +template +void PIXSetMarker(UINT8 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(color, formatString, args...); +} + +template +void PIXBeginEvent(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...); +} + +template +void PIXBeginEvent(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...); +} + +template +void PIXBeginEvent(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginEvent(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...); +} + +template +void PIXBeginEvent(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...); +} + +template +void PIXSetMarker(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, color, formatString, args...); +} + +template +void PIXSetMarker(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, color, formatString, args...); +} + +template +void PIXSetMarker(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetMarker(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, color, formatString, args...); +} + +template +void PIXSetMarker(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, color, formatString, args...); +} + +inline void PIXEndEvent() +{ + PIXEventsDetail::PIXEndEvent(); +} + +template +void PIXEndEvent(CONTEXT* context) +{ + PIXEventsDetail::PIXEndEvent(context); +} + +#else // USE_PIX_RETAIL + +inline void PIXBeginEvent(UINT64, _In_ PCSTR, ...) {} +inline void PIXBeginEvent(UINT64, _In_ PCWSTR, ...) {} +inline void PIXBeginEvent(void*, UINT64, _In_ PCSTR, ...) {} +inline void PIXBeginEvent(void*, UINT64, _In_ PCWSTR, ...) {} +inline void PIXEndEvent() {} +inline void PIXEndEvent(void*) {} +inline void PIXSetMarker(UINT64, _In_ PCSTR, ...) {} +inline void PIXSetMarker(UINT64, _In_ PCWSTR, ...) {} +inline void PIXSetMarker(void*, UINT64, _In_ PCSTR, ...) {} +inline void PIXSetMarker(void*, UINT64, _In_ PCWSTR, ...) {} + +#endif // USE_PIX + +template +void PIXBeginRetailEvent(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...); +} + +template +void PIXBeginRetailEvent(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...); +} + +template +void PIXBeginRetailEvent(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginRetailEvent(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginRetailEvent(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginRetailEvent(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginRetailEvent(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginRetailEvent(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, static_cast(color), formatString, args...); +} + +template +void PIXBeginRetailEvent(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...); +} + +template +void PIXBeginRetailEvent(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXBeginEvent(context, color, formatString, args...); +} + +template +void PIXSetRetailMarker(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, color, formatString, args...); +} + +template +void PIXSetRetailMarker(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, color, formatString, args...); +} + +template +void PIXSetRetailMarker(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetRetailMarker(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetRetailMarker(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetRetailMarker(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetRetailMarker(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetRetailMarker(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, static_cast(color), formatString, args...); +} + +template +void PIXSetRetailMarker(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, color, formatString, args...); +} + +template +void PIXSetRetailMarker(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args) +{ + PIXEventsDetail::PIXSetMarker(context, color, formatString, args...); +} + +template +void PIXEndRetailEvent(CONTEXT* context) +{ + PIXEventsDetail::PIXEndEvent(context); +} + +template +class PIXScopedEventObject +{ + CONTEXT* m_context; + +public: + template + PIXScopedEventObject(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginEvent(m_context, color, formatString, args...); + } + + template + PIXScopedEventObject(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginEvent(m_context, color, formatString, args...); + } + + template + PIXScopedEventObject(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginEvent(m_context, color, formatString, args...); + } + + template + PIXScopedEventObject(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginEvent(m_context, color, formatString, args...); + } + + template + PIXScopedEventObject(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginEvent(m_context, color, formatString, args...); + } + + template + PIXScopedEventObject(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginEvent(m_context, color, formatString, args...); + } + + template + PIXScopedEventObject(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginEvent(m_context, color, formatString, args...); + } + + template + PIXScopedEventObject(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginEvent(m_context, color, formatString, args...); + } + + template + PIXScopedEventObject(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginEvent(m_context, color, formatString, args...); + } + + template + PIXScopedEventObject(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginEvent(m_context, color, formatString, args...); + } + + ~PIXScopedEventObject() + { + PIXEndEvent(m_context); + } +}; + +template +class PIXScopedRetailEventObject +{ + CONTEXT* m_context; + +public: + template + PIXScopedRetailEventObject(CONTEXT* context, UINT64 color, PCWSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginRetailEvent(m_context, color, formatString, args...); + } + + template + PIXScopedRetailEventObject(CONTEXT* context, UINT64 color, PCSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginRetailEvent(m_context, color, formatString, args...); + } + + template + PIXScopedRetailEventObject(CONTEXT* context, UINT32 color, PCWSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginRetailEvent(m_context, color, formatString, args...); + } + + template + PIXScopedRetailEventObject(CONTEXT* context, UINT32 color, PCSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginRetailEvent(m_context, color, formatString, args...); + } + + template + PIXScopedRetailEventObject(CONTEXT* context, INT32 color, PCWSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginRetailEvent(m_context, color, formatString, args...); + } + + template + PIXScopedRetailEventObject(CONTEXT* context, INT32 color, PCSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginRetailEvent(m_context, color, formatString, args...); + } + + template + PIXScopedRetailEventObject(CONTEXT* context, DWORD color, PCWSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginRetailEvent(m_context, color, formatString, args...); + } + + template + PIXScopedRetailEventObject(CONTEXT* context, DWORD color, PCSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginRetailEvent(m_context, color, formatString, args...); + } + + template + PIXScopedRetailEventObject(CONTEXT* context, UINT8 color, PCWSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginRetailEvent(m_context, color, formatString, args...); + } + + template + PIXScopedRetailEventObject(CONTEXT* context, UINT8 color, PCSTR formatString, ARGS... args) + : m_context(context) + { + PIXBeginRetailEvent(m_context, color, formatString, args...); + } + + ~PIXScopedRetailEventObject() + { + PIXEndRetailEvent(m_context); + } +}; + +template<> +class PIXScopedEventObject +{ +public: + template + PIXScopedEventObject(UINT64 color, PCWSTR formatString, ARGS... args) + { + PIXBeginEvent(color, formatString, args...); + } + + template + PIXScopedEventObject(UINT64 color, PCSTR formatString, ARGS... args) + { + PIXBeginEvent(color, formatString, args...); + } + + template + PIXScopedEventObject(UINT32 color, PCWSTR formatString, ARGS... args) + { + PIXBeginEvent(color, formatString, args...); + } + + template + PIXScopedEventObject(UINT32 color, PCSTR formatString, ARGS... args) + { + PIXBeginEvent(color, formatString, args...); + } + + template + PIXScopedEventObject(INT32 color, PCWSTR formatString, ARGS... args) + { + PIXBeginEvent(color, formatString, args...); + } + + template + PIXScopedEventObject(INT32 color, PCSTR formatString, ARGS... args) + { + PIXBeginEvent(color, formatString, args...); + } + + template + PIXScopedEventObject(DWORD color, PCWSTR formatString, ARGS... args) + { + PIXBeginEvent(color, formatString, args...); + } + + template + PIXScopedEventObject(DWORD color, PCSTR formatString, ARGS... args) + { + PIXBeginEvent(color, formatString, args...); + } + + template + PIXScopedEventObject(UINT8 color, PCWSTR formatString, ARGS... args) + { + PIXBeginEvent(color, formatString, args...); + } + + template + PIXScopedEventObject(UINT8 color, PCSTR formatString, ARGS... args) + { + PIXBeginEvent(color, formatString, args...); + } + + ~PIXScopedEventObject() + { + PIXEndEvent(); + } +}; + +#define PIXConcatenate(a, b) a ## b +#define PIXGetScopedEventVariableName(a, b) PIXConcatenate(a, b) +#define PIXScopedEvent(context, ...) PIXScopedEventObject::Type> PIXGetScopedEventVariableName(pixEvent, __LINE__)(context, __VA_ARGS__) + +#ifdef PIX3__DEFINED_CONSTEXPR +#undef constexpr +#undef PIX3__DEFINED_CONSTEXPR +#endif + +#endif // _PIXEvents_H__ + diff --git a/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/PIXEventsCommon.h b/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/PIXEventsCommon.h new file mode 100644 index 0000000..69a9bb9 --- /dev/null +++ b/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/PIXEventsCommon.h @@ -0,0 +1,610 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// Don't include this file directly - use pix3.h + +#pragma once + +#ifndef _PIXEventsCommon_H_ +#define _PIXEventsCommon_H_ + +// +// The PIXBeginEvent and PIXSetMarker functions have an optimized path for +// copying strings that work by copying 128-bit or 64-bits at a time. In some +// circumstances this may result in PIX logging the remaining memory after the +// null terminator. +// +// By default this optimization is enabled unless Address Sanitizer is enabled, +// since this optimization can trigger a global-buffer-overflow when copying +// string literals. +// +// The PIX_ENABLE_BLOCK_ARGUMENT_COPY controls whether or not this optimization +// is enabled. Applications may also explicitly set this macro to 0 to disable +// the optimization if necessary. +// + +// Check for Address Sanitizer on either Clang or MSVC + +#if defined(__has_feature) +#if __has_feature(address_sanitizer) +#define PIX_ASAN_ENABLED +#endif +#elif defined(__SANITIZE_ADDRESS__) +#define PIX_ASAN_ENABLED +#endif + +#if defined(PIX_ENABLE_BLOCK_ARGUMENT_COPY) +// Previously set values override everything +# define PIX_ENABLE_BLOCK_ARGUMENT_COPY_SET 0 +#elif defined(PIX_ASAN_ENABLED) +// Disable block argument copy when address sanitizer is enabled +#define PIX_ENABLE_BLOCK_ARGUMENT_COPY 0 +#define PIX_ENABLE_BLOCK_ARGUMENT_COPY_SET 1 +#endif + +#if !defined(PIX_ENABLE_BLOCK_ARGUMENT_COPY) +// Default to enabled. +#define PIX_ENABLE_BLOCK_ARGUMENT_COPY 1 +#define PIX_ENABLE_BLOCK_ARGUMENT_COPY_SET 1 +#endif + +struct PIXEventsBlockInfo; + +struct PIXEventsThreadInfo +{ + PIXEventsBlockInfo* block; + UINT64* biasedLimit; + UINT64* destination; +}; + +extern "C" UINT64 WINAPI PIXEventsReplaceBlock(PIXEventsThreadInfo * threadInfo, bool getEarliestTime) noexcept; + +#define PIX_EVENT_METADATA_NONE 0x0 +#define PIX_EVENT_METADATA_ON_CONTEXT 0x1 +#define PIX_EVENT_METADATA_STRING_IS_ANSI 0x2 +#define PIX_EVENT_METADATA_HAS_COLOR 0xF0 + +#ifndef PIX_GAMING_XBOX +#include "PIXEventsLegacy.h" +#endif + +enum PIXEventType : UINT8 +{ + PIXEvent_EndEvent = 0x00, + PIXEvent_BeginEvent = 0x01, + PIXEvent_SetMarker = 0x02, +}; + +static const UINT64 PIXEventsReservedRecordSpaceQwords = 64; +//this is used to make sure SSE string copy always will end 16-byte write in the current block +//this way only a check if destination < limit can be performed, instead of destination < limit - 1 +//since both these are UINT64* and SSE writes in 16 byte chunks, 8 bytes are kept in reserve +//so even if SSE overwrites 8-15 extra bytes, those will still belong to the correct block +//on next iteration check destination will be greater than limit +//this is used as well for fixed size UMD events and PIXEndEvent since these require less space +//than other variable length user events and do not need big reserved space +static const UINT64 PIXEventsReservedTailSpaceQwords = 2; +static const UINT64 PIXEventsSafeFastCopySpaceQwords = PIXEventsReservedRecordSpaceQwords - PIXEventsReservedTailSpaceQwords; +static const UINT64 PIXEventsGraphicsRecordSpaceQwords = 64; + +//Bits 7-19 (13 bits) +static const UINT64 PIXEventsBlockEndMarker = 0x00000000000FFF80; + + +// V2 events + +// Bits 00..06 (7 bits) - Size in QWORDS +static const UINT64 PIXEventsSizeWriteMask = 0x000000000000007F; +static const UINT64 PIXEventsSizeBitShift = 0; +static const UINT64 PIXEventsSizeReadMask = PIXEventsSizeWriteMask << PIXEventsSizeBitShift; +static const UINT64 PIXEventsSizeMax = (1ull << 7) - 1ull; + +// Bits 07..11 (5 bits) - Event Type +static const UINT64 PIXEventsTypeWriteMask = 0x000000000000001F; +static const UINT64 PIXEventsTypeBitShift = 7; +static const UINT64 PIXEventsTypeReadMask = PIXEventsTypeWriteMask << PIXEventsTypeBitShift; + +// Bits 12..19 (8 bits) - Event Specific Metadata +static const UINT64 PIXEventsMetadataWriteMask = 0x00000000000000FF; +static const UINT64 PIXEventsMetadataBitShift = 12; +static const UINT64 PIXEventsMetadataReadMask = PIXEventsMetadataWriteMask << PIXEventsMetadataBitShift; + +// Buts 20..63 (44 bits) - Timestamp +static const UINT64 PIXEventsTimestampWriteMask = 0x00000FFFFFFFFFFF; +static const UINT64 PIXEventsTimestampBitShift = 20; +static const UINT64 PIXEventsTimestampReadMask = PIXEventsTimestampWriteMask << PIXEventsTimestampBitShift; + +inline UINT64 PIXEncodeEventInfo(UINT64 timestamp, PIXEventType eventType, UINT8 eventSize, UINT8 eventMetadata) +{ + return + ((timestamp & PIXEventsTimestampWriteMask) << PIXEventsTimestampBitShift) | + (((UINT64)eventType & PIXEventsTypeWriteMask) << PIXEventsTypeBitShift) | + (((UINT64)eventMetadata & PIXEventsMetadataWriteMask) << PIXEventsMetadataBitShift) | + (((UINT64)eventSize & PIXEventsSizeWriteMask) << PIXEventsSizeBitShift); +} + +inline UINT8 PIXEncodeIndexColor(UINT8 color) +{ + // There are 8 index colors, indexed 0 (default) to 7 + return (color & 0x7) << 4; +} + +//Bits 60-63 (4) +static const UINT64 PIXEventsStringAlignmentWriteMask = 0x000000000000000F; +static const UINT64 PIXEventsStringAlignmentReadMask = 0xF000000000000000; +static const UINT64 PIXEventsStringAlignmentBitShift = 60; + +//Bits 55-59 (5) +static const UINT64 PIXEventsStringCopyChunkSizeWriteMask = 0x000000000000001F; +static const UINT64 PIXEventsStringCopyChunkSizeReadMask = 0x0F80000000000000; +static const UINT64 PIXEventsStringCopyChunkSizeBitShift = 55; + +//Bit 54 +static const UINT64 PIXEventsStringIsANSIWriteMask = 0x0000000000000001; +static const UINT64 PIXEventsStringIsANSIReadMask = 0x0040000000000000; +static const UINT64 PIXEventsStringIsANSIBitShift = 54; + +//Bit 53 +static const UINT64 PIXEventsStringIsShortcutWriteMask = 0x0000000000000001; +static const UINT64 PIXEventsStringIsShortcutReadMask = 0x0020000000000000; +static const UINT64 PIXEventsStringIsShortcutBitShift = 53; + +inline void PIXEncodeStringInfo(UINT64*& destination, BOOL isANSI) +{ + const UINT64 encodedStringInfo = + ((sizeof(UINT64) & PIXEventsStringCopyChunkSizeWriteMask) << PIXEventsStringCopyChunkSizeBitShift) | + (((UINT64)isANSI & PIXEventsStringIsANSIWriteMask) << PIXEventsStringIsANSIBitShift); + + *destination++ = encodedStringInfo; +} + +template +inline bool PIXIsPointerAligned(T* pointer) +{ + return !(((UINT64)pointer) & (alignment - 1)); +} + +// Generic template version slower because of the additional clear write +template +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, T argument) +{ + if (destination < limit) + { + *destination = 0ull; + *((T*)destination) = argument; + ++destination; + } +} + +// int32 specialization to avoid slower double memory writes +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, INT32 argument) +{ + if (destination < limit) + { + *reinterpret_cast(destination) = static_cast(argument); + ++destination; + } +} + +// unsigned int32 specialization to avoid slower double memory writes +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, UINT32 argument) +{ + if (destination < limit) + { + *destination = static_cast(argument); + ++destination; + } +} + +// int64 specialization to avoid slower double memory writes +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, INT64 argument) +{ + if (destination < limit) + { + *reinterpret_cast(destination) = argument; + ++destination; + } +} + +// unsigned int64 specialization to avoid slower double memory writes +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, UINT64 argument) +{ + if (destination < limit) + { + *destination = argument; + ++destination; + } +} + +//floats must be cast to double during writing the data to be properly printed later when reading the data +//this is needed because when float is passed to varargs function it's cast to double +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, float argument) +{ + if (destination < limit) + { + *reinterpret_cast(destination) = static_cast(argument); + ++destination; + } +} + +//char has to be cast to a longer signed integer type +//this is due to printf not ignoring correctly the upper bits of unsigned long long for a char format specifier +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, char argument) +{ + if (destination < limit) + { + *reinterpret_cast(destination) = static_cast(argument); + ++destination; + } +} + +//UINT8 has to be cast to a longer unsigned integer type +//this is due to printf not ignoring correctly the upper bits of unsigned long long for a char format specifier +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, UINT8 argument) +{ + if (destination < limit) + { + *destination = static_cast(argument); + ++destination; + } +} + +//bool has to be cast to an integer since it's not explicitly supported by string format routines +//there's no format specifier for bool type, but it should work with integer format specifiers +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, bool argument) +{ + if (destination < limit) + { + *destination = static_cast(argument); + ++destination; + } +} + +inline void PIXCopyEventStringArgumentSlow(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCSTR argument) +{ + while (destination < limit) + { + UINT64 c = static_cast(argument[0]); + if (!c) + { + *destination++ = 0; + return; + } + UINT64 x = c; + c = static_cast(argument[1]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 8; + c = static_cast(argument[2]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 16; + c = static_cast(argument[3]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 24; + c = static_cast(argument[4]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 32; + c = static_cast(argument[5]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 40; + c = static_cast(argument[6]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 48; + c = static_cast(argument[7]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 56; + *destination++ = x; + argument += 8; + } +} + +template +inline void PIXCopyEventArgumentSlow(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCSTR argument) +{ + PIXEncodeStringInfo(destination, TRUE); + PIXCopyEventStringArgumentSlow(destination, limit, argument); +} + +template<> +inline void PIXCopyEventArgumentSlow(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCSTR argument) +{ + PIXCopyEventStringArgumentSlow(destination, limit, argument); +} + +#if (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + +inline void PIXCopyEventStringArgumentFast(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCSTR argument) +{ + constexpr UINT64 mask1 = 0x0101010101010101ULL; + constexpr UINT64 mask2 = 0x8080808080808080ULL; + UINT64* source = (UINT64*)argument; + + while (destination < limit) + { + UINT64 qword = *source++; + *destination++ = qword; + + //check if any of the characters is a terminating zero + UINT64 isTerminated = (qword - mask1) & (~qword & mask2); + + if (isTerminated) + { + break; + } + } +} +#endif + +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCSTR argument) +{ + if (destination < limit) + { + if (argument != nullptr) + { +#if (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + if (PIXIsPointerAligned<8>(argument)) + { + PIXEncodeStringInfo(destination, TRUE); + PIXCopyEventStringArgumentFast(destination, limit, argument); + } + else +#endif // (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + { + PIXCopyEventArgumentSlow(destination, limit, argument); + } + } + else + { + *destination++ = 0ull; + } + } +} + +inline void PIXCopyStringArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCSTR argument) +{ + if (argument != nullptr) + { +#if (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + if (PIXIsPointerAligned<8>(argument)) + { + PIXCopyEventStringArgumentFast(destination, limit, argument); + } + else +#endif // (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + { + PIXCopyEventArgumentSlow(destination, limit, argument); + } + } + else + { + *destination++ = 0ull; + } +} + +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PSTR argument) +{ + PIXCopyEventArgument(destination, limit, (PCSTR)argument); +} + +inline void PIXCopyStringArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PSTR argument) +{ + PIXCopyStringArgument(destination, limit, (PCSTR)argument); +} + +inline void PIXCopyEventStringArgumentSlow(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCWSTR argument) +{ + while (destination < limit) + { + UINT64 c = static_cast(argument[0]); + if (!c) + { + *destination++ = 0; + return; + } + UINT64 x = c; + c = static_cast(argument[1]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 16; + c = static_cast(argument[2]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 32; + c = static_cast(argument[3]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 48; + *destination++ = x; + argument += 4; + } +} + +template +inline void PIXCopyEventArgumentSlow(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCWSTR argument) +{ + PIXEncodeStringInfo(destination, FALSE); + PIXCopyEventStringArgumentSlow(destination, limit, argument); +} + +template<> +inline void PIXCopyEventArgumentSlow(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCWSTR argument) +{ + PIXCopyEventStringArgumentSlow(destination, limit, argument); +} + +#if (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY +inline void PIXCopyEventStringArgumentFast(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCWSTR argument) +{ + UINT64* source = (UINT64*)argument; + while (destination < limit) + { + UINT64 qword = *source++; + *destination++ = qword; + //check if any of the characters is a terminating zero + //TODO: check if reversed condition is faster + if (!((qword & 0xFFFF000000000000) && + (qword & 0xFFFF00000000) && + (qword & 0xFFFF0000) && + (qword & 0xFFFF))) + { + break; + } + } +} +#endif + +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCWSTR argument) +{ + if (destination < limit) + { + if (argument != nullptr) + { +#if (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + if (PIXIsPointerAligned<8>(argument)) + { + PIXEncodeStringInfo(destination, FALSE); + PIXCopyEventStringArgumentFast(destination, limit, argument); + } + else +#endif // (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + { + PIXCopyEventArgumentSlow(destination, limit, argument); + } + } + else + { + *destination++ = 0ull; + } + } +} + +inline void PIXCopyStringArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCWSTR argument) +{ + if (argument != nullptr) + { +#if (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + if (PIXIsPointerAligned<8>(argument)) + { + PIXCopyEventStringArgumentFast(destination, limit, argument); + } + else +#endif // (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + { + PIXCopyEventArgumentSlow(destination, limit, argument); + } + } + else + { + *destination++ = 0ull; + } +} + +template<> +inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PWSTR argument) +{ + PIXCopyEventArgument(destination, limit, (PCWSTR)argument); +}; + +inline void PIXCopyStringArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PWSTR argument) +{ + PIXCopyStringArgument(destination, limit, (PCWSTR)argument); +}; + +#if defined(__d3d12_x_h__) || defined(__d3d12_xs_h__) || defined(__d3d12_h__) + +inline void PIXSetGPUMarkerOnContext(_In_ ID3D12GraphicsCommandList* commandList, _In_reads_bytes_(size) void* data, UINT size) +{ + commandList->SetMarker(D3D12_EVENT_METADATA, data, size); +} + +inline void PIXSetGPUMarkerOnContext(_In_ ID3D12CommandQueue* commandQueue, _In_reads_bytes_(size) void* data, UINT size) +{ + commandQueue->SetMarker(D3D12_EVENT_METADATA, data, size); +} + +inline void PIXBeginGPUEventOnContext(_In_ ID3D12GraphicsCommandList* commandList, _In_reads_bytes_(size) void* data, UINT size) +{ + commandList->BeginEvent(D3D12_EVENT_METADATA, data, size); +} + +inline void PIXBeginGPUEventOnContext(_In_ ID3D12CommandQueue* commandQueue, _In_reads_bytes_(size) void* data, UINT size) +{ + commandQueue->BeginEvent(D3D12_EVENT_METADATA, data, size); +} + +inline void PIXEndGPUEventOnContext(_In_ ID3D12GraphicsCommandList* commandList) +{ + commandList->EndEvent(); +} + +inline void PIXEndGPUEventOnContext(_In_ ID3D12CommandQueue* commandQueue) +{ + commandQueue->EndEvent(); +} + +#endif //__d3d12_h__ + +template struct PIXInferScopedEventType { typedef T Type; }; +template struct PIXInferScopedEventType { typedef T Type; }; +template struct PIXInferScopedEventType { typedef T Type; }; +template struct PIXInferScopedEventType { typedef T Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; +template<> struct PIXInferScopedEventType { typedef void Type; }; + +#endif //_PIXEventsCommon_H_ diff --git a/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/PIXEventsLegacy.h b/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/PIXEventsLegacy.h new file mode 100644 index 0000000..5323013 --- /dev/null +++ b/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/PIXEventsLegacy.h @@ -0,0 +1,565 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// Don't include this file directly - use pix3.h +// This file encodes PIX events in the legacy PIX event format. + +#ifndef _PIXEventsLegacy_H_ +#define _PIXEventsLegacy_H_ + +#include + +#if defined(_M_X64) || defined(_M_IX86) +#include +#endif + +namespace PixEventsLegacy +{ + enum PIXEventType + { + PIXEvent_EndEvent = 0x000, + PIXEvent_BeginEvent_VarArgs = 0x001, + PIXEvent_BeginEvent_NoArgs = 0x002, + PIXEvent_SetMarker_VarArgs = 0x007, + PIXEvent_SetMarker_NoArgs = 0x008, + + PIXEvent_EndEvent_OnContext = 0x010, + PIXEvent_BeginEvent_OnContext_VarArgs = 0x011, + PIXEvent_BeginEvent_OnContext_NoArgs = 0x012, + PIXEvent_SetMarker_OnContext_VarArgs = 0x017, + PIXEvent_SetMarker_OnContext_NoArgs = 0x018, + }; + + static const UINT64 PIXEventsReservedRecordSpaceQwords = 64; + static const UINT64 PIXEventsReservedTailSpaceQwords = 2; + static const UINT64 PIXEventsSafeFastCopySpaceQwords = PIXEventsReservedRecordSpaceQwords - PIXEventsReservedTailSpaceQwords; + static const UINT64 PIXEventsGraphicsRecordSpaceQwords = 64; + + //Bits 7-19 (13 bits) + static const UINT64 PIXEventsBlockEndMarker = 0x00000000000FFF80; + + //Bits 10-19 (10 bits) + static const UINT64 PIXEventsTypeReadMask = 0x00000000000FFC00; + static const UINT64 PIXEventsTypeWriteMask = 0x00000000000003FF; + static const UINT64 PIXEventsTypeBitShift = 10; + + //Bits 20-63 (44 bits) + static const UINT64 PIXEventsTimestampReadMask = 0xFFFFFFFFFFF00000; + static const UINT64 PIXEventsTimestampWriteMask = 0x00000FFFFFFFFFFF; + static const UINT64 PIXEventsTimestampBitShift = 20; + + inline UINT64 PIXEncodeEventInfo(UINT64 timestamp, PIXEventType eventType) + { + return ((timestamp & PIXEventsTimestampWriteMask) << PIXEventsTimestampBitShift) | + (((UINT64)eventType & PIXEventsTypeWriteMask) << PIXEventsTypeBitShift); + } + + //Bits 60-63 (4) + static const UINT64 PIXEventsStringAlignmentWriteMask = 0x000000000000000F; + static const UINT64 PIXEventsStringAlignmentReadMask = 0xF000000000000000; + static const UINT64 PIXEventsStringAlignmentBitShift = 60; + + //Bits 55-59 (5) + static const UINT64 PIXEventsStringCopyChunkSizeWriteMask = 0x000000000000001F; + static const UINT64 PIXEventsStringCopyChunkSizeReadMask = 0x0F80000000000000; + static const UINT64 PIXEventsStringCopyChunkSizeBitShift = 55; + + //Bit 54 + static const UINT64 PIXEventsStringIsANSIWriteMask = 0x0000000000000001; + static const UINT64 PIXEventsStringIsANSIReadMask = 0x0040000000000000; + static const UINT64 PIXEventsStringIsANSIBitShift = 54; + + //Bit 53 + static const UINT64 PIXEventsStringIsShortcutWriteMask = 0x0000000000000001; + static const UINT64 PIXEventsStringIsShortcutReadMask = 0x0020000000000000; + static const UINT64 PIXEventsStringIsShortcutBitShift = 53; + + inline UINT64 PIXEncodeStringInfo(UINT64 alignment, UINT64 copyChunkSize, BOOL isANSI, BOOL isShortcut) + { + return ((alignment & PIXEventsStringAlignmentWriteMask) << PIXEventsStringAlignmentBitShift) | + ((copyChunkSize & PIXEventsStringCopyChunkSizeWriteMask) << PIXEventsStringCopyChunkSizeBitShift) | + (((UINT64)isANSI & PIXEventsStringIsANSIWriteMask) << PIXEventsStringIsANSIBitShift) | + (((UINT64)isShortcut & PIXEventsStringIsShortcutWriteMask) << PIXEventsStringIsShortcutBitShift); + } + + template + inline bool PIXIsPointerAligned(T* pointer) + { + return !(((UINT64)pointer) & (alignment - 1)); + } + + // Generic template version slower because of the additional clear write + template + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, T argument) + { + if (destination < limit) + { + *destination = 0ull; + *((T*)destination) = argument; + ++destination; + } + } + + // int32 specialization to avoid slower double memory writes + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, INT32 argument) + { + if (destination < limit) + { + *reinterpret_cast(destination) = static_cast(argument); + ++destination; + } + } + + // unsigned int32 specialization to avoid slower double memory writes + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, UINT32 argument) + { + if (destination < limit) + { + *destination = static_cast(argument); + ++destination; + } + } + + // int64 specialization to avoid slower double memory writes + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, INT64 argument) + { + if (destination < limit) + { + *reinterpret_cast(destination) = argument; + ++destination; + } + } + + // unsigned int64 specialization to avoid slower double memory writes + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, UINT64 argument) + { + if (destination < limit) + { + *destination = argument; + ++destination; + } + } + + //floats must be cast to double during writing the data to be properly printed later when reading the data + //this is needed because when float is passed to varargs function it's cast to double + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, float argument) + { + if (destination < limit) + { + *reinterpret_cast(destination) = static_cast(argument); + ++destination; + } + } + + //char has to be cast to a longer signed integer type + //this is due to printf not ignoring correctly the upper bits of unsigned long long for a char format specifier + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, char argument) + { + if (destination < limit) + { + *reinterpret_cast(destination) = static_cast(argument); + ++destination; + } + } + + //unsigned char has to be cast to a longer unsigned integer type + //this is due to printf not ignoring correctly the upper bits of unsigned long long for a char format specifier + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, unsigned char argument) + { + if (destination < limit) + { + *destination = static_cast(argument); + ++destination; + } + } + + //bool has to be cast to an integer since it's not explicitly supported by string format routines + //there's no format specifier for bool type, but it should work with integer format specifiers + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, bool argument) + { + if (destination < limit) + { + *destination = static_cast(argument); + ++destination; + } + } + + inline void PIXCopyEventArgumentSlowest(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCSTR argument) + { + *destination++ = PIXEncodeStringInfo(0, 8, TRUE, FALSE); + while (destination < limit) + { + UINT64 c = static_cast(argument[0]); + if (!c) + { + *destination++ = 0; + return; + } + UINT64 x = c; + c = static_cast(argument[1]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 8; + c = static_cast(argument[2]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 16; + c = static_cast(argument[3]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 24; + c = static_cast(argument[4]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 32; + c = static_cast(argument[5]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 40; + c = static_cast(argument[6]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 48; + c = static_cast(argument[7]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 56; + *destination++ = x; + argument += 8; + } + } + + inline void PIXCopyEventArgumentSlow(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCSTR argument) + { +#if PIX_ENABLE_BLOCK_ARGUMENT_COPY + if (PIXIsPointerAligned<8>(argument)) + { + *destination++ = PIXEncodeStringInfo(0, 8, TRUE, FALSE); + UINT64* source = (UINT64*)argument; + while (destination < limit) + { + UINT64 qword = *source++; + *destination++ = qword; + //check if any of the characters is a terminating zero + if (!((qword & 0xFF00000000000000) && + (qword & 0xFF000000000000) && + (qword & 0xFF0000000000) && + (qword & 0xFF00000000) && + (qword & 0xFF000000) && + (qword & 0xFF0000) && + (qword & 0xFF00) && + (qword & 0xFF))) + { + break; + } + } + } + else +#endif // PIX_ENABLE_BLOCK_ARGUMENT_COPY + { + PIXCopyEventArgumentSlowest(destination, limit, argument); + } + } + + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCSTR argument) + { + if (destination < limit) + { + if (argument != nullptr) + { +#if (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + if (PIXIsPointerAligned<16>(argument)) + { + *destination++ = PIXEncodeStringInfo(0, 16, TRUE, FALSE); + __m128i zero = _mm_setzero_si128(); + if (PIXIsPointerAligned<16>(destination)) + { + while (destination < limit) + { + __m128i mem = _mm_load_si128((__m128i*)argument); + _mm_store_si128((__m128i*)destination, mem); + //check if any of the characters is a terminating zero + __m128i res = _mm_cmpeq_epi8(mem, zero); + destination += 2; + if (_mm_movemask_epi8(res)) + break; + argument += 16; + } + } + else + { + while (destination < limit) + { + __m128i mem = _mm_load_si128((__m128i*)argument); + _mm_storeu_si128((__m128i*)destination, mem); + //check if any of the characters is a terminating zero + __m128i res = _mm_cmpeq_epi8(mem, zero); + destination += 2; + if (_mm_movemask_epi8(res)) + break; + argument += 16; + } + } + } + else +#endif // (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + { + PIXCopyEventArgumentSlow(destination, limit, argument); + } + } + else + { + *destination++ = 0ull; + } + } + } + + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PSTR argument) + { + PIXCopyEventArgument(destination, limit, (PCSTR)argument); + } + + inline void PIXCopyEventArgumentSlowest(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCWSTR argument) + { + *destination++ = PIXEncodeStringInfo(0, 8, FALSE, FALSE); + while (destination < limit) + { + UINT64 c = static_cast(argument[0]); + if (!c) + { + *destination++ = 0; + return; + } + UINT64 x = c; + c = static_cast(argument[1]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 16; + c = static_cast(argument[2]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 32; + c = static_cast(argument[3]); + if (!c) + { + *destination++ = x; + return; + } + x |= c << 48; + *destination++ = x; + argument += 4; + } + } + + inline void PIXCopyEventArgumentSlow(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCWSTR argument) + { +#if PIX_ENABLE_BLOCK_ARGUMENT_COPY + if (PIXIsPointerAligned<8>(argument)) + { + *destination++ = PIXEncodeStringInfo(0, 8, FALSE, FALSE); + UINT64* source = (UINT64*)argument; + while (destination < limit) + { + UINT64 qword = *source++; + *destination++ = qword; + //check if any of the characters is a terminating zero + //TODO: check if reversed condition is faster + if (!((qword & 0xFFFF000000000000) && + (qword & 0xFFFF00000000) && + (qword & 0xFFFF0000) && + (qword & 0xFFFF))) + { + break; + } + } + } + else +#endif // PIX_ENABLE_BLOCK_ARGUMENT_COPY + { + PIXCopyEventArgumentSlowest(destination, limit, argument); + } + } + + template<> + inline void PIXCopyEventArgument(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, _In_ PCWSTR argument) + { + if (destination < limit) + { + if (argument != nullptr) + { +#if (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + if (PIXIsPointerAligned<16>(argument)) + { + *destination++ = PIXEncodeStringInfo(0, 16, FALSE, FALSE); + __m128i zero = _mm_setzero_si128(); + if (PIXIsPointerAligned<16>(destination)) + { + while (destination < limit) + { + __m128i mem = _mm_load_si128((__m128i*)argument); + _mm_store_si128((__m128i*)destination, mem); + //check if any of the characters is a terminating zero + __m128i res = _mm_cmpeq_epi16(mem, zero); + destination += 2; + if (_mm_movemask_epi8(res)) + break; + argument += 8; + } + } + else + { + while (destination < limit) + { + __m128i mem = _mm_load_si128((__m128i*)argument); + _mm_storeu_si128((__m128i*)destination, mem); + //check if any of the characters is a terminating zero + __m128i res = _mm_cmpeq_epi16(mem, zero); + destination += 2; + if (_mm_movemask_epi8(res)) + break; + argument += 8; + } + } + } + else +#endif // (defined(_M_X64) || defined(_M_IX86)) && PIX_ENABLE_BLOCK_ARGUMENT_COPY + { + PIXCopyEventArgumentSlow(destination, limit, argument); + } + } + else + { + *destination++ = 0ull; + } + } + } + + inline void PIXCopyEventArguments(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit) + { + // nothing + UNREFERENCED_PARAMETER(destination); + UNREFERENCED_PARAMETER(limit); + } + + template + void PIXCopyEventArguments(_Out_writes_to_ptr_(limit) UINT64*& destination, _In_ const UINT64* limit, ARG const& arg, ARGS const&... args) + { + PIXCopyEventArgument(destination, limit, arg); + PIXCopyEventArguments(destination, limit, args...); + } + + template + struct PIXEventTypeInferer + { + static constexpr PIXEventType Begin() { return PIXEvent_BeginEvent_VarArgs; } + static constexpr PIXEventType SetMarker() { return PIXEvent_SetMarker_VarArgs; } + static constexpr PIXEventType BeginOnContext() { return PIXEvent_BeginEvent_OnContext_VarArgs; } + static constexpr PIXEventType SetMarkerOnContext() { return PIXEvent_SetMarker_OnContext_VarArgs; } + static constexpr PIXEventType End() { return PIXEvent_EndEvent; } + + // Xbox and Windows store different types of events for context events. + // On Xbox these include a context argument, while on Windows they do + // not. It is important not to change the event types used on the + // Windows version as there are OS components (eg debug layer & DRED) + // that decode event structs. +#ifdef PIX_XBOX + static constexpr PIXEventType GpuBeginOnContext() { return PIXEvent_BeginEvent_OnContext_VarArgs; } + static constexpr PIXEventType GpuSetMarkerOnContext() { return PIXEvent_SetMarker_OnContext_VarArgs; } + static constexpr PIXEventType GpuEndOnContext() { return PIXEvent_EndEvent_OnContext; } +#else + static constexpr PIXEventType GpuBeginOnContext() { return PIXEvent_BeginEvent_VarArgs; } + static constexpr PIXEventType GpuSetMarkerOnContext() { return PIXEvent_SetMarker_VarArgs; } + static constexpr PIXEventType GpuEndOnContext() { return PIXEvent_EndEvent; } +#endif + }; + + template<> + struct PIXEventTypeInferer<> + { + static constexpr PIXEventType Begin() { return PIXEvent_BeginEvent_NoArgs; } + static constexpr PIXEventType SetMarker() { return PIXEvent_SetMarker_NoArgs; } + static constexpr PIXEventType BeginOnContext() { return PIXEvent_BeginEvent_OnContext_NoArgs; } + static constexpr PIXEventType SetMarkerOnContext() { return PIXEvent_SetMarker_OnContext_NoArgs; } + static constexpr PIXEventType End() { return PIXEvent_EndEvent; } + +#ifdef PIX_XBOX + static constexpr PIXEventType GpuBeginOnContext() { return PIXEvent_BeginEvent_OnContext_NoArgs; } + static constexpr PIXEventType GpuSetMarkerOnContext() { return PIXEvent_SetMarker_OnContext_NoArgs; } + static constexpr PIXEventType GpuEndOnContext() { return PIXEvent_EndEvent_OnContext; } +#else + static constexpr PIXEventType GpuBeginOnContext() { return PIXEvent_BeginEvent_NoArgs; } + static constexpr PIXEventType GpuSetMarkerOnContext() { return PIXEvent_SetMarker_NoArgs; } + static constexpr PIXEventType GpuEndOnContext() { return PIXEvent_EndEvent; } +#endif + }; + + + template + UINT64* EncodeBeginEventForContext(UINT64 (&buffer)[size], UINT64 color, STR formatString, ARGS... args) + { + UINT64* destination = buffer; + UINT64* limit = buffer + PIXEventsGraphicsRecordSpaceQwords - PIXEventsReservedTailSpaceQwords; + + *destination++ = PIXEncodeEventInfo(0, PIXEventTypeInferer::GpuBeginOnContext()); + *destination++ = color; + + PIXCopyEventArguments(destination, limit, formatString, args...); + *destination = 0ull; + + return destination; + } + + template + UINT64* EncodeSetMarkerForContext(UINT64 (&buffer)[size], UINT64 color, STR formatString, ARGS... args) + { + UINT64* destination = buffer; + UINT64* limit = buffer + PIXEventsGraphicsRecordSpaceQwords - PIXEventsReservedTailSpaceQwords; + + *destination++ = PIXEncodeEventInfo(0, PIXEventTypeInferer::GpuSetMarkerOnContext()); + *destination++ = color; + + PIXCopyEventArguments(destination, limit, formatString, args...); + *destination = 0ull; + + return destination; + } +} + +#endif //_PIXEventsLegacy_H_ diff --git a/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/pix3.h b/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/pix3.h new file mode 100644 index 0000000..13126c4 --- /dev/null +++ b/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/pix3.h @@ -0,0 +1,195 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#pragma once + +#ifndef _PIX3_H_ +#define _PIX3_H_ + +#include + +#ifndef __cplusplus +#error "Only C++ files can include pix3.h. C is not supported." +#endif + +#if !defined(USE_PIX_SUPPORTED_ARCHITECTURE) +#if defined(_M_X64) || defined(USE_PIX_ON_ALL_ARCHITECTURES) || defined(_M_ARM64) +#define USE_PIX_SUPPORTED_ARCHITECTURE +#endif +#endif + +#if !defined(USE_PIX) +#if defined(USE_PIX_SUPPORTED_ARCHITECTURE) && (defined(_DEBUG) || DBG || defined(PROFILE) || defined(PROFILE_BUILD)) && !defined(_PREFAST_) +#define USE_PIX +#endif +#endif + +#if defined(USE_PIX) && !defined(USE_PIX_SUPPORTED_ARCHITECTURE) +#pragma message("Warning: Pix markers are only supported on AMD64 and ARM64") +#endif + + +// These flags are used by both PIXBeginCapture and PIXGetCaptureState +#define PIX_CAPTURE_TIMING (1 << 0) +#define PIX_CAPTURE_GPU (1 << 1) +#define PIX_CAPTURE_FUNCTION_SUMMARY (1 << 2) +#define PIX_CAPTURE_FUNCTION_DETAILS (1 << 3) +#define PIX_CAPTURE_CALLGRAPH (1 << 4) +#define PIX_CAPTURE_INSTRUCTION_TRACE (1 << 5) +#define PIX_CAPTURE_SYSTEM_MONITOR_COUNTERS (1 << 6) +#define PIX_CAPTURE_VIDEO (1 << 7) +#define PIX_CAPTURE_AUDIO (1 << 8) +#define PIX_CAPTURE_GPU_TRACE (1 << 9) +#define PIX_CAPTURE_RESERVED (1 << 15) + +union PIXCaptureParameters +{ + enum PIXCaptureStorage + { + Memory = 0, + MemoryCircular = 1, // Xbox only + FileCircular = 2, // PC only + }; + + struct GpuCaptureParameters + { + PCWSTR FileName; + } GpuCaptureParameters; + + struct TimingCaptureParameters + { + PCWSTR FileName; + UINT32 MaximumToolingMemorySizeMb; + PIXCaptureStorage CaptureStorage; + + BOOL CaptureGpuTiming; + + BOOL CaptureCallstacks; + BOOL CaptureCpuSamples; + UINT32 CpuSamplesPerSecond; + + BOOL CaptureFileIO; + + BOOL CaptureVirtualAllocEvents; + BOOL CaptureHeapAllocEvents; + BOOL CaptureXMemEvents; // Xbox only + BOOL CapturePixMemEvents; + BOOL CapturePageFaultEvents; + BOOL CaptureVideoFrames; // Xbox only + } TimingCaptureParameters; + + struct GpuTraceParameters // Xbox Series and newer only + { + PWSTR FileName; + UINT32 MaximumToolingMemorySizeMb; + + BOOL CaptureGpuOccupancy; + + } GpuTraceParameters; +}; + +typedef PIXCaptureParameters* PPIXCaptureParameters; + +#if defined(XBOX) || defined(_XBOX_ONE) || defined(_DURANGO) || defined(_GAMING_XBOX) || defined(_GAMING_XBOX_SCARLETT) +#include "pix3_xbox.h" +#else +#include "pix3_win.h" +#endif + +#if defined(XBOX) || defined(_XBOX_ONE) || defined(_DURANGO) || defined(_GAMING_XBOX) || defined(_GAMING_XBOX_SCARLETT) +#define PIX_XBOX +#if defined(_GAMING_XBOX) || defined(_GAMING_XBOX_SCARLETT) +#define PIX_GAMING_XBOX +#endif +#endif + +#if !defined(PIX_USE_GPU_MARKERS_V2) +#ifdef PIX_GAMING_XBOX +#define PIX_USE_GPU_MARKERS_V2 +#endif +#endif + +#if defined(USE_PIX_SUPPORTED_ARCHITECTURE) && (defined(USE_PIX) || defined(USE_PIX_RETAIL)) + +#define PIX_EVENTS_ARE_TURNED_ON + +#include "PIXEventsCommon.h" +#include "PIXEvents.h" + +#ifdef USE_PIX +// Starts a programmatically controlled capture. +// captureFlags uses the PIX_CAPTURE_* family of flags to specify the type of capture to take +extern "C" HRESULT WINAPI PIXBeginCapture2(DWORD captureFlags, _In_opt_ const PPIXCaptureParameters captureParameters); +inline HRESULT PIXBeginCapture(DWORD captureFlags, _In_opt_ const PPIXCaptureParameters captureParameters) { return PIXBeginCapture2(captureFlags, captureParameters); } + +// Stops a programmatically controlled capture +// If discard == TRUE, the captured data is discarded +// If discard == FALSE, the captured data is saved +// discard parameter is not supported on Windows +extern "C" HRESULT WINAPI PIXEndCapture(BOOL discard); + +extern "C" DWORD WINAPI PIXGetCaptureState(); + +extern "C" void WINAPI PIXReportCounter(_In_ PCWSTR name, float value); + +#endif // USE_PIX + +#endif // (USE_PIX_SUPPORTED_ARCHITECTURE) && (USE_PIX || USE_PIX_RETAIL) + +#if !defined(USE_PIX_SUPPORTED_ARCHITECTURE) || !defined(USE_PIX) + +// Eliminate these APIs when not using PIX +inline HRESULT PIXBeginCapture2(DWORD, _In_opt_ const PIXCaptureParameters*) { return S_OK; } +inline HRESULT PIXBeginCapture(DWORD, _In_opt_ const PIXCaptureParameters*) { return S_OK; } +inline HRESULT PIXEndCapture(BOOL) { return S_OK; } +inline HRESULT PIXGpuCaptureNextFrames(PCWSTR, UINT32) { return S_OK; } +inline HRESULT PIXSetTargetWindow(HWND) { return S_OK; } +inline HRESULT PIXForceD3D11On12() { return S_OK; } +inline HRESULT WINAPI PIXSetHUDOptions(PIXHUDOptions) { return S_OK; } +inline bool WINAPI PIXIsAttachedForGpuCapture() { return false; } +inline HINSTANCE WINAPI PIXOpenCaptureInUI(PCWSTR) { return 0; } +inline HMODULE PIXLoadLatestWinPixGpuCapturerLibrary() { return nullptr; } +inline HMODULE PIXLoadLatestWinPixTimingCapturerLibrary() { return nullptr; } +inline DWORD PIXGetCaptureState() { return 0; } +inline void PIXReportCounter(_In_ PCWSTR, float) {} +inline void PIXNotifyWakeFromFenceSignal(_In_ HANDLE) {} + +#if !defined(USE_PIX_RETAIL) + +inline void PIXBeginEvent(UINT64, _In_ PCSTR, ...) {} +inline void PIXBeginEvent(UINT64, _In_ PCWSTR, ...) {} +inline void PIXBeginEvent(void*, UINT64, _In_ PCSTR, ...) {} +inline void PIXBeginEvent(void*, UINT64, _In_ PCWSTR, ...) {} +inline void PIXEndEvent() {} +inline void PIXEndEvent(void*) {} +inline void PIXSetMarker(UINT64, _In_ PCSTR, ...) {} +inline void PIXSetMarker(UINT64, _In_ PCWSTR, ...) {} +inline void PIXSetMarker(void*, UINT64, _In_ PCSTR, ...) {} +inline void PIXSetMarker(void*, UINT64, _In_ PCWSTR, ...) {} +inline void PIXBeginRetailEvent(void*, UINT64, _In_ PCSTR, ...) {} +inline void PIXBeginRetailEvent(void*, UINT64, _In_ PCWSTR, ...) {} +inline void PIXEndRetailEvent(void*) {} +inline void PIXSetRetailMarker(void*, UINT64, _In_ PCSTR, ...) {} +inline void PIXSetRetailMarker(void*, UINT64, _In_ PCWSTR, ...) {} +inline void PIXScopedEvent(UINT64, _In_ PCSTR, ...) {} +inline void PIXScopedEvent(UINT64, _In_ PCWSTR, ...) {} +inline void PIXScopedEvent(void*, UINT64, _In_ PCSTR, ...) {} +inline void PIXScopedEvent(void*, UINT64, _In_ PCWSTR, ...) {} + +#endif // !USE_PIX_RETAIL + +// don't show warnings about expressions with no effect +#pragma warning(disable:4548) +#pragma warning(disable:4555) + +#endif // !USE_PIX_SUPPORTED_ARCHITECTURE || !USE_PIX + +// Use these functions to specify colors to pass as metadata to a PIX event/marker API. +// Use PIX_COLOR() to specify a particular color for an event. +// Or, use PIX_COLOR_INDEX() to specify a set of unique event categories, and let PIX choose +// the colors to represent each category. +inline UINT32 PIX_COLOR(UINT8 r, UINT8 g, UINT8 b) { return 0xff000000u | ((UINT32)r << 16) | ((UINT32)g << 8) | (UINT32)b; } +inline UINT8 PIX_COLOR_INDEX(UINT8 i) { return i; } +const UINT8 PIX_COLOR_DEFAULT = PIX_COLOR_INDEX(0); + +#endif // _PIX3_H_ diff --git a/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/pix3_win.h b/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/pix3_win.h new file mode 100644 index 0000000..121c40c --- /dev/null +++ b/Kinc/Backends/Graphics5/Direct3D12/pix/Include/WinPixEventRuntime/pix3_win.h @@ -0,0 +1,509 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// Don't include this file directly - use pix3.h + +#pragma once + +#ifndef _PIX3_H_ +#error Don't include this file directly - use pix3.h +#endif + +#ifndef _PIX3_WIN_H_ +#define _PIX3_WIN_H_ + +// PIXEventsThreadInfo is defined in PIXEventsCommon.h +struct PIXEventsThreadInfo; + +extern "C" PIXEventsThreadInfo* WINAPI PIXGetThreadInfo() noexcept; + +#if defined(USE_PIX) && defined(USE_PIX_SUPPORTED_ARCHITECTURE) +// Notifies PIX that an event handle was set as a result of a D3D12 fence being signaled. +// The event specified must have the same handle value as the handle +// used in ID3D12Fence::SetEventOnCompletion. +extern "C" void WINAPI PIXNotifyWakeFromFenceSignal(_In_ HANDLE event); + +// Notifies PIX that a block of memory was allocated +extern "C" void WINAPI PIXRecordMemoryAllocationEvent(USHORT allocatorId, void* baseAddress, size_t size, UINT64 metadata); + +// Notifies PIX that a block of memory was freed +extern "C" void WINAPI PIXRecordMemoryFreeEvent(USHORT allocatorId, void* baseAddress, size_t size, UINT64 metadata); + +#else + +// Eliminate these APIs when not using PIX +inline void PIXRecordMemoryAllocationEvent(USHORT, void*, size_t, UINT64) {} +inline void PIXRecordMemoryFreeEvent(USHORT, void*, size_t, UINT64) {} + +#endif + +// The following WINPIX_EVENT_* defines denote the different metadata values that have +// been used by tools to denote how to parse pix marker event data. The first two values +// are legacy values used by pix.h in the Windows SDK. +#define WINPIX_EVENT_UNICODE_VERSION 0 +#define WINPIX_EVENT_ANSI_VERSION 1 + +// These values denote PIX marker event data that was created by the WinPixEventRuntime. +// In early 2023 we revised the PIX marker format and defined a new version number. +#define WINPIX_EVENT_PIX3BLOB_VERSION 2 +#define WINPIX_EVENT_PIX3BLOB_V2 6345127 // A number that other applications are unlikely to have used before + +// For backcompat reasons, the WinPixEventRuntime uses the older PIX3BLOB format when it passes data +// into the D3D12 runtime. It will be updated to use the V2 format in the future. +#define D3D12_EVENT_METADATA WINPIX_EVENT_PIX3BLOB_VERSION + +__forceinline UINT64 PIXGetTimestampCounter() +{ + LARGE_INTEGER time = {}; + QueryPerformanceCounter(&time); + return static_cast(time.QuadPart); +} + +enum PIXHUDOptions +{ + PIX_HUD_SHOW_ON_ALL_WINDOWS = 0x1, + PIX_HUD_SHOW_ON_TARGET_WINDOW_ONLY = 0x2, + PIX_HUD_SHOW_ON_NO_WINDOWS = 0x4 +}; +DEFINE_ENUM_FLAG_OPERATORS(PIXHUDOptions); + +#if defined(USE_PIX_SUPPORTED_ARCHITECTURE) && defined(USE_PIX) + +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM | WINAPI_PARTITION_GAMES) + +#include +#include +#include +#include + +#define PIXERRORCHECK(value) do { \ + if (FAILED(value)) \ + return nullptr; \ + } while(0) + +namespace PixImpl +{ +#ifndef PIX3_WIN_UNIT_TEST + + __forceinline BOOL GetModuleHandleExW( + DWORD dwFlags, + LPCWSTR lpModuleName, + HMODULE* phModule) + { + return ::GetModuleHandleExW(dwFlags, lpModuleName, phModule); + } + + __forceinline HRESULT SHGetKnownFolderPath( + REFKNOWNFOLDERID rfid, + DWORD dwFlags, + HANDLE hToken, + PWSTR* ppszPath) + { + return ::SHGetKnownFolderPath(rfid, dwFlags, hToken, ppszPath); + } + + __forceinline void CoTaskMemFree(LPVOID pv) + { + return ::CoTaskMemFree(pv); + } + + __forceinline HANDLE FindFirstFileW( + LPCWSTR lpFileName, + LPWIN32_FIND_DATAW lpFindFileData) + { + return ::FindFirstFileW(lpFileName, lpFindFileData); + } + + __forceinline DWORD GetFileAttributesW(LPCWSTR lpFileName) + { + return ::GetFileAttributesW(lpFileName); + } + + __forceinline BOOL FindNextFileW( + HANDLE hFindFile, + LPWIN32_FIND_DATAW lpFindFileData) + { + return ::FindNextFileW(hFindFile, lpFindFileData); + } + + __forceinline BOOL FindClose(HANDLE hFindFile) + { + return ::FindClose(hFindFile); + } + + __forceinline HMODULE LoadLibraryExW(LPCWSTR lpLibFileName, DWORD flags) + { + return ::LoadLibraryExW(lpLibFileName, NULL, flags); + } + +#endif // !PIX3_WIN_UNIT_TESTS + + __forceinline void * GetGpuCaptureFunctionPtr(LPCSTR fnName) noexcept + { + HMODULE module = GetModuleHandleW(L"WinPixGpuCapturer.dll"); + if (module == NULL) + { + return nullptr; + } + + auto fn = (void*)GetProcAddress(module, fnName); + if (fn == nullptr) + { + return nullptr; + } + + return fn; + } + + __forceinline void* GetTimingCaptureFunctionPtr(LPCSTR fnName) noexcept + { + HMODULE module = GetModuleHandleW(L"WinPixTimingCapturer.dll"); + if (module == NULL) + { + return nullptr; + } + + auto fn = (void*)GetProcAddress(module, fnName); + if (fn == nullptr) + { + return nullptr; + } + + return fn; + } + + __forceinline HMODULE PIXLoadLatestCapturerLibrary(wchar_t const* capturerDllName, DWORD flags) + { + HMODULE libHandle{}; + + if (PixImpl::GetModuleHandleExW(0, capturerDllName, &libHandle)) + { + return libHandle; + } + + LPWSTR programFilesPath = nullptr; + if (FAILED(PixImpl::SHGetKnownFolderPath(FOLDERID_ProgramFiles, KF_FLAG_DEFAULT, NULL, &programFilesPath))) + { + PixImpl::CoTaskMemFree(programFilesPath); + return nullptr; + } + + wchar_t pixSearchPath[MAX_PATH]; + + if (FAILED(StringCchCopyW(pixSearchPath, MAX_PATH, programFilesPath))) + { + PixImpl::CoTaskMemFree(programFilesPath); + return nullptr; + } + PixImpl::CoTaskMemFree(programFilesPath); + + PIXERRORCHECK(StringCchCatW(pixSearchPath, MAX_PATH, L"\\Microsoft PIX\\*")); + + WIN32_FIND_DATAW findData; + bool foundPixInstallation = false; + wchar_t newestVersionFound[MAX_PATH]; + wchar_t output[MAX_PATH]; + wchar_t possibleOutput[MAX_PATH]; + + HANDLE hFind = PixImpl::FindFirstFileW(pixSearchPath, &findData); + if (hFind != INVALID_HANDLE_VALUE) + { + do + { + if (((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) && + (findData.cFileName[0] != '.')) + { + if (!foundPixInstallation || wcscmp(newestVersionFound, findData.cFileName) <= 0) + { + // length - 1 to get rid of the wildcard character in the search path + PIXERRORCHECK(StringCchCopyNW(possibleOutput, MAX_PATH, pixSearchPath, wcslen(pixSearchPath) - 1)); + PIXERRORCHECK(StringCchCatW(possibleOutput, MAX_PATH, findData.cFileName)); + PIXERRORCHECK(StringCchCatW(possibleOutput, MAX_PATH, L"\\")); + PIXERRORCHECK(StringCchCatW(possibleOutput, MAX_PATH, capturerDllName)); + + DWORD result = PixImpl::GetFileAttributesW(possibleOutput); + + if (result != INVALID_FILE_ATTRIBUTES && !(result & FILE_ATTRIBUTE_DIRECTORY)) + { + foundPixInstallation = true; + PIXERRORCHECK(StringCchCopyW(newestVersionFound, _countof(newestVersionFound), findData.cFileName)); + PIXERRORCHECK(StringCchCopyW(output, _countof(possibleOutput), possibleOutput)); + } + } + } + } while (PixImpl::FindNextFileW(hFind, &findData) != 0); + } + + PixImpl::FindClose(hFind); + + if (!foundPixInstallation) + { + SetLastError(ERROR_FILE_NOT_FOUND); + return nullptr; + } + + return PixImpl::LoadLibraryExW(output, flags); + } +} + +#undef PIXERRORCHECK + +__forceinline HMODULE PIXLoadLatestWinPixGpuCapturerLibrary() +{ + return PixImpl::PIXLoadLatestCapturerLibrary( + L"WinPixGpuCapturer.dll", + LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); +} + +__forceinline HMODULE PIXLoadLatestWinPixTimingCapturerLibrary() +{ + return PixImpl::PIXLoadLatestCapturerLibrary( + L"WinPixTimingCapturer.dll", + LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); +} + +__forceinline HRESULT WINAPI PIXSetTargetWindow(HWND hwnd) +{ + typedef void(WINAPI* SetGlobalTargetWindowFn)(HWND); + + auto fn = (SetGlobalTargetWindowFn)PixImpl::GetGpuCaptureFunctionPtr("SetGlobalTargetWindow"); + if (fn == nullptr) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + + fn(hwnd); + return S_OK; +} + +__forceinline HRESULT WINAPI PIXGpuCaptureNextFrames(PCWSTR fileName, UINT32 numFrames) +{ + typedef HRESULT(WINAPI* CaptureNextFrameFn)(PCWSTR, UINT32); + + auto fn = (CaptureNextFrameFn)PixImpl::GetGpuCaptureFunctionPtr("CaptureNextFrame"); + if (fn == nullptr) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + + return fn(fileName, numFrames); +} + +extern "C" __forceinline HRESULT WINAPI PIXBeginCapture2(DWORD captureFlags, _In_opt_ const PPIXCaptureParameters captureParameters) +{ + if (captureFlags == PIX_CAPTURE_GPU) + { + typedef HRESULT(WINAPI* BeginProgrammaticGpuCaptureFn)(const PPIXCaptureParameters); + + auto fn = (BeginProgrammaticGpuCaptureFn)PixImpl::GetGpuCaptureFunctionPtr("BeginProgrammaticGpuCapture"); + if (fn == nullptr) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + + return fn(captureParameters); + } + else if (captureFlags == PIX_CAPTURE_TIMING) + { + typedef HRESULT(WINAPI* BeginProgrammaticTimingCaptureFn)(void const*, UINT64); + + auto fn = (BeginProgrammaticTimingCaptureFn)PixImpl::GetTimingCaptureFunctionPtr("BeginProgrammaticTimingCapture"); + if (fn == nullptr) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + + return fn(&captureParameters->TimingCaptureParameters, sizeof(captureParameters->TimingCaptureParameters)); + } + else + { + return E_NOTIMPL; + } +} + +extern "C" __forceinline HRESULT WINAPI PIXEndCapture(BOOL discard) +{ + // We can't tell if the user wants to end a GPU Capture or a Timing Capture. + // The user shouldn't have both WinPixGpuCapturer and WinPixTimingCapturer loaded in the process though, + // so we can just look for one of them and call it. + typedef HRESULT(WINAPI* EndProgrammaticGpuCaptureFn)(void); + auto gpuFn = (EndProgrammaticGpuCaptureFn)PixImpl::GetGpuCaptureFunctionPtr("EndProgrammaticGpuCapture"); + if (gpuFn != NULL) + { + return gpuFn(); + } + + typedef HRESULT(WINAPI* EndProgrammaticTimingCaptureFn)(BOOL); + auto timingFn = (EndProgrammaticTimingCaptureFn)PixImpl::GetTimingCaptureFunctionPtr("EndProgrammaticTimingCapture"); + if (timingFn != NULL) + { + return timingFn(discard); + } + + return HRESULT_FROM_WIN32(GetLastError()); +} + +__forceinline HRESULT WINAPI PIXForceD3D11On12() +{ + typedef HRESULT (WINAPI* ForceD3D11On12Fn)(void); + + auto fn = (ForceD3D11On12Fn)PixImpl::GetGpuCaptureFunctionPtr("ForceD3D11On12"); + if (fn == NULL) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + + return fn(); +} + +__forceinline HRESULT WINAPI PIXSetHUDOptions(PIXHUDOptions hudOptions) +{ + typedef HRESULT(WINAPI* SetHUDOptionsFn)(PIXHUDOptions); + + auto fn = (SetHUDOptionsFn)PixImpl::GetGpuCaptureFunctionPtr("SetHUDOptions"); + if (fn == NULL) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + + return fn(hudOptions); +} + +__forceinline bool WINAPI PIXIsAttachedForGpuCapture() +{ + typedef bool(WINAPI* GetIsAttachedToPixFn)(void); + auto fn = (GetIsAttachedToPixFn)PixImpl::GetGpuCaptureFunctionPtr("GetIsAttachedToPix"); + if (fn == NULL) + { + OutputDebugStringW(L"WinPixEventRuntime error: Mismatched header/dll. Please ensure that pix3.h and WinPixGpuCapturer.dll match"); + return false; + } + + return fn(); +} + +__forceinline HINSTANCE WINAPI PIXOpenCaptureInUI(PCWSTR fileName) +{ + return ShellExecuteW(0, 0, fileName, 0, 0, SW_SHOW); +} + +#else +__forceinline HMODULE PIXLoadLatestWinPixGpuCapturerLibrary() +{ + return nullptr; +} +__forceinline HMODULE PIXLoadLatestWinPixTimingCapturerLibrary() +{ + return nullptr; +} +__forceinline HRESULT WINAPI PIXSetTargetWindow(HWND) +{ + return E_NOTIMPL; +} + +__forceinline HRESULT WINAPI PIXGpuCaptureNextFrames(PCWSTR, UINT32) +{ + return E_NOTIMPL; +} +extern "C" __forceinline HRESULT WINAPI PIXBeginCapture2(DWORD, _In_opt_ const PPIXCaptureParameters) +{ + return E_NOTIMPL; +} +extern "C" __forceinline HRESULT WINAPI PIXEndCapture(BOOL) +{ + return E_NOTIMPL; +} +__forceinline HRESULT WINAPI PIXForceD3D11On12() +{ + return E_NOTIMPL; +} +__forceinline HRESULT WINAPI PIXSetHUDOptions(PIXHUDOptions) +{ + return E_NOTIMPL; +} +__forceinline bool WINAPI PIXIsAttachedForGpuCapture() +{ + return false; +} +__forceinline HINSTANCE WINAPI PIXOpenCaptureInUI(PCWSTR) +{ + return 0; +} +#endif // WINAPI_PARTITION + +#endif // USE_PIX_SUPPORTED_ARCHITECTURE || USE_PIX + +#if defined(__d3d12_h__) + +inline void PIXInsertTimingMarkerOnContextForBeginEvent(_In_ ID3D12GraphicsCommandList* commandList, UINT8 eventType, _In_reads_bytes_(size) void* data, UINT size) +{ + UNREFERENCED_PARAMETER(eventType); + commandList->BeginEvent(WINPIX_EVENT_PIX3BLOB_V2, data, size); +} + +inline void PIXInsertTimingMarkerOnContextForBeginEvent(_In_ ID3D12CommandQueue* commandQueue, UINT8 eventType, _In_reads_bytes_(size) void* data, UINT size) +{ + UNREFERENCED_PARAMETER(eventType); + commandQueue->BeginEvent(WINPIX_EVENT_PIX3BLOB_V2, data, size); +} + +inline void PIXInsertTimingMarkerOnContextForSetMarker(_In_ ID3D12GraphicsCommandList* commandList, UINT8 eventType, _In_reads_bytes_(size) void* data, UINT size) +{ + UNREFERENCED_PARAMETER(eventType); + commandList->SetMarker(WINPIX_EVENT_PIX3BLOB_V2, data, size); +} + +inline void PIXInsertTimingMarkerOnContextForSetMarker(_In_ ID3D12CommandQueue* commandQueue, UINT8 eventType, _In_reads_bytes_(size) void* data, UINT size) +{ + UNREFERENCED_PARAMETER(eventType); + commandQueue->SetMarker(WINPIX_EVENT_PIX3BLOB_V2, data, size); +} + +inline void PIXInsertTimingMarkerOnContextForEndEvent(_In_ ID3D12GraphicsCommandList* commandList, UINT8 eventType) +{ + UNREFERENCED_PARAMETER(eventType); + commandList->EndEvent(); +} + +inline void PIXInsertTimingMarkerOnContextForEndEvent(_In_ ID3D12CommandQueue* commandQueue, UINT8 eventType) +{ + UNREFERENCED_PARAMETER(eventType); + commandQueue->EndEvent(); +} + +inline void PIXInsertGPUMarkerOnContextForBeginEvent(_In_ ID3D12GraphicsCommandList* commandList, UINT8 eventType, _In_reads_bytes_(size) void* data, UINT size) +{ + UNREFERENCED_PARAMETER(eventType); + commandList->BeginEvent(WINPIX_EVENT_PIX3BLOB_V2, data, size); +} + +inline void PIXInsertGPUMarkerOnContextForBeginEvent(_In_ ID3D12CommandQueue* commandQueue, UINT8 eventType, _In_reads_bytes_(size) void* data, UINT size) +{ + UNREFERENCED_PARAMETER(eventType); + commandQueue->BeginEvent(WINPIX_EVENT_PIX3BLOB_V2, data, size); +} + +inline void PIXInsertGPUMarkerOnContextForSetMarker(_In_ ID3D12GraphicsCommandList* commandList, UINT8 eventType, _In_reads_bytes_(size) void* data, UINT size) +{ + UNREFERENCED_PARAMETER(eventType); + commandList->SetMarker(WINPIX_EVENT_PIX3BLOB_V2, data, size); +} + +inline void PIXInsertGPUMarkerOnContextForSetMarker(_In_ ID3D12CommandQueue* commandQueue, UINT8 eventType, _In_reads_bytes_(size) void* data, UINT size) +{ + UNREFERENCED_PARAMETER(eventType); + commandQueue->SetMarker(WINPIX_EVENT_PIX3BLOB_V2, data, size); +} + +inline void PIXInsertGPUMarkerOnContextForEndEvent(_In_ ID3D12GraphicsCommandList* commandList, UINT8, void*, UINT) +{ + commandList->EndEvent(); +} + +inline void PIXInsertGPUMarkerOnContextForEndEvent(_In_ ID3D12CommandQueue* commandQueue, UINT8, void*, UINT) +{ + commandQueue->EndEvent(); +} + +#endif + +#endif //_PIX3_WIN_H_ diff --git a/Kinc/Backends/Graphics5/Direct3D12/pix/ThirdPartyNotices.txt b/Kinc/Backends/Graphics5/Direct3D12/pix/ThirdPartyNotices.txt new file mode 100644 index 0000000..90ad07d --- /dev/null +++ b/Kinc/Backends/Graphics5/Direct3D12/pix/ThirdPartyNotices.txt @@ -0,0 +1,579 @@ +THIRD-PARTY SOFTWARE NOTICES AND INFORMATION + +Note: While Microsoft is not the author of the files below, Microsoft is +offering you a license subject to the terms of the Microsoft Software License +Terms for Microsoft PIX Developer Tool (the "Microsoft Program"). Microsoft +reserves all other rights. The notices below are provided for informational +purposes only and are not the license terms under which Microsoft distributes +these files. + +The Microsoft Program includes the following third-party software: + +1. Boost v. 1.66.0 (https://sourceforge.net/projects/boost/files/boost/1.66.0) +2. fmt v4.1.0 (https://github.com/fmtlib/fmt/releases/tag/4.1.0) +3. SQLite 3 (http://www.sqlite.org/) +4. AMD PIX Plugin +5. nlohmann JSON (https://github.com/nlohmann/json) +6. PresentMon (https://github.com/GameTechDev/PresentMon) +7. DirectXTex (https://github.com/microsoft/directxtex) +8. DirectXTK12 (https://github.com/microsoft/DirectXTK12) +9. Guidelines Support Library (GSL) (https://github.com/microsoft/GSL) +10. Windows Implementation Library (WIL) (https://github.com/microsoft/wil) +11. GoogleTest (https://github.com/google/googletest/) +12. Newtonsoft.Json (https://www.newtonsoft.com/json) +13. WIX (https://wixtoolset.org/) +14. Moq (https://github.com/moq/moq) +15. FluentAssertions (https://github.com/fluentassertions/fluentassertions) +16. .NET Community Toolkit (https://github.com/CommunityToolkit/dotnet) +17. LiveCharts (https://lvcharts.com) +18. NVIDIA PIX Plugin + +As the recipient of the above third-party software, Microsoft sets forth a copy +of the notices and other information below. + + +BOOST NOTICES AND INFORMATION BEGIN HERE +======================================== + +Boost v. 1.66.0 +Copyright Beman Dawes, David Abrahams, 1998-2005 +Copyright Rene Rivera 2006-2007 +Provided for Informational Purposes Only +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by this +license (the "Software") to use, reproduce, display, distribute, execute, and +transmit the Software, and to prepare derivative works of the Software, and to +permit third-parties to whom the Software is furnished to do so, all subject to +the following: + +The copyright notices in the Software and this entire statement, including the +above license grant, this restriction and the following disclaimer, must be +included in all copies of the Software, in whole or in part, and all derivative +works of the Software, unless such copies or derivative works are solely in the +form of machine-executable object code generated by a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL +THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY +DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE + +END OF BOOST NOTICES AND INFORMATION +==================================== + +FMT NOTICES AND INFORMATION BEGIN HERE +====================================== + +fmt v4.1.0 +Copyright (c) 2012 - 2016, Victor Zverovich +Provided for Informational Purposes Only +BSD 2-clause + + +Copyright (c) 2012 - 2016, Victor Zverovich + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +END OF FMT NOTICES AND INFORMATION +================================== + +SQLITE3 NOTICES AND INFORMATION BEGIN HERE +========================================== + +https://www.sqlite.org/copyright.html +SQLite Is Public Domain + +All of the code and documentation in SQLite has been dedicated to the public +domain by the authors. All code authors, and representatives of the companies +they work for, have signed affidavits dedicating their contributions to the +public domain and originals of those signed affidavits are stored in a firesafe +at the main offices of Hwaci. Anyone is free to copy, modify, publish, use, +compile, sell, or distribute the original SQLite code, either in source code +form or as a compiled binary, for any purpose, commercial or non-commercial, and +by any means. + +The previous paragraph applies to the deliverable code and documentation in SQLite - +those parts of the SQLite library that you actually bundle and ship with a larger +application. Some scripts used as part of the build process (for example the "configure" +scripts generated by autoconf) might fall under other open-source licenses. Nothing +from these build scripts ever reaches the final deliverable SQLite library, however, +and so the licenses associated with those scripts should not be a factor in assessing +your rights to copy and use the SQLite library. + +All of the deliverable code in SQLite has been written from scratch. No code has been +taken from other projects or from the open internet. Every line of code can be traced +back to its original author, and all of those authors have public domain dedications +on file. So the SQLite code base is clean and is uncontaminated with licensed code +from other projects. + +END OF SQLITE3 NOTICES AND INFORMATION +====================================== + +AMD NOTICES AND INFORMATION BEGIN HERE +====================================== + +AMD copyrighted code (MIT) +Copyright (c) 2017-2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +Microsoft copyrighted code (MIT) +Copyright (c) Microsoft. All rights reserved. + +This code is licensed under the MIT License (MIT). +THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. + +END OF AMD NOTICES AND INFORMATION +================================== + +NLOHMANN JSON NOTICES AND INFORMATION BEGIN HERE +====================================== + +MIT License + +Copyright (c) 2013-2021 Niels Lohmann + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +END OF NLOHMANN JSON NOTICES AND INFORMATION +================================== + +PRESENTMON NOTICES AND INFORMATION BEGIN HERE +====================================== + +Copyright (C) 2017-2021 Intel Corporation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +OR OTHER DEALINGS IN THE SOFTWARE. + +END OF PRESENTMON NOTICES AND INFORMATION +================================== + +DIRECTXTEX NOTICES AND INFORMATION BEGIN HERE +====================================== + +Copyright (c) 2011-2021 Microsoft Corp + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +END OF DIRECTXTEX NOTICES AND INFORMATION +================================== + +DIRECTXTK12 NOTICES AND INFORMATION BEGIN HERE +====================================== + +Copyright (c) 2016-2021 Microsoft Corp + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +END OF DIRECTXTK12 NOTICES AND INFORMATION +================================== + +GSL NOTICES AND INFORMATION BEGIN HERE +====================================== + +Copyright (c) 2015 Microsoft Corporation. All rights reserved. + +This code is licensed under the MIT License (MIT). + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +END OF GSL NOTICES AND INFORMATION +================================== + +WIL NOTICES AND INFORMATION BEGIN HERE +====================================== +MIT License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE + +END OF WIL NOTICES AND INFORMATION +================================== + +GOOGLETEST NOTICES AND INFORMATION BEGIN HERE +====================================== +Copyright 2008, Google Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +END OF GOOGLETEST NOTICES AND INFORMATION +================================== + +NEWTONSOFT.JSON NOTICES AND INFORMATION BEGIN HERE +====================================== +The MIT License (MIT) + +Copyright (c) 2007 James Newton-King + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +END OF NEWTONSOFT.JSON NOTICES AND INFORMATION +================================= + +WIX NOTICES AND INFORMATION BEGIN HERE +====================================== +Copyright (c) .NET Foundation and contributors. This software is released under +the Microsoft Reciprocal License (MS-RL) (the "License"); you may not use the +software except in compliance with the License. + +The text of the Microsoft Reciprocal License (MS-RL) can be found online at: +http://opensource.org/licenses/ms-rl + + +Microsoft Reciprocal License (MS-RL) + +This license governs use of the accompanying software. If you use the software, +you accept this license. If you do not accept the license, do not use the +software. + +1. Definitions The terms "reproduce," "reproduction," "derivative works," and +"distribution" have the same meaning here as under U.S. copyright law. A +"contribution" is the original software, or any additions or changes to the +software. A "contributor" is any person that distributes its contribution under +this license. "Licensed patents" are a contributor's patent claims that read +directly on its contribution. + +2. Grant of Rights (A) Copyright Grant- Subject to the terms of this license, +including the license conditions and limitations in section 3, each contributor +grants you a non-exclusive, worldwide, royalty-free copyright license to +reproduce its contribution, prepare derivative works of its contribution, and +distribute its contribution or any derivative works that you create. (B) Patent +Grant- Subject to the terms of this license, including the license conditions and +limitations in section 3, each contributor grants you a non-exclusive, worldwide, +royalty-free license under its licensed patents to make, have made, use, sell, +offer for sale, import, and/or otherwise dispose of its contribution in the +software or derivative works of the contribution in the software. + +3. Conditions and Limitations (A) Reciprocal Grants- For any file you distribute +that contains code from the software (in source code or binary format), you must +provide recipients the source code to that file along with a copy of this +license, which license will govern that file. You may license other files that +are entirely your own work and do not contain code from the software under any +terms you choose. (B) No Trademark License- This license does not grant you +rights to use any contributors' name, logo, or trademarks. (C) If you bring a +patent claim against any contributor over patents that you claim are infringed by +the software, your patent license from such contributor to the software ends +automatically. (D) If you distribute any portion of the software, you must retain +all copyright, patent, trademark, and attribution notices that are present in the +software. (E) If you distribute any portion of the software in source code form, +you may do so only under this license by including a complete copy of this +license with your distribution. If you distribute any portion of the software in +compiled or object code form, you may only do so under a license that complies +with this license. (F) The software is licensed "as-is." You bear the risk of +using it. The contributors give no express warranties, guarantees or conditions. +You may have additional consumer rights under your local laws which this license +cannot change. To the extent permitted under your local laws, the contributors +exclude the implied warranties of merchantability, fitness for a particular +purpose and non-infringement. + +END OF WIX NOTICES AND INFORMATION +================================= + + +MOQ NOTICES AND INFORMATION BEGIN HERE +====================================== +MIT License + +Copyright (c) Daniel Cazzulino and Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +END OF MOQ NOTICES AND INFORMATION +================================== + + +FLUENTASSERTIONS NOTICES AND INFORMATION BEGIN HERE +=================================================== +Copyright [2010-2021] [Dennis Doomen] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +END OF FLUENTASSERTIONS NOTICES AND INFORMATION +=============================================== + +.NET COMMUNITY TOOLKIT NOTICES AND INFORMATION BEGIN HERE +====================================== +MIT License + +Copyright © .NET Foundation and Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +END OF .NET COMMUNITY TOOLKIT NOTICES AND INFORMATION +================================== + +LIVE CHARTS NOTICES AND INFORMATION BEGIN HERE +====================================== +MIT License + +Copyright (c) 2021 Alberto Rodriguez Orozco + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +END OF LIVE CHARTS NOTICES AND INFORMATION +================================== + +NVIDIA PIX PLUGIN NOTICES AND INFORMATION BEGIN HERE +====================================== +Copyright (c) Microsoft Corporation. +Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +END OF NVIDIA PIX PLUGIN NOTICES AND INFORMATION +================================== \ No newline at end of file diff --git a/Kinc/Backends/Graphics5/Direct3D12/pix/bin/x64/WinPixEventRuntime.dll b/Kinc/Backends/Graphics5/Direct3D12/pix/bin/x64/WinPixEventRuntime.dll new file mode 100644 index 0000000..5d86359 Binary files /dev/null and b/Kinc/Backends/Graphics5/Direct3D12/pix/bin/x64/WinPixEventRuntime.dll differ diff --git a/Kinc/Backends/Graphics5/Direct3D12/pix/bin/x64/WinPixEventRuntime.lib b/Kinc/Backends/Graphics5/Direct3D12/pix/bin/x64/WinPixEventRuntime.lib new file mode 100644 index 0000000..7a909a8 Binary files /dev/null and b/Kinc/Backends/Graphics5/Direct3D12/pix/bin/x64/WinPixEventRuntime.lib differ diff --git a/Kinc/Backends/Graphics5/Direct3D12/pix/license.txt b/Kinc/Backends/Graphics5/Direct3D12/pix/license.txt new file mode 100644 index 0000000..4437826 --- /dev/null +++ b/Kinc/Backends/Graphics5/Direct3D12/pix/license.txt @@ -0,0 +1,21 @@ +Copyright (c) Microsoft Corporation. + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/commandlist.c.h b/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/commandlist.c.h index be77628..57d42ce 100644 --- a/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/commandlist.c.h +++ b/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/commandlist.c.h @@ -10,7 +10,7 @@ #include #include -#ifdef KORE_MICROSOFT +#ifdef KINC_MICROSOFT #include #endif @@ -212,7 +212,7 @@ void kinc_g5_command_list_execute(kinc_g5_command_list_t *list) { } case SetVertexBuffers: { READ(int, count); -#ifdef KORE_MICROSOFT +#ifdef KINC_MICROSOFT kinc_g4_vertex_buffer_t **buffers = (kinc_g4_vertex_buffer_t **)alloca(sizeof(kinc_g4_vertex_buffer_t *) * count); #else kinc_g4_vertex_buffer_t *buffers[count]; @@ -231,7 +231,7 @@ void kinc_g5_command_list_execute(kinc_g5_command_list_t *list) { } case SetRenderTargets: { READ(int, count); -#ifdef KORE_MICROSOFT +#ifdef KINC_MICROSOFT kinc_g4_render_target_t **buffers = (kinc_g4_render_target_t **)alloca(sizeof(kinc_g4_render_target_t *) * count); #else kinc_g4_render_target_t *buffers[count]; @@ -279,11 +279,7 @@ void kinc_g5_command_list_execute(kinc_g5_command_list_t *list) { assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT); kinc_g4_texture_unit_t g4_unit; memcpy(&g4_unit.stages[0], &unit.stages[0], KINC_G4_SHADER_TYPE_COUNT * sizeof(int)); -#ifdef KINC_KONG - kinc_g4_set_texture(g4_unit.stages[0], &texture->impl.texture); -#else kinc_g4_set_texture(g4_unit, &texture->impl.texture); -#endif break; } case SetImageTexture: { @@ -396,3 +392,7 @@ bool kinc_g5_command_list_are_query_results_available(kinc_g5_command_list_t *li } void kinc_g5_command_list_get_query_result(kinc_g5_command_list_t *list, unsigned occlusionQuery, unsigned *pixelCount) {} + +void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, struct kinc_g5_compute_shader *shader) {} + +void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) {} diff --git a/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.c b/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.c new file mode 100644 index 0000000..3d13a3b --- /dev/null +++ b/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.c @@ -0,0 +1,28 @@ +#include +#include + +#include + +void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *source, int length) { + kinc_g4_compute_shader_init(&shader->impl.g4, source, length); +} + +void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader) { + kinc_g4_compute_shader_destroy(&shader->impl.g4); +} + +kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_location(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_constant_location_t location = {0}; + location.impl.location = kinc_g4_compute_shader_get_constant_location(&shader->impl.g4, name); + return location; +} + +kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_texture_unit_t g5_unit = {0}; + kinc_g4_texture_unit_t g4_unit = kinc_g4_compute_shader_get_texture_unit(&shader->impl.g4, name); + assert(KINC_G4_SHADER_TYPE_COUNT == KINC_G5_SHADER_TYPE_COUNT); + for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) { + g5_unit.stages[i] = g4_unit.stages[i]; + } + return g5_unit; +} diff --git a/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.h b/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.h new file mode 100644 index 0000000..59a2789 --- /dev/null +++ b/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/compute.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +typedef struct kinc_g5_compute_shader_impl { + kinc_g4_compute_shader g4; +} kinc_g5_compute_shader_impl; diff --git a/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/pipeline.c.h b/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/pipeline.c.h index 291e062..dcc51c8 100644 --- a/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/pipeline.c.h +++ b/Kinc/Backends/Graphics5/G5onG4/Sources/kinc/backend/graphics5/pipeline.c.h @@ -37,7 +37,6 @@ void kinc_g5_pipeline_destroy(kinc_g5_pipeline_t *pipe) { kinc_g4_pipeline_destroy(&pipe->impl.pipe); } -#ifndef KINC_KONG kinc_g5_constant_location_t kinc_g5_pipeline_get_constant_location(kinc_g5_pipeline_t *pipe, const char *name) { kinc_g5_constant_location_t location; location.impl.location = kinc_g4_pipeline_get_constant_location(&pipe->impl.pipe, name); @@ -53,7 +52,6 @@ kinc_g5_texture_unit_t kinc_g5_pipeline_get_texture_unit(kinc_g5_pipeline_t *pip return g5_unit; } -#endif void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) { for (int i = 0; i < 16; ++i) { diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/compute.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/compute.h deleted file mode 100644 index 7aa5bb8..0000000 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/compute.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include - -typedef struct { - uint32_t _offset; -} kinc_compute_constant_location_impl_t; - -typedef struct { - uint32_t _index; -} kinc_compute_texture_unit_impl_t; - -typedef struct { - char name[1024]; - void *_function; - void *_pipeline; - void *_reflection; -} kinc_compute_shader_impl_t; diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/compute.m b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/compute.m deleted file mode 100644 index 5bf988d..0000000 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/compute.m +++ /dev/null @@ -1,246 +0,0 @@ -#include -#include -#include - -#include - -id getMetalDevice(void); -id getMetalLibrary(void); - -#define constantsSize 1024 * 4 -static uint8_t *constantsMemory; - -static void setFloat(uint8_t *constants, uint32_t offset, uint32_t size, float value) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value; -} - -static void setFloat2(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; -} - -static void setFloat3(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2, float value3) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; - floats[2] = value3; -} - -static void setFloat4(uint8_t *constants, uint32_t offset, uint32_t size, float value1, float value2, float value3, float value4) { - if (size == 0) - return; - float *floats = (float *)&constants[offset]; - floats[0] = value1; - floats[1] = value2; - floats[2] = value3; - floats[3] = value4; -} - -static id commandQueue; -static id commandBuffer; -static id commandEncoder; -static id buffer; - -void initMetalCompute(id device, id queue) { - commandQueue = queue; - commandBuffer = [commandQueue commandBuffer]; - commandEncoder = [commandBuffer computeCommandEncoder]; - buffer = [device newBufferWithLength:constantsSize options:MTLResourceOptionCPUCacheModeDefault]; - constantsMemory = (uint8_t *)[buffer contents]; -} - -void shutdownMetalCompute(void) { - [commandEncoder endEncoding]; - commandEncoder = nil; - commandBuffer = nil; - commandQueue = nil; -} - -void kinc_compute_shader_destroy(kinc_compute_shader_t *shader) { - id function = (__bridge_transfer id)shader->impl._function; - function = nil; - shader->impl._function = NULL; - - id pipeline = (__bridge_transfer id)shader->impl._pipeline; - pipeline = nil; - shader->impl._pipeline = NULL; - - MTLComputePipelineReflection *reflection = (__bridge_transfer MTLComputePipelineReflection *)shader->impl._reflection; - reflection = nil; - shader->impl._reflection = NULL; -} - -void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int length) { - shader->impl.name[0] = 0; - - { - uint8_t *data = (uint8_t *)_data; - if (length > 1 && data[0] == '>') { - memcpy(shader->impl.name, data + 1, length - 1); - shader->impl.name[length - 1] = 0; - } - else { - for (int i = 3; i < length; ++i) { - if (data[i] == '\n') { - shader->impl.name[i - 3] = 0; - break; - } - else { - shader->impl.name[i - 3] = data[i]; - } - } - } - } - - char *data = (char *)_data; - id library = nil; - if (length > 1 && data[0] == '>') { - library = getMetalLibrary(); - } - else { - id device = getMetalDevice(); - library = [device newLibraryWithSource:[[NSString alloc] initWithBytes:data length:length encoding:NSUTF8StringEncoding] options:nil error:nil]; - } - id function = [library newFunctionWithName:[NSString stringWithCString:shader->impl.name encoding:NSUTF8StringEncoding]]; - assert(shader->impl._function != nil); - shader->impl._function = (__bridge_retained void *)function; - - id device = getMetalDevice(); - MTLComputePipelineReflection *reflection = nil; - NSError *error = nil; - shader->impl._pipeline = (__bridge_retained void *)[device newComputePipelineStateWithFunction:function - options:MTLPipelineOptionBufferTypeInfo - reflection:&reflection - error:&error]; - if (error != nil) - NSLog(@"%@", [error localizedDescription]); - assert(shader->impl._pipeline != NULL && !error); - shader->impl._reflection = (__bridge_retained void *)reflection; -} - -kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_constant_location_t location; - location.impl._offset = -1; - - MTLComputePipelineReflection *reflection = (__bridge MTLComputePipelineReflection *)shader->impl._reflection; - - for (MTLArgument *arg in reflection.arguments) { - if (arg.type == MTLArgumentTypeBuffer && [arg.name isEqualToString:@"uniforms"]) { - if ([arg bufferDataType] == MTLDataTypeStruct) { - MTLStructType *structObj = [arg bufferStructType]; - for (MTLStructMember *member in structObj.members) { - if (strcmp([[member name] UTF8String], name) == 0) { - location.impl._offset = (int)[member offset]; - break; - } - } - } - break; - } - } - - return location; -} - -kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_texture_unit_t unit; - unit.impl._index = -1; - - MTLComputePipelineReflection *reflection = (__bridge MTLComputePipelineReflection *)shader->impl._reflection; - for (MTLArgument *arg in reflection.arguments) { - if ([arg type] == MTLArgumentTypeTexture && strcmp([[arg name] UTF8String], name) == 0) { - unit.impl._index = (int)[arg index]; - } - } - - return unit; -} - -void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value) {} - -void kinc_compute_set_int(kinc_compute_constant_location_t location, int value) {} - -void kinc_compute_set_float(kinc_compute_constant_location_t location, float value) { - setFloat(constantsMemory, location.impl._offset, 4, value); -} - -void kinc_compute_set_float2(kinc_compute_constant_location_t location, float value1, float value2) { - setFloat2(constantsMemory, location.impl._offset, 4 * 2, value1, value2); -} - -void kinc_compute_set_float3(kinc_compute_constant_location_t location, float value1, float value2, float value3) { - setFloat3(constantsMemory, location.impl._offset, 4 * 3, value1, value2, value3); -} - -void kinc_compute_set_float4(kinc_compute_constant_location_t location, float value1, float value2, float value3, float value4) { - setFloat4(constantsMemory, location.impl._offset, 4 * 4, value1, value2, value3, value4); -} - -void kinc_compute_set_floats(kinc_compute_constant_location_t location, float *values, int count) {} - -void kinc_compute_set_matrix4(kinc_compute_constant_location_t location, kinc_matrix4x4_t *value) {} - -void kinc_compute_set_matrix3(kinc_compute_constant_location_t location, kinc_matrix3x3_t *value) {} - -void kinc_compute_set_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture, kinc_compute_access_t access) { - id tex = (__bridge id)texture->impl._texture.impl._tex; - [commandEncoder setTexture:tex atIndex:unit.impl._index]; -} - -void kinc_compute_set_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *texture, kinc_compute_access_t access) {} - -void kinc_compute_set_sampled_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture) {} - -void kinc_compute_set_sampled_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target) {} - -void kinc_compute_set_sampled_depth_from_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target) {} - -void kinc_compute_set_texture_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} - -void kinc_compute_set_texture3d_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} - -void kinc_compute_set_texture_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture3d_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} - -void kinc_compute_set_texture_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} - -void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} - -void kinc_compute_set_shader(kinc_compute_shader_t *shader) { - id pipeline = (__bridge id)shader->impl._pipeline; - [commandEncoder setComputePipelineState:pipeline]; -} - -void kinc_compute(int x, int y, int z) { - [commandEncoder setBuffer:buffer offset:0 atIndex:0]; - - MTLSize perGrid; - perGrid.width = x; - perGrid.height = y; - perGrid.depth = z; - MTLSize perGroup; - perGroup.width = 16; - perGroup.height = 16; - perGroup.depth = 1; - [commandEncoder dispatchThreadgroups:perGrid threadsPerThreadgroup:perGroup]; - - [commandEncoder endEncoding]; - [commandBuffer commit]; - [commandBuffer waitUntilCompleted]; - - commandBuffer = [commandQueue commandBuffer]; - commandEncoder = [commandBuffer computeCommandEncoder]; -} diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/Metal.m.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/Metal.m.h index f7b96d7..214f4cf 100644 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/Metal.m.h +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/Metal.m.h @@ -20,8 +20,6 @@ int newRenderTargetWidth; int newRenderTargetHeight; id drawable; -id commandBuffer; -id commandEncoder; id depthTexture; int depthBits; int stencilBits; @@ -29,14 +27,20 @@ int stencilBits; static kinc_g5_render_target_t fallback_render_target; id getMetalEncoder(void) { - return commandEncoder; + return render_command_encoder; } void kinc_g5_internal_destroy_window(int window) {} void kinc_g5_internal_destroy(void) {} +#ifdef __cplusplus +extern "C" { +#endif extern void kinc_g4_on_g5_internal_resize(int, int, int); +#ifdef __cplusplus +} +#endif void kinc_internal_resize(int window, int width, int height) { kinc_g4_on_g5_internal_resize(window, width, height); @@ -62,6 +66,30 @@ bool kinc_internal_current_render_target_has_depth(void) { return kinc_internal_metal_has_depth; } +static void start_render_pass(void) { + id texture = drawable.texture; + MTLRenderPassDescriptor *renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor]; + renderPassDescriptor.colorAttachments[0].texture = texture; + renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear; + renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore; + renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0); + renderPassDescriptor.depthAttachment.clearDepth = 1; + renderPassDescriptor.depthAttachment.loadAction = MTLLoadActionClear; + renderPassDescriptor.depthAttachment.storeAction = MTLStoreActionStore; + renderPassDescriptor.depthAttachment.texture = depthTexture; + renderPassDescriptor.stencilAttachment.clearStencil = 0; + renderPassDescriptor.stencilAttachment.loadAction = MTLLoadActionDontCare; + renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionDontCare; + renderPassDescriptor.stencilAttachment.texture = depthTexture; + + render_command_encoder = [command_buffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; +} + +static void end_render_pass(void) { + [render_command_encoder endEncoding]; + render_command_encoder = nil; +} + void kinc_g5_begin(kinc_g5_render_target_t *renderTarget, int window) { CAMetalLayer *metalLayer = getMetalLayer(); drawable = [metalLayer nextDrawable]; @@ -100,27 +128,27 @@ void kinc_g5_begin(kinc_g5_render_target_t *renderTarget, int window) { renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionDontCare; renderPassDescriptor.stencilAttachment.texture = depthTexture; - if (commandBuffer != nil && commandEncoder != nil) { - [commandEncoder endEncoding]; - [commandBuffer commit]; + if (command_buffer != nil && render_command_encoder != nil) { + [render_command_encoder endEncoding]; + [command_buffer commit]; } id commandQueue = getMetalQueue(); - commandBuffer = [commandQueue commandBuffer]; - commandEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; + command_buffer = [commandQueue commandBuffer]; + render_command_encoder = [command_buffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; } void kinc_g5_end(int window) {} bool kinc_g5_swap_buffers(void) { - if (commandBuffer != nil && commandEncoder != nil) { - [commandEncoder endEncoding]; - [commandBuffer presentDrawable:drawable]; - [commandBuffer commit]; + if (command_buffer != nil && render_command_encoder != nil) { + [render_command_encoder endEncoding]; + [command_buffer presentDrawable:drawable]; + [command_buffer commit]; } drawable = nil; - commandBuffer = nil; - commandEncoder = nil; + command_buffer = nil; + render_command_encoder = nil; return true; } @@ -131,11 +159,11 @@ bool kinc_window_vsynced(int window) { void kinc_g5_internal_new_render_pass(kinc_g5_render_target_t **renderTargets, int count, bool wait, unsigned clear_flags, unsigned color, float depth, int stencil) { - if (commandBuffer != nil && commandEncoder != nil) { - [commandEncoder endEncoding]; - [commandBuffer commit]; + if (command_buffer != nil && render_command_encoder != nil) { + [render_command_encoder endEncoding]; + [command_buffer commit]; if (wait) { - [commandBuffer waitUntilCompleted]; + [command_buffer waitUntilCompleted]; } } @@ -198,8 +226,8 @@ void kinc_g5_internal_new_render_pass(kinc_g5_render_target_t **renderTargets, i } id commandQueue = getMetalQueue(); - commandBuffer = [commandQueue commandBuffer]; - commandEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; + command_buffer = [commandQueue commandBuffer]; + render_command_encoder = [command_buffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; } bool kinc_g5_supports_raytracing(void) { diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/commandlist.m.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/commandlist.m.h index 45cc9c7..f81407d 100644 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/commandlist.m.h +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/commandlist.m.h @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -277,6 +278,12 @@ void kinc_g5_command_list_set_fragment_constant_buffer(kinc_g5_command_list_t *l [encoder setFragmentBuffer:buf offset:offset atIndex:0]; } +void kinc_g5_command_list_set_compute_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) { + assert(compute_command_encoder != nil); + id buf = (__bridge id)buffer->impl._buffer; + [compute_command_encoder setBuffer:buf offset:offset atIndex:1]; +} + void kinc_g5_command_list_render_target_to_texture_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) { #ifndef KINC_APPLE_SOC id encoder = getMetalEncoder(); @@ -287,17 +294,23 @@ void kinc_g5_command_list_render_target_to_texture_barrier(kinc_g5_command_list_ void kinc_g5_command_list_texture_to_render_target_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {} void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { - id encoder = getMetalEncoder(); id tex = (__bridge id)texture->impl._tex; - if (unit.stages[KINC_G5_SHADER_TYPE_VERTEX] >= 0) { - [encoder setVertexTexture:tex atIndex:unit.stages[KINC_G5_SHADER_TYPE_VERTEX]]; + if (compute_command_encoder != nil) { + [compute_command_encoder setTexture:tex atIndex:unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]]; } - if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { - [encoder setFragmentTexture:tex atIndex:unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]]; + else { + if (unit.stages[KINC_G5_SHADER_TYPE_VERTEX] >= 0) { + [render_command_encoder setVertexTexture:tex atIndex:unit.stages[KINC_G5_SHADER_TYPE_VERTEX]]; + } + if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { + [render_command_encoder setFragmentTexture:tex atIndex:unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]]; + } } } -void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) {} +void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { + kinc_g5_command_list_set_texture(list, unit, texture); +} bool kinc_g5_command_list_init_occlusion_query(kinc_g5_command_list_t *list, unsigned *occlusionQuery) { return false; @@ -348,3 +361,33 @@ void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_text [encoder setFragmentSamplerState:mtl_sampler atIndex:unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]]; } } + +void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_g5_compute_shader *shader) { + if (compute_command_encoder == nil) { + end_render_pass(); + compute_command_encoder = [command_buffer computeCommandEncoder]; + } + + id pipeline = (__bridge id)shader->impl._pipeline; + [compute_command_encoder setComputePipelineState:pipeline]; +} + +void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) { + assert(compute_command_encoder != nil); + + MTLSize perGrid; + perGrid.width = x; + perGrid.height = y; + perGrid.depth = z; + MTLSize perGroup; + perGroup.width = 16; + perGroup.height = 16; + perGroup.depth = 1; + [compute_command_encoder dispatchThreadgroups:perGrid threadsPerThreadgroup:perGroup]; + + [compute_command_encoder endEncoding]; + + compute_command_encoder = nil; + + start_render_pass(); +} diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.h new file mode 100644 index 0000000..a2ff02b --- /dev/null +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.h @@ -0,0 +1,8 @@ +#pragma once + +typedef struct kinc_g5_compute_shader_impl { + char name[1024]; + void *_function; + void *_pipeline; + void *_reflection; +} kinc_g5_compute_shader_impl; diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.m.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.m.h new file mode 100644 index 0000000..00f31a4 --- /dev/null +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/compute.m.h @@ -0,0 +1,112 @@ +#include +#include +#include + +#include + +id getMetalDevice(void); +id getMetalLibrary(void); + +void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *_data, int length) { + shader->impl.name[0] = 0; + + { + uint8_t *data = (uint8_t *)_data; + if (length > 1 && data[0] == '>') { + memcpy(shader->impl.name, data + 1, length - 1); + shader->impl.name[length - 1] = 0; + } + else { + for (int i = 3; i < length; ++i) { + if (data[i] == '\n') { + shader->impl.name[i - 3] = 0; + break; + } + else { + shader->impl.name[i - 3] = data[i]; + } + } + } + } + + char *data = (char *)_data; + id library = nil; + if (length > 1 && data[0] == '>') { + library = getMetalLibrary(); + } + else { + id device = getMetalDevice(); + library = [device newLibraryWithSource:[[NSString alloc] initWithBytes:data length:length encoding:NSUTF8StringEncoding] options:nil error:nil]; + } + id function = [library newFunctionWithName:[NSString stringWithCString:shader->impl.name encoding:NSUTF8StringEncoding]]; + assert(function != nil); + shader->impl._function = (__bridge_retained void *)function; + + id device = getMetalDevice(); + MTLComputePipelineReflection *reflection = nil; + NSError *error = nil; + shader->impl._pipeline = (__bridge_retained void *)[device newComputePipelineStateWithFunction:function + options:MTLPipelineOptionBufferTypeInfo + reflection:&reflection + error:&error]; + if (error != nil) + NSLog(@"%@", [error localizedDescription]); + assert(shader->impl._pipeline != NULL && !error); + shader->impl._reflection = (__bridge_retained void *)reflection; +} + +void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader) { + id function = (__bridge_transfer id)shader->impl._function; + function = nil; + shader->impl._function = NULL; + + id pipeline = (__bridge_transfer id)shader->impl._pipeline; + pipeline = nil; + shader->impl._pipeline = NULL; + + MTLComputePipelineReflection *reflection = (__bridge_transfer MTLComputePipelineReflection *)shader->impl._reflection; + reflection = nil; + shader->impl._reflection = NULL; +} + +kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_location(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_constant_location_t location; + location.impl.vertexOffset = -1; + location.impl.fragmentOffset = -1; + location.impl.computeOffset = -1; + + MTLComputePipelineReflection *reflection = (__bridge MTLComputePipelineReflection *)shader->impl._reflection; + + for (MTLArgument *arg in reflection.arguments) { + if (arg.type == MTLArgumentTypeBuffer && [arg.name isEqualToString:@"uniforms"]) { + if ([arg bufferDataType] == MTLDataTypeStruct) { + MTLStructType *structObj = [arg bufferStructType]; + for (MTLStructMember *member in structObj.members) { + if (strcmp([[member name] UTF8String], name) == 0) { + location.impl.computeOffset = (int)[member offset]; + break; + } + } + } + break; + } + } + + return location; +} + +kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_texture_unit_t unit = {0}; + for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) { + unit.stages[i] = -1; + } + + MTLComputePipelineReflection *reflection = (__bridge MTLComputePipelineReflection *)shader->impl._reflection; + for (MTLArgument *arg in reflection.arguments) { + if ([arg type] == MTLArgumentTypeTexture && strcmp([[arg name] UTF8String], name) == 0) { + unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] = (int)[arg index]; + } + } + + return unit; +} diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/metalunit.m b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/metalunit.m index 5edc61a..b8a7097 100644 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/metalunit.m +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/metalunit.m @@ -1,5 +1,16 @@ +#import +#import + +static id command_buffer = nil; +static id render_command_encoder = nil; +static id compute_command_encoder = nil; + +static void start_render_pass(void); +static void end_render_pass(void); + #include "Metal.m.h" #include "commandlist.m.h" +#include "compute.m.h" #include "constantbuffer.m.h" #include "indexbuffer.m.h" #include "pipeline.m.h" diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.h index b95f6a5..d43d212 100644 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.h +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.h @@ -20,4 +20,5 @@ typedef struct { typedef struct { int vertexOffset; int fragmentOffset; + int computeOffset; } ConstantLocation5Impl; diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.m.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.m.h index 537012b..05408be 100644 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.m.h +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/pipeline.m.h @@ -364,9 +364,14 @@ void kinc_g5_internal_pipeline_set(kinc_g5_pipeline_t *pipeline) { } kinc_g5_constant_location_t kinc_g5_pipeline_get_constant_location(kinc_g5_pipeline_t *pipeline, const char *name) { + if (strcmp(name, "bias") == 0) { + name = "bias0"; + } + kinc_g5_constant_location_t location; location.impl.vertexOffset = -1; location.impl.fragmentOffset = -1; + location.impl.computeOffset = -1; MTLRenderPipelineReflection *reflection = (__bridge MTLRenderPipelineReflection *)pipeline->impl._reflection; diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/raytrace.m.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/raytrace.m.h index e4b01ef..b9b185f 100644 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/raytrace.m.h +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/raytrace.m.h @@ -16,6 +16,7 @@ id getMetalQueue(void); id _raytracing_pipeline; NSMutableArray *_primitive_accels; +API_AVAILABLE(macos(11.0), ios(14.0)) id _instance_accel; dispatch_semaphore_t _sem; @@ -41,6 +42,7 @@ void kinc_raytrace_pipeline_init(kinc_raytrace_pipeline_t *pipeline, kinc_g5_com void kinc_raytrace_pipeline_destroy(kinc_raytrace_pipeline_t *pipeline) {} +API_AVAILABLE(macos(11.0), ios(14.0)) id create_acceleration_sctructure(MTLAccelerationStructureDescriptor *descriptor) { id device = getMetalDevice(); id queue = getMetalQueue(); @@ -72,6 +74,7 @@ id create_acceleration_sctructure(MTLAccelerationStruc return compacted_acceleration_structure; } +API_AVAILABLE(macos(11.0), ios(14.0)) void kinc_raytrace_acceleration_structure_init(kinc_raytrace_acceleration_structure_t *accel, kinc_g5_command_list_t *command_list, kinc_g5_vertex_buffer_t *vb, kinc_g5_index_buffer_t *ib) { #if !TARGET_OS_IPHONE @@ -130,6 +133,7 @@ void kinc_raytrace_set_target(kinc_g5_texture_t *_output) { output = _output; } +API_AVAILABLE(macos(11.0), ios(14.0)) void kinc_raytrace_dispatch_rays(kinc_g5_command_list_t *command_list) { dispatch_semaphore_wait(_sem, DISPATCH_TIME_FOREVER); @@ -151,8 +155,9 @@ void kinc_raytrace_dispatch_rays(kinc_g5_command_list_t *command_list) { [compute_encoder setAccelerationStructure:_instance_accel atBufferIndex:1]; [compute_encoder setTexture:(__bridge id)output->impl._tex atIndex:0]; - for (id primitive_accel in _primitive_accels) + for (id primitive_accel in _primitive_accels) { [compute_encoder useResource:primitive_accel usage:MTLResourceUsageRead]; + } [compute_encoder setComputePipelineState:_raytracing_pipeline]; [compute_encoder dispatchThreadgroups:threadgroups threadsPerThreadgroup:threads_per_threadgroup]; @@ -160,6 +165,7 @@ void kinc_raytrace_dispatch_rays(kinc_g5_command_list_t *command_list) { [command_buffer commit]; } +API_AVAILABLE(macos(11.0), ios(14.0)) void kinc_raytrace_copy(kinc_g5_command_list_t *command_list, kinc_g5_render_target_t *target, kinc_g5_texture_t *source) { id queue = getMetalQueue(); id command_buffer = [queue commandBuffer]; diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/sampler.m.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/sampler.m.h index ef5b5fc..3d55a02 100644 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/sampler.m.h +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/sampler.m.h @@ -5,7 +5,12 @@ static MTLSamplerAddressMode convert_addressing(kinc_g5_texture_addressing_t mod case KINC_G5_TEXTURE_ADDRESSING_REPEAT: return MTLSamplerAddressModeRepeat; case KINC_G5_TEXTURE_ADDRESSING_BORDER: - return MTLSamplerAddressModeClampToBorderColor; + if (@available(iOS 14.0, *)) { + return MTLSamplerAddressModeClampToBorderColor; + } + else { + return MTLSamplerAddressModeClampToEdge; + } case KINC_G5_TEXTURE_ADDRESSING_CLAMP: return MTLSamplerAddressModeClampToEdge; case KINC_G5_TEXTURE_ADDRESSING_MIRROR: diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/shader.m.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/shader.m.h index a495855..97106f8 100644 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/shader.m.h +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/shader.m.h @@ -15,11 +15,6 @@ void kinc_g5_shader_destroy(kinc_g5_shader_t *shader) { } void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t length, kinc_g5_shader_type_t type) { -#ifdef KINC_KONG - strcpy(shader->impl.name, (const char *)source); - shader->impl.mtlFunction = (__bridge_retained void *)[getMetalLibrary() newFunctionWithName:[NSString stringWithCString:shader->impl.name - encoding:NSUTF8StringEncoding]]; -#else shader->impl.name[0] = 0; { @@ -56,6 +51,5 @@ void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t le } shader->impl.mtlFunction = (__bridge_retained void *)[library newFunctionWithName:[NSString stringWithCString:shader->impl.name encoding:NSUTF8StringEncoding]]; -#endif assert(shader->impl.mtlFunction); } diff --git a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/texture.m.h b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/texture.m.h index c9f8523..f9d32c5 100644 --- a/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/texture.m.h +++ b/Kinc/Backends/Graphics5/Metal/Sources/kinc/backend/graphics5/texture.m.h @@ -277,7 +277,7 @@ void kinc_g5_texture_set_mipmap(kinc_g5_texture_t *texture, kinc_image_t *mipmap #include -#if defined(KORE_IOS) || defined(KORE_MACOS) +#if defined(KINC_IOS) || defined(KINC_MACOS) void kinc_g4_texture_upload(kinc_g4_texture_t *texture_g4, uint8_t *data, int stride) { kinc_g5_texture_t *tex = &texture_g4->impl._texture; id texture = (__bridge id)tex->impl._tex; diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.c b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.c deleted file mode 100644 index dbfc6ce..0000000 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include - -void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *source, int length) {} - -void kinc_compute_shader_destroy(kinc_compute_shader_t *shader) {} - -kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_constant_location_t location; - location.impl.nothing = 0; - return location; -} - -kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_texture_unit_t unit; - unit.impl.nothing = 0; - return unit; -} - -void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value) {} -void kinc_compute_set_int(kinc_compute_constant_location_t location, int value) {} -void kinc_compute_set_float(kinc_compute_constant_location_t location, float value) {} -void kinc_compute_set_float2(kinc_compute_constant_location_t location, float value1, float value2) {} -void kinc_compute_set_float3(kinc_compute_constant_location_t location, float value1, float value2, float value3) {} -void kinc_compute_set_float4(kinc_compute_constant_location_t location, float value1, float value2, float value3, float value4) {} -void kinc_compute_set_floats(kinc_compute_constant_location_t location, float *values, int count) {} -void kinc_compute_set_matrix4(kinc_compute_constant_location_t location, kinc_matrix4x4_t *value) {} -void kinc_compute_set_matrix3(kinc_compute_constant_location_t location, kinc_matrix3x3_t *value) {} -void kinc_compute_set_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture, kinc_compute_access_t access) {} -void kinc_compute_set_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *texture, kinc_compute_access_t access) {} -void kinc_compute_set_sampled_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture) {} -void kinc_compute_set_sampled_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target) {} -void kinc_compute_set_sampled_depth_from_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target) {} -void kinc_compute_set_texture_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} -void kinc_compute_set_texture_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} -void kinc_compute_set_texture_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} -void kinc_compute_set_texture_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} -void kinc_compute_set_texture3d_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} -void kinc_compute_set_texture3d_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} -void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} -void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} -void kinc_compute_set_shader(kinc_compute_shader_t *shader) {} -void kinc_compute(int x, int y, int z) {} diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.h deleted file mode 100644 index ad6125c..0000000 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -typedef struct { - int nothing; -} kinc_compute_constant_location_impl_t; - -typedef struct { - int nothing; -} kinc_compute_texture_unit_impl_t; - -typedef struct { - int nothing; -} kinc_compute_shader_impl_t; diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/ShaderHash.c.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/ShaderHash.c.h new file mode 100644 index 0000000..c1114a1 --- /dev/null +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/ShaderHash.c.h @@ -0,0 +1,11 @@ +#include "ShaderHash.h" + +// djb2 +uint32_t kinc_internal_hash_name(unsigned char *str) { + unsigned long hash = 5381; + int c; + while (c = *str++) { + hash = hash * 33 ^ c; + } + return hash; +} diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/ShaderHash.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/ShaderHash.h new file mode 100644 index 0000000..2963fd3 --- /dev/null +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/ShaderHash.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + uint32_t hash; + uint32_t index; +} kinc_internal_hash_index_t; + +uint32_t kinc_internal_hash_name(unsigned char *str); + +#ifdef __cplusplus +} +#endif diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/Vulkan.c.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/Vulkan.c.h index c10ea40..f8082ab 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/Vulkan.c.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/Vulkan.c.h @@ -1,4 +1,5 @@ #include "kinc/graphics4/graphics.h" + #include "vulkan.h" #include @@ -7,26 +8,14 @@ #include #include #include + #include + #include struct vk_funs vk = {0}; struct vk_context vk_ctx = {0}; -#ifdef KORE_WINDOWS -#define ERR_EXIT(err_msg, err_class) \ - do { \ - MessageBoxA(NULL, err_msg, err_class, MB_OK); \ - exit(1); \ - } while (0) -#else -#define ERR_EXIT(err_msg, err_class) \ - do { \ - kinc_log(KINC_LOG_LEVEL_ERROR, "%s", err_msg); \ - exit(1); \ - } while (0) -#endif - void kinc_vulkan_get_instance_extensions(const char **extensions, int *index, int max); VkBool32 kinc_vulkan_get_physical_device_presentation_support(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex); VkResult kinc_vulkan_create_surface(VkInstance instance, int window_index, VkSurfaceKHR *surface); @@ -35,15 +24,14 @@ VkResult kinc_vulkan_create_surface(VkInstance instance, int window_index, VkSur { \ vk.fp##entrypoint = (PFN_vk##entrypoint)vkGetInstanceProcAddr(instance, "vk" #entrypoint); \ if (vk.fp##entrypoint == NULL) { \ - ERR_EXIT("vkGetInstanceProcAddr failed to find vk" #entrypoint, "vkGetInstanceProcAddr Failure"); \ + kinc_error_message("vkGetInstanceProcAddr failed to find vk" #entrypoint); \ } \ } #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -#define APP_NAME_STR_LEN 80 - void createDescriptorLayout(void); +static void create_compute_descriptor_layout(void); void set_image_layout(VkImage image, VkImageAspectFlags aspectMask, VkImageLayout old_image_layout, VkImageLayout new_image_layout); // uint32_t current_buffer; @@ -55,7 +43,7 @@ VkSampler vulkanSamplers[16] = {VK_NULL_HANDLE, VK_NULL_HANDLE, VK_NULL_HANDLE, static bool began = false; -#ifndef KORE_ANDROID +#ifndef KINC_ANDROID static VkAllocationCallbacks allocator; #endif @@ -79,7 +67,7 @@ static VkBool32 vkDebugUtilsMessengerCallbackEXT(VkDebugUtilsMessageSeverityFlag return VK_FALSE; } -#ifndef KORE_ANDROID +#ifndef KINC_ANDROID static VKAPI_ATTR void *VKAPI_CALL myrealloc(void *pUserData, void *pOriginal, size_t size, size_t alignment, VkSystemAllocationScope allocationScope) { #ifdef _MSC_VER return _aligned_realloc(pOriginal, size, alignment); @@ -115,10 +103,8 @@ static VKAPI_ATTR void VKAPI_CALL myfree(void *pUserData, void *pMemory) { #endif bool memory_type_from_properties(uint32_t typeBits, VkFlags requirements_mask, uint32_t *typeIndex) { - // Search memtypes to find first index with those properties for (uint32_t i = 0; i < 32; i++) { if ((typeBits & 1) == 1) { - // Type is available, does it match user properties? if ((memory_properties.memoryTypes[i].propertyFlags & requirements_mask) == requirements_mask) { *typeIndex = i; return true; @@ -126,11 +112,16 @@ bool memory_type_from_properties(uint32_t typeBits, VkFlags requirements_mask, u } typeBits >>= 1; } - // No memory types matched, return failure return false; } +#ifdef __cplusplus +extern "C" { +#endif extern void kinc_g4_on_g5_internal_resize(int, int, int); +#ifdef __cplusplus +} +#endif void kinc_internal_resize(int window_index, int width, int height) { struct vk_window *window = &vk_ctx.windows[window_index]; @@ -184,6 +175,9 @@ VkSwapchainKHR cleanup_swapchain(int window_index) { return chain; } +#define MAX_PRESENT_MODES 256 +static VkPresentModeKHR present_modes[MAX_PRESENT_MODES]; + void create_swapchain(int window_index) { struct vk_window *window = &vk_ctx.windows[window_index]; @@ -204,12 +198,11 @@ void create_swapchain(int window_index) { VkResult err = vk.fpGetPhysicalDeviceSurfaceCapabilitiesKHR(vk_ctx.gpu, window->surface, &surfCapabilities); assert(!err); - uint32_t presentModeCount; - err = vk.fpGetPhysicalDeviceSurfacePresentModesKHR(vk_ctx.gpu, window->surface, &presentModeCount, NULL); + uint32_t present_mode_count; + err = vk.fpGetPhysicalDeviceSurfacePresentModesKHR(vk_ctx.gpu, window->surface, &present_mode_count, NULL); + present_mode_count = present_mode_count > MAX_PRESENT_MODES ? MAX_PRESENT_MODES : present_mode_count; assert(!err); - VkPresentModeKHR *presentModes = (VkPresentModeKHR *)malloc(presentModeCount * sizeof(VkPresentModeKHR)); - assert(presentModes); - err = vk.fpGetPhysicalDeviceSurfacePresentModesKHR(vk_ctx.gpu, window->surface, &presentModeCount, presentModes); + err = vk.fpGetPhysicalDeviceSurfacePresentModesKHR(vk_ctx.gpu, window->surface, &present_mode_count, present_modes); assert(!err); VkExtent2D swapchainExtent; @@ -337,10 +330,6 @@ void create_swapchain(int window_index) { window->current_image = 0; - if (NULL != presentModes) { - free(presentModes); - } - const VkFormat depth_format = VK_FORMAT_D16_UNORM; if (window->depth_bits > 0) { @@ -381,29 +370,23 @@ void create_swapchain(int window_index) { VkMemoryRequirements mem_reqs = {0}; bool pass; - /* create image */ err = vkCreateImage(vk_ctx.device, &image, NULL, &window->depth.image); assert(!err); - /* get memory requirements for this object */ vkGetImageMemoryRequirements(vk_ctx.device, window->depth.image, &mem_reqs); - /* select memory size and type */ mem_alloc.allocationSize = mem_reqs.size; - pass = memory_type_from_properties(mem_reqs.memoryTypeBits, 0, /* No requirements */ &mem_alloc.memoryTypeIndex); + pass = memory_type_from_properties(mem_reqs.memoryTypeBits, 0, &mem_alloc.memoryTypeIndex); assert(pass); - /* allocate memory */ err = vkAllocateMemory(vk_ctx.device, &mem_alloc, NULL, &window->depth.memory); assert(!err); - /* bind memory */ err = vkBindImageMemory(vk_ctx.device, window->depth.image, window->depth.memory, 0); assert(!err); set_image_layout(window->depth.image, VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); - /* create image view */ view.image = window->depth.image; err = vkCreateImageView(vk_ctx.device, &view, NULL, &window->depth.view); assert(!err); @@ -667,6 +650,7 @@ void kinc_g5_internal_init() { uint32_t instance_extension_count = 0; wanted_instance_extensions[wanted_instance_extension_count++] = VK_KHR_SURFACE_EXTENSION_NAME; + wanted_instance_extensions[wanted_instance_extension_count++] = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME; kinc_vulkan_get_instance_extensions(wanted_instance_extensions, &wanted_instance_extension_count, ARRAY_SIZE(wanted_instance_extensions)); err = vkEnumerateInstanceExtensionProperties(NULL, &instance_extension_count, NULL); @@ -678,7 +662,7 @@ void kinc_g5_internal_init() { check_extensions(wanted_instance_extensions, wanted_instance_extension_count, instance_extensions, instance_extension_count); if (missing_instance_extensions) { - exit(1); + kinc_error(); } #ifdef VALIDATE @@ -695,7 +679,7 @@ void kinc_g5_internal_init() { app.applicationVersion = 0; app.pEngineName = "Kore"; app.engineVersion = 0; -#ifdef KORE_VKRT +#ifdef KINC_VKRT app.apiVersion = VK_API_VERSION_1_2; #else app.apiVersion = VK_API_VERSION_1_0; @@ -719,7 +703,7 @@ void kinc_g5_internal_init() { info.enabledExtensionCount = wanted_instance_extension_count; info.ppEnabledExtensionNames = (const char *const *)wanted_instance_extensions; -#ifndef KORE_ANDROID +#ifndef KINC_ANDROID allocator.pfnAllocation = myalloc; allocator.pfnFree = myfree; allocator.pfnReallocation = myrealloc; @@ -728,21 +712,13 @@ void kinc_g5_internal_init() { err = vkCreateInstance(&info, NULL, &vk_ctx.instance); #endif if (err == VK_ERROR_INCOMPATIBLE_DRIVER) { - ERR_EXIT("Cannot find a compatible Vulkan installable client driver " - "(ICD).\n\nPlease look at the Getting Started guide for " - "additional information.\n", - "vkCreateInstance Failure"); + kinc_error_message("Vulkan driver is incompatible"); } else if (err == VK_ERROR_EXTENSION_NOT_PRESENT) { - ERR_EXIT("Cannot find a specified extension library" - ".\nMake sure your layers path is set appropriately\n", - "vkCreateInstance Failure"); + kinc_error_message("Vulkan extension not found"); } else if (err) { - ERR_EXIT("vkCreateInstance failed.\n\nDo you have a compatible Vulkan " - "installable client driver (ICD) installed?\nPlease look at " - "the Getting Started guide for additional information.\n", - "vkCreateInstance Failure"); + kinc_error_message("Can not create Vulkan instance"); } uint32_t gpu_count; @@ -750,20 +726,91 @@ void kinc_g5_internal_init() { err = vkEnumeratePhysicalDevices(vk_ctx.instance, &gpu_count, NULL); assert(!err && gpu_count > 0); + bool headless = false; + + // TODO: expose gpu selection to user? if (gpu_count > 0) { VkPhysicalDevice *physical_devices = (VkPhysicalDevice *)malloc(sizeof(VkPhysicalDevice) * gpu_count); err = vkEnumeratePhysicalDevices(vk_ctx.instance, &gpu_count, physical_devices); assert(!err); - // TODO: expose gpu selection to user? - vk_ctx.gpu = physical_devices[0]; + // The device with the highest score is chosen. + float best_score = 0.0; + for (uint32_t gpu_idx = 0; gpu_idx < gpu_count; gpu_idx++) { + VkPhysicalDevice gpu = physical_devices[gpu_idx]; + uint32_t queue_count = 0; + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL); + VkQueueFamilyProperties *queue_props = (VkQueueFamilyProperties *)malloc(queue_count * sizeof(VkQueueFamilyProperties)); + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, queue_props); + bool can_present = false; + bool can_render = false; + // According to the documentation, a device that supports graphics must also support compute, + // Just to be 100% safe verify that it supports both anyway. + bool can_compute = false; + for (uint32_t i = 0; i < queue_count; i++) { + VkBool32 queue_supports_present = kinc_vulkan_get_physical_device_presentation_support(gpu, i); + if (queue_supports_present) { + can_present = true; + } + VkQueueFamilyProperties queue_properties = queue_props[i]; + uint32_t flags = queue_properties.queueFlags; + if ((flags & VK_QUEUE_GRAPHICS_BIT) != 0) { + can_render = true; + } + if ((flags & VK_QUEUE_COMPUTE_BIT) != 0) { + can_compute = true; + } + } + if (!can_present || !can_render || !can_compute) { + // This device is missing required features so move on + continue; + } + + // Score the device in order to compare it to others. + // Higher score = better. + float score = 0.0; + VkPhysicalDeviceProperties properties; + vkGetPhysicalDeviceProperties(gpu, &properties); + switch (properties.deviceType) { + case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: + score += 10; + break; + case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: + score += 7; + break; + case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: + score += 5; + break; + case VK_PHYSICAL_DEVICE_TYPE_OTHER: + score += 1; + break; + case VK_PHYSICAL_DEVICE_TYPE_CPU: + // CPU gets a score of zero + break; + case VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM: + break; + } + // TODO: look into using more metrics than just the device type for scoring, eg: available memory, max texture sizes, etc. + // If this is the first usable device, skip testing against the previous best. + if (vk_ctx.gpu == VK_NULL_HANDLE || score > best_score) { + vk_ctx.gpu = gpu; + best_score = score; + } + } + if (vk_ctx.gpu == VK_NULL_HANDLE) { + if (headless) { + vk_ctx.gpu = physical_devices[0]; + } + else { + kinc_error_message("No Vulkan device that supports presentation found"); + } + } + VkPhysicalDeviceProperties properties; + vkGetPhysicalDeviceProperties(vk_ctx.gpu, &properties); + kinc_log(KINC_LOG_LEVEL_INFO, "Chosen Vulkan device: %s", properties.deviceName); free(physical_devices); } else { - ERR_EXIT("vkEnumeratePhysicalDevices reported zero accessible devices." - "\n\nDo you have a compatible Vulkan installable client" - " driver (ICD) installed?\nPlease look at the Getting Started" - " guide for additional information.\n", - "vkEnumeratePhysicalDevices Failure"); + kinc_error_message("No Vulkan device found"); } static const char *wanted_device_layers[64]; @@ -795,7 +842,7 @@ void kinc_g5_internal_init() { // Allows negative viewport height to flip viewport wanted_device_extensions[wanted_device_extension_count++] = VK_KHR_MAINTENANCE1_EXTENSION_NAME; -#ifdef KORE_VKRT +#ifdef KINC_VKRT wanted_device_extensions[wanted_device_extension_count++] = VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME; wanted_device_extensions[wanted_device_extension_count++] = VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME; wanted_device_extensions[wanted_device_extension_count++] = VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME; @@ -805,6 +852,12 @@ void kinc_g5_internal_init() { wanted_device_extensions[wanted_device_extension_count++] = VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME; #endif +#ifndef VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME // For Dave's Debian +#define VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME "VK_KHR_format_feature_flags2" +#endif + + wanted_device_extensions[wanted_device_extension_count++] = VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME; + uint32_t device_extension_count = 0; err = vkEnumerateDeviceExtensionProperties(vk_ctx.gpu, NULL, &device_extension_count, NULL); @@ -815,6 +868,10 @@ void kinc_g5_internal_init() { assert(!err); bool missing_device_extensions = check_extensions(wanted_device_extensions, wanted_device_extension_count, device_extensions, device_extension_count); + if (missing_device_extensions) { + wanted_device_extension_count -= 1; // remove VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME + } + missing_device_extensions = check_extensions(wanted_device_extensions, wanted_device_extension_count, device_extensions, device_extension_count); free(device_extensions); @@ -861,8 +918,6 @@ void kinc_g5_internal_init() { vkGetPhysicalDeviceQueueFamilyProperties(vk_ctx.gpu, &queue_count, queue_props); assert(queue_count >= 1); - bool headless = false; - if (!headless) { // Iterate over each queue to learn whether it supports presenting: VkBool32 *supportsPresent = (VkBool32 *)malloc(queue_count * sizeof(VkBool32)); @@ -902,7 +957,7 @@ void kinc_g5_internal_init() { // Generate error if could not find both a graphics and a present queue if (graphicsQueueNodeIndex == UINT32_MAX || presentQueueNodeIndex == UINT32_MAX) { - ERR_EXIT("Could not find a graphics and a present queue\n", "Swapchain Initialization Failure"); + kinc_error_message("Graphics or present queue not found"); } // TODO: Add support for separate queues, including presentation, @@ -911,7 +966,7 @@ void kinc_g5_internal_init() { // and a present queues, this demo program assumes it is only using // one: if (graphicsQueueNodeIndex != presentQueueNodeIndex) { - ERR_EXIT("Could not find a common graphics and a present queue\n", "Swapchain Initialization Failure"); + kinc_error_message("Graphics and present queue do not match"); } graphics_queue_node_index = graphicsQueueNodeIndex; @@ -937,7 +992,7 @@ void kinc_g5_internal_init() { deviceinfo.enabledExtensionCount = wanted_device_extension_count; deviceinfo.ppEnabledExtensionNames = (const char *const *)wanted_device_extensions; -#ifdef KORE_VKRT +#ifdef KINC_VKRT VkPhysicalDeviceRayTracingPipelineFeaturesKHR rayTracingPipelineExt = {0}; rayTracingPipelineExt.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR; rayTracingPipelineExt.pNext = NULL; @@ -973,6 +1028,7 @@ void kinc_g5_internal_init() { err = vkCreateCommandPool(vk_ctx.device, &cmd_pool_info, NULL, &vk_ctx.cmd_pool); createDescriptorLayout(); + create_compute_descriptor_layout(); assert(!err); } @@ -1129,6 +1185,7 @@ void kinc_g5_end(int window) { } reuse_descriptor_sets(); + reuse_compute_descriptor_sets(); began = false; } @@ -1152,7 +1209,7 @@ bool kinc_vulkan_internal_get_size(int *width, int *height) { } bool kinc_g5_supports_raytracing() { -#ifdef KORE_VKRT +#ifdef KINC_VKRT return true; #else return false; diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/commandlist.c.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/commandlist.c.h index 0231e5c..a06f930 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/commandlist.c.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/commandlist.c.h @@ -2,6 +2,7 @@ #include "vulkan.h" #include +#include #include #include #include @@ -12,6 +13,7 @@ extern kinc_g5_texture_t *vulkanTextures[16]; extern kinc_g5_render_target_t *vulkanRenderTargets[16]; VkDescriptorSet getDescriptorSet(void); +static VkDescriptorSet get_compute_descriptor_set(void); bool memory_type_from_properties(uint32_t typeBits, VkFlags requirements_mask, uint32_t *typeIndex); void setImageLayout(VkCommandBuffer _buffer, VkImage image, VkImageAspectFlags aspectMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout); @@ -22,13 +24,20 @@ kinc_g5_render_target_t *currentRenderTargets[8] = {NULL, NULL, NULL, NULL, NULL static bool onBackBuffer = false; static uint32_t lastVertexConstantBufferOffset = 0; static uint32_t lastFragmentConstantBufferOffset = 0; +static uint32_t lastComputeConstantBufferOffset = 0; static kinc_g5_pipeline_t *currentPipeline = NULL; +static kinc_g5_compute_shader *current_compute_shader = NULL; static int mrtIndex = 0; static VkFramebuffer mrtFramebuffer[16]; static VkRenderPass mrtRenderPass[16]; +static bool in_render_pass = false; + static void endPass(kinc_g5_command_list_t *list) { - vkCmdEndRenderPass(list->impl._buffer); + if (in_render_pass) { + vkCmdEndRenderPass(list->impl._buffer); + in_render_pass = false; + } for (int i = 0; i < 16; ++i) { vulkanTextures[i] = NULL; @@ -302,6 +311,7 @@ void kinc_g5_command_list_begin(kinc_g5_command_list_t *list) { vkCmdBeginRenderPass(list->impl._buffer, &rp_begin, VK_SUBPASS_CONTENTS_INLINE); currentRenderPassBeginInfo = rp_begin; + in_render_pass = true; set_viewport_and_scissor(list); @@ -455,7 +465,7 @@ void kinc_g5_command_list_set_blend_constant(kinc_g5_command_list_t *list, float void kinc_g5_command_list_set_vertex_buffers(kinc_g5_command_list_t *list, struct kinc_g5_vertex_buffer **vertexBuffers, int *offsets_, int count) { // this seems to be a no-op function? // kinc_g5_internal_vertex_buffer_set(vertexBuffers[0], 0); -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS VkBuffer *buffers = (VkBuffer *)alloca(sizeof(VkBuffer) * count); VkDeviceSize *offsets = (VkDeviceSize *)alloca(sizeof(VkDeviceSize) * count); #else @@ -493,7 +503,7 @@ void kinc_internal_restore_render_target(kinc_g5_command_list_t *list, struct ki scissor.offset.y = 0; vkCmdSetScissor(list->impl._buffer, 0, 1, &scissor); - if (onBackBuffer) { + if (onBackBuffer && in_render_pass) { return; } @@ -523,6 +533,7 @@ void kinc_internal_restore_render_target(kinc_g5_command_list_t *list, struct ki rp_begin.pClearValues = clear_values; vkCmdBeginRenderPass(list->impl._buffer, &rp_begin, VK_SUBPASS_CONTENTS_INLINE); currentRenderPassBeginInfo = rp_begin; + in_render_pass = true; if (currentPipeline != NULL) { currentVulkanPipeline = currentPipeline->impl.framebuffer_pipeline; @@ -531,6 +542,13 @@ void kinc_internal_restore_render_target(kinc_g5_command_list_t *list, struct ki } void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struct kinc_g5_render_target **targets, int count) { + for (int i = 0; i < count; ++i) { + currentRenderTargets[i] = targets[i]; + } + for (int i = count; i < 8; ++i) { + currentRenderTargets[i] = NULL; + } + if (targets[0]->framebuffer_index >= 0) { kinc_internal_restore_render_target(list, targets[0]); return; @@ -538,12 +556,6 @@ void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struc endPass(list); - for (int i = 0; i < count; ++i) { - currentRenderTargets[i] = targets[i]; - } - for (int i = count; i < 8; ++i) { - currentRenderTargets[i] = NULL; - } onBackBuffer = false; VkClearValue clear_values[9]; @@ -685,6 +697,7 @@ void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struc vkCmdBeginRenderPass(list->impl._buffer, &rp_begin, VK_SUBPASS_CONTENTS_INLINE); currentRenderPassBeginInfo = rp_begin; + in_render_pass = true; VkViewport viewport; memset(&viewport, 0, sizeof(viewport)); @@ -771,6 +784,7 @@ void kinc_g5_command_list_get_render_target_pixels(kinc_g5_command_list_t *list, setImageLayout(list->impl._buffer, render_target->impl.sourceImage, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); vkCmdBeginRenderPass(list->impl._buffer, ¤tRenderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); + in_render_pass = true; kinc_g5_command_list_end(list); kinc_g5_command_list_execute(list); @@ -804,6 +818,15 @@ void kinc_g5_command_list_set_fragment_constant_buffer(kinc_g5_command_list_t *l vkCmdBindDescriptorSets(list->impl._buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, currentPipeline->impl.pipeline_layout, 0, 1, &descriptor_set, 2, offsets); } +void kinc_g5_command_list_set_compute_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) { + lastComputeConstantBufferOffset = offset; + + VkDescriptorSet descriptor_set = get_compute_descriptor_set(); + uint32_t offsets[2] = {lastComputeConstantBufferOffset, lastComputeConstantBufferOffset}; + vkCmdBindDescriptorSets(list->impl._buffer, VK_PIPELINE_BIND_POINT_COMPUTE, current_compute_shader->impl.pipeline_layout, 0, 1, &descriptor_set, 2, + offsets); +} + static bool wait_for_framebuffer = false; static void command_list_should_wait_for_framebuffer(void) { @@ -822,21 +845,15 @@ void kinc_g5_command_list_execute(kinc_g5_command_list_t *list) { submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submit_info.pNext = NULL; - VkSemaphore semaphores[2] = { - framebuffer_available, - relay_semaphore - }; - VkPipelineStageFlags dst_stage_flags[2] = { - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, - VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT - }; + VkSemaphore semaphores[2] = {framebuffer_available, relay_semaphore}; + VkPipelineStageFlags dst_stage_flags[2] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT}; if (wait_for_framebuffer) { submit_info.pWaitSemaphores = semaphores; submit_info.pWaitDstStageMask = dst_stage_flags; submit_info.waitSemaphoreCount = wait_for_relay ? 2 : 1; wait_for_framebuffer = false; } - else if(wait_for_relay) { + else if (wait_for_relay) { submit_info.waitSemaphoreCount = 1; submit_info.pWaitSemaphores = &semaphores[1]; submit_info.pWaitDstStageMask = &dst_stage_flags[1]; @@ -863,10 +880,15 @@ void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_text } void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler) { - vulkanSamplers[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = sampler->impl.sampler; + if (unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT] >= 0) { + vulkanSamplers[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = sampler->impl.sampler; + } } -void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) {} +void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { + vulkanTextures[unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]] = texture; + vulkanRenderTargets[unit.stages[KINC_G5_SHADER_TYPE_COMPUTE]] = NULL; +} void kinc_g5_command_list_set_render_target_face(kinc_g5_command_list_t *list, kinc_g5_render_target_t *texture, int face) {} @@ -895,3 +917,29 @@ void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_l vulkanRenderTargets[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = target; vulkanTextures[unit.stages[KINC_G5_SHADER_TYPE_FRAGMENT]] = NULL; } + +void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_g5_compute_shader *shader) { + current_compute_shader = shader; + vkCmdBindPipeline(list->impl._buffer, VK_PIPELINE_BIND_POINT_COMPUTE, shader->impl.pipeline); + //**vkCmdBindDescriptorSets(list->impl._buffer, VK_PIPELINE_BIND_POINT_COMPUTE, shader->impl.pipeline_layout, 0, 1, &shader->impl.descriptor_set, 0, 0); +} + +void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) { + if (in_render_pass) { + vkCmdEndRenderPass(list->impl._buffer); + in_render_pass = false; + } + + vkCmdDispatch(list->impl._buffer, x, y, z); + + int render_target_count = 0; + for (int i = 0; i < 8; ++i) { + if (currentRenderTargets[i] == NULL) { + break; + } + ++render_target_count; + } + if (render_target_count > 0) { + kinc_g5_command_list_set_render_targets(list, currentRenderTargets, render_target_count); + } +} diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h new file mode 100644 index 0000000..3c26676 --- /dev/null +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h @@ -0,0 +1,237 @@ +#include + +#include +#include +#include + +static void parse_shader(uint32_t *shader_source, int shader_length, kinc_internal_named_number *locations, kinc_internal_named_number *textureBindings, + kinc_internal_named_number *uniformOffsets); + +static VkShaderModule create_shader_module(const void *code, size_t size); + +static VkDescriptorPool compute_descriptor_pool; + +static void create_compute_descriptor_layout(void) { + VkDescriptorSetLayoutBinding layoutBindings[18]; + memset(layoutBindings, 0, sizeof(layoutBindings)); + + layoutBindings[0].binding = 0; + layoutBindings[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; + layoutBindings[0].descriptorCount = 1; + layoutBindings[0].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; + layoutBindings[0].pImmutableSamplers = NULL; + + layoutBindings[1].binding = 1; + layoutBindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; + layoutBindings[1].descriptorCount = 1; + layoutBindings[1].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; + layoutBindings[1].pImmutableSamplers = NULL; + + for (int i = 2; i < 18; ++i) { + layoutBindings[i].binding = i; + layoutBindings[i].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + layoutBindings[i].descriptorCount = 1; + layoutBindings[i].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; + layoutBindings[i].pImmutableSamplers = NULL; + } + + VkDescriptorSetLayoutCreateInfo descriptor_layout = {0}; + descriptor_layout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + descriptor_layout.pNext = NULL; + descriptor_layout.bindingCount = 18; + descriptor_layout.pBindings = layoutBindings; + + VkResult err = vkCreateDescriptorSetLayout(vk_ctx.device, &descriptor_layout, NULL, &compute_descriptor_layout); + assert(!err); + + VkDescriptorPoolSize typeCounts[2]; + memset(typeCounts, 0, sizeof(typeCounts)); + + typeCounts[0].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; + typeCounts[0].descriptorCount = 2 * 1024; + + typeCounts[1].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + typeCounts[1].descriptorCount = 16 * 1024; + + VkDescriptorPoolCreateInfo pool_info = {0}; + pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + pool_info.pNext = NULL; + pool_info.maxSets = 1024; + pool_info.poolSizeCount = 2; + pool_info.pPoolSizes = typeCounts; + + err = vkCreateDescriptorPool(vk_ctx.device, &pool_info, NULL, &compute_descriptor_pool); + assert(!err); +} + +void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *_data, int length) { + memset(shader->impl.locations, 0, sizeof(kinc_internal_named_number) * KINC_INTERNAL_NAMED_NUMBER_COUNT); + memset(shader->impl.offsets, 0, sizeof(kinc_internal_named_number) * KINC_INTERNAL_NAMED_NUMBER_COUNT); + memset(shader->impl.texture_bindings, 0, sizeof(kinc_internal_named_number) * KINC_INTERNAL_NAMED_NUMBER_COUNT); + parse_shader((uint32_t *)_data, length, shader->impl.locations, shader->impl.texture_bindings, shader->impl.offsets); + + VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo = {0}; + pPipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pPipelineLayoutCreateInfo.pNext = NULL; + pPipelineLayoutCreateInfo.setLayoutCount = 1; + pPipelineLayoutCreateInfo.pSetLayouts = &compute_descriptor_layout; + + VkResult err = vkCreatePipelineLayout(vk_ctx.device, &pPipelineLayoutCreateInfo, NULL, &shader->impl.pipeline_layout); + assert(!err); + + VkComputePipelineCreateInfo pipeline_info = {0}; + + memset(&pipeline_info, 0, sizeof(pipeline_info)); + pipeline_info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + pipeline_info.layout = shader->impl.pipeline_layout; + + VkPipelineShaderStageCreateInfo shader_stage; + memset(&shader_stage, 0, sizeof(VkPipelineShaderStageCreateInfo)); + + shader_stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shader_stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; + shader->impl.shader_module = create_shader_module(_data, (size_t)length); + shader_stage.module = shader->impl.shader_module; + shader_stage.pName = "main"; + + pipeline_info.stage = shader_stage; + + err = vkCreateComputePipelines(vk_ctx.device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &shader->impl.pipeline); + assert(!err); + + vkDestroyShaderModule(vk_ctx.device, shader->impl.shader_module, NULL); + + /*shader->impl.length = (int)(length - index); + shader->impl.data = (uint8_t *)malloc(shader->impl.length); + assert(shader->impl.data != NULL); + memcpy(shader->impl.data, &data[index], shader->impl.length); + + VkShaderModuleCreateInfo module_create_info; + module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + module_create_info.pNext = NULL; + module_create_info.codeSize = shader->impl.length; + module_create_info.pCode = (const uint32_t *)shader->impl.data; + module_create_info.flags = 0; + + VkShaderModule module; + VkResult err = vkCreateShaderModule(vk_ctx.device, &module_create_info, NULL, &module); + assert(!err); + + VkPipelineShaderStageCreateInfo compute_shader_stage_info = {0}; + compute_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + compute_shader_stage_info.stage = VK_SHADER_STAGE_COMPUTE_BIT; + compute_shader_stage_info.module = module; + compute_shader_stage_info.pName = "main"; + + VkDescriptorSetLayoutBinding layout_bindings[1] = {0}; + layout_bindings[0].binding = 0; + layout_bindings[0].descriptorCount = 1; + layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + layout_bindings[0].pImmutableSamplers = NULL; + layout_bindings[0].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; + + /*layout_bindings[1].binding = 1; + layout_bindings[1].descriptorCount = 1; + layout_bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + layout_bindings[1].pImmutableSamplers = NULL; + layout_bindings[1].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; + + layout_bindings[2].binding = 2; + layout_bindings[2].descriptorCount = 1; + layout_bindings[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + layout_bindings[2].pImmutableSamplers = NULL; + layout_bindings[2].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;*/ + + /*VkDescriptorSetLayoutCreateInfo layoutInfo = {0}; + layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + layoutInfo.bindingCount = 1; + layoutInfo.pBindings = layout_bindings; + + VkDescriptorSetLayout descriptor_set_layout; + if (vkCreateDescriptorSetLayout(vk_ctx.device, &layoutInfo, NULL, &descriptor_set_layout) != VK_SUCCESS) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Could not initialize compute shader."); + return; + } + + VkPipelineLayoutCreateInfo pipeline_layout_info = {0}; + pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + pipeline_layout_info.setLayoutCount = 1; + pipeline_layout_info.pSetLayouts = &descriptor_set_layout; + + if (vkCreatePipelineLayout(vk_ctx.device, &pipeline_layout_info, NULL, &shader->impl.pipeline_layout) != VK_SUCCESS) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Could not initialize compute shader."); + return; + } + + VkComputePipelineCreateInfo pipeline_info = {0}; + memset(&pipeline_info, 0, sizeof(pipeline_info)); + pipeline_info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + pipeline_info.layout = shader->impl.pipeline_layout; + pipeline_info.stage = compute_shader_stage_info; + + if (vkCreateComputePipelines(vk_ctx.device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &shader->impl.pipeline) != VK_SUCCESS) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Could not initialize compute shader."); + return; + }*/ +} + +void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader) {} + +kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_location(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_constant_location_t location = {0}; + + uint32_t hash = kinc_internal_hash_name((unsigned char *)name); + + /*kinc_compute_internal_shader_constant_t *constant = findComputeConstant(shader->impl.constants, hash); + if (constant == NULL) { + location.impl.computeOffset = 0; + } + else { + location.impl.computeOffset = constant->offset; + } + + if (location.impl.computeOffset == 0) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Uniform %s not found.", name); + }*/ + + return location; +} + +kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_shader *shader, const char *name) { + char unitName[64]; + int unitOffset = 0; + size_t len = strlen(name); + if (len > 63) + len = 63; + strncpy(unitName, name, len + 1); + if (unitName[len - 1] == ']') { // Check for array - mySampler[2] + unitOffset = (int)(unitName[len - 2] - '0'); // Array index is unit offset + unitName[len - 3] = 0; // Strip array from name + } + + uint32_t hash = kinc_internal_hash_name((unsigned char *)unitName); + + kinc_g5_texture_unit_t unit; + for (int i = 0; i < KINC_G5_SHADER_TYPE_COUNT; ++i) { + unit.stages[i] = -1; + } + unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] = 0; + /*kinc_internal_hash_index_t *compute_unit = findComputeTextureUnit(shader->impl.textures, hash); + if (compute_unit == NULL) { +#ifndef NDEBUG + static int notFoundCount = 0; + if (notFoundCount < 10) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Sampler %s not found.", unitName); + ++notFoundCount; + } + else if (notFoundCount == 10) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Giving up on sampler not found messages.", unitName); + ++notFoundCount; + } +#endif + } + else { + unit.stages[KINC_G5_SHADER_TYPE_COMPUTE] = compute_unit->index + unitOffset; + }*/ + return unit; +} diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.h new file mode 100644 index 0000000..702516a --- /dev/null +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "MiniVulkan.h" + +#include "named_number.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct kinc_g5_compute_shader_impl { + kinc_internal_named_number locations[KINC_INTERNAL_NAMED_NUMBER_COUNT]; + kinc_internal_named_number texture_bindings[KINC_INTERNAL_NAMED_NUMBER_COUNT]; + kinc_internal_named_number offsets[KINC_INTERNAL_NAMED_NUMBER_COUNT]; + + VkPipelineLayout pipeline_layout; + VkPipeline pipeline; + VkShaderModule shader_module; +} kinc_g5_compute_shader_impl; + +#ifdef __cplusplus +} +#endif diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/constantbuffer.c.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/constantbuffer.c.h index a245407..86cd674 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/constantbuffer.c.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/constantbuffer.c.h @@ -48,12 +48,22 @@ void kinc_g5_constant_buffer_init(kinc_g5_constant_buffer_t *buffer, int size) { createUniformBuffer(&buffer->impl.buf, &buffer->impl.mem_alloc, &buffer->impl.mem, &buffer->impl.buffer_info, size); // buffer hack + if (vk_ctx.vertex_uniform_buffer != NULL && vk_ctx.fragment_uniform_buffer != NULL && vk_ctx.compute_uniform_buffer != NULL) { + // allow writing the buffers again after G4onG5 wrote them + vk_ctx.vertex_uniform_buffer = NULL; + vk_ctx.fragment_uniform_buffer = NULL; + vk_ctx.compute_uniform_buffer = NULL; + } + if (vk_ctx.vertex_uniform_buffer == NULL) { vk_ctx.vertex_uniform_buffer = &buffer->impl.buf; } else if (vk_ctx.fragment_uniform_buffer == NULL) { vk_ctx.fragment_uniform_buffer = &buffer->impl.buf; } + else if (vk_ctx.compute_uniform_buffer == NULL) { + vk_ctx.compute_uniform_buffer = &buffer->impl.buf; + } void *p; VkResult err = vkMapMemory(vk_ctx.device, buffer->impl.mem, 0, buffer->impl.mem_alloc.allocationSize, 0, (void **)&p); diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/indexbuffer.c.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/indexbuffer.c.h index ef54b65..d89fb79 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/indexbuffer.c.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/indexbuffer.c.h @@ -21,7 +21,7 @@ void kinc_g5_index_buffer_init(kinc_g5_index_buffer_t *buffer, int indexCount, k buf_info.pNext = NULL; buf_info.size = format == KINC_G5_INDEX_BUFFER_FORMAT_16BIT ? indexCount * sizeof(uint16_t) : indexCount * sizeof(uint32_t); buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; -#ifdef KORE_VKRT +#ifdef KINC_VKRT buf_info.usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; #endif buf_info.flags = 0; @@ -45,7 +45,7 @@ void kinc_g5_index_buffer_init(kinc_g5_index_buffer_t *buffer, int indexCount, k bool pass = memory_type_from_properties(mem_reqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &buffer->impl.mem_alloc.memoryTypeIndex); assert(pass); -#ifdef KORE_VKRT +#ifdef KINC_VKRT VkMemoryAllocateFlagsInfo memory_allocate_flags_info = {0}; memory_allocate_flags_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO; memory_allocate_flags_info.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR; diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/named_number.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/named_number.h new file mode 100644 index 0000000..f28898e --- /dev/null +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/named_number.h @@ -0,0 +1,8 @@ +#pragma once + +#define KINC_INTERNAL_NAMED_NUMBER_COUNT 32 + +typedef struct { + char name[256]; + uint32_t number; +} kinc_internal_named_number; diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.c.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.c.h index 8c241cf..3d2c5bb 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.c.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.c.h @@ -122,16 +122,16 @@ static void add_offset(uint32_t id, uint32_t offset) { ++offsets_size; } -static void parseShader(kinc_g5_shader_t *shader, kinc_internal_named_number *locations, kinc_internal_named_number *textureBindings, - kinc_internal_named_number *uniformOffsets) { +static void parse_shader(uint32_t *shader_source, int shader_length, kinc_internal_named_number *locations, kinc_internal_named_number *textureBindings, + kinc_internal_named_number *uniformOffsets) { names_size = 0; memberNames_size = 0; locs_size = 0; bindings_size = 0; offsets_size = 0; - uint32_t *spirv = (uint32_t *)shader->impl.source; - int spirvsize = shader->impl.length / 4; + uint32_t *spirv = (uint32_t *)shader_source; + int spirvsize = shader_length / 4; int index = 0; uint32_t magicNumber = spirv[index++]; @@ -217,30 +217,28 @@ static void parseShader(kinc_g5_shader_t *shader, kinc_internal_named_number *lo } } -static VkShaderModule prepare_shader_module(const void *code, size_t size) { +static VkShaderModule create_shader_module(const void *code, size_t size) { VkShaderModuleCreateInfo moduleCreateInfo; - VkShaderModule module; - VkResult err; - moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; moduleCreateInfo.pNext = NULL; - moduleCreateInfo.codeSize = size; moduleCreateInfo.pCode = (const uint32_t *)code; moduleCreateInfo.flags = 0; - err = vkCreateShaderModule(vk_ctx.device, &moduleCreateInfo, NULL, &module); + + VkShaderModule module; + VkResult err = vkCreateShaderModule(vk_ctx.device, &moduleCreateInfo, NULL, &module); assert(!err); return module; } static VkShaderModule prepare_vs(VkShaderModule *vert_shader_module, kinc_g5_shader_t *vertexShader) { - *vert_shader_module = prepare_shader_module(vertexShader->impl.source, vertexShader->impl.length); + *vert_shader_module = create_shader_module(vertexShader->impl.source, vertexShader->impl.length); return *vert_shader_module; } static VkShaderModule prepare_fs(VkShaderModule *frag_shader_module, kinc_g5_shader_t *fragmentShader) { - *frag_shader_module = prepare_shader_module(fragmentShader->impl.source, fragmentShader->impl.length); + *frag_shader_module = create_shader_module(fragmentShader->impl.source, fragmentShader->impl.length); return *frag_shader_module; } @@ -276,6 +274,7 @@ kinc_g5_constant_location_t kinc_g5_pipeline_get_constant_location(kinc_g5_pipel kinc_g5_constant_location_t location; location.impl.vertexOffset = -1; location.impl.fragmentOffset = -1; + location.impl.computeOffset = -1; if (has_number(pipeline->impl.vertexOffsets, name)) { location.impl.vertexOffset = find_number(pipeline->impl.vertexOffsets, name); } @@ -391,8 +390,10 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipeline) { memset(pipeline->impl.fragmentLocations, 0, sizeof(kinc_internal_named_number) * KINC_INTERNAL_NAMED_NUMBER_COUNT); memset(pipeline->impl.fragmentOffsets, 0, sizeof(kinc_internal_named_number) * KINC_INTERNAL_NAMED_NUMBER_COUNT); memset(pipeline->impl.textureBindings, 0, sizeof(kinc_internal_named_number) * KINC_INTERNAL_NAMED_NUMBER_COUNT); - parseShader(pipeline->vertexShader, pipeline->impl.vertexLocations, pipeline->impl.textureBindings, pipeline->impl.vertexOffsets); - parseShader(pipeline->fragmentShader, pipeline->impl.fragmentLocations, pipeline->impl.textureBindings, pipeline->impl.fragmentOffsets); + parse_shader((uint32_t *)pipeline->vertexShader->impl.source, pipeline->vertexShader->impl.length, pipeline->impl.vertexLocations, + pipeline->impl.textureBindings, pipeline->impl.vertexOffsets); + parse_shader((uint32_t *)pipeline->fragmentShader->impl.source, pipeline->fragmentShader->impl.length, pipeline->impl.fragmentLocations, + pipeline->impl.textureBindings, pipeline->impl.fragmentOffsets); VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo = {0}; pPipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; @@ -434,12 +435,12 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipeline) { vertexBindingCount++; } -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS VkVertexInputBindingDescription *vi_bindings = (VkVertexInputBindingDescription *)alloca(sizeof(VkVertexInputBindingDescription) * vertexBindingCount); #else VkVertexInputBindingDescription vi_bindings[vertexBindingCount]; #endif -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS VkVertexInputAttributeDescription *vi_attrs = (VkVertexInputAttributeDescription *)alloca(sizeof(VkVertexInputAttributeDescription) * vertexAttributeCount); #else VkVertexInputAttributeDescription vi_attrs[vertexAttributeCount]; @@ -686,7 +687,7 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipeline) { vkDestroyShaderModule(vk_ctx.device, pipeline->impl.vert_shader_module, NULL); } -void createDescriptorLayout() { +void createDescriptorLayout(void) { VkDescriptorSetLayoutBinding layoutBindings[18]; memset(layoutBindings, 0, sizeof(layoutBindings)); @@ -755,6 +756,22 @@ int calc_descriptor_id(void) { return 1 | (texture_count << 1) | ((uniform_buffer ? 1 : 0) << 8); } +int calc_compute_descriptor_id(void) { + int texture_count = 0; + for (int i = 0; i < 16; ++i) { + if (vulkanTextures[i] != NULL) { + texture_count++; + } + else if (vulkanRenderTargets[i] != NULL) { + texture_count++; + } + } + + bool uniform_buffer = vk_ctx.compute_uniform_buffer != NULL; + + return 1 | (texture_count << 1) | ((uniform_buffer ? 1 : 0) << 8); +} + #define MAX_DESCRIPTOR_SETS 256 struct destriptor_set { @@ -788,7 +805,7 @@ static int write_tex_descs(VkDescriptorImageInfo *tex_descs) { } texture_count++; } - tex_descs[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + tex_descs[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; } return texture_count; } @@ -894,7 +911,7 @@ VkDescriptorSet getDescriptorSet() { } texture_count++; } - tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; } VkWriteDescriptorSet writes[18]; @@ -946,3 +963,186 @@ VkDescriptorSet getDescriptorSet() { return descriptor_set; } + +static struct destriptor_set compute_descriptor_sets[MAX_DESCRIPTOR_SETS] = {0}; +static int compute_descriptor_sets_count = 0; + +static int write_compute_tex_descs(VkDescriptorImageInfo *tex_descs) { + memset(tex_descs, 0, sizeof(VkDescriptorImageInfo) * 16); + + int texture_count = 0; + for (int i = 0; i < 16; ++i) { + if (vulkanTextures[i] != NULL) { + tex_descs[i].sampler = vulkanSamplers[i]; + tex_descs[i].imageView = vulkanTextures[i]->impl.texture.view; + texture_count++; + } + else if (vulkanRenderTargets[i] != NULL) { + tex_descs[i].sampler = vulkanSamplers[i]; + if (vulkanRenderTargets[i]->impl.stage_depth == i) { + tex_descs[i].imageView = vulkanRenderTargets[i]->impl.depthView; + vulkanRenderTargets[i]->impl.stage_depth = -1; + } + else { + tex_descs[i].imageView = vulkanRenderTargets[i]->impl.sourceView; + } + texture_count++; + } + tex_descs[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; + } + return texture_count; +} + +static bool compute_textures_changed(struct destriptor_set *set) { + VkDescriptorImageInfo tex_desc[16]; + + write_compute_tex_descs(tex_desc); + + return memcmp(&tex_desc, &set->tex_desc, sizeof(tex_desc)) != 0; +} + +static void update_compute_textures(struct destriptor_set *set) { + memset(&set->tex_desc, 0, sizeof(set->tex_desc)); + + int texture_count = write_compute_tex_descs(set->tex_desc); + + VkWriteDescriptorSet writes[16]; + memset(&writes, 0, sizeof(writes)); + + for (int i = 0; i < 16; ++i) { + writes[i].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + writes[i].dstSet = set->set; + writes[i].dstBinding = i + 2; + writes[i].descriptorCount = 1; + writes[i].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + writes[i].pImageInfo = &set->tex_desc[i]; + } + + if (vulkanTextures[0] != NULL || vulkanRenderTargets[0] != NULL) { + vkUpdateDescriptorSets(vk_ctx.device, texture_count, writes, 0, NULL); + } +} + +void reuse_compute_descriptor_sets(void) { + for (int i = 0; i < compute_descriptor_sets_count; ++i) { + compute_descriptor_sets[i].in_use = false; + } +} + +static VkDescriptorSet get_compute_descriptor_set() { + int id = calc_compute_descriptor_id(); + for (int i = 0; i < compute_descriptor_sets_count; ++i) { + if (compute_descriptor_sets[i].id == id) { + if (!compute_descriptor_sets[i].in_use) { + compute_descriptor_sets[i].in_use = true; + update_compute_textures(&compute_descriptor_sets[i]); + return compute_descriptor_sets[i].set; + } + else { + if (!compute_textures_changed(&compute_descriptor_sets[i])) { + return compute_descriptor_sets[i].set; + } + } + } + } + + VkDescriptorSetAllocateInfo alloc_info = {0}; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.pNext = NULL; + alloc_info.descriptorPool = descriptor_pool; + alloc_info.descriptorSetCount = 1; + alloc_info.pSetLayouts = &compute_descriptor_layout; + VkDescriptorSet descriptor_set; + VkResult err = vkAllocateDescriptorSets(vk_ctx.device, &alloc_info, &descriptor_set); + assert(!err); + + VkDescriptorBufferInfo buffer_descs[2]; + + memset(&buffer_descs, 0, sizeof(buffer_descs)); + + if (vk_ctx.compute_uniform_buffer != NULL) { + buffer_descs[0].buffer = *vk_ctx.compute_uniform_buffer; + } + buffer_descs[0].offset = 0; + buffer_descs[0].range = 256 * sizeof(float); + + if (vk_ctx.compute_uniform_buffer != NULL) { + buffer_descs[1].buffer = *vk_ctx.compute_uniform_buffer; + } + buffer_descs[1].offset = 0; + buffer_descs[1].range = 256 * sizeof(float); + + VkDescriptorImageInfo tex_desc[16]; + memset(&tex_desc, 0, sizeof(tex_desc)); + + int texture_count = 0; + for (int i = 0; i < 16; ++i) { + if (vulkanTextures[i] != NULL) { + // assert(vulkanSamplers[i] != VK_NULL_HANDLE); + tex_desc[i].sampler = VK_NULL_HANDLE; // vulkanSamplers[i]; + tex_desc[i].imageView = vulkanTextures[i]->impl.texture.view; + texture_count++; + } + else if (vulkanRenderTargets[i] != NULL) { + tex_desc[i].sampler = vulkanSamplers[i]; + if (vulkanRenderTargets[i]->impl.stage_depth == i) { + tex_desc[i].imageView = vulkanRenderTargets[i]->impl.depthView; + vulkanRenderTargets[i]->impl.stage_depth = -1; + } + else { + tex_desc[i].imageView = vulkanRenderTargets[i]->impl.sourceView; + } + texture_count++; + } + tex_desc[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; + } + + VkWriteDescriptorSet writes[18]; + memset(&writes, 0, sizeof(writes)); + + writes[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + writes[0].dstSet = descriptor_set; + writes[0].dstBinding = 0; + writes[0].descriptorCount = 1; + writes[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; + writes[0].pBufferInfo = &buffer_descs[0]; + + writes[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + writes[1].dstSet = descriptor_set; + writes[1].dstBinding = 1; + writes[1].descriptorCount = 1; + writes[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; + writes[1].pBufferInfo = &buffer_descs[1]; + + for (int i = 2; i < 18; ++i) { + writes[i].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + writes[i].dstSet = descriptor_set; + writes[i].dstBinding = i; + writes[i].descriptorCount = 1; + writes[i].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + writes[i].pImageInfo = &tex_desc[i - 2]; + } + + if (vulkanTextures[0] != NULL || vulkanRenderTargets[0] != NULL) { + if (vk_ctx.compute_uniform_buffer != NULL) { + vkUpdateDescriptorSets(vk_ctx.device, 2 + texture_count, writes, 0, NULL); + } + else { + vkUpdateDescriptorSets(vk_ctx.device, texture_count, writes + 2, 0, NULL); + } + } + else { + if (vk_ctx.compute_uniform_buffer != NULL) { + vkUpdateDescriptorSets(vk_ctx.device, 2, writes, 0, NULL); + } + } + + assert(compute_descriptor_sets_count + 1 < MAX_DESCRIPTOR_SETS); + compute_descriptor_sets[compute_descriptor_sets_count].id = id; + compute_descriptor_sets[compute_descriptor_sets_count].in_use = true; + compute_descriptor_sets[compute_descriptor_sets_count].set = descriptor_set; + write_tex_descs(compute_descriptor_sets[compute_descriptor_sets_count].tex_desc); + compute_descriptor_sets_count += 1; + + return descriptor_set; +} diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.h index 0a1894b..7e52181 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/pipeline.h @@ -2,15 +2,10 @@ #include "MiniVulkan.h" +#include "named_number.h" + struct kinc_g5_shader; -#define KINC_INTERNAL_NAMED_NUMBER_COUNT 32 - -typedef struct { - char name[256]; - uint32_t number; -} kinc_internal_named_number; - typedef struct PipelineState5Impl_s { const char **textures; int *textureValues; @@ -37,6 +32,7 @@ typedef struct ComputePipelineState5Impl_t { typedef struct { int vertexOffset; int fragmentOffset; + int computeOffset; } ConstantLocation5Impl; typedef struct { diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/raytrace.c.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/raytrace.c.h index 14c97b2..0c3623e 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/raytrace.c.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/raytrace.c.h @@ -2,7 +2,7 @@ #include "raytrace.h" -#ifndef KORE_ANDROID +#ifndef KINC_ANDROID #include #include diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/raytrace.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/raytrace.h index 4110400..31538e7 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/raytrace.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/raytrace.h @@ -1,6 +1,6 @@ #pragma once -#ifndef KORE_ANDROID +#ifndef KINC_ANDROID #include "MiniVulkan.h" diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/texture.c.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/texture.c.h index 0fac5c9..6ebd953 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/texture.c.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/texture.c.h @@ -153,7 +153,7 @@ static void prepare_texture_image(uint8_t *tex_colors, uint32_t tex_width, uint3 tex_obj->imageLayout = VK_IMAGE_LAYOUT_GENERAL; } else { - tex_obj->imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + tex_obj->imageLayout = VK_IMAGE_LAYOUT_GENERAL; // VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; } set_image_layout(tex_obj->image, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, tex_obj->imageLayout); // setting the image layout does not reference the actual memory so no need to add a mem ref @@ -235,7 +235,8 @@ void kinc_g5_texture_init_from_image(kinc_g5_texture_t *texture, kinc_image_t *i if ((props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) && !use_staging_buffer) { // Device can texture using linear textures prepare_texture_image((uint8_t *)image->data, (uint32_t)image->width, (uint32_t)image->height, &texture->impl.texture, VK_IMAGE_TILING_LINEAR, - VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format); + VK_IMAGE_USAGE_SAMPLED_BIT /*| VK_IMAGE_USAGE_STORAGE_BIT*/, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, + tex_format); flush_init_cmd(); } @@ -247,8 +248,8 @@ void kinc_g5_texture_init_from_image(kinc_g5_texture_t *texture, kinc_image_t *i prepare_texture_image((uint8_t *)image->data, (uint32_t)image->width, (uint32_t)image->height, &staging_texture, VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format); prepare_texture_image((uint8_t *)image->data, (uint32_t)image->width, (uint32_t)image->height, &texture->impl.texture, VK_IMAGE_TILING_OPTIMAL, - (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture->impl.deviceSize, - tex_format); + (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT /*| VK_IMAGE_USAGE_STORAGE_BIT*/), + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture->impl.deviceSize, tex_format); set_image_layout(staging_texture.image, VK_IMAGE_ASPECT_COLOR_BIT, staging_texture.imageLayout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); set_image_layout(texture->impl.texture.image, VK_IMAGE_ASPECT_COLOR_BIT, texture->impl.texture.imageLayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); @@ -315,8 +316,9 @@ void kinc_g5_texture_init(kinc_g5_texture_t *texture, int width, int height, kin vkGetPhysicalDeviceFormatProperties(vk_ctx.gpu, tex_format, &props); // Device can texture using linear textures - prepare_texture_image(NULL, (uint32_t)width, (uint32_t)height, &texture->impl.texture, VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_SAMPLED_BIT, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, tex_format); + prepare_texture_image(NULL, (uint32_t)width, (uint32_t)height, &texture->impl.texture, VK_IMAGE_TILING_LINEAR, + VK_IMAGE_USAGE_SAMPLED_BIT /*| VK_IMAGE_USAGE_STORAGE_BIT*/, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &texture->impl.deviceSize, + tex_format); flush_init_cmd(); diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vertexbuffer.c.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vertexbuffer.c.h index e6f9925..a06fdc3 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vertexbuffer.c.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vertexbuffer.c.h @@ -27,7 +27,7 @@ void kinc_g5_vertex_buffer_init(kinc_g5_vertex_buffer_t *buffer, int vertexCount buf_info.pNext = NULL; buf_info.size = vertexCount * buffer->impl.myStride; buf_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; -#ifdef KORE_VKRT +#ifdef KINC_VKRT buf_info.usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; #endif buf_info.flags = 0; @@ -54,7 +54,7 @@ void kinc_g5_vertex_buffer_init(kinc_g5_vertex_buffer_t *buffer, int vertexCount pass = memory_type_from_properties(mem_reqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &buffer->impl.mem_alloc.memoryTypeIndex); assert(pass); -#ifdef KORE_VKRT +#ifdef KINC_VKRT VkMemoryAllocateFlagsInfo memory_allocate_flags_info = {0}; memory_allocate_flags_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO; memory_allocate_flags_info.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR; diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vulkan.h b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vulkan.h index c18b13e..0bff547 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vulkan.h +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vulkan.h @@ -74,6 +74,7 @@ struct vk_context { // buffer hack VkBuffer *vertex_uniform_buffer; VkBuffer *fragment_uniform_buffer; + VkBuffer *compute_uniform_buffer; int current_window; @@ -88,5 +89,6 @@ extern struct vk_context vk_ctx; extern void flush_init_cmd(void); extern void reuse_descriptor_sets(void); +extern void reuse_compute_descriptor_sets(void); #include diff --git a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vulkanunit.c b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vulkanunit.c index b95a282..762799a 100644 --- a/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vulkanunit.c +++ b/Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vulkanunit.c @@ -1,4 +1,4 @@ -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS // Windows 7 #define WINVER 0x0601 @@ -17,7 +17,7 @@ #define NOICONS #define NOKANJI #define NOKEYSTATES -//#define NOMB +// #define NOMB #define NOMCX #define NOMEMMGR #define NOMENUS @@ -35,7 +35,7 @@ #define NOSYSCOMMANDS #define NOSYSMETRICS #define NOTEXTMETRIC -//#define NOUSER +// #define NOUSER #define NOVIRTUALKEYCODES #define NOWH #define NOWINMESSAGES @@ -72,15 +72,18 @@ static VkSemaphore framebuffer_available; static VkSemaphore relay_semaphore; static bool wait_for_relay = false; static void command_list_should_wait_for_framebuffer(void); +static VkDescriptorSetLayout compute_descriptor_layout; +#include "ShaderHash.c.h" #include "Vulkan.c.h" -#include "sampler.c.h" #include "commandlist.c.h" +#include "compute.c.h" #include "constantbuffer.c.h" #include "indexbuffer.c.h" #include "pipeline.c.h" #include "raytrace.c.h" #include "rendertarget.c.h" +#include "sampler.c.h" #include "shader.c.h" #include "texture.c.h" -#include "vertexbuffer.c.h" +#include "vertexbuffer.c.h" \ No newline at end of file diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/compute.cpp b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/compute.cpp deleted file mode 100644 index 986bc8d..0000000 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/compute.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include - -void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *source, int length) {} - -void kinc_compute_shader_destroy(kinc_compute_shader_t *shader) {} - -kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_constant_location_t location; - location.impl.nothing = 0; - return location; -} - -kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name) { - kinc_compute_texture_unit_t unit; - unit.impl.nothing = 0; - return unit; -} - -void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value) {} -void kinc_compute_set_int(kinc_compute_constant_location_t location, int value) {} -void kinc_compute_set_float(kinc_compute_constant_location_t location, float value) {} -void kinc_compute_set_float2(kinc_compute_constant_location_t location, float value1, float value2) {} -void kinc_compute_set_float3(kinc_compute_constant_location_t location, float value1, float value2, float value3) {} -void kinc_compute_set_float4(kinc_compute_constant_location_t location, float value1, float value2, float value3, float value4) {} -void kinc_compute_set_floats(kinc_compute_constant_location_t location, float *values, int count) {} -void kinc_compute_set_matrix4(kinc_compute_constant_location_t location, kinc_matrix4x4_t *value) {} -void kinc_compute_set_matrix3(kinc_compute_constant_location_t location, kinc_matrix3x3_t *value) {} -void kinc_compute_set_texture(kinc_compute_texture_unit_t unit, kinc_g4_texture *texture, kinc_compute_access_t access) {} -void kinc_compute_set_render_target(kinc_compute_texture_unit_t unit, kinc_g4_render_target *texture, kinc_compute_access_t access) {} -void kinc_compute_set_sampled_texture(kinc_compute_texture_unit_t unit, kinc_g4_texture *texture) {} -void kinc_compute_set_sampled_render_target(kinc_compute_texture_unit_t unit, kinc_g4_render_target *target) {} -void kinc_compute_set_sampled_depth_from_render_target(kinc_compute_texture_unit_t unit, kinc_g4_render_target *target) {} -void kinc_compute_set_texture_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} -void kinc_compute_set_texture_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} -void kinc_compute_set_texture_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} -void kinc_compute_set_texture_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} -void kinc_compute_set_texture3d_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {} -void kinc_compute_set_texture3d_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} -void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter) {} -void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} -void kinc_compute_set_shader(kinc_compute_shader_t *shader) {} -void kinc_compute(int x, int y, int z) {} diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/compute.h b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/compute.h deleted file mode 100644 index ad6125c..0000000 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/compute.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -typedef struct { - int nothing; -} kinc_compute_constant_location_impl_t; - -typedef struct { - int nothing; -} kinc_compute_texture_unit_impl_t; - -typedef struct { - int nothing; -} kinc_compute_shader_impl_t; diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/WebGPU.c b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/WebGPU.c index b448d1b..1fd6cf6 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/WebGPU.c +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/WebGPU.c @@ -1,13 +1,13 @@ -#include #include #include #include -#include #include #include +#include #include #include -#include +#include +#include int renderTargetWidth; int renderTargetHeight; diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/commandlist.c b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/commandlist.c index 57f1944..02962a9 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/commandlist.c +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/commandlist.c @@ -1,9 +1,10 @@ -#include #include +#include #include #include #include #include +#include extern WGPUDevice device; extern WGPUQueue queue; @@ -20,7 +21,8 @@ void kinc_g5_command_list_begin(kinc_g5_command_list_t *list) { WGPURenderPassColorAttachment attachment; memset(&attachment, 0, sizeof(attachment)); - attachment.view = wgpuSwapChainGetCurrentTextureView(swapChain);; + attachment.view = wgpuSwapChainGetCurrentTextureView(swapChain); + ; attachment.loadOp = WGPULoadOp_Clear; attachment.storeOp = WGPUStoreOp_Store; WGPUColor color = {0, 0, 0, 1}; @@ -44,9 +46,7 @@ void kinc_g5_command_list_end(kinc_g5_command_list_t *list) { } void kinc_g5_command_list_clear(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget, unsigned flags, unsigned color, float depth, - int stencil) { - -} + int stencil) {} void kinc_g5_command_list_render_target_to_framebuffer_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {} void kinc_g5_command_list_framebuffer_to_render_target_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget) {} @@ -57,24 +57,14 @@ void kinc_g5_command_list_draw_indexed_vertices(kinc_g5_command_list_t *list) { wgpuRenderPassEncoderDrawIndexed(list->impl.pass, list->impl.indexCount, 1, 0, 0, 0); } -void kinc_g5_command_list_draw_indexed_vertices_from_to(kinc_g5_command_list_t *list, int start, int count) { +void kinc_g5_command_list_draw_indexed_vertices_from_to(kinc_g5_command_list_t *list, int start, int count) {} -} +void kinc_g5_command_list_draw_indexed_vertices_instanced(kinc_g5_command_list_t *list, int instanceCount) {} +void kinc_g5_command_list_draw_indexed_vertices_instanced_from_to(kinc_g5_command_list_t *list, int instanceCount, int start, int count) {} -void kinc_g5_command_list_draw_indexed_vertices_instanced(kinc_g5_command_list_t *list, int instanceCount) { +void kinc_g5_command_list_viewport(kinc_g5_command_list_t *list, int x, int y, int width, int height) {} -} -void kinc_g5_command_list_draw_indexed_vertices_instanced_from_to(kinc_g5_command_list_t *list, int instanceCount, int start, int count) { - -} - -void kinc_g5_command_list_viewport(kinc_g5_command_list_t *list, int x, int y, int width, int height) { - -} - -void kinc_g5_command_list_scissor(kinc_g5_command_list_t *list, int x, int y, int width, int height) { - -} +void kinc_g5_command_list_scissor(kinc_g5_command_list_t *list, int x, int y, int width, int height) {} void kinc_g5_command_list_disable_scissor(kinc_g5_command_list_t *list) {} @@ -96,40 +86,30 @@ void kinc_g5_command_list_set_vertex_buffers(kinc_g5_command_list_t *list, struc void kinc_g5_command_list_set_index_buffer(kinc_g5_command_list_t *list, struct kinc_g5_index_buffer *buffer) { list->impl.indexCount = kinc_g5_index_buffer_count(buffer); uint64_t size = kinc_g5_index_buffer_count(buffer) * sizeof(int); - wgpuRenderPassEncoderSetIndexBuffer(list->impl.pass, buffer->impl.buffer, buffer->impl.format == KINC_G5_INDEX_BUFFER_FORMAT_16BIT ? WGPUIndexFormat_Uint16 : WGPUIndexFormat_Uint32, 0, size); + wgpuRenderPassEncoderSetIndexBuffer(list->impl.pass, buffer->impl.buffer, + buffer->impl.format == KINC_G5_INDEX_BUFFER_FORMAT_16BIT ? WGPUIndexFormat_Uint16 : WGPUIndexFormat_Uint32, 0, size); } -void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struct kinc_g5_render_target **targets, int count) { - -} +void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struct kinc_g5_render_target **targets, int count) {} void kinc_g5_command_list_upload_index_buffer(kinc_g5_command_list_t *list, struct kinc_g5_index_buffer *buffer) {} void kinc_g5_command_list_upload_vertex_buffer(kinc_g5_command_list_t *list, struct kinc_g5_vertex_buffer *buffer) {} void kinc_g5_command_list_upload_texture(kinc_g5_command_list_t *list, struct kinc_g5_texture *texture) {} void kinc_g5_command_list_get_render_target_pixels(kinc_g5_command_list_t *list, kinc_g5_render_target_t *render_target, uint8_t *data) {} -void kinc_g5_command_list_execute(kinc_g5_command_list_t *list) { +void kinc_g5_command_list_execute(kinc_g5_command_list_t *list) {} -} +void kinc_g5_command_list_wait_for_execution_to_finish(kinc_g5_command_list_t *list) {} -void kinc_g5_command_list_wait_for_execution_to_finish(kinc_g5_command_list_t *list) { +void kinc_g5_command_list_set_vertex_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) {} -} - -void kinc_g5_command_list_set_vertex_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) { - -} - -void kinc_g5_command_list_set_fragment_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) { - -} +void kinc_g5_command_list_set_fragment_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) {} +void kinc_g5_command_list_set_compute_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) {} void kinc_g5_command_list_set_render_target_face(kinc_g5_command_list_t *list, kinc_g5_render_target_t *texture, int face) {} -void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) { - -} +void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture) {} void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler) {} @@ -151,4 +131,9 @@ void kinc_g5_command_list_get_query_result(kinc_g5_command_list_t *list, unsigne void kinc_g5_command_list_set_texture_from_render_target(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_render_target_t *renderTarget) {} -void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_render_target_t *renderTarget) {} +void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, + kinc_g5_render_target_t *renderTarget) {} + +void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, kinc_g5_compute_shader *shader) {} + +void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z) {} diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/compute.c b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/compute.c new file mode 100644 index 0000000..6869e08 --- /dev/null +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/compute.c @@ -0,0 +1,16 @@ +#include +#include + +void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *source, int length) {} + +void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader) {} + +kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_location(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_constant_location_t location = {0}; + return location; +} + +kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_shader *shader, const char *name) { + kinc_g5_texture_unit_t unit = {0}; + return unit; +} diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/compute.h b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/compute.h new file mode 100644 index 0000000..cbea4ec --- /dev/null +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/compute.h @@ -0,0 +1,5 @@ +#pragma once + +typedef struct kinc_g5_compute_shader_impl { + int nothing; +} kinc_g5_compute_shader_impl; diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/constantbuffer.c b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/constantbuffer.c index 2edbd54..1f3d76e 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/constantbuffer.c +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/constantbuffer.c @@ -9,9 +9,7 @@ extern "C" { bool kinc_g5_transposeMat3 = false; bool kinc_g5_transposeMat4 = false; -void kinc_g5_constant_buffer_init(kinc_g5_constant_buffer_t *buffer, int size) { - -} +void kinc_g5_constant_buffer_init(kinc_g5_constant_buffer_t *buffer, int size) {} void kinc_g5_constant_buffer_destroy(kinc_g5_constant_buffer_t *buffer) {} @@ -21,9 +19,7 @@ void kinc_g5_constant_buffer_lock_all(kinc_g5_constant_buffer_t *buffer) { void kinc_g5_constant_buffer_lock(kinc_g5_constant_buffer_t *buffer, int start, int count) {} -void kinc_g5_constant_buffer_unlock(kinc_g5_constant_buffer_t *buffer) { - -} +void kinc_g5_constant_buffer_unlock(kinc_g5_constant_buffer_t *buffer) {} int kinc_g5_constant_buffer_size(kinc_g5_constant_buffer_t *buffer) { return 0; diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/indexbuffer.c b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/indexbuffer.c index ff73833..eaeba7b 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/indexbuffer.c +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/indexbuffer.c @@ -1,8 +1,8 @@ #include -#include -#include #include +#include +#include extern WGPUDevice device; @@ -13,9 +13,7 @@ void kinc_g5_index_buffer_init(kinc_g5_index_buffer_t *buffer, int count, kinc_g buffer->impl.format = format; } -void kinc_g5_index_buffer_destroy(kinc_g5_index_buffer_t *buffer) { - -} +void kinc_g5_index_buffer_destroy(kinc_g5_index_buffer_t *buffer) {} static int kinc_g5_internal_index_buffer_stride(kinc_g5_index_buffer_t *buffer) { return buffer->impl.format == KINC_G5_INDEX_BUFFER_FORMAT_16BIT ? 2 : 4; @@ -43,9 +41,7 @@ void kinc_g5_index_buffer_unlock(kinc_g5_index_buffer_t *buffer, int count) { kinc_g5_index_buffer_unlock_all(buffer); } -void kinc_g5_internal_index_buffer_set(kinc_g5_index_buffer_t *buffer) { - -} +void kinc_g5_internal_index_buffer_set(kinc_g5_index_buffer_t *buffer) {} int kinc_g5_index_buffer_count(kinc_g5_index_buffer_t *buffer) { return buffer->impl.count; diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.c b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.c index 28098eb..1158245 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.c +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.c @@ -1,20 +1,16 @@ -#include #include +#include #include #include extern WGPUDevice device; -#ifdef KINC_KONG -extern WGPUShaderModule kinc_g5_internal_webgpu_shader_module; -#endif - void kinc_g5_pipeline_init(kinc_g5_pipeline_t *pipe) { kinc_g5_internal_pipeline_init(pipe); } -kinc_g5_constant_location_t kinc_g5_pipeline_get_constant_location(kinc_g5_pipeline_t *pipe, const char* name) { +kinc_g5_constant_location_t kinc_g5_pipeline_get_constant_location(kinc_g5_pipeline_t *pipe, const char *name) { kinc_g5_constant_location_t location; return location; } @@ -92,7 +88,7 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) { vaDesc[i].format = WGPUVertexFormat_Sint8x2; break; case KINC_G4_VERTEX_DATA_U8_2X: - vaDesc[i].format = WGPUVertexFormat_Uint8x2 ; + vaDesc[i].format = WGPUVertexFormat_Uint8x2; break; case KINC_G4_VERTEX_DATA_I8_2X_NORMALIZED: vaDesc[i].format = WGPUVertexFormat_Snorm8x2; @@ -187,25 +183,15 @@ void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipe) { WGPUVertexState vsDest; memset(&vsDest, 0, sizeof(vsDest)); -#ifdef KINC_KONG - vsDest.module = kinc_g5_internal_webgpu_shader_module; - vsDest.entryPoint = pipe->vertexShader->impl.entry_name; -#else vsDest.module = pipe->vertexShader->impl.module; vsDest.entryPoint = "main"; -#endif vsDest.bufferCount = 1; vsDest.buffers = &vbDesc; WGPUFragmentState fragmentDest; memset(&fragmentDest, 0, sizeof(fragmentDest)); -#ifdef KINC_KONG - fragmentDest.module = kinc_g5_internal_webgpu_shader_module; - fragmentDest.entryPoint = pipe->fragmentShader->impl.entry_name; -#else fragmentDest.module = pipe->fragmentShader->impl.module; fragmentDest.entryPoint = "main"; -#endif fragmentDest.targetCount = 1; fragmentDest.targets = &csDesc; diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.h b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.h index b1611e3..fb00609 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.h +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/pipeline.h @@ -17,6 +17,7 @@ typedef struct { typedef struct { int vertexOffset; int fragmentOffset; + int computeOffset; } ConstantLocation5Impl; #ifdef __cplusplus diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/rendertarget.c b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/rendertarget.c index 582e702..60bd14d 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/rendertarget.c +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/rendertarget.c @@ -2,9 +2,7 @@ #include void kinc_g5_render_target_init_with_multisampling(kinc_g5_render_target_t *target, int width, int height, kinc_g5_render_target_format_t format, - int depthBufferBits, int stencilBufferBits, int samples_per_pixel) { - -} + int depthBufferBits, int stencilBufferBits, int samples_per_pixel) {} void kinc_g5_render_target_init_framebuffer_with_multisampling(kinc_g5_render_target_t *target, int width, int height, kinc_g5_render_target_format_t format, int depthBufferBits, int stencilBufferBits, int samples_per_pixel) {} diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c index daf79a7..4b769e5 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.c @@ -4,24 +4,6 @@ extern WGPUDevice device; -#ifdef KINC_KONG -WGPUShaderModule kinc_g5_internal_webgpu_shader_module; - -void kinc_g5_internal_webgpu_create_shader_module(const void *source, size_t length) { - WGPUShaderModuleWGSLDescriptor wgsl_desc = {0}; - wgsl_desc.code = (const char *)source; - wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor; - - WGPUShaderModuleDescriptor desc = {0}; - desc.nextInChain = (WGPUChainedStruct *)(&wgsl_desc); - - kinc_g5_internal_webgpu_shader_module = wgpuDeviceCreateShaderModule(device, &desc); -} - -void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t length, kinc_g5_shader_type_t type) { - strcpy(&shader->impl.entry_name[0], source); -} -#else void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t length, kinc_g5_shader_type_t type) { WGPUShaderModuleSPIRVDescriptor smSpirvDesc; memset(&smSpirvDesc, 0, sizeof(smSpirvDesc)); @@ -33,6 +15,5 @@ void kinc_g5_shader_init(kinc_g5_shader_t *shader, const void *source, size_t le smDesc.nextInChain = &smSpirvDesc; shader->impl.module = wgpuDeviceCreateShaderModule(device, &smDesc); } -#endif void kinc_g5_shader_destroy(kinc_g5_shader_t *shader) {} diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h index 125e8eb..8a7036e 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/shader.h @@ -9,11 +9,7 @@ extern "C" { struct WGPUShaderModuleImpl; typedef struct { -#ifdef KINC_KONG - char entry_name[256]; -#else WGPUShaderModule module; -#endif } Shader5Impl; #ifdef __cplusplus diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/texture.c b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/texture.c index dc5b583..f37cf6c 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/texture.c +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/texture.c @@ -20,8 +20,7 @@ void kinc_g5_texture_init(kinc_g5_texture_t *texture, int width, int height, kin // WGPUTextureViewDescriptor tvDesc = {}; // tvDesc.format = WGPUTextureFormat_BGRA8Unorm; // tvDesc.dimension = WGPUTextureViewDimension_2D; - // WGPUTextureView textureView = wgpuTextureCreateView(texture, &tvDesc); - + // WGPUTextureView textureView = wgpuTextureCreateView(texture, &tvDesc); } void kinc_g5_texture_init3d(kinc_g5_texture_t *texture, int width, int height, int depth, kinc_image_format_t format) {} void kinc_g5_texture_init_from_image(kinc_g5_texture_t *texture, kinc_image_t *image) {} diff --git a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/vertexbuffer.c b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/vertexbuffer.c index ad7e81b..5812955 100644 --- a/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/vertexbuffer.c +++ b/Kinc/Backends/Graphics5/WebGPU/Sources/kinc/backend/graphics5/vertexbuffer.c @@ -1,7 +1,7 @@ -#include -#include #include #include +#include +#include extern WGPUDevice device; @@ -15,9 +15,7 @@ void kinc_g5_vertex_buffer_init(kinc_g5_vertex_buffer_t *buffer, int count, kinc } } -void kinc_g5_vertex_buffer_destroy(kinc_g5_vertex_buffer_t *buffer) { - -} +void kinc_g5_vertex_buffer_destroy(kinc_g5_vertex_buffer_t *buffer) {} float *kinc_g5_vertex_buffer_lock_all(kinc_g5_vertex_buffer_t *buffer) { WGPUBufferDescriptor bDesc; @@ -37,9 +35,7 @@ void kinc_g5_vertex_buffer_unlock_all(kinc_g5_vertex_buffer_t *buffer) { wgpuBufferUnmap(buffer->impl.buffer); } -void kinc_g5_vertex_buffer_unlock(kinc_g5_vertex_buffer_t* buffer, int count) { - -} +void kinc_g5_vertex_buffer_unlock(kinc_g5_vertex_buffer_t *buffer, int count) {} int kinc_g5_vertex_buffer_count(kinc_g5_vertex_buffer_t *buffer) { return buffer->impl.count; diff --git a/Kinc/Backends/System/Android/Java-Sources/tech/kinc/KincActivity.kt b/Kinc/Backends/System/Android/Java-Sources/tech/kore/KoreActivity.kt similarity index 93% rename from Kinc/Backends/System/Android/Java-Sources/tech/kinc/KincActivity.kt rename to Kinc/Backends/System/Android/Java-Sources/tech/kore/KoreActivity.kt index 1660b59..f4a62f1 100644 --- a/Kinc/Backends/System/Android/Java-Sources/tech/kinc/KincActivity.kt +++ b/Kinc/Backends/System/Android/Java-Sources/tech/kore/KoreActivity.kt @@ -1,4 +1,4 @@ -package tech.kinc +package tech.kore import android.app.NativeActivity import android.content.Context @@ -18,9 +18,9 @@ import android.view.WindowManager import android.view.inputmethod.InputMethodManager import kotlin.system.exitProcess -class KincActivity: NativeActivity(), KeyEvent.Callback { +class KoreActivity: NativeActivity(), KeyEvent.Callback { companion object { - var instance: KincActivity? = null + var instance: KoreActivity? = null @JvmStatic fun showKeyboard() { @@ -107,9 +107,9 @@ class KincActivity: NativeActivity(), KeyEvent.Callback { } } - class MyHandler(private val kincActivity: KincActivity) : Handler() { + class MyHandler(private val koreActivity: KoreActivity) : Handler() { override fun handleMessage(msg: Message) { - kincActivity.hideSystemUI() + koreActivity.hideSystemUI() } } } @@ -157,9 +157,9 @@ class KincActivity: NativeActivity(), KeyEvent.Callback { } override fun onKeyMultiple(keyCode: Int, count: Int, event: KeyEvent): Boolean { - this.nativeKincKeyPress(event.characters) + this.nativeKoreKeyPress(event.characters) return false } - private external fun nativeKincKeyPress(chars: String) + private external fun nativeKoreKeyPress(chars: String) } diff --git a/Kinc/Backends/System/Android/Java-Sources/tech/kinc/KincMoviePlayer.kt b/Kinc/Backends/System/Android/Java-Sources/tech/kore/KoreMoviePlayer.kt similarity index 68% rename from Kinc/Backends/System/Android/Java-Sources/tech/kinc/KincMoviePlayer.kt rename to Kinc/Backends/System/Android/Java-Sources/tech/kore/KoreMoviePlayer.kt index 724f52b..c73d4c7 100644 --- a/Kinc/Backends/System/Android/Java-Sources/tech/kinc/KincMoviePlayer.kt +++ b/Kinc/Backends/System/Android/Java-Sources/tech/kore/KoreMoviePlayer.kt @@ -1,16 +1,16 @@ -package tech.kinc +package tech.kore import java.util.ArrayList import android.view.Surface -class KincMoviePlayer(var path: String) { +class KoreMoviePlayer(var path: String) { companion object { - var players = ArrayList() + var players = ArrayList() @JvmStatic fun updateAll() { - for (player in KincMoviePlayer.players) { + for (player in KoreMoviePlayer.players) { player!!.update() } } @@ -20,7 +20,7 @@ class KincMoviePlayer(var path: String) { } } - private var movieTexture: KincMovieTexture? = null + private var movieTexture: KoreMovieTexture? = null var id: Int = players.size init { @@ -28,13 +28,13 @@ class KincMoviePlayer(var path: String) { } fun init() { - movieTexture = KincMovieTexture() + movieTexture = KoreMovieTexture() val surface = Surface(movieTexture!!.surfaceTexture) nativeCreate(path, surface, id) surface.release() } - fun getMovieTexture(): KincMovieTexture? { + fun getMovieTexture(): KoreMovieTexture? { return movieTexture } diff --git a/Kinc/Backends/System/Android/Java-Sources/tech/kinc/KincMovieTexture.kt b/Kinc/Backends/System/Android/Java-Sources/tech/kore/KoreMovieTexture.kt similarity index 94% rename from Kinc/Backends/System/Android/Java-Sources/tech/kinc/KincMovieTexture.kt rename to Kinc/Backends/System/Android/Java-Sources/tech/kore/KoreMovieTexture.kt index ed058b8..b881d03 100644 --- a/Kinc/Backends/System/Android/Java-Sources/tech/kinc/KincMovieTexture.kt +++ b/Kinc/Backends/System/Android/Java-Sources/tech/kore/KoreMovieTexture.kt @@ -1,10 +1,10 @@ -package tech.kinc +package tech.kore import android.graphics.SurfaceTexture import android.graphics.SurfaceTexture.OnFrameAvailableListener import android.opengl.GLES20 -class KincMovieTexture: OnFrameAvailableListener { +class KoreMovieTexture: OnFrameAvailableListener { private val GL_TEXTURE_EXTERNAL_OES: Int = 0x8D65 var textureId: Int = 0 diff --git a/Kinc/Backends/System/Android/Sources/android_native_app_glue.c b/Kinc/Backends/System/Android/Sources/Android/android_native_app_glue.c similarity index 100% rename from Kinc/Backends/System/Android/Sources/android_native_app_glue.c rename to Kinc/Backends/System/Android/Sources/Android/android_native_app_glue.c diff --git a/Kinc/Backends/System/Android/Sources/android_native_app_glue.h b/Kinc/Backends/System/Android/Sources/Android/android_native_app_glue.h similarity index 100% rename from Kinc/Backends/System/Android/Sources/android_native_app_glue.h rename to Kinc/Backends/System/Android/Sources/Android/android_native_app_glue.h diff --git a/Kinc/Backends/System/Android/Sources/kinc/backend/Android.h b/Kinc/Backends/System/Android/Sources/kinc/backend/Android.h index b1f91e0..ef7a202 100644 --- a/Kinc/Backends/System/Android/Sources/kinc/backend/Android.h +++ b/Kinc/Backends/System/Android/Sources/kinc/backend/Android.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #ifdef __cplusplus extern "C" { diff --git a/Kinc/Backends/System/Android/Sources/kinc/backend/androidunit.c b/Kinc/Backends/System/Android/Sources/kinc/backend/androidunit.c index f4a4e00..bdc6eb8 100644 --- a/Kinc/Backends/System/Android/Sources/kinc/backend/androidunit.c +++ b/Kinc/Backends/System/Android/Sources/kinc/backend/androidunit.c @@ -1,5 +1,5 @@ #include "audio.c.h" #include "display.c.h" #include "system.c.h" -#include "window.c.h" -#include "video.c.h" \ No newline at end of file +#include "video.c.h" +#include "window.c.h" \ No newline at end of file diff --git a/Kinc/Backends/System/Android/Sources/kinc/backend/audio.c.h b/Kinc/Backends/System/Android/Sources/kinc/backend/audio.c.h index 7397b55..7ee362d 100644 --- a/Kinc/Backends/System/Android/Sources/kinc/backend/audio.c.h +++ b/Kinc/Backends/System/Android/Sources/kinc/backend/audio.c.h @@ -6,7 +6,6 @@ #include #include -static void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = NULL; static kinc_a2_buffer_t a2_buffer; static SLObjectItf engineObject; @@ -19,25 +18,26 @@ static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue; static int16_t tempBuffer[AUDIO_BUFFER_SIZE]; static void copySample(void *buffer) { - float value = *(float *)&a2_buffer.data[a2_buffer.read_location]; - a2_buffer.read_location += 4; - if (a2_buffer.read_location >= a2_buffer.data_size) + float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location]; + float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location]; + a2_buffer.read_location += 1; + if (a2_buffer.read_location >= a2_buffer.data_size) { a2_buffer.read_location = 0; - *(int16_t *)buffer = (int16_t)(value * 32767); + } + ((int16_t *)buffer)[0] = (int16_t)(left_value * 32767); + ((int16_t *)buffer)[1] = (int16_t)(right_value * 32767); } static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf caller, void *context) { - if (a2_callback != NULL) { - a2_callback(&a2_buffer, AUDIO_BUFFER_SIZE); - for (int i = 0; i < AUDIO_BUFFER_SIZE; i++) { + if (kinc_a2_internal_callback(&a2_buffer, AUDIO_BUFFER_SIZE / 2)) { + for (int i = 0; i < AUDIO_BUFFER_SIZE; i += 2) { copySample(&tempBuffer[i]); } - SLresult result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, tempBuffer, AUDIO_BUFFER_SIZE * 2); } else { memset(tempBuffer, 0, sizeof(tempBuffer)); - SLresult result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, tempBuffer, AUDIO_BUFFER_SIZE * 2); } + SLresult result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, tempBuffer, AUDIO_BUFFER_SIZE * 2); } static bool initialized = false; @@ -47,13 +47,15 @@ void kinc_a2_init() { return; } + kinc_a2_internal_init(); initialized = true; - kinc_a2_samples_per_second = 44100; a2_buffer.read_location = 0; a2_buffer.write_location = 0; a2_buffer.data_size = 128 * 1024; - a2_buffer.data = malloc(a2_buffer.data_size); + a2_buffer.channel_count = 2; + a2_buffer.channels[0] = (float *)malloc(a2_buffer.data_size * sizeof(float)); + a2_buffer.channels[1] = (float *)malloc(a2_buffer.data_size * sizeof(float)); SLresult result; result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); @@ -93,14 +95,16 @@ void kinc_a2_init() { } void pauseAudio() { - if (bqPlayerPlay == NULL) + if (bqPlayerPlay == NULL) { return; + } SLresult result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PAUSED); } void resumeAudio() { - if (bqPlayerPlay == NULL) + if (bqPlayerPlay == NULL) { return; + } SLresult result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING); } @@ -124,6 +128,6 @@ void kinc_a2_shutdown() { } } -void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) { - a2_callback = kinc_a2_audio_callback; +uint32_t kinc_a2_samples_per_second(void) { + return 44100; } diff --git a/Kinc/Backends/System/Android/Sources/kinc/backend/display.c.h b/Kinc/Backends/System/Android/Sources/kinc/backend/display.c.h index 5ed5f4f..7f6b123 100644 --- a/Kinc/Backends/System/Android/Sources/kinc/backend/display.c.h +++ b/Kinc/Backends/System/Android/Sources/kinc/backend/display.c.h @@ -27,7 +27,7 @@ static int width() { JNIEnv *env; JavaVM *vm = kinc_android_get_activity()->vm; (*vm)->AttachCurrentThread(vm, &env, NULL); - jclass koreActivityClass = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass koreActivityClass = kinc_android_find_class(env, "tech.kore.KoreActivity"); jmethodID koreActivityGetScreenDpi = (*env)->GetStaticMethodID(env, koreActivityClass, "getDisplayWidth", "()I"); int width = (*env)->CallStaticIntMethod(env, koreActivityClass, koreActivityGetScreenDpi); (*vm)->DetachCurrentThread(vm); @@ -38,7 +38,7 @@ static int height() { JNIEnv *env; JavaVM *vm = kinc_android_get_activity()->vm; (*vm)->AttachCurrentThread(vm, &env, NULL); - jclass koreActivityClass = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass koreActivityClass = kinc_android_find_class(env, "tech.kore.KoreActivity"); jmethodID koreActivityGetScreenDpi = (*env)->GetStaticMethodID(env, koreActivityClass, "getDisplayHeight", "()I"); int height = (*env)->CallStaticIntMethod(env, koreActivityClass, koreActivityGetScreenDpi); (*vm)->DetachCurrentThread(vm); @@ -49,7 +49,7 @@ static int pixelsPerInch() { JNIEnv *env; JavaVM *vm = kinc_android_get_activity()->vm; (*vm)->AttachCurrentThread(vm, &env, NULL); - jclass koreActivityClass = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass koreActivityClass = kinc_android_find_class(env, "tech.kore.KoreActivity"); jmethodID koreActivityGetScreenDpi = (*env)->GetStaticMethodID(env, koreActivityClass, "getScreenDpi", "()I"); int dpi = (*env)->CallStaticIntMethod(env, koreActivityClass, koreActivityGetScreenDpi); (*vm)->DetachCurrentThread(vm); @@ -60,7 +60,7 @@ static int refreshRate() { JNIEnv *env; JavaVM *vm = kinc_android_get_activity()->vm; (*vm)->AttachCurrentThread(vm, &env, NULL); - jclass koreActivityClass = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass koreActivityClass = kinc_android_find_class(env, "tech.kore.KoreActivity"); jmethodID koreActivityGetScreenDpi = (*env)->GetStaticMethodID(env, koreActivityClass, "getRefreshRate", "()I"); int dpi = (*env)->CallStaticIntMethod(env, koreActivityClass, koreActivityGetScreenDpi); (*vm)->DetachCurrentThread(vm); diff --git a/Kinc/Backends/System/Android/Sources/kinc/backend/system.c.h b/Kinc/Backends/System/Android/Sources/kinc/backend/system.c.h index e473dd5..5cf5552 100644 --- a/Kinc/Backends/System/Android/Sources/kinc/backend/system.c.h +++ b/Kinc/Backends/System/Android/Sources/kinc/backend/system.c.h @@ -8,9 +8,9 @@ #include #include // #include +#include #include #include -#include #include #include #include @@ -43,6 +43,7 @@ static bool activityJustResized = false; #include #ifdef KINC_EGL + EGLDisplay kinc_egl_get_display() { return eglGetDisplay(EGL_DEFAULT_DISPLAY); } @@ -57,11 +58,14 @@ EGLNativeWindowType kinc_egl_get_native_window(EGLDisplay display, EGLConfig con } return app->window; } + #endif -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN + #include #include + VkResult kinc_vulkan_create_surface(VkInstance instance, int window_index, VkSurfaceKHR *surface) { assert(app->window != NULL); VkAndroidSurfaceCreateInfoKHR createInfo = {}; @@ -88,25 +92,25 @@ VkBool32 kinc_vulkan_get_physical_device_presentation_support(VkPhysicalDevice p } #endif -#ifndef KORE_VULKAN +#ifndef KINC_VULKAN void kinc_egl_init_window(int window); void kinc_egl_destroy_window(int window); #endif -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN void kinc_vulkan_init_window(int window); #endif static void initDisplay() { -#ifndef KORE_VULKAN +#ifndef KINC_VULKAN kinc_egl_init_window(0); #endif -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN kinc_vulkan_init_window(0); #endif } static void termDisplay() { -#ifndef KORE_VULKAN +#ifndef KINC_VULKAN kinc_egl_destroy_window(0); #endif } @@ -872,7 +876,7 @@ static uint16_t unicode_stack[UNICODE_STACK_SIZE]; static int unicode_stack_index = 0; static kinc_mutex_t unicode_mutex; -JNIEXPORT void JNICALL Java_tech_kinc_KincActivity_nativeKincKeyPress(JNIEnv *env, jobject jobj, jstring chars) { +JNIEXPORT void JNICALL Java_tech_kore_KoreActivity_nativeKoreKeyPress(JNIEnv *env, jobject jobj, jstring chars) { const jchar *text = (*env)->GetStringChars(env, chars, NULL); const jsize length = (*env)->GetStringLength(env, chars); @@ -889,17 +893,17 @@ void KincAndroidKeyboardInit() { JNIEnv *env; (*activity->vm)->AttachCurrentThread(activity->vm, &env, NULL); - jclass clazz = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass clazz = kinc_android_find_class(env, "tech.kore.KoreActivity"); // String chars - JNINativeMethod methodTable[] = {{"nativeKincKeyPress", "(Ljava/lang/String;)V", (void *)Java_tech_kinc_KincActivity_nativeKincKeyPress}}; + JNINativeMethod methodTable[] = {{"nativeKoreKeyPress", "(Ljava/lang/String;)V", (void *)Java_tech_kore_KoreActivity_nativeKoreKeyPress}}; int methodTableSize = sizeof(methodTable) / sizeof(methodTable[0]); int failure = (*env)->RegisterNatives(env, clazz, methodTable, methodTableSize); - if (failure != 0) { - kinc_log(KINC_LOG_LEVEL_WARNING, "Failed to register KincActivity.nativeKincKeyPress"); - } + if (failure != 0) { + kinc_log(KINC_LOG_LEVEL_WARNING, "Failed to register KoreActivity.nativeKoreKeyPress"); + } (*activity->vm)->DetachCurrentThread(activity->vm); } @@ -910,7 +914,7 @@ void kinc_keyboard_show() { keyboard_active = true; JNIEnv *env; (*activity->vm)->AttachCurrentThread(activity->vm, &env, NULL); - jclass koreActivityClass = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass koreActivityClass = kinc_android_find_class(env, "tech.kore.KoreActivity"); (*env)->CallStaticVoidMethod(env, koreActivityClass, (*env)->GetStaticMethodID(env, koreActivityClass, "showKeyboard", "()V")); (*activity->vm)->DetachCurrentThread(activity->vm); } @@ -919,7 +923,7 @@ void kinc_keyboard_hide() { keyboard_active = false; JNIEnv *env; (*activity->vm)->AttachCurrentThread(activity->vm, &env, NULL); - jclass koreActivityClass = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass koreActivityClass = kinc_android_find_class(env, "tech.kore.KoreActivity"); (*env)->CallStaticVoidMethod(env, koreActivityClass, (*env)->GetStaticMethodID(env, koreActivityClass, "hideKeyboard", "()V")); (*activity->vm)->DetachCurrentThread(activity->vm); } @@ -931,7 +935,7 @@ bool kinc_keyboard_active() { void kinc_load_url(const char *url) { JNIEnv *env; (*activity->vm)->AttachCurrentThread(activity->vm, &env, NULL); - jclass koreActivityClass = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass koreActivityClass = kinc_android_find_class(env, "tech.kore.KoreActivity"); jstring jurl = (*env)->NewStringUTF(env, url); (*env)->CallStaticVoidMethod(env, koreActivityClass, (*env)->GetStaticMethodID(env, koreActivityClass, "loadURL", "(Ljava/lang/String;)V"), jurl); (*activity->vm)->DetachCurrentThread(activity->vm); @@ -940,7 +944,7 @@ void kinc_load_url(const char *url) { void kinc_vibrate(int ms) { JNIEnv *env; (*activity->vm)->AttachCurrentThread(activity->vm, &env, NULL); - jclass koreActivityClass = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass koreActivityClass = kinc_android_find_class(env, "tech.kore.KoreActivity"); (*env)->CallStaticVoidMethod(env, koreActivityClass, (*env)->GetStaticMethodID(env, koreActivityClass, "vibrate", "(I)V"), ms); (*activity->vm)->DetachCurrentThread(activity->vm); } @@ -948,7 +952,7 @@ void kinc_vibrate(int ms) { const char *kinc_language() { JNIEnv *env; (*activity->vm)->AttachCurrentThread(activity->vm, &env, NULL); - jclass koreActivityClass = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass koreActivityClass = kinc_android_find_class(env, "tech.kore.KoreActivity"); jstring s = (jstring)(*env)->CallStaticObjectMethod(env, koreActivityClass, (*env)->GetStaticMethodID(env, koreActivityClass, "getLanguage", "()Ljava/lang/String;")); const char *str = (*env)->GetStringUTFChars(env, s, 0); @@ -956,7 +960,7 @@ const char *kinc_language() { return str; } -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN bool kinc_vulkan_internal_get_size(int *width, int *height); #endif @@ -968,7 +972,7 @@ extern int kinc_egl_height(int window); int kinc_android_width() { #if defined(KINC_EGL) return kinc_egl_width(0); -#elif defined(KORE_VULKAN) +#elif defined(KINC_VULKAN) int width, height; if (kinc_vulkan_internal_get_size(&width, &height)) { return width; @@ -981,7 +985,7 @@ int kinc_android_width() { int kinc_android_height() { #if defined(KINC_EGL) return kinc_egl_height(0); -#elif defined(KORE_VULKAN) +#elif defined(KINC_VULKAN) int width, height; if (kinc_vulkan_internal_get_size(&width, &height)) { return height; @@ -1052,7 +1056,7 @@ bool kinc_internal_handle_messages(void) { int events; struct android_poll_source *source; - while ((ident = ALooper_pollAll(paused ? -1 : 0, NULL, &events, (void **)&source)) >= 0) { + while ((ident = ALooper_pollOnce(paused ? -1 : 0, NULL, &events, (void **)&source)) >= 0) { if (source != NULL) { source->process(app, source); } @@ -1082,7 +1086,7 @@ bool kinc_internal_handle_messages(void) { activityJustResized = false; int32_t width = kinc_android_width(); int32_t height = kinc_android_height(); -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN kinc_internal_resize(0, width, height); #endif kinc_internal_call_resize_callback(0, width, height); @@ -1127,7 +1131,7 @@ void kinc_login() {} void kinc_unlock_achievement(int id) {} bool kinc_gamepad_connected(int num) { - return true; + return num == 0; } void kinc_gamepad_rumble(int gamepad, float left, float right) {} @@ -1150,7 +1154,7 @@ void android_main(struct android_app *application) { application->onAppCmd = cmd; application->onInputEvent = input; activity->callbacks->onNativeWindowResized = resize; - // #ifndef KORE_VULKAN + // #ifndef KINC_VULKAN // glContext = ndk_helper::GLContext::GetInstance(); // #endif sensorManager = ASensorManager_getInstance(); @@ -1161,7 +1165,7 @@ void android_main(struct android_app *application) { JNIEnv *env = NULL; (*kinc_android_get_activity()->vm)->AttachCurrentThread(kinc_android_get_activity()->vm, &env, NULL); - jclass koreMoviePlayerClass = kinc_android_find_class(env, "tech.kinc.KincMoviePlayer"); + jclass koreMoviePlayerClass = kinc_android_find_class(env, "tech.kore.KoreMoviePlayer"); jmethodID updateAll = (*env)->GetStaticMethodID(env, koreMoviePlayerClass, "updateAll", "()V"); while (!started) { @@ -1172,16 +1176,12 @@ void android_main(struct android_app *application) { kickstart(0, NULL); (*activity->vm)->AttachCurrentThread(activity->vm, &env, NULL); - jclass koreActivityClass = kinc_android_find_class(env, "tech.kinc.KincActivity"); + jclass koreActivityClass = kinc_android_find_class(env, "tech.kore.KoreActivity"); jmethodID FinishHim = (*env)->GetStaticMethodID(env, koreActivityClass, "stop", "()V"); (*env)->CallStaticVoidMethod(env, koreActivityClass, FinishHim); (*activity->vm)->DetachCurrentThread(activity->vm); } -#ifdef KINC_KONG -void kong_init(void); -#endif - int kinc_init(const char *name, int width, int height, struct kinc_window_options *win, struct kinc_framebuffer_options *frame) { kinc_mutex_init(&unicode_mutex); @@ -1202,14 +1202,14 @@ int kinc_init(const char *name, int width, int height, struct kinc_window_option kinc_g4_internal_init(); kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true); -#ifdef KINC_KONG - kong_init(); -#endif + kinc_internal_gamepad_trigger_connect(0); return 0; } -void kinc_internal_shutdown(void) {} +void kinc_internal_shutdown(void) { + kinc_internal_gamepad_trigger_disconnect(0); +} const char *kinc_gamepad_vendor(int gamepad) { return "Google"; @@ -1221,8 +1221,6 @@ const char *kinc_gamepad_product_name(int gamepad) { #include -static char *externalFilesDir = NULL; - #define CLASS_NAME "android/app/NativeActivity" void initAndroidFileReader(void) { @@ -1243,60 +1241,51 @@ void initAndroidFileReader(void) { jstring jPath = (*env)->CallObjectMethod(env, file, getPath); const char *path = (*env)->GetStringUTFChars(env, jPath, NULL); - externalFilesDir = malloc(strlen(path) + 1); + char *externalFilesDir = malloc(strlen(path) + 1); strcpy(externalFilesDir, path); + kinc_internal_set_files_location(externalFilesDir); (*env)->ReleaseStringUTFChars(env, jPath, path); (*env)->DeleteLocalRef(env, jPath); (*activity->vm)->DetachCurrentThread(activity->vm); } +static bool kinc_aasset_reader_close(kinc_file_reader_t *reader) { + AAsset_close((struct AAsset *)reader->data); + return true; +} + +static size_t kinc_aasset_reader_read(kinc_file_reader_t *reader, void *data, size_t size) { + return AAsset_read((struct AAsset *)reader->data, data, size); +} + +static size_t kinc_aasset_reader_pos(kinc_file_reader_t *reader) { + return (size_t)AAsset_seek((struct AAsset *)reader->data, 0, SEEK_CUR); +} + +static bool kinc_aasset_reader_seek(kinc_file_reader_t *reader, size_t pos) { + AAsset_seek((struct AAsset *)reader->data, pos, SEEK_SET); + return true; +} + +static bool kinc_aasset_reader_open(kinc_file_reader_t *reader, const char *filename, int type) { + if (type != KINC_FILE_TYPE_ASSET) + return false; + reader->data = AAssetManager_open(kinc_android_get_asset_manager(), filename, AASSET_MODE_RANDOM); + if (reader->data == NULL) + return false; + reader->size = AAsset_getLength((struct AAsset *)reader->data); + reader->close = kinc_aasset_reader_close; + reader->read = kinc_aasset_reader_read; + reader->pos = kinc_aasset_reader_pos; + reader->seek = kinc_aasset_reader_seek; + return true; +} + bool kinc_file_reader_open(kinc_file_reader_t *reader, const char *filename, int type) { - reader->pos = 0; - reader->file = NULL; - reader->asset = NULL; - if (type == KINC_FILE_TYPE_SAVE) { - char filepath[1001]; - - strcpy(filepath, kinc_internal_save_path()); - strcat(filepath, filename); - - reader->file = fopen(filepath, "rb"); - if (reader->file == NULL) { - return false; - } - fseek(reader->file, 0, SEEK_END); - reader->size = ftell(reader->file); - fseek(reader->file, 0, SEEK_SET); - return true; - } - else { - char filepath[1001]; - bool isAbsolute = filename[0] == '/'; - if (isAbsolute) { - strcpy(filepath, filename); - } - else { - strcpy(filepath, externalFilesDir); - strcat(filepath, "/"); - strcat(filepath, filename); - } - - reader->file = fopen(filepath, "rb"); - if (reader->file != NULL) { - fseek(reader->file, 0, SEEK_END); - reader->size = ftell(reader->file); - fseek(reader->file, 0, SEEK_SET); - return true; - } - else { - reader->asset = AAssetManager_open(kinc_android_get_asset_manager(), filename, AASSET_MODE_RANDOM); - if (reader->asset == NULL) - return false; - reader->size = AAsset_getLength(reader->asset); - return true; - } - } + memset(reader, 0, sizeof(*reader)); + return kinc_internal_file_reader_callback(reader, filename, type) || kinc_internal_file_reader_open(reader, filename, type) || + kinc_aasset_reader_open(reader, filename, type); } int kinc_cpu_cores(void) { diff --git a/Kinc/Backends/System/Android/Sources/kinc/backend/video.c.h b/Kinc/Backends/System/Android/Sources/kinc/backend/video.c.h index 4fb702e..489ca74 100644 --- a/Kinc/Backends/System/Android/Sources/kinc/backend/video.c.h +++ b/Kinc/Backends/System/Android/Sources/kinc/backend/video.c.h @@ -6,11 +6,11 @@ #include #include -#include +#include #include #include #include -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) #include #include #endif @@ -18,7 +18,7 @@ #include #include #include -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) #include #include #include @@ -36,15 +36,17 @@ void kinc_video_sound_stream_impl_destroy(kinc_internal_video_sound_stream_t *st void kinc_video_sound_stream_impl_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count) {} -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream) { - return 0; +static float samples[2] = {0}; + +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream) { + return samples; } bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream) { return false; } -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) #define videosCount 10 static kinc_video_t *videos[videosCount] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; @@ -429,7 +431,7 @@ void kinc_android_video_shutdown(kinc_android_video_t *video) { #endif JNIEXPORT void JNICALL Java_tech_kinc_KincMoviePlayer_nativeCreate(JNIEnv *env, jobject jobj, jstring jpath, jobject surface, jint id) { -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) const char *path = (*env)->GetStringUTFChars(env, jpath, NULL); kinc_android_video_t *av = malloc(sizeof *av); kinc_android_video_init(av); @@ -449,17 +451,16 @@ void KoreAndroidVideoInit() { JNIEnv *env; (*kinc_android_get_activity()->vm)->AttachCurrentThread(kinc_android_get_activity()->vm, &env, NULL); - jclass clazz = kinc_android_find_class(env, "tech.kinc.KincMoviePlayer"); + jclass clazz = kinc_android_find_class(env, "tech.kore.KoreMoviePlayer"); // String path, Surface surface, int id - JNINativeMethod methodTable[] = { - {"nativeCreate", "(Ljava/lang/String;Landroid/view/Surface;I)V", (void *)Java_tech_kinc_KincMoviePlayer_nativeCreate}}; + JNINativeMethod methodTable[] = {{"nativeCreate", "(Ljava/lang/String;Landroid/view/Surface;I)V", (void *)Java_tech_kinc_KincMoviePlayer_nativeCreate}}; int methodTableSize = sizeof(methodTable) / sizeof(methodTable[0]); int failure = (*env)->RegisterNatives(env, clazz, methodTable, methodTableSize); if (failure != 0) { - kinc_log(KINC_LOG_LEVEL_WARNING, "Failed to register KincMoviePlayer.nativeCreate"); + kinc_log(KINC_LOG_LEVEL_WARNING, "Failed to register KoreMoviePlayer.nativeCreate"); } (*kinc_android_get_activity()->vm)->DetachCurrentThread(kinc_android_get_activity()->vm); @@ -468,7 +469,7 @@ void KoreAndroidVideoInit() { void kinc_video_init(kinc_video_t *video, const char *filename) { video->impl.playing = false; video->impl.sound = NULL; -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) kinc_log(KINC_LOG_LEVEL_INFO, "Opening video %s.", filename); video->impl.myWidth = 1023; video->impl.myHeight = 684; @@ -478,7 +479,7 @@ void kinc_video_init(kinc_video_t *video, const char *filename) { JNIEnv *env = NULL; (*kinc_android_get_activity()->vm)->AttachCurrentThread(kinc_android_get_activity()->vm, &env, NULL); - jclass koreMoviePlayerClass = kinc_android_find_class(env, "tech.kinc.KincMoviePlayer"); + jclass koreMoviePlayerClass = kinc_android_find_class(env, "tech.kore.KoreMoviePlayer"); jmethodID constructor = (*env)->GetMethodID(env, koreMoviePlayerClass, "", "(Ljava/lang/String;)V"); jobject object = (*env)->NewObject(env, koreMoviePlayerClass, constructor, (*env)->NewStringUTF(env, filename)); @@ -505,7 +506,7 @@ void kinc_video_init(kinc_video_t *video, const char *filename) { } void kinc_video_destroy(kinc_video_t *video) { -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) kinc_video_stop(video); kinc_android_video_t *av = (kinc_android_video_t *)video->impl.androidVideo; kinc_android_video_shutdown(av); @@ -519,20 +520,20 @@ void kinc_video_destroy(kinc_video_t *video) { } void kinc_video_play(kinc_video_t *video, bool loop) { -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) video->impl.playing = true; video->impl.start = kinc_time(); #endif } void kinc_video_pause(kinc_video_t *video) { -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) video->impl.playing = false; #endif } void kinc_video_stop(kinc_video_t *video) { -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) kinc_video_pause(video); #endif } @@ -540,7 +541,7 @@ void kinc_video_stop(kinc_video_t *video) { void kinc_video_update(kinc_video_t *video, double time) {} int kinc_video_width(kinc_video_t *video) { -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) return video->impl.myWidth; #else return 512; @@ -548,7 +549,7 @@ int kinc_video_width(kinc_video_t *video) { } int kinc_video_height(kinc_video_t *video) { -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) return video->impl.myHeight; #else return 512; @@ -556,7 +557,7 @@ int kinc_video_height(kinc_video_t *video) { } kinc_g4_texture_t *kinc_video_current_image(kinc_video_t *video) { -#if KORE_ANDROID_API >= 15 && !defined(KORE_VULKAN) +#if KINC_ANDROID_API >= 15 && !defined(KINC_VULKAN) return &video->impl.image; #else return NULL; diff --git a/Kinc/Backends/System/Android/Sources/kinc/backend/video.h b/Kinc/Backends/System/Android/Sources/kinc/backend/video.h index ca4e90c..471e32f 100644 --- a/Kinc/Backends/System/Android/Sources/kinc/backend/video.h +++ b/Kinc/Backends/System/Android/Sources/kinc/backend/video.h @@ -40,7 +40,7 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count); -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream); +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream); bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream); diff --git a/Kinc/Backends/System/Apple/Sources/kinc/backend/video.h b/Kinc/Backends/System/Apple/Sources/kinc/backend/video.h index e562781..ac39956 100644 --- a/Kinc/Backends/System/Apple/Sources/kinc/backend/video.h +++ b/Kinc/Backends/System/Apple/Sources/kinc/backend/video.h @@ -47,7 +47,7 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count); -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream); +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream); bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream); diff --git a/Kinc/Backends/System/Apple/Sources/kinc/backend/video.m.h b/Kinc/Backends/System/Apple/Sources/kinc/backend/video.m.h index b615ea7..5a08a7b 100644 --- a/Kinc/Backends/System/Apple/Sources/kinc/backend/video.m.h +++ b/Kinc/Backends/System/Apple/Sources/kinc/backend/video.m.h @@ -10,8 +10,14 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif extern const char *iphonegetresourcepath(void); extern const char *macgetresourcepath(void); +#ifdef __cplusplus +} +#endif void kinc_internal_video_sound_stream_init(kinc_internal_video_sound_stream_t *stream, int channel_count, int frequency) { stream->bufferSize = 1024 * 100; @@ -37,17 +43,28 @@ void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stre } } -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream) { +static float samples[2] = {0}; + +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream) { ++stream->read; if (stream->written <= stream->read) { kinc_log(KINC_LOG_LEVEL_WARNING, "Out of audio\n"); return 0; } + if (stream->bufferReadPosition >= stream->bufferSize) { stream->bufferReadPosition = 0; kinc_log(KINC_LOG_LEVEL_INFO, "buffer read back - %i\n", (int)(stream->written - stream->read)); } - return stream->buffer[stream->bufferReadPosition++]; + samples[0] = stream->buffer[stream->bufferReadPosition++]; + + if (stream->bufferReadPosition >= stream->bufferSize) { + stream->bufferReadPosition = 0; + kinc_log(KINC_LOG_LEVEL_INFO, "buffer read back - %i\n", (int)(stream->written - stream->read)); + } + samples[1] = stream->buffer[stream->bufferReadPosition++]; + + return samples; } bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream) { @@ -115,13 +132,13 @@ void kinc_video_init(kinc_video_t *video, const char *filename) { video->impl.sound = NULL; video->impl.image_initialized = false; char name[2048]; -#ifdef KORE_IOS +#ifdef KINC_IOS strcpy(name, iphonegetresourcepath()); #else strcpy(name, macgetresourcepath()); #endif strcat(name, "/"); - strcat(name, KORE_DEBUGDIR); + strcat(name, KINC_DEBUGDIR); strcat(name, "/"); strcat(name, filename); video->impl.url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:name]]; @@ -136,7 +153,7 @@ void kinc_video_destroy(kinc_video_t *video) { kinc_video_stop(video); } -#ifdef KORE_IOS +#ifdef KINC_IOS void iosPlayVideoSoundStream(kinc_internal_video_sound_stream_t *video); void iosStopVideoSoundStream(void); #else @@ -151,7 +168,7 @@ void kinc_video_play(kinc_video_t *video, bool loop) { kinc_internal_video_sound_stream_t *stream = (kinc_internal_video_sound_stream_t *)malloc(sizeof(kinc_internal_video_sound_stream_t)); kinc_internal_video_sound_stream_init(stream, 2, 44100); video->impl.sound = stream; -#ifdef KORE_IOS +#ifdef KINC_IOS iosPlayVideoSoundStream((kinc_internal_video_sound_stream_t *)video->impl.sound); #else macPlayVideoSoundStream((kinc_internal_video_sound_stream_t *)video->impl.sound); @@ -166,7 +183,7 @@ void kinc_video_pause(kinc_video_t *video) { video->impl.playing = false; if (video->impl.sound != NULL) { // Mixer::stop(sound); -#ifdef KORE_IOS +#ifdef KINC_IOS iosStopVideoSoundStream(); #else macStopVideoSoundStream(); @@ -224,7 +241,7 @@ static void updateImage(kinc_video_t *video) { if (pixelBuffer != NULL) { CVPixelBufferLockBaseAddress(pixelBuffer, 0); -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL kinc_g4_texture_upload(&video->impl.image, (uint8_t *)CVPixelBufferGetBaseAddress(pixelBuffer), (int)(CVPixelBufferGetBytesPerRow(pixelBuffer) / 4)); #else diff --git a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/audio.c.h b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/audio.c.h index 4488369..b5cb289 100644 --- a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/audio.c.h +++ b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/audio.c.h @@ -6,7 +6,6 @@ #include #include -static void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = NULL; static kinc_a2_buffer_t a2_buffer; static ALCdevice *device = NULL; @@ -21,35 +20,40 @@ static bool audioRunning = false; static short buf[BUFSIZE]; #define NUM_BUFFERS 3 +static uint32_t samples_per_second = 44100; + static void copySample(void *buffer) { - float value = *(float *)&a2_buffer.data[a2_buffer.read_location]; - a2_buffer.read_location += 4; + float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location]; + float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location]; + a2_buffer.read_location += 1; if (a2_buffer.read_location >= a2_buffer.data_size) { a2_buffer.read_location = 0; } - *(int16_t *)buffer = (int16_t)(value * 32767); + ((int16_t *)buffer)[0] = (int16_t)(left_value * 32767); + ((int16_t *)buffer)[1] = (int16_t)(right_value * 32767); } static void streamBuffer(ALuint buffer) { - if (a2_callback != NULL) { - a2_callback(&a2_buffer, BUFSIZE); - for (int i = 0; i < BUFSIZE; ++i) { + if (kinc_a2_internal_callback(&a2_buffer, BUFSIZE / 2)) { + for (int i = 0; i < BUFSIZE; i += 2) { copySample(&buf[i]); } } - alBufferData(buffer, format, buf, BUFSIZE * 2, 44100); + alBufferData(buffer, format, buf, BUFSIZE * 2, samples_per_second); } static void iter() { - if (!audioRunning) + if (!audioRunning) { return; + } ALint processed; alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed); - if (processed <= 0) + if (processed <= 0) { return; + } while (processed--) { ALuint buffer; alSourceUnqueueBuffers(source, 1, &buffer); @@ -71,12 +75,15 @@ void kinc_a2_init() { return; } + kinc_a2_internal_init(); a2_initialized = true; a2_buffer.read_location = 0; a2_buffer.write_location = 0; a2_buffer.data_size = 128 * 1024; - a2_buffer.data = malloc(a2_buffer.data_size); + a2_buffer.channel_count = 2; + a2_buffer.channels[0] = (float *)malloc(a2_buffer.data_size * sizeof(float)); + a2_buffer.channels[1] = (float *)malloc(a2_buffer.data_size * sizeof(float)); audioRunning = true; @@ -106,6 +113,6 @@ void kinc_a2_shutdown() { audioRunning = false; } -void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) { - a2_callback = kinc_a2_audio_callback; +uint32_t kinc_a2_samples_per_second(void) { + return samples_per_second; } diff --git a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/gamepad.c.h b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/gamepad.c.h new file mode 100644 index 0000000..7a2ed0b --- /dev/null +++ b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/gamepad.c.h @@ -0,0 +1,15 @@ +#include + +const char *kinc_gamepad_vendor(int gamepad) { + return "None"; +} + +const char *kinc_gamepad_product_name(int gamepad) { + return "Gamepad"; +} + +bool kinc_gamepad_connected(int gamepad) { + return false; +} + +void kinc_gamepad_rumble(int gamepad, float left, float right) {} diff --git a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/html5unit.c b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/html5unit.c index 48072f3..08c2b4b 100644 --- a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/html5unit.c +++ b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/html5unit.c @@ -1,6 +1,7 @@ #include "audio.c.h" #include "display.c.h" #include "event.c.h" +#include "gamepad.c.h" #include "mouse.c.h" #include "mutex.c.h" #include "semaphore.c.h" diff --git a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/system.c.h b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/system.c.h index 8cb3206..593379a 100644 --- a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/system.c.h +++ b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/system.c.h @@ -1,4 +1,4 @@ -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL #include #endif @@ -22,7 +22,7 @@ static void drawfunc() { return; kinc_internal_update_callback(); kinc_a2_update(); -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL glfwSwapBuffers(); #endif } @@ -37,7 +37,7 @@ static void drawfunc() { kinc_internal_keyboard_trigger_key_up(KINC_KEY); \ break; -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL // glfw mappings as state here: https://www.glfw.org/docs/3.3/group__keys.html static void onKeyPressed(int key, int action) { if (action == GLFW_PRESS) { @@ -250,10 +250,6 @@ static int with, height; extern int kinc_internal_window_width; extern int kinc_internal_window_height; -#ifdef KINC_KONG -void kong_init(void); -#endif - int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) { kinc_window_options_t defaultWin; if (win == NULL) { @@ -268,7 +264,7 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi win->width = width; win->height = height; -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL glfwInit(); glfwOpenWindow(width, height, 8, 8, 8, 0, frame->depth_bits, frame->stencil_bits, GLFW_WINDOW); glfwSetWindowTitle(name); @@ -281,10 +277,6 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi kinc_g4_internal_init(); kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true); -#ifdef KINC_KONG - kong_init(); -#endif - return 0; } @@ -299,7 +291,7 @@ double kinc_frequency(void) { } kinc_ticks_t kinc_timestamp(void) { -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL return (kinc_ticks_t)(glfwGetTime() * 1000.0); #else return (kinc_ticks_t)(0.0); @@ -307,7 +299,7 @@ kinc_ticks_t kinc_timestamp(void) { } double kinc_time(void) { -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL return glfwGetTime(); #else return 0.0; @@ -324,7 +316,7 @@ int kinc_hardware_threads(void) { extern int kickstart(int argc, char **argv); -#ifdef KORE_WEBGPU +#ifdef KINC_WEBGPU EMSCRIPTEN_KEEPALIVE void kinc_internal_webgpu_initialized() { kickstart(html5_argc, html5_argv); initialized = true; @@ -334,7 +326,7 @@ EMSCRIPTEN_KEEPALIVE void kinc_internal_webgpu_initialized() { int main(int argc, char **argv) { html5_argc = argc; html5_argv = argv; -#ifdef KORE_WEBGPU +#ifdef KINC_WEBGPU char *code = "(async () => {\ const adapter = await navigator.gpu.requestAdapter();\ const device = await adapter.requestDevice();\ diff --git a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/video.c.h b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/video.c.h index e1a5111..c5d3481 100644 --- a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/video.c.h +++ b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/video.c.h @@ -46,8 +46,10 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count) {} -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream) { - return 0.0f; +float samples[2] = {0}; + +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream) { + return samples; } bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream) { diff --git a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/video.h b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/video.h index 0acd202..146a7d4 100644 --- a/Kinc/Backends/System/Emscripten/Sources/kinc/backend/video.h +++ b/Kinc/Backends/System/Emscripten/Sources/kinc/backend/video.h @@ -18,7 +18,7 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count); -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream); +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream); bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream); diff --git a/Kinc/Backends/System/FreeBSD/Sources/kinc/backend/input/gamepad.cpp b/Kinc/Backends/System/FreeBSD/Sources/kinc/backend/input/gamepad.cpp index 9701667..3bb01ec 100644 --- a/Kinc/Backends/System/FreeBSD/Sources/kinc/backend/input/gamepad.cpp +++ b/Kinc/Backends/System/FreeBSD/Sources/kinc/backend/input/gamepad.cpp @@ -60,11 +60,13 @@ namespace { if (ioctl(file_descriptor, JSIOCGNAME(sizeof(buf)), buf) < 0) strncpy(buf, "Unknown", sizeof(buf)); snprintf(name, sizeof(name), "%s%s%s%s", buf, " (", gamepad_dev_name, ")"); + kinc_internal_gamepad_trigger_connect(idx); } } void HIDGamepad::close() { if (connected) { + kinc_internal_gamepad_trigger_disconnect(idx); ::close(file_descriptor); file_descriptor = -1; connected = false; @@ -94,18 +96,17 @@ namespace { } } - const int gamepadCount = 12; - HIDGamepad gamepads[gamepadCount]; + HIDGamepad gamepads[KINC_GAMEPAD_MAX_COUNT]; } void Kore::initHIDGamepads() { - for (int i = 0; i < gamepadCount; ++i) { + for (int i = 0; i < KINC_GAMEPAD_MAX_COUNT; ++i) { gamepads[i].init(i); } } void Kore::updateHIDGamepads() { - for (int i = 0; i < gamepadCount; ++i) { + for (int i = 0; i < KINC_GAMEPAD_MAX_COUNT; ++i) { gamepads[i].update(); } } @@ -117,11 +118,11 @@ const char *kinc_gamepad_vendor(int gamepad) { } const char *kinc_gamepad_product_name(int gamepad) { - return gamepads[gamepad].name; + return gamepad >= 0 && gamepad < KINC_GAMEPAD_MAX_COUNT ? gamepads[gamepad].name : ""; } bool kinc_gamepad_connected(int gamepad) { - return gamepads[gamepad].connected; + return gamepad >= 0 && gamepad < KINC_GAMEPAD_MAX_COUNT && gamepads[gamepad].connected; } void kinc_gamepad_rumble(int gamepad, float left, float right) {} \ No newline at end of file diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/funcs.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/funcs.h index b9efce7..cf66fb8 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/funcs.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/funcs.h @@ -7,7 +7,7 @@ #define EGL_NO_PLATFORM_SPECIFIC_TYPES #include #endif -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN #include #endif @@ -29,7 +29,6 @@ struct linux_procs { int (*window_display)(int window_index); void (*window_show)(int window_index); void (*window_hide)(int window_index); - void (*window_set_foreground)(int window_index); void (*window_set_title)(int window_index, const char *title); void (*window_change_mode)(int window_index, kinc_window_mode_t mode); kinc_window_mode_t (*window_get_mode)(int window_index); @@ -56,7 +55,7 @@ struct linux_procs { EGLDisplay (*egl_get_display)(void); EGLNativeWindowType (*egl_get_native_window)(EGLDisplay display, EGLConfig config, int window_index); #endif -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN void (*vulkan_get_instance_extensions)(const char **extensions, int *count, int max); VkResult (*vulkan_create_surface)(VkInstance instance, int window_index, VkSurfaceKHR *surface); VkBool32 (*vulkan_get_physical_device_presentation_support)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex); diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/gamepad.c.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/gamepad.c.h index f305bc9..74b3dde 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/gamepad.c.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/gamepad.c.h @@ -32,6 +32,7 @@ static void HIDGamepad_open(struct HIDGamepad *pad) { strncpy(buf, "Unknown", sizeof(buf)); } snprintf(pad->name, sizeof(pad->name), "%s(%s)", buf, pad->gamepad_dev_name); + kinc_internal_gamepad_trigger_connect(pad->idx); } } @@ -48,6 +49,7 @@ static void HIDGamepad_init(struct HIDGamepad *pad, int index) { static void HIDGamepad_close(struct HIDGamepad *pad) { if (pad->connected) { + kinc_internal_gamepad_trigger_disconnect(pad->idx); close(pad->file_descriptor); pad->file_descriptor = -1; pad->connected = false; @@ -85,8 +87,7 @@ struct HIDGamepadUdevHelper { static struct HIDGamepadUdevHelper udev_helper; -#define gamepadCount 12 -static struct HIDGamepad gamepads[gamepadCount]; +static struct HIDGamepad gamepads[KINC_GAMEPAD_MAX_COUNT]; static void HIDGamepadUdevHelper_openOrCloseGamepad(struct HIDGamepadUdevHelper *helper, struct udev_device *dev) { const char *action = udev_device_get_action(dev); @@ -165,7 +166,7 @@ static void HIDGamepadUdevHelper_close(struct HIDGamepadUdevHelper *helper) { } void kinc_linux_initHIDGamepads() { - for (int i = 0; i < gamepadCount; ++i) { + for (int i = 0; i < KINC_GAMEPAD_MAX_COUNT; ++i) { HIDGamepad_init(&gamepads[i], i); } HIDGamepadUdevHelper_init(&udev_helper); @@ -173,7 +174,7 @@ void kinc_linux_initHIDGamepads() { void kinc_linux_updateHIDGamepads() { HIDGamepadUdevHelper_update(&udev_helper); - for (int i = 0; i < gamepadCount; ++i) { + for (int i = 0; i < KINC_GAMEPAD_MAX_COUNT; ++i) { HIDGamepad_update(&gamepads[i]); } } @@ -187,11 +188,11 @@ const char *kinc_gamepad_vendor(int gamepad) { } const char *kinc_gamepad_product_name(int gamepad) { - return gamepads[gamepad].name; + return gamepad >= 0 && gamepad < KINC_GAMEPAD_MAX_COUNT ? gamepads[gamepad].name : ""; } bool kinc_gamepad_connected(int gamepad) { - return gamepads[gamepad].connected; + return gamepad >= 0 && gamepad < KINC_GAMEPAD_MAX_COUNT && gamepads[gamepad].connected; } void kinc_gamepad_rumble(int gamepad, float left, float right) {} diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/linuxunit.c b/Kinc/Backends/System/Linux/Sources/kinc/backend/linuxunit.c index 832dddc..e86e33d 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/linuxunit.c +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/linuxunit.c @@ -1,164 +1,161 @@ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE // memfd_create and mkostemp -#endif -#include "funcs.h" -#include -#include - -static void load_lib(void **lib, const char *name) { - char libname[64]; - sprintf(libname, "lib%s.so", name); - *lib = dlopen(libname, RTLD_LAZY); - if (*lib != NULL) { - return; - } - // Ubuntu and Fedora only ship libFoo.so.major by default, so look for those. - for (int i = 0; i < 10; i++) { - sprintf(libname, "lib%s.so.%i", name, i); - *lib = dlopen(libname, RTLD_LAZY); - if (*lib != NULL) { - return; - } - } -} - -#ifndef KINC_NO_WAYLAND -#include "wayland/display.c.h" -#include "wayland/system.c.h" -#include "wayland/window.c.h" -#endif - -#ifndef KINC_NO_X11 -#include "x11/display.c.h" -#include "x11/system.c.h" -#include "x11/window.c.h" -#endif - -struct linux_procs procs = {0}; - -void kinc_linux_init_procs() { - if (procs.window_create != NULL) { - return; - } -#ifndef KINC_NO_WAYLAND - if (kinc_wayland_init()) { - procs.handle_messages = kinc_wayland_handle_messages; - procs.shutdown = kinc_wayland_shutdown; - - procs.window_create = kinc_wayland_window_create; - procs.window_width = kinc_wayland_window_width; - procs.window_height = kinc_wayland_window_height; - procs.window_x = kinc_wayland_window_x; - procs.window_y = kinc_wayland_window_y; - procs.window_destroy = kinc_wayland_window_destroy; - procs.window_change_mode = kinc_wayland_window_change_mode; - procs.window_get_mode = kinc_wayland_window_get_mode; - procs.window_set_title = kinc_wayland_window_set_title; - procs.window_display = kinc_wayland_window_display; - procs.window_move = kinc_wayland_window_move; - procs.window_resize = kinc_wayland_window_resize; - procs.window_show = kinc_wayland_window_show; - procs.window_hide = kinc_wayland_window_hide; - procs.window_set_foreground = kinc_wayland_window_set_foreground; - procs.count_windows = kinc_wayland_count_windows; - - procs.mouse_can_lock = kinc_wl_mouse_can_lock; - procs.mouse_lock = kinc_wl_mouse_lock; - procs.mouse_unlock = kinc_wl_mouse_unlock; - procs.mouse_show = kinc_wl_mouse_show; - procs.mouse_hide = kinc_wl_mouse_hide; - procs.mouse_set_position = kinc_wl_mouse_set_position; - procs.mouse_get_position = kinc_wl_mouse_get_position; - procs.mouse_set_cursor = kinc_wl_mouse_set_cursor; - - procs.display_init = kinc_wayland_display_init; - procs.display_available = kinc_wayland_display_available; - procs.display_available_mode = kinc_wayland_display_available_mode; - procs.display_count_available_modes = kinc_wayland_display_count_available_modes; - procs.display_current_mode = kinc_wayland_display_current_mode; - procs.display_name = kinc_wayland_display_name; - procs.display_primary = kinc_wayland_display_primary; - procs.count_displays = kinc_wayland_count_displays; - - procs.copy_to_clipboard = kinc_wayland_copy_to_clipboard; -#ifdef KINC_EGL - procs.egl_get_display = kinc_wayland_egl_get_display; - procs.egl_get_native_window = kinc_wayland_egl_get_native_window; -#endif -#ifdef KORE_VULKAN - procs.vulkan_create_surface = kinc_wayland_vulkan_create_surface; - procs.vulkan_get_instance_extensions = kinc_wayland_vulkan_get_instance_extensions; - procs.vulkan_get_physical_device_presentation_support = kinc_wayland_vulkan_get_physical_device_presentation_support; -#endif - } - else -#endif -#ifndef KINC_NO_X11 - if (kinc_x11_init()) { - procs.handle_messages = kinc_x11_handle_messages; - procs.shutdown = kinc_x11_shutdown; - - procs.window_create = kinc_x11_window_create; - procs.window_width = kinc_x11_window_width; - procs.window_height = kinc_x11_window_height; - procs.window_x = kinc_x11_window_x; - procs.window_y = kinc_x11_window_y; - procs.window_destroy = kinc_x11_window_destroy; - procs.window_change_mode = kinc_x11_window_change_mode; - procs.window_get_mode = kinc_x11_window_get_mode; - procs.window_set_title = kinc_x11_window_set_title; - procs.window_display = kinc_x11_window_display; - procs.window_move = kinc_x11_window_move; - procs.window_resize = kinc_x11_window_resize; - procs.window_show = kinc_x11_window_show; - procs.window_hide = kinc_x11_window_hide; - procs.window_set_foreground = kinc_x11_window_set_foreground; - - procs.count_windows = kinc_x11_count_windows; - - procs.display_init = kinc_x11_display_init; - procs.display_available = kinc_x11_display_available; - procs.display_available_mode = kinc_x11_display_available_mode; - procs.display_count_available_modes = kinc_x11_display_count_available_modes; - procs.display_current_mode = kinc_x11_display_current_mode; - procs.display_name = kinc_x11_display_name; - procs.display_primary = kinc_x11_display_primary; - procs.count_displays = kinc_x11_count_displays; - - procs.mouse_can_lock = kinc_x11_mouse_can_lock; - procs.mouse_lock = kinc_x11_mouse_lock; - procs.mouse_unlock = kinc_x11_mouse_unlock; - procs.mouse_show = kinc_x11_mouse_show; - procs.mouse_hide = kinc_x11_mouse_hide; - procs.mouse_set_position = kinc_x11_mouse_set_position; - procs.mouse_get_position = kinc_x11_mouse_get_position; - procs.mouse_set_cursor = kinc_x11_mouse_set_cursor; - - procs.copy_to_clipboard = kinc_x11_copy_to_clipboard; -#ifdef KINC_EGL - procs.egl_get_display = kinc_x11_egl_get_display; - procs.egl_get_native_window = kinc_x11_egl_get_native_window; -#endif -#ifdef KORE_VULKAN - procs.vulkan_create_surface = kinc_x11_vulkan_create_surface; - procs.vulkan_get_instance_extensions = kinc_x11_vulkan_get_instance_extensions; - procs.vulkan_get_physical_device_presentation_support = kinc_x11_vulkan_get_physical_device_presentation_support; -#endif - } - else -#endif - { - kinc_log(KINC_LOG_LEVEL_ERROR, "Neither wayland nor X11 found."); - exit(1); - } -} - -#include "display.c.h" -#ifndef __FreeBSD__ -#include "gamepad.c.h" -#endif -#include "mouse.c.h" -#include "sound.c.h" -#include "system.c.h" -#include "video.c.h" -#include "window.c.h" +#ifndef _GNU_SOURCE +#define _GNU_SOURCE // memfd_create and mkostemp +#endif +#include "funcs.h" +#include +#include + +static void load_lib(void **lib, const char *name) { + char libname[64]; + sprintf(libname, "lib%s.so", name); + *lib = dlopen(libname, RTLD_LAZY); + if (*lib != NULL) { + return; + } + // Ubuntu and Fedora only ship libFoo.so.major by default, so look for those. + for (int i = 0; i < 10; i++) { + sprintf(libname, "lib%s.so.%i", name, i); + *lib = dlopen(libname, RTLD_LAZY); + if (*lib != NULL) { + return; + } + } +} + +#ifndef KINC_NO_WAYLAND +#include "wayland/display.c.h" +#include "wayland/system.c.h" +#include "wayland/window.c.h" +#endif + +#ifndef KINC_NO_X11 +#include "x11/display.c.h" +#include "x11/system.c.h" +#include "x11/window.c.h" +#endif + +struct linux_procs procs = {0}; + +void kinc_linux_init_procs() { + if (procs.window_create != NULL) { + return; + } +#ifndef KINC_NO_WAYLAND + if (kinc_wayland_init()) { + procs.handle_messages = kinc_wayland_handle_messages; + procs.shutdown = kinc_wayland_shutdown; + + procs.window_create = kinc_wayland_window_create; + procs.window_width = kinc_wayland_window_width; + procs.window_height = kinc_wayland_window_height; + procs.window_x = kinc_wayland_window_x; + procs.window_y = kinc_wayland_window_y; + procs.window_destroy = kinc_wayland_window_destroy; + procs.window_change_mode = kinc_wayland_window_change_mode; + procs.window_get_mode = kinc_wayland_window_get_mode; + procs.window_set_title = kinc_wayland_window_set_title; + procs.window_display = kinc_wayland_window_display; + procs.window_move = kinc_wayland_window_move; + procs.window_resize = kinc_wayland_window_resize; + procs.window_show = kinc_wayland_window_show; + procs.window_hide = kinc_wayland_window_hide; + procs.count_windows = kinc_wayland_count_windows; + + procs.mouse_can_lock = kinc_wl_mouse_can_lock; + procs.mouse_lock = kinc_wl_mouse_lock; + procs.mouse_unlock = kinc_wl_mouse_unlock; + procs.mouse_show = kinc_wl_mouse_show; + procs.mouse_hide = kinc_wl_mouse_hide; + procs.mouse_set_position = kinc_wl_mouse_set_position; + procs.mouse_get_position = kinc_wl_mouse_get_position; + procs.mouse_set_cursor = kinc_wl_mouse_set_cursor; + + procs.display_init = kinc_wayland_display_init; + procs.display_available = kinc_wayland_display_available; + procs.display_available_mode = kinc_wayland_display_available_mode; + procs.display_count_available_modes = kinc_wayland_display_count_available_modes; + procs.display_current_mode = kinc_wayland_display_current_mode; + procs.display_name = kinc_wayland_display_name; + procs.display_primary = kinc_wayland_display_primary; + procs.count_displays = kinc_wayland_count_displays; + + procs.copy_to_clipboard = kinc_wayland_copy_to_clipboard; +#ifdef KINC_EGL + procs.egl_get_display = kinc_wayland_egl_get_display; + procs.egl_get_native_window = kinc_wayland_egl_get_native_window; +#endif +#ifdef KINC_VULKAN + procs.vulkan_create_surface = kinc_wayland_vulkan_create_surface; + procs.vulkan_get_instance_extensions = kinc_wayland_vulkan_get_instance_extensions; + procs.vulkan_get_physical_device_presentation_support = kinc_wayland_vulkan_get_physical_device_presentation_support; +#endif + } + else +#endif +#ifndef KINC_NO_X11 + if (kinc_x11_init()) { + procs.handle_messages = kinc_x11_handle_messages; + procs.shutdown = kinc_x11_shutdown; + + procs.window_create = kinc_x11_window_create; + procs.window_width = kinc_x11_window_width; + procs.window_height = kinc_x11_window_height; + procs.window_x = kinc_x11_window_x; + procs.window_y = kinc_x11_window_y; + procs.window_destroy = kinc_x11_window_destroy; + procs.window_change_mode = kinc_x11_window_change_mode; + procs.window_get_mode = kinc_x11_window_get_mode; + procs.window_set_title = kinc_x11_window_set_title; + procs.window_display = kinc_x11_window_display; + procs.window_move = kinc_x11_window_move; + procs.window_resize = kinc_x11_window_resize; + procs.window_show = kinc_x11_window_show; + procs.window_hide = kinc_x11_window_hide; + procs.count_windows = kinc_x11_count_windows; + + procs.display_init = kinc_x11_display_init; + procs.display_available = kinc_x11_display_available; + procs.display_available_mode = kinc_x11_display_available_mode; + procs.display_count_available_modes = kinc_x11_display_count_available_modes; + procs.display_current_mode = kinc_x11_display_current_mode; + procs.display_name = kinc_x11_display_name; + procs.display_primary = kinc_x11_display_primary; + procs.count_displays = kinc_x11_count_displays; + + procs.mouse_can_lock = kinc_x11_mouse_can_lock; + procs.mouse_lock = kinc_x11_mouse_lock; + procs.mouse_unlock = kinc_x11_mouse_unlock; + procs.mouse_show = kinc_x11_mouse_show; + procs.mouse_hide = kinc_x11_mouse_hide; + procs.mouse_set_position = kinc_x11_mouse_set_position; + procs.mouse_get_position = kinc_x11_mouse_get_position; + procs.mouse_set_cursor = kinc_x11_mouse_set_cursor; + + procs.copy_to_clipboard = kinc_x11_copy_to_clipboard; +#ifdef KINC_EGL + procs.egl_get_display = kinc_x11_egl_get_display; + procs.egl_get_native_window = kinc_x11_egl_get_native_window; +#endif +#ifdef KINC_VULKAN + procs.vulkan_create_surface = kinc_x11_vulkan_create_surface; + procs.vulkan_get_instance_extensions = kinc_x11_vulkan_get_instance_extensions; + procs.vulkan_get_physical_device_presentation_support = kinc_x11_vulkan_get_physical_device_presentation_support; +#endif + } + else +#endif + { + kinc_log(KINC_LOG_LEVEL_ERROR, "Neither wayland nor X11 found."); + exit(1); + } +} + +#include "display.c.h" +#ifndef __FreeBSD__ +#include "gamepad.c.h" +#endif +#include "mouse.c.h" +#include "sound.c.h" +#include "system.c.h" +#include "video.c.h" +#include "window.c.h" diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/sound.c.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/sound.c.h index 0b6df36..283d71c 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/sound.c.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/sound.c.h @@ -9,42 +9,50 @@ // apt-get install libasound2-dev -void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = NULL; kinc_a2_buffer_t a2_buffer; pthread_t threadid; bool audioRunning = false; snd_pcm_t *playback_handle; -short buf[4096 * 4]; +#define AUDIO_BUFFER_SIZE (4096 * 4) +short buf[AUDIO_BUFFER_SIZE]; + +static unsigned int samples_per_second = 44100; + +uint32_t kinc_a2_samples_per_second(void) { + return samples_per_second; +} void copySample(void *buffer) { - float value = *(float *)&a2_buffer.data[a2_buffer.read_location]; - a2_buffer.read_location += 4; - if (a2_buffer.read_location >= a2_buffer.data_size) + float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location]; + float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location]; + a2_buffer.read_location += 1; + if (a2_buffer.read_location >= a2_buffer.data_size) { a2_buffer.read_location = 0; - if (value != 0) { - int a = 3; - ++a; } - *(int16_t *)buffer = (int16_t)(value * 32767); + ((int16_t *)buffer)[0] = (int16_t)(left_value * 32767); + ((int16_t *)buffer)[1] = (int16_t)(right_value * 32767); } int playback_callback(snd_pcm_sframes_t nframes) { int err = 0; - if (a2_callback != NULL) { - a2_callback(&a2_buffer, nframes * 2); + if (kinc_a2_internal_callback(&a2_buffer, nframes)) { int ni = 0; while (ni < nframes) { int i = 0; - for (; ni < nframes && i < 4096 * 2; ++i, ++ni) { + for (; ni < nframes && i < AUDIO_BUFFER_SIZE / 2; ++i, ++ni) { copySample(&buf[i * 2]); - copySample(&buf[i * 2 + 1]); } int err2; if ((err2 = snd_pcm_writei(playback_handle, buf, i)) < 0) { + // EPIPE is an underrun fprintf(stderr, "write failed (%s)\n", snd_strerror(err2)); + int recovered = snd_pcm_recover(playback_handle, err2, 1); + printf("Recovered: %d\n", recovered); + } + else { + err += err2; } - err += err2; } } return err; @@ -107,9 +115,8 @@ void *doAudio(void *arg) { return NULL; } - unsigned int rate = 44100; int dir = 0; - if ((err = snd_pcm_hw_params_set_rate_near(playback_handle, hw_params, &rate, &dir)) < 0) { + if ((err = snd_pcm_hw_params_set_rate_near(playback_handle, hw_params, &samples_per_second, &dir)) < 0) { fprintf(stderr, "cannot set sample rate (%s)\n", snd_strerror(err)); return NULL; } @@ -119,7 +126,7 @@ void *doAudio(void *arg) { return NULL; } - snd_pcm_uframes_t bufferSize = rate / 8; + snd_pcm_uframes_t bufferSize = samples_per_second / 8; if (((err = snd_pcm_hw_params_set_buffer_size(playback_handle, hw_params, bufferSize)) < 0 && (snd_pcm_hw_params_set_buffer_size_near(playback_handle, hw_params, &bufferSize)) < 0)) { fprintf(stderr, "cannot set buffer size (%s)\n", snd_strerror(err)); @@ -195,7 +202,7 @@ void *doAudio(void *arg) { if (delivered != frames_to_deliver) { fprintf(stderr, "playback callback failed (delivered %i / %ld frames)\n", delivered, frames_to_deliver); - // break; + // break; // Do not break so we can recover from errors. } } } @@ -211,12 +218,15 @@ void kinc_a2_init() { return; } + kinc_a2_internal_init(); initialized = true; a2_buffer.read_location = 0; a2_buffer.write_location = 0; a2_buffer.data_size = 128 * 1024; - a2_buffer.data = (uint8_t *)malloc(a2_buffer.data_size); + a2_buffer.channel_count = 2; + a2_buffer.channels[0] = (float *)malloc(a2_buffer.data_size * sizeof(float)); + a2_buffer.channels[1] = (float *)malloc(a2_buffer.data_size * sizeof(float)); audioRunning = true; pthread_create(&threadid, NULL, &doAudio, NULL); @@ -227,7 +237,3 @@ void kinc_a2_update() {} void kinc_a2_shutdown() { audioRunning = false; } - -void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) { - a2_callback = kinc_a2_audio_callback; -} diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/system.c.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/system.c.h index 5e2d9a3..9aa94ce 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/system.c.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/system.c.h @@ -152,10 +152,6 @@ void kinc_unlock_achievement(int id) {} void kinc_linux_init_procs(); -#ifdef KINC_KONG -void kong_init(void); -#endif - int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) { #ifndef __FreeBSD__ kinc_linux_initHIDGamepads(); @@ -185,11 +181,7 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi win->title = name; } - int window = kinc_window_create(win, frame); -#ifdef KINC_KONG - kong_init(); -#endif - return window; + return kinc_window_create(win, frame); } void kinc_internal_shutdown() { diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/video.c.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/video.c.h index 5171667..adf52f7 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/video.c.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/video.c.h @@ -47,8 +47,10 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count) {} -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream) { - return 0.0f; +static float samples[2] = {0}; + +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream) { + return samples; } bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream) { diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/video.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/video.h index d93718a..22c464e 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/video.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/video.h @@ -21,7 +21,7 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count); -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream); +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream); bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream); #endif diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/system.c.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/system.c.h index 4e3762e..2fb161a 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/system.c.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/system.c.h @@ -1,3 +1,5 @@ +#include "kinc/math/core.h" +#include "wayland-generated/wayland-fractional-scale.h" #include "wayland.h" #include @@ -280,7 +282,7 @@ void wl_pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, uint32_ case KINC_WL_DECORATION_FOCUS_BOTTOM: if (x < 10) cursor_name = "sw-resize"; - else if (x > window->width + 10) + else if (x > window->surface_width + 10) cursor_name = "se-resize"; else cursor_name = "s-resize"; @@ -432,8 +434,12 @@ void wl_keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard, uint case WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1: { char *mapStr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); if (mapStr == MAP_FAILED) { - close(fd); - return; + mapStr = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + if (mapStr == MAP_FAILED) { + kinc_log(KINC_LOG_LEVEL_ERROR, "Failed to map wayland keymap."); + close(fd); + return; + } } keyboard->keymap = wl_xkb.xkb_keymap_new_from_string(wl_ctx.xkb_context, mapStr, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); munmap(mapStr, size); @@ -766,7 +772,7 @@ void zwp_tablet_tool_v2_handle_type(void *data, struct zwp_tablet_tool_v2 *zwp_t tool->type = tool_type; } -#ifdef KORE_LITTLE_ENDIAN +#ifdef KINC_LITTLE_ENDIAN #define HI_LO_TO_64(hi, lo) (uint64_t) lo | ((uint64_t)hi << 32) #else #define HI_LO_TO_64(hi, lo) (uint64_t) hi | ((uint64_t)lo << 32) @@ -938,7 +944,7 @@ static const struct zwp_tablet_seat_v2_listener zwp_tablet_seat_v2_listener = { static void wl_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { if (strcmp(interface, wl_compositor_interface.name) == 0) { - wl_ctx.compositor = wl_registry_bind(wl_ctx.registry, name, &wl_compositor_interface, 4); + wl_ctx.compositor = wl_registry_bind(wl_ctx.registry, name, &wl_compositor_interface, kinc_mini(version, 6)); } else if (strcmp(interface, wl_shm_interface.name) == 0) { wl_ctx.shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); @@ -1008,6 +1014,8 @@ static void wl_registry_handle_global(void *data, struct wl_registry *registry, } else if (strcmp(interface, zwp_relative_pointer_manager_v1_interface.name) == 0) { wl_ctx.relative_pointer_manager = wl_registry_bind(registry, name, &zwp_relative_pointer_manager_v1_interface, 1); + } else if(strcmp(interface, wp_fractional_scale_manager_v1_interface.name) == 0) { + wl_ctx.fractional_scale_manager = wl_registry_bind(registry, name, &wp_fractional_scale_manager_v1_interface, 1); } } @@ -1176,7 +1184,7 @@ EGLNativeWindowType kinc_wayland_egl_get_native_window(EGLDisplay display, EGLCo } #endif -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN #include #include VkResult kinc_wayland_vulkan_create_surface(VkInstance instance, int window_index, VkSurfaceKHR *surface) { @@ -1320,4 +1328,4 @@ void kinc_wl_mouse_set_position(int window_index, int x, int y) { void kinc_wl_mouse_get_position(int window_index, int *x, int *y) { *x = wl_ctx.seat.mouse.x; *y = wl_ctx.seat.mouse.y; -} \ No newline at end of file +} diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/wayland.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/wayland.h index 83498c0..b8bead1 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/wayland.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/wayland.h @@ -93,6 +93,7 @@ struct kinc_wl_procs { extern struct kinc_wl_procs wl; #include +#include #include #include #include @@ -150,25 +151,25 @@ enum kinc_wl_decoration_focus { #define KINC_WL_DECORATION_TOP_X 0 #define KINC_WL_DECORATION_TOP_Y -(KINC_WL_DECORATION_TOP_HEIGHT) -#define KINC_WL_DECORATION_TOP_WIDTH window->width +#define KINC_WL_DECORATION_TOP_WIDTH window->surface_width #define KINC_WL_DECORATION_TOP_HEIGHT KINC_WL_DECORATION_WIDTH * 3 #define KINC_WL_DECORATION_LEFT_X -10 #define KINC_WL_DECORATION_LEFT_Y -(KINC_WL_DECORATION_TOP_HEIGHT) #define KINC_WL_DECORATION_LEFT_WIDTH KINC_WL_DECORATION_WIDTH -#define KINC_WL_DECORATION_LEFT_HEIGHT window->height + KINC_WL_DECORATION_TOP_HEIGHT + KINC_WL_DECORATION_BOTTOM_HEIGHT +#define KINC_WL_DECORATION_LEFT_HEIGHT window->surface_height + KINC_WL_DECORATION_TOP_HEIGHT + KINC_WL_DECORATION_BOTTOM_HEIGHT -#define KINC_WL_DECORATION_RIGHT_X window->width +#define KINC_WL_DECORATION_RIGHT_X window->surface_width #define KINC_WL_DECORATION_RIGHT_Y -(KINC_WL_DECORATION_TOP_HEIGHT) #define KINC_WL_DECORATION_RIGHT_WIDTH 10 -#define KINC_WL_DECORATION_RIGHT_HEIGHT window->height + KINC_WL_DECORATION_TOP_HEIGHT + KINC_WL_DECORATION_BOTTOM_HEIGHT +#define KINC_WL_DECORATION_RIGHT_HEIGHT window->surface_height + KINC_WL_DECORATION_TOP_HEIGHT + KINC_WL_DECORATION_BOTTOM_HEIGHT #define KINC_WL_DECORATION_BOTTOM_X 0 -#define KINC_WL_DECORATION_BOTTOM_Y window->height -#define KINC_WL_DECORATION_BOTTOM_WIDTH window->width +#define KINC_WL_DECORATION_BOTTOM_Y window->surface_height +#define KINC_WL_DECORATION_BOTTOM_WIDTH window->surface_width #define KINC_WL_DECORATION_BOTTOM_HEIGHT KINC_WL_DECORATION_WIDTH -#define KINC_WL_DECORATION_CLOSE_X window->width - 10 +#define KINC_WL_DECORATION_CLOSE_X window->surface_width - 10 #define KINC_WL_DECORATION_CLOSE_Y -20 #define KINC_WL_DECORATION_CLOSE_WIDTH 9 #define KINC_WL_DECORATION_CLOSE_HEIGHT 9 @@ -176,13 +177,21 @@ enum kinc_wl_decoration_focus { struct kinc_wl_window { int display_index; int window_id; - int width; - int height; + int surface_width; + int surface_height; + + int buffer_width; + int buffer_height; + kinc_window_mode_t mode; struct wl_surface *surface; struct xdg_surface *xdg_surface; struct xdg_toplevel *toplevel; struct zxdg_toplevel_decoration_v1 *xdg_decoration; + struct wp_fractional_scale_v1 *fractional_scale; + struct wp_viewport *viewport; + + uint32_t preferred_scale; bool configured; @@ -347,6 +356,7 @@ struct wayland_context { struct zwp_tablet_manager_v2 *tablet_manager; struct zwp_pointer_constraints_v1 *pointer_constraints; struct zwp_relative_pointer_manager_v1 *relative_pointer_manager; + struct wp_fractional_scale_manager_v1 *fractional_scale_manager; struct wl_cursor_theme *cursor_theme; int cursor_size; int num_windows; diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/window.c.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/window.c.h index f63ec09..bc49016 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/window.c.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/wayland/window.c.h @@ -2,6 +2,7 @@ #include #include +#include // for all that shared memory stuff later on #include @@ -27,17 +28,17 @@ void kinc_wayland_destroy_decoration(struct kinc_wl_decoration *); void kinc_wayland_resize_decoration(struct kinc_wl_decoration *, int x, int y, int width, int height); static void xdg_toplevel_handle_configure(void *data, struct xdg_toplevel *toplevel, int32_t width, int32_t height, struct wl_array *states) { struct kinc_wl_window *window = data; - if ((width <= 0 || height <= 0) || (width == window->width + (KINC_WL_DECORATION_WIDTH * 2) && - height == window->height + KINC_WL_DECORATION_TOP_HEIGHT + KINC_WL_DECORATION_BOTTOM_HEIGHT)) { - return; - } - if (window->decorations.server_side) { - window->width = width; - window->height = height; - } - else { - window->width = width - (KINC_WL_DECORATION_WIDTH * 2); - window->height = height - KINC_WL_DECORATION_TOP_HEIGHT + KINC_WL_DECORATION_BOTTOM_HEIGHT; + if(width > 0 && height > 0) { + if (window->decorations.server_side) { + window->surface_width = width; + window->surface_height = height; + } + else { + window->surface_width = width - (KINC_WL_DECORATION_WIDTH * 2); + window->surface_height = height - KINC_WL_DECORATION_TOP_HEIGHT + KINC_WL_DECORATION_BOTTOM_HEIGHT; + } + window->buffer_width = window->surface_width * window->preferred_scale / 120; + window->buffer_height = window->surface_height * window->preferred_scale / 120; } enum xdg_toplevel_state *state; @@ -54,30 +55,41 @@ static void xdg_toplevel_handle_configure(void *data, struct xdg_toplevel *tople break; } } - kinc_internal_resize(window->window_id, window->width, window->height); - kinc_internal_call_resize_callback(window->window_id, window->width, window->height); - if (window->decorations.server_side) { - xdg_surface_set_window_geometry(window->xdg_surface, 0, 0, window->width, window->height); - } - else { - xdg_surface_set_window_geometry(window->xdg_surface, KINC_WL_DECORATION_LEFT_X, KINC_WL_DECORATION_TOP_Y, - window->width + (KINC_WL_DECORATION_WIDTH * 2), - window->height + KINC_WL_DECORATION_TOP_HEIGHT + KINC_WL_DECORATION_BOTTOM_HEIGHT); - } + + if (window->surface_width > 0 && window->surface_height > 0) { + if (window->decorations.server_side) { + xdg_surface_set_window_geometry(window->xdg_surface, 0, 0, window->surface_width, window->surface_height); + } + else { + xdg_surface_set_window_geometry(window->xdg_surface, KINC_WL_DECORATION_LEFT_X, KINC_WL_DECORATION_TOP_Y, + window->surface_width + (KINC_WL_DECORATION_WIDTH * 2), + window->surface_height + KINC_WL_DECORATION_TOP_HEIGHT + KINC_WL_DECORATION_BOTTOM_HEIGHT); + } + if (window->viewport) { + wp_viewport_set_source(window->viewport, 0, 0, wl_fixed_from_int(window->buffer_width), wl_fixed_from_int(window->buffer_height)); + wp_viewport_set_destination(window->viewport, window->surface_width, window->surface_height); + } + else { + wl_surface_set_buffer_scale(window->surface, window->preferred_scale / 120); + } + + kinc_internal_resize(window->window_id, window->buffer_width, window->buffer_height); + kinc_internal_call_resize_callback(window->window_id, window->buffer_width, window->buffer_height); #ifdef KINC_EGL - wl_egl_window_resize(window->egl_window, window->width, window->height, 0, 0); + wl_egl_window_resize(window->egl_window, window->buffer_width, window->buffer_height, 0, 0); #endif - kinc_wayland_resize_decoration(&window->decorations.top, KINC_WL_DECORATION_TOP_X, KINC_WL_DECORATION_TOP_Y, KINC_WL_DECORATION_TOP_WIDTH, - KINC_WL_DECORATION_TOP_HEIGHT); - kinc_wayland_resize_decoration(&window->decorations.left, KINC_WL_DECORATION_LEFT_X, KINC_WL_DECORATION_LEFT_Y, KINC_WL_DECORATION_LEFT_WIDTH, - KINC_WL_DECORATION_LEFT_HEIGHT); - kinc_wayland_resize_decoration(&window->decorations.right, KINC_WL_DECORATION_RIGHT_X, KINC_WL_DECORATION_RIGHT_Y, KINC_WL_DECORATION_RIGHT_WIDTH, - KINC_WL_DECORATION_RIGHT_HEIGHT); - kinc_wayland_resize_decoration(&window->decorations.bottom, KINC_WL_DECORATION_BOTTOM_X, KINC_WL_DECORATION_BOTTOM_Y, KINC_WL_DECORATION_BOTTOM_WIDTH, - KINC_WL_DECORATION_BOTTOM_HEIGHT); - kinc_wayland_resize_decoration(&window->decorations.close, KINC_WL_DECORATION_CLOSE_X, KINC_WL_DECORATION_CLOSE_Y, KINC_WL_DECORATION_CLOSE_WIDTH, - KINC_WL_DECORATION_CLOSE_HEIGHT); + kinc_wayland_resize_decoration(&window->decorations.top, KINC_WL_DECORATION_TOP_X, KINC_WL_DECORATION_TOP_Y, KINC_WL_DECORATION_TOP_WIDTH, + KINC_WL_DECORATION_TOP_HEIGHT); + kinc_wayland_resize_decoration(&window->decorations.left, KINC_WL_DECORATION_LEFT_X, KINC_WL_DECORATION_LEFT_Y, KINC_WL_DECORATION_LEFT_WIDTH, + KINC_WL_DECORATION_LEFT_HEIGHT); + kinc_wayland_resize_decoration(&window->decorations.right, KINC_WL_DECORATION_RIGHT_X, KINC_WL_DECORATION_RIGHT_Y, KINC_WL_DECORATION_RIGHT_WIDTH, + KINC_WL_DECORATION_RIGHT_HEIGHT); + kinc_wayland_resize_decoration(&window->decorations.bottom, KINC_WL_DECORATION_BOTTOM_X, KINC_WL_DECORATION_BOTTOM_Y, KINC_WL_DECORATION_BOTTOM_WIDTH, + KINC_WL_DECORATION_BOTTOM_HEIGHT); + kinc_wayland_resize_decoration(&window->decorations.close, KINC_WL_DECORATION_CLOSE_X, KINC_WL_DECORATION_CLOSE_Y, KINC_WL_DECORATION_CLOSE_WIDTH, + KINC_WL_DECORATION_CLOSE_HEIGHT); + } } void kinc_wayland_window_destroy(int window_index); @@ -301,9 +313,23 @@ void wl_surface_handle_enter(void *data, struct wl_surface *wl_surface, struct w void wl_surface_handle_leave(void *data, struct wl_surface *wl_surface, struct wl_output *output) {} +static void wl_surface_handle_preferred_buffer_scale(void *data, struct wl_surface *wl_surface, int32_t scale) { + struct kinc_wl_window *window = wl_surface_get_user_data(wl_surface); + if (!wl_ctx.fractional_scale_manager) { + window->preferred_scale = scale * 120; + } +} +static void wl_surface_handle_preferred_buffer_transform(void *data, struct wl_surface *wl_surface, uint32_t transform) {} + static const struct wl_surface_listener wl_surface_listener = { wl_surface_handle_enter, wl_surface_handle_leave, +#ifdef WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION + wl_surface_handle_preferred_buffer_scale, +#endif +#ifdef WL_SURFACE_PREFERRED_BUFFER_TRANSFORM_SINCE_VERSION + wl_surface_handle_preferred_buffer_transform, +#endif }; static const struct xdg_surface_listener xdg_surface_listener = { @@ -319,9 +345,22 @@ static const struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration xdg_toplevel_decoration_configure, }; +static void wp_fractional_scale_v1_handle_preferred_scale(void *data, struct wp_fractional_scale_v1 *fractional_scale, uint32_t scale) { + struct kinc_wl_window *window = data; + window->preferred_scale = scale; +} + +static const struct wp_fractional_scale_v1_listener wp_fractional_scale_v1_listener = { + wp_fractional_scale_v1_handle_preferred_scale, +}; + void kinc_wayland_window_set_title(int window_index, const char *title); void kinc_wayland_window_change_mode(int window_index, kinc_window_mode_t mode); +#ifndef KINC_WAYLAND_APP_ID +#define KINC_WAYLAND_APP_ID "_KincApplication" +#endif + int kinc_wayland_window_create(kinc_window_options_t *win, kinc_framebuffer_options_t *frame) { int window_index = -1; for (int i = 0; i < MAXIMUM_WINDOWS; i++) { @@ -331,26 +370,36 @@ int kinc_wayland_window_create(kinc_window_options_t *win, kinc_framebuffer_opti } } if (window_index == -1) { - kinc_log(KINC_LOG_LEVEL_ERROR, "Too much windows (maximum is %i)", MAXIMUM_WINDOWS); + kinc_log(KINC_LOG_LEVEL_ERROR, "Too many windows (maximum is %i)", MAXIMUM_WINDOWS); exit(1); } struct kinc_wl_window *window = &wl_ctx.windows[window_index]; window->window_id = window_index; - window->width = win->width; - window->height = win->height; - window->mode = KINC_WINDOW_MODE_WINDOW; + window->mode = -1; + window->preferred_scale = 120; window->surface = wl_compositor_create_surface(wl_ctx.compositor); wl_surface_set_user_data(window->surface, window); wl_surface_add_listener(window->surface, &wl_surface_listener, NULL); + if (wl_ctx.viewporter) { + window->viewport = wp_viewporter_get_viewport(wl_ctx.viewporter, window->surface); + } + + if (wl_ctx.fractional_scale_manager) { + if (!window->viewport) { + kinc_log(KINC_LOG_LEVEL_ERROR, "missing wp_viewport wayland extension"); + exit(1); + } + window->fractional_scale = wp_fractional_scale_manager_v1_get_fractional_scale(wl_ctx.fractional_scale_manager, window->surface); + wp_fractional_scale_v1_add_listener(window->fractional_scale, &wp_fractional_scale_v1_listener, window); + } + window->xdg_surface = xdg_wm_base_get_xdg_surface(wl_ctx.xdg_wm_base, window->surface); xdg_surface_add_listener(window->xdg_surface, &xdg_surface_listener, window); window->toplevel = xdg_surface_get_toplevel(window->xdg_surface); xdg_toplevel_add_listener(window->toplevel, &xdg_toplevel_listener, window); - kinc_wayland_window_set_title(window_index, win->title); - if (wl_ctx.decoration_manager) { window->xdg_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(wl_ctx.decoration_manager, window->toplevel); #ifdef KINC_WAYLAND_FORCE_CSD @@ -360,20 +409,38 @@ int kinc_wayland_window_create(kinc_window_options_t *win, kinc_framebuffer_opti } else { window->decorations.server_side = false; - kinc_wayland_create_decorations(window); } -#ifdef KINC_EGL - window->egl_window = wl_egl_window_create(window->surface, window->width, window->height); -#endif + xdg_toplevel_set_app_id(window->toplevel, KINC_WAYLAND_APP_ID); + wl_surface_commit(window->surface); - kinc_wayland_window_change_mode(window_index, win->mode); wl_ctx.num_windows++; while (!window->configured) { wl_display_roundtrip(wl_ctx.display); } + kinc_wayland_window_set_title(window_index, win->title); + kinc_wayland_window_change_mode(window_index, win->mode); + window->surface_width = (win->width * 120) / window->preferred_scale; + window->surface_height = (win->height * 120) / window->preferred_scale; + window->buffer_width = win->width; + window->buffer_height = win->height; + if (window->viewport) { + wp_viewport_set_source(window->viewport, 0, 0, wl_fixed_from_int(window->buffer_width), wl_fixed_from_int(window->buffer_height)); + wp_viewport_set_destination(window->viewport, window->surface_width, window->surface_height); + } else { + wl_surface_set_buffer_scale(window->surface, window->preferred_scale / 120); + } + xdg_surface_set_window_geometry(window->xdg_surface, 0, 0, window->surface_width, window->surface_height); + if(!window->decorations.server_side) { + kinc_wayland_create_decorations(window); + } + +#ifdef KINC_EGL + window->egl_window = wl_egl_window_create(window->surface, window->buffer_width, window->buffer_height); +#endif + wl_surface_commit(window->surface); return window_index; } @@ -413,11 +480,11 @@ void kinc_wayland_window_move(int window_index, int x, int y) { } int kinc_wayland_window_width(int window_index) { - return wl_ctx.windows[window_index].width; + return wl_ctx.windows[window_index].buffer_width; } int kinc_wayland_window_height(int window_index) { - return wl_ctx.windows[window_index].height; + return wl_ctx.windows[window_index].buffer_height; } void kinc_wayland_window_resize(int window_index, int width, int height) { @@ -466,4 +533,4 @@ int kinc_wayland_window_display(int window_index) { int kinc_wayland_count_windows() { return wl_ctx.num_windows; -} \ No newline at end of file +} diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/window.c.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/window.c.h index 4f2599c..47df1af 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/window.c.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/window.c.h @@ -14,7 +14,7 @@ EGLNativeWindowType kinc_egl_get_native_window(EGLDisplay display, EGLConfig con } #endif -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN void kinc_vulkan_get_instance_extensions(const char **extensions, int *count, int max) { procs.vulkan_get_instance_extensions(extensions, count, max); } @@ -80,10 +80,6 @@ void kinc_window_hide(int window_index) { procs.window_hide(window_index); } -void kinc_window_set_foreground(int window_index) { - procs.window_set_foreground(window_index); -} - void kinc_window_set_title(int window_index, const char *title) { procs.window_set_title(window_index, title); } diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/x11/system.c.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/x11/system.c.h index 57cbfcb..7e26ff5 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/x11/system.c.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/x11/system.c.h @@ -870,7 +870,7 @@ EGLNativeWindowType kinc_x11_egl_get_native_window(EGLDisplay display, EGLConfig } #endif -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN #include #include VkResult kinc_x11_vulkan_create_surface(VkInstance instance, int window_index, VkSurfaceKHR *surface) { diff --git a/Kinc/Backends/System/Linux/Sources/kinc/backend/x11/window.c.h b/Kinc/Backends/System/Linux/Sources/kinc/backend/x11/window.c.h index c2b76b6..fb8ada0 100644 --- a/Kinc/Backends/System/Linux/Sources/kinc/backend/x11/window.c.h +++ b/Kinc/Backends/System/Linux/Sources/kinc/backend/x11/window.c.h @@ -145,16 +145,6 @@ void kinc_x11_window_hide(int window_index) { xlib.XUnmapWindow(x11_ctx.display, window->window); } -void kinc_x11_window_set_foreground(int window_index) { - struct kinc_x11_window *window = &x11_ctx.windows[window_index]; - if (window->window == None) { - return; - } - xlib.XRaiseWindow(x11_ctx.display, window->window); - xlib.XSetInputFocus(x11_ctx.display, window->window, RevertToParent, CurrentTime); - xlib.XFlush(x11_ctx.display); -} - kinc_window_mode_t kinc_x11_window_get_mode(int window_index) { return x11_ctx.windows[window_index].mode; } diff --git a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/MiniWindows.h b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/MiniWindows.h index e5c9358..c56590e 100644 --- a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/MiniWindows.h +++ b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/MiniWindows.h @@ -14,8 +14,8 @@ typedef _W64 unsigned long ULONG_PTR; typedef unsigned long DWORD; typedef DWORD *LPDWORD; -#define STD_OUTPUT_HANDLE ((DWORD)-11) -#define STD_ERROR_HANDLE ((DWORD)-12) +#define STD_OUTPUT_HANDLE ((DWORD) - 11) +#define STD_ERROR_HANDLE ((DWORD) - 12) #define WINAPI __stdcall typedef void *HWND; typedef void *HANDLE; @@ -47,7 +47,7 @@ typedef CONST void *LPCVOID; #define OPEN_EXISTING 3 #define FILE_ATTRIBUTE_NORMAL 0x00000080 -#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1) +#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR) - 1) #define FILE_BEGIN 0 #define FILE_CURRENT 1 #define MAX_PATH 260 diff --git a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/SystemMicrosoft.c.h b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/SystemMicrosoft.c.h index 7f4ac2d..fbcbdef 100644 --- a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/SystemMicrosoft.c.h +++ b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/SystemMicrosoft.c.h @@ -1,7 +1,6 @@ #include "SystemMicrosoft.h" #include -#include #define S_OK ((HRESULT)0L) @@ -11,7 +10,7 @@ static void winerror(HRESULT result) { __debugbreak(); -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) if (dw != 0) { FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&buffer, 0, NULL); @@ -21,7 +20,7 @@ static void winerror(HRESULT result) { else { #endif kinc_error_message("Unknown Windows error, return value was 0x%x.", result); -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) } #endif } @@ -44,3 +43,7 @@ void kinc_microsoft_format(const char *format, va_list args, wchar_t *buffer) { vsprintf(cbuffer, format, args); MultiByteToWideChar(CP_UTF8, 0, cbuffer, -1, buffer, 4096); } + +void kinc_microsoft_convert_string(wchar_t *destination, const char *source, int num) { + MultiByteToWideChar(CP_UTF8, 0, source, -1, destination, num); +} diff --git a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/SystemMicrosoft.h b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/SystemMicrosoft.h index fa2dfd5..f833c66 100644 --- a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/SystemMicrosoft.h +++ b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/SystemMicrosoft.h @@ -11,6 +11,7 @@ typedef long HRESULT; void kinc_microsoft_affirm(HRESULT result); void kinc_microsoft_affirm_message(HRESULT result, const char *format, ...); void kinc_microsoft_format(const char *format, va_list args, wchar_t *buffer); +void kinc_microsoft_convert_string(wchar_t *destination, const char *source, int num); #ifdef __cplusplus } diff --git a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/fiber.c.h b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/fiber.c.h index c22a832..86c7115 100644 --- a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/fiber.c.h +++ b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/fiber.c.h @@ -1,20 +1,20 @@ #include VOID WINAPI fiber_func(LPVOID param) { -#ifndef KORE_WINDOWSAPP +#ifndef KINC_WINDOWSAPP kinc_fiber_t *fiber = (kinc_fiber_t *)param; fiber->impl.func(fiber->impl.param); #endif } void kinc_fiber_init_current_thread(kinc_fiber_t *fiber) { -#ifndef KORE_WINDOWSAPP +#ifndef KINC_WINDOWSAPP fiber->impl.fiber = ConvertThreadToFiber(NULL); #endif } void kinc_fiber_init(kinc_fiber_t *fiber, void (*func)(void *param), void *param) { -#ifndef KORE_WINDOWSAPP +#ifndef KINC_WINDOWSAPP fiber->impl.func = func; fiber->impl.param = param; fiber->impl.fiber = CreateFiber(0, fiber_func, fiber); @@ -22,14 +22,14 @@ void kinc_fiber_init(kinc_fiber_t *fiber, void (*func)(void *param), void *param } void kinc_fiber_destroy(kinc_fiber_t *fiber) { -#ifndef KORE_WINDOWSAPP +#ifndef KINC_WINDOWSAPP DeleteFiber(fiber->impl.fiber); fiber->impl.fiber = NULL; #endif } void kinc_fiber_switch(kinc_fiber_t *fiber) { -#ifndef KORE_WINDOWSAPP +#ifndef KINC_WINDOWSAPP SwitchToFiber(fiber->impl.fiber); #endif } diff --git a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/microsoftunit.c b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/microsoftunit.c index 2955740..789d5db 100644 --- a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/microsoftunit.c +++ b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/microsoftunit.c @@ -22,7 +22,7 @@ #define NOMETAFILE #define NOMINMAX #define NOMSG -//#define NONLS +// #define NONLS #define NOOPENFILE #define NOPROFILER #define NORASTEROPS diff --git a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/mutex.c.h b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/mutex.c.h index 5b47d13..3aea921 100644 --- a/Kinc/Backends/System/Microsoft/Sources/kinc/backend/mutex.c.h +++ b/Kinc/Backends/System/Microsoft/Sources/kinc/backend/mutex.c.h @@ -22,7 +22,7 @@ void kinc_mutex_unlock(kinc_mutex_t *mutex) { } bool kinc_uber_mutex_init(kinc_uber_mutex_t *mutex, const char *name) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) mutex->impl.id = (void *)CreateMutexA(NULL, FALSE, name); HRESULT res = GetLastError(); if (res && res != ERROR_ALREADY_EXISTS) { @@ -37,7 +37,7 @@ bool kinc_uber_mutex_init(kinc_uber_mutex_t *mutex, const char *name) { } void kinc_uber_mutex_destroy(kinc_uber_mutex_t *mutex) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) if (mutex->impl.id) { CloseHandle((HANDLE)mutex->impl.id); mutex->impl.id = NULL; @@ -46,14 +46,14 @@ void kinc_uber_mutex_destroy(kinc_uber_mutex_t *mutex) { } void kinc_uber_mutex_lock(kinc_uber_mutex_t *mutex) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) bool succ = WaitForSingleObject((HANDLE)mutex->impl.id, INFINITE) == WAIT_FAILED ? false : true; assert(succ); #endif } void kinc_uber_mutex_unlock(kinc_uber_mutex_t *mutex) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) bool succ = ReleaseMutex((HANDLE)mutex->impl.id) == FALSE ? false : true; assert(succ); #endif diff --git a/Kinc/Backends/System/POSIX/Sources/kinc/backend/atomic.h b/Kinc/Backends/System/POSIX/Sources/kinc/backend/atomic.h index 3cfb0fa..02b7437 100644 --- a/Kinc/Backends/System/POSIX/Sources/kinc/backend/atomic.h +++ b/Kinc/Backends/System/POSIX/Sources/kinc/backend/atomic.h @@ -2,40 +2,6 @@ #include -#if defined(KORE_MACOS) || defined(KORE_IOS) - -#include - -static inline bool kinc_atomic_compare_exchange(volatile int32_t *pointer, int32_t old_value, int32_t new_value) { - return OSAtomicCompareAndSwap32Barrier(old_value, new_value, pointer); -} - -static inline bool kinc_atomic_compare_exchange_pointer(void *volatile *pointer, void *old_value, void *new_value) { - return OSAtomicCompareAndSwapPtrBarrier(old_value, new_value, pointer); -} - -static inline int32_t kinc_atomic_increment(volatile int32_t *pointer) { - return OSAtomicIncrement32Barrier(pointer) - 1; -} - -static inline int32_t kinc_atomic_decrement(volatile int32_t *pointer) { - return OSAtomicDecrement32Barrier(pointer) + 1; -} - -static inline void kinc_atomic_exchange(volatile int32_t *pointer, int32_t value) { - __sync_swap(pointer, value); -} - -static inline void kinc_atomic_exchange_float(volatile float *pointer, float value) { - __sync_swap((volatile int32_t *)pointer, *(int32_t *)&value); -} - -static inline void kinc_atomic_exchange_double(volatile double *pointer, double value) { - __sync_swap((volatile int64_t *)pointer, *(int64_t *)&value); -} - -#else - // clang/gcc intrinsics static inline bool kinc_atomic_compare_exchange(volatile int32_t *pointer, int32_t old_value, int32_t new_value) { @@ -86,8 +52,6 @@ static inline void kinc_atomic_exchange_double(volatile double *pointer, double #endif -#endif - #define KINC_ATOMIC_COMPARE_EXCHANGE(pointer, oldValue, newValue) (kinc_atomic_compare_exchange(pointer, oldValue, newValue)) #define KINC_ATOMIC_COMPARE_EXCHANGE_POINTER(pointer, oldValue, newValue) (kinc_atomic_compare_exchange_pointer(pointer, oldValue, newValue)) diff --git a/Kinc/Backends/System/POSIX/Sources/kinc/backend/posixunit.c b/Kinc/Backends/System/POSIX/Sources/kinc/backend/posixunit.c index 76414a7..255e49c 100644 --- a/Kinc/Backends/System/POSIX/Sources/kinc/backend/posixunit.c +++ b/Kinc/Backends/System/POSIX/Sources/kinc/backend/posixunit.c @@ -1,5 +1,5 @@ -#include "event.c.h" -#include "mutex.c.h" -#include "semaphore.c.h" -#include "thread.c.h" -#include "threadlocal.c.h" +#include "event.c.h" +#include "mutex.c.h" +#include "semaphore.c.h" +#include "thread.c.h" +#include "threadlocal.c.h" diff --git a/Kinc/Backends/System/POSIX/Sources/kinc/backend/thread.c.h b/Kinc/Backends/System/POSIX/Sources/kinc/backend/thread.c.h index 6f5b95a..ad32f35 100644 --- a/Kinc/Backends/System/POSIX/Sources/kinc/backend/thread.c.h +++ b/Kinc/Backends/System/POSIX/Sources/kinc/backend/thread.c.h @@ -6,7 +6,7 @@ #include #include -#if !defined(KORE_IOS) && !defined(KORE_MACOS) +#if !defined(KINC_IOS) && !defined(KINC_MACOS) struct thread_start { void (*thread)(void *param); @@ -62,7 +62,7 @@ void kinc_threads_quit() {} #endif -#if !defined(KORE_IOS) && !defined(KORE_MACOS) +#if !defined(KINC_IOS) && !defined(KINC_MACOS) // Alternatively _GNU_SOURCE can be defined to make // the headers declare it but let's not make it too // easy to write Linux-specific POSIX-code @@ -70,7 +70,7 @@ int pthread_setname_np(pthread_t thread, const char *name); #endif void kinc_thread_set_name(const char *name) { -#if !defined(KORE_IOS) && !defined(KORE_MACOS) +#if !defined(KINC_IOS) && !defined(KINC_MACOS) pthread_setname_np(pthread_self(), name); #else pthread_setname_np(name); diff --git a/Kinc/Backends/System/Pi/Sources/kinc/backend/system.cpp b/Kinc/Backends/System/Pi/Sources/kinc/backend/system.cpp index 24ea409..f88ae83 100644 --- a/Kinc/Backends/System/Pi/Sources/kinc/backend/system.cpp +++ b/Kinc/Backends/System/Pi/Sources/kinc/backend/system.cpp @@ -204,7 +204,7 @@ int createWindow(const char *title, int x, int y, int width, int height, Kore::W else { dst_rect.x = x; dst_rect.y = y; -#ifdef KORE_PI_SCALING +#ifdef KINC_RASPBERRY_PI_SCALING dst_rect.width = screen_width; dst_rect.height = screen_height; #else @@ -236,7 +236,7 @@ int createWindow(const char *title, int x, int y, int width, int height, Kore::W else { nativewindow.width = width; nativewindow.height = height; -#ifndef KORE_PI_SCALING +#ifndef KINC_RASPBERRY_PI_SCALING openXWindow(x, y, width, height); #endif } @@ -473,7 +473,7 @@ bool Kore::System::handleMessages() { } } -#ifndef KORE_PI_SCALING +#ifndef KINC_RASPBERRY_PI_SCALING if (windowMode != Kore::WindowModeFullscreen) { while (XPending(dpy) > 0) { XEvent event; diff --git a/Kinc/Backends/System/Wasm/JS-Sources/audio-thread.js b/Kinc/Backends/System/Wasm/JS-Sources/audio-thread.js index 38f8f1c..157b1e9 100644 --- a/Kinc/Backends/System/Wasm/JS-Sources/audio-thread.js +++ b/Kinc/Backends/System/Wasm/JS-Sources/audio-thread.js @@ -5,42 +5,169 @@ function create_thread(func) { } class AudioThread extends AudioWorkletProcessor { - constructor(...args) { - super(...args); + constructor(options) { + super(); const self = this; this.port.onmessageerror = (e) => { - console.error('Error', e); + this.port.postMessage('Error: ' + JSON.stringify(e)); }; - this.port.onmessage = (e) => { - console.log('Audio onmessage'); - - const mod = e.data.mod; - const memory = e.data.memory; - - const importObject = { - env: { memory }, - imports: { - imported_func: arg => console.log('thread: ' + arg), - create_thread - } - }; - - WebAssembly.instantiate(mod, importObject).then((instance) => { - console.log('Running audio thread'); - self.audio_func = instance.exports.audio_func; - self.audio_pointer = instance.exports.malloc(16 * 1024); - console.log('Audio pointer: ' + self.audio_pointer); - console.log('Memory byteLength: ' + memory.buffer.byteLength); - self.audio_data = new Float32Array( - memory.buffer, - self.audio_pointer, - 16 * 256 - ); - }); + const mod = options.processorOptions.mod; + const memory = options.processorOptions.memory; + + const importObject = { + env: { memory }, + imports: { + imported_func: arg => console.log('thread: ' + arg), + create_thread, + glViewport: function(x, y, width, height) { }, + glScissor: function(x, y, width, height) { }, + glGetIntegerv: function(pname, data) { }, + glGetFloatv: function(pname, data) { }, + glGetString: function(name) { }, + glDrawElements: function(mode, count, type, offset) { }, + glDrawElementsInstanced: function(mode, count, type, indices, instancecount) { }, + glVertexAttribDivisor: function(index, divisor) { }, + glBindFramebuffer: function(target, framebuffer) { }, + glFramebufferTexture2D: function(target, attachment, textarget, texture, level) { }, + glGenFramebuffers: function(n, framebuffers) { }, + glGenRenderbuffers: function(n, renderbuffers) { }, + glBindRenderbuffer: function(target, renderbuffer) { }, + glRenderbufferStorage: function(target, internalformat, width, height) { }, + glFramebufferRenderbuffer: function(target, attachment, renderbuffertarget, renderbuffer) { }, + glReadPixels: function(x, y, width, height, format, type, data) { }, + glTexSubImage2D: function(target, level, xoffset, yoffset, width, height, format, type, pixels) { }, + glEnable: function(cap) { }, + glDisable: function(cap) { }, + glColorMask: function(red, green, blue, alpha) { }, + glClearColor: function(red, green, blue, alpha) { }, + glDepthMask: function(flag) { }, + glClearDepthf: function(depth) { }, + glStencilMask: function(mask) { }, + glClearStencil: function(s) { }, + glClear: function(mask) { }, + glBindBuffer: function(target, buffer) { }, + glUseProgram: function(program) { }, + glStencilMaskSeparate: function(face, mask) { }, + glStencilOpSeparate: function(face, fail, zfail, zpass) { }, + glStencilFuncSeparate: function(face, func, ref, mask) { }, + glDepthFunc: function(func) { }, + glCullFace: function(mode) { }, + glBlendFuncSeparate: function(src_rgb, dst_rgb, src_alpha, dst_alpha) { }, + glBlendEquationSeparate: function(mode_rgb, mode_alpha) { }, + glGenBuffers: function(n, buffers) { }, + glBufferData: function(target, size, data, usage) { }, + glCreateProgram: function() { }, + glAttachShader: function(program, shader) { }, + glBindAttribLocation: function(program, index, name) { }, + glLinkProgram: function(program) { }, + glGetProgramiv: function(program, pname, params) { }, + glGetProgramInfoLog: function(program) { }, + glCreateShader: function(type) { }, + glShaderSource: function(shader, count, source, length) { }, + glCompileShader: function(shader) { }, + glGetShaderiv: function(shader, pname, params) { }, + glGetShaderInfoLog: function(shader) { }, + glBufferSubData: function(target, offset, size, data) { }, + glEnableVertexAttribArray: function(index) { }, + glVertexAttribPointer: function(index, size, type, normalized, stride, offset) { }, + glDisableVertexAttribArray: function(index) { }, + glGetUniformLocation: function(program, name) { }, + glUniform1i: function(location, v0) { }, + glUniform2i: function(location, v0, v1) { }, + glUniform3i: function(location, v0, v1, v2) { }, + glUniform4i: function(location, v0, v1, v2, v3) { }, + glUniform1iv: function(location, count, value) { }, + glUniform2iv: function(location, count, value) { }, + glUniform3iv: function(location, count, value) { }, + glUniform4iv: function(location, count, value) { }, + glUniform1f: function(location, v0) { }, + glUniform2f: function(location, v0, v1) { }, + glUniform3f: function(location, v0, v1, v2) { }, + glUniform4f: function(location, v0, v1, v2, v3) { }, + glUniform1fv: function(location, count, value) { }, + glUniform2fv: function(location, count, value) { }, + glUniform3fv: function(location, count, value) { }, + glUniform4fv: function(location, count, value) { }, + glUniformMatrix3fv: function(location, count, transpose, value) { }, + glUniformMatrix4fv: function(location, count, transpose, value) { }, + glTexParameterf: function(target, pname, param) { }, + glActiveTexture: function(texture) { }, + glBindTexture: function(target, texture) { }, + glTexParameteri: function(target, pname, param) { }, + glGetActiveUniform: function(program, index, bufSize, length, size, type, name) { }, + glGenTextures: function(n, textures) { }, + glTexImage2D: function(target, level, internalformat, width, height, border, format, type, data) { }, + glPixelStorei: function(pname, param) { }, + glCompressedTexImage2D: function(target, level, internalformat, width, height, border, imageSize, data) { }, + glDrawBuffers: function(n, bufs) { }, + glGenerateMipmap: function(target) { }, + glFlush: function() { }, + glDeleteBuffers: function(n, buffers) { }, + glDeleteTextures: function(n, textures) { }, + glDeleteFramebuffers: function(n, framebuffers) { }, + glDeleteProgram: function(program) { }, + glDeleteShader: function(shader) { }, + js_fprintf: function(format) { + console.log(read_string(format)); + }, + js_fopen: function(filename) { + return 0; + }, + js_ftell: function(stream) { + return 0; + }, + js_fseek: function(stream, offset, origin) { + return 0; + }, + js_fread: function(ptr, size, count, stream) { + return 0; + }, + js_time: function() { + return window.performance.now(); + }, + js_pow: function(x) { + return Math.pow(x); + }, + js_floor: function(x) { + return Math.floor(x); + }, + js_sin: function(x) { + return Math.sin(x); + }, + js_cos: function(x) { + return Math.cos(x); + }, + js_tan: function(x) { + return Math.tan(x); + }, + js_log: function(base, exponent) { + return Math.log(base, exponent); + }, + js_exp: function(x) { + return Math.exp(x); + }, + js_sqrt: function(x) { + return Math.sqrt(x); + }, + js_eval: function(str) { } + } }; + + WebAssembly.instantiate(mod, importObject).then((instance) => { + this.port.postMessage('Running audio thread'); + self.audio_func = instance.exports.audio_func; + self.audio_pointer = instance.exports.malloc(16 * 1024); + this.port.postMessage('Audio pointer: ' + self.audio_pointer); + this.port.postMessage('Memory byteLength: ' + memory.buffer.byteLength); + self.audio_data = new Float32Array( + memory.buffer, + self.audio_pointer, + 16 * 256 + ); + }); } process(inputs, outputs, parameters) { diff --git a/Kinc/Backends/System/Wasm/JS-Sources/index.html b/Kinc/Backends/System/Wasm/JS-Sources/index.html new file mode 100644 index 0000000..93c9632 --- /dev/null +++ b/Kinc/Backends/System/Wasm/JS-Sources/index.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/Kinc/Backends/System/Wasm/JS-Sources/start.js b/Kinc/Backends/System/Wasm/JS-Sources/start.js index 5cc1391..1ea61de 100644 --- a/Kinc/Backends/System/Wasm/JS-Sources/start.js +++ b/Kinc/Backends/System/Wasm/JS-Sources/start.js @@ -8,6 +8,7 @@ let heapi32 = null; let heapf32 = null; let mod = null; let instance = null; +let audio_thread_started = false; function create_thread(func) { console.log('Creating thread'); @@ -23,8 +24,10 @@ function create_thread(func) { async function start_audio_thread() { const audioContext = new AudioContext(); await audioContext.audioWorklet.addModule('audio-thread.js'); - const audioThreadNode = new AudioWorkletNode(audioContext, 'audio-thread'); - audioThreadNode.port.postMessage({ mod, memory }); + const audioThreadNode = new AudioWorkletNode(audioContext, 'audio-thread', { processorOptions: { mod, memory }}); + audioThreadNode.port.onmessage = (message) => { + console.log(message.data); + }; audioThreadNode.connect(audioContext.destination); } @@ -492,7 +495,10 @@ async function init() { window.requestAnimationFrame(update); kanvas.addEventListener('click', (event) => { - // start_audio_thread(); + if (!audio_thread_started) { + start_audio_thread(); + audio_thread_started = true; + } }); kanvas.addEventListener('contextmenu', (event) => { diff --git a/Kinc/Backends/System/Wasm/Sources/kinc/backend/audio.c.h b/Kinc/Backends/System/Wasm/Sources/kinc/backend/audio.c.h index b9c6e38..3be8307 100644 --- a/Kinc/Backends/System/Wasm/Sources/kinc/backend/audio.c.h +++ b/Kinc/Backends/System/Wasm/Sources/kinc/backend/audio.c.h @@ -1,15 +1,18 @@ #include #include -static void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = NULL; static kinc_a2_buffer_t a2_buffer; -void kinc_a2_init() {} +void kinc_a2_init() { + kinc_a2_internal_init(); +} void kinc_a2_update() {} void kinc_a2_shutdown() {} -void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) { - a2_callback = kinc_a2_audio_callback; +static uint32_t samples_per_second = 44100; + +uint32_t kinc_a2_samples_per_second(void) { + return samples_per_second; } diff --git a/Kinc/Backends/System/Wasm/Sources/kinc/backend/system.c.h b/Kinc/Backends/System/Wasm/Sources/kinc/backend/system.c.h index f71d3f0..615d8b4 100644 --- a/Kinc/Backends/System/Wasm/Sources/kinc/backend/system.c.h +++ b/Kinc/Backends/System/Wasm/Sources/kinc/backend/system.c.h @@ -13,10 +13,6 @@ __attribute__((import_module("imports"), import_name("js_time"))) int js_time(); extern int kinc_internal_window_width; extern int kinc_internal_window_height; -#ifdef KINC_KONG -void kong_init(void); -#endif - int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) { kinc_window_options_t defaultWin; if (win == NULL) { @@ -37,10 +33,6 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi kinc_g4_internal_init(); kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true); -#ifdef KINC_KONG - kong_init(); -#endif - return 0; } diff --git a/Kinc/Backends/System/Wasm/Sources/kinc/backend/video.c.h b/Kinc/Backends/System/Wasm/Sources/kinc/backend/video.c.h index e1a5111..bedd154 100644 --- a/Kinc/Backends/System/Wasm/Sources/kinc/backend/video.c.h +++ b/Kinc/Backends/System/Wasm/Sources/kinc/backend/video.c.h @@ -46,8 +46,10 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count) {} -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream) { - return 0.0f; +static float samples[2] = {0}; + +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream) { + return samples; } bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream) { diff --git a/Kinc/Backends/System/Wasm/Sources/kinc/backend/video.h b/Kinc/Backends/System/Wasm/Sources/kinc/backend/video.h index 0acd202..146a7d4 100644 --- a/Kinc/Backends/System/Wasm/Sources/kinc/backend/video.h +++ b/Kinc/Backends/System/Wasm/Sources/kinc/backend/video.h @@ -18,7 +18,7 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count); -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream); +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream); bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream); diff --git a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/amvideo.cpp b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/amvideo.cpp index 42fe446..2538389 100644 --- a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/amvideo.cpp +++ b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/amvideo.cpp @@ -23,8 +23,8 @@ const DWORD bits888[] = {0xFF0000,0x00FF00,0x0000FF}; const struct { const GUID *pSubtype; WORD BitCount; - CHAR *pName; - WCHAR *wszName; + const CHAR *pName; + const WCHAR *wszName; } BitCountMap[] = { &MEDIASUBTYPE_RGB1, 1, "RGB Monochrome", L"RGB Monochrome", &MEDIASUBTYPE_RGB4, 4, "RGB VGA", L"RGB VGA", &MEDIASUBTYPE_RGB8, 8, "RGB 8", L"RGB 8", @@ -173,12 +173,12 @@ int LocateSubtype(const GUID *pSubtype) -STDAPI_(WCHAR *) GetSubtypeNameW(const GUID *pSubtype) +STDAPI_(const WCHAR *) GetSubtypeNameW(const GUID *pSubtype) { return BitCountMap[LocateSubtype(pSubtype)].wszName; } -STDAPI_(CHAR *) GetSubtypeNameA(const GUID *pSubtype) +STDAPI_(const CHAR *) GetSubtypeNameA(const GUID *pSubtype) { return BitCountMap[LocateSubtype(pSubtype)].pName; } @@ -190,7 +190,7 @@ STDAPI_(CHAR *) GetSubtypeNameA(const GUID *pSubtype) // this is here for people that linked to it directly; most people // would use the header file that picks the A or W version. -STDAPI_(CHAR *) GetSubtypeName(const GUID *pSubtype) +STDAPI_(const CHAR *) GetSubtypeName(const GUID *pSubtype) { return GetSubtypeNameA(pSubtype); } diff --git a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/transip.h b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/transip.h index 3fc335e..687efd9 100644 --- a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/transip.h +++ b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/transip.h @@ -211,7 +211,7 @@ public: protected: - __out_opt IMediaSample * CTransInPlaceFilter::Copy(IMediaSample *pSource); + __out_opt IMediaSample * Copy(IMediaSample *pSource); #ifdef PERF int m_idTransInPlace; // performance measuring id diff --git a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/videoctl.cpp b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/videoctl.cpp index b12ccbd..7a559cf 100644 --- a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/videoctl.cpp +++ b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/videoctl.cpp @@ -15,7 +15,7 @@ // buffer in the property page class and use it for all string loading. It // cannot be static as multiple property pages may be active simultaneously -LPTSTR WINAPI StringFromResource(__out_ecount(STR_MAX_LENGTH) LPTSTR pBuffer, int iResourceID) +LPCTSTR WINAPI StringFromResource(__out_ecount(STR_MAX_LENGTH) LPTSTR pBuffer, int iResourceID) { if (LoadString(g_hInst,iResourceID,pBuffer,STR_MAX_LENGTH) == 0) { return TEXT(""); @@ -24,7 +24,7 @@ LPTSTR WINAPI StringFromResource(__out_ecount(STR_MAX_LENGTH) LPTSTR pBuffer, in } #ifdef UNICODE -LPSTR WINAPI StringFromResource(__out_ecount(STR_MAX_LENGTH) LPSTR pBuffer, int iResourceID) +LPCSTR WINAPI StringFromResource(__out_ecount(STR_MAX_LENGTH) LPSTR pBuffer, int iResourceID) { if (LoadStringA(g_hInst,iResourceID,pBuffer,STR_MAX_LENGTH) == 0) { return ""; diff --git a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/videoctl.h b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/videoctl.h index 30c3778..306a944 100644 --- a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/videoctl.h +++ b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/videoctl.h @@ -17,11 +17,11 @@ // resource ID of a dialog box and returns the size of it in screen pixels #define STR_MAX_LENGTH 256 -LPTSTR WINAPI StringFromResource(__out_ecount(STR_MAX_LENGTH) LPTSTR pBuffer, int iResourceID); +LPCTSTR WINAPI StringFromResource(__out_ecount(STR_MAX_LENGTH) LPTSTR pBuffer, int iResourceID); #ifdef UNICODE #define WideStringFromResource StringFromResource -LPSTR WINAPI StringFromResource(__out_ecount(STR_MAX_LENGTH) LPSTR pBuffer, int iResourceID); +LPCSTR WINAPI StringFromResource(__out_ecount(STR_MAX_LENGTH) LPSTR pBuffer, int iResourceID); #else LPWSTR WINAPI WideStringFromResource(__out_ecount(STR_MAX_LENGTH) LPWSTR pBuffer, int iResourceID); #endif @@ -51,7 +51,7 @@ public: CUnknown(pName,pUnk), m_pDirectDraw(NULL) { }; - virtual CAggDirectDraw::~CAggDirectDraw() { }; + virtual ~CAggDirectDraw() { }; // Set the object we should be aggregating void SetDirectDraw(__inout LPDIRECTDRAW pDirectDraw) { diff --git a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxdebug.cpp b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxdebug.cpp index 78e0472..31763bf 100644 --- a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxdebug.cpp +++ b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxdebug.cpp @@ -86,7 +86,7 @@ bool g_fAutoRefreshLevels = false; LPCTSTR pBaseKey = TEXT("SOFTWARE\\Microsoft\\DirectShow\\Debug"); LPCTSTR pGlobalKey = TEXT("GLOBAL"); -static CHAR *pUnknownName = "UNKNOWN"; +static const CHAR *pUnknownName = "UNKNOWN"; LPCTSTR TimeoutName = TEXT("TIMEOUT"); @@ -1086,7 +1086,7 @@ void WINAPI DbgSetWaitTimeout(DWORD dwTimeout) CGuidNameList GuidNames; int g_cGuidNames = sizeof(g_GuidNames) / sizeof(g_GuidNames[0]); - char *CGuidNameList::operator [] (const GUID &guid) + const char *CGuidNameList::operator [] (const GUID &guid) { for (int i = 0; i < g_cGuidNames; i++) { if (g_GuidNames[i].guid == guid) { diff --git a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxdebug.h b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxdebug.h index d4c69db..7d2518f 100644 --- a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxdebug.h +++ b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxdebug.h @@ -254,13 +254,13 @@ typedef struct tag_ObjectDesc { // Returns the name defined in uuids.h as a string typedef struct { - CHAR *szName; + const CHAR *szName; GUID guid; } GUID_STRING_ENTRY; class CGuidNameList { public: - CHAR *operator [] (const GUID& guid); + const CHAR *operator [] (const GUID& guid); }; extern CGuidNameList GuidNames; diff --git a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxutil.h b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxutil.h index 0f17139..36777ba 100644 --- a/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxutil.h +++ b/Kinc/Backends/System/Windows/Libraries/DirectShow/BaseClasses/wxutil.h @@ -408,8 +408,8 @@ STDAPI_(WORD) GetBitCount(const GUID *pSubtype); // // STDAPI_(/* T */ CHAR *) GetSubtypeName(const GUID *pSubtype); -STDAPI_(CHAR *) GetSubtypeNameA(const GUID *pSubtype); -STDAPI_(WCHAR *) GetSubtypeNameW(const GUID *pSubtype); +STDAPI_(const CHAR *) GetSubtypeNameA(const GUID *pSubtype); +STDAPI_(const WCHAR *) GetSubtypeNameW(const GUID *pSubtype); #ifdef UNICODE #define GetSubtypeName GetSubtypeNameW diff --git a/Kinc/Backends/System/Windows/Sources/kinc/backend/VrInterface_SteamVR.cpp.h b/Kinc/Backends/System/Windows/Sources/kinc/backend/VrInterface_SteamVR.cpp.h index f33dd8b..3ab9586 100644 --- a/Kinc/Backends/System/Windows/Sources/kinc/backend/VrInterface_SteamVR.cpp.h +++ b/Kinc/Backends/System/Windows/Sources/kinc/backend/VrInterface_SteamVR.cpp.h @@ -1,4 +1,4 @@ -#ifdef KORE_STEAMVR +#ifdef KINC_STEAMVR #include #include @@ -280,7 +280,7 @@ kinc_vr_pose_state_t kinc_vr_interface_get_controller(int index) { } void kinc_vr_interface_warp_swap() { -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL vr::Texture_t leftEyeTexture = {(void *)(uintptr_t)leftTexture.impl._texture, vr::TextureType_OpenGL, vr::ColorSpace_Gamma}; vr::VRCompositor()->Submit(vr::Eye_Left, &leftEyeTexture); vr::Texture_t rightEyeTexture = {(void *)(uintptr_t)rightTexture.impl._texture, vr::TextureType_OpenGL, vr::ColorSpace_Gamma}; diff --git a/Kinc/Backends/System/Windows/Sources/kinc/backend/system.c.h b/Kinc/Backends/System/Windows/Sources/kinc/backend/system.c.h index e384f2d..305ad0c 100644 --- a/Kinc/Backends/System/Windows/Sources/kinc/backend/system.c.h +++ b/Kinc/Backends/System/Windows/Sources/kinc/backend/system.c.h @@ -33,9 +33,9 @@ __itt_domain *kinc_itt_domain; #endif -#ifdef KORE_G4ONG5 +#ifdef KINC_G4ONG5 #define Graphics Graphics5 -#elif KORE_G4 +#elif KINC_G4 #define Graphics Graphics4 #else #define Graphics Graphics3 @@ -54,6 +54,8 @@ static EnableNonClientDpiScalingType MyEnableNonClientDpiScaling = NULL; #define MAX_TOUCH_POINTS 10 +#define KINC_DINPUT_MAX_COUNT 8 + struct touchpoint { int sysID; int x; @@ -288,7 +290,7 @@ static wchar_t toUnicode(WPARAM wParam, LPARAM lParam) { return buffer[0]; } -#if !defined(KORE_DIRECT3D9) && !defined(KORE_DIRECT3D11) && !defined(KORE_DIRECT3D12) +#if !defined(KINC_DIRECT3D9) && !defined(KINC_DIRECT3D11) && !defined(KINC_DIRECT3D12) #define HANDLE_ALT_ENTER #endif @@ -346,7 +348,7 @@ LRESULT WINAPI KoreWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L } break; } - case WM_CLOSE: + case WM_CLOSE: { int window_index = kinc_windows_window_index_from_hwnd(hWnd); if (kinc_internal_call_close_callback(window_index)) { kinc_window_destroy(window_index); @@ -356,6 +358,7 @@ LRESULT WINAPI KoreWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L } } return 0; + } case WM_ERASEBKGND: return 1; case WM_ACTIVATE: @@ -543,7 +546,7 @@ LRESULT WINAPI KoreWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L if (bHandled) CloseTouchInputHandle((HTOUCHINPUT)lParam); else - DefWindowProc(hWnd, WM_TOUCH, wParam, lParam); + DefWindowProcW(hWnd, WM_TOUCH, wParam, lParam); InvalidateRect(hWnd, NULL, FALSE); } break; @@ -633,9 +636,8 @@ LRESULT WINAPI KoreWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L } #endif } - - kinc_internal_keyboard_trigger_key_down(keyTranslated[wParam]); } + kinc_internal_keyboard_trigger_key_down(keyTranslated[wParam]); break; case WM_KEYUP: case WM_SYSKEYUP: @@ -654,19 +656,8 @@ LRESULT WINAPI KoreWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L break; case WM_CHAR: switch (wParam) { - case 0x08: // backspace - break; - case 0x0A: // linefeed - kinc_internal_keyboard_trigger_key_press(L'\n'); - break; case 0x1B: // escape break; - case 0x09: // tab - kinc_internal_keyboard_trigger_key_press(L'\t'); - break; - case 0x0D: // carriage return - kinc_internal_keyboard_trigger_key_press(L'\r'); - break; default: kinc_internal_keyboard_trigger_key_press((unsigned)wParam); break; @@ -698,7 +689,7 @@ LRESULT WINAPI KoreWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L case WM_DEVICECHANGE: detectGamepad = true; break; - case WM_DROPFILES: + case WM_DROPFILES: { HDROP hDrop = (HDROP)wParam; unsigned count = DragQueryFileW(hDrop, 0xFFFFFFFF, NULL, 0); for (unsigned i = 0; i < count; ++i) { @@ -710,7 +701,8 @@ LRESULT WINAPI KoreWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L DragFinish(hDrop); break; } - return DefWindowProc(hWnd, msg, wParam, lParam); + } + return DefWindowProcW(hWnd, msg, wParam, lParam); } static float axes[12 * 6]; @@ -722,12 +714,12 @@ static XInputGetStateType InputGetState = NULL; static XInputSetStateType InputSetState = NULL; void loadXInput() { - HMODULE lib = LoadLibrary(L"xinput1_4.dll"); + HMODULE lib = LoadLibraryA("xinput1_4.dll"); if (lib == NULL) { - lib = LoadLibrary(L"xinput1_3.dll"); + lib = LoadLibraryA("xinput1_3.dll"); } if (lib == NULL) { - lib = LoadLibrary(L"xinput9_1_0.dll"); + lib = LoadLibraryA("xinput9_1_0.dll"); } if (lib != NULL) { @@ -736,11 +728,11 @@ void loadXInput() { } } -static IDirectInput8 *di_instance = NULL; -static IDirectInputDevice8 *di_pads[XUSER_MAX_COUNT]; -static DIJOYSTATE2 di_padState[XUSER_MAX_COUNT]; -static DIJOYSTATE2 di_lastPadState[XUSER_MAX_COUNT]; -static DIDEVCAPS di_deviceCaps[XUSER_MAX_COUNT]; +static IDirectInput8W *di_instance = NULL; +static IDirectInputDevice8W *di_pads[KINC_DINPUT_MAX_COUNT]; +static DIJOYSTATE2 di_padState[KINC_DINPUT_MAX_COUNT]; +static DIJOYSTATE2 di_lastPadState[KINC_DINPUT_MAX_COUNT]; +static DIDEVCAPS di_deviceCaps[KINC_DINPUT_MAX_COUNT]; static int padCount = 0; static void cleanupPad(int padIndex) { @@ -874,7 +866,7 @@ LCleanup: // TODO (DK) this should probably be called from somewhere? static void cleanupDirectInput() { - for (int padIndex = 0; padIndex < XUSER_MAX_COUNT; ++padIndex) { + for (int padIndex = 0; padIndex < KINC_DINPUT_MAX_COUNT; ++padIndex) { cleanupPad(padIndex); } @@ -910,8 +902,10 @@ static BOOL CALLBACK enumerateJoystickAxesCallback(LPCDIDEVICEOBJECTINSTANCEW dd } static BOOL CALLBACK enumerateJoysticksCallback(LPCDIDEVICEINSTANCEW ddi, LPVOID context) { - if (IsXInputDevice(&ddi->guidProduct)) + if (padCount < XUSER_MAX_COUNT && IsXInputDevice(&ddi->guidProduct)) { + ++padCount; return DIENUM_CONTINUE; + } HRESULT hr = di_instance->lpVtbl->CreateDevice(di_instance, &ddi->guidInstance, &di_pads[padCount], NULL); @@ -965,7 +959,7 @@ static BOOL CALLBACK enumerateJoysticksCallback(LPCDIDEVICEINSTANCEW ddi, LPVOID ++padCount; - if (padCount >= XUSER_MAX_COUNT) { + if (padCount >= KINC_DINPUT_MAX_COUNT) { return DIENUM_STOP; } } @@ -974,14 +968,14 @@ static BOOL CALLBACK enumerateJoysticksCallback(LPCDIDEVICEINSTANCEW ddi, LPVOID } static void initializeDirectInput() { - HINSTANCE hinstance = GetModuleHandle(NULL); + HINSTANCE hinstance = GetModuleHandleW(NULL); - memset(&di_pads, 0, sizeof(IDirectInputDevice8) * XUSER_MAX_COUNT); - memset(&di_padState, 0, sizeof(DIJOYSTATE2) * XUSER_MAX_COUNT); - memset(&di_lastPadState, 0, sizeof(DIJOYSTATE2) * XUSER_MAX_COUNT); - memset(&di_deviceCaps, 0, sizeof(DIDEVCAPS) * XUSER_MAX_COUNT); + memset(&di_pads, 0, sizeof(IDirectInputDevice8) * KINC_DINPUT_MAX_COUNT); + memset(&di_padState, 0, sizeof(DIJOYSTATE2) * KINC_DINPUT_MAX_COUNT); + memset(&di_lastPadState, 0, sizeof(DIJOYSTATE2) * KINC_DINPUT_MAX_COUNT); + memset(&di_deviceCaps, 0, sizeof(DIDEVCAPS) * KINC_DINPUT_MAX_COUNT); - HRESULT hr = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, &IID_IDirectInput8, (void **)&di_instance, NULL); + HRESULT hr = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, &IID_IDirectInput8W, (void **)&di_instance, NULL); if (SUCCEEDED(hr)) { hr = di_instance->lpVtbl->EnumDevices(di_instance, DI8DEVCLASS_GAMECTRL, enumerateJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY); @@ -1082,6 +1076,10 @@ bool handleDirectInputPad(int padIndex) { } static bool isXInputGamepad(int gamepad) { + // if gamepad is greater than XInput max, treat it as DINPUT. + if (gamepad >= XUSER_MAX_COUNT) { + return false; + } XINPUT_STATE state; memset(&state, 0, sizeof(XINPUT_STATE)); DWORD dwResult = InputGetState(gamepad, &state); @@ -1117,14 +1115,14 @@ const char *kinc_gamepad_product_name(int gamepad) { bool kinc_internal_handle_messages() { MSG message; - while (PeekMessage(&message, 0, 0, 0, PM_REMOVE)) { + while (PeekMessageW(&message, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&message); - DispatchMessage(&message); + DispatchMessageW(&message); } if (InputGetState != NULL && (detectGamepad || gamepadFound)) { detectGamepad = false; - for (DWORD i = 0; i < XUSER_MAX_COUNT; ++i) { + for (DWORD i = 0; i < KINC_DINPUT_MAX_COUNT; ++i) { XINPUT_STATE state; memset(&state, 0, sizeof(XINPUT_STATE)); DWORD dwResult = InputGetState(i, &state); @@ -1263,7 +1261,7 @@ static void findSavePath() { wcscat(savePathw, name); wcscat(savePathw, L"\\"); - SHCreateDirectoryEx(NULL, savePathw, NULL); + SHCreateDirectoryExW(NULL, savePathw, NULL); WideCharToMultiByte(CP_UTF8, 0, savePathw, -1, savePath, 1024, NULL, NULL); CoTaskMemFree(path); @@ -1362,10 +1360,6 @@ static void init_crash_handler() { } } -#ifdef KINC_KONG -void kong_init(void); -#endif - int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) { init_crash_handler(); @@ -1417,10 +1411,6 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi loadXInput(); initializeDirectInput(); -#ifdef KINC_KONG - kong_init(); -#endif - return window; } diff --git a/Kinc/Backends/System/Windows/Sources/kinc/backend/video.cpp.h b/Kinc/Backends/System/Windows/Sources/kinc/backend/video.cpp.h index 197dbf6..5a51c7c 100644 --- a/Kinc/Backends/System/Windows/Sources/kinc/backend/video.cpp.h +++ b/Kinc/Backends/System/Windows/Sources/kinc/backend/video.cpp.h @@ -1,6 +1,6 @@ #include -#ifdef KORE_DIRECT3D12 +#ifdef KINC_DIRECT3D12 void kinc_video_init(kinc_video_t *video, const char *filename) {} @@ -285,8 +285,12 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count) {} -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream) { - return 0.0f; +static float samples[2]; + +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream) { + samples[0] = 0.0f; + samples[1] = 0.0f; + return samples; } bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream) { diff --git a/Kinc/Backends/System/Windows/Sources/kinc/backend/video.h b/Kinc/Backends/System/Windows/Sources/kinc/backend/video.h index 9484fe2..de21038 100644 --- a/Kinc/Backends/System/Windows/Sources/kinc/backend/video.h +++ b/Kinc/Backends/System/Windows/Sources/kinc/backend/video.h @@ -22,7 +22,7 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count); -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream); +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream); bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream); diff --git a/Kinc/Backends/System/Windows/Sources/kinc/backend/window.c.h b/Kinc/Backends/System/Windows/Sources/kinc/backend/window.c.h index c46cccc..b22d623 100644 --- a/Kinc/Backends/System/Windows/Sources/kinc/backend/window.c.h +++ b/Kinc/Backends/System/Windows/Sources/kinc/backend/window.c.h @@ -4,7 +4,7 @@ #include -#ifdef KORE_VR +#ifdef KINC_VR #include #endif @@ -34,13 +34,13 @@ LRESULT WINAPI KoreWindowsMessageProcedure(HWND hWnd, UINT msg, WPARAM wParam, L static WindowData windows[MAXIMUM_WINDOWS] = {0}; static int window_counter = 0; -#ifdef KORE_OCULUS +#ifdef KINC_OCULUS const wchar_t *windowClassName = L"ORT"; #else const wchar_t *windowClassName = L"KoreWindow"; #endif -#ifdef KORE_VULKAN +#ifdef KINC_VULKAN #include #include @@ -73,13 +73,13 @@ static void RegisterWindowClass(HINSTANCE hInstance, const wchar_t *className) { 0L, 0L, hInstance, - LoadIcon(hInstance, MAKEINTRESOURCE(107)), + LoadIconW(hInstance, MAKEINTRESOURCEW(107)), LoadCursor(NULL, IDC_ARROW), 0, 0, className, 0}; - RegisterClassEx(&wc); + RegisterClassExW(&wc); } static DWORD getStyle(int features) { @@ -185,7 +185,7 @@ static DWORD getDwExStyle(kinc_window_mode_t mode, int features) { static int createWindow(const wchar_t *title, int x, int y, int width, int height, int bpp, int frequency, int features, kinc_window_mode_t windowMode, int target_display_index) { - HINSTANCE inst = GetModuleHandle(NULL); + HINSTANCE inst = GetModuleHandleW(NULL); if (window_counter == 0) { RegisterWindowClass(inst, windowClassName); @@ -193,7 +193,7 @@ static int createWindow(const wchar_t *title, int x, int y, int width, int heigh int display_index = target_display_index == -1 ? kinc_primary_display() : target_display_index; -#ifdef KORE_VR +#ifdef KINC_VR int dstx = 0; int dsty = 0; @@ -238,11 +238,11 @@ static int createWindow(const wchar_t *title, int x, int y, int width, int heigh break; } - HWND hwnd = CreateWindowEx(getDwExStyle(windowMode, features), windowClassName, title, getDwStyle(windowMode, features), dstx, dsty, dstw, dsth, NULL, NULL, - inst, NULL); + HWND hwnd = CreateWindowExW(getDwExStyle(windowMode, features), windowClassName, title, getDwStyle(windowMode, features), dstx, dsty, dstw, dsth, NULL, + NULL, inst, NULL); #endif - SetCursor(LoadCursor(0, IDC_ARROW)); + SetCursor(LoadCursor(NULL, IDC_ARROW)); DragAcceptFiles(hwnd, true); windows[window_counter].handle = hwnd; @@ -314,8 +314,8 @@ void kinc_window_change_framebuffer(int window, kinc_framebuffer_options_t *fram void kinc_window_change_features(int window_index, int features) { WindowData *win = &windows[window_index]; win->features = features; - SetWindowLong(win->handle, GWL_STYLE, getStyle(features)); - SetWindowLong(win->handle, GWL_EXSTYLE, getExStyle(features)); + SetWindowLongW(win->handle, GWL_STYLE, getStyle(features)); + SetWindowLongW(win->handle, GWL_EXSTYLE, getExStyle(features)); HWND on_top = (features & KINC_WINDOW_FEATURE_ON_TOP) ? HWND_TOPMOST : HWND_NOTOPMOST; SetWindowPos(win->handle, on_top, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); @@ -335,16 +335,16 @@ void kinc_window_change_mode(int window_index, kinc_window_mode_t mode) { break; case KINC_WINDOW_MODE_FULLSCREEN: { kinc_windows_restore_display(display_index); - SetWindowLong(win->handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP); - SetWindowLong(win->handle, GWL_EXSTYLE, WS_EX_APPWINDOW); + SetWindowLongW(win->handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP); + SetWindowLongW(win->handle, GWL_EXSTYLE, WS_EX_APPWINDOW); SetWindowPos(win->handle, NULL, display_mode.x, display_mode.y, display_mode.width, display_mode.height, 0); kinc_window_show(window_index); break; } case KINC_WINDOW_MODE_EXCLUSIVE_FULLSCREEN: kinc_windows_set_display_mode(display_index, win->manualWidth, win->manualHeight, win->bpp, win->frequency); - SetWindowLong(win->handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP); - SetWindowLong(win->handle, GWL_EXSTYLE, WS_EX_APPWINDOW); + SetWindowLongW(win->handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP); + SetWindowLongW(win->handle, GWL_EXSTYLE, WS_EX_APPWINDOW); SetWindowPos(win->handle, NULL, display_mode.x, display_mode.y, display_mode.width, display_mode.height, 0); kinc_window_show(window_index); break; @@ -379,7 +379,7 @@ void kinc_windows_destroy_windows(void) { for (int i = 0; i < MAXIMUM_WINDOWS; ++i) { kinc_window_destroy(i); } - UnregisterClass(windowClassName, GetModuleHandle(NULL)); + UnregisterClassW(windowClassName, GetModuleHandleW(NULL)); } void kinc_window_show(int window_index) { @@ -392,11 +392,6 @@ void kinc_window_hide(int window_index) { UpdateWindow(windows[window_index].handle); } -void kinc_window_set_foreground(int window_index) { - SetForegroundWindow(windows[window_index].handle); - SetFocus(windows[window_index].handle); -} - void kinc_window_set_title(int window_index, const char *title) { wchar_t buffer[1024]; MultiByteToWideChar(CP_UTF8, 0, title, -1, buffer, 1024); @@ -429,7 +424,7 @@ int kinc_window_create(kinc_window_options_t *win, kinc_framebuffer_options_t *f kinc_g4_set_antialiasing_samples(frame->samples_per_pixel); bool vsync = frame->vertical_sync; -#ifdef KORE_OCULUS +#ifdef KINC_OCULUS vsync = false; #endif kinc_g4_internal_init_window(windowId, frame->depth_bits, frame->stencil_bits, vsync); diff --git a/Kinc/Backends/System/Windows/Sources/kinc/backend/windowsunit.c b/Kinc/Backends/System/Windows/Sources/kinc/backend/windowsunit.c index 15e09d2..85c9189 100644 --- a/Kinc/Backends/System/Windows/Sources/kinc/backend/windowsunit.c +++ b/Kinc/Backends/System/Windows/Sources/kinc/backend/windowsunit.c @@ -1,44 +1,47 @@ // Windows 7 #define WINVER 0x0601 +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif #define _WIN32_WINNT 0x0601 #define NOATOM -//#define NOCLIPBOARD +// #define NOCLIPBOARD #define NOCOLOR #define NOCOMM -//#define NOCTLMGR +// #define NOCTLMGR #define NODEFERWINDOWPOS #define NODRAWTEXT -//#define NOGDI +// #define NOGDI #define NOGDICAPMASKS #define NOHELP #define NOICONS #define NOKANJI #define NOKEYSTATES -//#define NOMB +// #define NOMB #define NOMCX #define NOMEMMGR #define NOMENUS #define NOMETAFILE #define NOMINMAX -//#define NOMSG -//#define NONLS +// #define NOMSG +// #define NONLS #define NOOPENFILE #define NOPROFILER #define NORASTEROPS #define NOSCROLL #define NOSERVICE -//#define NOSHOWWINDOW +// #define NOSHOWWINDOW #define NOSOUND -//#define NOSYSCOMMANDS +// #define NOSYSCOMMANDS #define NOSYSMETRICS #define NOTEXTMETRIC -//#define NOUSER -//#define NOVIRTUALKEYCODES +// #define NOUSER +// #define NOVIRTUALKEYCODES #define NOWH -//#define NOWINMESSAGES -//#define NOWINOFFSETS -//#define NOWINSTYLES +// #define NOWINMESSAGES +// #define NOWINOFFSETS +// #define NOWINSTYLES #define WIN32_LEAN_AND_MEAN #include diff --git a/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/display.c b/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/display.c index d2bc2b3..1410952 100644 --- a/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/display.c +++ b/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/display.c @@ -8,9 +8,7 @@ int kinc_count_displays() { return 1; } -void kinc_display_init() { - -} +void kinc_display_init() {} bool kinc_display_available(int display_index) { return display_index == 0; diff --git a/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/mouse.c b/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/mouse.c index 509a49f..482c0cb 100644 --- a/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/mouse.c +++ b/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/mouse.c @@ -1,34 +1,22 @@ #include -void kinc_internal_mouse_lock(int window) { +void kinc_internal_mouse_lock(int window) {} -} - -void kinc_internal_mouse_unlock(void) { - -} +void kinc_internal_mouse_unlock(void) {} bool kinc_mouse_can_lock(void) { return false; } -void kinc_mouse_show() { +void kinc_mouse_show() {} -} +void kinc_mouse_hide() {} -void kinc_mouse_hide() { +void kinc_mouse_set_position(int window, int x, int y) {} -} - -void kinc_mouse_set_position(int window, int x, int y) { - -} - -void kinc_mouse_get_position(int window, int* x, int* y) { +void kinc_mouse_get_position(int window, int *x, int *y) { *x = 0; *y = 0; } -void kinc_mouse_set_cursor(int cursor_index) { - -} +void kinc_mouse_set_cursor(int cursor_index) {} diff --git a/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/system.winrt.cpp b/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/system.winrt.cpp index 4012f96..a8dc4cc 100644 --- a/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/system.winrt.cpp +++ b/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/system.winrt.cpp @@ -11,11 +11,11 @@ #define NOMINMAX #include #ifndef XINPUT -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #define XINPUT 1 #endif -#ifdef KORE_WINDOWSAPP +#ifdef KINC_WINDOWSAPP #define XINPUT !(WINAPI_PARTITION_PHONE_APP) #endif #endif @@ -28,11 +28,11 @@ #include #include -#ifdef KORE_WINDOWSAPP +#ifdef KINC_WINDOWSAPP using namespace ::Microsoft::WRL; using namespace Windows::UI::Core; using namespace Windows::Foundation; -#ifdef KORE_HOLOLENS +#ifdef KINC_HOLOLENS using namespace Windows::Graphics::Holographic; using namespace Windows::Graphics::DirectX::Direct3D11; #endif @@ -160,10 +160,6 @@ bool kinc_internal_handle_messages(void) { // return vec2i(mouseX, mouseY); //} -#ifdef KINC_KONG -extern "C" void kong_init(void); -#endif - #undef CreateWindow int kinc_init(const char *name, int width, int height, struct kinc_window_options *win, struct kinc_framebuffer_options *frame) { @@ -184,10 +180,6 @@ int kinc_init(const char *name, int width, int height, struct kinc_window_option kinc_g4_internal_init(); kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true); -#ifdef KINC_KONG - kong_init(); -#endif - return 0; } @@ -245,7 +237,7 @@ void Win8Application::SetWindow(CoreWindow ^ window) { ref new Windows::Foundation::TypedEventHandler(this, &Win8Application::OnKeyUp); // m_renderer->Initialize(CoreWindow::GetForCurrentThread()); -#ifdef KORE_HOLOLENS +#ifdef KINC_HOLOLENS // Create holographics space - needs to be created before window is activated holographicFrameController = std::make_unique(window); diff --git a/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/video.c b/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/video.c index e1a5111..bedd154 100644 --- a/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/video.c +++ b/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/video.c @@ -46,8 +46,10 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count) {} -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream) { - return 0.0f; +static float samples[2] = {0}; + +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream) { + return samples; } bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream) { diff --git a/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/video.h b/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/video.h index 0acd202..146a7d4 100644 --- a/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/video.h +++ b/Kinc/Backends/System/WindowsApp/Sources/kinc/backend/video.h @@ -18,7 +18,7 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count); -float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream); +float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream); bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream); diff --git a/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.h b/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.h index 1e468b7..bb5f70a 100644 --- a/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.h +++ b/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.h @@ -1,13 +1,13 @@ #import #import -#ifdef KORE_METAL +#ifdef KINC_METAL #import #import #else #import #import #endif -#ifndef KORE_TVOS +#ifndef KINC_TVOS #import #endif @@ -15,7 +15,7 @@ struct kinc_g5_render_target; @interface GLView : UIView { @private -#ifdef KORE_METAL +#ifdef KINC_METAL id device; id commandQueue; id commandBuffer; @@ -29,7 +29,7 @@ struct kinc_g5_render_target; GLuint defaultFramebuffer, colorRenderbuffer, depthStencilRenderbuffer; #endif -#ifndef KORE_TVOS +#ifndef KINC_TVOS CMMotionManager *motionManager; #endif bool hasAccelerometer; @@ -40,7 +40,7 @@ struct kinc_g5_render_target; - (void)end; - (void)showKeyboard; - (void)hideKeyboard; -#ifdef KORE_METAL +#ifdef KINC_METAL - (CAMetalLayer *)metalLayer; - (id)metalDevice; - (id)metalLibrary; diff --git a/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.m.h b/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.m.h index ffd13c8..3774619 100644 --- a/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.m.h +++ b/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.m.h @@ -10,7 +10,7 @@ #include #include -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL #include #endif @@ -63,7 +63,7 @@ int kinc_window_height(int window) { @implementation GLView -#ifdef KORE_METAL +#ifdef KINC_METAL + (Class)layerClass { return [CAMetalLayer class]; } @@ -73,13 +73,11 @@ int kinc_window_height(int window) { } #endif -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL extern int kinc_ios_gl_framebuffer; #endif -#ifdef KORE_METAL -void initMetalCompute(id device, id commandQueue); - +#ifdef KINC_METAL - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:(CGRect)frame]; self.contentScaleFactor = [UIScreen mainScreen].scale; @@ -92,7 +90,6 @@ void initMetalCompute(id device, id commandQueue); device = MTLCreateSystemDefaultDevice(); commandQueue = [device newCommandQueue]; library = [device newDefaultLibrary]; - initMetalCompute(device, commandQueue); CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer; @@ -144,7 +141,7 @@ void initMetalCompute(id device, id commandQueue); // Start acceletometer hasAccelerometer = false; -#ifndef KORE_TVOS +#ifndef KINC_TVOS motionManager = [[CMMotionManager alloc] init]; if ([motionManager isAccelerometerAvailable]) { motionManager.accelerometerUpdateInterval = 0.033; @@ -153,7 +150,7 @@ void initMetalCompute(id device, id commandQueue); } #endif -#ifndef KORE_TVOS +#ifndef KINC_TVOS [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onKeyboardHide:) name:UIKeyboardWillHideNotification object:nil]; #endif @@ -161,7 +158,7 @@ void initMetalCompute(id device, id commandQueue); } #endif -#ifdef KORE_METAL +#ifdef KINC_METAL - (void)begin { } #else @@ -170,7 +167,7 @@ void initMetalCompute(id device, id commandQueue); // glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer); // glViewport(0, 0, backingWidth, backingHeight); -#ifndef KORE_TVOS +#ifndef KINC_TVOS // Accelerometer updates if (hasAccelerometer) { @@ -189,7 +186,7 @@ void initMetalCompute(id device, id commandQueue); } #endif -#ifdef KORE_METAL +#ifdef KINC_METAL - (void)end { } #else @@ -201,7 +198,7 @@ void initMetalCompute(id device, id commandQueue); void kinc_internal_call_resize_callback(int window, int width, int height); -#ifdef KORE_METAL +#ifdef KINC_METAL - (void)layoutSubviews { backingWidth = self.frame.size.width * self.contentScaleFactor; backingHeight = self.frame.size.height * self.contentScaleFactor; @@ -232,7 +229,7 @@ void kinc_internal_call_resize_callback(int window, int width, int height); } #endif -#ifdef KORE_METAL +#ifdef KINC_METAL - (void)dealloc { } #else @@ -272,7 +269,12 @@ void kinc_internal_call_resize_callback(int window, int width, int height); float x = point.x * self.contentScaleFactor; float y = point.y * self.contentScaleFactor; if (index == 0) { - kinc_internal_mouse_trigger_press(0, event.buttonMask == UIEventButtonMaskSecondary ? 1 : 0, x, y); + if (@available(iOS 13.4, *)) { + kinc_internal_mouse_trigger_press(0, event.buttonMask == UIEventButtonMaskSecondary ? 1 : 0, x, y); + } + else { + kinc_internal_mouse_trigger_press(0, 0, x, y); + } } kinc_internal_surface_trigger_touch_start(index, x, y); @@ -317,7 +319,12 @@ void kinc_internal_call_resize_callback(int window, int width, int height); float x = point.x * self.contentScaleFactor; float y = point.y * self.contentScaleFactor; if (index == 0) { - kinc_internal_mouse_trigger_release(0, event.buttonMask == UIEventButtonMaskSecondary ? 1 : 0, x, y); + if (@available(iOS 13.4, *)) { + kinc_internal_mouse_trigger_release(0, event.buttonMask == UIEventButtonMaskSecondary ? 1 : 0, x, y); + } + else { + kinc_internal_mouse_trigger_release(0, 0, x, y); + } } kinc_internal_surface_trigger_touch_end(index, x, y); @@ -336,7 +343,12 @@ void kinc_internal_call_resize_callback(int window, int width, int height); float x = point.x * self.contentScaleFactor; float y = point.y * self.contentScaleFactor; if (index == 0) { - kinc_internal_mouse_trigger_release(0, event.buttonMask == UIEventButtonMaskSecondary ? 1 : 0, x, y); + if (@available(iOS 13.4, *)) { + kinc_internal_mouse_trigger_release(0, event.buttonMask == UIEventButtonMaskSecondary ? 1 : 0, x, y); + } + else { + kinc_internal_mouse_trigger_release(0, 0, x, y); + } } kinc_internal_surface_trigger_touch_end(index, x, y); @@ -432,7 +444,7 @@ static bool shiftDown = false; kinc_keyboard_hide(); } -#ifdef KORE_METAL +#ifdef KINC_METAL - (CAMetalLayer *)metalLayer { return (CAMetalLayer *)self.layer; } diff --git a/Kinc/Backends/System/iOS/Sources/kinc/backend/GLViewController.h b/Kinc/Backends/System/iOS/Sources/kinc/backend/GLViewController.h index 4244cc9..443bc9f 100644 --- a/Kinc/Backends/System/iOS/Sources/kinc/backend/GLViewController.h +++ b/Kinc/Backends/System/iOS/Sources/kinc/backend/GLViewController.h @@ -2,7 +2,7 @@ #import #import #import -#ifndef KORE_TVOS +#ifndef KINC_TVOS #import #endif diff --git a/Kinc/Backends/System/iOS/Sources/kinc/backend/GLViewController.m.h b/Kinc/Backends/System/iOS/Sources/kinc/backend/GLViewController.m.h index 8bdee73..f476f96 100644 --- a/Kinc/Backends/System/iOS/Sources/kinc/backend/GLViewController.m.h +++ b/Kinc/Backends/System/iOS/Sources/kinc/backend/GLViewController.m.h @@ -13,7 +13,7 @@ static GLView *glView; static bool visible; void beginGL(void) { -#ifdef KORE_METAL +#ifdef KINC_METAL if (!visible) { return; } @@ -22,7 +22,7 @@ void beginGL(void) { } void endGL(void) { -#ifdef KORE_METAL +#ifdef KINC_METAL if (!visible) { return; } @@ -38,7 +38,7 @@ void hideKeyboard(void) { [glView hideKeyboard]; } -#ifdef KORE_METAL +#ifdef KINC_METAL CAMetalLayer *getMetalLayer(void) { return [glView metalLayer]; diff --git a/Kinc/Backends/System/iOS/Sources/kinc/backend/KoreAppDelegate.m.h b/Kinc/Backends/System/iOS/Sources/kinc/backend/KoreAppDelegate.m.h index b003389..d209488 100644 --- a/Kinc/Backends/System/iOS/Sources/kinc/backend/KoreAppDelegate.m.h +++ b/Kinc/Backends/System/iOS/Sources/kinc/backend/KoreAppDelegate.m.h @@ -12,23 +12,13 @@ static UIWindow *window; static GLViewController *glViewController; void loadURL(const char *url) { - [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]]; + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]] options:@{} completionHandler:nil]; } - (void)mainLoop { - // NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - // try { @autoreleasepool { kickstart(0, NULL); } - //} - // catch (Kt::Exception& ex) { - // printf("Exception\n"); - // printf("%s", ex.what()); - //} - - //[pool drain]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { @@ -52,7 +42,7 @@ void loadURL(const char *url) { // glView = [[GLView alloc] initWithFrame:CGRectMake(0, 0, Kore::max(screenBounds.size.width, screenBounds.size.height), Kore::max(screenBounds.size.width, // screenBounds.size.height))]; glViewController = [[GLViewController alloc] init]; -#ifndef KORE_TVOS +#ifndef KINC_TVOS glViewController.view.multipleTouchEnabled = YES; #endif // glViewController.view = glView; @@ -66,48 +56,8 @@ void loadURL(const char *url) { return YES; } -#ifndef KORE_TVOS -// static Kore::Orientation convertOrientation(UIDeviceOrientation orientation) { -// switch (orientation) { -// case UIDeviceOrientationLandscapeLeft: -// return Kore::OrientationLandscapeRight; -// case UIDeviceOrientationLandscapeRight: -// return Kore::OrientationLandscapeLeft; -// case UIDeviceOrientationPortrait: -// return Kore::OrientationPortrait; -// case UIDeviceOrientationPortraitUpsideDown: -// return Kore::OrientationPortraitUpsideDown; -// default: -// return Kore::OrientationUnknown; -// } -//} - -// static UIInterfaceOrientation convertAppleOrientation(UIDeviceOrientation orientation, UIInterfaceOrientation lastOrientation) { -// switch (orientation) { -// case UIDeviceOrientationLandscapeLeft: -// return UIInterfaceOrientationLandscapeRight; -// case UIDeviceOrientationLandscapeRight: -// return UIInterfaceOrientationLandscapeLeft; -// case UIDeviceOrientationPortrait: -// return UIInterfaceOrientationPortrait; -// case UIDeviceOrientationPortraitUpsideDown: -// return UIInterfaceOrientationPortraitUpsideDown; -// default: -// return lastOrientation; -// } -//} -#endif - void KoreUpdateKeyboard(void); -/* -- (void)didRotate:(NSNotification*)notification { - if (Kore::Application::the() != nullptr && Kore::Application::the()->orientationCallback != nullptr) -Kore::Application::the()->orientationCallback(convertOrientation([[UIDevice currentDevice] orientation])); - [UIApplication sharedApplication].statusBarOrientation = convertAppleOrientation([[UIDevice currentDevice] orientation], [UIApplication -sharedApplication].statusBarOrientation); - KoreUpdateKeyboard(); -} -*/ + - (void)applicationWillEnterForeground:(UIApplication *)application { [glViewController setVisible:YES]; kinc_internal_foreground_callback(); diff --git a/Kinc/Backends/System/iOS/Sources/kinc/backend/audio.m.h b/Kinc/Backends/System/iOS/Sources/kinc/backend/audio.m.h index 40a4392..ab1a03a 100644 --- a/Kinc/Backends/System/iOS/Sources/kinc/backend/audio.m.h +++ b/Kinc/Backends/System/iOS/Sources/kinc/backend/audio.m.h @@ -32,46 +32,65 @@ static AudioComponentInstance audioUnit; static bool isFloat = false; static bool isInterleaved = true; -static void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = NULL; -static void (*a2_sample_rate_callback)(void) = NULL; static kinc_a2_buffer_t a2_buffer; -static void copySample(void *buffer) { - float value = *(float *)&a2_buffer.data[a2_buffer.read_location]; - a2_buffer.read_location += 4; - if (a2_buffer.read_location >= a2_buffer.data_size) +static void copySample(void *buffer, void *secondary_buffer) { + float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location]; + float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location]; + a2_buffer.read_location += 1; + if (a2_buffer.read_location >= a2_buffer.data_size) { a2_buffer.read_location = 0; + } if (video != NULL) { - value += kinc_internal_video_sound_stream_next_sample(video); - value = kinc_max(kinc_min(value, 1.0f), -1.0f); + float *frame = kinc_internal_video_sound_stream_next_frame(video); + left_value += frame[0]; + left_value = kinc_max(kinc_min(left_value, 1.0f), -1.0f); + right_value += frame[1]; + right_value = kinc_max(kinc_min(right_value, 1.0f), -1.0f); if (kinc_internal_video_sound_stream_ended(video)) { video = NULL; } } - if (isFloat) - *(float *)buffer = value; - else - *(int16_t *)buffer = (int16_t)(value * 32767); + if (secondary_buffer == NULL) { + if (isFloat) { + ((float *)buffer)[0] = left_value; + ((float *)buffer)[1] = right_value; + } + else { + ((int16_t *)buffer)[0] = (int16_t)(left_value * 32767); + ((int16_t *)buffer)[1] = (int16_t)(right_value * 32767); + } + } + else { + if (isFloat) { + *(float *)buffer = left_value; + *(float *)secondary_buffer = right_value; + } + else { + *(int16_t *)buffer = (int16_t)(left_value * 32767); + *(int16_t *)secondary_buffer = (int16_t)(right_value * 32767); + } + } } static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *outOutputData) { - a2_callback(&a2_buffer, inNumberFrames * 2); + kinc_a2_internal_callback(&a2_buffer, inNumberFrames); if (isInterleaved) { if (isFloat) { - float *out = (float *)outOutputData->mBuffers[0].mData; + float *output = (float *)outOutputData->mBuffers[0].mData; for (int i = 0; i < inNumberFrames; ++i) { - copySample(out++); // left - copySample(out++); // right + copySample(output, NULL); + output += 2; } } else { - int16_t *out = (int16_t *)outOutputData->mBuffers[0].mData; + int16_t *output = (int16_t *)outOutputData->mBuffers[0].mData; for (int i = 0; i < inNumberFrames; ++i) { - copySample(out++); // left - copySample(out++); // right + copySample(output, NULL); + output += 2; } } } @@ -80,30 +99,30 @@ static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioAction float *out1 = (float *)outOutputData->mBuffers[0].mData; float *out2 = (float *)outOutputData->mBuffers[1].mData; for (int i = 0; i < inNumberFrames; ++i) { - copySample(out1++); // left - copySample(out2++); // right + copySample(out1++, out2++); } } else { int16_t *out1 = (int16_t *)outOutputData->mBuffers[0].mData; int16_t *out2 = (int16_t *)outOutputData->mBuffers[1].mData; for (int i = 0; i < inNumberFrames; ++i) { - copySample(out1++); // left - copySample(out2++); // right + copySample(out1++, out2++); } } } return noErr; } +static uint32_t samples_per_second = 44100; + static void sampleRateListener(void *inRefCon, AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement) { Float64 sampleRate; UInt32 size = sizeof(sampleRate); affirm(AudioUnitGetProperty(inUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Output, 0, &sampleRate, &size)); - kinc_a2_samples_per_second = (int)sampleRate; - if (a2_sample_rate_callback != NULL) { - a2_sample_rate_callback(); + if (samples_per_second != (uint32_t)sampleRate) { + samples_per_second = (uint32_t)sampleRate; + kinc_a2_internal_sample_rate_callback(); } } @@ -114,12 +133,15 @@ void kinc_a2_init(void) { return; } + kinc_a2_internal_init(); initialized = true; a2_buffer.read_location = 0; a2_buffer.write_location = 0; a2_buffer.data_size = 128 * 1024; - a2_buffer.data = (uint8_t *)malloc(a2_buffer.data_size); + a2_buffer.channel_count = 2; + a2_buffer.channels[0] = (float *)malloc(a2_buffer.data_size * sizeof(float)); + a2_buffer.channels[1] = (float *)malloc(a2_buffer.data_size * sizeof(float)); initialized = false; @@ -170,10 +192,10 @@ void kinc_a2_init(void) { printf("mBytesPerFrame = %d\n", (unsigned int)deviceFormat.mBytesPerFrame); printf("mBitsPerChannel = %d\n", (unsigned int)deviceFormat.mBitsPerChannel); - kinc_a2_samples_per_second = deviceFormat.mSampleRate; - a2_buffer.format.samples_per_second = kinc_a2_samples_per_second; - a2_buffer.format.bits_per_sample = 32; - a2_buffer.format.channels = 2; + if (samples_per_second != (uint32_t)deviceFormat.mSampleRate) { + samples_per_second = (uint32_t)deviceFormat.mSampleRate; + kinc_a2_internal_sample_rate_callback(); + } AURenderCallbackStruct callbackStruct; callbackStruct.inputProc = renderInput; @@ -196,10 +218,6 @@ void kinc_a2_shutdown(void) { soundPlaying = false; } -void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) { - a2_callback = kinc_a2_audio_callback; -} - -void kinc_a2_set_sample_rate_callback(void (*kinc_a2_sample_rate_callback)(void)) { - a2_sample_rate_callback = kinc_a2_sample_rate_callback; +uint32_t kinc_a2_samples_per_second(void) { + return samples_per_second; } diff --git a/Kinc/Backends/System/iOS/Sources/kinc/backend/system.m.h b/Kinc/Backends/System/iOS/Sources/kinc/backend/system.m.h index 4da9571..c675cea 100644 --- a/Kinc/Backends/System/iOS/Sources/kinc/backend/system.m.h +++ b/Kinc/Backends/System/iOS/Sources/kinc/backend/system.m.h @@ -82,10 +82,6 @@ void KoreUpdateKeyboard(void) { } } -#ifdef KINC_KONG -void kong_init(void); -#endif - void kinc_internal_shutdown(void) {} int kinc_init(const char *name, int width, int height, struct kinc_window_options *win, struct kinc_framebuffer_options *frame) { @@ -101,10 +97,7 @@ int kinc_init(const char *name, int width, int height, struct kinc_window_option } kinc_g4_internal_init(); kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true); - -#ifdef KINC_KONG - kong_init(); -#endif + return 0; } diff --git a/Kinc/Backends/System/iOS/Sources/kinc/backend/window.c.h b/Kinc/Backends/System/iOS/Sources/kinc/backend/window.c.h index e42a899..f564d95 100644 --- a/Kinc/Backends/System/iOS/Sources/kinc/backend/window.c.h +++ b/Kinc/Backends/System/iOS/Sources/kinc/backend/window.c.h @@ -27,7 +27,7 @@ void kinc_window_change_framebuffer(int window, struct kinc_framebuffer_options kinc_internal_change_framebuffer(0, frame); } -#ifdef KORE_METAL +#ifdef KINC_METAL void kinc_internal_change_framebuffer(int window, struct kinc_framebuffer_options *frame) {} #endif diff --git a/Kinc/Backends/System/macOS/Sources/kinc/backend/BasicOpenGLView.h b/Kinc/Backends/System/macOS/Sources/kinc/backend/BasicOpenGLView.h index d0ebd79..741a116 100644 --- a/Kinc/Backends/System/macOS/Sources/kinc/backend/BasicOpenGLView.h +++ b/Kinc/Backends/System/macOS/Sources/kinc/backend/BasicOpenGLView.h @@ -1,4 +1,4 @@ -#ifdef KORE_METAL +#ifdef KINC_METAL #import #else #import @@ -9,7 +9,7 @@ #import #endif -#ifdef KORE_METAL +#ifdef KINC_METAL struct kinc_g5_render_target; @@ -32,7 +32,7 @@ struct kinc_g5_render_target; #endif -#ifdef KORE_METAL +#ifdef KINC_METAL - (CAMetalLayer *)metalLayer; - (id)metalDevice; - (id)metalLibrary; diff --git a/Kinc/Backends/System/macOS/Sources/kinc/backend/BasicOpenGLView.m.h b/Kinc/Backends/System/macOS/Sources/kinc/backend/BasicOpenGLView.m.h index bb73d6b..42ce735 100644 --- a/Kinc/Backends/System/macOS/Sources/kinc/backend/BasicOpenGLView.m.h +++ b/Kinc/Backends/System/macOS/Sources/kinc/backend/BasicOpenGLView.m.h @@ -5,7 +5,7 @@ #include #include -#ifdef KORE_METAL +#ifdef KINC_METAL #include #endif @@ -16,7 +16,7 @@ static bool ctrl = false; static bool alt = false; static bool cmd = false; -#ifndef KORE_METAL +#ifndef KINC_METAL + (NSOpenGLPixelFormat *)basicPixelFormat { // TODO (DK) pass via argument in int aa = 1; // Kore::Application::the()->antialiasing(); @@ -62,19 +62,19 @@ static bool cmd = false; cmd = false; } - if ([theEvent modifierFlags] & NSShiftKeyMask) { + if ([theEvent modifierFlags] & NSEventModifierFlagShift) { kinc_internal_keyboard_trigger_key_down(KINC_KEY_SHIFT); shift = true; } - if ([theEvent modifierFlags] & NSControlKeyMask) { + if ([theEvent modifierFlags] & NSEventModifierFlagControl) { kinc_internal_keyboard_trigger_key_down(KINC_KEY_CONTROL); ctrl = true; } - if ([theEvent modifierFlags] & NSAlternateKeyMask) { + if ([theEvent modifierFlags] & NSEventModifierFlagOption) { kinc_internal_keyboard_trigger_key_down(KINC_KEY_ALT); alt = true; } - if ([theEvent modifierFlags] & NSCommandKeyMask) { + if ([theEvent modifierFlags] & NSEventModifierFlagCommand) { kinc_internal_keyboard_trigger_key_down(KINC_KEY_META); cmd = true; } @@ -144,15 +144,18 @@ static bool cmd = false; case NSNewlineCharacter: case NSCarriageReturnCharacter: kinc_internal_keyboard_trigger_key_down(KINC_KEY_RETURN); + kinc_internal_keyboard_trigger_key_press('\n'); break; case 0x7f: kinc_internal_keyboard_trigger_key_down(KINC_KEY_BACKSPACE); + kinc_internal_keyboard_trigger_key_press('\x08'); break; case 9: kinc_internal_keyboard_trigger_key_down(KINC_KEY_TAB); + kinc_internal_keyboard_trigger_key_press('\t'); break; default: - if (ch == 'x' && [theEvent modifierFlags] & NSCommandKeyMask) { + if (ch == 'x' && [theEvent modifierFlags] & NSEventModifierFlagCommand) { char *text = kinc_internal_cut_callback(); if (text != NULL) { NSPasteboard *board = [NSPasteboard generalPasteboard]; @@ -160,7 +163,7 @@ static bool cmd = false; [board setString:[NSString stringWithUTF8String:text] forType:NSStringPboardType]; } } - if (ch == 'c' && [theEvent modifierFlags] & NSCommandKeyMask) { + if (ch == 'c' && [theEvent modifierFlags] & NSEventModifierFlagCommand) { char *text = kinc_internal_copy_callback(); if (text != NULL) { NSPasteboard *board = [NSPasteboard generalPasteboard]; @@ -168,7 +171,7 @@ static bool cmd = false; [board setString:[NSString stringWithUTF8String:text] forType:NSStringPboardType]; } } - if (ch == 'v' && [theEvent modifierFlags] & NSCommandKeyMask) { + if (ch == 'v' && [theEvent modifierFlags] & NSEventModifierFlagCommand) { NSPasteboard *board = [NSPasteboard generalPasteboard]; NSString *data = [board stringForType:NSStringPboardType]; if (data != nil) { @@ -292,7 +295,7 @@ static bool controlKeyMouseButton = false; - (void)mouseDown:(NSEvent *)theEvent { // TODO (DK) map [theEvent window] to window id instead of 0 - if ([theEvent modifierFlags] & NSControlKeyMask) { + if ([theEvent modifierFlags] & NSEventModifierFlagControl) { controlKeyMouseButton = true; kinc_internal_mouse_trigger_press(0, 1, getMouseX(theEvent), getMouseY(theEvent)); } @@ -301,7 +304,7 @@ static bool controlKeyMouseButton = false; kinc_internal_mouse_trigger_press(0, 0, getMouseX(theEvent), getMouseY(theEvent)); } - if ([theEvent subtype] == NSTabletPointEventSubtype) { + if ([theEvent subtype] == NSEventSubtypeTabletPoint) { kinc_internal_pen_trigger_press(0, getMouseX(theEvent), getMouseY(theEvent), theEvent.pressure); } } @@ -316,7 +319,7 @@ static bool controlKeyMouseButton = false; } controlKeyMouseButton = false; - if ([theEvent subtype] == NSTabletPointEventSubtype) { + if ([theEvent subtype] == NSEventSubtypeTabletPoint) { kinc_internal_pen_trigger_release(0, getMouseX(theEvent), getMouseY(theEvent), theEvent.pressure); } } @@ -330,7 +333,7 @@ static bool controlKeyMouseButton = false; // TODO (DK) map [theEvent window] to window id instead of 0 kinc_internal_mouse_trigger_move(0, getMouseX(theEvent), getMouseY(theEvent)); - if ([theEvent subtype] == NSTabletPointEventSubtype) { + if ([theEvent subtype] == NSEventSubtypeTabletPoint) { kinc_internal_pen_trigger_move(0, getMouseX(theEvent), getMouseY(theEvent), theEvent.pressure); } } @@ -390,7 +393,7 @@ static bool controlKeyMouseButton = false; return YES; } -#ifndef KORE_METAL +#ifndef KINC_METAL - (void)prepareOpenGL { const GLint swapInt = 1; [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; @@ -399,12 +402,12 @@ static bool controlKeyMouseButton = false; #endif - (void)update { // window resizes, moves and display changes (resize, depth and display config change) -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL [super update]; #endif } -#ifndef KORE_METAL +#ifndef KINC_METAL - (id)initWithFrame:(NSRect)frameRect { NSOpenGLPixelFormat *pf = [BasicOpenGLView basicPixelFormat]; self = [super initWithFrame:frameRect pixelFormat:pf]; @@ -416,7 +419,7 @@ static bool controlKeyMouseButton = false; } #else -void initMetalCompute(id device, id commandBuffer); +static CAMetalLayer *metalLayer = NULL; - (id)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; @@ -424,9 +427,8 @@ void initMetalCompute(id device, id commandBuffer); device = MTLCreateSystemDefaultDevice(); commandQueue = [device newCommandQueue]; library = [device newDefaultLibrary]; - initMetalCompute(device, commandQueue); - CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer; + metalLayer = (CAMetalLayer *)self.layer; metalLayer.device = device; metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm; @@ -456,7 +458,7 @@ void initMetalCompute(id device, id commandBuffer); [self setFrameSize:size]; } -#ifdef KORE_METAL +#ifdef KINC_METAL - (CAMetalLayer *)metalLayer { return (CAMetalLayer *)self.layer; } diff --git a/Kinc/Backends/System/macOS/Sources/kinc/backend/audio.c.h b/Kinc/Backends/System/macOS/Sources/kinc/backend/audio.c.h index e70889b..d592629 100644 --- a/Kinc/Backends/System/macOS/Sources/kinc/backend/audio.c.h +++ b/Kinc/Backends/System/macOS/Sources/kinc/backend/audio.c.h @@ -17,15 +17,13 @@ void macStopVideoSoundStream(void) { video = NULL; } -// const int samplesPerSecond = 44100; - static void affirm(OSStatus err) { if (err != kAudioHardwareNoError) { kinc_log(KINC_LOG_LEVEL_ERROR, "Error: %i\n", err); } } -static bool initialized; +static bool initialized = false; static bool soundPlaying; static AudioDeviceID device; static UInt32 deviceBufferSize; @@ -35,50 +33,56 @@ static AudioObjectPropertyAddress address; static AudioDeviceIOProcID theIOProcID = NULL; -static void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = NULL; -static void (*a2_sample_rate_callback)(void) = NULL; static kinc_a2_buffer_t a2_buffer; +static uint32_t samples_per_second = 44100; + +uint32_t kinc_a2_samples_per_second(void) { + return samples_per_second; +} + static void copySample(void *buffer) { - float value = *(float *)&a2_buffer.data[a2_buffer.read_location]; - a2_buffer.read_location += 4; - if (a2_buffer.read_location >= a2_buffer.data_size) + float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location]; + float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location]; + a2_buffer.read_location += 1; + if (a2_buffer.read_location >= a2_buffer.data_size) { a2_buffer.read_location = 0; - *(float *)buffer = value; + } + ((float *)buffer)[0] = left_value; + ((float *)buffer)[1] = right_value; } static OSStatus appIOProc(AudioDeviceID inDevice, const AudioTimeStamp *inNow, const AudioBufferList *inInputData, const AudioTimeStamp *inInputTime, AudioBufferList *outOutputData, const AudioTimeStamp *inOutputTime, void *userdata) { affirm(AudioObjectGetPropertyData(device, &address, 0, NULL, &size, &deviceFormat)); - if (kinc_a2_samples_per_second != (int)deviceFormat.mSampleRate) { - kinc_a2_samples_per_second = (int)deviceFormat.mSampleRate; - if (a2_sample_rate_callback != NULL) { - a2_sample_rate_callback(); - } + if (samples_per_second != (int)deviceFormat.mSampleRate) { + samples_per_second = (int)deviceFormat.mSampleRate; + kinc_a2_internal_sample_rate_callback(); } - int numSamples = deviceBufferSize / deviceFormat.mBytesPerFrame; - a2_callback(&a2_buffer, numSamples * 2); - float *out = (float *)outOutputData->mBuffers[0].mData; - for (int i = 0; i < numSamples; ++i) { - copySample(out++); // left - copySample(out++); // right + int num_frames = deviceBufferSize / deviceFormat.mBytesPerFrame; + kinc_a2_internal_callback(&a2_buffer, num_frames); + float *output = (float *)outOutputData->mBuffers[0].mData; + for (int i = 0; i < num_frames; ++i) { + copySample(output); + output += 2; } return kAudioHardwareNoError; } -static bool initialized = false; - void kinc_a2_init(void) { if (initialized) { return; } + kinc_a2_internal_init(); initialized = true; a2_buffer.read_location = 0; a2_buffer.write_location = 0; a2_buffer.data_size = 128 * 1024; - a2_buffer.data = (uint8_t *)malloc(a2_buffer.data_size); + a2_buffer.channel_count = 2; + a2_buffer.channels[0] = (float *)malloc(a2_buffer.data_size * sizeof(float)); + a2_buffer.channels[1] = (float *)malloc(a2_buffer.data_size * sizeof(float)); device = kAudioDeviceUnknown; @@ -113,10 +117,10 @@ void kinc_a2_init(void) { return; } - kinc_a2_samples_per_second = (int)deviceFormat.mSampleRate; - a2_buffer.format.samples_per_second = kinc_a2_samples_per_second; - a2_buffer.format.bits_per_sample = 32; - a2_buffer.format.channels = 2; + if (samples_per_second != (int)deviceFormat.mSampleRate) { + samples_per_second = (int)deviceFormat.mSampleRate; + kinc_a2_internal_sample_rate_callback(); + } initialized = true; @@ -150,11 +154,3 @@ void kinc_a2_shutdown(void) { soundPlaying = false; } - -void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) { - a2_callback = kinc_a2_audio_callback; -} - -void kinc_a2_set_sample_rate_callback(void (*kinc_a2_sample_rate_callback)(void)) { - a2_sample_rate_callback = kinc_a2_sample_rate_callback; -} diff --git a/Kinc/Backends/System/macOS/Sources/kinc/backend/system.m.h b/Kinc/Backends/System/macOS/Sources/kinc/backend/system.m.h index 783169e..f30d75b 100644 --- a/Kinc/Backends/System/macOS/Sources/kinc/backend/system.m.h +++ b/Kinc/Backends/System/macOS/Sources/kinc/backend/system.m.h @@ -13,17 +13,21 @@ #include +#ifdef __cplusplus +extern "C" { +#endif bool withAutoreleasepool(bool (*f)(void)) { @autoreleasepool { return f(); } } -extern const char *macgetresourcepath(void); - const char *macgetresourcepath(void) { return [[[NSBundle mainBundle] resourcePath] cStringUsingEncoding:NSUTF8StringEncoding]; } +#ifdef __cplusplus +} +#endif @interface KincApplication : NSApplication { } @@ -56,7 +60,7 @@ static struct HIDManager *hidManager; } };*/ -#ifdef KORE_METAL +#ifdef KINC_METAL CAMetalLayer *getMetalLayer(void) { return [view metalLayer]; } @@ -75,7 +79,7 @@ id getMetalQueue(void) { #endif bool kinc_internal_handle_messages(void) { - NSEvent *event = [myapp nextEventMatchingMask:NSAnyEventMask + NSEvent *event = [myapp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; // distantPast: non-blocking @@ -91,11 +95,17 @@ bool kinc_internal_handle_messages(void) { return true; } +#ifdef __cplusplus +extern "C" { +#endif void swapBuffersMac(int windowId) { -#ifndef KORE_METAL +#ifndef KINC_METAL [windows[windowId].view switchBuffers]; #endif } +#ifdef __cplusplus +} +#endif static int createWindow(kinc_window_options_t *options) { int width = options->width / [[NSScreen mainScreen] backingScaleFactor]; @@ -174,10 +184,6 @@ static void addMenubar(void) { [NSApp setMainMenu:menubar]; } -#ifdef KINC_KONG -void kong_init(void); -#endif - int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) { @autoreleasepool { myapp = [KincApplication sharedApplication]; @@ -212,11 +218,7 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi int windowId = createWindow(win); kinc_g4_internal_init(); kinc_g4_internal_init_window(windowId, frame->depth_bits, frame->stencil_bits, true); - -#ifdef KINC_KONG - kong_init(); -#endif - + return 0; } diff --git a/Kinc/Backends/System/macOS/Sources/kinc/backend/window.c.h b/Kinc/Backends/System/macOS/Sources/kinc/backend/window.c.h index 75b7221..e4b0de2 100644 --- a/Kinc/Backends/System/macOS/Sources/kinc/backend/window.c.h +++ b/Kinc/Backends/System/macOS/Sources/kinc/backend/window.c.h @@ -14,14 +14,26 @@ void kinc_window_resize(int window, int width, int height) {} void kinc_window_move(int window, int x, int y) {} +#ifdef __cplusplus +extern "C" { +#endif void kinc_internal_change_framebuffer(int window, struct kinc_framebuffer_options *frame); +#ifdef __cplusplus +} +#endif void kinc_window_change_framebuffer(int window, struct kinc_framebuffer_options *frame) { kinc_internal_change_framebuffer(0, frame); } -#ifdef KORE_METAL +#ifdef KINC_METAL +#ifdef __cplusplus +extern "C" { +#endif void kinc_internal_change_framebuffer(int window, struct kinc_framebuffer_options *frame) {} +#ifdef __cplusplus +} +#endif #endif void kinc_window_change_features(int window, int features) {} diff --git a/Kinc/Doxyfile b/Kinc/Doxyfile index 7c6b140..0941666 100644 --- a/Kinc/Doxyfile +++ b/Kinc/Doxyfile @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = "Kinc" +PROJECT_NAME = "Kore" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version diff --git a/Kinc/KongShaders/g1.kong b/Kinc/KongShaders/g1.kong deleted file mode 100644 index 88fb2ec..0000000 --- a/Kinc/KongShaders/g1.kong +++ /dev/null @@ -1,34 +0,0 @@ -struct kinc_g1_vertex_in { - pos: float3; - tex: float2; -} - -struct kinc_g1_vertex_out { - pos: float4; - tex: float2; -} - -fun kinc_g1_vertex(input: kinc_g1_vertex_in): kinc_g1_vertex_out { - var output: kinc_g1_vertex_out; - - output.pos.xy = input.pos.xy; - output.pos.z = 0.5; - output.pos.w = 1.0; - - output.tex = input.tex; - - return output; -} - -const kinc_g1_texture: tex2d; -const kinc_g1_sampler: sampler; - -fun kinc_g1_fragment(input: kinc_g1_vertex_out): float4 { - return sample(kinc_g1_texture, kinc_g1_sampler, input.tex); -} - -#[pipe] -struct kinc_g1_pipeline { - vertex = kinc_g1_vertex; - fragment = kinc_g1_fragment; -} diff --git a/Kinc/GLSLShaders/g1.frag.glsl b/Kinc/Shaders/g1.frag.glsl similarity index 100% rename from Kinc/GLSLShaders/g1.frag.glsl rename to Kinc/Shaders/g1.frag.glsl diff --git a/Kinc/GLSLShaders/g1.vert.glsl b/Kinc/Shaders/g1.vert.glsl similarity index 100% rename from Kinc/GLSLShaders/g1.vert.glsl rename to Kinc/Shaders/g1.vert.glsl diff --git a/Kinc/Sources/kinc/audio1/a1unit.c b/Kinc/Sources/kinc/audio1/a1unit.c index b3612f9..46b2c20 100644 --- a/Kinc/Sources/kinc/audio1/a1unit.c +++ b/Kinc/Sources/kinc/audio1/a1unit.c @@ -4,7 +4,7 @@ struct kinc_a1_channel { kinc_a1_sound_t *sound; - float position; + double position; bool loop; volatile float volume; float pitch; diff --git a/Kinc/Sources/kinc/audio1/audio.c.h b/Kinc/Sources/kinc/audio1/audio.c.h index 28e424c..43c9333 100644 --- a/Kinc/Sources/kinc/audio1/audio.c.h +++ b/Kinc/Sources/kinc/audio1/audio.c.h @@ -8,6 +8,7 @@ #include #include +#include #include static kinc_mutex_t mutex; @@ -17,15 +18,19 @@ static kinc_a1_channel_t channels[CHANNEL_COUNT]; static kinc_a1_stream_channel_t streamchannels[CHANNEL_COUNT]; static kinc_internal_video_channel_t videos[CHANNEL_COUNT]; -static float sampleLinear(int16_t *data, float position) { +static float sampleLinear(int16_t *data, double position) { int pos1 = (int)position; int pos2 = (int)(position + 1); float sample1 = data[pos1] / 32767.0f; float sample2 = data[pos2] / 32767.0f; - float a = position - pos1; + float a = (float)(position - pos1); return sample1 * (1 - a) + sample2 * a; } +static void kinc_a2_on_a1_mix(kinc_a2_buffer_t *buffer, uint32_t samples, void *userdata) { + kinc_a1_mix(buffer, samples); +} + /*float sampleHermite4pt3oX(s16* data, float position) { float s0 = data[(int)(position - 1)] / 32767.0f; float s1 = data[(int)(position + 0)] / 32767.0f; @@ -42,10 +47,10 @@ static float sampleLinear(int16_t *data, float position) { return ((c3 * x + c2) * x + c1) * x + c0; }*/ -void kinc_a1_mix(kinc_a2_buffer_t *buffer, int samples) { - for (int i = 0; i < samples; ++i) { - bool left = (i % 2) == 0; - float value = 0; +void kinc_a1_mix(kinc_a2_buffer_t *buffer, uint32_t samples) { + for (uint32_t i = 0; i < samples; ++i) { + float left_value = 0.0f; + float right_value = 0.0f; #if 0 __m128 sseSamples[4]; for (int i = 0; i < channelCount; i += 4) { @@ -71,14 +76,12 @@ void kinc_a1_mix(kinc_a2_buffer_t *buffer, int samples) { kinc_mutex_lock(&mutex); for (int i = 0; i < CHANNEL_COUNT; ++i) { if (channels[i].sound != NULL) { - // value += *(s16*)&channels[i].sound->data[(int)channels[i].position] / 32767.0f * channels[i].sound->volume(); - if (left) - value += sampleLinear(channels[i].sound->left, channels[i].position) * channels[i].volume * channels[i].volume; - else - value += sampleLinear(channels[i].sound->right, channels[i].position) * channels[i].volume * channels[i].volume; - value = kinc_max(kinc_min(value, 1.0f), -1.0f); - if (!left) - channels[i].position += channels[i].pitch / channels[i].sound->sample_rate_pos; + left_value += sampleLinear(channels[i].sound->left, channels[i].position) * channels[i].volume * channels[i].sound->volume; + left_value = kinc_max(kinc_min(left_value, 1.0f), -1.0f); + right_value += sampleLinear(channels[i].sound->right, channels[i].position) * channels[i].volume * channels[i].sound->volume; + right_value = kinc_max(kinc_min(right_value, 1.0f), -1.0f); + + channels[i].position += channels[i].pitch / channels[i].sound->sample_rate_pos; // channels[i].position += 2; if (channels[i].position + 1 >= channels[i].sound->size) { if (channels[i].loop) { @@ -92,17 +95,24 @@ void kinc_a1_mix(kinc_a2_buffer_t *buffer, int samples) { } for (int i = 0; i < CHANNEL_COUNT; ++i) { if (streamchannels[i].stream != NULL) { - value += kinc_a1_sound_stream_next_sample(streamchannels[i].stream) * kinc_a1_sound_stream_volume(streamchannels[i].stream); - value = kinc_max(kinc_min(value, 1.0f), -1.0f); - if (kinc_a1_sound_stream_ended(streamchannels[i].stream)) + float *samples = kinc_a1_sound_stream_next_frame(streamchannels[i].stream); + left_value += samples[0] * kinc_a1_sound_stream_volume(streamchannels[i].stream); + left_value = kinc_max(kinc_min(left_value, 1.0f), -1.0f); + right_value += samples[1] * kinc_a1_sound_stream_volume(streamchannels[i].stream); + right_value = kinc_max(kinc_min(right_value, 1.0f), -1.0f); + if (kinc_a1_sound_stream_ended(streamchannels[i].stream)) { streamchannels[i].stream = NULL; + } } } for (int i = 0; i < CHANNEL_COUNT; ++i) { if (videos[i].stream != NULL) { - value += kinc_internal_video_sound_stream_next_sample(videos[i].stream); - value = kinc_max(kinc_min(value, 1.0f), -1.0f); + float *samples = kinc_internal_video_sound_stream_next_frame(videos[i].stream); + left_value += samples[0]; + left_value = kinc_max(kinc_min(left_value, 1.0f), -1.0f); + right_value += samples[1]; + right_value = kinc_max(kinc_min(right_value, 1.0f), -1.0f); if (kinc_internal_video_sound_stream_ended(videos[i].stream)) { videos[i].stream = NULL; } @@ -111,10 +121,14 @@ void kinc_a1_mix(kinc_a2_buffer_t *buffer, int samples) { kinc_mutex_unlock(&mutex); #endif - *(float *)&buffer->data[buffer->write_location] = value; - buffer->write_location += 4; - if (buffer->write_location >= buffer->data_size) + assert(buffer->channel_count >= 2); + buffer->channels[0][buffer->write_location] = left_value; + buffer->channels[1][buffer->write_location] = right_value; + + buffer->write_location += 1; + if (buffer->write_location >= buffer->data_size) { buffer->write_location = 0; + } } } @@ -130,7 +144,7 @@ void kinc_a1_init(void) { kinc_mutex_init(&mutex); kinc_a2_init(); - kinc_a2_set_callback(kinc_a1_mix); + kinc_a2_set_callback(kinc_a2_on_a1_mix, NULL); } kinc_a1_channel_t *kinc_a1_play_sound(kinc_a1_sound_t *sound, bool loop, float pitch, bool unique) { @@ -150,7 +164,7 @@ kinc_a1_channel_t *kinc_a1_play_sound(kinc_a1_sound_t *sound, bool loop, float p channels[i].position = 0; channels[i].loop = loop; channels[i].pitch = pitch; - channels[i].volume = sound->volume; + channels[i].volume = 1.0f; channel = &channels[i]; break; } diff --git a/Kinc/Sources/kinc/audio1/audio.h b/Kinc/Sources/kinc/audio1/audio.h index 586b4ae..a6c39a2 100644 --- a/Kinc/Sources/kinc/audio1/audio.h +++ b/Kinc/Sources/kinc/audio1/audio.h @@ -85,7 +85,7 @@ KINC_FUNC void kinc_a1_channel_set_volume(kinc_a1_channel_t *channel, float volu /// /// The audio-buffer to be filled /// The number of samples to be filled in -KINC_FUNC void kinc_a1_mix(kinc_a2_buffer_t *buffer, int samples); +KINC_FUNC void kinc_a1_mix(kinc_a2_buffer_t *buffer, uint32_t samples); void kinc_internal_play_video_sound_stream(struct kinc_internal_video_sound_stream *stream); void kinc_internal_stop_video_sound_stream(struct kinc_internal_video_sound_stream *stream); diff --git a/Kinc/Sources/kinc/audio1/sound.c.h b/Kinc/Sources/kinc/audio1/sound.c.h index 0b52089..0fd7706 100644 --- a/Kinc/Sources/kinc/audio1/sound.c.h +++ b/Kinc/Sources/kinc/audio1/sound.c.h @@ -104,7 +104,7 @@ static kinc_a1_sound_t *find_sound(void) { return NULL; } -kinc_a1_sound_t *kinc_a1_sound_create(const char *filename) { +kinc_a1_sound_t *kinc_a1_sound_create_from_buffer(uint8_t *audio_data, const uint32_t size, kinc_a1_audioformat_t format) { kinc_a1_sound_t *sound = find_sound(); assert(sound != NULL); sound->in_use = true; @@ -112,66 +112,49 @@ kinc_a1_sound_t *kinc_a1_sound_create(const char *filename) { sound->size = 0; sound->left = NULL; sound->right = NULL; - size_t filenameLength = strlen(filename); + // size_t filenameLength = strlen(filename); uint8_t *data = NULL; - if (strncmp(&filename[filenameLength - 4], ".ogg", 4) == 0) { - kinc_file_reader_t file; - if (!kinc_file_reader_open(&file, filename, KINC_FILE_TYPE_ASSET)) { - sound->in_use = false; - return NULL; - } - uint8_t *filedata = (uint8_t *)malloc(kinc_file_reader_size(&file)); - kinc_file_reader_read(&file, filedata, kinc_file_reader_size(&file)); - kinc_file_reader_close(&file); - - int samples = - stb_vorbis_decode_memory(filedata, (int)kinc_file_reader_size(&file), &sound->format.channels, &sound->format.samples_per_second, (short **)&data); - sound->size = samples * 2 * sound->format.channels; - sound->format.bits_per_sample = 16; - free(filedata); + if (format == KINC_A1_AUDIOFORMAT_OGG) { + int channels, sample_rate; + int samples = stb_vorbis_decode_memory(audio_data, size, &channels, &sample_rate, (short **)&data); + kinc_affirm(samples > 0); + sound->channel_count = (uint8_t)channels; + sound->samples_per_second = (uint32_t)sample_rate; + sound->size = samples * 2 * sound->channel_count; + sound->bits_per_sample = 16; } - else if (strncmp(&filename[filenameLength - 4], ".wav", 4) == 0) { + else if (format == KINC_A1_AUDIOFORMAT_WAV) { struct WaveData wave = {0}; { - kinc_file_reader_t file; - if (!kinc_file_reader_open(&file, filename, KINC_FILE_TYPE_ASSET)) { - sound->in_use = false; - return NULL; - } - uint8_t *filedata = (uint8_t *)malloc(kinc_file_reader_size(&file)); - kinc_file_reader_read(&file, filedata, kinc_file_reader_size(&file)); - kinc_file_reader_close(&file); - uint8_t *data = filedata; + uint8_t *data = audio_data; checkFOURCC(&data, "RIFF"); uint32_t filesize = kinc_read_u32le(data); data += 4; checkFOURCC(&data, "WAVE"); - while (data + 8 - filedata < (intptr_t)filesize) { + while (data + 8 - audio_data < (intptr_t)filesize) { readChunk(&data, &wave); } - - free(filedata); } - sound->format.bits_per_sample = wave.bitsPerSample; - sound->format.channels = wave.numChannels; - sound->format.samples_per_second = wave.sampleRate; + sound->bits_per_sample = (uint8_t)wave.bitsPerSample; + sound->channel_count = (uint8_t)wave.numChannels; + sound->samples_per_second = wave.sampleRate; data = wave.data; sound->size = wave.dataSize; } else { - assert(false); + kinc_affirm(false); } - if (sound->format.channels == 1) { - if (sound->format.bits_per_sample == 8) { + if (sound->channel_count == 1) { + if (sound->bits_per_sample == 8) { sound->left = (int16_t *)malloc(sound->size * sizeof(int16_t)); sound->right = (int16_t *)malloc(sound->size * sizeof(int16_t)); splitMono8(data, sound->size, sound->left, sound->right); } - else if (sound->format.bits_per_sample == 16) { + else if (sound->bits_per_sample == 16) { sound->size /= 2; sound->left = (int16_t *)malloc(sound->size * sizeof(int16_t)); sound->right = (int16_t *)malloc(sound->size * sizeof(int16_t)); @@ -183,13 +166,13 @@ kinc_a1_sound_t *kinc_a1_sound_create(const char *filename) { } else { // Left and right channel are in s16 audio stream, alternating. - if (sound->format.bits_per_sample == 8) { + if (sound->bits_per_sample == 8) { sound->size /= 2; sound->left = (int16_t *)malloc(sound->size * sizeof(int16_t)); sound->right = (int16_t *)malloc(sound->size * sizeof(int16_t)); splitStereo8(data, sound->size, sound->left, sound->right); } - else if (sound->format.bits_per_sample == 16) { + else if (sound->bits_per_sample == 16) { sound->size /= 4; sound->left = (int16_t *)malloc(sound->size * sizeof(int16_t)); sound->right = (int16_t *)malloc(sound->size * sizeof(int16_t)); @@ -199,12 +182,43 @@ kinc_a1_sound_t *kinc_a1_sound_create(const char *filename) { kinc_affirm(false); } } - sound->sample_rate_pos = 44100 / (float)sound->format.samples_per_second; + sound->sample_rate_pos = kinc_a2_samples_per_second() / (float)sound->samples_per_second; free(data); return sound; } +kinc_a1_sound_t *kinc_a1_sound_create(const char *filename) { + size_t filenameLength = strlen(filename); + + kinc_a1_audioformat_t fileformat; + if (strncmp(&filename[filenameLength - 4], ".ogg", 4) == 0) { + fileformat = KINC_A1_AUDIOFORMAT_OGG; + } + else if (strncmp(&filename[filenameLength - 4], ".wav", 4) == 0) { + fileformat = KINC_A1_AUDIOFORMAT_WAV; + } + else { + assert(false); + } + + kinc_file_reader_t file; + if (!kinc_file_reader_open(&file, filename, KINC_FILE_TYPE_ASSET)) { + return NULL; + } + + uint8_t *filedata = (uint8_t *)malloc(kinc_file_reader_size(&file)); + kinc_file_reader_read(&file, filedata, kinc_file_reader_size(&file)); + kinc_file_reader_close(&file); + size_t filesize = kinc_file_reader_size(&file); + + kinc_a1_sound_t *sound = kinc_a1_sound_create_from_buffer(filedata, (uint32_t)filesize, fileformat); + + free(filedata); + + return sound; +} + void kinc_a1_sound_destroy(kinc_a1_sound_t *sound) { free(sound->left); free(sound->right); diff --git a/Kinc/Sources/kinc/audio1/sound.h b/Kinc/Sources/kinc/audio1/sound.h index 2d4f543..1dfafb9 100644 --- a/Kinc/Sources/kinc/audio1/sound.h +++ b/Kinc/Sources/kinc/audio1/sound.h @@ -15,7 +15,9 @@ extern "C" { #endif typedef struct kinc_a1_sound { - kinc_a2_buffer_format_t format; + uint8_t channel_count; + uint8_t bits_per_sample; + uint32_t samples_per_second; int16_t *left; int16_t *right; int size; @@ -24,12 +26,21 @@ typedef struct kinc_a1_sound { bool in_use; } kinc_a1_sound_t; +typedef enum { KINC_A1_AUDIOFORMAT_WAV, KINC_A1_AUDIOFORMAT_OGG } kinc_a1_audioformat_t; + /// -/// Create a sound from a wav file. +/// Create a sound from a wav or ogg file. +/// +/// Path to a wav or ogg file +/// The newly created sound +KINC_FUNC kinc_a1_sound_t *kinc_a1_sound_create(const char *filename); + +/// +/// Create a sound from a buffer. /// /// Path to a wav file /// The newly created sound -KINC_FUNC kinc_a1_sound_t *kinc_a1_sound_create(const char *filename); +KINC_FUNC kinc_a1_sound_t *kinc_a1_sound_create_from_buffer(uint8_t *audio_data, const uint32_t size, kinc_a1_audioformat_t format); /// /// Destroy a sound. diff --git a/Kinc/Sources/kinc/audio1/soundstream.c.h b/Kinc/Sources/kinc/audio1/soundstream.c.h index 7f9524c..c30e721 100644 --- a/Kinc/Sources/kinc/audio1/soundstream.c.h +++ b/Kinc/Sources/kinc/audio1/soundstream.c.h @@ -10,12 +10,11 @@ static kinc_a1_sound_stream_t streams[256]; static int nextStream = 0; -static uint8_t buffer[1024 * 10]; +static uint8_t buffer[1024 * 1024 * 10]; static int bufferIndex; kinc_a1_sound_stream_t *kinc_a1_sound_stream_create(const char *filename, bool looping) { kinc_a1_sound_stream_t *stream = &streams[nextStream]; - stream->decoded = false; stream->myLooping = looping; stream->myVolume = 1; stream->rateDecodedHack = false; @@ -88,48 +87,42 @@ void kinc_a1_sound_stream_reset(kinc_a1_sound_stream_t *stream) { stb_vorbis_seek_start(stream->vorbis); stream->end = false; stream->rateDecodedHack = false; - stream->decoded = false; } -float kinc_a1_sound_stream_next_sample(kinc_a1_sound_stream_t *stream) { - if (stream->vorbis == NULL) - return 0; +float *kinc_a1_sound_stream_next_frame(kinc_a1_sound_stream_t *stream) { + if (stream->vorbis == NULL) { + for (int i = 0; i < stream->chans; ++i) { + stream->samples[i] = 0; + } + return stream->samples; + } if (stream->rate == 22050) { if (stream->rateDecodedHack) { - if (stream->decoded) { - stream->decoded = false; - return stream->samples[0]; - } - else { - stream->rateDecodedHack = false; - stream->decoded = true; - return stream->samples[1]; - } + stream->rateDecodedHack = false; + return stream->samples; } } - if (stream->decoded) { - stream->decoded = false; - if (stream->chans == 1) { - return stream->samples[0]; + + float left, right; + float *samples_array[2] = {&left, &right}; + int read = stb_vorbis_get_samples_float(stream->vorbis, stream->chans, samples_array, 1); + if (read == 0) { + if (kinc_a1_sound_stream_looping(stream)) { + stb_vorbis_seek_start(stream->vorbis); + stb_vorbis_get_samples_float(stream->vorbis, stream->chans, samples_array, 1); } else { - return stream->samples[1]; + stream->end = true; + for (int i = 0; i < stream->chans; ++i) { + stream->samples[i] = 0; + } + return stream->samples; } } - else { - int read = stb_vorbis_get_samples_float_interleaved(stream->vorbis, stream->chans, &stream->samples[0], stream->chans); - if (read == 0) { - if (kinc_a1_sound_stream_looping(stream)) { - stb_vorbis_seek_start(stream->vorbis); - stb_vorbis_get_samples_float_interleaved(stream->vorbis, stream->chans, &stream->samples[0], stream->chans); - } - else { - stream->end = true; - return 0.0f; - } - } - stream->decoded = true; - stream->rateDecodedHack = true; - return stream->samples[0]; - } + + stream->samples[0] = samples_array[0][0]; + stream->samples[1] = samples_array[1][0]; + + stream->rateDecodedHack = true; + return stream->samples; } diff --git a/Kinc/Sources/kinc/audio1/soundstream.h b/Kinc/Sources/kinc/audio1/soundstream.h index 030f6b8..57d5a68 100644 --- a/Kinc/Sources/kinc/audio1/soundstream.h +++ b/Kinc/Sources/kinc/audio1/soundstream.h @@ -21,7 +21,6 @@ typedef struct kinc_a1_sound_stream { int rate; bool myLooping; float myVolume; - bool decoded; bool rateDecodedHack; bool end; float samples[2]; @@ -37,11 +36,11 @@ typedef struct kinc_a1_sound_stream { KINC_FUNC kinc_a1_sound_stream_t *kinc_a1_sound_stream_create(const char *filename, bool looping); /// -/// Gets the next audio-sample in the stream. +/// Gets the next audio-frame in the stream. /// -/// The stream to extract the sample from +/// The stream to extract the frame from /// The next sample -KINC_FUNC float kinc_a1_sound_stream_next_sample(kinc_a1_sound_stream_t *stream); +KINC_FUNC float *kinc_a1_sound_stream_next_frame(kinc_a1_sound_stream_t *stream); /// /// Gets the number of audio-channels the stream uses. diff --git a/Kinc/Sources/kinc/audio2/audio.h b/Kinc/Sources/kinc/audio2/audio.h index 5f66b58..c5492b5 100644 --- a/Kinc/Sources/kinc/audio2/audio.h +++ b/Kinc/Sources/kinc/audio2/audio.h @@ -12,18 +12,14 @@ extern "C" { #endif -typedef struct kinc_a2_buffer_format { - int channels; - int samples_per_second; - int bits_per_sample; -} kinc_a2_buffer_format_t; +#define KINC_A2_MAX_CHANNELS 8 typedef struct kinc_a2_buffer { - kinc_a2_buffer_format_t format; - uint8_t *data; - int data_size; - int read_location; - int write_location; + uint8_t channel_count; + float *channels[KINC_A2_MAX_CHANNELS]; + uint32_t data_size; + uint32_t read_location; + uint32_t write_location; } kinc_a2_buffer_t; /// @@ -36,19 +32,21 @@ KINC_FUNC void kinc_a2_init(void); /// number of samples into the ring-buffer. The callback is typically called from the system's audio-thread to minimize audio-latency. /// /// The callback to set -KINC_FUNC void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)); +/// The user data provided to the callback +KINC_FUNC void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, uint32_t samples, void *userdata), void *userdata); + +/// +/// The current sample-rate of the system. +/// +KINC_FUNC uint32_t kinc_a2_samples_per_second(void); /// /// Sets a callback that's called when the system's sample-rate changes. /// /// The callback to set +/// The user data provided to the callback /// -KINC_FUNC void kinc_a2_set_sample_rate_callback(void (*kinc_a2_sample_rate_callback)(void)); - -/// -/// The current sample-rate of the system. -/// -KINC_FUNC extern int kinc_a2_samples_per_second; +KINC_FUNC void kinc_a2_set_sample_rate_callback(void (*kinc_a2_sample_rate_callback)(void *userdata), void *userdata); /// /// kinc_a2_update should be called every frame. It is required by some systems to pump their audio-loops but on most systems it is a no-op. @@ -60,15 +58,63 @@ KINC_FUNC void kinc_a2_update(void); /// KINC_FUNC void kinc_a2_shutdown(void); +void kinc_a2_internal_init(void); +bool kinc_a2_internal_callback(kinc_a2_buffer_t *buffer, int samples); +void kinc_a2_internal_sample_rate_callback(void); + #ifdef KINC_IMPLEMENTATION_AUDIO2 #define KINC_IMPLEMENTATION #endif #ifdef KINC_IMPLEMENTATION -int kinc_a2_samples_per_second = 44100; +#include +#include +#include -// BACKENDS-PLACEHOLDER +static kinc_mutex_t mutex; + +static void (*a2_callback)(kinc_a2_buffer_t *buffer, uint32_t samples, void *userdata) = NULL; +static void *a2_userdata = NULL; + +void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, uint32_t samples, void *userdata), void *userdata) { + kinc_mutex_lock(&mutex); + a2_callback = kinc_a2_audio_callback; + a2_userdata = userdata; + kinc_mutex_unlock(&mutex); +} + +static void (*a2_sample_rate_callback)(void *userdata) = NULL; +static void *a2_sample_rate_userdata = NULL; + +void kinc_a2_set_sample_rate_callback(void (*kinc_a2_sample_rate_callback)(void *userdata), void *userdata) { + kinc_mutex_lock(&mutex); + a2_sample_rate_callback = kinc_a2_sample_rate_callback; + a2_sample_rate_userdata = userdata; + kinc_mutex_unlock(&mutex); +} + +void kinc_a2_internal_init(void) { + kinc_mutex_init(&mutex); +} + +bool kinc_a2_internal_callback(kinc_a2_buffer_t *buffer, int samples) { + kinc_mutex_lock(&mutex); + bool has_callback = a2_callback != NULL; + if (has_callback) { + a2_callback(buffer, samples, a2_userdata); + } + kinc_mutex_unlock(&mutex); + return has_callback; +} + +void kinc_a2_internal_sample_rate_callback(void) { + kinc_mutex_lock(&mutex); + if (a2_sample_rate_callback != NULL) { + a2_sample_rate_callback(a2_sample_rate_userdata); + } + kinc_mutex_unlock(&mutex); +} #endif diff --git a/Kinc/Sources/kinc/error.h b/Kinc/Sources/kinc/error.h index 6be4c66..78e373e 100644 --- a/Kinc/Sources/kinc/error.h +++ b/Kinc/Sources/kinc/error.h @@ -124,7 +124,7 @@ KINC_FUNC void kinc_error_args(const char *format, va_list args); #include -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include #include @@ -163,7 +163,7 @@ void kinc_error_message(const char *format, ...) { va_end(args); } -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS { va_list args; va_start(args, format); @@ -182,7 +182,7 @@ void kinc_error_message(const char *format, ...) { void kinc_error_args(const char *format, va_list args) { kinc_log_args(KINC_LOG_LEVEL_ERROR, format, args); -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS wchar_t buffer[4096]; kinc_microsoft_format(format, args, buffer); MessageBoxW(NULL, buffer, L"Error", 0); diff --git a/Kinc/Sources/kinc/global.h b/Kinc/Sources/kinc/global.h index c0872ac..afcf4c9 100644 --- a/Kinc/Sources/kinc/global.h +++ b/Kinc/Sources/kinc/global.h @@ -7,13 +7,13 @@ #include #include -#if defined(KORE_PPC) -#define KORE_BIG_ENDIAN +#if defined(KINC_PPC) +#define KINC_BIG_ENDIAN #else -#define KORE_LITTLE_ENDIAN +#define KINC_LITTLE_ENDIAN #endif -#if defined(KORE_PPC) +#if defined(KINC_PPC) #define KINC_BIG_ENDIAN #else #define KINC_LITTLE_ENDIAN @@ -27,22 +27,19 @@ #ifdef _MSC_VER #define KINC_MICROSOFT -#define KORE_MICROSOFT +#define KINC_MICROSOFT #endif #if defined(_WIN32) -#if defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWSAPP) #define KINC_WINDOWSAPP -#define KINC_WINRT -#define KORE_WINRT #else -#ifndef KORE_CONSOLE +#ifndef KINC_CONSOLE #define KINC_WINDOWS -#define KORE_WINDOWS #endif #endif @@ -53,11 +50,8 @@ #if TARGET_OS_IPHONE -#if defined(KORE_TVOS) -#define KINC_TVOS -#else +#if !defined(KINC_TVOS) #define KINC_IOS -#define KORE_IOS #endif #define KINC_APPLE_SOC @@ -65,7 +59,6 @@ #else #define KINC_MACOS -#define KORE_MACOS #if defined(__arm64__) #define KINC_APPLE_SOC @@ -74,21 +67,18 @@ #endif #define KINC_POSIX -#define KORE_POSIX #elif defined(__linux__) -#if !defined(KORE_ANDROID) +#if !defined(KINC_ANDROID) #define KINC_LINUX -#define KORE_LINUX #endif #define KINC_POSIX -#define KORE_POSIX #endif -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #if defined(KINC_DYNAMIC) #define KINC_FUNC __declspec(dllimport) #elif defined(KINC_DYNAMIC_COMPILE) @@ -100,6 +90,10 @@ #define KINC_FUNC #endif +#if defined(__LP64__) || defined(_LP64) || defined(_WIN64) +#define KINC_64 +#endif + #ifdef __cplusplus namespace Kore { @@ -107,11 +101,7 @@ namespace Kore { typedef unsigned short u16; // 2 Byte typedef unsigned int u32; // 4 Byte -#if defined(__LP64__) || defined(_LP64) || defined(_WIN64) -#define KORE_64 -#endif - -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS typedef unsigned __int64 u64; // 8 Byte #else typedef unsigned long long u64; @@ -119,7 +109,7 @@ namespace Kore { typedef char s8; // 1 Byte typedef short s16; // 2 Byte typedef int s32; // 4 Byte -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS typedef __int64 s64; // 8 Byte #else typedef long long s64; @@ -128,7 +118,7 @@ namespace Kore { typedef u32 uint; // 4 Byte typedef s32 sint; // 4 Byte -#ifdef KORE_64 +#ifdef KINC_64 typedef s64 spint; typedef u64 upint; #else diff --git a/Kinc/Sources/kinc/graphics1/graphics.c b/Kinc/Sources/kinc/graphics1/graphics.c index 809593d..abc09f0 100644 --- a/Kinc/Sources/kinc/graphics1/graphics.c +++ b/Kinc/Sources/kinc/graphics1/graphics.c @@ -7,17 +7,15 @@ #include #include #include +#include -#ifdef KINC_KONG -#include -#endif - -#ifndef KINC_KONG static kinc_g4_shader_t vertexShader; static kinc_g4_shader_t fragmentShader; static kinc_g4_pipeline_t pipeline; static kinc_g4_texture_unit_t tex; -#endif +kinc_g1_texture_filter_t kinc_internal_g1_texture_filter_min = KINC_G1_TEXTURE_FILTER_LINEAR; +kinc_g1_texture_filter_t kinc_internal_g1_texture_filter_mag = KINC_G1_TEXTURE_FILTER_LINEAR; +kinc_g1_mipmap_filter_t kinc_internal_g1_mipmap_filter = KINC_G1_MIPMAP_FILTER_NONE; static kinc_g4_vertex_buffer_t vb; static kinc_g4_index_buffer_t ib; static kinc_g4_texture_t texture; @@ -30,21 +28,47 @@ void kinc_g1_begin(void) { kinc_internal_g1_image = (uint32_t *)kinc_g4_texture_lock(&texture); } +static inline kinc_g4_texture_filter_t map_texture_filter(kinc_g1_texture_filter_t filter) { + switch (filter) { + case KINC_G1_TEXTURE_FILTER_POINT: + return KINC_G4_TEXTURE_FILTER_POINT; + case KINC_G1_TEXTURE_FILTER_LINEAR: + return KINC_G4_TEXTURE_FILTER_LINEAR; + case KINC_G1_TEXTURE_FILTER_ANISOTROPIC: + return KINC_G4_TEXTURE_FILTER_ANISOTROPIC; + } + + kinc_log(KINC_LOG_LEVEL_WARNING, "unhandled kinc_g1_texture_filter_t (%i)", filter); + return KINC_G4_TEXTURE_FILTER_LINEAR; +} + +static inline kinc_g4_mipmap_filter_t map_mipmap_filter(kinc_g1_mipmap_filter_t filter) { + switch (filter) { + case KINC_G1_MIPMAP_FILTER_NONE: + return KINC_G4_MIPMAP_FILTER_NONE; + case KINC_G1_MIPMAP_FILTER_POINT: + return KINC_G4_MIPMAP_FILTER_POINT; + case KINC_G1_MIPMAP_FILTER_LINEAR: + return KINC_G4_MIPMAP_FILTER_LINEAR; + } + + kinc_log(KINC_LOG_LEVEL_WARNING, "unhandled kinc_g1_mipmap_filter_t (%i)", filter); + return KINC_G4_MIPMAP_FILTER_NONE; +} + void kinc_g1_end(void) { kinc_internal_g1_image = NULL; kinc_g4_texture_unlock(&texture); kinc_g4_clear(KINC_G4_CLEAR_COLOR, 0xff000000, 0.0f, 0); -#ifdef KINC_KONG - kinc_g4_set_pipeline(&kinc_g1_pipeline); -#else kinc_g4_set_pipeline(&pipeline); -#endif -#ifndef KINC_KONG kinc_g4_set_texture(tex, &texture); -#endif + kinc_g4_set_texture_minification_filter(tex, map_texture_filter(kinc_internal_g1_texture_filter_min)); + kinc_g4_set_texture_magnification_filter(tex, map_texture_filter(kinc_internal_g1_texture_filter_mag)); + kinc_g4_set_texture_mipmap_filter(tex, map_mipmap_filter(kinc_internal_g1_mipmap_filter)); + kinc_g4_set_vertex_buffer(&vb); kinc_g4_set_index_buffer(&ib); kinc_g4_draw_indexed_vertices(); @@ -57,7 +81,6 @@ void kinc_g1_init(int width, int height) { kinc_internal_g1_w = width; kinc_internal_g1_h = height; -#ifndef KINC_KONG { kinc_file_reader_t file; kinc_file_reader_open(&file, "g1.vert", KINC_FILE_TYPE_ASSET); @@ -90,7 +113,6 @@ void kinc_g1_init(int width, int height) { kinc_g4_pipeline_compile(&pipeline); tex = kinc_g4_pipeline_get_texture_unit(&pipeline, "texy"); -#endif kinc_g4_texture_init(&texture, width, height, KINC_IMAGE_FORMAT_RGBA32); kinc_internal_g1_tex_width = texture.tex_width; @@ -108,11 +130,8 @@ void kinc_g1_init(int width, int height) { float xAspect = (float)width / texture.tex_width; float yAspect = (float)height / texture.tex_height; -#ifdef KINC_KONG - kinc_g4_vertex_buffer_init(&vb, 4, &kinc_g1_vertex_in_structure, KINC_G4_USAGE_STATIC, 0); -#else kinc_g4_vertex_buffer_init(&vb, 4, &structure, KINC_G4_USAGE_STATIC, 0); -#endif + float *v = kinc_g4_vertex_buffer_lock_all(&vb); { int i = 0; @@ -172,4 +191,16 @@ int kinc_g1_height() { return kinc_internal_g1_h; } +void kinc_g1_set_texture_magnification_filter(kinc_g1_texture_filter_t filter) { + kinc_internal_g1_texture_filter_mag = filter; +} + +void kinc_g1_set_texture_minification_filter(kinc_g1_texture_filter_t filter) { + kinc_internal_g1_texture_filter_min = filter; +} + +void kinc_g1_set_texture_mipmap_filter(kinc_g1_mipmap_filter_t filter) { + kinc_internal_g1_mipmap_filter = filter; +} + #endif diff --git a/Kinc/Sources/kinc/graphics1/graphics.h b/Kinc/Sources/kinc/graphics1/graphics.h index d171f50..7a4ba18 100644 --- a/Kinc/Sources/kinc/graphics1/graphics.h +++ b/Kinc/Sources/kinc/graphics1/graphics.h @@ -14,6 +14,18 @@ extern "C" { #endif +typedef enum { + KINC_G1_TEXTURE_FILTER_POINT, + KINC_G1_TEXTURE_FILTER_LINEAR, + KINC_G1_TEXTURE_FILTER_ANISOTROPIC, +} kinc_g1_texture_filter_t; + +typedef enum { + KINC_G1_MIPMAP_FILTER_NONE, + KINC_G1_MIPMAP_FILTER_POINT, + KINC_G1_MIPMAP_FILTER_LINEAR, +} kinc_g1_mipmap_filter_t; + /// /// Initializes the G1-API. /// @@ -34,6 +46,9 @@ KINC_FUNC void kinc_g1_end(void); extern uint32_t *kinc_internal_g1_image; extern int kinc_internal_g1_w, kinc_internal_g1_h, kinc_internal_g1_tex_width; +extern kinc_g1_texture_filter_t kinc_internal_g1_texture_filter_min; +extern kinc_g1_texture_filter_t kinc_internal_g1_texture_filter_mag; +extern kinc_g1_mipmap_filter_t kinc_internal_g1_mipmap_filter; #if defined(KINC_DYNAMIC_COMPILE) || defined(KINC_DYNAMIC) || defined(KINC_DOCS) @@ -59,6 +74,27 @@ KINC_FUNC int kinc_g1_width(void); /// The height KINC_FUNC int kinc_g1_height(void); +/// +/// Set the texture-sampling-mode for upscaled textures. +/// +/// The texture-unit to set the texture-sampling-mode for +/// The mode to set +KINC_FUNC void kinc_g1_set_texture_magnification_filter(kinc_g1_texture_filter_t filter); + +/// +/// Set the texture-sampling-mode for downscaled textures. +/// +/// The texture-unit to set the texture-sampling-mode for +/// The mode to set +KINC_FUNC void kinc_g1_set_texture_minification_filter(kinc_g1_texture_filter_t filter); + +/// +/// Sets the mipmap-sampling-mode which defines whether mipmaps are used at all and if so whether the two neighbouring mipmaps are linearly interpolated. +/// +/// The texture-unit to set the mipmap-sampling-mode for +/// The mode to set +KINC_FUNC void kinc_g1_set_texture_mipmap_filter(kinc_g1_mipmap_filter_t filter); + #else // implementation moved to the header to allow easy inlining @@ -79,6 +115,18 @@ static inline int kinc_g1_height(void) { return kinc_internal_g1_h; } +static inline void kinc_g1_set_texture_magnification_filter(kinc_g1_texture_filter_t filter) { + kinc_internal_g1_texture_filter_mag = filter; +} + +static inline void kinc_g1_set_texture_minification_filter(kinc_g1_texture_filter_t filter) { + kinc_internal_g1_texture_filter_min = filter; +} + +static inline void kinc_g1_set_texture_mipmap_filter(kinc_g1_mipmap_filter_t filter) { + kinc_internal_g1_mipmap_filter = filter; +} + #endif #ifdef __cplusplus diff --git a/Kinc/Sources/kinc/graphics4/compute.h b/Kinc/Sources/kinc/graphics4/compute.h index 43f09e5..f1ee96a 100644 --- a/Kinc/Sources/kinc/graphics4/compute.h +++ b/Kinc/Sources/kinc/graphics4/compute.h @@ -2,13 +2,12 @@ #include -#include -#ifdef KORE_OPENGL +#include +#ifdef KINC_OPENGL #include +#include #endif #include -#include -#include /*! \file compute.h \brief Provides support for running compute-shaders. @@ -21,17 +20,9 @@ extern "C" { struct kinc_g4_texture; struct kinc_g4_render_target; -typedef struct kinc_compute_constant_location { - kinc_compute_constant_location_impl_t impl; -} kinc_compute_constant_location_t; - -typedef struct kinc_compute_texture_unit { - kinc_compute_texture_unit_impl_t impl; -} kinc_compute_texture_unit_t; - -typedef struct kinc_compute_shader { - kinc_compute_shader_impl_t impl; -} kinc_compute_shader_t; +typedef struct kinc_g4_compute_shader { + kinc_g4_compute_shader_impl impl; +} kinc_g4_compute_shader; /// /// Initialize a compute-shader from system-specific shader-data. @@ -39,22 +30,21 @@ typedef struct kinc_compute_shader { /// The shader-object to initialize /// A pointer to system-specific shader-data /// Length of the shader-data in bytes -KINC_FUNC void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *source, int length); +KINC_FUNC void kinc_g4_compute_shader_init(kinc_g4_compute_shader *shader, void *source, int length); /// /// Destroy a shader-object /// /// The shader-object to destroy -KINC_FUNC void kinc_compute_shader_destroy(kinc_compute_shader_t *shader); +KINC_FUNC void kinc_g4_compute_shader_destroy(kinc_g4_compute_shader *shader); -#ifndef KINC_KONG /// /// Finds the location of a constant/uniform inside of a shader. /// /// The shader to look into /// The constant/uniform-name to look for /// The found constant-location -KINC_FUNC kinc_compute_constant_location_t kinc_compute_shader_get_constant_location(kinc_compute_shader_t *shader, const char *name); +KINC_FUNC kinc_g4_constant_location_t kinc_g4_compute_shader_get_constant_location(kinc_g4_compute_shader *shader, const char *name); /// /// Finds a texture-unit inside of a shader. @@ -62,10 +52,9 @@ KINC_FUNC kinc_compute_constant_location_t kinc_compute_shader_get_constant_loca /// The shader to look into /// The texture-name to look for /// The found texture-unit -KINC_FUNC kinc_compute_texture_unit_t kinc_compute_shader_get_texture_unit(kinc_compute_shader_t *shader, const char *name); -#endif +KINC_FUNC kinc_g4_texture_unit_t kinc_g4_compute_shader_get_texture_unit(kinc_g4_compute_shader *shader, const char *name); -#ifdef KORE_OPENGL +#ifdef KINC_OPENGL typedef struct kinc_shader_storage_buffer { kinc_compute_shader_storage_buffer_impl_t impl; } kinc_shader_storage_buffer_t; @@ -78,149 +67,6 @@ KINC_FUNC int kinc_shader_storage_buffer_count(kinc_shader_storage_buffer_t *buf KINC_FUNC void kinc_shader_storage_buffer_internal_set(kinc_shader_storage_buffer_t *buffer); #endif -typedef enum kinc_compute_access { KINC_COMPUTE_ACCESS_READ, KINC_COMPUTE_ACCESS_WRITE, KINC_COMPUTE_ACCESS_READ_WRITE } kinc_compute_access_t; - -/// -/// Assigns a bool-value to a constant/uniform. The constant/uniform has to be declared as a bool in the shader. -/// -/// The location to set -/// The value to set the location to -KINC_FUNC void kinc_compute_set_bool(kinc_compute_constant_location_t location, bool value); - -/// -/// Assigns an int-value to a constant/uniform. The constant/uniform has to be declared as an int in the shader. -/// -/// The location to set -/// The value to set the location to -KINC_FUNC void kinc_compute_set_int(kinc_compute_constant_location_t location, int value); - -/// -/// Assigns a float-value to a constant/uniform. The constant/uniform has to be declared as a float in the shader. -/// -/// The location to set -/// The value to set the location to -KINC_FUNC void kinc_compute_set_float(kinc_compute_constant_location_t location, float value); - -/// -/// Assigns two float-values to a constant/uniform. The constant/uniform has to be declared as a vec2 in the shader. -/// -/// The location to set -KINC_FUNC void kinc_compute_set_float2(kinc_compute_constant_location_t location, float value1, float value2); - -/// -/// Assigns three float-values to a constant/uniform. The constant/uniform has to be declared as a vec3 in the shader. -/// -/// The location to set -KINC_FUNC void kinc_compute_set_float3(kinc_compute_constant_location_t location, float value1, float value2, float value3); - -/// -/// Assigns four float-values to a constant/uniform. The constant/uniform has to be declared as a vec4 in the shader. -/// -/// The location to set -KINC_FUNC void kinc_compute_set_float4(kinc_compute_constant_location_t location, float value1, float value2, float value3, float value4); - -/// -/// Assigns an array of float-values to a constant/uniform. The constant/uniform has to be declared as a float-array in the shader. -/// -/// The location to set -KINC_FUNC void kinc_compute_set_floats(kinc_compute_constant_location_t location, float *values, int count); - -/// -/// Assigns a 4x4-matrix-value to a constant/uniform. The constant/uniform has to be declared as a mat4 in the shader. -/// -/// The location to set -KINC_FUNC void kinc_compute_set_matrix4(kinc_compute_constant_location_t location, kinc_matrix4x4_t *value); - -/// -/// Assigns a 3x3-matrix-value to a constant/uniform. The constant/uniform has to be declared as a mat3 in the shader. -/// -/// The location to set -KINC_FUNC void kinc_compute_set_matrix3(kinc_compute_constant_location_t location, kinc_matrix3x3_t *value); - -#ifdef KORE_OPENGL -KINC_FUNC void kinc_compute_set_buffer(kinc_shader_storage_buffer_t *buffer, int index); -#endif - -/// -/// Assigns a texture to a texture-unit for direct access. -/// -KINC_FUNC void kinc_compute_set_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture, kinc_compute_access_t access); - -/// -/// Assigns a render-target to a texture-unit for direct access. -/// -KINC_FUNC void kinc_compute_set_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *texture, kinc_compute_access_t access); - -/// -/// Assigns a texture to a texture-unit for samples access. -/// -KINC_FUNC void kinc_compute_set_sampled_texture(kinc_compute_texture_unit_t unit, struct kinc_g4_texture *texture); - -/// -/// Assigns a render-target to a texture-unit for samples access. -/// -KINC_FUNC void kinc_compute_set_sampled_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target); - -/// -/// Assigns the depth-component of a render-target to a texture-unit for samples access. -/// -KINC_FUNC void kinc_compute_set_sampled_depth_from_render_target(kinc_compute_texture_unit_t unit, struct kinc_g4_render_target *target); - -/// -/// Assigns the mode for accessing a texture outside of the 0 to 1-range for a texture-unit. -/// -KINC_FUNC void kinc_compute_set_texture_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing); - -/// -/// Sets the magnification-mode for a texture-unit. -/// -KINC_FUNC void kinc_compute_set_texture_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter); - -/// -/// Sets the minification-mode for a texture-unit. -/// -KINC_FUNC void kinc_compute_set_texture_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter); - -/// -/// Sets the mipmap-mode for a texture-unit. -/// -KINC_FUNC void kinc_compute_set_texture_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter); - -/// -/// Assigns the mode for accessing a texture outside of the 0 to 1-range for a texture-unit. -/// -KINC_FUNC void kinc_compute_set_texture3d_addressing(kinc_compute_texture_unit_t unit, kinc_g4_texture_direction_t dir, - kinc_g4_texture_addressing_t addressing); - -/// -/// Sets the magnification-mode for a texture-unit. -/// -KINC_FUNC void kinc_compute_set_texture3d_magnification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter); - -/// -/// Sets the minification-mode for a texture-unit. -/// -KINC_FUNC void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t unit, kinc_g4_texture_filter_t filter); - -/// -/// Sets the mipmap-mode for a texture-unit. -/// -KINC_FUNC void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter); - -/// -/// Sets a shader for the next compute-run. -/// -/// The shader to use -KINC_FUNC void kinc_compute_set_shader(kinc_compute_shader_t *shader); - -/// -/// Fire off a compute-run on x * y * z elements. -/// -/// The x-size for the compute-run -/// The y-size for the compute-run -/// The z-size for the compute-run -KINC_FUNC void kinc_compute(int x, int y, int z); - #ifdef __cplusplus } #endif diff --git a/Kinc/Sources/kinc/graphics4/constantbuffer.h b/Kinc/Sources/kinc/graphics4/constantbuffer.h deleted file mode 100644 index f103f9a..0000000 --- a/Kinc/Sources/kinc/graphics4/constantbuffer.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once - -#ifdef KINC_KONG - -#include - -#include - -#include -#include - -/*! \file constantbuffer.h - \brief Provides support for managing buffers of constant-data for shaders. -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct kinc_g4_constant_buffer { - kinc_g4_constant_buffer_impl impl; -} kinc_g4_constant_buffer; - -/// -/// Initializes a constant-buffer. -/// -/// The buffer to initialize -/// The size of the constant-data in the buffer in bytes -KINC_FUNC void kinc_g4_constant_buffer_init(kinc_g4_constant_buffer *buffer, size_t size); - -/// -/// Destroys a buffer. -/// -/// The buffer to destroy -KINC_FUNC void kinc_g4_constant_buffer_destroy(kinc_g4_constant_buffer *buffer); - -/// -/// Locks all of a constant-buffer to modify its contents. -/// -/// The buffer to lock -/// The contents of the buffer -KINC_FUNC uint8_t *kinc_g4_constant_buffer_lock_all(kinc_g4_constant_buffer *buffer); - -/// -/// Locks part of a constant-buffer to modify its contents. -/// -/// The buffer to lock -/// The offset of where to start the lock in bytes -/// The number of bytes to lock -/// The contents of the buffer, starting at start -KINC_FUNC uint8_t *kinc_g4_constant_buffer_lock(kinc_g4_constant_buffer *buffer, size_t start, size_t count); - -/// -/// Unlocks a constant-buffer so the changed contents can be used. -/// -/// The buffer to unlock -KINC_FUNC void kinc_g4_constant_buffer_unlock_all(kinc_g4_constant_buffer *buffer); - -/// -/// Unlocks parts of a constant-buffer so the changed contents can be used. -/// -/// The buffer to unlock -/// /// The number of bytes to unlock, starting from the start-index from the previous lock-call -KINC_FUNC void kinc_g4_constant_buffer_unlock(kinc_g4_constant_buffer *buffer, size_t count); - -/// -/// Figures out the size of the constant-data in the buffer. -/// -/// The buffer to figure out the size for -/// Returns the size of the constant-data in the buffer in bytes -KINC_FUNC size_t kinc_g4_constant_buffer_size(kinc_g4_constant_buffer *buffer); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Kinc/Sources/kinc/graphics4/graphics.h b/Kinc/Sources/kinc/graphics4/graphics.h index 7552f18..8f1c241 100644 --- a/Kinc/Sources/kinc/graphics4/graphics.h +++ b/Kinc/Sources/kinc/graphics4/graphics.h @@ -16,12 +16,13 @@ extern "C" { #endif +struct kinc_g4_compute_shader; struct kinc_g4_pipeline; struct kinc_g4_render_target; struct kinc_g4_texture; struct kinc_g4_texture_array; -#ifdef KINC_KONG -struct kinc_g4_constant_buffer; +#ifdef KINC_OPENGL +struct kinc_shader_storage_buffer; #endif typedef enum { @@ -48,7 +49,7 @@ typedef enum { KINC_FUNC bool kinc_g4_supports_instanced_rendering(void); /// -/// Returns whether GPU-compute (the functions in kinc/graphics4/compute.h) is supported. +/// Returns whether GPU-compute (the functions in kinc/compute/compute.h) is supported. /// /// Whether GPU-compute is supported KINC_FUNC bool kinc_g4_supports_compute_shaders(void); @@ -108,7 +109,7 @@ KINC_FUNC bool kinc_g4_swap_buffers(void); /// Clears the color, depth and/or stencil-components of the current framebuffer or render-target. /// /// Defines what components to clear -/// The color-value to clear to +/// The color-value to clear to in 0xAARRGGBB /// The depth-value to clear to /// The stencil-value to clear to KINC_FUNC void kinc_g4_clear(unsigned flags, unsigned color, float depth, int stencil); @@ -181,10 +182,6 @@ KINC_FUNC void kinc_g4_set_stencil_reference_value(int value); /// KINC_FUNC void kinc_g4_set_blend_constant(float r, float g, float b, float a); -#ifdef KINC_KONG -KINC_FUNC void kinc_g4_set_constant_buffer(uint32_t id, struct kinc_g4_constant_buffer *buffer); -#endif - /// /// Assigns an integer to a constant/uniform in the currently set pipeline. /// @@ -363,21 +360,12 @@ KINC_FUNC void kinc_g4_set_render_targets(struct kinc_g4_render_target **targets KINC_FUNC void kinc_g4_set_render_target_face(struct kinc_g4_render_target *texture, int face); -#ifdef KINC_KONG -/// -/// Assigns a texture to a texture-unit for sampled access via GLSL's texture. -/// -/// The unit to assign this texture to -/// The texture to assign to the unit -KINC_FUNC void kinc_g4_set_texture(uint32_t unit, struct kinc_g4_texture *texture); -#else /// /// Assigns a texture to a texture-unit for sampled access via GLSL's texture. /// /// The unit to assign this texture to /// The texture to assign to the unit KINC_FUNC void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture); -#endif /// /// Assigns a texture to a texture-unit for direct access via GLSL's texelFetch (as @@ -420,6 +408,27 @@ KINC_FUNC int kinc_g4_antialiasing_samples(void); /// The number of samples KINC_FUNC void kinc_g4_set_antialiasing_samples(int samples); +#ifdef KINC_OPENGL +/// +/// Old, hack thing, do not use. +/// +KINC_FUNC void kinc_g4_set_shader_storage_buffer(struct kinc_shader_storage_buffer *buffer, int index); +#endif + +/// +/// Sets a shader for the next compute-run. +/// +/// The shader to use +KINC_FUNC void kinc_g4_set_compute_shader(struct kinc_g4_compute_shader *shader); + +/// +/// Fire off a compute-run on x * y * z elements. +/// +/// The x-size for the compute-run +/// The y-size for the compute-run +/// The z-size for the compute-run +KINC_FUNC void kinc_g4_compute(int x, int y, int z); + #ifndef KINC_DOCS void kinc_g4_internal_init(void); void kinc_g4_internal_init_window(int window, int depth_buffer_bits, int stencil_buffer_bits, bool vsync); diff --git a/Kinc/Sources/kinc/graphics4/pipeline.c.h b/Kinc/Sources/kinc/graphics4/pipeline.c.h index 13e6304..35b308a 100644 --- a/Kinc/Sources/kinc/graphics4/pipeline.c.h +++ b/Kinc/Sources/kinc/graphics4/pipeline.c.h @@ -1,5 +1,7 @@ #include "pipeline.h" +#include + void kinc_g4_internal_pipeline_set_defaults(kinc_g4_pipeline_t *state) { for (int i = 0; i < 16; ++i) state->input_layout[i] = NULL; diff --git a/Kinc/Sources/kinc/graphics4/pipeline.h b/Kinc/Sources/kinc/graphics4/pipeline.h index b74da37..d788a37 100644 --- a/Kinc/Sources/kinc/graphics4/pipeline.h +++ b/Kinc/Sources/kinc/graphics4/pipeline.h @@ -135,7 +135,6 @@ KINC_FUNC void kinc_g4_pipeline_destroy(kinc_g4_pipeline_t *pipeline); /// The pipeline to compile KINC_FUNC void kinc_g4_pipeline_compile(kinc_g4_pipeline_t *pipeline); -#ifndef KINC_KONG /// /// Searches for a constant/uniform and returns a constant-location which can be used to change the constant/uniform. /// @@ -151,7 +150,6 @@ KINC_FUNC kinc_g4_constant_location_t kinc_g4_pipeline_get_constant_location(kin /// The name of the texture-declaration to search for /// The texture-unit of the texture-declaration KINC_FUNC kinc_g4_texture_unit_t kinc_g4_pipeline_get_texture_unit(kinc_g4_pipeline_t *pipeline, const char *name); -#endif void kinc_g4_internal_set_pipeline(kinc_g4_pipeline_t *pipeline); void kinc_g4_internal_pipeline_set_defaults(kinc_g4_pipeline_t *pipeline); diff --git a/Kinc/Sources/kinc/graphics4/rendertarget.h b/Kinc/Sources/kinc/graphics4/rendertarget.h index 1a41386..c340298 100644 --- a/Kinc/Sources/kinc/graphics4/rendertarget.h +++ b/Kinc/Sources/kinc/graphics4/rendertarget.h @@ -38,7 +38,7 @@ typedef struct kinc_g4_render_target { } kinc_g4_render_target_t; /// -/// Allocates and initializes a regular render-target. +/// Allocates and initializes a regular render-target. The contents of the render-target are undefined. /// /// /// @@ -50,7 +50,8 @@ KINC_FUNC void kinc_g4_render_target_init(kinc_g4_render_target_t *renderTarget, int depthBufferBits, int stencilBufferBits); /// -/// Allocates and initializes a multi-sampled render-target if possible - otherwise it falls back to a regular render-target. +/// Allocates and initializes a multi-sampled render-target if possible - otherwise it falls back to a regular render-target. The contents of the render-target +/// are undefined. /// /// /// @@ -64,7 +65,7 @@ KINC_FUNC void kinc_g4_render_target_init_with_multisampling(kinc_g4_render_targ int samples_per_pixel); /// -/// Allocates and initializes a render-target-cube-map. +/// Allocates and initializes a render-target-cube-map. The contents of the render-target are undefined. /// /// /// @@ -75,7 +76,8 @@ KINC_FUNC void kinc_g4_render_target_init_cube(kinc_g4_render_target_t *renderTa int depthBufferBits, int stencilBufferBits); /// -/// Allocates and initializes a multi-sampled render-target-cube-map. Can fall back to a non-multi-sampled cube-map. +/// Allocates and initializes a multi-sampled render-target-cube-map. Can fall back to a non-multi-sampled cube-map. The contents of the render-target are +/// undefined. /// /// /// @@ -92,21 +94,12 @@ KINC_FUNC void kinc_g4_render_target_init_cube_with_multisampling(kinc_g4_render /// The render-target to destroy KINC_FUNC void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget); -#ifdef KINC_KONG -/// -/// Uses the color-component of a render-target as a texture. -/// -/// The render-target to use -/// The texture-unit to assign the render-target to -KINC_FUNC void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, uint32_t unit); -#else /// /// Uses the color-component of a render-target as a texture. /// /// The render-target to use /// The texture-unit to assign the render-target to KINC_FUNC void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit); -#endif /// /// Uses the depth-component of a render-target as a texture. diff --git a/Kinc/Sources/kinc/graphics4/texture.h b/Kinc/Sources/kinc/graphics4/texture.h index 8049820..672d913 100644 --- a/Kinc/Sources/kinc/graphics4/texture.h +++ b/Kinc/Sources/kinc/graphics4/texture.h @@ -93,11 +93,11 @@ KINC_FUNC void kinc_g4_texture_set_mipmap(kinc_g4_texture_t *texture, kinc_image /// The stride of the first mipmap-layer in bytes KINC_FUNC int kinc_g4_texture_stride(kinc_g4_texture_t *texture); -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID KINC_FUNC void kinc_g4_texture_init_from_id(kinc_g4_texture_t *texture, unsigned texid); #endif -#if defined(KORE_IOS) || defined(KORE_MACOS) +#if defined(KINC_IOS) || defined(KINC_MACOS) KINC_FUNC void kinc_g4_texture_upload(kinc_g4_texture_t *texture, uint8_t *data, int stride); #endif diff --git a/Kinc/Sources/kinc/graphics5/commandlist.h b/Kinc/Sources/kinc/graphics5/commandlist.h index 6623fc0..2d6c639 100644 --- a/Kinc/Sources/kinc/graphics5/commandlist.h +++ b/Kinc/Sources/kinc/graphics5/commandlist.h @@ -23,6 +23,7 @@ extern "C" { #define KINC_G5_CLEAR_DEPTH 2 #define KINC_G5_CLEAR_STENCIL 4 +struct kinc_g5_compute_shader; struct kinc_g5_constant_buffer; struct kinc_g5_index_buffer; struct kinc_g5_pipeline; @@ -76,7 +77,7 @@ KINC_FUNC void kinc_g5_command_list_end(kinc_g5_command_list_t *list); /// The list to write the command to /// The render-target to clear /// Defines what components to clear -/// The color-value to clear to +/// The color-value to clear to in 0xAARRGGBB /// The depth-value to clear to /// The stencil-value to clear to KINC_FUNC void kinc_g5_command_list_clear(kinc_g5_command_list_t *list, struct kinc_g5_render_target *render_target, unsigned flags, unsigned color, @@ -174,6 +175,13 @@ KINC_FUNC void kinc_g5_command_list_disable_scissor(kinc_g5_command_list_t *list /// The pipeline to set KINC_FUNC void kinc_g5_command_list_set_pipeline(kinc_g5_command_list_t *list, struct kinc_g5_pipeline *pipeline); +/// +/// Writes a command to set the compute shader for the next compute-call. +/// +/// The list to write the command to +/// The compute shader to set +KINC_FUNC void kinc_g5_command_list_set_compute_shader(kinc_g5_command_list_t *list, struct kinc_g5_compute_shader *shader); + /// /// Sets the blend constant used for `KINC_G5_BLEND_CONSTANT` or `KINC_G5_INV_BLEND_CONSTANT` /// @@ -242,6 +250,15 @@ KINC_FUNC void kinc_g5_command_list_set_vertex_constant_buffer(kinc_g5_command_l /// The size of the buffer to use in bytes starting at the offset KINC_FUNC void kinc_g5_command_list_set_fragment_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size); +/// +/// Writes a command that sets a constant-buffer for the compute-shader-stage. +/// +/// The list to write the command to +/// The buffer to set +/// The offset into the buffer in bytes to use as the start +/// The size of the buffer to use in bytes starting at the offset +KINC_FUNC void kinc_g5_command_list_set_compute_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size); + /// /// Kicks off execution of the commands which have been recorded in the command-list. kinc_g5_command_list_end has to be called beforehand. /// diff --git a/Kinc/Sources/kinc/graphics5/compute.h b/Kinc/Sources/kinc/graphics5/compute.h index 7efb446..9ef1647 100644 --- a/Kinc/Sources/kinc/graphics5/compute.h +++ b/Kinc/Sources/kinc/graphics5/compute.h @@ -2,7 +2,7 @@ #include -#include +#include #include #include @@ -15,13 +15,9 @@ extern "C" { #endif -typedef struct kinc_g5_compute_shader_impl { - int a; -} kinc_g5_compute_shader_ímpl_t; - typedef struct kinc_g5_compute_shader { - kinc_g5_compute_shader_ímpl_t impl; -} kinc_g5_compute_shader_t; + kinc_g5_compute_shader_impl impl; +} kinc_g5_compute_shader; /// /// Initialize a compute-shader from system-specific shader-data. @@ -29,13 +25,13 @@ typedef struct kinc_g5_compute_shader { /// The shader-object to initialize /// A pointer to system-specific shader-data /// Length of the shader-data in bytes -KINC_FUNC void kinc_g5_compute_shader_init(kinc_g5_compute_shader_t *shader, void *source, int length); +KINC_FUNC void kinc_g5_compute_shader_init(kinc_g5_compute_shader *shader, void *source, int length); /// /// Desotry a shader-object /// /// The shader-object to destroy -KINC_FUNC void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader_t *shader); +KINC_FUNC void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader *shader); /// /// Finds the location of a constant/uniform inside of a shader. @@ -43,7 +39,7 @@ KINC_FUNC void kinc_g5_compute_shader_destroy(kinc_g5_compute_shader_t *shader); /// The shader to look into /// The constant/uniform-name to look for /// The found constant-location -KINC_FUNC kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_location(kinc_g5_compute_shader_t *shader, const char *name); +KINC_FUNC kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_location(kinc_g5_compute_shader *shader, const char *name); /// /// Finds a texture-unit inside of a shader. @@ -51,7 +47,7 @@ KINC_FUNC kinc_g5_constant_location_t kinc_g5_compute_shader_get_constant_locati /// The shader to look into /// The texture-name to look for /// The found texture-unit -KINC_FUNC kinc_g5_texture_unit_t kinc_compute_g5_shader_get_texture_unit(kinc_g5_compute_shader_t *shader, const char *name); +KINC_FUNC kinc_g5_texture_unit_t kinc_g5_compute_shader_get_texture_unit(kinc_g5_compute_shader *shader, const char *name); #ifdef __cplusplus } diff --git a/Kinc/Sources/kinc/graphics5/constantbuffer.c.h b/Kinc/Sources/kinc/graphics5/constantbuffer.c.h index 8a82fa3..1427782 100644 --- a/Kinc/Sources/kinc/graphics5/constantbuffer.c.h +++ b/Kinc/Sources/kinc/graphics5/constantbuffer.c.h @@ -1,58 +1,77 @@ #include "constantbuffer.h" -static void setInt(uint8_t *constants, int offset, int value) { - int *ints = (int *)(&constants[offset]); +void kinc_g5_constant_buffer_set_int(kinc_g5_constant_buffer_t *buffer, int offset, int value) { + int *ints = (int *)(&buffer->data[offset]); ints[0] = value; } -static void setFloat(uint8_t *constants, int offset, float value) { - float *floats = (float *)(&constants[offset]); +void kinc_g5_constant_buffer_set_int2(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2) { + int *ints = (int *)(&buffer->data[offset]); + ints[0] = value1; + ints[1] = value2; +} + +void kinc_g5_constant_buffer_set_int3(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2, int value3) { + int *ints = (int *)(&buffer->data[offset]); + ints[0] = value1; + ints[1] = value2; + ints[2] = value3; +} + +void kinc_g5_constant_buffer_set_int4(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2, int value3, int value4) { + int *ints = (int *)(&buffer->data[offset]); + ints[0] = value1; + ints[1] = value2; + ints[2] = value3; + ints[3] = value4; +} + +void kinc_g5_constant_buffer_set_ints(kinc_g5_constant_buffer_t *buffer, int offset, int *values, int count) { + int *ints = (int *)(&buffer->data[offset]); + for (int i = 0; i < count; ++i) { + ints[i] = values[i]; + } +} + +void kinc_g5_constant_buffer_set_float(kinc_g5_constant_buffer_t *buffer, int offset, float value) { + float *floats = (float *)(&buffer->data[offset]); floats[0] = value; } -static void setFloat2(uint8_t *constants, int offset, float value1, float value2) { - float *floats = (float *)(&constants[offset]); +void kinc_g5_constant_buffer_set_float2(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2) { + float *floats = (float *)(&buffer->data[offset]); floats[0] = value1; floats[1] = value2; } -static void setFloat3(uint8_t *constants, int offset, float value1, float value2, float value3) { - float *floats = (float *)(&constants[offset]); +void kinc_g5_constant_buffer_set_float3(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2, float value3) { + float *floats = (float *)(&buffer->data[offset]); floats[0] = value1; floats[1] = value2; floats[2] = value3; } -static void setFloat4(uint8_t *constants, int offset, float value1, float value2, float value3, float value4) { - float *floats = (float *)(&constants[offset]); +void kinc_g5_constant_buffer_set_float4(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2, float value3, float value4) { + float *floats = (float *)(&buffer->data[offset]); floats[0] = value1; floats[1] = value2; floats[2] = value3; floats[3] = value4; } -static void setFloats(uint8_t *constants, int offset, float *values, int count) { - float *floats = (float *)(&constants[offset]); +void kinc_g5_constant_buffer_set_floats(kinc_g5_constant_buffer_t *buffer, int offset, float *values, int count) { + float *floats = (float *)(&buffer->data[offset]); for (int i = 0; i < count; ++i) { floats[i] = values[i]; } } -static void setBool(uint8_t *constants, int offset, bool value) { - int *ints = (int *)(&constants[offset]); +void kinc_g5_constant_buffer_set_bool(kinc_g5_constant_buffer_t *buffer, int offset, bool value) { + int *ints = (int *)(&buffer->data[offset]); ints[0] = value ? 1 : 0; } -static void setMatrix4(uint8_t *constants, int offset, kinc_matrix4x4_t *value) { - float *floats = (float *)(&constants[offset]); - for (int y = 0; y < 4; ++y) { - for (int x = 0; x < 4; ++x) { - floats[x + y * 4] = kinc_matrix4x4_get(value, x, y); - } - } -} - -static void setMatrix3(uint8_t *constants, int offset, kinc_matrix3x3_t *value) { +static void set_matrix3(uint8_t *constants, int offset, kinc_matrix3x3_t *value) { float *floats = (float *)(&constants[offset]); for (int y = 0; y < 3; ++y) { for (int x = 0; x < 3; ++x) { @@ -61,52 +80,33 @@ static void setMatrix3(uint8_t *constants, int offset, kinc_matrix3x3_t *value) } } -void kinc_g5_constant_buffer_set_int(kinc_g5_constant_buffer_t *buffer, int offset, int value) { - setInt(buffer->data, offset, value); +void kinc_g5_constant_buffer_set_matrix3(kinc_g5_constant_buffer_t *buffer, int offset, kinc_matrix3x3_t *value) { + if (kinc_g5_transposeMat3) { + kinc_matrix3x3_t m = *value; + kinc_matrix3x3_transpose(&m); + set_matrix3(buffer->data, offset, &m); + } + else { + set_matrix3(buffer->data, offset, value); + } } -void kinc_g5_constant_buffer_set_float(kinc_g5_constant_buffer_t *buffer, int offset, float value) { - setFloat(buffer->data, offset, value); -} - -void kinc_g5_constant_buffer_set_float2(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2) { - setFloat2(buffer->data, offset, value1, value2); -} - -void kinc_g5_constant_buffer_set_float3(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2, float value3) { - setFloat3(buffer->data, offset, value1, value2, value3); -} - -void kinc_g5_constant_buffer_set_float4(kinc_g5_constant_buffer_t *buffer, int offset, float value1, float value2, float value3, float value4) { - setFloat4(buffer->data, offset, value1, value2, value3, value4); -} - -void kinc_g5_constant_buffer_set_floats(kinc_g5_constant_buffer_t *buffer, int offset, float *values, int count) { - setFloats(buffer->data, offset, values, count); -} - -void kinc_g5_constant_buffer_set_bool(kinc_g5_constant_buffer_t *buffer, int offset, bool value) { - setBool(buffer->data, offset, value); +static void set_matrix4(uint8_t *constants, int offset, kinc_matrix4x4_t *value) { + float *floats = (float *)(&constants[offset]); + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < 4; ++x) { + floats[x + y * 4] = kinc_matrix4x4_get(value, x, y); + } + } } void kinc_g5_constant_buffer_set_matrix4(kinc_g5_constant_buffer_t *buffer, int offset, kinc_matrix4x4_t *value) { if (kinc_g5_transposeMat4) { kinc_matrix4x4_t m = *value; kinc_matrix4x4_transpose(&m); - setMatrix4(buffer->data, offset, &m); + set_matrix4(buffer->data, offset, &m); } else { - setMatrix4(buffer->data, offset, value); - } -} - -void kinc_g5_constant_buffer_set_matrix3(kinc_g5_constant_buffer_t *buffer, int offset, kinc_matrix3x3_t *value) { - if (kinc_g5_transposeMat3) { - kinc_matrix3x3_t m = *value; - kinc_matrix3x3_transpose(&m); - setMatrix3(buffer->data, offset, &m); - } - else { - setMatrix3(buffer->data, offset, value); + set_matrix4(buffer->data, offset, value); } } diff --git a/Kinc/Sources/kinc/graphics5/constantbuffer.h b/Kinc/Sources/kinc/graphics5/constantbuffer.h index ce68967..9909752 100644 --- a/Kinc/Sources/kinc/graphics5/constantbuffer.h +++ b/Kinc/Sources/kinc/graphics5/constantbuffer.h @@ -76,6 +76,41 @@ KINC_FUNC void kinc_g5_constant_buffer_set_bool(kinc_g5_constant_buffer_t *buffe /// The value to assign to the constant/uniform KINC_FUNC void kinc_g5_constant_buffer_set_int(kinc_g5_constant_buffer_t *buffer, int offset, int value); +/// +/// Assigns two integers at an offset in a constant-buffer. +/// +/// The offset at which to write the data +/// The first value to write into the buffer +/// The second value to write into the buffer +KINC_FUNC void kinc_g5_constant_buffer_set_int2(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2); + +/// +/// Assigns three integers at an offset in a constant-buffer. +/// +/// The offset at which to write the data +/// The first value to write into the buffer +/// The second value to write into the buffer +/// The third value to write into the buffer/param> +KINC_FUNC void kinc_g5_constant_buffer_set_int3(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2, int value3); + +/// +/// Assigns four integers at an offset in a constant-buffer. +/// +/// The offset at which to write the data +/// The first value to write into the buffer +/// The second value to write into the buffer +/// The third value to write into the buffer/param> +/// The fourth value to write into the buffer +KINC_FUNC void kinc_g5_constant_buffer_set_int4(kinc_g5_constant_buffer_t *buffer, int offset, int value1, int value2, int value3, int value4); + +/// +/// Assigns a bunch of integers at an offset in a constant-buffer. +/// +/// The location of the constant/uniform to assign the values to +/// The values to write into the buffer +/// The number of values to write into the buffer +KINC_FUNC void kinc_g5_constant_buffer_set_ints(kinc_g5_constant_buffer_t *buffer, int offset, int *values, int count); + /// /// Assigns a float at an offset in a constant-buffer. /// diff --git a/Kinc/Sources/kinc/graphics5/graphics.h b/Kinc/Sources/kinc/graphics5/graphics.h index fd9ac6a..cdcf94e 100644 --- a/Kinc/Sources/kinc/graphics5/graphics.h +++ b/Kinc/Sources/kinc/graphics5/graphics.h @@ -36,7 +36,7 @@ KINC_FUNC bool kinc_g5_supports_raytracing(void); KINC_FUNC bool kinc_g5_supports_instanced_rendering(void); /// -/// Returns whether GPU-compute (the functions in kinc/graphics5/compute.h) is supported. +/// Returns whether GPU-compute (the functions in kinc/compute/compute.h) is supported. /// /// Whether GPU-compute is supported KINC_FUNC bool kinc_g5_supports_compute_shaders(void); diff --git a/Kinc/Sources/kinc/graphics5/pipeline.c.h b/Kinc/Sources/kinc/graphics5/pipeline.c.h index 5362889..7acd388 100644 --- a/Kinc/Sources/kinc/graphics5/pipeline.c.h +++ b/Kinc/Sources/kinc/graphics5/pipeline.c.h @@ -45,7 +45,3 @@ void kinc_g5_internal_pipeline_init(kinc_g5_pipeline_t *pipe) { pipe->depthAttachmentBits = 0; pipe->stencilAttachmentBits = 0; } - -void kinc_g5_internal_compute_pipeline_init(kinc_g5_compute_pipeline_t *pipe) { - pipe->compute_shader = NULL; -} diff --git a/Kinc/Sources/kinc/graphics5/pipeline.h b/Kinc/Sources/kinc/graphics5/pipeline.h index f8a20ea..4791669 100644 --- a/Kinc/Sources/kinc/graphics5/pipeline.h +++ b/Kinc/Sources/kinc/graphics5/pipeline.h @@ -113,12 +113,6 @@ typedef struct kinc_g5_pipeline { PipelineState5Impl impl; } kinc_g5_pipeline_t; -typedef struct kinc_g5_compute_pipeline { - struct kinc_g5_shader *compute_shader; - - ComputePipelineState5Impl impl; -} kinc_g5_compute_pipeline_t; - /// /// Initializes a pipeline. /// @@ -139,7 +133,6 @@ KINC_FUNC void kinc_g5_pipeline_destroy(kinc_g5_pipeline_t *pipeline); /// The pipeline to compile KINC_FUNC void kinc_g5_pipeline_compile(kinc_g5_pipeline_t *pipeline); -#ifndef KINC_KONG /// /// Searches for a constant/uniform and returns a constant-location which can be used to change the constant/uniform. /// @@ -155,44 +148,6 @@ KINC_FUNC kinc_g5_constant_location_t kinc_g5_pipeline_get_constant_location(kin /// The name of the texture-declaration to search for /// The texture-unit of the texture-declaration KINC_FUNC kinc_g5_texture_unit_t kinc_g5_pipeline_get_texture_unit(kinc_g5_pipeline_t *pipeline, const char *name); -#endif - -/// -/// Initializes a compute-pipeline. -/// -/// The pipeline to initialize -KINC_FUNC void kinc_g5_compute_pipeline_init(kinc_g5_compute_pipeline_t *pipeline); - -void kinc_g5_internal_compute_pipeline_init(kinc_g5_compute_pipeline_t *pipeline); - -/// -/// Destroys a compute-pipeline. -/// -/// The pipeline to destroy -KINC_FUNC void kinc_g5_compute_pipeline_destroy(kinc_g5_compute_pipeline_t *pipeline); - -/// -/// Compiles a compute-pipeline. After a pipeline has been compiled it is finalized. It cannot be compiled again and further changes to the pipeline are -/// ignored. -/// -/// The pipeline to compile -KINC_FUNC void kinc_g5_compute_pipeline_compile(kinc_g5_compute_pipeline_t *pipeline); - -/// -/// Searches for a constant/uniform and returns a constant-location which can be used to change the constant/uniform. -/// -/// The pipeline to search in -/// The name of the constant/uniform to find -/// The constant-location of the constant/uniform -KINC_FUNC kinc_g5_constant_location_t kinc_g5_compute_pipeline_get_constant_location(kinc_g5_compute_pipeline_t *pipeline, const char *name); - -/// -/// Searches for a texture-declaration and returns a texture-unit which can be used to assign a texture. -/// -/// The pipeline to search in -/// The name of the texture-declaration to search for -/// The texture-unit of the texture-declaration -KINC_FUNC kinc_g5_texture_unit_t kinc_g5_compute_pipeline_get_texture_unit(kinc_g5_compute_pipeline_t *pipeline, const char *name); #ifdef __cplusplus } diff --git a/Kinc/Sources/kinc/graphics5/rendertarget.h b/Kinc/Sources/kinc/graphics5/rendertarget.h index b9f736a..c3cf2dc 100644 --- a/Kinc/Sources/kinc/graphics5/rendertarget.h +++ b/Kinc/Sources/kinc/graphics5/rendertarget.h @@ -36,7 +36,7 @@ typedef struct kinc_g5_render_target { } kinc_g5_render_target_t; /// -/// Allocates and initializes a regular render-target. +/// Allocates and initializes a regular render-target. The contents of the render-target are undefined. /// /// /// @@ -49,7 +49,7 @@ KINC_FUNC void kinc_g5_render_target_init(kinc_g5_render_target_t *target, int w int stencilBufferBits); /// -/// Allocates and initializes a regular render-target. Can fall back to a regular render-target. +/// Allocates and initializes a regular render-target. Can fall back to a regular render-target. The contents of the render-target are undefined. /// /// /// @@ -63,7 +63,7 @@ KINC_FUNC void kinc_g5_render_target_init_with_multisampling(kinc_g5_render_targ int depthBufferBits, int stencilBufferBits, int samples_per_pixel); /// -/// Allocates and initializes a framebuffer. +/// Allocates and initializes a framebuffer. The contents of the framebuffer are undefined. /// /// /// @@ -76,7 +76,7 @@ KINC_FUNC void kinc_g5_render_target_init_framebuffer(kinc_g5_render_target_t *t int depthBufferBits, int stencilBufferBits); /// -/// Allocates and initializes a multisampled framebuffer. Can fall back to a regular framebuffer. +/// Allocates and initializes a multisampled framebuffer. Can fall back to a regular framebuffer. The contents of the framebuffer are undefined. /// /// /// @@ -91,7 +91,7 @@ KINC_FUNC void kinc_g5_render_target_init_framebuffer_with_multisampling(kinc_g5 int samples_per_pixel); /// -/// Allocates and initializes a render-target-cube-map. +/// Allocates and initializes a render-target-cube-map. The contents of the render-target are undefined. /// /// /// @@ -103,7 +103,7 @@ KINC_FUNC void kinc_g5_render_target_init_cube(kinc_g5_render_target_t *target, int stencilBufferBits); /// -/// Allocates and initializes a multisampled render-target-cube-map. Can fall back to a regular cube-map. +/// Allocates and initializes a multisampled render-target-cube-map. Can fall back to a regular cube-map. The contents of the render-target are undefined. /// /// /// diff --git a/Kinc/Sources/kinc/graphics5/texture.h b/Kinc/Sources/kinc/graphics5/texture.h index f9cb993..59b48a9 100644 --- a/Kinc/Sources/kinc/graphics5/texture.h +++ b/Kinc/Sources/kinc/graphics5/texture.h @@ -60,7 +60,7 @@ KINC_FUNC void kinc_g5_texture_init_non_sampled_access(kinc_g5_texture_t *textur /// The texture to destroy KINC_FUNC void kinc_g5_texture_destroy(kinc_g5_texture_t *texture); -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID KINC_FUNC void kinc_g5_texture_init_from_id(kinc_g5_texture_t *texture, unsigned texid); #endif @@ -73,7 +73,7 @@ KINC_FUNC void kinc_g5_texture_unlock(kinc_g5_texture_t *texture); /// KINC_FUNC void kinc_g5_texture_clear(kinc_g5_texture_t *texture, int x, int y, int z, int width, int height, int depth, unsigned color); -#if defined(KORE_IOS) || defined(KORE_MACOS) +#if defined(KINC_IOS) || defined(KINC_MACOS) KINC_FUNC void kinc_g5_texture_upload(kinc_g5_texture_t *texture, uint8_t *data); #endif diff --git a/Kinc/Sources/kinc/image.h b/Kinc/Sources/kinc/image.h index 96616e5..c98e12f 100644 --- a/Kinc/Sources/kinc/image.h +++ b/Kinc/Sources/kinc/image.h @@ -39,13 +39,13 @@ typedef struct kinc_image { unsigned internal_format; kinc_image_compression_t compression; void *data; - int data_size; + size_t data_size; } kinc_image_t; typedef struct kinc_image_read_callbacks { - int (*read)(void *user_data, void *data, size_t size); - void (*seek)(void *user_data, int pos); - int (*pos)(void *user_data); + size_t (*read)(void *user_data, void *data, size_t size); + void (*seek)(void *user_data, size_t pos); + size_t (*pos)(void *user_data); size_t (*size)(void *user_data); } kinc_image_read_callbacks_t; @@ -85,21 +85,66 @@ KINC_FUNC size_t kinc_image_size_from_encoded_bytes(void *data, size_t data_size /// /// Loads an image from a file. /// +/// The image-object to initialize with the data +/// The pre-allocated memory to load the image-data into +/// The file to load /// The memory size in bytes that will be used when loading the image KINC_FUNC size_t kinc_image_init_from_file(kinc_image_t *image, void *memory, const char *filename); +/// +/// Loads an image from a file with an enforced stride. +/// +/// The image-object to initialize with the data +/// The pre-allocated memory to load the image-data into +/// The file to load +/// The enforced stride in bytes +/// The memory size in bytes that will be used when loading the image +KINC_FUNC size_t kinc_image_init_from_file_with_stride(kinc_image_t *image, void *memory, const char *filename, uint32_t stride); + /// /// Loads an image file using callbacks. /// +/// The image-object to initialize with the data +/// The pre-allocated memory to load the image-data into +/// The callbacks that are used to query the data to encode +/// An optional pointer that is passed to the callbacks /// The memory size in bytes that will be used when loading the image KINC_FUNC size_t kinc_image_init_from_callbacks(kinc_image_t *image, void *memory, kinc_image_read_callbacks_t callbacks, void *user_data, const char *format); /// -/// Loads an image file from a memory. +/// Loads an image file using callbacks with an enforced stride. /// +/// The image-object to initialize with the data +/// The pre-allocated memory to load the image-data into +/// The callbacks that are used to query the data to encode +/// An optional pointer that is passed to the callbacks +/// The enforced stride in bytes +/// The memory size in bytes that will be used when loading the image +KINC_FUNC size_t kinc_image_init_from_callbacks_with_stride(kinc_image_t *image, void *memory, kinc_image_read_callbacks_t callbacks, void *user_data, + const char *format, uint32_t stride); + +/// +/// Loads an image file from memory. +/// +/// The image-object to initialize with the data +/// The pre-allocated memory to load the image-data into +/// The data to encode +/// The size of the data to encode in bytes /// The memory size in bytes that will be used when loading the image KINC_FUNC size_t kinc_image_init_from_encoded_bytes(kinc_image_t *image, void *memory, void *data, size_t data_size, const char *format); +/// +/// Loads an image file from memory with an enforced stride. +/// +/// The image-object to initialize with the data +/// The pre-allocated memory to load the image-data into +/// The data to encode +/// The size of the data to encode in bytes +/// The enforced stride in bytes +/// The memory size in bytes that will be used when loading the image +KINC_FUNC size_t kinc_image_init_from_encoded_bytes_with_stride(kinc_image_t *image, void *memory, void *data, size_t data_size, const char *format, + uint32_t stride); + /// /// Creates a 2D image from memory. /// @@ -147,7 +192,7 @@ KINC_FUNC int kinc_image_format_sizeof(kinc_image_format_t format); #include "image.h" -#ifdef KORE_LZ4X +#ifdef KINC_LZ4X #include #else #include @@ -181,7 +226,7 @@ static void *buffer_malloc(size_t size) { kinc_log(KINC_LOG_LEVEL_ERROR, "Not enough memory on image.c Buffer."); return NULL; } - *(size_t *)current = size; + memcpy(current, &size, sizeof(size_t)); last_allocated_pointer = current + sizeof(size_t); return current + sizeof(size_t); } @@ -213,9 +258,11 @@ static void *buffer_realloc(void *p, size_t size) { static void buffer_free(void *p) {} +#ifndef KINC_NO_STBI_BUFFER #define STBI_MALLOC(sz) buffer_malloc(sz) #define STBI_REALLOC(p, newsz) buffer_realloc(p, newsz) #define STBI_FREE(p) buffer_free(p) +#endif #define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_STATIC @@ -236,13 +283,13 @@ typedef struct { // fill 'data' with 'size' bytes. return number of bytes actually read static int stb_read(void *user, char *data, int size) { read_data *reader = (read_data *)user; - return reader->callbacks.read(reader->user_data, data, size); + return (int)reader->callbacks.read(reader->user_data, data, (size_t)size); } // skip the next 'n' bytes, or 'unget' the last -n bytes if negative static void stb_skip(void *user, int n) { read_data *reader = (read_data *)user; - reader->callbacks.seek(reader->user_data, reader->callbacks.pos(reader->user_data) + n); + reader->callbacks.seek(reader->user_data, reader->callbacks.pos(reader->user_data) + (size_t)n); } // returns nonzero if we are at end of file/data @@ -336,8 +383,8 @@ static size_t loadImageSize(kinc_image_read_callbacks_t callbacks, void *user_da } } -static bool loadImage(kinc_image_read_callbacks_t callbacks, void *user_data, const char *filename, uint8_t *output, int *outputSize, int *width, int *height, - kinc_image_compression_t *compression, kinc_image_format_t *format, unsigned *internalFormat) { +static bool loadImage(kinc_image_read_callbacks_t callbacks, void *user_data, const char *filename, uint8_t *output, size_t *outputSize, int *width, + int *height, kinc_image_compression_t *compression, kinc_image_format_t *format, unsigned *internalFormat, uint32_t forced_stride) { *format = KINC_IMAGE_FORMAT_RGBA32; if (endsWith(filename, "k")) { uint8_t data[4]; @@ -355,25 +402,25 @@ static bool loadImage(kinc_image_read_callbacks_t callbacks, void *user_data, co if (strcmp(fourcc, "LZ4 ") == 0) { *compression = KINC_IMAGE_COMPRESSION_NONE; *internalFormat = 0; - *outputSize = *width * *height * 4; + *outputSize = (size_t)(*width * *height * 4); callbacks.read(user_data, buffer, compressedSize); - LZ4_decompress_safe((char *)buffer, (char *)output, compressedSize, *outputSize); + LZ4_decompress_safe((char *)buffer, (char *)output, compressedSize, (int)*outputSize); return true; } else if (strcmp(fourcc, "LZ4F") == 0) { *compression = KINC_IMAGE_COMPRESSION_NONE; *internalFormat = 0; - *outputSize = *width * *height * 16; + *outputSize = (size_t)(*width * *height * 16); callbacks.read(user_data, buffer, compressedSize); - LZ4_decompress_safe((char *)buffer, (char *)output, compressedSize, *outputSize); + LZ4_decompress_safe((char *)buffer, (char *)output, compressedSize, (int)*outputSize); *format = KINC_IMAGE_FORMAT_RGBA128; return true; } else if (strcmp(fourcc, "ASTC") == 0) { *compression = KINC_IMAGE_COMPRESSION_ASTC; - *outputSize = *width * *height * 4; + *outputSize = (size_t)(*width * *height * 4); callbacks.read(user_data, buffer, compressedSize); - *outputSize = LZ4_decompress_safe((char *)buffer, (char *)output, compressedSize, *outputSize); + *outputSize = LZ4_decompress_safe((char *)buffer, (char *)output, compressedSize, (int)*outputSize); uint8_t blockdim_x = 6; uint8_t blockdim_y = 6; @@ -413,9 +460,9 @@ static bool loadImage(kinc_image_read_callbacks_t callbacks, void *user_data, co } else if (strcmp(fourcc, "DXT5") == 0) { *compression = KINC_IMAGE_COMPRESSION_DXT5; - *outputSize = *width * *height; + *outputSize = (size_t)(*width * *height); callbacks.read(user_data, buffer, compressedSize); - *outputSize = LZ4_decompress_safe((char *)buffer, (char *)output, compressedSize, *outputSize); + *outputSize = LZ4_decompress_safe((char *)buffer, (char *)output, compressedSize, (int)*outputSize); *internalFormat = 0; return true; } @@ -472,7 +519,7 @@ static bool loadImage(kinc_image_read_callbacks_t callbacks, void *user_data, co *compression = KINC_IMAGE_COMPRESSION_PVRTC; *internalFormat = 0; - *outputSize = ww * hh / 2; + *outputSize = (size_t)(ww * hh / 2); callbacks.read(user_data, output, *outputSize); return true; } @@ -495,7 +542,7 @@ static bool loadImage(kinc_image_read_callbacks_t callbacks, void *user_data, co kinc_log(KINC_LOG_LEVEL_ERROR, stbi_failure_reason()); return false; } - *outputSize = *width * *height * 16; + *outputSize = (size_t)(*width * *height * 16); memcpy(output, uncompressed, *outputSize); *format = KINC_IMAGE_FORMAT_RGBA128; buffer_offset = 0; @@ -520,6 +567,9 @@ static bool loadImage(kinc_image_read_callbacks_t callbacks, void *user_data, co kinc_log(KINC_LOG_LEVEL_ERROR, stbi_failure_reason()); return false; } + + uint32_t stride = forced_stride > 0 ? forced_stride : *width * 4; + for (int y = 0; y < *height; ++y) { for (int x = 0; x < *width; ++x) { float r = uncompressed[y * *width * 4 + x * 4 + 0] / 255.0f; @@ -529,13 +579,13 @@ static bool loadImage(kinc_image_read_callbacks_t callbacks, void *user_data, co r *= a; g *= a; b *= a; - output[y * *width * 4 + x * 4 + 0] = (uint8_t)kinc_round(r * 255.0f); - output[y * *width * 4 + x * 4 + 1] = (uint8_t)kinc_round(g * 255.0f); - output[y * *width * 4 + x * 4 + 2] = (uint8_t)kinc_round(b * 255.0f); - output[y * *width * 4 + x * 4 + 3] = (uint8_t)kinc_round(a * 255.0f); + output[y * stride + x * 4 + 0] = (uint8_t)kinc_round(r * 255.0f); + output[y * stride + x * 4 + 1] = (uint8_t)kinc_round(g * 255.0f); + output[y * stride + x * 4 + 2] = (uint8_t)kinc_round(b * 255.0f); + output[y * stride + x * 4 + 3] = (uint8_t)kinc_round(a * 255.0f); } } - *outputSize = *width * *height * 4; + *outputSize = (size_t)(*width * *height * 4); buffer_offset = 0; return true; } @@ -593,7 +643,7 @@ void kinc_image_init_from_bytes3d(kinc_image_t *image, void *data, int width, in image->data = data; } -static int read_callback(void *user_data, void *data, size_t size) { +static size_t read_callback(void *user_data, void *data, size_t size) { return kinc_file_reader_read((kinc_file_reader_t *)user_data, data, size); } @@ -601,11 +651,11 @@ static size_t size_callback(void *user_data) { return kinc_file_reader_size((kinc_file_reader_t *)user_data); } -static int pos_callback(void *user_data) { +static size_t pos_callback(void *user_data) { return kinc_file_reader_pos((kinc_file_reader_t *)user_data); } -static void seek_callback(void *user_data, int pos) { +static void seek_callback(void *user_data, size_t pos) { kinc_file_reader_seek((kinc_file_reader_t *)user_data, pos); } @@ -615,12 +665,12 @@ struct kinc_internal_image_memory { size_t offset; }; -static int memory_read_callback(void *user_data, void *data, size_t size) { +static size_t memory_read_callback(void *user_data, void *data, size_t size) { struct kinc_internal_image_memory *memory = (struct kinc_internal_image_memory *)user_data; size_t read_size = memory->size - memory->offset < size ? memory->size - memory->offset : size; memcpy(data, &memory->data[memory->offset], read_size); memory->offset += read_size; - return (int)read_size; + return read_size; } static size_t memory_size_callback(void *user_data) { @@ -628,14 +678,14 @@ static size_t memory_size_callback(void *user_data) { return memory->size; } -static int memory_pos_callback(void *user_data) { +static size_t memory_pos_callback(void *user_data) { struct kinc_internal_image_memory *memory = (struct kinc_internal_image_memory *)user_data; - return (int)memory->offset; + return memory->offset; } -static void memory_seek_callback(void *user_data, int pos) { +static void memory_seek_callback(void *user_data, size_t pos) { struct kinc_internal_image_memory *memory = (struct kinc_internal_image_memory *)user_data; - memory->offset = (size_t)pos; + memory->offset = pos; } size_t kinc_image_size_from_callbacks(kinc_image_read_callbacks_t callbacks, void *user_data, const char *filename) { @@ -673,14 +723,21 @@ size_t kinc_image_size_from_encoded_bytes(void *data, size_t data_size, const ch return loadImageSize(callbacks, &image_memory, format); } -size_t kinc_image_init_from_callbacks(kinc_image_t *image, void *memory, kinc_image_read_callbacks_t callbacks, void *user_data, const char *filename) { - int dataSize; - loadImage(callbacks, user_data, filename, memory, &dataSize, &image->width, &image->height, &image->compression, &image->format, &image->internal_format); +size_t kinc_image_init_from_callbacks_with_stride(kinc_image_t *image, void *memory, kinc_image_read_callbacks_t callbacks, void *user_data, + const char *filename, uint32_t stride) { + size_t dataSize = 0; + loadImage(callbacks, user_data, filename, memory, &dataSize, &image->width, &image->height, &image->compression, &image->format, &image->internal_format, + stride); image->data = memory; + image->data_size = dataSize; return dataSize; } -size_t kinc_image_init_from_file(kinc_image_t *image, void *memory, const char *filename) { +size_t kinc_image_init_from_callbacks(kinc_image_t *image, void *memory, kinc_image_read_callbacks_t callbacks, void *user_data, const char *filename) { + return kinc_image_init_from_callbacks_with_stride(image, memory, callbacks, user_data, filename, 0); +} + +size_t kinc_image_init_from_file_with_stride(kinc_image_t *image, void *memory, const char *filename, uint32_t stride) { kinc_file_reader_t reader; if (kinc_file_reader_open(&reader, filename, KINC_FILE_TYPE_ASSET)) { kinc_image_read_callbacks_t callbacks; @@ -689,8 +746,9 @@ size_t kinc_image_init_from_file(kinc_image_t *image, void *memory, const char * callbacks.pos = pos_callback; callbacks.seek = seek_callback; - int dataSize; - loadImage(callbacks, &reader, filename, memory, &dataSize, &image->width, &image->height, &image->compression, &image->format, &image->internal_format); + size_t dataSize = 0; + loadImage(callbacks, &reader, filename, memory, &dataSize, &image->width, &image->height, &image->compression, &image->format, &image->internal_format, + stride); kinc_file_reader_close(&reader); image->data = memory; image->data_size = dataSize; @@ -700,7 +758,11 @@ size_t kinc_image_init_from_file(kinc_image_t *image, void *memory, const char * return 0; } -size_t kinc_image_init_from_encoded_bytes(kinc_image_t *image, void *memory, void *data, size_t data_size, const char *format) { +size_t kinc_image_init_from_file(kinc_image_t *image, void *memory, const char *filename) { + return kinc_image_init_from_file_with_stride(image, memory, filename, 0); +} + +size_t kinc_image_init_from_encoded_bytes_with_stride(kinc_image_t *image, void *memory, void *data, size_t data_size, const char *format, uint32_t stride) { kinc_image_read_callbacks_t callbacks; callbacks.read = memory_read_callback; callbacks.size = memory_size_callback; @@ -712,14 +774,19 @@ size_t kinc_image_init_from_encoded_bytes(kinc_image_t *image, void *memory, voi image_memory.size = data_size; image_memory.offset = 0; - int dataSize; - loadImage(callbacks, &image_memory, format, memory, &dataSize, &image->width, &image->height, &image->compression, &image->format, &image->internal_format); + size_t dataSize = 0; + loadImage(callbacks, &image_memory, format, memory, &dataSize, &image->width, &image->height, &image->compression, &image->format, &image->internal_format, + stride); image->data = memory; image->data_size = dataSize; image->depth = 1; return dataSize; } +size_t kinc_image_init_from_encoded_bytes(kinc_image_t *image, void *memory, void *data, size_t data_size, const char *format) { + return kinc_image_init_from_encoded_bytes_with_stride(image, memory, data, data_size, format, 0); +} + void kinc_image_destroy(kinc_image_t *image) { // user has to free the data image->data = NULL; diff --git a/Kinc/Sources/kinc/input/acceleration.h b/Kinc/Sources/kinc/input/acceleration.h index 390545d..d924d87 100644 --- a/Kinc/Sources/kinc/input/acceleration.h +++ b/Kinc/Sources/kinc/input/acceleration.h @@ -25,6 +25,7 @@ void kinc_internal_on_acceleration(float x, float y, float z); #ifdef KINC_IMPLEMENTATION #include +#include void (*acceleration_callback)(float /*x*/, float /*y*/, float /*z*/) = NULL; diff --git a/Kinc/Sources/kinc/input/gamepad.h b/Kinc/Sources/kinc/input/gamepad.h index f2d7b77..d2583ce 100644 --- a/Kinc/Sources/kinc/input/gamepad.h +++ b/Kinc/Sources/kinc/input/gamepad.h @@ -10,17 +10,35 @@ extern "C" { #endif +#define KINC_GAMEPAD_MAX_COUNT 12 + +/// +/// Sets the gamepad-connect-callback which is called when a gamepad is connected. +/// +/// The callback +/// Userdata you will receive back as the 2nd callback parameter +KINC_FUNC void kinc_gamepad_set_connect_callback(void (*value)(int /*gamepad*/, void * /*userdata*/), void *userdata); + +/// +/// Sets the gamepad-disconnect-callback which is called when a gamepad is disconnected. +/// +/// The callback +/// Userdata you will receive back as the 2nd callback parameter +KINC_FUNC void kinc_gamepad_set_disconnect_callback(void (*value)(int /*gamepad*/, void * /*userdata*/), void *userdata); + /// /// Sets the gamepad-axis-callback which is called with data about changing gamepad-sticks. /// /// The callback -KINC_FUNC void kinc_gamepad_set_axis_callback(void (*value)(int /*gamepad*/, int /*axis*/, float /*value*/)); +/// Userdata you will receive back as the 4th callback parameter +KINC_FUNC void kinc_gamepad_set_axis_callback(void (*value)(int /*gamepad*/, int /*axis*/, float /*value*/, void * /*userdata*/), void *userdata); /// /// Sets the gamepad-button-callback which is called with data about changing gamepad-buttons. /// /// The callback -KINC_FUNC void kinc_gamepad_set_button_callback(void (*value)(int /*gamepad*/, int /*button*/, float /*value*/)); +/// Userdata you will receive back as the 4th callback parameter +KINC_FUNC void kinc_gamepad_set_button_callback(void (*value)(int /*gamepad*/, int /*button*/, float /*value*/, void * /*userdata*/), void *userdata); /// /// Returns a vendor-name for a gamepad. @@ -51,6 +69,8 @@ KINC_FUNC bool kinc_gamepad_connected(int gamepad); /// Rumble-strength for the right motor between 0 and 1 KINC_FUNC void kinc_gamepad_rumble(int gamepad, float left, float right); +void kinc_internal_gamepad_trigger_connect(int gamepad); +void kinc_internal_gamepad_trigger_disconnect(int gamepad); void kinc_internal_gamepad_trigger_axis(int gamepad, int axis, float value); void kinc_internal_gamepad_trigger_button(int gamepad, int button, float value); @@ -61,27 +81,58 @@ void kinc_internal_gamepad_trigger_button(int gamepad, int button, float value); #ifdef KINC_IMPLEMENTATION #include +#include -static void (*gamepad_axis_callback)(int /*gamepad*/, int /*axis*/, float /*value*/) = NULL; -static void (*gamepad_button_callback)(int /*gamepad*/, int /*button*/, float /*value*/) = NULL; +static void (*gamepad_connect_callback)(int /*gamepad*/, void * /*userdata*/) = NULL; +static void *gamepad_connect_callback_userdata = NULL; +static void (*gamepad_disconnect_callback)(int /*gamepad*/, void * /*userdata*/) = NULL; +static void *gamepad_disconnect_callback_userdata = NULL; +static void (*gamepad_axis_callback)(int /*gamepad*/, int /*axis*/, float /*value*/, void * /*userdata*/) = NULL; +static void *gamepad_axis_callback_userdata = NULL; +static void (*gamepad_button_callback)(int /*gamepad*/, int /*button*/, float /*value*/, void * /*userdata*/) = NULL; +static void *gamepad_button_callback_userdata = NULL; -void kinc_gamepad_set_axis_callback(void (*value)(int /*gamepad*/, int /*axis*/, float /*value*/)) { - gamepad_axis_callback = value; +void kinc_gamepad_set_connect_callback(void (*value)(int /*gamepad*/, void * /*userdata*/), void *userdata) { + gamepad_connect_callback = value; + gamepad_connect_callback_userdata = userdata; } -void kinc_gamepad_set_button_callback(void (*value)(int /*gamepad*/, int /*button*/, float /*value*/)) { +void kinc_gamepad_set_disconnect_callback(void (*value)(int /*gamepad*/, void * /*userdata*/), void *userdata) { + gamepad_disconnect_callback = value; + gamepad_disconnect_callback_userdata = userdata; +} + +void kinc_gamepad_set_axis_callback(void (*value)(int /*gamepad*/, int /*axis*/, float /*value*/, void * /*userdata*/), void *userdata) { + gamepad_axis_callback = value; + gamepad_axis_callback_userdata = userdata; +} + +void kinc_gamepad_set_button_callback(void (*value)(int /*gamepad*/, int /*button*/, float /*value*/, void * /*userdata*/), void *userdata) { gamepad_button_callback = value; + gamepad_button_callback_userdata = userdata; +} + +void kinc_internal_gamepad_trigger_connect(int gamepad) { + if (gamepad_connect_callback != NULL) { + gamepad_connect_callback(gamepad, gamepad_connect_callback_userdata); + } +} + +void kinc_internal_gamepad_trigger_disconnect(int gamepad) { + if (gamepad_disconnect_callback != NULL) { + gamepad_disconnect_callback(gamepad, gamepad_disconnect_callback_userdata); + } } void kinc_internal_gamepad_trigger_axis(int gamepad, int axis, float value) { if (gamepad_axis_callback != NULL) { - gamepad_axis_callback(gamepad, axis, value); + gamepad_axis_callback(gamepad, axis, value, gamepad_axis_callback_userdata); } } void kinc_internal_gamepad_trigger_button(int gamepad, int button, float value) { if (gamepad_button_callback != NULL) { - gamepad_button_callback(gamepad, button, value); + gamepad_button_callback(gamepad, button, value, gamepad_button_callback_userdata); } } diff --git a/Kinc/Sources/kinc/input/keyboard.h b/Kinc/Sources/kinc/input/keyboard.h index 0315390..788f845 100644 --- a/Kinc/Sources/kinc/input/keyboard.h +++ b/Kinc/Sources/kinc/input/keyboard.h @@ -245,6 +245,7 @@ void kinc_internal_keyboard_trigger_key_press(unsigned character); #ifdef KINC_IMPLEMENTATION #include +#include static void (*keyboard_key_down_callback)(int /*key_code*/, void * /*data*/) = NULL; static void *keyboard_key_down_callback_data = NULL; diff --git a/Kinc/Sources/kinc/input/mouse.h b/Kinc/Sources/kinc/input/mouse.h index 3d76dd0..3fec181 100644 --- a/Kinc/Sources/kinc/input/mouse.h +++ b/Kinc/Sources/kinc/input/mouse.h @@ -140,6 +140,7 @@ void kinc_internal_mouse_window_deactivated(int window); #define KINC_IMPLEMENTATION #include +#include static void (*mouse_press_callback)(int /*window*/, int /*button*/, int /*x*/, int /*y*/, void * /*data*/) = NULL; static void *mouse_press_callback_data = NULL; diff --git a/Kinc/Sources/kinc/input/pen.h b/Kinc/Sources/kinc/input/pen.h index d16e957..a20e1e2 100644 --- a/Kinc/Sources/kinc/input/pen.h +++ b/Kinc/Sources/kinc/input/pen.h @@ -61,6 +61,7 @@ void kinc_internal_eraser_trigger_release(int window, int x, int y, float pressu #ifdef KINC_IMPLEMENTATION #include +#include static void (*pen_press_callback)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/) = NULL; static void (*pen_move_callback)(int /*window*/, int /*x*/, int /*y*/, float /*pressure*/) = NULL; diff --git a/Kinc/Sources/kinc/input/rotation.h b/Kinc/Sources/kinc/input/rotation.h index 3bf2dd1..7a715be 100644 --- a/Kinc/Sources/kinc/input/rotation.h +++ b/Kinc/Sources/kinc/input/rotation.h @@ -25,6 +25,7 @@ void kinc_internal_on_rotation(float x, float y, float z); #ifdef KINC_IMPLEMENTATION #include +#include static void (*rotation_callback)(float /*x*/, float /*y*/, float /*z*/) = NULL; diff --git a/Kinc/Sources/kinc/input/surface.h b/Kinc/Sources/kinc/input/surface.h index f61d8df..d08c50b 100644 --- a/Kinc/Sources/kinc/input/surface.h +++ b/Kinc/Sources/kinc/input/surface.h @@ -39,6 +39,7 @@ void kinc_internal_surface_trigger_touch_end(int index, int x, int y); #ifdef KINC_IMPLEMENTATION #include +#include static void (*surface_touch_start_callback)(int /*index*/, int /*x*/, int /*y*/) = NULL; static void (*surface_move_callback)(int /*index*/, int /*x*/, int /*y*/) = NULL; diff --git a/Kinc/Sources/kinc/io/filereader.h b/Kinc/Sources/kinc/io/filereader.h index 428492b..87b7ecb 100644 --- a/Kinc/Sources/kinc/io/filereader.h +++ b/Kinc/Sources/kinc/io/filereader.h @@ -2,10 +2,6 @@ #include -#if defined(KORE_SONY) || defined(KORE_SWITCH) -#include -#endif - #include #include #include @@ -18,11 +14,11 @@ extern "C" { #endif -#ifndef KORE_DEBUGDIR -#define KORE_DEBUGDIR "Deployment" +#ifndef KINC_DEBUGDIR +#define KINC_DEBUGDIR "Deployment" #endif -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID struct AAsset; struct __sFILE; typedef struct __sFILE FILE; @@ -31,26 +27,16 @@ typedef struct __sFILE FILE; #define KINC_FILE_TYPE_ASSET 0 #define KINC_FILE_TYPE_SAVE 1 -#ifdef KORE_ANDROID typedef struct kinc_file_reader { - int pos; - int size; - FILE *file; - struct AAsset *asset; - int type; + void *data; // A file handle or a more complex structure + size_t size; + size_t offset; // Needed by some implementations + + bool (*close)(struct kinc_file_reader *reader); + size_t (*read)(struct kinc_file_reader *reader, void *data, size_t size); + size_t (*pos)(struct kinc_file_reader *reader); + bool (*seek)(struct kinc_file_reader *reader, size_t pos); } kinc_file_reader_t; -#else -typedef struct kinc_file_reader { - void *file; - int size; - int type; - int mode; - bool mounted; -#if defined(KORE_SONY) || defined(KORE_SWITCH) - kinc_file_reader_impl_t impl; -#endif -} kinc_file_reader_t; -#endif /// /// Opens a file for reading. @@ -61,11 +47,27 @@ typedef struct kinc_file_reader { /// Whether the file could be opened KINC_FUNC bool kinc_file_reader_open(kinc_file_reader_t *reader, const char *filepath, int type); +/// +/// Opens a memory area for reading using the file reader API. +/// +/// The reader to initialize for reading +/// A pointer to the memory area to read +/// The size of the memory area +/// This function always returns true +KINC_FUNC bool kinc_file_reader_from_memory(kinc_file_reader_t *reader, void *data, size_t size); + +/// +/// Registers a file reader callback. +/// +/// The function to call when opening a file +KINC_FUNC void kinc_file_reader_set_callback(bool (*callback)(kinc_file_reader_t *reader, const char *filename, int type)); + /// /// Closes a file. /// /// The file to close -KINC_FUNC void kinc_file_reader_close(kinc_file_reader_t *reader); +/// Whether the file could be closed +KINC_FUNC bool kinc_file_reader_close(kinc_file_reader_t *reader); /// /// Reads data from a file starting from the current reading-position and increases the reading-position accordingly. @@ -74,7 +76,7 @@ KINC_FUNC void kinc_file_reader_close(kinc_file_reader_t *reader); /// A pointer to write the data to /// The amount of data to read in bytes /// The number of bytes that were read - can be less than size if there is not enough data in the file -KINC_FUNC int kinc_file_reader_read(kinc_file_reader_t *reader, void *data, size_t size); +KINC_FUNC size_t kinc_file_reader_read(kinc_file_reader_t *reader, void *data, size_t size); /// /// Figures out the size of a file. @@ -88,14 +90,15 @@ KINC_FUNC size_t kinc_file_reader_size(kinc_file_reader_t *reader); /// /// The reader which's reading-position to figure out /// The current reading-position -KINC_FUNC int kinc_file_reader_pos(kinc_file_reader_t *reader); +KINC_FUNC size_t kinc_file_reader_pos(kinc_file_reader_t *reader); /// /// Sets the reading-position manually. /// /// The reader which's reading-position to set /// The reading-position to set -KINC_FUNC void kinc_file_reader_seek(kinc_file_reader_t *reader, int pos); +/// Whether the reading position could be set +KINC_FUNC bool kinc_file_reader_seek(kinc_file_reader_t *reader, size_t pos); /// /// Interprets four bytes starting at the provided pointer as a little-endian float. @@ -179,6 +182,8 @@ KINC_FUNC int8_t kinc_read_s8(uint8_t *data); void kinc_internal_set_files_location(char *dir); char *kinc_internal_get_files_location(void); +bool kinc_internal_file_reader_callback(kinc_file_reader_t *reader, const char *filename, int type); +bool kinc_internal_file_reader_open(kinc_file_reader_t *reader, const char *filename, int type); #ifdef KINC_IMPLEMENTATION_IO #define KINC_IMPLEMENTATION @@ -192,41 +197,67 @@ char *kinc_internal_get_files_location(void); #include #define KINC_IMPLEMENTATION -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID #include #endif #include #include #include -#ifdef KORE_WINDOWS +#ifdef KINC_MICROSOFT #include #include #endif -#ifndef KORE_CONSOLE +static bool memory_close_callback(kinc_file_reader_t *reader) { + return true; +} -#ifdef KORE_IOS +static size_t memory_read_callback(kinc_file_reader_t *reader, void *data, size_t size) { + size_t read_size = reader->size - reader->offset < size ? reader->size - reader->offset : size; + memcpy(data, (uint8_t *)reader->data + reader->offset, read_size); + reader->offset += read_size; + return read_size; +} + +static size_t memory_pos_callback(kinc_file_reader_t *reader) { + return reader->offset; +} + +static bool memory_seek_callback(kinc_file_reader_t *reader, size_t pos) { + reader->offset = pos; + return true; +} + +bool kinc_file_reader_from_memory(kinc_file_reader_t *reader, void *data, size_t size) { + memset(reader, 0, sizeof(kinc_file_reader_t)); + reader->data = data; + reader->size = size; + reader->read = memory_read_callback; + reader->pos = memory_pos_callback; + reader->seek = memory_seek_callback; + reader->close = memory_close_callback; + return true; +} + +#ifdef KINC_IOS const char *iphonegetresourcepath(void); #endif -#ifdef KORE_MACOS +#ifdef KINC_MACOS const char *macgetresourcepath(void); #endif -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_MICROSOFT) #include #endif -#ifdef KORE_TIZEN -#include -#endif - -#ifdef KORE_PI -#define KORE_LINUX +#ifdef KINC_RASPBERRY_PI +#define KINC_LINUX #endif static char *fileslocation = NULL; -#ifdef KORE_WINDOWS +static bool (*file_reader_callback)(kinc_file_reader_t *reader, const char *filename, int type) = NULL; +#ifdef KINC_MICROSOFT static wchar_t wfilepath[1001]; #endif @@ -238,34 +269,85 @@ char *kinc_internal_get_files_location(void) { return fileslocation; } -#ifdef KORE_WINDOWSAPP +bool kinc_internal_file_reader_callback(kinc_file_reader_t *reader, const char *filename, int type) { + return file_reader_callback ? file_reader_callback(reader, filename, type) : false; +} + +#ifdef KINC_WINDOWSAPP void kinc_internal_uwp_installed_location_path(char *path); #endif -#ifndef KORE_ANDROID -bool kinc_file_reader_open(kinc_file_reader_t *reader, const char *filename, int type) { - memset(reader, 0, sizeof(kinc_file_reader_t)); +#if defined(KINC_MICROSOFT) +static size_t kinc_libc_file_reader_read(kinc_file_reader_t *reader, void *data, size_t size) { + DWORD readBytes = 0; + if (ReadFile(reader->data, data, (DWORD)size, &readBytes, NULL)) { + return (size_t)readBytes; + } + else { + return 0; + } +} + +static bool kinc_libc_file_reader_seek(kinc_file_reader_t *reader, size_t pos) { + // TODO: make this 64-bit compliant + SetFilePointer(reader->data, (LONG)pos, NULL, FILE_BEGIN); + return true; +} + +static bool kinc_libc_file_reader_close(kinc_file_reader_t *reader) { + CloseHandle(reader->data); + return true; +} + +static size_t kinc_libc_file_reader_pos(kinc_file_reader_t *reader) { + // TODO: make this 64-bit compliant + return (size_t)SetFilePointer(reader->data, 0, NULL, FILE_CURRENT); +} +#else +static size_t kinc_libc_file_reader_read(kinc_file_reader_t *reader, void *data, size_t size) { + return fread(data, 1, size, (FILE *)reader->data); +} + +static bool kinc_libc_file_reader_seek(kinc_file_reader_t *reader, size_t pos) { + fseek((FILE *)reader->data, pos, SEEK_SET); + return true; +} + +static bool kinc_libc_file_reader_close(kinc_file_reader_t *reader) { + if (reader->data != NULL) { + fclose((FILE *)reader->data); + reader->data = NULL; + } + return true; +} + +static size_t kinc_libc_file_reader_pos(kinc_file_reader_t *reader) { + return ftell((FILE *)reader->data); +} +#endif + +bool kinc_internal_file_reader_open(kinc_file_reader_t *reader, const char *filename, int type) { char filepath[1001]; -#ifdef KORE_IOS +#ifdef KINC_IOS strcpy(filepath, type == KINC_FILE_TYPE_SAVE ? kinc_internal_save_path() : iphonegetresourcepath()); if (type != KINC_FILE_TYPE_SAVE) { strcat(filepath, "/"); - strcat(filepath, KORE_DEBUGDIR); + strcat(filepath, KINC_DEBUGDIR); strcat(filepath, "/"); } strcat(filepath, filename); #endif -#ifdef KORE_MACOS +#ifdef KINC_MACOS strcpy(filepath, type == KINC_FILE_TYPE_SAVE ? kinc_internal_save_path() : macgetresourcepath()); if (type != KINC_FILE_TYPE_SAVE) { strcat(filepath, "/"); - strcat(filepath, KORE_DEBUGDIR); + strcat(filepath, KINC_DEBUGDIR); strcat(filepath, "/"); } strcat(filepath, filename); #endif -#ifdef KORE_WINDOWS +#ifdef KINC_MICROSOFT if (type == KINC_FILE_TYPE_SAVE) { strcpy(filepath, kinc_internal_save_path()); strcat(filepath, filename); @@ -278,12 +360,12 @@ bool kinc_file_reader_open(kinc_file_reader_t *reader, const char *filename, int if (filepath[i] == '/') filepath[i] = '\\'; #endif -#ifdef KORE_WINDOWSAPP +#ifdef KINC_WINDOWSAPP kinc_internal_uwp_installed_location_path(filepath); strcat(filepath, "\\"); strcat(filepath, filename); #endif -#ifdef KORE_LINUX +#if defined(KINC_LINUX) || defined(KINC_ANDROID) if (type == KINC_FILE_TYPE_SAVE) { strcpy(filepath, kinc_internal_save_path()); strcat(filepath, filename); @@ -292,26 +374,16 @@ bool kinc_file_reader_open(kinc_file_reader_t *reader, const char *filename, int strcpy(filepath, filename); } #endif -#ifdef KORE_WASM +#ifdef KINC_WASM strcpy(filepath, filename); #endif -#ifdef KORE_EMSCRIPTEN - strcpy(filepath, KORE_DEBUGDIR); - strcat(filepath, "/"); - strcat(filepath, filename); -#endif -#ifdef KORE_TIZEN - for (int i = 0; i < Tizen::App::App::GetInstance()->GetAppDataPath().GetLength(); ++i) { - wchar_t c; - Tizen::App::App::GetInstance()->GetAppDataPath().GetCharAt(i, c); - filepath[i] = (char)c; - } - filepath[Tizen::App::App::GetInstance()->GetAppDataPath().GetLength()] = 0; +#ifdef KINC_EMSCRIPTEN + strcpy(filepath, KINC_DEBUGDIR); strcat(filepath, "/"); strcat(filepath, filename); #endif -#ifdef KORE_WINDOWS +#ifdef KINC_MICROSOFT // Drive letter or network bool isAbsolute = (filename[1] == ':' && filename[2] == '\\') || (filename[0] == '\\' && filename[1] == '\\'); #else @@ -327,111 +399,69 @@ bool kinc_file_reader_open(kinc_file_reader_t *reader, const char *filename, int strcat(filepath, filename); } -#ifdef KORE_WINDOWS +#ifdef KINC_MICROSOFT MultiByteToWideChar(CP_UTF8, 0, filepath, -1, wfilepath, 1000); - reader->file = CreateFileW(wfilepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (reader->file == INVALID_HANDLE_VALUE) { + reader->data = CreateFileW(wfilepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (reader->data == INVALID_HANDLE_VALUE) { return false; } #else - reader->file = fopen(filepath, "rb"); - if (reader->file == NULL) { + reader->data = fopen(filepath, "rb"); + if (reader->data == NULL) { return false; } #endif -#ifdef KORE_WINDOWS - reader->size = GetFileSize(reader->file, NULL); +#ifdef KINC_MICROSOFT + // TODO: make this 64-bit compliant + reader->size = (size_t)GetFileSize(reader->data, NULL); #else - fseek((FILE *)reader->file, 0, SEEK_END); - reader->size = (int)ftell((FILE *)reader->file); - fseek((FILE *)reader->file, 0, SEEK_SET); + fseek((FILE *)reader->data, 0, SEEK_END); + reader->size = ftell((FILE *)reader->data); + fseek((FILE *)reader->data, 0, SEEK_SET); #endif + + reader->read = kinc_libc_file_reader_read; + reader->seek = kinc_libc_file_reader_seek; + reader->close = kinc_libc_file_reader_close; + reader->pos = kinc_libc_file_reader_pos; + return true; } + +#if !defined(KINC_ANDROID) && !defined(KINC_CONSOLE) +bool kinc_file_reader_open(kinc_file_reader_t *reader, const char *filename, int type) { + memset(reader, 0, sizeof(*reader)); + return kinc_internal_file_reader_callback(reader, filename, type) || kinc_internal_file_reader_open(reader, filename, type); +} #endif -int kinc_file_reader_read(kinc_file_reader_t *reader, void *data, size_t size) { -#ifdef KORE_ANDROID - if (reader->file != NULL) { - return (int)fread(data, 1, size, reader->file); - } - else { - int read = AAsset_read(reader->asset, data, size); - reader->pos += read; - return read; - } -#elif defined(KORE_WINDOWS) - DWORD readBytes = 0; - if (ReadFile(reader->file, data, (DWORD)size, &readBytes, NULL)) { - return (int)readBytes; - } - else { - return 0; - } -#else - return (int)fread(data, 1, size, (FILE *)reader->file); -#endif +void kinc_file_reader_set_callback(bool (*callback)(kinc_file_reader_t *reader, const char *filename, int type)) { + file_reader_callback = callback; } -void kinc_file_reader_seek(kinc_file_reader_t *reader, int pos) { -#ifdef KORE_ANDROID - if (reader->file != NULL) { - fseek(reader->file, pos, SEEK_SET); - } - else { - AAsset_seek(reader->asset, pos, SEEK_SET); - reader->pos = pos; - } -#elif defined(KORE_WINDOWS) - SetFilePointer(reader->file, pos, NULL, FILE_BEGIN); -#else - fseek((FILE *)reader->file, pos, SEEK_SET); -#endif +size_t kinc_file_reader_read(kinc_file_reader_t *reader, void *data, size_t size) { + return reader->read(reader, data, size); } -void kinc_file_reader_close(kinc_file_reader_t *reader) { -#ifdef KORE_ANDROID - if (reader->file != NULL) { - fclose(reader->file); - reader->file = NULL; - } - if (reader->asset != NULL) { - AAsset_close(reader->asset); - reader->asset = NULL; - } -#elif defined(KORE_WINDOWS) - CloseHandle(reader->file); -#else - if (reader->file == NULL) { - return; - } - fclose((FILE *)reader->file); - reader->file = NULL; -#endif +bool kinc_file_reader_seek(kinc_file_reader_t *reader, size_t pos) { + return reader->seek(reader, pos); } -int kinc_file_reader_pos(kinc_file_reader_t *reader) { -#ifdef KORE_ANDROID - if (reader->file != NULL) - return (int)ftell(reader->file); - else - return reader->pos; -#elif defined(KORE_WINDOWS) - return (int)SetFilePointer(reader->file, 0, NULL, FILE_CURRENT); -#else - return (int)ftell((FILE *)reader->file); -#endif +bool kinc_file_reader_close(kinc_file_reader_t *reader) { + return reader->close(reader); +} + +size_t kinc_file_reader_pos(kinc_file_reader_t *reader) { + return reader->pos(reader); } size_t kinc_file_reader_size(kinc_file_reader_t *reader) { - return (size_t)reader->size; + return reader->size; } -#endif - float kinc_read_f32le(uint8_t *data) { -#ifdef KORE_LITTLE_ENDIAN // speed optimization +#ifdef KINC_LITTLE_ENDIAN // speed optimization return *(float *)data; #else // works on all architectures int i = (data[0] << 0) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); @@ -440,7 +470,7 @@ float kinc_read_f32le(uint8_t *data) { } float kinc_read_f32be(uint8_t *data) { -#ifdef KORE_BIG_ENDIAN // speed optimization +#ifdef KINC_BIG_ENDIAN // speed optimization return *(float *)data; #else // works on all architectures int i = (data[3] << 0) | (data[2] << 8) | (data[1] << 16) | (data[0] << 24); @@ -449,7 +479,7 @@ float kinc_read_f32be(uint8_t *data) { } uint64_t kinc_read_u64le(uint8_t *data) { -#ifdef KORE_LITTLE_ENDIAN +#ifdef KINC_LITTLE_ENDIAN return *(uint64_t *)data; #else return ((uint64_t)data[0] << 0) | ((uint64_t)data[1] << 8) | ((uint64_t)data[2] << 16) | ((uint64_t)data[3] << 24) | ((uint64_t)data[4] << 32) | @@ -458,7 +488,7 @@ uint64_t kinc_read_u64le(uint8_t *data) { } uint64_t kinc_read_u64be(uint8_t *data) { -#ifdef KORE_BIG_ENDIAN +#ifdef KINC_BIG_ENDIAN return *(uint64_t *)data; #else return ((uint64_t)data[7] << 0) | ((uint64_t)data[6] << 8) | ((uint64_t)data[5] << 16) | ((uint64_t)data[4] << 24) | ((uint64_t)data[3] << 32) | @@ -467,7 +497,7 @@ uint64_t kinc_read_u64be(uint8_t *data) { } int64_t kinc_read_s64le(uint8_t *data) { -#ifdef KORE_LITTLE_ENDIAN +#ifdef KINC_LITTLE_ENDIAN return *(int64_t *)data; #else return ((int64_t)data[0] << 0) | ((int64_t)data[1] << 8) | ((int64_t)data[2] << 16) | ((int64_t)data[3] << 24) | ((int64_t)data[4] << 32) | @@ -476,7 +506,7 @@ int64_t kinc_read_s64le(uint8_t *data) { } int64_t kinc_read_s64be(uint8_t *data) { -#ifdef KORE_BIG_ENDIAN +#ifdef KINC_BIG_ENDIAN return *(int64_t *)data; #else return ((int64_t)data[7] << 0) | ((int64_t)data[6] << 8) | ((int64_t)data[5] << 16) | ((int64_t)data[4] << 24) | ((int64_t)data[3] << 32) | @@ -485,7 +515,7 @@ int64_t kinc_read_s64be(uint8_t *data) { } uint32_t kinc_read_u32le(uint8_t *data) { -#ifdef KORE_LITTLE_ENDIAN +#ifdef KINC_LITTLE_ENDIAN return *(uint32_t *)data; #else return (data[0] << 0) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); @@ -493,7 +523,7 @@ uint32_t kinc_read_u32le(uint8_t *data) { } uint32_t kinc_read_u32be(uint8_t *data) { -#ifdef KORE_BIG_ENDIAN +#ifdef KINC_BIG_ENDIAN return *(uint32_t *)data; #else return (data[3] << 0) | (data[2] << 8) | (data[1] << 16) | (data[0] << 24); @@ -501,7 +531,7 @@ uint32_t kinc_read_u32be(uint8_t *data) { } int32_t kinc_read_s32le(uint8_t *data) { -#ifdef KORE_LITTLE_ENDIAN +#ifdef KINC_LITTLE_ENDIAN return *(int32_t *)data; #else return (data[0] << 0) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); @@ -509,7 +539,7 @@ int32_t kinc_read_s32le(uint8_t *data) { } int32_t kinc_read_s32be(uint8_t *data) { -#ifdef KORE_BIG_ENDIAN +#ifdef KINC_BIG_ENDIAN return *(int32_t *)data; #else return (data[3] << 0) | (data[2] << 8) | (data[1] << 16) | (data[0] << 24); @@ -517,7 +547,7 @@ int32_t kinc_read_s32be(uint8_t *data) { } uint16_t kinc_read_u16le(uint8_t *data) { -#ifdef KORE_LITTLE_ENDIAN +#ifdef KINC_LITTLE_ENDIAN return *(uint16_t *)data; #else return (data[0] << 0) | (data[1] << 8); @@ -525,7 +555,7 @@ uint16_t kinc_read_u16le(uint8_t *data) { } uint16_t kinc_read_u16be(uint8_t *data) { -#ifdef KORE_BIG_ENDIAN +#ifdef KINC_BIG_ENDIAN return *(uint16_t *)data; #else return (data[1] << 0) | (data[0] << 8); @@ -533,7 +563,7 @@ uint16_t kinc_read_u16be(uint8_t *data) { } int16_t kinc_read_s16le(uint8_t *data) { -#ifdef KORE_LITTLE_ENDIAN +#ifdef KINC_LITTLE_ENDIAN return *(int16_t *)data; #else return (data[0] << 0) | (data[1] << 8); @@ -541,7 +571,7 @@ int16_t kinc_read_s16le(uint8_t *data) { } int16_t kinc_read_s16be(uint8_t *data) { -#ifdef KORE_BIG_ENDIAN +#ifdef KINC_BIG_ENDIAN return *(int16_t *)data; #else return (data[1] << 0) | (data[0] << 8); diff --git a/Kinc/Sources/kinc/io/filewriter.h b/Kinc/Sources/kinc/io/filewriter.h index c4b84f7..68528e6 100644 --- a/Kinc/Sources/kinc/io/filewriter.h +++ b/Kinc/Sources/kinc/io/filewriter.h @@ -47,7 +47,7 @@ KINC_FUNC void kinc_file_writer_close(kinc_file_writer_t *writer); #ifdef KINC_IMPLEMENTATION -#if !defined(KORE_CONSOLE) +#if !defined(KINC_CONSOLE) #include "filewriter.h" @@ -60,11 +60,11 @@ KINC_FUNC void kinc_file_writer_close(kinc_file_writer_t *writer); #include #include -#if defined(KORE_WINDOWS) +#if defined(KINC_WINDOWS) #include #endif -#if defined(KORE_PS4) || defined(KORE_SWITCH) +#if defined(KINC_PS4) || defined(KINC_SWITCH) #define MOUNT_SAVES bool mountSaveData(bool); void unmountSaveData(); @@ -83,7 +83,7 @@ bool kinc_file_writer_open(kinc_file_writer_t *writer, const char *filepath) { strcpy(path, kinc_internal_save_path()); strcat(path, filepath); -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS wchar_t wpath[MAX_PATH]; MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH); writer->file = CreateFileW(wpath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -99,7 +99,7 @@ bool kinc_file_writer_open(kinc_file_writer_t *writer, const char *filepath) { void kinc_file_writer_close(kinc_file_writer_t *writer) { if (writer->file != NULL) { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS CloseHandle(writer->file); #else fclose((FILE *)writer->file); @@ -115,7 +115,7 @@ void kinc_file_writer_close(kinc_file_writer_t *writer) { } void kinc_file_writer_write(kinc_file_writer_t *writer, void *data, int size) { -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS DWORD written = 0; WriteFile(writer->file, data, (DWORD)size, &written, NULL); #else diff --git a/Kinc/Sources/kinc/io/lz4/lz4.c b/Kinc/Sources/kinc/io/lz4/lz4.c index 08fe324..7c1b81a 100644 --- a/Kinc/Sources/kinc/io/lz4/lz4.c +++ b/Kinc/Sources/kinc/io/lz4/lz4.c @@ -1314,7 +1314,7 @@ _output_error: return (int)(-(((const char *)ip) - source)) - 1; } -#ifndef KORE_LZ4X +#ifndef KINC_LZ4X int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize) { return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, full, 0, noDict, (BYTE *)dest, NULL, 0); } diff --git a/Kinc/Sources/kinc/libs/lz4x.h b/Kinc/Sources/kinc/libs/lz4x.h index c3459f2..1d99658 100644 --- a/Kinc/Sources/kinc/libs/lz4x.h +++ b/Kinc/Sources/kinc/libs/lz4x.h @@ -445,7 +445,9 @@ static size_t kwrite(void* src, size_t size, char* dst, size_t* offset, int maxO } //int decompress() -#ifdef KORE_LZ4X +#ifdef KINC_LZ4X +#include + int LZ4_decompress_safe(const char *source, char *buf, int compressedSize, int maxOutputSize) { size_t read_offset = 0; diff --git a/Kinc/Sources/kinc/libs/stb_sprintf.h b/Kinc/Sources/kinc/libs/stb_sprintf.h deleted file mode 100644 index ca432a6..0000000 --- a/Kinc/Sources/kinc/libs/stb_sprintf.h +++ /dev/null @@ -1,1906 +0,0 @@ -// stb_sprintf - v1.10 - public domain snprintf() implementation -// originally by Jeff Roberts / RAD Game Tools, 2015/10/20 -// http://github.com/nothings/stb -// -// allowed types: sc uidBboXx p AaGgEef n -// lengths : hh h ll j z t I64 I32 I -// -// Contributors: -// Fabian "ryg" Giesen (reformatting) -// github:aganm (attribute format) -// -// Contributors (bugfixes): -// github:d26435 -// github:trex78 -// github:account-login -// Jari Komppa (SI suffixes) -// Rohit Nirmal -// Marcin Wojdyr -// Leonard Ritter -// Stefano Zanotti -// Adam Allison -// Arvid Gerstmann -// Markus Kolb -// -// LICENSE: -// -// See end of file for license information. - -#ifndef STB_SPRINTF_H_INCLUDE -#define STB_SPRINTF_H_INCLUDE - -/* -Single file sprintf replacement. - -Originally written by Jeff Roberts at RAD Game Tools - 2015/10/20. -Hereby placed in public domain. - -This is a full sprintf replacement that supports everything that -the C runtime sprintfs support, including float/double, 64-bit integers, -hex floats, field parameters (%*.*d stuff), length reads backs, etc. - -Why would you need this if sprintf already exists? Well, first off, -it's *much* faster (see below). It's also much smaller than the CRT -versions code-space-wise. We've also added some simple improvements -that are super handy (commas in thousands, callbacks at buffer full, -for example). Finally, the format strings for MSVC and GCC differ -for 64-bit integers (among other small things), so this lets you use -the same format strings in cross platform code. - -It uses the standard single file trick of being both the header file -and the source itself. If you just include it normally, you just get -the header file function definitions. To get the code, you include -it from a C or C++ file and define STB_SPRINTF_IMPLEMENTATION first. - -It only uses va_args macros from the C runtime to do it's work. It -does cast doubles to S64s and shifts and divides U64s, which does -drag in CRT code on most platforms. - -It compiles to roughly 8K with float support, and 4K without. -As a comparison, when using MSVC static libs, calling sprintf drags -in 16K. - -API: -==== -int stbsp_sprintf( char * buf, char const * fmt, ... ) -int stbsp_snprintf( char * buf, int count, char const * fmt, ... ) - Convert an arg list into a buffer. stbsp_snprintf always returns - a zero-terminated string (unlike regular snprintf). - -int stbsp_vsprintf( char * buf, char const * fmt, va_list va ) -int stbsp_vsnprintf( char * buf, int count, char const * fmt, va_list va ) - Convert a va_list arg list into a buffer. stbsp_vsnprintf always returns - a zero-terminated string (unlike regular snprintf). - -int stbsp_vsprintfcb( STBSP_SPRINTFCB * callback, void * user, char * buf, char const * fmt, va_list va ) - typedef char * STBSP_SPRINTFCB( char const * buf, void * user, int len ); - Convert into a buffer, calling back every STB_SPRINTF_MIN chars. - Your callback can then copy the chars out, print them or whatever. - This function is actually the workhorse for everything else. - The buffer you pass in must hold at least STB_SPRINTF_MIN characters. - // you return the next buffer to use or 0 to stop converting - -void stbsp_set_separators( char comma, char period ) - Set the comma and period characters to use. - -FLOATS/DOUBLES: -=============== -This code uses a internal float->ascii conversion method that uses -doubles with error correction (double-doubles, for ~105 bits of -precision). This conversion is round-trip perfect - that is, an atof -of the values output here will give you the bit-exact double back. - -One difference is that our insignificant digits will be different than -with MSVC or GCC (but they don't match each other either). We also -don't attempt to find the minimum length matching float (pre-MSVC15 -doesn't either). - -If you don't need float or doubles at all, define STB_SPRINTF_NOFLOAT -and you'll save 4K of code space. - -64-BIT INTS: -============ -This library also supports 64-bit integers and you can use MSVC style or -GCC style indicators (%I64d or %lld). It supports the C99 specifiers -for size_t and ptr_diff_t (%jd %zd) as well. - -EXTRAS: -======= -Like some GCCs, for integers and floats, you can use a ' (single quote) -specifier and commas will be inserted on the thousands: "%'d" on 12345 -would print 12,345. - -For integers and floats, you can use a "$" specifier and the number -will be converted to float and then divided to get kilo, mega, giga or -tera and then printed, so "%$d" 1000 is "1.0 k", "%$.2d" 2536000 is -"2.53 M", etc. For byte values, use two $:s, like "%$$d" to turn -2536000 to "2.42 Mi". If you prefer JEDEC suffixes to SI ones, use three -$:s: "%$$$d" -> "2.42 M". To remove the space between the number and the -suffix, add "_" specifier: "%_$d" -> "2.53M". - -In addition to octal and hexadecimal conversions, you can print -integers in binary: "%b" for 256 would print 100. - -PERFORMANCE vs MSVC 2008 32-/64-bit (GCC is even slower than MSVC): -=================================================================== -"%d" across all 32-bit ints (4.8x/4.0x faster than 32-/64-bit MSVC) -"%24d" across all 32-bit ints (4.5x/4.2x faster) -"%x" across all 32-bit ints (4.5x/3.8x faster) -"%08x" across all 32-bit ints (4.3x/3.8x faster) -"%f" across e-10 to e+10 floats (7.3x/6.0x faster) -"%e" across e-10 to e+10 floats (8.1x/6.0x faster) -"%g" across e-10 to e+10 floats (10.0x/7.1x faster) -"%f" for values near e-300 (7.9x/6.5x faster) -"%f" for values near e+300 (10.0x/9.1x faster) -"%e" for values near e-300 (10.1x/7.0x faster) -"%e" for values near e+300 (9.2x/6.0x faster) -"%.320f" for values near e-300 (12.6x/11.2x faster) -"%a" for random values (8.6x/4.3x faster) -"%I64d" for 64-bits with 32-bit values (4.8x/3.4x faster) -"%I64d" for 64-bits > 32-bit values (4.9x/5.5x faster) -"%s%s%s" for 64 char strings (7.1x/7.3x faster) -"...512 char string..." ( 35.0x/32.5x faster!) -*/ - -#if defined(__clang__) - #if defined(__has_feature) && defined(__has_attribute) - #if __has_feature(address_sanitizer) - #if __has_attribute(__no_sanitize__) - #define STBSP__ASAN __attribute__((__no_sanitize__("address"))) - #elif __has_attribute(__no_sanitize_address__) - #define STBSP__ASAN __attribute__((__no_sanitize_address__)) - #elif __has_attribute(__no_address_safety_analysis__) - #define STBSP__ASAN __attribute__((__no_address_safety_analysis__)) - #endif - #endif - #endif -#elif defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) - #if defined(__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__ - #define STBSP__ASAN __attribute__((__no_sanitize_address__)) - #endif -#endif - -#ifndef STBSP__ASAN -#define STBSP__ASAN -#endif - -#ifdef STB_SPRINTF_STATIC -#define STBSP__PUBLICDEC static -#define STBSP__PUBLICDEF static STBSP__ASAN -#else -#ifdef __cplusplus -#define STBSP__PUBLICDEC extern "C" -#define STBSP__PUBLICDEF extern "C" STBSP__ASAN -#else -#define STBSP__PUBLICDEC extern -#define STBSP__PUBLICDEF STBSP__ASAN -#endif -#endif - -#if defined(__has_attribute) - #if __has_attribute(format) - #define STBSP__ATTRIBUTE_FORMAT(fmt,va) __attribute__((format(printf,fmt,va))) - #endif -#endif - -#ifndef STBSP__ATTRIBUTE_FORMAT -#define STBSP__ATTRIBUTE_FORMAT(fmt,va) -#endif - -#ifdef _MSC_VER -#define STBSP__NOTUSED(v) (void)(v) -#else -#define STBSP__NOTUSED(v) (void)sizeof(v) -#endif - -#include // for va_arg(), va_list() -#include // size_t, ptrdiff_t - -#ifndef STB_SPRINTF_MIN -#define STB_SPRINTF_MIN 512 // how many characters per callback -#endif -typedef char *STBSP_SPRINTFCB(const char *buf, void *user, int len); - -#ifndef STB_SPRINTF_DECORATE -#define STB_SPRINTF_DECORATE(name) stbsp_##name // define this before including if you want to change the names -#endif - -STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsprintf)(char *buf, char const *fmt, va_list va); -STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsnprintf)(char *buf, int count, char const *fmt, va_list va); -STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(sprintf)(char *buf, char const *fmt, ...) STBSP__ATTRIBUTE_FORMAT(2,3); -STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(snprintf)(char *buf, int count, char const *fmt, ...) STBSP__ATTRIBUTE_FORMAT(3,4); - -STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char *buf, char const *fmt, va_list va); -STBSP__PUBLICDEC void STB_SPRINTF_DECORATE(set_separators)(char comma, char period); - -#endif // STB_SPRINTF_H_INCLUDE - -#ifdef STB_SPRINTF_IMPLEMENTATION - -#define stbsp__uint32 unsigned int -#define stbsp__int32 signed int - -#ifdef _MSC_VER -#define stbsp__uint64 unsigned __int64 -#define stbsp__int64 signed __int64 -#else -#define stbsp__uint64 unsigned long long -#define stbsp__int64 signed long long -#endif -#define stbsp__uint16 unsigned short - -#ifndef stbsp__uintptr -#if defined(__ppc64__) || defined(__powerpc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__s390x__) -#define stbsp__uintptr stbsp__uint64 -#else -#define stbsp__uintptr stbsp__uint32 -#endif -#endif - -#ifndef STB_SPRINTF_MSVC_MODE // used for MSVC2013 and earlier (MSVC2015 matches GCC) -#if defined(_MSC_VER) && (_MSC_VER < 1900) -#define STB_SPRINTF_MSVC_MODE -#endif -#endif - -#ifdef STB_SPRINTF_NOUNALIGNED // define this before inclusion to force stbsp_sprintf to always use aligned accesses -#define STBSP__UNALIGNED(code) -#else -#define STBSP__UNALIGNED(code) code -#endif - -#ifndef STB_SPRINTF_NOFLOAT -// internal float utility functions -static stbsp__int32 stbsp__real_to_str(char const **start, stbsp__uint32 *len, char *out, stbsp__int32 *decimal_pos, double value, stbsp__uint32 frac_digits); -static stbsp__int32 stbsp__real_to_parts(stbsp__int64 *bits, stbsp__int32 *expo, double value); -#define STBSP__SPECIAL 0x7000 -#endif - -static char stbsp__period = '.'; -static char stbsp__comma = ','; -static struct -{ - short temp; // force next field to be 2-byte aligned - char pair[201]; -} stbsp__digitpair = -{ - 0, - "00010203040506070809101112131415161718192021222324" - "25262728293031323334353637383940414243444546474849" - "50515253545556575859606162636465666768697071727374" - "75767778798081828384858687888990919293949596979899" -}; - -STBSP__PUBLICDEF void STB_SPRINTF_DECORATE(set_separators)(char pcomma, char pperiod) -{ - stbsp__period = pperiod; - stbsp__comma = pcomma; -} - -#define STBSP__LEFTJUST 1 -#define STBSP__LEADINGPLUS 2 -#define STBSP__LEADINGSPACE 4 -#define STBSP__LEADING_0X 8 -#define STBSP__LEADINGZERO 16 -#define STBSP__INTMAX 32 -#define STBSP__TRIPLET_COMMA 64 -#define STBSP__NEGATIVE 128 -#define STBSP__METRIC_SUFFIX 256 -#define STBSP__HALFWIDTH 512 -#define STBSP__METRIC_NOSPACE 1024 -#define STBSP__METRIC_1024 2048 -#define STBSP__METRIC_JEDEC 4096 - -static void stbsp__lead_sign(stbsp__uint32 fl, char *sign) -{ - sign[0] = 0; - if (fl & STBSP__NEGATIVE) { - sign[0] = 1; - sign[1] = '-'; - } else if (fl & STBSP__LEADINGSPACE) { - sign[0] = 1; - sign[1] = ' '; - } else if (fl & STBSP__LEADINGPLUS) { - sign[0] = 1; - sign[1] = '+'; - } -} - -static STBSP__ASAN stbsp__uint32 stbsp__strlen_limited(char const *s, stbsp__uint32 limit) -{ - char const * sn = s; - - // get up to 4-byte alignment - for (;;) { - if (((stbsp__uintptr)sn & 3) == 0) - break; - - if (!limit || *sn == 0) - return (stbsp__uint32)(sn - s); - - ++sn; - --limit; - } - - // scan over 4 bytes at a time to find terminating 0 - // this will intentionally scan up to 3 bytes past the end of buffers, - // but becase it works 4B aligned, it will never cross page boundaries - // (hence the STBSP__ASAN markup; the over-read here is intentional - // and harmless) - while (limit >= 4) { - stbsp__uint32 v = *(stbsp__uint32 *)sn; - // bit hack to find if there's a 0 byte in there - if ((v - 0x01010101) & (~v) & 0x80808080UL) - break; - - sn += 4; - limit -= 4; - } - - // handle the last few characters to find actual size - while (limit && *sn) { - ++sn; - --limit; - } - - return (stbsp__uint32)(sn - s); -} - -STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char *buf, char const *fmt, va_list va) -{ - static char hex[] = "0123456789abcdefxp"; - static char hexu[] = "0123456789ABCDEFXP"; - char *bf; - char const *f; - int tlen = 0; - - bf = buf; - f = fmt; - for (;;) { - stbsp__int32 fw, pr, tz; - stbsp__uint32 fl; - - // macros for the callback buffer stuff - #define stbsp__chk_cb_bufL(bytes) \ - { \ - int len = (int)(bf - buf); \ - if ((len + (bytes)) >= STB_SPRINTF_MIN) { \ - tlen += len; \ - if (0 == (bf = buf = callback(buf, user, len))) \ - goto done; \ - } \ - } - #define stbsp__chk_cb_buf(bytes) \ - { \ - if (callback) { \ - stbsp__chk_cb_bufL(bytes); \ - } \ - } - #define stbsp__flush_cb() \ - { \ - stbsp__chk_cb_bufL(STB_SPRINTF_MIN - 1); \ - } // flush if there is even one byte in the buffer - #define stbsp__cb_buf_clamp(cl, v) \ - cl = v; \ - if (callback) { \ - int lg = STB_SPRINTF_MIN - (int)(bf - buf); \ - if (cl > lg) \ - cl = lg; \ - } - - // fast copy everything up to the next % (or end of string) - for (;;) { - while (((stbsp__uintptr)f) & 3) { - schk1: - if (f[0] == '%') - goto scandd; - schk2: - if (f[0] == 0) - goto endfmt; - stbsp__chk_cb_buf(1); - *bf++ = f[0]; - ++f; - } - for (;;) { - // Check if the next 4 bytes contain %(0x25) or end of string. - // Using the 'hasless' trick: - // https://graphics.stanford.edu/~seander/bithacks.html#HasLessInWord - stbsp__uint32 v, c; - v = *(stbsp__uint32 *)f; - c = (~v) & 0x80808080; - if (((v ^ 0x25252525) - 0x01010101) & c) - goto schk1; - if ((v - 0x01010101) & c) - goto schk2; - if (callback) - if ((STB_SPRINTF_MIN - (int)(bf - buf)) < 4) - goto schk1; - #ifdef STB_SPRINTF_NOUNALIGNED - if(((stbsp__uintptr)bf) & 3) { - bf[0] = f[0]; - bf[1] = f[1]; - bf[2] = f[2]; - bf[3] = f[3]; - } else - #endif - { - *(stbsp__uint32 *)bf = v; - } - bf += 4; - f += 4; - } - } - scandd: - - ++f; - - // ok, we have a percent, read the modifiers first - fw = 0; - pr = -1; - fl = 0; - tz = 0; - - // flags - for (;;) { - switch (f[0]) { - // if we have left justify - case '-': - fl |= STBSP__LEFTJUST; - ++f; - continue; - // if we have leading plus - case '+': - fl |= STBSP__LEADINGPLUS; - ++f; - continue; - // if we have leading space - case ' ': - fl |= STBSP__LEADINGSPACE; - ++f; - continue; - // if we have leading 0x - case '#': - fl |= STBSP__LEADING_0X; - ++f; - continue; - // if we have thousand commas - case '\'': - fl |= STBSP__TRIPLET_COMMA; - ++f; - continue; - // if we have kilo marker (none->kilo->kibi->jedec) - case '$': - if (fl & STBSP__METRIC_SUFFIX) { - if (fl & STBSP__METRIC_1024) { - fl |= STBSP__METRIC_JEDEC; - } else { - fl |= STBSP__METRIC_1024; - } - } else { - fl |= STBSP__METRIC_SUFFIX; - } - ++f; - continue; - // if we don't want space between metric suffix and number - case '_': - fl |= STBSP__METRIC_NOSPACE; - ++f; - continue; - // if we have leading zero - case '0': - fl |= STBSP__LEADINGZERO; - ++f; - goto flags_done; - default: goto flags_done; - } - } - flags_done: - - // get the field width - if (f[0] == '*') { - fw = va_arg(va, stbsp__uint32); - ++f; - } else { - while ((f[0] >= '0') && (f[0] <= '9')) { - fw = fw * 10 + f[0] - '0'; - f++; - } - } - // get the precision - if (f[0] == '.') { - ++f; - if (f[0] == '*') { - pr = va_arg(va, stbsp__uint32); - ++f; - } else { - pr = 0; - while ((f[0] >= '0') && (f[0] <= '9')) { - pr = pr * 10 + f[0] - '0'; - f++; - } - } - } - - // handle integer size overrides - switch (f[0]) { - // are we halfwidth? - case 'h': - fl |= STBSP__HALFWIDTH; - ++f; - if (f[0] == 'h') - ++f; // QUARTERWIDTH - break; - // are we 64-bit (unix style) - case 'l': - fl |= ((sizeof(long) == 8) ? STBSP__INTMAX : 0); - ++f; - if (f[0] == 'l') { - fl |= STBSP__INTMAX; - ++f; - } - break; - // are we 64-bit on intmax? (c99) - case 'j': - fl |= (sizeof(size_t) == 8) ? STBSP__INTMAX : 0; - ++f; - break; - // are we 64-bit on size_t or ptrdiff_t? (c99) - case 'z': - fl |= (sizeof(ptrdiff_t) == 8) ? STBSP__INTMAX : 0; - ++f; - break; - case 't': - fl |= (sizeof(ptrdiff_t) == 8) ? STBSP__INTMAX : 0; - ++f; - break; - // are we 64-bit (msft style) - case 'I': - if ((f[1] == '6') && (f[2] == '4')) { - fl |= STBSP__INTMAX; - f += 3; - } else if ((f[1] == '3') && (f[2] == '2')) { - f += 3; - } else { - fl |= ((sizeof(void *) == 8) ? STBSP__INTMAX : 0); - ++f; - } - break; - default: break; - } - - // handle each replacement - switch (f[0]) { - #define STBSP__NUMSZ 512 // big enough for e308 (with commas) or e-307 - char num[STBSP__NUMSZ]; - char lead[8]; - char tail[8]; - char *s; - char const *h; - stbsp__uint32 l, n, cs; - stbsp__uint64 n64; -#ifndef STB_SPRINTF_NOFLOAT - double fv; -#endif - stbsp__int32 dp; - char const *sn; - - case 's': - // get the string - s = va_arg(va, char *); - if (s == 0) - s = (char *)"null"; - // get the length, limited to desired precision - // always limit to ~0u chars since our counts are 32b - l = stbsp__strlen_limited(s, (pr >= 0) ? pr : ~0u); - lead[0] = 0; - tail[0] = 0; - pr = 0; - dp = 0; - cs = 0; - // copy the string in - goto scopy; - - case 'c': // char - // get the character - s = num + STBSP__NUMSZ - 1; - *s = (char)va_arg(va, int); - l = 1; - lead[0] = 0; - tail[0] = 0; - pr = 0; - dp = 0; - cs = 0; - goto scopy; - - case 'n': // weird write-bytes specifier - { - int *d = va_arg(va, int *); - *d = tlen + (int)(bf - buf); - } break; - -#ifdef STB_SPRINTF_NOFLOAT - case 'A': // float - case 'a': // hex float - case 'G': // float - case 'g': // float - case 'E': // float - case 'e': // float - case 'f': // float - va_arg(va, double); // eat it - s = (char *)"No float"; - l = 8; - lead[0] = 0; - tail[0] = 0; - pr = 0; - cs = 0; - STBSP__NOTUSED(dp); - goto scopy; -#else - case 'A': // hex float - case 'a': // hex float - h = (f[0] == 'A') ? hexu : hex; - fv = va_arg(va, double); - if (pr == -1) - pr = 6; // default is 6 - // read the double into a string - if (stbsp__real_to_parts((stbsp__int64 *)&n64, &dp, fv)) - fl |= STBSP__NEGATIVE; - - s = num + 64; - - stbsp__lead_sign(fl, lead); - - if (dp == -1023) - dp = (n64) ? -1022 : 0; - else - n64 |= (((stbsp__uint64)1) << 52); - n64 <<= (64 - 56); - if (pr < 15) - n64 += ((((stbsp__uint64)8) << 56) >> (pr * 4)); -// add leading chars - -#ifdef STB_SPRINTF_MSVC_MODE - *s++ = '0'; - *s++ = 'x'; -#else - lead[1 + lead[0]] = '0'; - lead[2 + lead[0]] = 'x'; - lead[0] += 2; -#endif - *s++ = h[(n64 >> 60) & 15]; - n64 <<= 4; - if (pr) - *s++ = stbsp__period; - sn = s; - - // print the bits - n = pr; - if (n > 13) - n = 13; - if (pr > (stbsp__int32)n) - tz = pr - n; - pr = 0; - while (n--) { - *s++ = h[(n64 >> 60) & 15]; - n64 <<= 4; - } - - // print the expo - tail[1] = h[17]; - if (dp < 0) { - tail[2] = '-'; - dp = -dp; - } else - tail[2] = '+'; - n = (dp >= 1000) ? 6 : ((dp >= 100) ? 5 : ((dp >= 10) ? 4 : 3)); - tail[0] = (char)n; - for (;;) { - tail[n] = '0' + dp % 10; - if (n <= 3) - break; - --n; - dp /= 10; - } - - dp = (int)(s - sn); - l = (int)(s - (num + 64)); - s = num + 64; - cs = 1 + (3 << 24); - goto scopy; - - case 'G': // float - case 'g': // float - h = (f[0] == 'G') ? hexu : hex; - fv = va_arg(va, double); - if (pr == -1) - pr = 6; - else if (pr == 0) - pr = 1; // default is 6 - // read the double into a string - if (stbsp__real_to_str(&sn, &l, num, &dp, fv, (pr - 1) | 0x80000000)) - fl |= STBSP__NEGATIVE; - - // clamp the precision and delete extra zeros after clamp - n = pr; - if (l > (stbsp__uint32)pr) - l = pr; - while ((l > 1) && (pr) && (sn[l - 1] == '0')) { - --pr; - --l; - } - - // should we use %e - if ((dp <= -4) || (dp > (stbsp__int32)n)) { - if (pr > (stbsp__int32)l) - pr = l - 1; - else if (pr) - --pr; // when using %e, there is one digit before the decimal - goto doexpfromg; - } - // this is the insane action to get the pr to match %g semantics for %f - if (dp > 0) { - pr = (dp < (stbsp__int32)l) ? l - dp : 0; - } else { - pr = -dp + ((pr > (stbsp__int32)l) ? (stbsp__int32) l : pr); - } - goto dofloatfromg; - - case 'E': // float - case 'e': // float - h = (f[0] == 'E') ? hexu : hex; - fv = va_arg(va, double); - if (pr == -1) - pr = 6; // default is 6 - // read the double into a string - if (stbsp__real_to_str(&sn, &l, num, &dp, fv, pr | 0x80000000)) - fl |= STBSP__NEGATIVE; - doexpfromg: - tail[0] = 0; - stbsp__lead_sign(fl, lead); - if (dp == STBSP__SPECIAL) { - s = (char *)sn; - cs = 0; - pr = 0; - goto scopy; - } - s = num + 64; - // handle leading chars - *s++ = sn[0]; - - if (pr) - *s++ = stbsp__period; - - // handle after decimal - if ((l - 1) > (stbsp__uint32)pr) - l = pr + 1; - for (n = 1; n < l; n++) - *s++ = sn[n]; - // trailing zeros - tz = pr - (l - 1); - pr = 0; - // dump expo - tail[1] = h[0xe]; - dp -= 1; - if (dp < 0) { - tail[2] = '-'; - dp = -dp; - } else - tail[2] = '+'; -#ifdef STB_SPRINTF_MSVC_MODE - n = 5; -#else - n = (dp >= 100) ? 5 : 4; -#endif - tail[0] = (char)n; - for (;;) { - tail[n] = '0' + dp % 10; - if (n <= 3) - break; - --n; - dp /= 10; - } - cs = 1 + (3 << 24); // how many tens - goto flt_lead; - - case 'f': // float - fv = va_arg(va, double); - doafloat: - // do kilos - if (fl & STBSP__METRIC_SUFFIX) { - double divisor; - divisor = 1000.0f; - if (fl & STBSP__METRIC_1024) - divisor = 1024.0; - while (fl < 0x4000000) { - if ((fv < divisor) && (fv > -divisor)) - break; - fv /= divisor; - fl += 0x1000000; - } - } - if (pr == -1) - pr = 6; // default is 6 - // read the double into a string - if (stbsp__real_to_str(&sn, &l, num, &dp, fv, pr)) - fl |= STBSP__NEGATIVE; - dofloatfromg: - tail[0] = 0; - stbsp__lead_sign(fl, lead); - if (dp == STBSP__SPECIAL) { - s = (char *)sn; - cs = 0; - pr = 0; - goto scopy; - } - s = num + 64; - - // handle the three decimal varieties - if (dp <= 0) { - stbsp__int32 i; - // handle 0.000*000xxxx - *s++ = '0'; - if (pr) - *s++ = stbsp__period; - n = -dp; - if ((stbsp__int32)n > pr) - n = pr; - i = n; - while (i) { - if ((((stbsp__uintptr)s) & 3) == 0) - break; - *s++ = '0'; - --i; - } - while (i >= 4) { - *(stbsp__uint32 *)s = 0x30303030; - s += 4; - i -= 4; - } - while (i) { - *s++ = '0'; - --i; - } - if ((stbsp__int32)(l + n) > pr) - l = pr - n; - i = l; - while (i) { - *s++ = *sn++; - --i; - } - tz = pr - (n + l); - cs = 1 + (3 << 24); // how many tens did we write (for commas below) - } else { - cs = (fl & STBSP__TRIPLET_COMMA) ? ((600 - (stbsp__uint32)dp) % 3) : 0; - if ((stbsp__uint32)dp >= l) { - // handle xxxx000*000.0 - n = 0; - for (;;) { - if ((fl & STBSP__TRIPLET_COMMA) && (++cs == 4)) { - cs = 0; - *s++ = stbsp__comma; - } else { - *s++ = sn[n]; - ++n; - if (n >= l) - break; - } - } - if (n < (stbsp__uint32)dp) { - n = dp - n; - if ((fl & STBSP__TRIPLET_COMMA) == 0) { - while (n) { - if ((((stbsp__uintptr)s) & 3) == 0) - break; - *s++ = '0'; - --n; - } - while (n >= 4) { - *(stbsp__uint32 *)s = 0x30303030; - s += 4; - n -= 4; - } - } - while (n) { - if ((fl & STBSP__TRIPLET_COMMA) && (++cs == 4)) { - cs = 0; - *s++ = stbsp__comma; - } else { - *s++ = '0'; - --n; - } - } - } - cs = (int)(s - (num + 64)) + (3 << 24); // cs is how many tens - if (pr) { - *s++ = stbsp__period; - tz = pr; - } - } else { - // handle xxxxx.xxxx000*000 - n = 0; - for (;;) { - if ((fl & STBSP__TRIPLET_COMMA) && (++cs == 4)) { - cs = 0; - *s++ = stbsp__comma; - } else { - *s++ = sn[n]; - ++n; - if (n >= (stbsp__uint32)dp) - break; - } - } - cs = (int)(s - (num + 64)) + (3 << 24); // cs is how many tens - if (pr) - *s++ = stbsp__period; - if ((l - dp) > (stbsp__uint32)pr) - l = pr + dp; - while (n < l) { - *s++ = sn[n]; - ++n; - } - tz = pr - (l - dp); - } - } - pr = 0; - - // handle k,m,g,t - if (fl & STBSP__METRIC_SUFFIX) { - char idx; - idx = 1; - if (fl & STBSP__METRIC_NOSPACE) - idx = 0; - tail[0] = idx; - tail[1] = ' '; - { - if (fl >> 24) { // SI kilo is 'k', JEDEC and SI kibits are 'K'. - if (fl & STBSP__METRIC_1024) - tail[idx + 1] = "_KMGT"[fl >> 24]; - else - tail[idx + 1] = "_kMGT"[fl >> 24]; - idx++; - // If printing kibits and not in jedec, add the 'i'. - if (fl & STBSP__METRIC_1024 && !(fl & STBSP__METRIC_JEDEC)) { - tail[idx + 1] = 'i'; - idx++; - } - tail[0] = idx; - } - } - }; - - flt_lead: - // get the length that we copied - l = (stbsp__uint32)(s - (num + 64)); - s = num + 64; - goto scopy; -#endif - - case 'B': // upper binary - case 'b': // lower binary - h = (f[0] == 'B') ? hexu : hex; - lead[0] = 0; - if (fl & STBSP__LEADING_0X) { - lead[0] = 2; - lead[1] = '0'; - lead[2] = h[0xb]; - } - l = (8 << 4) | (1 << 8); - goto radixnum; - - case 'o': // octal - h = hexu; - lead[0] = 0; - if (fl & STBSP__LEADING_0X) { - lead[0] = 1; - lead[1] = '0'; - } - l = (3 << 4) | (3 << 8); - goto radixnum; - - case 'p': // pointer - fl |= (sizeof(void *) == 8) ? STBSP__INTMAX : 0; - pr = sizeof(void *) * 2; - fl &= ~STBSP__LEADINGZERO; // 'p' only prints the pointer with zeros - // fall through - to X - - case 'X': // upper hex - case 'x': // lower hex - h = (f[0] == 'X') ? hexu : hex; - l = (4 << 4) | (4 << 8); - lead[0] = 0; - if (fl & STBSP__LEADING_0X) { - lead[0] = 2; - lead[1] = '0'; - lead[2] = h[16]; - } - radixnum: - // get the number - if (fl & STBSP__INTMAX) - n64 = va_arg(va, stbsp__uint64); - else - n64 = va_arg(va, stbsp__uint32); - - s = num + STBSP__NUMSZ; - dp = 0; - // clear tail, and clear leading if value is zero - tail[0] = 0; - if (n64 == 0) { - lead[0] = 0; - if (pr == 0) { - l = 0; - cs = 0; - goto scopy; - } - } - // convert to string - for (;;) { - *--s = h[n64 & ((1 << (l >> 8)) - 1)]; - n64 >>= (l >> 8); - if (!((n64) || ((stbsp__int32)((num + STBSP__NUMSZ) - s) < pr))) - break; - if (fl & STBSP__TRIPLET_COMMA) { - ++l; - if ((l & 15) == ((l >> 4) & 15)) { - l &= ~15; - *--s = stbsp__comma; - } - } - }; - // get the tens and the comma pos - cs = (stbsp__uint32)((num + STBSP__NUMSZ) - s) + ((((l >> 4) & 15)) << 24); - // get the length that we copied - l = (stbsp__uint32)((num + STBSP__NUMSZ) - s); - // copy it - goto scopy; - - case 'u': // unsigned - case 'i': - case 'd': // integer - // get the integer and abs it - if (fl & STBSP__INTMAX) { - stbsp__int64 i64 = va_arg(va, stbsp__int64); - n64 = (stbsp__uint64)i64; - if ((f[0] != 'u') && (i64 < 0)) { - n64 = (stbsp__uint64)-i64; - fl |= STBSP__NEGATIVE; - } - } else { - stbsp__int32 i = va_arg(va, stbsp__int32); - n64 = (stbsp__uint32)i; - if ((f[0] != 'u') && (i < 0)) { - n64 = (stbsp__uint32)-i; - fl |= STBSP__NEGATIVE; - } - } - -#ifndef STB_SPRINTF_NOFLOAT - if (fl & STBSP__METRIC_SUFFIX) { - if (n64 < 1024) - pr = 0; - else if (pr == -1) - pr = 1; - fv = (double)(stbsp__int64)n64; - goto doafloat; - } -#endif - - // convert to string - s = num + STBSP__NUMSZ; - l = 0; - - for (;;) { - // do in 32-bit chunks (avoid lots of 64-bit divides even with constant denominators) - char *o = s - 8; - if (n64 >= 100000000) { - n = (stbsp__uint32)(n64 % 100000000); - n64 /= 100000000; - } else { - n = (stbsp__uint32)n64; - n64 = 0; - } - if ((fl & STBSP__TRIPLET_COMMA) == 0) { - do { - s -= 2; - *(stbsp__uint16 *)s = *(stbsp__uint16 *)&stbsp__digitpair.pair[(n % 100) * 2]; - n /= 100; - } while (n); - } - while (n) { - if ((fl & STBSP__TRIPLET_COMMA) && (l++ == 3)) { - l = 0; - *--s = stbsp__comma; - --o; - } else { - *--s = (char)(n % 10) + '0'; - n /= 10; - } - } - if (n64 == 0) { - if ((s[0] == '0') && (s != (num + STBSP__NUMSZ))) - ++s; - break; - } - while (s != o) - if ((fl & STBSP__TRIPLET_COMMA) && (l++ == 3)) { - l = 0; - *--s = stbsp__comma; - --o; - } else { - *--s = '0'; - } - } - - tail[0] = 0; - stbsp__lead_sign(fl, lead); - - // get the length that we copied - l = (stbsp__uint32)((num + STBSP__NUMSZ) - s); - if (l == 0) { - *--s = '0'; - l = 1; - } - cs = l + (3 << 24); - if (pr < 0) - pr = 0; - - scopy: - // get fw=leading/trailing space, pr=leading zeros - if (pr < (stbsp__int32)l) - pr = l; - n = pr + lead[0] + tail[0] + tz; - if (fw < (stbsp__int32)n) - fw = n; - fw -= n; - pr -= l; - - // handle right justify and leading zeros - if ((fl & STBSP__LEFTJUST) == 0) { - if (fl & STBSP__LEADINGZERO) // if leading zeros, everything is in pr - { - pr = (fw > pr) ? fw : pr; - fw = 0; - } else { - fl &= ~STBSP__TRIPLET_COMMA; // if no leading zeros, then no commas - } - } - - // copy the spaces and/or zeros - if (fw + pr) { - stbsp__int32 i; - stbsp__uint32 c; - - // copy leading spaces (or when doing %8.4d stuff) - if ((fl & STBSP__LEFTJUST) == 0) - while (fw > 0) { - stbsp__cb_buf_clamp(i, fw); - fw -= i; - while (i) { - if ((((stbsp__uintptr)bf) & 3) == 0) - break; - *bf++ = ' '; - --i; - } - while (i >= 4) { - *(stbsp__uint32 *)bf = 0x20202020; - bf += 4; - i -= 4; - } - while (i) { - *bf++ = ' '; - --i; - } - stbsp__chk_cb_buf(1); - } - - // copy leader - sn = lead + 1; - while (lead[0]) { - stbsp__cb_buf_clamp(i, lead[0]); - lead[0] -= (char)i; - while (i) { - *bf++ = *sn++; - --i; - } - stbsp__chk_cb_buf(1); - } - - // copy leading zeros - c = cs >> 24; - cs &= 0xffffff; - cs = (fl & STBSP__TRIPLET_COMMA) ? ((stbsp__uint32)(c - ((pr + cs) % (c + 1)))) : 0; - while (pr > 0) { - stbsp__cb_buf_clamp(i, pr); - pr -= i; - if ((fl & STBSP__TRIPLET_COMMA) == 0) { - while (i) { - if ((((stbsp__uintptr)bf) & 3) == 0) - break; - *bf++ = '0'; - --i; - } - while (i >= 4) { - *(stbsp__uint32 *)bf = 0x30303030; - bf += 4; - i -= 4; - } - } - while (i) { - if ((fl & STBSP__TRIPLET_COMMA) && (cs++ == c)) { - cs = 0; - *bf++ = stbsp__comma; - } else - *bf++ = '0'; - --i; - } - stbsp__chk_cb_buf(1); - } - } - - // copy leader if there is still one - sn = lead + 1; - while (lead[0]) { - stbsp__int32 i; - stbsp__cb_buf_clamp(i, lead[0]); - lead[0] -= (char)i; - while (i) { - *bf++ = *sn++; - --i; - } - stbsp__chk_cb_buf(1); - } - - // copy the string - n = l; - while (n) { - stbsp__int32 i; - stbsp__cb_buf_clamp(i, n); - n -= i; - STBSP__UNALIGNED(while (i >= 4) { - *(stbsp__uint32 volatile *)bf = *(stbsp__uint32 volatile *)s; - bf += 4; - s += 4; - i -= 4; - }) - while (i) { - *bf++ = *s++; - --i; - } - stbsp__chk_cb_buf(1); - } - - // copy trailing zeros - while (tz) { - stbsp__int32 i; - stbsp__cb_buf_clamp(i, tz); - tz -= i; - while (i) { - if ((((stbsp__uintptr)bf) & 3) == 0) - break; - *bf++ = '0'; - --i; - } - while (i >= 4) { - *(stbsp__uint32 *)bf = 0x30303030; - bf += 4; - i -= 4; - } - while (i) { - *bf++ = '0'; - --i; - } - stbsp__chk_cb_buf(1); - } - - // copy tail if there is one - sn = tail + 1; - while (tail[0]) { - stbsp__int32 i; - stbsp__cb_buf_clamp(i, tail[0]); - tail[0] -= (char)i; - while (i) { - *bf++ = *sn++; - --i; - } - stbsp__chk_cb_buf(1); - } - - // handle the left justify - if (fl & STBSP__LEFTJUST) - if (fw > 0) { - while (fw) { - stbsp__int32 i; - stbsp__cb_buf_clamp(i, fw); - fw -= i; - while (i) { - if ((((stbsp__uintptr)bf) & 3) == 0) - break; - *bf++ = ' '; - --i; - } - while (i >= 4) { - *(stbsp__uint32 *)bf = 0x20202020; - bf += 4; - i -= 4; - } - while (i--) - *bf++ = ' '; - stbsp__chk_cb_buf(1); - } - } - break; - - default: // unknown, just copy code - s = num + STBSP__NUMSZ - 1; - *s = f[0]; - l = 1; - fw = fl = 0; - lead[0] = 0; - tail[0] = 0; - pr = 0; - dp = 0; - cs = 0; - goto scopy; - } - ++f; - } -endfmt: - - if (!callback) - *bf = 0; - else - stbsp__flush_cb(); - -done: - return tlen + (int)(bf - buf); -} - -// cleanup -#undef STBSP__LEFTJUST -#undef STBSP__LEADINGPLUS -#undef STBSP__LEADINGSPACE -#undef STBSP__LEADING_0X -#undef STBSP__LEADINGZERO -#undef STBSP__INTMAX -#undef STBSP__TRIPLET_COMMA -#undef STBSP__NEGATIVE -#undef STBSP__METRIC_SUFFIX -#undef STBSP__NUMSZ -#undef stbsp__chk_cb_bufL -#undef stbsp__chk_cb_buf -#undef stbsp__flush_cb -#undef stbsp__cb_buf_clamp - -// ============================================================================ -// wrapper functions - -STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(sprintf)(char *buf, char const *fmt, ...) -{ - int result; - va_list va; - va_start(va, fmt); - result = STB_SPRINTF_DECORATE(vsprintfcb)(0, 0, buf, fmt, va); - va_end(va); - return result; -} - -typedef struct stbsp__context { - char *buf; - int count; - int length; - char tmp[STB_SPRINTF_MIN]; -} stbsp__context; - -static char *stbsp__clamp_callback(const char *buf, void *user, int len) -{ - stbsp__context *c = (stbsp__context *)user; - c->length += len; - - if (len > c->count) - len = c->count; - - if (len) { - if (buf != c->buf) { - const char *s, *se; - char *d; - d = c->buf; - s = buf; - se = buf + len; - do { - *d++ = *s++; - } while (s < se); - } - c->buf += len; - c->count -= len; - } - - if (c->count <= 0) - return c->tmp; - return (c->count >= STB_SPRINTF_MIN) ? c->buf : c->tmp; // go direct into buffer if you can -} - -static char * stbsp__count_clamp_callback( const char * buf, void * user, int len ) -{ - stbsp__context * c = (stbsp__context*)user; - (void) sizeof(buf); - - c->length += len; - return c->tmp; // go direct into buffer if you can -} - -STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsnprintf )( char * buf, int count, char const * fmt, va_list va ) -{ - stbsp__context c; - - if ( (count == 0) && !buf ) - { - c.length = 0; - - STB_SPRINTF_DECORATE( vsprintfcb )( stbsp__count_clamp_callback, &c, c.tmp, fmt, va ); - } - else - { - int l; - - c.buf = buf; - c.count = count; - c.length = 0; - - STB_SPRINTF_DECORATE( vsprintfcb )( stbsp__clamp_callback, &c, stbsp__clamp_callback(0,&c,0), fmt, va ); - - // zero-terminate - l = (int)( c.buf - buf ); - if ( l >= count ) // should never be greater, only equal (or less) than count - l = count - 1; - buf[l] = 0; - } - - return c.length; -} - -STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(snprintf)(char *buf, int count, char const *fmt, ...) -{ - int result; - va_list va; - va_start(va, fmt); - - result = STB_SPRINTF_DECORATE(vsnprintf)(buf, count, fmt, va); - va_end(va); - - return result; -} - -STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintf)(char *buf, char const *fmt, va_list va) -{ - return STB_SPRINTF_DECORATE(vsprintfcb)(0, 0, buf, fmt, va); -} - -// ======================================================================= -// low level float utility functions - -#ifndef STB_SPRINTF_NOFLOAT - -// copies d to bits w/ strict aliasing (this compiles to nothing on /Ox) -#define STBSP__COPYFP(dest, src) \ - { \ - int cn; \ - for (cn = 0; cn < 8; cn++) \ - ((char *)&dest)[cn] = ((char *)&src)[cn]; \ - } - -// get float info -static stbsp__int32 stbsp__real_to_parts(stbsp__int64 *bits, stbsp__int32 *expo, double value) -{ - double d; - stbsp__int64 b = 0; - - // load value and round at the frac_digits - d = value; - - STBSP__COPYFP(b, d); - - *bits = b & ((((stbsp__uint64)1) << 52) - 1); - *expo = (stbsp__int32)(((b >> 52) & 2047) - 1023); - - return (stbsp__int32)((stbsp__uint64) b >> 63); -} - -static double const stbsp__bot[23] = { - 1e+000, 1e+001, 1e+002, 1e+003, 1e+004, 1e+005, 1e+006, 1e+007, 1e+008, 1e+009, 1e+010, 1e+011, - 1e+012, 1e+013, 1e+014, 1e+015, 1e+016, 1e+017, 1e+018, 1e+019, 1e+020, 1e+021, 1e+022 -}; -static double const stbsp__negbot[22] = { - 1e-001, 1e-002, 1e-003, 1e-004, 1e-005, 1e-006, 1e-007, 1e-008, 1e-009, 1e-010, 1e-011, - 1e-012, 1e-013, 1e-014, 1e-015, 1e-016, 1e-017, 1e-018, 1e-019, 1e-020, 1e-021, 1e-022 -}; -static double const stbsp__negboterr[22] = { - -5.551115123125783e-018, -2.0816681711721684e-019, -2.0816681711721686e-020, -4.7921736023859299e-021, -8.1803053914031305e-022, 4.5251888174113741e-023, - 4.5251888174113739e-024, -2.0922560830128471e-025, -6.2281591457779853e-026, -3.6432197315497743e-027, 6.0503030718060191e-028, 2.0113352370744385e-029, - -3.0373745563400371e-030, 1.1806906454401013e-032, -7.7705399876661076e-032, 2.0902213275965398e-033, -7.1542424054621921e-034, -7.1542424054621926e-035, - 2.4754073164739869e-036, 5.4846728545790429e-037, 9.2462547772103625e-038, -4.8596774326570872e-039 -}; -static double const stbsp__top[13] = { - 1e+023, 1e+046, 1e+069, 1e+092, 1e+115, 1e+138, 1e+161, 1e+184, 1e+207, 1e+230, 1e+253, 1e+276, 1e+299 -}; -static double const stbsp__negtop[13] = { - 1e-023, 1e-046, 1e-069, 1e-092, 1e-115, 1e-138, 1e-161, 1e-184, 1e-207, 1e-230, 1e-253, 1e-276, 1e-299 -}; -static double const stbsp__toperr[13] = { - 8388608, - 6.8601809640529717e+028, - -7.253143638152921e+052, - -4.3377296974619174e+075, - -1.5559416129466825e+098, - -3.2841562489204913e+121, - -3.7745893248228135e+144, - -1.7356668416969134e+167, - -3.8893577551088374e+190, - -9.9566444326005119e+213, - 6.3641293062232429e+236, - -5.2069140800249813e+259, - -5.2504760255204387e+282 -}; -static double const stbsp__negtoperr[13] = { - 3.9565301985100693e-040, -2.299904345391321e-063, 3.6506201437945798e-086, 1.1875228833981544e-109, - -5.0644902316928607e-132, -6.7156837247865426e-155, -2.812077463003139e-178, -5.7778912386589953e-201, - 7.4997100559334532e-224, -4.6439668915134491e-247, -6.3691100762962136e-270, -9.436808465446358e-293, - 8.0970921678014997e-317 -}; - -#if defined(_MSC_VER) && (_MSC_VER <= 1200) -static stbsp__uint64 const stbsp__powten[20] = { - 1, - 10, - 100, - 1000, - 10000, - 100000, - 1000000, - 10000000, - 100000000, - 1000000000, - 10000000000, - 100000000000, - 1000000000000, - 10000000000000, - 100000000000000, - 1000000000000000, - 10000000000000000, - 100000000000000000, - 1000000000000000000, - 10000000000000000000U -}; -#define stbsp__tento19th ((stbsp__uint64)1000000000000000000) -#else -static stbsp__uint64 const stbsp__powten[20] = { - 1, - 10, - 100, - 1000, - 10000, - 100000, - 1000000, - 10000000, - 100000000, - 1000000000, - 10000000000ULL, - 100000000000ULL, - 1000000000000ULL, - 10000000000000ULL, - 100000000000000ULL, - 1000000000000000ULL, - 10000000000000000ULL, - 100000000000000000ULL, - 1000000000000000000ULL, - 10000000000000000000ULL -}; -#define stbsp__tento19th (1000000000000000000ULL) -#endif - -#define stbsp__ddmulthi(oh, ol, xh, yh) \ - { \ - double ahi = 0, alo, bhi = 0, blo; \ - stbsp__int64 bt; \ - oh = xh * yh; \ - STBSP__COPYFP(bt, xh); \ - bt &= ((~(stbsp__uint64)0) << 27); \ - STBSP__COPYFP(ahi, bt); \ - alo = xh - ahi; \ - STBSP__COPYFP(bt, yh); \ - bt &= ((~(stbsp__uint64)0) << 27); \ - STBSP__COPYFP(bhi, bt); \ - blo = yh - bhi; \ - ol = ((ahi * bhi - oh) + ahi * blo + alo * bhi) + alo * blo; \ - } - -#define stbsp__ddtoS64(ob, xh, xl) \ - { \ - double ahi = 0, alo, vh, t; \ - ob = (stbsp__int64)xh; \ - vh = (double)ob; \ - ahi = (xh - vh); \ - t = (ahi - xh); \ - alo = (xh - (ahi - t)) - (vh + t); \ - ob += (stbsp__int64)(ahi + alo + xl); \ - } - -#define stbsp__ddrenorm(oh, ol) \ - { \ - double s; \ - s = oh + ol; \ - ol = ol - (s - oh); \ - oh = s; \ - } - -#define stbsp__ddmultlo(oh, ol, xh, xl, yh, yl) ol = ol + (xh * yl + xl * yh); - -#define stbsp__ddmultlos(oh, ol, xh, yl) ol = ol + (xh * yl); - -static void stbsp__raise_to_power10(double *ohi, double *olo, double d, stbsp__int32 power) // power can be -323 to +350 -{ - double ph, pl; - if ((power >= 0) && (power <= 22)) { - stbsp__ddmulthi(ph, pl, d, stbsp__bot[power]); - } else { - stbsp__int32 e, et, eb; - double p2h, p2l; - - e = power; - if (power < 0) - e = -e; - et = (e * 0x2c9) >> 14; /* %23 */ - if (et > 13) - et = 13; - eb = e - (et * 23); - - ph = d; - pl = 0.0; - if (power < 0) { - if (eb) { - --eb; - stbsp__ddmulthi(ph, pl, d, stbsp__negbot[eb]); - stbsp__ddmultlos(ph, pl, d, stbsp__negboterr[eb]); - } - if (et) { - stbsp__ddrenorm(ph, pl); - --et; - stbsp__ddmulthi(p2h, p2l, ph, stbsp__negtop[et]); - stbsp__ddmultlo(p2h, p2l, ph, pl, stbsp__negtop[et], stbsp__negtoperr[et]); - ph = p2h; - pl = p2l; - } - } else { - if (eb) { - e = eb; - if (eb > 22) - eb = 22; - e -= eb; - stbsp__ddmulthi(ph, pl, d, stbsp__bot[eb]); - if (e) { - stbsp__ddrenorm(ph, pl); - stbsp__ddmulthi(p2h, p2l, ph, stbsp__bot[e]); - stbsp__ddmultlos(p2h, p2l, stbsp__bot[e], pl); - ph = p2h; - pl = p2l; - } - } - if (et) { - stbsp__ddrenorm(ph, pl); - --et; - stbsp__ddmulthi(p2h, p2l, ph, stbsp__top[et]); - stbsp__ddmultlo(p2h, p2l, ph, pl, stbsp__top[et], stbsp__toperr[et]); - ph = p2h; - pl = p2l; - } - } - } - stbsp__ddrenorm(ph, pl); - *ohi = ph; - *olo = pl; -} - -// given a float value, returns the significant bits in bits, and the position of the -// decimal point in decimal_pos. +/-INF and NAN are specified by special values -// returned in the decimal_pos parameter. -// frac_digits is absolute normally, but if you want from first significant digits (got %g and %e), or in 0x80000000 -static stbsp__int32 stbsp__real_to_str(char const **start, stbsp__uint32 *len, char *out, stbsp__int32 *decimal_pos, double value, stbsp__uint32 frac_digits) -{ - double d; - stbsp__int64 bits = 0; - stbsp__int32 expo, e, ng, tens; - - d = value; - STBSP__COPYFP(bits, d); - expo = (stbsp__int32)((bits >> 52) & 2047); - ng = (stbsp__int32)((stbsp__uint64) bits >> 63); - if (ng) - d = -d; - - if (expo == 2047) // is nan or inf? - { - *start = (bits & ((((stbsp__uint64)1) << 52) - 1)) ? "NaN" : "Inf"; - *decimal_pos = STBSP__SPECIAL; - *len = 3; - return ng; - } - - if (expo == 0) // is zero or denormal - { - if (((stbsp__uint64) bits << 1) == 0) // do zero - { - *decimal_pos = 1; - *start = out; - out[0] = '0'; - *len = 1; - return ng; - } - // find the right expo for denormals - { - stbsp__int64 v = ((stbsp__uint64)1) << 51; - while ((bits & v) == 0) { - --expo; - v >>= 1; - } - } - } - - // find the decimal exponent as well as the decimal bits of the value - { - double ph, pl; - - // log10 estimate - very specifically tweaked to hit or undershoot by no more than 1 of log10 of all expos 1..2046 - tens = expo - 1023; - tens = (tens < 0) ? ((tens * 617) / 2048) : (((tens * 1233) / 4096) + 1); - - // move the significant bits into position and stick them into an int - stbsp__raise_to_power10(&ph, &pl, d, 18 - tens); - - // get full as much precision from double-double as possible - stbsp__ddtoS64(bits, ph, pl); - - // check if we undershot - if (((stbsp__uint64)bits) >= stbsp__tento19th) - ++tens; - } - - // now do the rounding in integer land - frac_digits = (frac_digits & 0x80000000) ? ((frac_digits & 0x7ffffff) + 1) : (tens + frac_digits); - if ((frac_digits < 24)) { - stbsp__uint32 dg = 1; - if ((stbsp__uint64)bits >= stbsp__powten[9]) - dg = 10; - while ((stbsp__uint64)bits >= stbsp__powten[dg]) { - ++dg; - if (dg == 20) - goto noround; - } - if (frac_digits < dg) { - stbsp__uint64 r; - // add 0.5 at the right position and round - e = dg - frac_digits; - if ((stbsp__uint32)e >= 24) - goto noround; - r = stbsp__powten[e]; - bits = bits + (r / 2); - if ((stbsp__uint64)bits >= stbsp__powten[dg]) - ++tens; - bits /= r; - } - noround:; - } - - // kill long trailing runs of zeros - if (bits) { - stbsp__uint32 n; - for (;;) { - if (bits <= 0xffffffff) - break; - if (bits % 1000) - goto donez; - bits /= 1000; - } - n = (stbsp__uint32)bits; - while ((n % 1000) == 0) - n /= 1000; - bits = n; - donez:; - } - - // convert to string - out += 64; - e = 0; - for (;;) { - stbsp__uint32 n; - char *o = out - 8; - // do the conversion in chunks of U32s (avoid most 64-bit divides, worth it, constant denomiators be damned) - if (bits >= 100000000) { - n = (stbsp__uint32)(bits % 100000000); - bits /= 100000000; - } else { - n = (stbsp__uint32)bits; - bits = 0; - } - while (n) { - out -= 2; - *(stbsp__uint16 *)out = *(stbsp__uint16 *)&stbsp__digitpair.pair[(n % 100) * 2]; - n /= 100; - e += 2; - } - if (bits == 0) { - if ((e) && (out[0] == '0')) { - ++out; - --e; - } - break; - } - while (out != o) { - *--out = '0'; - ++e; - } - } - - *decimal_pos = tens; - *start = out; - *len = e; - return ng; -} - -#undef stbsp__ddmulthi -#undef stbsp__ddrenorm -#undef stbsp__ddmultlo -#undef stbsp__ddmultlos -#undef STBSP__SPECIAL -#undef STBSP__COPYFP - -#endif // STB_SPRINTF_NOFLOAT - -// clean up -#undef stbsp__uint16 -#undef stbsp__uint32 -#undef stbsp__int32 -#undef stbsp__uint64 -#undef stbsp__int64 -#undef STBSP__UNALIGNED - -#endif // STB_SPRINTF_IMPLEMENTATION - -/* ------------------------------------------------------------------------------- -This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------- -ALTERNATIVE A - MIT License -Copyright (c) 2017 Sean Barrett -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. ------------------------------------------------------------------------------- -ALTERNATIVE B - Public Domain (www.unlicense.org) -This is free and unencumbered software released into the public domain. -Anyone is free to copy, modify, publish, use, compile, sell, or distribute this -software, either in source code form or as a compiled binary, for any purpose, -commercial or non-commercial, and by any means. -In jurisdictions that recognize copyright laws, the author or authors of this -software dedicate any and all copyright interest in the software to the public -domain. We make this dedication for the benefit of the public at large and to -the detriment of our heirs and successors. We intend this dedication to be an -overt act of relinquishment in perpetuity of all present and future rights to -this software under copyright law. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- -*/ diff --git a/Kinc/Sources/kinc/libs/stb_vorbis.c b/Kinc/Sources/kinc/libs/stb_vorbis.c index 2c01901..0504762 100644 --- a/Kinc/Sources/kinc/libs/stb_vorbis.c +++ b/Kinc/Sources/kinc/libs/stb_vorbis.c @@ -601,7 +601,7 @@ enum STBVorbisError #endif #endif -#if defined(__FreeBSD__) && !defined(KORE_PS4) && !defined(KORE_PS5) +#if defined(__FreeBSD__) && !defined(KINC_PS4) && !defined(KINC_PS5) #ifdef alloca #undef alloca #endif diff --git a/Kinc/Sources/kinc/log.h b/Kinc/Sources/kinc/log.h index 69a837c..5117245 100644 --- a/Kinc/Sources/kinc/log.h +++ b/Kinc/Sources/kinc/log.h @@ -67,12 +67,12 @@ KINC_FUNC void kinc_log_args(kinc_log_level_t log_level, const char *format, va_ #undef KINC_IMPLEMENTATION #endif -#ifdef KORE_MICROSOFT +#ifdef KINC_MICROSOFT #include #include #endif -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID #include #endif @@ -86,13 +86,29 @@ void kinc_log(kinc_log_level_t level, const char *format, ...) { #define UTF8 void kinc_log_args(kinc_log_level_t level, const char *format, va_list args) { -#ifdef KORE_MICROSOFT +#ifdef KINC_ANDROID + va_list args_android_copy; + va_copy(args_android_copy, args); + switch (level) { + case KINC_LOG_LEVEL_INFO: + __android_log_vprint(ANDROID_LOG_INFO, "Kinc", format, args_android_copy); + break; + case KINC_LOG_LEVEL_WARNING: + __android_log_vprint(ANDROID_LOG_WARN, "Kinc", format, args_android_copy); + break; + case KINC_LOG_LEVEL_ERROR: + __android_log_vprint(ANDROID_LOG_ERROR, "Kinc", format, args_android_copy); + break; + } + va_end(args_android_copy); +#endif +#ifdef KINC_MICROSOFT #ifdef UTF8 wchar_t buffer[4096]; kinc_microsoft_format(format, args, buffer); wcscat(buffer, L"\r\n"); OutputDebugStringW(buffer); -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS DWORD written; WriteConsoleW(GetStdHandle(level == KINC_LOG_LEVEL_INFO ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE), buffer, (DWORD)wcslen(buffer), &written, NULL); #endif @@ -101,7 +117,7 @@ void kinc_log_args(kinc_log_level_t level, const char *format, va_list args) { vsnprintf(buffer, 4090, format, args); strcat(buffer, "\r\n"); OutputDebugStringA(buffer); -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS DWORD written; WriteConsoleA(GetStdHandle(level == KINC_LOG_LEVEL_INFO ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE), buffer, (DWORD)strlen(buffer), &written, NULL); #endif @@ -112,20 +128,6 @@ void kinc_log_args(kinc_log_level_t level, const char *format, va_list args) { strcat(buffer, "\n"); fprintf(level == KINC_LOG_LEVEL_INFO ? stdout : stderr, "%s", buffer); #endif - -#ifdef KORE_ANDROID - switch (level) { - case KINC_LOG_LEVEL_INFO: - __android_log_vprint(ANDROID_LOG_INFO, "Kinc", format, args); - break; - case KINC_LOG_LEVEL_WARNING: - __android_log_vprint(ANDROID_LOG_WARN, "Kinc", format, args); - break; - case KINC_LOG_LEVEL_ERROR: - __android_log_vprint(ANDROID_LOG_ERROR, "Kinc", format, args); - break; - } -#endif } #endif diff --git a/Kinc/Sources/kinc/math/matrix.h b/Kinc/Sources/kinc/math/matrix.h index 88c6ea0..fea5f87 100644 --- a/Kinc/Sources/kinc/math/matrix.h +++ b/Kinc/Sources/kinc/math/matrix.h @@ -24,6 +24,7 @@ KINC_FUNC kinc_matrix3x3_t kinc_matrix3x3_rotation_x(float alpha); KINC_FUNC kinc_matrix3x3_t kinc_matrix3x3_rotation_y(float alpha); KINC_FUNC kinc_matrix3x3_t kinc_matrix3x3_rotation_z(float alpha); KINC_FUNC kinc_matrix3x3_t kinc_matrix3x3_translation(float x, float y); +KINC_FUNC kinc_matrix3x3_t kinc_matrix3x3_scale(float x, float y, float z); KINC_FUNC kinc_matrix3x3_t kinc_matrix3x3_multiply(kinc_matrix3x3_t *a, kinc_matrix3x3_t *b); KINC_FUNC kinc_vector3_t kinc_matrix3x3_multiply_vector(kinc_matrix3x3_t *a, kinc_vector3_t b); @@ -34,7 +35,14 @@ typedef struct kinc_matrix4x4 { KINC_FUNC float kinc_matrix4x4_get(kinc_matrix4x4_t *matrix, int x, int y); KINC_FUNC void kinc_matrix4x4_set(kinc_matrix4x4_t *matrix, int x, int y, float value); KINC_FUNC void kinc_matrix4x4_transpose(kinc_matrix4x4_t *matrix); +KINC_FUNC kinc_matrix4x4_t kinc_matrix4x4_identity(void); +KINC_FUNC kinc_matrix4x4_t kinc_matrix4x4_rotation_x(float alpha); +KINC_FUNC kinc_matrix4x4_t kinc_matrix4x4_rotation_y(float alpha); +KINC_FUNC kinc_matrix4x4_t kinc_matrix4x4_rotation_z(float alpha); +KINC_FUNC kinc_matrix4x4_t kinc_matrix4x4_translation(float x, float y, float z); +KINC_FUNC kinc_matrix4x4_t kinc_matrix4x4_scale(float x, float y, float z); KINC_FUNC kinc_matrix4x4_t kinc_matrix4x4_multiply(kinc_matrix4x4_t *a, kinc_matrix4x4_t *b); +KINC_FUNC kinc_vector4_t kinc_matrix4x4_multiply_vector(kinc_matrix4x4_t *a, kinc_vector4_t b); #ifdef KINC_IMPLEMENTATION_MATH #define KINC_IMPLEMENTATION @@ -120,6 +128,14 @@ kinc_matrix3x3_t kinc_matrix3x3_translation(float x, float y) { return m; } +kinc_matrix3x3_t kinc_matrix3x3_scale(float x, float y, float z) { + kinc_matrix3x3_t m = kinc_matrix3x3_identity(); + kinc_matrix3x3_set(&m, 0, 0, x); + kinc_matrix3x3_set(&m, 1, 1, y); + kinc_matrix3x3_set(&m, 2, 2, z); + return m; +} + #ifdef __clang__ #pragma clang diagnostic ignored "-Wconditional-uninitialized" #endif @@ -178,6 +194,64 @@ void kinc_matrix4x4_transpose(kinc_matrix4x4_t *matrix) { memcpy(matrix->m, transposed.m, sizeof(transposed.m)); } +kinc_matrix4x4_t kinc_matrix4x4_identity(void) { + kinc_matrix4x4_t m; + memset(m.m, 0, sizeof(m.m)); + for (unsigned x = 0; x < 4; ++x) { + kinc_matrix4x4_set(&m, x, x, 1.0f); + } + return m; +} + +kinc_matrix4x4_t kinc_matrix4x4_rotation_x(float alpha) { + kinc_matrix4x4_t m = kinc_matrix4x4_identity(); + float ca = cosf(alpha); + float sa = sinf(alpha); + kinc_matrix4x4_set(&m, 1, 1, ca); + kinc_matrix4x4_set(&m, 2, 1, -sa); + kinc_matrix4x4_set(&m, 1, 2, sa); + kinc_matrix4x4_set(&m, 2, 2, ca); + return m; +} + +kinc_matrix4x4_t kinc_matrix4x4_rotation_y(float alpha) { + kinc_matrix4x4_t m = kinc_matrix4x4_identity(); + float ca = cosf(alpha); + float sa = sinf(alpha); + kinc_matrix4x4_set(&m, 0, 0, ca); + kinc_matrix4x4_set(&m, 2, 0, sa); + kinc_matrix4x4_set(&m, 0, 2, -sa); + kinc_matrix4x4_set(&m, 2, 2, ca); + return m; +} + +kinc_matrix4x4_t kinc_matrix4x4_rotation_z(float alpha) { + kinc_matrix4x4_t m = kinc_matrix4x4_identity(); + float ca = cosf(alpha); + float sa = sinf(alpha); + kinc_matrix4x4_set(&m, 0, 0, ca); + kinc_matrix4x4_set(&m, 1, 0, -sa); + kinc_matrix4x4_set(&m, 0, 1, sa); + kinc_matrix4x4_set(&m, 1, 1, ca); + return m; +} + +kinc_matrix4x4_t kinc_matrix4x4_translation(float x, float y, float z) { + kinc_matrix4x4_t m = kinc_matrix4x4_identity(); + kinc_matrix4x4_set(&m, 3, 0, x); + kinc_matrix4x4_set(&m, 3, 1, y); + kinc_matrix4x4_set(&m, 3, 2, z); + return m; +} + +kinc_matrix4x4_t kinc_matrix4x4_scale(float x, float y, float z) { + kinc_matrix4x4_t m = kinc_matrix4x4_identity(); + kinc_matrix4x4_set(&m, 0, 0, x); + kinc_matrix4x4_set(&m, 1, 1, y); + kinc_matrix4x4_set(&m, 2, 2, z); + return m; +} + kinc_matrix4x4_t kinc_matrix4x4_multiply(kinc_matrix4x4_t *a, kinc_matrix4x4_t *b) { kinc_matrix4x4_t result; for (unsigned x = 0; x < 4; ++x) @@ -191,6 +265,28 @@ kinc_matrix4x4_t kinc_matrix4x4_multiply(kinc_matrix4x4_t *a, kinc_matrix4x4_t * return result; } +static float vector4_get(kinc_vector4_t vec, int index) { + float *values = (float *)&vec; + return values[index]; +} + +static void vector4_set(kinc_vector4_t *vec, int index, float value) { + float *values = (float *)vec; + values[index] = value; +} + +kinc_vector4_t kinc_matrix4x4_multiply_vector(kinc_matrix4x4_t *a, kinc_vector4_t b) { + kinc_vector4_t product; + for (unsigned y = 0; y < 4; ++y) { + float t = 0; + for (unsigned x = 0; x < 4; ++x) { + t += kinc_matrix4x4_get(a, x, y) * vector4_get(b, x); + } + vector4_set(&product, y, t); + } + return product; +} + #endif #ifdef __cplusplus diff --git a/Kinc/Sources/kinc/network/http.h b/Kinc/Sources/kinc/network/http.h index 7a98d3c..ea8ac7a 100644 --- a/Kinc/Sources/kinc/network/http.h +++ b/Kinc/Sources/kinc/network/http.h @@ -31,7 +31,7 @@ KINC_FUNC void kinc_http_request(const char *url, const char *path, const char * #ifdef KINC_IMPLEMENTATION -#if !defined KORE_MACOS && !defined KORE_IOS && !defined KORE_WINDOWS +#if !defined KINC_MACOS && !defined KINC_IOS && !defined KINC_WINDOWS #include diff --git a/Kinc/Sources/kinc/network/socket.h b/Kinc/Sources/kinc/network/socket.h index 0d5c654..b39bf65 100644 --- a/Kinc/Sources/kinc/network/socket.h +++ b/Kinc/Sources/kinc/network/socket.h @@ -14,7 +14,7 @@ typedef enum kinc_socket_protocol { KINC_SOCKET_PROTOCOL_UDP, KINC_SOCKET_PROTOC typedef enum kinc_socket_family { KINC_SOCKET_FAMILY_IP4, KINC_SOCKET_FAMILY_IP6 } kinc_socket_family_t; -#ifdef KORE_MICROSOFT +#ifdef KINC_MICROSOFT #if defined(_WIN64) typedef unsigned __int64 UINT_PTR, *PUINT_PTR; #else @@ -27,7 +27,7 @@ typedef UINT_PTR SOCKET; #endif typedef struct kinc_socket { -#ifdef KORE_MICROSOFT +#ifdef KINC_MICROSOFT SOCKET handle; #else int handle; @@ -126,8 +126,9 @@ KINC_FUNC unsigned kinc_url_to_int(const char *url, int port); #ifdef KINC_IMPLEMENTATION #undef KINC_IMPLEMENTATION -#include + #include + #define KINC_IMPLEMENTATION #include @@ -135,7 +136,7 @@ KINC_FUNC unsigned kinc_url_to_int(const char *url, int port); #include #include -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) // Windows 7 #define WINVER 0x0601 @@ -182,7 +183,7 @@ KINC_FUNC unsigned kinc_url_to_int(const char *url, int port); #include #include -#elif defined(KORE_POSIX) || defined(KORE_EMSCRIPTEN) +#elif defined(KINC_POSIX) || defined(KINC_EMSCRIPTEN) #include // for inet_addr() #include #include @@ -194,20 +195,20 @@ KINC_FUNC unsigned kinc_url_to_int(const char *url, int port); #include #endif -#if defined(KORE_EMSCRIPTEN) +#if defined(KINC_EMSCRIPTEN) #include #include #include #include static EMSCRIPTEN_WEBSOCKET_T bridgeSocket = 0; -#elif defined(KORE_POSIX) +#elif defined(KINC_POSIX) #include #endif static int counter = 0; -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) // Important: Must be cleaned with freeaddrinfo(address) later if the result is 0 in order to prevent memory leaks static int resolveAddress(const char *url, int port, struct addrinfo **result) { struct addrinfo hints = {0}; @@ -222,8 +223,8 @@ static int resolveAddress(const char *url, int port, struct addrinfo **result) { } #endif -KINC_FUNC bool kinc_socket_bind(kinc_socket_t *sock) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +bool kinc_socket_bind(kinc_socket_t *sock) { +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) struct sockaddr_in address; address.sin_family = sock->family == KINC_SOCKET_FAMILY_IP4 ? AF_INET : AF_INET6; address.sin_addr.s_addr = sock->host; @@ -238,7 +239,7 @@ KINC_FUNC bool kinc_socket_bind(kinc_socket_t *sock) { #endif } -KINC_FUNC void kinc_socket_options_set_defaults(kinc_socket_options_t *options) { +void kinc_socket_options_set_defaults(kinc_socket_options_t *options) { options->non_blocking = true; options->broadcast = false; options->tcp_no_delay = false; @@ -247,7 +248,7 @@ KINC_FUNC void kinc_socket_options_set_defaults(kinc_socket_options_t *options) void kinc_socket_init(kinc_socket_t *sock) { sock->handle = 0; -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) sock->host = INADDR_ANY; sock->port = htons((unsigned short)8080); sock->protocol = KINC_SOCKET_PROTOCOL_TCP; @@ -255,12 +256,12 @@ void kinc_socket_init(kinc_socket_t *sock) { #endif sock->connected = false; -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) if (counter == 0) { WSADATA WsaData; WSAStartup(MAKEWORD(2, 2), &WsaData); } -#if defined(KORE_EMSCRIPTEN) +#if defined(KINC_EMSCRIPTEN) if (!bridgeSocket) { bridgeSocket = emscripten_init_websocket_to_posix_socket_bridge("ws://localhost:8080"); // Synchronously wait until connection has been established. @@ -276,7 +277,7 @@ void kinc_socket_init(kinc_socket_t *sock) { } bool kinc_socket_open(kinc_socket_t *sock, struct kinc_socket_options *options) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) switch (sock->protocol) { case KINC_SOCKET_PROTOCOL_UDP: sock->handle = socket(sock->family == KINC_SOCKET_FAMILY_IP4 ? AF_INET : AF_INET6, SOCK_DGRAM, IPPROTO_UDP); @@ -291,7 +292,7 @@ bool kinc_socket_open(kinc_socket_t *sock, struct kinc_socket_options *options) if (sock->handle <= 0) { kinc_log(KINC_LOG_LEVEL_ERROR, "Could not create socket."); -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) int errorCode = WSAGetLastError(); switch (errorCode) { case (WSANOTINITIALISED): @@ -343,7 +344,7 @@ bool kinc_socket_open(kinc_socket_t *sock, struct kinc_socket_options *options) default: kinc_log(KINC_LOG_LEVEL_ERROR, "Unknown error."); } -#elif defined(KORE_POSIX) && !defined(KORE_EMSCRIPTEN) +#elif defined(KINC_POSIX) && !defined(KINC_EMSCRIPTEN) kinc_log(KINC_LOG_LEVEL_ERROR, "%s", strerror(errno)); #endif return false; @@ -352,13 +353,13 @@ bool kinc_socket_open(kinc_socket_t *sock, struct kinc_socket_options *options) if (options) { if (options->non_blocking) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) DWORD value = 1; if (ioctlsocket(sock->handle, FIONBIO, &value) != 0) { kinc_log(KINC_LOG_LEVEL_ERROR, "Could not set non-blocking mode."); return false; } -#elif defined(KORE_POSIX) +#elif defined(KINC_POSIX) int value = 1; if (fcntl(sock->handle, F_SETFL, O_NONBLOCK, value) == -1) { kinc_log(KINC_LOG_LEVEL_ERROR, "Could not set non-blocking mode."); @@ -368,7 +369,7 @@ bool kinc_socket_open(kinc_socket_t *sock, struct kinc_socket_options *options) } if (options->broadcast) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) int value = 1; if (setsockopt(sock->handle, SOL_SOCKET, SO_BROADCAST, (const char *)&value, sizeof(value)) < 0) { kinc_log(KINC_LOG_LEVEL_ERROR, "Could not set broadcast mode."); @@ -378,7 +379,7 @@ bool kinc_socket_open(kinc_socket_t *sock, struct kinc_socket_options *options) } if (options->tcp_no_delay) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) int value = 1; if (setsockopt(sock->handle, IPPROTO_TCP, TCP_NODELAY, (const char *)&value, sizeof(value)) != 0) { kinc_log(KINC_LOG_LEVEL_ERROR, "Could not set no-delay mode."); @@ -392,16 +393,16 @@ bool kinc_socket_open(kinc_socket_t *sock, struct kinc_socket_options *options) } void kinc_socket_destroy(kinc_socket_t *sock) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) closesocket(sock->handle); -#elif defined(KORE_POSIX) +#elif defined(KINC_POSIX) close(sock->handle); #endif memset(sock, 0, sizeof(kinc_socket_t)); --counter; -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) if (counter == 0) { WSACleanup(); } @@ -409,7 +410,7 @@ void kinc_socket_destroy(kinc_socket_t *sock) { } bool kinc_socket_select(kinc_socket_t *sock, uint32_t waittime, bool read, bool write) { -#if !defined(KORE_EMSCRIPTEN) && (defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX)) +#if !defined(KINC_EMSCRIPTEN) && (defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX)) fd_set r_fds, w_fds; struct timeval timeout; @@ -446,7 +447,7 @@ bool kinc_socket_select(kinc_socket_t *sock, uint32_t waittime, bool read, bool } bool kinc_socket_set(kinc_socket_t *sock, const char *host, int port, kinc_socket_family_t family, kinc_socket_protocol_t protocol) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) sock->family = family; sock->protocol = protocol; @@ -472,7 +473,7 @@ bool kinc_socket_set(kinc_socket_t *sock, const char *host, int port, kinc_socke kinc_log(KINC_LOG_LEVEL_ERROR, "Could not resolve address."); return false; } -#if defined(KORE_POSIX) +#if defined(KINC_POSIX) sock->host = ((struct sockaddr_in *)address->ai_addr)->sin_addr.s_addr; #else sock->host = ((struct sockaddr_in *)address->ai_addr)->sin_addr.S_un.S_addr; @@ -487,7 +488,7 @@ bool kinc_socket_set(kinc_socket_t *sock, const char *host, int port, kinc_socke } bool kinc_socket_listen(kinc_socket_t *socket, int backlog) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) int res = listen(socket->handle, backlog); return (res == 0); #else @@ -496,10 +497,10 @@ bool kinc_socket_listen(kinc_socket_t *socket, int backlog) { } bool kinc_socket_accept(kinc_socket_t *sock, kinc_socket_t *newSocket, unsigned *remoteAddress, unsigned *remotePort) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) typedef int socklen_t; #endif -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) struct sockaddr_in addr; socklen_t addrLength = sizeof(addr); newSocket->handle = accept(sock->handle, (struct sockaddr *)&addr, &addrLength); @@ -521,7 +522,7 @@ bool kinc_socket_accept(kinc_socket_t *sock, kinc_socket_t *newSocket, unsigned } bool kinc_socket_connect(kinc_socket_t *sock) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) struct sockaddr_in addr; addr.sin_family = sock->family == KINC_SOCKET_FAMILY_IP4 ? AF_INET : AF_INET6; addr.sin_addr.s_addr = sock->host; @@ -535,10 +536,10 @@ bool kinc_socket_connect(kinc_socket_t *sock) { } int kinc_socket_send(kinc_socket_t *sock, const uint8_t *data, int size) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) typedef int socklen_t; #endif -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) if (sock->protocol == KINC_SOCKET_PROTOCOL_UDP) { struct sockaddr_in addr; addr.sin_family = sock->family == KINC_SOCKET_FAMILY_IP4 ? AF_INET : AF_INET6; @@ -570,7 +571,7 @@ int kinc_socket_send(kinc_socket_t *sock, const uint8_t *data, int size) { } int kinc_socket_send_address(kinc_socket_t *sock, unsigned address, int port, const uint8_t *data, int size) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(address); @@ -587,7 +588,7 @@ int kinc_socket_send_address(kinc_socket_t *sock, unsigned address, int port, co } int kinc_socket_send_url(kinc_socket_t *sock, const char *url, int port, const uint8_t *data, int size) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) struct addrinfo *address = NULL; int res = resolveAddress(url, port, &address); if (res != 0) { @@ -607,11 +608,11 @@ int kinc_socket_send_url(kinc_socket_t *sock, const char *url, int port, const u } int kinc_socket_receive(kinc_socket_t *sock, uint8_t *data, int maxSize, unsigned *fromAddress, unsigned *fromPort) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) typedef int socklen_t; typedef int ssize_t; #endif -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) || defined(KORE_POSIX) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) || defined(KINC_POSIX) if (sock->protocol == KINC_SOCKET_PROTOCOL_UDP) { struct sockaddr_in from; @@ -641,7 +642,7 @@ int kinc_socket_receive(kinc_socket_t *sock, uint8_t *data, int maxSize, unsigne } unsigned kinc_url_to_int(const char *url, int port) { -#if defined(KORE_WINDOWS) || defined(KORE_WINDOWSAPP) +#if defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP) struct addrinfo *address = NULL; int res = resolveAddress(url, port, &address); if (res != 0) { diff --git a/Kinc/Sources/kinc/rootunit.cpp b/Kinc/Sources/kinc/rootcppunit.cpp similarity index 100% rename from Kinc/Sources/kinc/rootunit.cpp rename to Kinc/Sources/kinc/rootcppunit.cpp diff --git a/Kinc/Sources/kinc/simd/float32x4.h b/Kinc/Sources/kinc/simd/float32x4.h index 1efa4fe..f4dec0e 100644 --- a/Kinc/Sources/kinc/simd/float32x4.h +++ b/Kinc/Sources/kinc/simd/float32x4.h @@ -302,8 +302,8 @@ static inline kinc_float32x4_t kinc_float32x4_not(kinc_float32x4_t t) { #define kinc_float32x4_shuffle_custom(abcd, efgh, left_1, left_2, right_1, right_2) \ (kinc_float32x4_t) { \ - vgetq_lane_f32((abcd), ((left_1)&0x3)), vgetq_lane_f32((abcd), ((left_2)&0x3)), vgetq_lane_f32((efgh), ((right_1)&0x3)), \ - vgetq_lane_f32((efgh), ((right_2)&0x3)) \ + vgetq_lane_f32((abcd), ((left_1) & 0x3)), vgetq_lane_f32((abcd), ((left_2) & 0x3)), vgetq_lane_f32((efgh), ((right_1) & 0x3)), \ + vgetq_lane_f32((efgh), ((right_2) & 0x3)) \ } static inline kinc_float32x4_t kinc_float32x4_shuffle_aebf(kinc_float32x4_t abcd, kinc_float32x4_t efgh) { diff --git a/Kinc/Sources/kinc/simd/type_conversions.h b/Kinc/Sources/kinc/simd/type_conversions.h index 99b21cb..41379ba 100644 --- a/Kinc/Sources/kinc/simd/type_conversions.h +++ b/Kinc/Sources/kinc/simd/type_conversions.h @@ -2,10 +2,10 @@ #include "types.h" #include -#include +#include /*! \file type_conversions.h - \brief Provides type casts and type conversions between all 128bit SIMD types + \brief Provides functions to interpret one type as another type for all 128bit SIMD types */ #ifdef __cplusplus @@ -15,185 +15,185 @@ extern "C" { #if defined(KINC_SSE2) // Float32x4 ----> Other -static inline kinc_int32x4_t kinc_float32x4_cast_to_int32x4(kinc_float32x4_t t) { +static inline kinc_int32x4_t kinc_float32x4_reinterpret_as_int32x4(kinc_float32x4_t t) { return _mm_castps_si128(t); } -static inline kinc_uint32x4_t kinc_float32x4_cast_to_uint32x4(kinc_float32x4_t t) { +static inline kinc_uint32x4_t kinc_float32x4_reinterpret_as_uint32x4(kinc_float32x4_t t) { return _mm_castps_si128(t); } -static inline kinc_int16x8_t kinc_float32x4_cast_to_int16x8(kinc_float32x4_t t) { +static inline kinc_int16x8_t kinc_float32x4_reinterpret_as_int16x8(kinc_float32x4_t t) { return _mm_castps_si128(t); } -static inline kinc_uint16x8_t kinc_float32x4_cast_to_uint16x8(kinc_float32x4_t t) { +static inline kinc_uint16x8_t kinc_float32x4_reinterpret_as_uint16x8(kinc_float32x4_t t) { return _mm_castps_si128(t); } -static inline kinc_int8x16_t kinc_float32x4_cast_to_int8x16(kinc_float32x4_t t) { +static inline kinc_int8x16_t kinc_float32x4_reinterpret_as_int8x16(kinc_float32x4_t t) { return _mm_castps_si128(t); } -static inline kinc_uint8x16_t kinc_float32x4_cast_to_uint8x16(kinc_float32x4_t t) { +static inline kinc_uint8x16_t kinc_float32x4_reinterpret_as_uint8x16(kinc_float32x4_t t) { return _mm_castps_si128(t); } // Int32x4 ----> Other -static inline kinc_float32x4_t kinc_int32x4_cast_to_float32x4(kinc_int32x4_t t) { +static inline kinc_float32x4_t kinc_int32x4_reinterpret_as_float32x4(kinc_int32x4_t t) { return _mm_castsi128_ps(t); } -static inline kinc_uint32x4_t kinc_int32x4_cast_to_uint32x4(kinc_int32x4_t t) { +static inline kinc_uint32x4_t kinc_int32x4_reinterpret_as_uint32x4(kinc_int32x4_t t) { // SSE2's m128i is every int type, so we can just return any inbound int type parameter return t; } -static inline kinc_int16x8_t kinc_int32x4_cast_to_int16x8(kinc_int32x4_t t) { +static inline kinc_int16x8_t kinc_int32x4_reinterpret_as_int16x8(kinc_int32x4_t t) { return t; } -static inline kinc_uint16x8_t kinc_int32x4_cast_to_uint16x8(kinc_int32x4_t t) { +static inline kinc_uint16x8_t kinc_int32x4_reinterpret_as_uint16x8(kinc_int32x4_t t) { return t; } -static inline kinc_int8x16_t kinc_int32x4_cast_to_int8x16(kinc_int32x4_t t) { +static inline kinc_int8x16_t kinc_int32x4_reinterpret_as_int8x16(kinc_int32x4_t t) { return t; } -static inline kinc_uint8x16_t kinc_int32x4_cast_to_uint8x16(kinc_int32x4_t t) { +static inline kinc_uint8x16_t kinc_int32x4_reinterpret_as_uint8x16(kinc_int32x4_t t) { return t; } // Unsigned Int32x4 ----> Other -static inline kinc_float32x4_t kinc_uint32x4_cast_to_float32x4(kinc_uint32x4_t t) { +static inline kinc_float32x4_t kinc_uint32x4_reinterpret_as_float32x4(kinc_uint32x4_t t) { return _mm_castsi128_ps(t); } -static inline kinc_int32x4_t kinc_uint32x4_cast_to_int32x4(kinc_uint32x4_t t) { +static inline kinc_int32x4_t kinc_uint32x4_reinterpret_as_int32x4(kinc_uint32x4_t t) { return t; } -static inline kinc_int16x8_t kinc_uint32x4_cast_to_int16x8(kinc_uint32x4_t t) { +static inline kinc_int16x8_t kinc_uint32x4_reinterpret_as_int16x8(kinc_uint32x4_t t) { return t; } -static inline kinc_uint16x8_t kinc_uint32x4_cast_to_uint16x8(kinc_uint32x4_t t) { +static inline kinc_uint16x8_t kinc_uint32x4_reinterpret_as_uint16x8(kinc_uint32x4_t t) { return t; } -static inline kinc_int8x16_t kinc_uint32x4_cast_to_int8x16(kinc_uint32x4_t t) { +static inline kinc_int8x16_t kinc_uint32x4_reinterpret_as_int8x16(kinc_uint32x4_t t) { return t; } -static inline kinc_uint8x16_t kinc_uint32x4_cast_to_uint8x16(kinc_uint32x4_t t) { +static inline kinc_uint8x16_t kinc_uint32x4_reinterpret_as_uint8x16(kinc_uint32x4_t t) { return t; } // Int16x8 ----> Other -static inline kinc_float32x4_t kinc_int16x8_cast_to_float32x4(kinc_int16x8_t t) { +static inline kinc_float32x4_t kinc_int16x8_reinterpret_as_float32x4(kinc_int16x8_t t) { return _mm_castsi128_ps(t); } -static inline kinc_int32x4_t kinc_int16x8_cast_to_int32x4(kinc_int16x8_t t) { +static inline kinc_int32x4_t kinc_int16x8_reinterpret_as_int32x4(kinc_int16x8_t t) { return t; } -static inline kinc_uint32x4_t kinc_int16x8_cast_to_uint32x4(kinc_int16x8_t t) { +static inline kinc_uint32x4_t kinc_int16x8_reinterpret_as_uint32x4(kinc_int16x8_t t) { return t; } -static inline kinc_uint16x8_t kinc_int16x8_cast_to_uint16x8(kinc_int16x8_t t) { +static inline kinc_uint16x8_t kinc_int16x8_reinterpret_as_uint16x8(kinc_int16x8_t t) { return t; } -static inline kinc_int8x16_t kinc_int16x8_cast_to_int8x16(kinc_int16x8_t t) { +static inline kinc_int8x16_t kinc_int16x8_reinterpret_as_int8x16(kinc_int16x8_t t) { return t; } -static inline kinc_uint8x16_t kinc_int16x8_cast_to_uint8x16(kinc_int16x8_t t) { +static inline kinc_uint8x16_t kinc_int16x8_reinterpret_as_uint8x16(kinc_int16x8_t t) { return t; } // Unsigned Int16x8 ----> Other -static inline kinc_float32x4_t kinc_uint16x8_cast_to_float32x4(kinc_uint16x8_t t) { +static inline kinc_float32x4_t kinc_uint16x8_reinterpret_as_float32x4(kinc_uint16x8_t t) { return _mm_castsi128_ps(t); } -static inline kinc_int32x4_t kinc_uint16x8_cast_to_int32x4(kinc_uint16x8_t t) { +static inline kinc_int32x4_t kinc_uint16x8_reinterpret_as_int32x4(kinc_uint16x8_t t) { return t; } -static inline kinc_uint32x4_t kinc_uint16x8_cast_to_uint32x4(kinc_uint16x8_t t) { +static inline kinc_uint32x4_t kinc_uint16x8_reinterpret_as_uint32x4(kinc_uint16x8_t t) { return t; } -static inline kinc_int16x8_t kinc_uint16x8_cast_to_int16x8(kinc_uint16x8_t t) { +static inline kinc_int16x8_t kinc_uint16x8_reinterpret_as_int16x8(kinc_uint16x8_t t) { return t; } -static inline kinc_int8x16_t kinc_uint16x8_cast_to_int8x16(kinc_uint16x8_t t) { +static inline kinc_int8x16_t kinc_uint16x8_reinterpret_as_int8x16(kinc_uint16x8_t t) { return t; } -static inline kinc_uint8x16_t kinc_uint16x8_cast_to_uint8x16(kinc_uint16x8_t t) { +static inline kinc_uint8x16_t kinc_uint16x8_reinterpret_as_uint8x16(kinc_uint16x8_t t) { return t; } // Int8x16 ----> Other -static inline kinc_float32x4_t kinc_int8x16_cast_to_float32x4(kinc_int8x16_t t) { +static inline kinc_float32x4_t kinc_int8x16_reinterpret_as_float32x4(kinc_int8x16_t t) { return _mm_castsi128_ps(t); } -static inline kinc_int32x4_t kinc_int8x16_cast_to_int32x4(kinc_int8x16_t t) { +static inline kinc_int32x4_t kinc_int8x16_reinterpret_as_int32x4(kinc_int8x16_t t) { return t; } -static inline kinc_uint32x4_t kinc_int8x16_cast_to_uint32x4(kinc_int8x16_t t) { +static inline kinc_uint32x4_t kinc_int8x16_reinterpret_as_uint32x4(kinc_int8x16_t t) { return t; } -static inline kinc_int16x8_t kinc_int8x16_cast_to_int16x8(kinc_int8x16_t t) { +static inline kinc_int16x8_t kinc_int8x16_reinterpret_as_int16x8(kinc_int8x16_t t) { return t; } -static inline kinc_uint16x8_t kinc_int8x16_cast_to_uint16x8(kinc_int8x16_t t) { +static inline kinc_uint16x8_t kinc_int8x16_reinterpret_as_uint16x8(kinc_int8x16_t t) { return t; } -static inline kinc_uint8x16_t kinc_int8x16_cast_to_uint8x16(kinc_int8x16_t t) { +static inline kinc_uint8x16_t kinc_int8x16_reinterpret_as_uint8x16(kinc_int8x16_t t) { return t; } // Unsigned Int8x16 ----> Other -static inline kinc_float32x4_t kinc_uint8x16_cast_to_float32x4(kinc_uint8x16_t t) { +static inline kinc_float32x4_t kinc_uint8x16_reinterpret_as_float32x4(kinc_uint8x16_t t) { return _mm_castsi128_ps(t); } -static inline kinc_int32x4_t kinc_uint8x16_cast_to_int32x4(kinc_uint8x16_t t) { +static inline kinc_int32x4_t kinc_uint8x16_reinterpret_as_int32x4(kinc_uint8x16_t t) { return t; } -static inline kinc_uint32x4_t kinc_uint8x16_cast_to_uint32x4(kinc_uint8x16_t t) { +static inline kinc_uint32x4_t kinc_uint8x16_reinterpret_as_uint32x4(kinc_uint8x16_t t) { return t; } -static inline kinc_int16x8_t kinc_uint8x16_cast_to_int16x8(kinc_uint8x16_t t) { +static inline kinc_int16x8_t kinc_uint8x16_reinterpret_as_int16x8(kinc_uint8x16_t t) { return t; } -static inline kinc_uint16x8_t kinc_uint8x16_cast_to_uint16x8(kinc_uint8x16_t t) { +static inline kinc_uint16x8_t kinc_uint8x16_reinterpret_as_uint16x8(kinc_uint8x16_t t) { return t; } -static inline kinc_int8x16_t kinc_uint8x16_cast_to_int8x16(kinc_uint8x16_t t) { +static inline kinc_int8x16_t kinc_uint8x16_reinterpret_as_int8x16(kinc_uint8x16_t t) { return t; } #elif defined(KINC_SSE) // Float32x4 ----> Other -static inline kinc_int32x4_t kinc_float32x4_cast_to_int32x4(kinc_float32x4_t t) { +static inline kinc_int32x4_t kinc_float32x4_reinterpret_as_int32x4(kinc_float32x4_t t) { float extracted[4]; _mm_storeu_ps(&extracted[0], t); @@ -203,7 +203,7 @@ static inline kinc_int32x4_t kinc_float32x4_cast_to_int32x4(kinc_float32x4_t t) return cvt; } -static inline kinc_uint32x4_t kinc_float32x4_cast_to_uint32x4(kinc_float32x4_t t) { +static inline kinc_uint32x4_t kinc_float32x4_reinterpret_as_uint32x4(kinc_float32x4_t t) { float extracted[4]; _mm_storeu_ps(&extracted[0], t); @@ -213,7 +213,7 @@ static inline kinc_uint32x4_t kinc_float32x4_cast_to_uint32x4(kinc_float32x4_t t return cvt; } -static inline kinc_int16x8_t kinc_float32x4_cast_to_int16x8(kinc_float32x4_t t) { +static inline kinc_int16x8_t kinc_float32x4_reinterpret_as_int16x8(kinc_float32x4_t t) { float extracted[4]; _mm_storeu_ps(&extracted[0], t); @@ -223,7 +223,7 @@ static inline kinc_int16x8_t kinc_float32x4_cast_to_int16x8(kinc_float32x4_t t) return cvt; } -static inline kinc_uint16x8_t kinc_float32x4_cast_to_uint16x8(kinc_float32x4_t t) { +static inline kinc_uint16x8_t kinc_float32x4_reinterpret_as_uint16x8(kinc_float32x4_t t) { float extracted[4]; _mm_storeu_ps(&extracted[0], t); @@ -233,7 +233,7 @@ static inline kinc_uint16x8_t kinc_float32x4_cast_to_uint16x8(kinc_float32x4_t t return cvt; } -static inline kinc_int8x16_t kinc_float32x4_cast_to_int8x16(kinc_float32x4_t t) { +static inline kinc_int8x16_t kinc_float32x4_reinterpret_as_int8x16(kinc_float32x4_t t) { float extracted[4]; _mm_storeu_ps(&extracted[0], t); @@ -243,7 +243,7 @@ static inline kinc_int8x16_t kinc_float32x4_cast_to_int8x16(kinc_float32x4_t t) return cvt; } -static inline kinc_uint8x16_t kinc_float32x4_cast_to_uint8x16(kinc_float32x4_t t) { +static inline kinc_uint8x16_t kinc_float32x4_reinterpret_as_uint8x16(kinc_float32x4_t t) { float extracted[4]; _mm_storeu_ps(&extracted[0], t); @@ -254,7 +254,7 @@ static inline kinc_uint8x16_t kinc_float32x4_cast_to_uint8x16(kinc_float32x4_t t } // Int32x4 ----> Other -static inline kinc_float32x4_t kinc_int32x4_cast_to_float32x4(kinc_int32x4_t t) { +static inline kinc_float32x4_t kinc_int32x4_reinterpret_as_float32x4(kinc_int32x4_t t) { float cvt[4]; memcpy(&cvt[0], &t.values[0], sizeof(t)); @@ -262,7 +262,7 @@ static inline kinc_float32x4_t kinc_int32x4_cast_to_float32x4(kinc_int32x4_t t) } // Unsigned Int32x4 ----> Other -static inline kinc_float32x4_t kinc_uint32x4_cast_to_float32x4(kinc_uint32x4_t t) { +static inline kinc_float32x4_t kinc_uint32x4_reinterpret_as_float32x4(kinc_uint32x4_t t) { float cvt[4]; memcpy(&cvt[0], &t.values[0], sizeof(t)); @@ -270,7 +270,7 @@ static inline kinc_float32x4_t kinc_uint32x4_cast_to_float32x4(kinc_uint32x4_t t } // Int16x8 ----> Other -static inline kinc_float32x4_t kinc_int16x8_cast_to_float32x4(kinc_int16x8_t t) { +static inline kinc_float32x4_t kinc_int16x8_reinterpret_as_float32x4(kinc_int16x8_t t) { float cvt[4]; memcpy(&cvt[0], &t.values[0], sizeof(t)); @@ -278,7 +278,7 @@ static inline kinc_float32x4_t kinc_int16x8_cast_to_float32x4(kinc_int16x8_t t) } // Unsigned Int16x8 ----> Other -static inline kinc_float32x4_t kinc_uint16x8_cast_to_float32x4(kinc_uint16x8_t t) { +static inline kinc_float32x4_t kinc_uint16x8_reinterpret_as_float32x4(kinc_uint16x8_t t) { float cvt[4]; memcpy(&cvt[0], &t.values[0], sizeof(t)); @@ -286,7 +286,7 @@ static inline kinc_float32x4_t kinc_uint16x8_cast_to_float32x4(kinc_uint16x8_t t } // Int8x16 ----> Other -static inline kinc_float32x4_t kinc_int8x16_cast_to_float32x4(kinc_int8x16_t t) { +static inline kinc_float32x4_t kinc_int8x16_reinterpret_as_float32x4(kinc_int8x16_t t) { float cvt[4]; memcpy(&cvt[0], &t.values[0], sizeof(t)); @@ -294,7 +294,7 @@ static inline kinc_float32x4_t kinc_int8x16_cast_to_float32x4(kinc_int8x16_t t) } // Unsigned Int8x16 ----> Other -static inline kinc_float32x4_t kinc_uint8x16_cast_to_float32x4(kinc_uint8x16_t t) { +static inline kinc_float32x4_t kinc_uint8x16_reinterpret_as_float32x4(kinc_uint8x16_t t) { float cvt[4]; memcpy(&cvt[0], &t.values[0], sizeof(t)); @@ -304,177 +304,177 @@ static inline kinc_float32x4_t kinc_uint8x16_cast_to_float32x4(kinc_uint8x16_t t #elif defined(KINC_NEON) // Float32x4 ----> Other -static inline kinc_int32x4_t kinc_float32x4_cast_to_int32x4(kinc_float32x4_t t) { +static inline kinc_int32x4_t kinc_float32x4_reinterpret_as_int32x4(kinc_float32x4_t t) { return vreinterpretq_s32_f32(t); } -static inline kinc_uint32x4_t kinc_float32x4_cast_to_uint32x4(kinc_float32x4_t t) { +static inline kinc_uint32x4_t kinc_float32x4_reinterpret_as_uint32x4(kinc_float32x4_t t) { return vreinterpretq_u32_f32(t); } -static inline kinc_int16x8_t kinc_float32x4_cast_to_int16x8(kinc_float32x4_t t) { +static inline kinc_int16x8_t kinc_float32x4_reinterpret_as_int16x8(kinc_float32x4_t t) { return vreinterpretq_s16_f32(t); } -static inline kinc_uint16x8_t kinc_float32x4_cast_to_uint16x8(kinc_float32x4_t t) { +static inline kinc_uint16x8_t kinc_float32x4_reinterpret_as_uint16x8(kinc_float32x4_t t) { return vreinterpretq_u16_f32(t); } -static inline kinc_int8x16_t kinc_float32x4_cast_to_int8x16(kinc_float32x4_t t) { +static inline kinc_int8x16_t kinc_float32x4_reinterpret_as_int8x16(kinc_float32x4_t t) { return vreinterpretq_s8_f32(t); } -static inline kinc_uint8x16_t kinc_float32x4_cast_to_uint8x16(kinc_float32x4_t t) { +static inline kinc_uint8x16_t kinc_float32x4_reinterpret_as_uint8x16(kinc_float32x4_t t) { return vreinterpretq_u8_f32(t); } // Int32x4 ----> Other -static inline kinc_float32x4_t kinc_int32x4_cast_to_float32x4(kinc_int32x4_t t) { +static inline kinc_float32x4_t kinc_int32x4_reinterpret_as_float32x4(kinc_int32x4_t t) { return vreinterpretq_f32_s32(t); } -static inline kinc_uint32x4_t kinc_int32x4_cast_to_uint32x4(kinc_int32x4_t t) { +static inline kinc_uint32x4_t kinc_int32x4_reinterpret_as_uint32x4(kinc_int32x4_t t) { return vreinterpretq_u32_s32(t); } -static inline kinc_int16x8_t kinc_int32x4_cast_to_int16x8(kinc_int32x4_t t) { +static inline kinc_int16x8_t kinc_int32x4_reinterpret_as_int16x8(kinc_int32x4_t t) { return vreinterpretq_s16_s32(t); } -static inline kinc_uint16x8_t kinc_int32x4_cast_to_uint16x8(kinc_int32x4_t t) { +static inline kinc_uint16x8_t kinc_int32x4_reinterpret_as_uint16x8(kinc_int32x4_t t) { return vreinterpretq_u16_s32(t); } -static inline kinc_int8x16_t kinc_int32x4_cast_to_int8x16(kinc_int32x4_t t) { +static inline kinc_int8x16_t kinc_int32x4_reinterpret_as_int8x16(kinc_int32x4_t t) { return vreinterpretq_s8_s32(t); } -static inline kinc_uint8x16_t kinc_int32x4_cast_to_uint8x16(kinc_int32x4_t t) { +static inline kinc_uint8x16_t kinc_int32x4_reinterpret_as_uint8x16(kinc_int32x4_t t) { return vreinterpretq_u8_s32(t); } // Unsigned Int32x4 ----> Other -static inline kinc_float32x4_t kinc_uint32x4_cast_to_float32x4(kinc_uint32x4_t t) { +static inline kinc_float32x4_t kinc_uint32x4_reinterpret_as_float32x4(kinc_uint32x4_t t) { return vreinterpretq_f32_u32(t); } -static inline kinc_int32x4_t kinc_uint32x4_cast_to_int32x4(kinc_uint32x4_t t) { +static inline kinc_int32x4_t kinc_uint32x4_reinterpret_as_int32x4(kinc_uint32x4_t t) { return vreinterpretq_s32_u32(t); } -static inline kinc_int16x8_t kinc_uint32x4_cast_to_int16x8(kinc_uint32x4_t t) { +static inline kinc_int16x8_t kinc_uint32x4_reinterpret_as_int16x8(kinc_uint32x4_t t) { return vreinterpretq_s16_u32(t); } -static inline kinc_uint16x8_t kinc_uint32x4_cast_to_uint16x8(kinc_uint32x4_t t) { +static inline kinc_uint16x8_t kinc_uint32x4_reinterpret_as_uint16x8(kinc_uint32x4_t t) { return vreinterpretq_u16_u32(t); } -static inline kinc_int8x16_t kinc_uint32x4_cast_to_int8x16(kinc_uint32x4_t t) { +static inline kinc_int8x16_t kinc_uint32x4_reinterpret_as_int8x16(kinc_uint32x4_t t) { return vreinterpretq_s8_u32(t); } -static inline kinc_uint8x16_t kinc_uint32x4_cast_to_uint8x16(kinc_uint32x4_t t) { +static inline kinc_uint8x16_t kinc_uint32x4_reinterpret_as_uint8x16(kinc_uint32x4_t t) { return vreinterpretq_u8_u32(t); } // Int16x8 ----> Other -static inline kinc_float32x4_t kinc_int16x8_cast_to_float32x4(kinc_int16x8_t t) { +static inline kinc_float32x4_t kinc_int16x8_reinterpret_as_float32x4(kinc_int16x8_t t) { return vreinterpretq_f32_s16(t); } -static inline kinc_int32x4_t kinc_int16x8_cast_to_int32x4(kinc_int16x8_t t) { +static inline kinc_int32x4_t kinc_int16x8_reinterpret_as_int32x4(kinc_int16x8_t t) { return vreinterpretq_s32_s16(t); } -static inline kinc_uint32x4_t kinc_int16x8_cast_to_uint32x4(kinc_int16x8_t t) { +static inline kinc_uint32x4_t kinc_int16x8_reinterpret_as_uint32x4(kinc_int16x8_t t) { return vreinterpretq_u32_s16(t); } -static inline kinc_uint16x8_t kinc_int16x8_cast_to_uint16x8(kinc_int16x8_t t) { +static inline kinc_uint16x8_t kinc_int16x8_reinterpret_as_uint16x8(kinc_int16x8_t t) { return vreinterpretq_u16_s16(t); } -static inline kinc_int8x16_t kinc_int16x8_cast_to_int8x16(kinc_int16x8_t t) { +static inline kinc_int8x16_t kinc_int16x8_reinterpret_as_int8x16(kinc_int16x8_t t) { return vreinterpretq_s8_s16(t); } -static inline kinc_uint8x16_t kinc_int16x8_cast_to_uint8x16(kinc_int16x8_t t) { +static inline kinc_uint8x16_t kinc_int16x8_reinterpret_as_uint8x16(kinc_int16x8_t t) { return vreinterpretq_u8_s16(t); } // Unsigned Int16x8 ----> Other -static inline kinc_float32x4_t kinc_uint16x8_cast_to_float32x4(kinc_uint16x8_t t) { +static inline kinc_float32x4_t kinc_uint16x8_reinterpret_as_float32x4(kinc_uint16x8_t t) { return vreinterpretq_f32_u16(t); } -static inline kinc_int32x4_t kinc_uint16x8_cast_to_int32x4(kinc_uint16x8_t t) { +static inline kinc_int32x4_t kinc_uint16x8_reinterpret_as_int32x4(kinc_uint16x8_t t) { return vreinterpretq_s32_u16(t); } -static inline kinc_uint32x4_t kinc_uint16x8_cast_to_uint32x4(kinc_uint16x8_t t) { +static inline kinc_uint32x4_t kinc_uint16x8_reinterpret_as_uint32x4(kinc_uint16x8_t t) { return vreinterpretq_u32_u16(t); } -static inline kinc_int16x8_t kinc_uint16x8_cast_to_int16x8(kinc_uint16x8_t t) { +static inline kinc_int16x8_t kinc_uint16x8_reinterpret_as_int16x8(kinc_uint16x8_t t) { return vreinterpretq_s16_u16(t); } -static inline kinc_int8x16_t kinc_uint16x8_cast_to_int8x16(kinc_uint16x8_t t) { +static inline kinc_int8x16_t kinc_uint16x8_reinterpret_as_int8x16(kinc_uint16x8_t t) { return vreinterpretq_s8_u16(t); } -static inline kinc_uint8x16_t kinc_uint16x8_cast_to_uint8x16(kinc_uint16x8_t t) { +static inline kinc_uint8x16_t kinc_uint16x8_reinterpret_as_uint8x16(kinc_uint16x8_t t) { return vreinterpretq_u8_u16(t); } // Int8x16 ----> Other -static inline kinc_float32x4_t kinc_int8x16_cast_to_float32x4(kinc_int8x16_t t) { +static inline kinc_float32x4_t kinc_int8x16_reinterpret_as_float32x4(kinc_int8x16_t t) { return vreinterpretq_f32_s8(t); } -static inline kinc_int32x4_t kinc_int8x16_cast_to_int32x4(kinc_int8x16_t t) { +static inline kinc_int32x4_t kinc_int8x16_reinterpret_as_int32x4(kinc_int8x16_t t) { return vreinterpretq_s32_s8(t); } -static inline kinc_uint32x4_t kinc_int8x16_cast_to_uint32x4(kinc_int8x16_t t) { +static inline kinc_uint32x4_t kinc_int8x16_reinterpret_as_uint32x4(kinc_int8x16_t t) { return vreinterpretq_u32_s8(t); } -static inline kinc_int16x8_t kinc_int8x16_cast_to_int16x8(kinc_int8x16_t t) { +static inline kinc_int16x8_t kinc_int8x16_reinterpret_as_int16x8(kinc_int8x16_t t) { return vreinterpretq_s16_s8(t); } -static inline kinc_uint16x8_t kinc_int8x16_cast_to_uint16x8(kinc_int8x16_t t) { +static inline kinc_uint16x8_t kinc_int8x16_reinterpret_as_uint16x8(kinc_int8x16_t t) { return vreinterpretq_u16_s8(t); } -static inline kinc_uint8x16_t kinc_int8x16_cast_to_uint8x16(kinc_int8x16_t t) { +static inline kinc_uint8x16_t kinc_int8x16_reinterpret_as_uint8x16(kinc_int8x16_t t) { return vreinterpretq_u8_s8(t); } // Unsigned Int8x16 ----> Other -static inline kinc_float32x4_t kinc_uint8x16_cast_to_float32x4(kinc_uint8x16_t t) { +static inline kinc_float32x4_t kinc_uint8x16_reinterpret_as_float32x4(kinc_uint8x16_t t) { return vreinterpretq_f32_u8(t); } -static inline kinc_int32x4_t kinc_uint8x16_cast_to_int32x4(kinc_uint8x16_t t) { +static inline kinc_int32x4_t kinc_uint8x16_reinterpret_as_int32x4(kinc_uint8x16_t t) { return vreinterpretq_s32_u8(t); } -static inline kinc_uint32x4_t kinc_uint8x16_cast_to_uint32x4(kinc_uint8x16_t t) { +static inline kinc_uint32x4_t kinc_uint8x16_reinterpret_as_uint32x4(kinc_uint8x16_t t) { return vreinterpretq_u32_u8(t); } -static inline kinc_int16x8_t kinc_uint8x16_cast_to_int16x8(kinc_uint8x16_t t) { +static inline kinc_int16x8_t kinc_uint8x16_reinterpret_as_int16x8(kinc_uint8x16_t t) { return vreinterpretq_s16_u8(t); } -static inline kinc_uint16x8_t kinc_uint8x16_cast_to_uint16x8(kinc_uint8x16_t t) { +static inline kinc_uint16x8_t kinc_uint8x16_reinterpret_as_uint16x8(kinc_uint8x16_t t) { return vreinterpretq_u16_u8(t); } -static inline kinc_int8x16_t kinc_uint8x16_cast_to_int8x16(kinc_uint8x16_t t) { +static inline kinc_int8x16_t kinc_uint8x16_reinterpret_as_int8x16(kinc_uint8x16_t t) { return vreinterpretq_s8_u8(t); } @@ -482,42 +482,42 @@ static inline kinc_int8x16_t kinc_uint8x16_cast_to_int8x16(kinc_uint8x16_t t) { #else // Float32x4 ----> Other -static inline kinc_int32x4_t kinc_float32x4_cast_to_int32x4(kinc_float32x4_t t) { +static inline kinc_int32x4_t kinc_float32x4_reinterpret_as_int32x4(kinc_float32x4_t t) { kinc_int32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint32x4_t kinc_float32x4_cast_to_uint32x4(kinc_float32x4_t t) { +static inline kinc_uint32x4_t kinc_float32x4_reinterpret_as_uint32x4(kinc_float32x4_t t) { kinc_uint32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int16x8_t kinc_float32x4_cast_to_int16x8(kinc_float32x4_t t) { +static inline kinc_int16x8_t kinc_float32x4_reinterpret_as_int16x8(kinc_float32x4_t t) { kinc_int16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint16x8_t kinc_float32x4_cast_to_uint16x8(kinc_float32x4_t t) { +static inline kinc_uint16x8_t kinc_float32x4_reinterpret_as_uint16x8(kinc_float32x4_t t) { kinc_uint16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int8x16_t kinc_float32x4_cast_to_int8x16(kinc_float32x4_t t) { +static inline kinc_int8x16_t kinc_float32x4_reinterpret_as_int8x16(kinc_float32x4_t t) { kinc_int8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint8x16_t kinc_float32x4_cast_to_uint8x16(kinc_float32x4_t t) { +static inline kinc_uint8x16_t kinc_float32x4_reinterpret_as_uint8x16(kinc_float32x4_t t) { kinc_uint8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -525,7 +525,7 @@ static inline kinc_uint8x16_t kinc_float32x4_cast_to_uint8x16(kinc_float32x4_t t } // Int32x4 ----> Float32x4 -static inline kinc_float32x4_t kinc_int32x4_cast_to_float32x4(kinc_int32x4_t t) { +static inline kinc_float32x4_t kinc_int32x4_reinterpret_as_float32x4(kinc_int32x4_t t) { kinc_float32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -533,7 +533,7 @@ static inline kinc_float32x4_t kinc_int32x4_cast_to_float32x4(kinc_int32x4_t t) } // Unsigned Int32x4 ----> Float32x4 -static inline kinc_float32x4_t kinc_uint32x4_cast_to_float32x4(kinc_uint32x4_t t) { +static inline kinc_float32x4_t kinc_uint32x4_reinterpret_as_float32x4(kinc_uint32x4_t t) { kinc_float32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -541,7 +541,7 @@ static inline kinc_float32x4_t kinc_uint32x4_cast_to_float32x4(kinc_uint32x4_t t } // Int16x8 ----> Float32x4 -static inline kinc_float32x4_t kinc_int16x8_cast_to_float32x4(kinc_int16x8_t t) { +static inline kinc_float32x4_t kinc_int16x8_reinterpret_as_float32x4(kinc_int16x8_t t) { kinc_float32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -549,7 +549,7 @@ static inline kinc_float32x4_t kinc_int16x8_cast_to_float32x4(kinc_int16x8_t t) } // Unsigned Int16x8 ----> Float32x4 -static inline kinc_float32x4_t kinc_uint16x8_cast_to_float32x4(kinc_uint16x8_t t) { +static inline kinc_float32x4_t kinc_uint16x8_reinterpret_as_float32x4(kinc_uint16x8_t t) { kinc_float32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -557,7 +557,7 @@ static inline kinc_float32x4_t kinc_uint16x8_cast_to_float32x4(kinc_uint16x8_t t } // Int8x16 ----> Float32x4 -static inline kinc_float32x4_t kinc_int8x16_cast_to_float32x4(kinc_int8x16_t t) { +static inline kinc_float32x4_t kinc_int8x16_reinterpret_as_float32x4(kinc_int8x16_t t) { kinc_float32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -565,7 +565,7 @@ static inline kinc_float32x4_t kinc_int8x16_cast_to_float32x4(kinc_int8x16_t t) } // Unsigned Int8x16 ----> Float32x4 -static inline kinc_float32x4_t kinc_uint8x16_cast_to_float32x4(kinc_uint8x16_t t) { +static inline kinc_float32x4_t kinc_uint8x16_reinterpret_as_float32x4(kinc_uint8x16_t t) { kinc_float32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -578,35 +578,35 @@ static inline kinc_float32x4_t kinc_uint8x16_cast_to_float32x4(kinc_uint8x16_t t #if !defined(KINC_SSE2) && (defined(KINC_SSE) || defined(KINC_NOSIMD)) // Int32x4 ----> Other -static inline kinc_uint32x4_t kinc_int32x4_cast_to_uint32x4(kinc_int32x4_t t) { +static inline kinc_uint32x4_t kinc_int32x4_reinterpret_as_uint32x4(kinc_int32x4_t t) { kinc_uint32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int16x8_t kinc_int32x4_cast_to_int16x8(kinc_int32x4_t t) { +static inline kinc_int16x8_t kinc_int32x4_reinterpret_as_int16x8(kinc_int32x4_t t) { kinc_int16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint16x8_t kinc_int32x4_cast_to_uint16x8(kinc_int32x4_t t) { +static inline kinc_uint16x8_t kinc_int32x4_reinterpret_as_uint16x8(kinc_int32x4_t t) { kinc_uint16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int8x16_t kinc_int32x4_cast_to_int8x16(kinc_int32x4_t t) { +static inline kinc_int8x16_t kinc_int32x4_reinterpret_as_int8x16(kinc_int32x4_t t) { kinc_int8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint8x16_t kinc_int32x4_cast_to_uint8x16(kinc_int32x4_t t) { +static inline kinc_uint8x16_t kinc_int32x4_reinterpret_as_uint8x16(kinc_int32x4_t t) { kinc_uint8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -614,35 +614,35 @@ static inline kinc_uint8x16_t kinc_int32x4_cast_to_uint8x16(kinc_int32x4_t t) { } // Unsigned Int32x4 ----> Other -static inline kinc_int32x4_t kinc_uint32x4_cast_to_int32x4(kinc_uint32x4_t t) { +static inline kinc_int32x4_t kinc_uint32x4_reinterpret_as_int32x4(kinc_uint32x4_t t) { kinc_int32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int16x8_t kinc_uint32x4_cast_to_int16x8(kinc_uint32x4_t t) { +static inline kinc_int16x8_t kinc_uint32x4_reinterpret_as_int16x8(kinc_uint32x4_t t) { kinc_int16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint16x8_t kinc_uint32x4_cast_to_uint16x8(kinc_uint32x4_t t) { +static inline kinc_uint16x8_t kinc_uint32x4_reinterpret_as_uint16x8(kinc_uint32x4_t t) { kinc_uint16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int8x16_t kinc_uint32x4_cast_to_int8x16(kinc_uint32x4_t t) { +static inline kinc_int8x16_t kinc_uint32x4_reinterpret_as_int8x16(kinc_uint32x4_t t) { kinc_int8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint8x16_t kinc_uint32x4_cast_to_uint8x16(kinc_uint32x4_t t) { +static inline kinc_uint8x16_t kinc_uint32x4_reinterpret_as_uint8x16(kinc_uint32x4_t t) { kinc_uint8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -650,35 +650,35 @@ static inline kinc_uint8x16_t kinc_uint32x4_cast_to_uint8x16(kinc_uint32x4_t t) } // Int16x8 ----> Other -static inline kinc_int32x4_t kinc_int16x8_cast_to_int32x4(kinc_int16x8_t t) { +static inline kinc_int32x4_t kinc_int16x8_reinterpret_as_int32x4(kinc_int16x8_t t) { kinc_int32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint32x4_t kinc_int16x8_cast_to_uint32x4(kinc_int16x8_t t) { +static inline kinc_uint32x4_t kinc_int16x8_reinterpret_as_uint32x4(kinc_int16x8_t t) { kinc_uint32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint16x8_t kinc_int16x8_cast_to_uint16x8(kinc_int16x8_t t) { +static inline kinc_uint16x8_t kinc_int16x8_reinterpret_as_uint16x8(kinc_int16x8_t t) { kinc_uint16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int8x16_t kinc_int16x8_cast_to_int8x16(kinc_int16x8_t t) { +static inline kinc_int8x16_t kinc_int16x8_reinterpret_as_int8x16(kinc_int16x8_t t) { kinc_int8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint8x16_t kinc_int16x8_cast_to_uint8x16(kinc_int16x8_t t) { +static inline kinc_uint8x16_t kinc_int16x8_reinterpret_as_uint8x16(kinc_int16x8_t t) { kinc_uint8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -686,35 +686,35 @@ static inline kinc_uint8x16_t kinc_int16x8_cast_to_uint8x16(kinc_int16x8_t t) { } // Unsigned Int16x8 ----> Other -static inline kinc_int32x4_t kinc_uint16x8_cast_to_int32x4(kinc_uint16x8_t t) { +static inline kinc_int32x4_t kinc_uint16x8_reinterpret_as_int32x4(kinc_uint16x8_t t) { kinc_int32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint32x4_t kinc_uint16x8_cast_to_uint32x4(kinc_uint16x8_t t) { +static inline kinc_uint32x4_t kinc_uint16x8_reinterpret_as_uint32x4(kinc_uint16x8_t t) { kinc_uint32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int16x8_t kinc_uint16x8_cast_to_int16x8(kinc_uint16x8_t t) { +static inline kinc_int16x8_t kinc_uint16x8_reinterpret_as_int16x8(kinc_uint16x8_t t) { kinc_int16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int8x16_t kinc_uint16x8_cast_to_int8x16(kinc_uint16x8_t t) { +static inline kinc_int8x16_t kinc_uint16x8_reinterpret_as_int8x16(kinc_uint16x8_t t) { kinc_int8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint8x16_t kinc_uint16x8_cast_to_uint8x16(kinc_uint16x8_t t) { +static inline kinc_uint8x16_t kinc_uint16x8_reinterpret_as_uint8x16(kinc_uint16x8_t t) { kinc_uint8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -722,35 +722,35 @@ static inline kinc_uint8x16_t kinc_uint16x8_cast_to_uint8x16(kinc_uint16x8_t t) } // Int8x16 ----> Other -static inline kinc_int32x4_t kinc_int8x16_cast_to_int32x4(kinc_int8x16_t t) { +static inline kinc_int32x4_t kinc_int8x16_reinterpret_as_int32x4(kinc_int8x16_t t) { kinc_int32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint32x4_t kinc_int8x16_cast_to_uint32x4(kinc_int8x16_t t) { +static inline kinc_uint32x4_t kinc_int8x16_reinterpret_as_uint32x4(kinc_int8x16_t t) { kinc_uint32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int16x8_t kinc_int8x16_cast_to_int16x8(kinc_int8x16_t t) { +static inline kinc_int16x8_t kinc_int8x16_reinterpret_as_int16x8(kinc_int8x16_t t) { kinc_int16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint16x8_t kinc_int8x16_cast_to_uint16x8(kinc_int8x16_t t) { +static inline kinc_uint16x8_t kinc_int8x16_reinterpret_as_uint16x8(kinc_int8x16_t t) { kinc_uint16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint8x16_t kinc_int8x16_cast_to_uint8x16(kinc_int8x16_t t) { +static inline kinc_uint8x16_t kinc_int8x16_reinterpret_as_uint8x16(kinc_int8x16_t t) { kinc_uint8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); @@ -758,35 +758,35 @@ static inline kinc_uint8x16_t kinc_int8x16_cast_to_uint8x16(kinc_int8x16_t t) { } // Unsigned Int8x16 ----> Other -static inline kinc_int32x4_t kinc_uint8x16_cast_to_int32x4(kinc_uint8x16_t t) { +static inline kinc_int32x4_t kinc_uint8x16_reinterpret_as_int32x4(kinc_uint8x16_t t) { kinc_int32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint32x4_t kinc_uint8x16_cast_to_uint32x4(kinc_uint8x16_t t) { +static inline kinc_uint32x4_t kinc_uint8x16_reinterpret_as_uint32x4(kinc_uint8x16_t t) { kinc_uint32x4_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int16x8_t kinc_uint8x16_cast_to_int16x8(kinc_uint8x16_t t) { +static inline kinc_int16x8_t kinc_uint8x16_reinterpret_as_int16x8(kinc_uint8x16_t t) { kinc_int16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_uint16x8_t kinc_uint8x16_cast_to_uint16x8(kinc_uint8x16_t t) { +static inline kinc_uint16x8_t kinc_uint8x16_reinterpret_as_uint16x8(kinc_uint8x16_t t) { kinc_uint16x8_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); return cvt; } -static inline kinc_int8x16_t kinc_uint8x16_cast_to_int8x16(kinc_uint8x16_t t) { +static inline kinc_int8x16_t kinc_uint8x16_reinterpret_as_int8x16(kinc_uint8x16_t t) { kinc_int8x16_t cvt; memcpy(&cvt.values[0], &t.values[0], sizeof(t)); diff --git a/Kinc/Sources/kinc/simd/types.h b/Kinc/Sources/kinc/simd/types.h index 38451d1..780c715 100644 --- a/Kinc/Sources/kinc/simd/types.h +++ b/Kinc/Sources/kinc/simd/types.h @@ -20,25 +20,30 @@ extern "C" { #define KINC_SSE4_1 #define KINC_SSSE3 #define KINC_SSE3 -#endif +#define KINC_SSE2 +#define KINC_SSE + +#else // SSE2 Capability check // Note for Windows: // _M_IX86_FP checks SSE2 and SSE for 32bit Windows programs only, and is unset if not a 32bit program. // SSE2 and earlier is --guaranteed-- to be active for any 64bit Windows program -#if defined(__SSE2__) || (_M_IX86_FP == 2) || (defined(KORE_WINDOWS) && defined(KORE_64)) +#if defined(__SSE2__) || (_M_IX86_FP == 2) || ((defined(KINC_WINDOWS) || defined(KINC_WINDOWSAPP)) && defined(KINC_64) && !defined(__aarch64__)) #define KINC_SSE2 #endif // SSE Capability check -#if defined(__SSE__) || _M_IX86_FP == 2 || _M_IX86_FP == 1 || (defined(KORE_WINDOWS) && !defined(__aarch64__)) || \ - (defined(KORE_WINDOWSAPP) && !defined(__aarch64__)) || (defined(KORE_MACOS) && __x86_64) +#if defined(__SSE__) || _M_IX86_FP == 2 || _M_IX86_FP == 1 || (defined(KINC_WINDOWS) && !defined(__aarch64__)) || \ + (defined(KINC_WINDOWSAPP) && !defined(__aarch64__)) || (defined(KINC_MACOS) && __x86_64) #define KINC_SSE #endif +#endif + // NEON Capability check -#if defined(KORE_IOS) || defined(KORE_SWITCH) || defined(__aarch64__) || defined(KORE_NEON) +#if defined(KINC_IOS) || defined(KINC_SWITCH) || defined(__aarch64__) || defined(KINC_NEON) #define KINC_NEON #endif @@ -50,7 +55,7 @@ extern "C" { #endif #define KINC_SHUFFLE_TABLE(LANE_A1, LANE_A2, LANE_B1, LANE_B2) \ - ((((LANE_B2)&0x3) << 6) | (((LANE_B1)&0x3) << 4) | (((LANE_A2)&0x3) << 2) | (((LANE_A1)&0x3) << 0)) + ((((LANE_B2) & 0x3) << 6) | (((LANE_B1) & 0x3) << 4) | (((LANE_A2) & 0x3) << 2) | (((LANE_A1) & 0x3) << 0)) #if defined(KINC_SSE2) diff --git a/Kinc/Sources/kinc/system.h b/Kinc/Sources/kinc/system.h index a5672d6..4a10f56 100644 --- a/Kinc/Sources/kinc/system.h +++ b/Kinc/Sources/kinc/system.h @@ -252,6 +252,7 @@ KINC_FUNC void kinc_set_drop_files_callback(void (*callback)(wchar_t *, void *), /// /// Sets a callback which is called when the application is instructed to cut, typically via ctrl+x or cmd+x. +/// Kinc does not take ownership of the provided string. /// /// The cut-callback /// Arbitrary data-pointer that's passed to the callback @@ -259,6 +260,7 @@ KINC_FUNC void kinc_set_cut_callback(char *(*callback)(void *), void *data); /// /// Sets a callback which is called when the application is instructed to copy, typically via ctrl+c or cmd+c. +/// Kinc does not take ownership of the provided string. /// /// The copy-callback /// Arbitrary data-pointer that's passed to the callback @@ -266,6 +268,7 @@ KINC_FUNC void kinc_set_copy_callback(char *(*callback)(void *), void *data); /// /// Sets a callback which is called when the application is instructed to paste, typically via ctrl+v or cmd+v. +/// The provided string is only valid during the callback-call - copy it if you want to keep it. /// /// The paste-callback /// Arbitrary data-pointer that's passed to the callback @@ -381,7 +384,7 @@ void kinc_internal_logout_callback(void); #include #include -#if !defined(KORE_WASM) && !defined(KORE_EMSCRIPTEN) && !defined(KORE_ANDROID) && !defined(KORE_WINDOWS) && !defined(KORE_CONSOLE) +#if !defined(KINC_WASM) && !defined(KINC_EMSCRIPTEN) && !defined(KINC_ANDROID) && !defined(KINC_WINDOWS) && !defined(KINC_CONSOLE) double kinc_time(void) { return kinc_timestamp() / kinc_frequency(); } @@ -412,7 +415,7 @@ static void *login_callback_data = NULL; static void (*logout_callback)(void *) = NULL; static void *logout_callback_data = NULL; -#if defined(KORE_IOS) || defined(KORE_MACOS) +#if defined(KINC_IOS) || defined(KINC_MACOS) bool withAutoreleasepool(bool (*f)(void)); #endif @@ -562,10 +565,6 @@ void kinc_set_application_name(const char *name) { strcpy(application_name, name); } -#ifdef KORE_METAL -void shutdownMetalCompute(void); -#endif - void kinc_stop(void) { running = false; @@ -574,10 +573,6 @@ void kinc_stop(void) { // for (int windowIndex = 0; windowIndex < sizeof(windowIds) / sizeof(int); ++windowIndex) { // Graphics::destroy(windowIndex); //} - -#ifdef KORE_METAL - shutdownMetalCompute(); -#endif } bool kinc_internal_frame(void) { @@ -589,10 +584,10 @@ bool kinc_internal_frame(void) { void kinc_start(void) { running = true; -#if !defined(KORE_WASM) && !defined(KORE_EMSCRIPTEN) && !defined(KORE_TIZEN) +#if !defined(KINC_WASM) && !defined(KINC_EMSCRIPTEN) // if (Graphics::hasWindow()) Graphics::swapBuffers(); -#if defined(KORE_IOS) || defined(KORE_MACOS) +#if defined(KINC_IOS) || defined(KINC_MACOS) while (withAutoreleasepool(kinc_internal_frame)) { } #else @@ -615,11 +610,11 @@ int kinc_height(void) { void kinc_memory_emergency(void) {} #endif -#if !defined(KORE_SONY) && !defined(KORE_SWITCH) +#if !defined(KINC_SONY) && !defined(KINC_SWITCH) static float safe_zone = 0.9f; float kinc_safe_zone(void) { -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID return 1.0f; #else return safe_zone; @@ -627,7 +622,7 @@ float kinc_safe_zone(void) { } bool kinc_automatic_safe_zone(void) { -#ifdef KORE_ANDROID +#ifdef KINC_ANDROID return true; #else return false; @@ -639,7 +634,7 @@ void kinc_set_safe_zone(float value) { } #endif -#if !defined(KORE_SONY) +#if !defined(KINC_SONY) bool is_save_load_initialized(void) { return true; } @@ -653,7 +648,7 @@ bool is_save_load_broken(void) { } #endif -#if !defined(KORE_CONSOLE) +#if !defined(KINC_CONSOLE) #define SAVE_RESULT_NONE 0 #define SAVE_RESULT_SUCCESS 1 @@ -709,7 +704,7 @@ bool kinc_waiting_for_login(void) { return false; } -#if !defined(KORE_WINDOWS) && !defined(KORE_LINUX) && !defined(KORE_MACOS) +#if !defined(KINC_WINDOWS) && !defined(KINC_LINUX) && !defined(KINC_MACOS) void kinc_copy_to_clipboard(const char *text) { kinc_log(KINC_LOG_LEVEL_WARNING, "Oh no, kinc_copy_to_clipboard is not implemented for this system."); } diff --git a/Kinc/Sources/kinc/vr/vrinterface.h b/Kinc/Sources/kinc/vr/vrinterface.h index 2ba1fa9..56afe14 100644 --- a/Kinc/Sources/kinc/vr/vrinterface.h +++ b/Kinc/Sources/kinc/vr/vrinterface.h @@ -10,7 +10,7 @@ \brief The C-API for VR is currently deactivated and needs some work. Please use the Kore/C++-API in the meantime or send pull-requests. */ -#ifdef KORE_VR +#ifdef KINC_VR #ifdef __cplusplus extern "C" { diff --git a/Kinc/Sources/kinc/window.h b/Kinc/Sources/kinc/window.h index ba863ee..966053b 100644 --- a/Kinc/Sources/kinc/window.h +++ b/Kinc/Sources/kinc/window.h @@ -139,11 +139,6 @@ KINC_FUNC void kinc_window_show(int window); /// KINC_FUNC void kinc_window_hide(int window); -/// -/// Set a window to the foreground. -/// -KINC_FUNC void kinc_window_set_foreground(int window); - /// /// Sets the title of a window. /// @@ -152,7 +147,7 @@ KINC_FUNC void kinc_window_set_title(int window, const char *title); /// /// Sets a resize callback that's called whenever the window is resized. /// -KINC_FUNC void kinc_window_set_resize_callback(int window, void (*callback)(int x, int y, void *data), void *data); +KINC_FUNC void kinc_window_set_resize_callback(int window, void (*callback)(int width, int height, void *data), void *data); /// /// Sets a PPI callback that's called whenever the window moves to a display that uses a different PPI-setting. diff --git a/Kinc/Tests/Input/Sources/input.c b/Kinc/Tests/Input/Sources/input.c index 8cb5086..8fcadb9 100644 --- a/Kinc/Tests/Input/Sources/input.c +++ b/Kinc/Tests/Input/Sources/input.c @@ -14,7 +14,7 @@ static void update(void *data) { kinc_g4_swap_buffers(); } -static void mouse_enter_window(int window, void* data) { +static void mouse_enter_window(int window, void *data) { kinc_log(KINC_LOG_LEVEL_INFO, "mouse_enter_window -- window: %i", window); } static void mouse_leave_window(int window, void *data) { diff --git a/Kinc/Tests/SIMD/Sources/simd.c b/Kinc/Tests/SIMD/Sources/simd.c index 9bd7a55..43e2e74 100644 --- a/Kinc/Tests/SIMD/Sources/simd.c +++ b/Kinc/Tests/SIMD/Sources/simd.c @@ -354,7 +354,8 @@ int kickstart(int argc, char **argv) { result = kinc_uint8x16_not(a); uint8_t chk[16] = {1, 2, 3, 4, 5, 6, 7, 8, 4, 2, 3, 4, 5, 6, 7, 8}; - for (int i = 0; i < 16; ++i) chk[i] = (uint8_t)(~chk[i]); + for (int i = 0; i < 16; ++i) + chk[i] = (uint8_t)(~chk[i]); failed += check_u8("uint8x16 not", result, chk) ? 0 : 1; } @@ -446,7 +447,8 @@ int kickstart(int argc, char **argv) { result = kinc_uint16x8_not(a); uint16_t chk[8] = {1, 2, 3, 4, 5, 6, 7, 8}; - for (int i = 0; i < 8; ++i) chk[i] = (uint16_t)(~chk[i]); + for (int i = 0; i < 8; ++i) + chk[i] = (uint16_t)(~chk[i]); failed += check_u16("uint16x8 not", result, chk) ? 0 : 1; } @@ -538,7 +540,8 @@ int kickstart(int argc, char **argv) { result = kinc_uint32x4_not(a); uint32_t chk[4] = {1, 2, 3, 4}; - for (int i = 0; i < 4; ++i) chk[i] = (uint32_t)(~chk[i]); + for (int i = 0; i < 4; ++i) + chk[i] = (uint32_t)(~chk[i]); failed += check_u32("uint32x4 not", result, chk) ? 0 : 1; } diff --git a/Kinc/Tests/Shader-G5/Sources/shader.c b/Kinc/Tests/Shader-G5/Sources/shader.c index a857124..0e007e1 100644 --- a/Kinc/Tests/Shader-G5/Sources/shader.c +++ b/Kinc/Tests/Shader-G5/Sources/shader.c @@ -1,117 +1,125 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define BUFFER_COUNT 2 -static int current_buffer = -1; -static kinc_g5_render_target_t framebuffers[BUFFER_COUNT]; -static kinc_g5_command_list_t command_list; -static kinc_g5_shader_t vertex_shader; -static kinc_g5_shader_t fragment_shader; -static kinc_g5_pipeline_t pipeline; -static kinc_g5_vertex_buffer_t vertices; -static kinc_g5_index_buffer_t indices; - -#define HEAP_SIZE 1024 * 1024 -static uint8_t *heap = NULL; -static size_t heap_top = 0; - -static void *allocate(size_t size) { - size_t old_top = heap_top; - heap_top += size; - assert(heap_top <= HEAP_SIZE); - return &heap[old_top]; -} - -static void update(void *data) { - current_buffer = (current_buffer + 1) % BUFFER_COUNT; - - kinc_g5_begin(&framebuffers[current_buffer], 0); - - kinc_g5_command_list_begin(&command_list); - kinc_g5_command_list_framebuffer_to_render_target_barrier(&command_list, &framebuffers[current_buffer]); - kinc_g5_render_target_t *renderTargets[1] = {&framebuffers[current_buffer]}; - kinc_g5_command_list_set_render_targets(&command_list, renderTargets, 1); - - kinc_g5_command_list_clear(&command_list, &framebuffers[current_buffer], KINC_G5_CLEAR_COLOR, 0, 0.0f, 0); - kinc_g5_command_list_set_pipeline(&command_list, &pipeline); - kinc_g5_command_list_set_pipeline_layout(&command_list); - - int offsets[1] = { 0 }; - kinc_g5_vertex_buffer_t *vertex_buffers[1] = { &vertices }; - kinc_g5_command_list_set_vertex_buffers(&command_list, vertex_buffers, offsets, 1); - kinc_g5_command_list_set_index_buffer(&command_list, &indices); - kinc_g5_command_list_draw_indexed_vertices(&command_list); - - kinc_g5_command_list_render_target_to_framebuffer_barrier(&command_list, &framebuffers[current_buffer]); - kinc_g5_command_list_end(&command_list); - kinc_g5_command_list_execute_and_wait(&command_list); - - kinc_g5_end(0); - kinc_g5_swap_buffers(); -} - -static void load_shader(const char *filename, kinc_g5_shader_t *shader, kinc_g5_shader_type_t shader_type) { - kinc_file_reader_t file; - kinc_file_reader_open(&file, filename, KINC_FILE_TYPE_ASSET); - size_t data_size = kinc_file_reader_size(&file); - uint8_t *data = allocate(data_size); - kinc_file_reader_read(&file, data, data_size); - kinc_file_reader_close(&file); - kinc_g5_shader_init(shader, data, data_size, shader_type); -} - -int kickstart(int argc, char** argv) { - kinc_init("Shader", 1024, 768, NULL, NULL); - kinc_set_update_callback(update, NULL); - - heap = (uint8_t*)malloc(HEAP_SIZE); - assert(heap != NULL); - - load_shader("shader.vert", &vertex_shader, KINC_G5_SHADER_TYPE_VERTEX); - load_shader("shader.frag", &fragment_shader, KINC_G5_SHADER_TYPE_FRAGMENT); - - kinc_g5_vertex_structure_t structure; - kinc_g4_vertex_structure_init(&structure); - kinc_g4_vertex_structure_add(&structure, "pos", KINC_G4_VERTEX_DATA_FLOAT3); - kinc_g5_pipeline_init(&pipeline); - pipeline.vertexShader = &vertex_shader; - pipeline.fragmentShader = &fragment_shader; - pipeline.inputLayout[0] = &structure; - pipeline.inputLayout[1] = NULL; - kinc_g5_pipeline_compile(&pipeline); - - kinc_g5_command_list_init(&command_list); - for (int i = 0; i < BUFFER_COUNT; ++i) { - kinc_g5_render_target_init(&framebuffers[i], kinc_window_width(0), kinc_window_height(0), 16, false, KINC_G5_RENDER_TARGET_FORMAT_32BIT, -1, - -i - 1 /* hack in an index for backbuffer render targets */); - } - - kinc_g5_vertex_buffer_init(&vertices, 3, &structure, true, 0); - float *v = kinc_g5_vertex_buffer_lock_all(&vertices); - v[0] = -1; v[1] = -1; v[2] = 0.5; - v[3] = 1; v[4] = -1; v[5] = 0.5; - v[6] = -1; v[7] = 1; v[8] = 0.5; - kinc_g5_vertex_buffer_unlock_all(&vertices); - kinc_g5_command_list_upload_vertex_buffer(&command_list, &vertices); - - kinc_g5_index_buffer_init(&indices, 3, KINC_G5_INDEX_BUFFER_FORMAT_32BIT, true); - int *i = kinc_g5_index_buffer_lock_all(&indices); - i[0] = 0; i[1] = 1; i[2] = 2; - kinc_g5_index_buffer_unlock_all(&indices); - kinc_g5_command_list_upload_index_buffer(&command_list, &indices); - - kinc_start(); - - return 0; -} +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define BUFFER_COUNT 2 +static int current_buffer = -1; +static kinc_g5_render_target_t framebuffers[BUFFER_COUNT]; +static kinc_g5_command_list_t command_list; +static kinc_g5_shader_t vertex_shader; +static kinc_g5_shader_t fragment_shader; +static kinc_g5_pipeline_t pipeline; +static kinc_g5_vertex_buffer_t vertices; +static kinc_g5_index_buffer_t indices; + +#define HEAP_SIZE 1024 * 1024 +static uint8_t *heap = NULL; +static size_t heap_top = 0; + +static void *allocate(size_t size) { + size_t old_top = heap_top; + heap_top += size; + assert(heap_top <= HEAP_SIZE); + return &heap[old_top]; +} + +static void update(void *data) { + current_buffer = (current_buffer + 1) % BUFFER_COUNT; + + kinc_g5_begin(&framebuffers[current_buffer], 0); + + kinc_g5_command_list_begin(&command_list); + kinc_g5_command_list_framebuffer_to_render_target_barrier(&command_list, &framebuffers[current_buffer]); + kinc_g5_render_target_t *renderTargets[1] = {&framebuffers[current_buffer]}; + kinc_g5_command_list_set_render_targets(&command_list, renderTargets, 1); + + kinc_g5_command_list_clear(&command_list, &framebuffers[current_buffer], KINC_G5_CLEAR_COLOR, 0, 0.0f, 0); + kinc_g5_command_list_set_pipeline(&command_list, &pipeline); + kinc_g5_command_list_set_pipeline_layout(&command_list); + + int offsets[1] = {0}; + kinc_g5_vertex_buffer_t *vertex_buffers[1] = {&vertices}; + kinc_g5_command_list_set_vertex_buffers(&command_list, vertex_buffers, offsets, 1); + kinc_g5_command_list_set_index_buffer(&command_list, &indices); + kinc_g5_command_list_draw_indexed_vertices(&command_list); + + kinc_g5_command_list_render_target_to_framebuffer_barrier(&command_list, &framebuffers[current_buffer]); + kinc_g5_command_list_end(&command_list); + kinc_g5_command_list_execute_and_wait(&command_list); + + kinc_g5_end(0); + kinc_g5_swap_buffers(); +} + +static void load_shader(const char *filename, kinc_g5_shader_t *shader, kinc_g5_shader_type_t shader_type) { + kinc_file_reader_t file; + kinc_file_reader_open(&file, filename, KINC_FILE_TYPE_ASSET); + size_t data_size = kinc_file_reader_size(&file); + uint8_t *data = allocate(data_size); + kinc_file_reader_read(&file, data, data_size); + kinc_file_reader_close(&file); + kinc_g5_shader_init(shader, data, data_size, shader_type); +} + +int kickstart(int argc, char **argv) { + kinc_init("Shader", 1024, 768, NULL, NULL); + kinc_set_update_callback(update, NULL); + + heap = (uint8_t *)malloc(HEAP_SIZE); + assert(heap != NULL); + + load_shader("shader.vert", &vertex_shader, KINC_G5_SHADER_TYPE_VERTEX); + load_shader("shader.frag", &fragment_shader, KINC_G5_SHADER_TYPE_FRAGMENT); + + kinc_g5_vertex_structure_t structure; + kinc_g4_vertex_structure_init(&structure); + kinc_g4_vertex_structure_add(&structure, "pos", KINC_G4_VERTEX_DATA_FLOAT3); + kinc_g5_pipeline_init(&pipeline); + pipeline.vertexShader = &vertex_shader; + pipeline.fragmentShader = &fragment_shader; + pipeline.inputLayout[0] = &structure; + pipeline.inputLayout[1] = NULL; + kinc_g5_pipeline_compile(&pipeline); + + kinc_g5_command_list_init(&command_list); + for (int i = 0; i < BUFFER_COUNT; ++i) { + kinc_g5_render_target_init(&framebuffers[i], kinc_window_width(0), kinc_window_height(0), 16, false, KINC_G5_RENDER_TARGET_FORMAT_32BIT, -1, + -i - 1 /* hack in an index for backbuffer render targets */); + } + + kinc_g5_vertex_buffer_init(&vertices, 3, &structure, true, 0); + float *v = kinc_g5_vertex_buffer_lock_all(&vertices); + v[0] = -1; + v[1] = -1; + v[2] = 0.5; + v[3] = 1; + v[4] = -1; + v[5] = 0.5; + v[6] = -1; + v[7] = 1; + v[8] = 0.5; + kinc_g5_vertex_buffer_unlock_all(&vertices); + kinc_g5_command_list_upload_vertex_buffer(&command_list, &vertices); + + kinc_g5_index_buffer_init(&indices, 3, KINC_G5_INDEX_BUFFER_FORMAT_32BIT, true); + int *i = kinc_g5_index_buffer_lock_all(&indices); + i[0] = 0; + i[1] = 1; + i[2] = 2; + kinc_g5_index_buffer_unlock_all(&indices); + kinc_g5_command_list_upload_index_buffer(&command_list, &indices); + + kinc_start(); + + return 0; +} diff --git a/Kinc/Tools/freebsd_x64/.gitattributes b/Kinc/Tools/freebsd_x64/.gitattributes deleted file mode 100644 index 6254495..0000000 --- a/Kinc/Tools/freebsd_x64/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* -text diff --git a/Kinc/Tools/freebsd_x64/icon.png b/Kinc/Tools/freebsd_x64/icon.png index 33cc846..5dd0e8d 100644 Binary files a/Kinc/Tools/freebsd_x64/icon.png and b/Kinc/Tools/freebsd_x64/icon.png differ diff --git a/Kinc/Tools/linux_arm/.gitattributes b/Kinc/Tools/linux_arm/.gitattributes deleted file mode 100644 index 6254495..0000000 --- a/Kinc/Tools/linux_arm/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* -text diff --git a/Kinc/Tools/linux_arm/icon.png b/Kinc/Tools/linux_arm/icon.png index 33cc846..5dd0e8d 100644 Binary files a/Kinc/Tools/linux_arm/icon.png and b/Kinc/Tools/linux_arm/icon.png differ diff --git a/Kinc/Tools/linux_arm/kmake b/Kinc/Tools/linux_arm/kmake index ec233d1..297b9ff 100755 Binary files a/Kinc/Tools/linux_arm/kmake and b/Kinc/Tools/linux_arm/kmake differ diff --git a/Kinc/Tools/linux_arm/kongruent b/Kinc/Tools/linux_arm/kongruent index b98df83..daaaacc 100755 Binary files a/Kinc/Tools/linux_arm/kongruent and b/Kinc/Tools/linux_arm/kongruent differ diff --git a/Kinc/Tools/linux_arm/kraffiti b/Kinc/Tools/linux_arm/kraffiti index 4dc5f65..b6b6b6e 100755 Binary files a/Kinc/Tools/linux_arm/kraffiti and b/Kinc/Tools/linux_arm/kraffiti differ diff --git a/Kinc/Tools/linux_arm/krafix b/Kinc/Tools/linux_arm/krafix index db83ec7..4fbdb45 100755 Binary files a/Kinc/Tools/linux_arm/krafix and b/Kinc/Tools/linux_arm/krafix differ diff --git a/Kinc/Tools/windows_x64/LICENSE b/Kinc/Tools/linux_arm/licenses.txt similarity index 100% rename from Kinc/Tools/windows_x64/LICENSE rename to Kinc/Tools/linux_arm/licenses.txt diff --git a/Kinc/Tools/linux_arm64/.gitattributes b/Kinc/Tools/linux_arm64/.gitattributes deleted file mode 100644 index 6254495..0000000 --- a/Kinc/Tools/linux_arm64/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* -text diff --git a/Kinc/Tools/linux_arm64/icon.png b/Kinc/Tools/linux_arm64/icon.png index 33cc846..5dd0e8d 100644 Binary files a/Kinc/Tools/linux_arm64/icon.png and b/Kinc/Tools/linux_arm64/icon.png differ diff --git a/Kinc/Tools/linux_arm64/kmake b/Kinc/Tools/linux_arm64/kmake index 4979329..3f16a7e 100755 Binary files a/Kinc/Tools/linux_arm64/kmake and b/Kinc/Tools/linux_arm64/kmake differ diff --git a/Kinc/Tools/linux_arm64/kongruent b/Kinc/Tools/linux_arm64/kongruent index 32d9c7f..9ac8744 100755 Binary files a/Kinc/Tools/linux_arm64/kongruent and b/Kinc/Tools/linux_arm64/kongruent differ diff --git a/Kinc/Tools/linux_arm64/kraffiti b/Kinc/Tools/linux_arm64/kraffiti index 8414cbb..6abd056 100755 Binary files a/Kinc/Tools/linux_arm64/kraffiti and b/Kinc/Tools/linux_arm64/kraffiti differ diff --git a/Kinc/Tools/linux_arm64/krafix b/Kinc/Tools/linux_arm64/krafix index fbb24c6..b8aaf3a 100755 Binary files a/Kinc/Tools/linux_arm64/krafix and b/Kinc/Tools/linux_arm64/krafix differ diff --git a/Kinc/Tools/linux_arm64/licenses.txt b/Kinc/Tools/linux_arm64/licenses.txt new file mode 100644 index 0000000..7025946 --- /dev/null +++ b/Kinc/Tools/linux_arm64/licenses.txt @@ -0,0 +1,1764 @@ +kmake is licensed for use as follows: + +""" +Copyright kmake contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +This license applies to parts of kmake originating from the +https://github.com/nodejs/node repository: + +""" +Copyright Node.js contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +This license applies to parts of kmake originating from the +https://github.com/joyent/node repository: + +""" +Copyright Joyent, Inc. and other Node contributors. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +The kmake license applies to all parts of kmake that are not externally +maintained libraries. + +The externally maintained libraries used by kmake are: + +- Acorn, located at deps/acorn, is licensed as follows: + """ + MIT License + + Copyright (C) 2012-2020 by various contributors (see AUTHORS) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- c-ares, located at deps/cares, is licensed as follows: + """ + Copyright (c) 2007 - 2018, Daniel Stenberg with many contributors, see AUTHORS + file. + + Copyright 1998 by the Massachusetts Institute of Technology. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose and without fee is hereby granted, provided that + the above copyright notice appear in all copies and that both that copyright + notice and this permission notice appear in supporting documentation, and that + the name of M.I.T. not be used in advertising or publicity pertaining to + distribution of the software without specific, written prior permission. + M.I.T. makes no representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied warranty. + """ + +- cjs-module-lexer, located at deps/cjs-module-lexer, is licensed as follows: + """ + MIT License + ----------- + + Copyright (C) 2018-2020 Guy Bedford + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- ICU, located at deps/icu-small, is licensed as follows: + """ + COPYRIGHT AND PERMISSION NOTICE (ICU 58 and later) + + Copyright © 1991-2020 Unicode, Inc. All rights reserved. + Distributed under the Terms of Use in https://www.unicode.org/copyright.html. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of the Unicode data files and any associated documentation + (the "Data Files") or Unicode software and any associated documentation + (the "Software") to deal in the Data Files or Software + without restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, and/or sell copies of + the Data Files or Software, and to permit persons to whom the Data Files + or Software are furnished to do so, provided that either + (a) this copyright and permission notice appear with all copies + of the Data Files or Software, or + (b) this copyright and permission notice appear in associated + Documentation. + + THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF + ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT OF THIRD PARTY RIGHTS. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS + NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL + DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THE DATA FILES OR SOFTWARE. + + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, + use or other dealings in these Data Files or Software without prior + written authorization of the copyright holder. + + --------------------- + + Third-Party Software Licenses + + This section contains third-party software notices and/or additional + terms for licensed third-party software components included within ICU + libraries. + + 1. ICU License - ICU 1.8.1 to ICU 57.1 + + COPYRIGHT AND PERMISSION NOTICE + + Copyright (c) 1995-2016 International Business Machines Corporation and others + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, and/or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, provided that the above + copyright notice(s) and this permission notice appear in all copies of + the Software and that both the above copyright notice(s) and this + permission notice appear in supporting documentation. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, use + or other dealings in this Software without prior written authorization + of the copyright holder. + + All trademarks and registered trademarks mentioned herein are the + property of their respective owners. + + 2. Chinese/Japanese Word Break Dictionary Data (cjdict.txt) + + # The Google Chrome software developed by Google is licensed under + # the BSD license. Other software included in this distribution is + # provided under other licenses, as set forth below. + # + # The BSD License + # http://opensource.org/licenses/bsd-license.php + # Copyright (C) 2006-2008, Google Inc. + # + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # Redistributions of source code must retain the above copyright notice, + # this list of conditions and the following disclaimer. + # Redistributions in binary form must reproduce the above + # copyright notice, this list of conditions and the following + # disclaimer in the documentation and/or other materials provided with + # the distribution. + # Neither the name of Google Inc. nor the names of its + # contributors may be used to endorse or promote products derived from + # this software without specific prior written permission. + # + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # + # + # The word list in cjdict.txt are generated by combining three word lists + # listed below with further processing for compound word breaking. The + # frequency is generated with an iterative training against Google web + # corpora. + # + # * Libtabe (Chinese) + # - https://sourceforge.net/project/?group_id=1519 + # - Its license terms and conditions are shown below. + # + # * IPADIC (Japanese) + # - http://chasen.aist-nara.ac.jp/chasen/distribution.html + # - Its license terms and conditions are shown below. + # + # ---------COPYING.libtabe ---- BEGIN-------------------- + # + # /* + # * Copyright (c) 1999 TaBE Project. + # * Copyright (c) 1999 Pai-Hsiang Hsiao. + # * All rights reserved. + # * + # * Redistribution and use in source and binary forms, with or without + # * modification, are permitted provided that the following conditions + # * are met: + # * + # * . Redistributions of source code must retain the above copyright + # * notice, this list of conditions and the following disclaimer. + # * . Redistributions in binary form must reproduce the above copyright + # * notice, this list of conditions and the following disclaimer in + # * the documentation and/or other materials provided with the + # * distribution. + # * . Neither the name of the TaBE Project nor the names of its + # * contributors may be used to endorse or promote products derived + # * from this software without specific prior written permission. + # * + # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + # * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # * OF THE POSSIBILITY OF SUCH DAMAGE. + # */ + # + # /* + # * Copyright (c) 1999 Computer Systems and Communication Lab, + # * Institute of Information Science, Academia + # * Sinica. All rights reserved. + # * + # * Redistribution and use in source and binary forms, with or without + # * modification, are permitted provided that the following conditions + # * are met: + # * + # * . Redistributions of source code must retain the above copyright + # * notice, this list of conditions and the following disclaimer. + # * . Redistributions in binary form must reproduce the above copyright + # * notice, this list of conditions and the following disclaimer in + # * the documentation and/or other materials provided with the + # * distribution. + # * . Neither the name of the Computer Systems and Communication Lab + # * nor the names of its contributors may be used to endorse or + # * promote products derived from this software without specific + # * prior written permission. + # * + # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + # * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # * OF THE POSSIBILITY OF SUCH DAMAGE. + # */ + # + # Copyright 1996 Chih-Hao Tsai @ Beckman Institute, + # University of Illinois + # c-tsai4@uiuc.edu http://casper.beckman.uiuc.edu/~c-tsai4 + # + # ---------------COPYING.libtabe-----END-------------------------------- + # + # + # ---------------COPYING.ipadic-----BEGIN------------------------------- + # + # Copyright 2000, 2001, 2002, 2003 Nara Institute of Science + # and Technology. All Rights Reserved. + # + # Use, reproduction, and distribution of this software is permitted. + # Any copy of this software, whether in its original form or modified, + # must include both the above copyright notice and the following + # paragraphs. + # + # Nara Institute of Science and Technology (NAIST), + # the copyright holders, disclaims all warranties with regard to this + # software, including all implied warranties of merchantability and + # fitness, in no event shall NAIST be liable for + # any special, indirect or consequential damages or any damages + # whatsoever resulting from loss of use, data or profits, whether in an + # action of contract, negligence or other tortuous action, arising out + # of or in connection with the use or performance of this software. + # + # A large portion of the dictionary entries + # originate from ICOT Free Software. The following conditions for ICOT + # Free Software applies to the current dictionary as well. + # + # Each User may also freely distribute the Program, whether in its + # original form or modified, to any third party or parties, PROVIDED + # that the provisions of Section 3 ("NO WARRANTY") will ALWAYS appear + # on, or be attached to, the Program, which is distributed substantially + # in the same form as set out herein and that such intended + # distribution, if actually made, will neither violate or otherwise + # contravene any of the laws and regulations of the countries having + # jurisdiction over the User or the intended distribution itself. + # + # NO WARRANTY + # + # The program was produced on an experimental basis in the course of the + # research and development conducted during the project and is provided + # to users as so produced on an experimental basis. Accordingly, the + # program is provided without any warranty whatsoever, whether express, + # implied, statutory or otherwise. The term "warranty" used herein + # includes, but is not limited to, any warranty of the quality, + # performance, merchantability and fitness for a particular purpose of + # the program and the nonexistence of any infringement or violation of + # any right of any third party. + # + # Each user of the program will agree and understand, and be deemed to + # have agreed and understood, that there is no warranty whatsoever for + # the program and, accordingly, the entire risk arising from or + # otherwise connected with the program is assumed by the user. + # + # Therefore, neither ICOT, the copyright holder, or any other + # organization that participated in or was otherwise related to the + # development of the program and their respective officials, directors, + # officers and other employees shall be held liable for any and all + # damages, including, without limitation, general, special, incidental + # and consequential damages, arising out of or otherwise in connection + # with the use or inability to use the program or any product, material + # or result produced or otherwise obtained by using the program, + # regardless of whether they have been advised of, or otherwise had + # knowledge of, the possibility of such damages at any time during the + # project or thereafter. Each user will be deemed to have agreed to the + # foregoing by his or her commencement of use of the program. The term + # "use" as used herein includes, but is not limited to, the use, + # modification, copying and distribution of the program and the + # production of secondary products from the program. + # + # In the case where the program, whether in its original form or + # modified, was distributed or delivered to or received by a user from + # any person, organization or entity other than ICOT, unless it makes or + # grants independently of ICOT any specific warranty to the user in + # writing, such person, organization or entity, will also be exempted + # from and not be held liable to the user for any such damages as noted + # above as far as the program is concerned. + # + # ---------------COPYING.ipadic-----END---------------------------------- + + 3. Lao Word Break Dictionary Data (laodict.txt) + + # Copyright (C) 2016 and later: Unicode, Inc. and others. + # License & terms of use: http://www.unicode.org/copyright.html + # Copyright (c) 2015 International Business Machines Corporation + # and others. All Rights Reserved. + # + # Project: https://github.com/rober42539/lao-dictionary + # Dictionary: https://github.com/rober42539/lao-dictionary/laodict.txt + # License: https://github.com/rober42539/lao-dictionary/LICENSE.txt + # (copied below) + # + # This file is derived from the above dictionary version of Nov 22, 2020 + # ---------------------------------------------------------------------- + # Copyright (C) 2013 Brian Eugene Wilson, Robert Martin Campbell. + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # Redistributions of source code must retain the above copyright notice, this + # list of conditions and the following disclaimer. Redistributions in binary + # form must reproduce the above copyright notice, this list of conditions and + # the following disclaimer in the documentation and/or other materials + # provided with the distribution. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # OF THE POSSIBILITY OF SUCH DAMAGE. + # -------------------------------------------------------------------------- + + 4. Burmese Word Break Dictionary Data (burmesedict.txt) + + # Copyright (c) 2014 International Business Machines Corporation + # and others. All Rights Reserved. + # + # This list is part of a project hosted at: + # github.com/kanyawtech/myanmar-karen-word-lists + # + # -------------------------------------------------------------------------- + # Copyright (c) 2013, LeRoy Benjamin Sharon + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions + # are met: Redistributions of source code must retain the above + # copyright notice, this list of conditions and the following + # disclaimer. Redistributions in binary form must reproduce the + # above copyright notice, this list of conditions and the following + # disclaimer in the documentation and/or other materials provided + # with the distribution. + # + # Neither the name Myanmar Karen Word Lists, nor the names of its + # contributors may be used to endorse or promote products derived + # from this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS + # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + # SUCH DAMAGE. + # -------------------------------------------------------------------------- + + 5. Time Zone Database + + ICU uses the public domain data and code derived from Time Zone + Database for its time zone support. The ownership of the TZ database + is explained in BCP 175: Procedure for Maintaining the Time Zone + Database section 7. + + # 7. Database Ownership + # + # The TZ database itself is not an IETF Contribution or an IETF + # document. Rather it is a pre-existing and regularly updated work + # that is in the public domain, and is intended to remain in the + # public domain. Therefore, BCPs 78 [RFC5378] and 79 [RFC3979] do + # not apply to the TZ Database or contributions that individuals make + # to it. Should any claims be made and substantiated against the TZ + # Database, the organization that is providing the IANA + # Considerations defined in this RFC, under the memorandum of + # understanding with the IETF, currently ICANN, may act in accordance + # with all competent court orders. No ownership claims will be made + # by ICANN or the IETF Trust on the database or the code. Any person + # making a contribution to the database or code waives all rights to + # future claims in that contribution or in the TZ Database. + + 6. Google double-conversion + + Copyright 2006-2011, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- libuv, located at deps/uv, is licensed as follows: + """ + libuv is licensed for use as follows: + + ==== + Copyright (c) 2015-present libuv project contributors. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + ==== + + This license applies to parts of libuv originating from the + https://github.com/joyent/libuv repository: + + ==== + + Copyright Joyent, Inc. and other Node contributors. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + ==== + + This license applies to all parts of libuv that are not externally + maintained libraries. + + The externally maintained libraries used by libuv are: + + - tree.h (from FreeBSD), copyright Niels Provos. Two clause BSD license. + + - inet_pton and inet_ntop implementations, contained in src/inet.c, are + copyright the Internet Systems Consortium, Inc., and licensed under the ISC + license. + + - stdint-msvc2008.h (from msinttypes), copyright Alexander Chemeris. Three + clause BSD license. + + - pthread-fixes.c, copyright Google Inc. and Sony Mobile Communications AB. + Three clause BSD license. + + - android-ifaddrs.h, android-ifaddrs.c, copyright Berkeley Software Design + Inc, Kenneth MacKay and Emergya (Cloud4all, FP7/2007-2013, grant agreement + n° 289016). Three clause BSD license. + """ + +- llhttp, located at deps/llhttp, is licensed as follows: + """ + This software is licensed under the MIT License. + + Copyright Fedor Indutny, 2018. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- corepack, located at deps/corepack, is licensed as follows: + """ + **Copyright © Corepack contributors** + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- undici, located at deps/undici, is licensed as follows: + """ + MIT License + + Copyright (c) Matteo Collina and Undici contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + """ + +- OpenSSL, located at deps/openssl, is licensed as follows: + """ + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + """ + +- Punycode.js, located at lib/punycode.js, is licensed as follows: + """ + Copyright Mathias Bynens + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- V8, located at deps/v8, is licensed as follows: + """ + This license applies to all parts of V8 that are not externally + maintained libraries. The externally maintained libraries used by V8 + are: + + - PCRE test suite, located in + test/mjsunit/third_party/regexp-pcre/regexp-pcre.js. This is based on the + test suite from PCRE-7.3, which is copyrighted by the University + of Cambridge and Google, Inc. The copyright notice and license + are embedded in regexp-pcre.js. + + - Layout tests, located in test/mjsunit/third_party/object-keys. These are + based on layout tests from webkit.org which are copyrighted by + Apple Computer, Inc. and released under a 3-clause BSD license. + + - Strongtalk assembler, the basis of the files assembler-arm-inl.h, + assembler-arm.cc, assembler-arm.h, assembler-ia32-inl.h, + assembler-ia32.cc, assembler-ia32.h, assembler-x64-inl.h, + assembler-x64.cc, assembler-x64.h, assembler-mips-inl.h, + assembler-mips.cc, assembler-mips.h, assembler.cc and assembler.h. + This code is copyrighted by Sun Microsystems Inc. and released + under a 3-clause BSD license. + + - Valgrind client API header, located at src/third_party/valgrind/valgrind.h + This is released under the BSD license. + + - The Wasm C/C++ API headers, located at third_party/wasm-api/wasm.{h,hh} + This is released under the Apache license. The API's upstream prototype + implementation also formed the basis of V8's implementation in + src/wasm/c-api.cc. + + These libraries have their own licenses; we recommend you read them, + as their terms may differ from the terms below. + + Further license information can be found in LICENSE files located in + sub-directories. + + Copyright 2014, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- SipHash, located at deps/v8/src/third_party/siphash, is licensed as follows: + """ + SipHash reference C implementation + + Copyright (c) 2016 Jean-Philippe Aumasson + + To the extent possible under law, the author(s) have dedicated all + copyright and related and neighboring rights to this software to the public + domain worldwide. This software is distributed without any warranty. + """ + +- zlib, located at deps/zlib, is licensed as follows: + """ + zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.11, January 15th, 2017 + + Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + """ + +- npm, located at deps/npm, is licensed as follows: + """ + The npm application + Copyright (c) npm, Inc. and Contributors + Licensed on the terms of The Artistic License 2.0 + + Node package dependencies of the npm application + Copyright (c) their respective copyright owners + Licensed on their respective license terms + + The npm public registry at https://registry.npmjs.org + and the npm website at https://www.npmjs.com + Operated by npm, Inc. + Use governed by terms published on https://www.npmjs.com + + "Node.js" + Trademark Joyent, Inc., https://joyent.com + Neither npm nor npm, Inc. are affiliated with Joyent, Inc. + + The Node.js application + Project of Node Foundation, https://nodejs.org + + The npm Logo + Copyright (c) Mathias Pettersson and Brian Hammond + + "Gubblebum Blocky" typeface + Copyright (c) Tjarda Koster, https://jelloween.deviantart.com + Used with permission + + -------- + + The Artistic License 2.0 + + Copyright (c) 2000-2006, The Perl Foundation. + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + This license establishes the terms under which a given free software + Package may be copied, modified, distributed, and/or redistributed. + The intent is that the Copyright Holder maintains some artistic + control over the development of that Package while still keeping the + Package available as open source and free software. + + You are always permitted to make arrangements wholly outside of this + license directly with the Copyright Holder of a given Package. If the + terms of this license do not permit the full use that you propose to + make of the Package, you should contact the Copyright Holder and seek + a different licensing arrangement. + + Definitions + + "Copyright Holder" means the individual(s) or organization(s) + named in the copyright notice for the entire Package. + + "Contributor" means any party that has contributed code or other + material to the Package, in accordance with the Copyright Holder's + procedures. + + "You" and "your" means any person who would like to copy, + distribute, or modify the Package. + + "Package" means the collection of files distributed by the + Copyright Holder, and derivatives of that collection and/or of + those files. A given Package may consist of either the Standard + Version, or a Modified Version. + + "Distribute" means providing a copy of the Package or making it + accessible to anyone else, or in the case of a company or + organization, to others outside of your company or organization. + + "Distributor Fee" means any fee that you charge for Distributing + this Package or providing support for this Package to another + party. It does not mean licensing fees. + + "Standard Version" refers to the Package if it has not been + modified, or has been modified only in ways explicitly requested + by the Copyright Holder. + + "Modified Version" means the Package, if it has been changed, and + such changes were not explicitly requested by the Copyright + Holder. + + "Original License" means this Artistic License as Distributed with + the Standard Version of the Package, in its current version or as + it may be modified by The Perl Foundation in the future. + + "Source" form means the source code, documentation source, and + configuration files for the Package. + + "Compiled" form means the compiled bytecode, object code, binary, + or any other form resulting from mechanical transformation or + translation of the Source form. + + Permission for Use and Modification Without Distribution + + (1) You are permitted to use the Standard Version and create and use + Modified Versions for any purpose without restriction, provided that + you do not Distribute the Modified Version. + + Permissions for Redistribution of the Standard Version + + (2) You may Distribute verbatim copies of the Source form of the + Standard Version of this Package in any medium without restriction, + either gratis or for a Distributor Fee, provided that you duplicate + all of the original copyright notices and associated disclaimers. At + your discretion, such verbatim copies may or may not include a + Compiled form of the Package. + + (3) You may apply any bug fixes, portability changes, and other + modifications made available from the Copyright Holder. The resulting + Package will still be considered the Standard Version, and as such + will be subject to the Original License. + + Distribution of Modified Versions of the Package as Source + + (4) You may Distribute your Modified Version as Source (either gratis + or for a Distributor Fee, and with or without a Compiled form of the + Modified Version) provided that you clearly document how it differs + from the Standard Version, including, but not limited to, documenting + any non-standard features, executables, or modules, and provided that + you do at least ONE of the following: + + (a) make the Modified Version available to the Copyright Holder + of the Standard Version, under the Original License, so that the + Copyright Holder may include your modifications in the Standard + Version. + + (b) ensure that installation of your Modified Version does not + prevent the user installing or running the Standard Version. In + addition, the Modified Version must bear a name that is different + from the name of the Standard Version. + + (c) allow anyone who receives a copy of the Modified Version to + make the Source form of the Modified Version available to others + under + + (i) the Original License or + + (ii) a license that permits the licensee to freely copy, + modify and redistribute the Modified Version using the same + licensing terms that apply to the copy that the licensee + received, and requires that the Source form of the Modified + Version, and of any works derived from it, be made freely + available in that license fees are prohibited but Distributor + Fees are allowed. + + Distribution of Compiled Forms of the Standard Version + or Modified Versions without the Source + + (5) You may Distribute Compiled forms of the Standard Version without + the Source, provided that you include complete instructions on how to + get the Source of the Standard Version. Such instructions must be + valid at the time of your distribution. If these instructions, at any + time while you are carrying out such distribution, become invalid, you + must provide new instructions on demand or cease further distribution. + If you provide valid instructions or cease distribution within thirty + days after you become aware that the instructions are invalid, then + you do not forfeit any of your rights under this license. + + (6) You may Distribute a Modified Version in Compiled form without + the Source, provided that you comply with Section 4 with respect to + the Source of the Modified Version. + + Aggregating or Linking the Package + + (7) You may aggregate the Package (either the Standard Version or + Modified Version) with other packages and Distribute the resulting + aggregation provided that you do not charge a licensing fee for the + Package. Distributor Fees are permitted, and licensing fees for other + components in the aggregation are permitted. The terms of this license + apply to the use and Distribution of the Standard or Modified Versions + as included in the aggregation. + + (8) You are permitted to link Modified and Standard Versions with + other works, to embed the Package in a larger work of your own, or to + build stand-alone binary or bytecode versions of applications that + include the Package, and Distribute the result without restriction, + provided the result does not expose a direct interface to the Package. + + Items That are Not Considered Part of a Modified Version + + (9) Works (including, but not limited to, modules and scripts) that + merely extend or make use of the Package, do not, by themselves, cause + the Package to be a Modified Version. In addition, such works are not + considered parts of the Package itself, and are not subject to the + terms of this license. + + General Provisions + + (10) Any use, modification, and distribution of the Standard or + Modified Versions is governed by this Artistic License. By using, + modifying or distributing the Package, you accept this license. Do not + use, modify, or distribute the Package, if you do not accept this + license. + + (11) If your Modified Version has been derived from a Modified + Version made by someone other than you, you are nevertheless required + to ensure that your Modified Version complies with the requirements of + this license. + + (12) This license does not grant you the right to use any trademark, + service mark, tradename, or logo of the Copyright Holder. + + (13) This license includes the non-exclusive, worldwide, + free-of-charge patent license to make, have made, use, offer to sell, + sell, import and otherwise transfer the Package with respect to any + patent claims licensable by the Copyright Holder that are necessarily + infringed by the Package. If you institute patent litigation + (including a cross-claim or counterclaim) against any party alleging + that the Package constitutes direct or contributory patent + infringement, then this Artistic License to you shall terminate on the + date that such litigation is filed. + + (14) Disclaimer of Warranty: + THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR + NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL + LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL + DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + -------- + """ + +- GYP, located at tools/gyp, is licensed as follows: + """ + Copyright (c) 2020 Node.js contributors. All rights reserved. + Copyright (c) 2009 Google Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- inspector_protocol, located at tools/inspector_protocol, is licensed as follows: + """ + // Copyright 2016 The Chromium Authors. All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions are + // met: + // + // * Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // * Redistributions in binary form must reproduce the above + // copyright notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // * Neither the name of Google Inc. nor the names of its + // contributors may be used to endorse or promote products derived from + // this software without specific prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- jinja2, located at tools/inspector_protocol/jinja2, is licensed as follows: + """ + Copyright (c) 2009 by the Jinja Team, see AUTHORS for more details. + + Some rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- markupsafe, located at tools/inspector_protocol/markupsafe, is licensed as follows: + """ + Copyright (c) 2010 by Armin Ronacher and contributors. See AUTHORS + for more details. + + Some rights reserved. + + Redistribution and use in source and binary forms of the software as well + as documentation, with or without modification, are permitted provided + that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + DAMAGE. + """ + +- cpplint.py, located at tools/cpplint.py, is licensed as follows: + """ + Copyright (c) 2009 Google Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- ESLint, located at tools/node_modules/eslint, is licensed as follows: + """ + Copyright OpenJS Foundation and other contributors, + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- gtest, located at deps/googletest, is licensed as follows: + """ + Copyright 2008, Google Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- nghttp2, located at deps/nghttp2, is licensed as follows: + """ + The MIT License + + Copyright (c) 2012, 2014, 2015, 2016 Tatsuhiro Tsujikawa + Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- large_pages, located at src/large_pages, is licensed as follows: + """ + Copyright (C) 2018 Intel Corporation + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES + OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- caja, located at lib/internal/freeze_intrinsics.js, is licensed as follows: + """ + Adapted from SES/Caja - Copyright (C) 2011 Google Inc. + Copyright (C) 2018 Agoric + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + """ + +- brotli, located at deps/brotli, is licensed as follows: + """ + Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- HdrHistogram, located at deps/histogram, is licensed as follows: + """ + The code in this repository code was Written by Gil Tene, Michael Barker, + and Matt Warren, and released to the public domain, as explained at + http://creativecommons.org/publicdomain/zero/1.0/ + + For users of this code who wish to consume it under the "BSD" license + rather than under the public domain or CC0 contribution text mentioned + above, the code found under this directory is *also* provided under the + following license (commonly referred to as the BSD 2-Clause License). This + license does not detract from the above stated release of the code into + the public domain, and simply represents an additional license granted by + the Author. + + ----------------------------------------------------------------------------- + ** Beginning of "BSD 2-Clause License" text. ** + + Copyright (c) 2012, 2013, 2014 Gil Tene + Copyright (c) 2014 Michael Barker + Copyright (c) 2014 Matt Warren + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + """ + +- highlight.js, located at doc/api_assets/highlight.pack.js, is licensed as follows: + """ + BSD 3-Clause License + + Copyright (c) 2006, Ivan Sagalaev. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- node-heapdump, located at src/heap_utils.cc, is licensed as follows: + """ + ISC License + + Copyright (c) 2012, Ben Noordhuis + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + === src/compat.h src/compat-inl.h === + + ISC License + + Copyright (c) 2014, StrongLoop Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- rimraf, located at lib/internal/fs/rimraf.js, is licensed as follows: + """ + The ISC License + + Copyright (c) Isaac Z. Schlueter and Contributors + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- uvwasi, located at deps/uvwasi, is licensed as follows: + """ + MIT License + + Copyright (c) 2019 Colin Ihrig and Contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + """ + +- ngtcp2, located at deps/ngtcp2/ngtcp2/, is licensed as follows: + """ + The MIT License + + Copyright (c) 2016 ngtcp2 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- nghttp3, located at deps/ngtcp2/nghttp3/, is licensed as follows: + """ + The MIT License + + Copyright (c) 2019 nghttp3 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- node-fs-extra, located at lib/internal/fs/cp, is licensed as follows: + """ + (The MIT License) + + Copyright (c) 2011-2017 JP Richardson + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files + (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, + merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ diff --git a/Kinc/Tools/linux_x64/.gitattributes b/Kinc/Tools/linux_x64/.gitattributes deleted file mode 100644 index 6254495..0000000 --- a/Kinc/Tools/linux_x64/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* -text diff --git a/Kinc/Tools/linux_x64/icon.png b/Kinc/Tools/linux_x64/icon.png index 33cc846..5dd0e8d 100644 Binary files a/Kinc/Tools/linux_x64/icon.png and b/Kinc/Tools/linux_x64/icon.png differ diff --git a/Kinc/Tools/linux_x64/kmake b/Kinc/Tools/linux_x64/kmake index 65a3ad8..24d6129 100755 Binary files a/Kinc/Tools/linux_x64/kmake and b/Kinc/Tools/linux_x64/kmake differ diff --git a/Kinc/Tools/linux_x64/kongruent b/Kinc/Tools/linux_x64/kongruent index ce429cd..6095d0e 100755 Binary files a/Kinc/Tools/linux_x64/kongruent and b/Kinc/Tools/linux_x64/kongruent differ diff --git a/Kinc/Tools/linux_x64/kraffiti b/Kinc/Tools/linux_x64/kraffiti index 3168143..c9ac885 100755 Binary files a/Kinc/Tools/linux_x64/kraffiti and b/Kinc/Tools/linux_x64/kraffiti differ diff --git a/Kinc/Tools/linux_x64/krafix b/Kinc/Tools/linux_x64/krafix index cbbf5f1..f512e94 100755 Binary files a/Kinc/Tools/linux_x64/krafix and b/Kinc/Tools/linux_x64/krafix differ diff --git a/Kinc/Tools/linux_x64/licenses.txt b/Kinc/Tools/linux_x64/licenses.txt new file mode 100644 index 0000000..7025946 --- /dev/null +++ b/Kinc/Tools/linux_x64/licenses.txt @@ -0,0 +1,1764 @@ +kmake is licensed for use as follows: + +""" +Copyright kmake contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +This license applies to parts of kmake originating from the +https://github.com/nodejs/node repository: + +""" +Copyright Node.js contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +This license applies to parts of kmake originating from the +https://github.com/joyent/node repository: + +""" +Copyright Joyent, Inc. and other Node contributors. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +The kmake license applies to all parts of kmake that are not externally +maintained libraries. + +The externally maintained libraries used by kmake are: + +- Acorn, located at deps/acorn, is licensed as follows: + """ + MIT License + + Copyright (C) 2012-2020 by various contributors (see AUTHORS) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- c-ares, located at deps/cares, is licensed as follows: + """ + Copyright (c) 2007 - 2018, Daniel Stenberg with many contributors, see AUTHORS + file. + + Copyright 1998 by the Massachusetts Institute of Technology. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose and without fee is hereby granted, provided that + the above copyright notice appear in all copies and that both that copyright + notice and this permission notice appear in supporting documentation, and that + the name of M.I.T. not be used in advertising or publicity pertaining to + distribution of the software without specific, written prior permission. + M.I.T. makes no representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied warranty. + """ + +- cjs-module-lexer, located at deps/cjs-module-lexer, is licensed as follows: + """ + MIT License + ----------- + + Copyright (C) 2018-2020 Guy Bedford + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- ICU, located at deps/icu-small, is licensed as follows: + """ + COPYRIGHT AND PERMISSION NOTICE (ICU 58 and later) + + Copyright © 1991-2020 Unicode, Inc. All rights reserved. + Distributed under the Terms of Use in https://www.unicode.org/copyright.html. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of the Unicode data files and any associated documentation + (the "Data Files") or Unicode software and any associated documentation + (the "Software") to deal in the Data Files or Software + without restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, and/or sell copies of + the Data Files or Software, and to permit persons to whom the Data Files + or Software are furnished to do so, provided that either + (a) this copyright and permission notice appear with all copies + of the Data Files or Software, or + (b) this copyright and permission notice appear in associated + Documentation. + + THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF + ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT OF THIRD PARTY RIGHTS. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS + NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL + DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THE DATA FILES OR SOFTWARE. + + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, + use or other dealings in these Data Files or Software without prior + written authorization of the copyright holder. + + --------------------- + + Third-Party Software Licenses + + This section contains third-party software notices and/or additional + terms for licensed third-party software components included within ICU + libraries. + + 1. ICU License - ICU 1.8.1 to ICU 57.1 + + COPYRIGHT AND PERMISSION NOTICE + + Copyright (c) 1995-2016 International Business Machines Corporation and others + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, and/or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, provided that the above + copyright notice(s) and this permission notice appear in all copies of + the Software and that both the above copyright notice(s) and this + permission notice appear in supporting documentation. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, use + or other dealings in this Software without prior written authorization + of the copyright holder. + + All trademarks and registered trademarks mentioned herein are the + property of their respective owners. + + 2. Chinese/Japanese Word Break Dictionary Data (cjdict.txt) + + # The Google Chrome software developed by Google is licensed under + # the BSD license. Other software included in this distribution is + # provided under other licenses, as set forth below. + # + # The BSD License + # http://opensource.org/licenses/bsd-license.php + # Copyright (C) 2006-2008, Google Inc. + # + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # Redistributions of source code must retain the above copyright notice, + # this list of conditions and the following disclaimer. + # Redistributions in binary form must reproduce the above + # copyright notice, this list of conditions and the following + # disclaimer in the documentation and/or other materials provided with + # the distribution. + # Neither the name of Google Inc. nor the names of its + # contributors may be used to endorse or promote products derived from + # this software without specific prior written permission. + # + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # + # + # The word list in cjdict.txt are generated by combining three word lists + # listed below with further processing for compound word breaking. The + # frequency is generated with an iterative training against Google web + # corpora. + # + # * Libtabe (Chinese) + # - https://sourceforge.net/project/?group_id=1519 + # - Its license terms and conditions are shown below. + # + # * IPADIC (Japanese) + # - http://chasen.aist-nara.ac.jp/chasen/distribution.html + # - Its license terms and conditions are shown below. + # + # ---------COPYING.libtabe ---- BEGIN-------------------- + # + # /* + # * Copyright (c) 1999 TaBE Project. + # * Copyright (c) 1999 Pai-Hsiang Hsiao. + # * All rights reserved. + # * + # * Redistribution and use in source and binary forms, with or without + # * modification, are permitted provided that the following conditions + # * are met: + # * + # * . Redistributions of source code must retain the above copyright + # * notice, this list of conditions and the following disclaimer. + # * . Redistributions in binary form must reproduce the above copyright + # * notice, this list of conditions and the following disclaimer in + # * the documentation and/or other materials provided with the + # * distribution. + # * . Neither the name of the TaBE Project nor the names of its + # * contributors may be used to endorse or promote products derived + # * from this software without specific prior written permission. + # * + # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + # * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # * OF THE POSSIBILITY OF SUCH DAMAGE. + # */ + # + # /* + # * Copyright (c) 1999 Computer Systems and Communication Lab, + # * Institute of Information Science, Academia + # * Sinica. All rights reserved. + # * + # * Redistribution and use in source and binary forms, with or without + # * modification, are permitted provided that the following conditions + # * are met: + # * + # * . Redistributions of source code must retain the above copyright + # * notice, this list of conditions and the following disclaimer. + # * . Redistributions in binary form must reproduce the above copyright + # * notice, this list of conditions and the following disclaimer in + # * the documentation and/or other materials provided with the + # * distribution. + # * . Neither the name of the Computer Systems and Communication Lab + # * nor the names of its contributors may be used to endorse or + # * promote products derived from this software without specific + # * prior written permission. + # * + # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + # * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # * OF THE POSSIBILITY OF SUCH DAMAGE. + # */ + # + # Copyright 1996 Chih-Hao Tsai @ Beckman Institute, + # University of Illinois + # c-tsai4@uiuc.edu http://casper.beckman.uiuc.edu/~c-tsai4 + # + # ---------------COPYING.libtabe-----END-------------------------------- + # + # + # ---------------COPYING.ipadic-----BEGIN------------------------------- + # + # Copyright 2000, 2001, 2002, 2003 Nara Institute of Science + # and Technology. All Rights Reserved. + # + # Use, reproduction, and distribution of this software is permitted. + # Any copy of this software, whether in its original form or modified, + # must include both the above copyright notice and the following + # paragraphs. + # + # Nara Institute of Science and Technology (NAIST), + # the copyright holders, disclaims all warranties with regard to this + # software, including all implied warranties of merchantability and + # fitness, in no event shall NAIST be liable for + # any special, indirect or consequential damages or any damages + # whatsoever resulting from loss of use, data or profits, whether in an + # action of contract, negligence or other tortuous action, arising out + # of or in connection with the use or performance of this software. + # + # A large portion of the dictionary entries + # originate from ICOT Free Software. The following conditions for ICOT + # Free Software applies to the current dictionary as well. + # + # Each User may also freely distribute the Program, whether in its + # original form or modified, to any third party or parties, PROVIDED + # that the provisions of Section 3 ("NO WARRANTY") will ALWAYS appear + # on, or be attached to, the Program, which is distributed substantially + # in the same form as set out herein and that such intended + # distribution, if actually made, will neither violate or otherwise + # contravene any of the laws and regulations of the countries having + # jurisdiction over the User or the intended distribution itself. + # + # NO WARRANTY + # + # The program was produced on an experimental basis in the course of the + # research and development conducted during the project and is provided + # to users as so produced on an experimental basis. Accordingly, the + # program is provided without any warranty whatsoever, whether express, + # implied, statutory or otherwise. The term "warranty" used herein + # includes, but is not limited to, any warranty of the quality, + # performance, merchantability and fitness for a particular purpose of + # the program and the nonexistence of any infringement or violation of + # any right of any third party. + # + # Each user of the program will agree and understand, and be deemed to + # have agreed and understood, that there is no warranty whatsoever for + # the program and, accordingly, the entire risk arising from or + # otherwise connected with the program is assumed by the user. + # + # Therefore, neither ICOT, the copyright holder, or any other + # organization that participated in or was otherwise related to the + # development of the program and their respective officials, directors, + # officers and other employees shall be held liable for any and all + # damages, including, without limitation, general, special, incidental + # and consequential damages, arising out of or otherwise in connection + # with the use or inability to use the program or any product, material + # or result produced or otherwise obtained by using the program, + # regardless of whether they have been advised of, or otherwise had + # knowledge of, the possibility of such damages at any time during the + # project or thereafter. Each user will be deemed to have agreed to the + # foregoing by his or her commencement of use of the program. The term + # "use" as used herein includes, but is not limited to, the use, + # modification, copying and distribution of the program and the + # production of secondary products from the program. + # + # In the case where the program, whether in its original form or + # modified, was distributed or delivered to or received by a user from + # any person, organization or entity other than ICOT, unless it makes or + # grants independently of ICOT any specific warranty to the user in + # writing, such person, organization or entity, will also be exempted + # from and not be held liable to the user for any such damages as noted + # above as far as the program is concerned. + # + # ---------------COPYING.ipadic-----END---------------------------------- + + 3. Lao Word Break Dictionary Data (laodict.txt) + + # Copyright (C) 2016 and later: Unicode, Inc. and others. + # License & terms of use: http://www.unicode.org/copyright.html + # Copyright (c) 2015 International Business Machines Corporation + # and others. All Rights Reserved. + # + # Project: https://github.com/rober42539/lao-dictionary + # Dictionary: https://github.com/rober42539/lao-dictionary/laodict.txt + # License: https://github.com/rober42539/lao-dictionary/LICENSE.txt + # (copied below) + # + # This file is derived from the above dictionary version of Nov 22, 2020 + # ---------------------------------------------------------------------- + # Copyright (C) 2013 Brian Eugene Wilson, Robert Martin Campbell. + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # Redistributions of source code must retain the above copyright notice, this + # list of conditions and the following disclaimer. Redistributions in binary + # form must reproduce the above copyright notice, this list of conditions and + # the following disclaimer in the documentation and/or other materials + # provided with the distribution. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # OF THE POSSIBILITY OF SUCH DAMAGE. + # -------------------------------------------------------------------------- + + 4. Burmese Word Break Dictionary Data (burmesedict.txt) + + # Copyright (c) 2014 International Business Machines Corporation + # and others. All Rights Reserved. + # + # This list is part of a project hosted at: + # github.com/kanyawtech/myanmar-karen-word-lists + # + # -------------------------------------------------------------------------- + # Copyright (c) 2013, LeRoy Benjamin Sharon + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions + # are met: Redistributions of source code must retain the above + # copyright notice, this list of conditions and the following + # disclaimer. Redistributions in binary form must reproduce the + # above copyright notice, this list of conditions and the following + # disclaimer in the documentation and/or other materials provided + # with the distribution. + # + # Neither the name Myanmar Karen Word Lists, nor the names of its + # contributors may be used to endorse or promote products derived + # from this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS + # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + # SUCH DAMAGE. + # -------------------------------------------------------------------------- + + 5. Time Zone Database + + ICU uses the public domain data and code derived from Time Zone + Database for its time zone support. The ownership of the TZ database + is explained in BCP 175: Procedure for Maintaining the Time Zone + Database section 7. + + # 7. Database Ownership + # + # The TZ database itself is not an IETF Contribution or an IETF + # document. Rather it is a pre-existing and regularly updated work + # that is in the public domain, and is intended to remain in the + # public domain. Therefore, BCPs 78 [RFC5378] and 79 [RFC3979] do + # not apply to the TZ Database or contributions that individuals make + # to it. Should any claims be made and substantiated against the TZ + # Database, the organization that is providing the IANA + # Considerations defined in this RFC, under the memorandum of + # understanding with the IETF, currently ICANN, may act in accordance + # with all competent court orders. No ownership claims will be made + # by ICANN or the IETF Trust on the database or the code. Any person + # making a contribution to the database or code waives all rights to + # future claims in that contribution or in the TZ Database. + + 6. Google double-conversion + + Copyright 2006-2011, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- libuv, located at deps/uv, is licensed as follows: + """ + libuv is licensed for use as follows: + + ==== + Copyright (c) 2015-present libuv project contributors. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + ==== + + This license applies to parts of libuv originating from the + https://github.com/joyent/libuv repository: + + ==== + + Copyright Joyent, Inc. and other Node contributors. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + ==== + + This license applies to all parts of libuv that are not externally + maintained libraries. + + The externally maintained libraries used by libuv are: + + - tree.h (from FreeBSD), copyright Niels Provos. Two clause BSD license. + + - inet_pton and inet_ntop implementations, contained in src/inet.c, are + copyright the Internet Systems Consortium, Inc., and licensed under the ISC + license. + + - stdint-msvc2008.h (from msinttypes), copyright Alexander Chemeris. Three + clause BSD license. + + - pthread-fixes.c, copyright Google Inc. and Sony Mobile Communications AB. + Three clause BSD license. + + - android-ifaddrs.h, android-ifaddrs.c, copyright Berkeley Software Design + Inc, Kenneth MacKay and Emergya (Cloud4all, FP7/2007-2013, grant agreement + n° 289016). Three clause BSD license. + """ + +- llhttp, located at deps/llhttp, is licensed as follows: + """ + This software is licensed under the MIT License. + + Copyright Fedor Indutny, 2018. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- corepack, located at deps/corepack, is licensed as follows: + """ + **Copyright © Corepack contributors** + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- undici, located at deps/undici, is licensed as follows: + """ + MIT License + + Copyright (c) Matteo Collina and Undici contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + """ + +- OpenSSL, located at deps/openssl, is licensed as follows: + """ + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + """ + +- Punycode.js, located at lib/punycode.js, is licensed as follows: + """ + Copyright Mathias Bynens + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- V8, located at deps/v8, is licensed as follows: + """ + This license applies to all parts of V8 that are not externally + maintained libraries. The externally maintained libraries used by V8 + are: + + - PCRE test suite, located in + test/mjsunit/third_party/regexp-pcre/regexp-pcre.js. This is based on the + test suite from PCRE-7.3, which is copyrighted by the University + of Cambridge and Google, Inc. The copyright notice and license + are embedded in regexp-pcre.js. + + - Layout tests, located in test/mjsunit/third_party/object-keys. These are + based on layout tests from webkit.org which are copyrighted by + Apple Computer, Inc. and released under a 3-clause BSD license. + + - Strongtalk assembler, the basis of the files assembler-arm-inl.h, + assembler-arm.cc, assembler-arm.h, assembler-ia32-inl.h, + assembler-ia32.cc, assembler-ia32.h, assembler-x64-inl.h, + assembler-x64.cc, assembler-x64.h, assembler-mips-inl.h, + assembler-mips.cc, assembler-mips.h, assembler.cc and assembler.h. + This code is copyrighted by Sun Microsystems Inc. and released + under a 3-clause BSD license. + + - Valgrind client API header, located at src/third_party/valgrind/valgrind.h + This is released under the BSD license. + + - The Wasm C/C++ API headers, located at third_party/wasm-api/wasm.{h,hh} + This is released under the Apache license. The API's upstream prototype + implementation also formed the basis of V8's implementation in + src/wasm/c-api.cc. + + These libraries have their own licenses; we recommend you read them, + as their terms may differ from the terms below. + + Further license information can be found in LICENSE files located in + sub-directories. + + Copyright 2014, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- SipHash, located at deps/v8/src/third_party/siphash, is licensed as follows: + """ + SipHash reference C implementation + + Copyright (c) 2016 Jean-Philippe Aumasson + + To the extent possible under law, the author(s) have dedicated all + copyright and related and neighboring rights to this software to the public + domain worldwide. This software is distributed without any warranty. + """ + +- zlib, located at deps/zlib, is licensed as follows: + """ + zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.11, January 15th, 2017 + + Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + """ + +- npm, located at deps/npm, is licensed as follows: + """ + The npm application + Copyright (c) npm, Inc. and Contributors + Licensed on the terms of The Artistic License 2.0 + + Node package dependencies of the npm application + Copyright (c) their respective copyright owners + Licensed on their respective license terms + + The npm public registry at https://registry.npmjs.org + and the npm website at https://www.npmjs.com + Operated by npm, Inc. + Use governed by terms published on https://www.npmjs.com + + "Node.js" + Trademark Joyent, Inc., https://joyent.com + Neither npm nor npm, Inc. are affiliated with Joyent, Inc. + + The Node.js application + Project of Node Foundation, https://nodejs.org + + The npm Logo + Copyright (c) Mathias Pettersson and Brian Hammond + + "Gubblebum Blocky" typeface + Copyright (c) Tjarda Koster, https://jelloween.deviantart.com + Used with permission + + -------- + + The Artistic License 2.0 + + Copyright (c) 2000-2006, The Perl Foundation. + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + This license establishes the terms under which a given free software + Package may be copied, modified, distributed, and/or redistributed. + The intent is that the Copyright Holder maintains some artistic + control over the development of that Package while still keeping the + Package available as open source and free software. + + You are always permitted to make arrangements wholly outside of this + license directly with the Copyright Holder of a given Package. If the + terms of this license do not permit the full use that you propose to + make of the Package, you should contact the Copyright Holder and seek + a different licensing arrangement. + + Definitions + + "Copyright Holder" means the individual(s) or organization(s) + named in the copyright notice for the entire Package. + + "Contributor" means any party that has contributed code or other + material to the Package, in accordance with the Copyright Holder's + procedures. + + "You" and "your" means any person who would like to copy, + distribute, or modify the Package. + + "Package" means the collection of files distributed by the + Copyright Holder, and derivatives of that collection and/or of + those files. A given Package may consist of either the Standard + Version, or a Modified Version. + + "Distribute" means providing a copy of the Package or making it + accessible to anyone else, or in the case of a company or + organization, to others outside of your company or organization. + + "Distributor Fee" means any fee that you charge for Distributing + this Package or providing support for this Package to another + party. It does not mean licensing fees. + + "Standard Version" refers to the Package if it has not been + modified, or has been modified only in ways explicitly requested + by the Copyright Holder. + + "Modified Version" means the Package, if it has been changed, and + such changes were not explicitly requested by the Copyright + Holder. + + "Original License" means this Artistic License as Distributed with + the Standard Version of the Package, in its current version or as + it may be modified by The Perl Foundation in the future. + + "Source" form means the source code, documentation source, and + configuration files for the Package. + + "Compiled" form means the compiled bytecode, object code, binary, + or any other form resulting from mechanical transformation or + translation of the Source form. + + Permission for Use and Modification Without Distribution + + (1) You are permitted to use the Standard Version and create and use + Modified Versions for any purpose without restriction, provided that + you do not Distribute the Modified Version. + + Permissions for Redistribution of the Standard Version + + (2) You may Distribute verbatim copies of the Source form of the + Standard Version of this Package in any medium without restriction, + either gratis or for a Distributor Fee, provided that you duplicate + all of the original copyright notices and associated disclaimers. At + your discretion, such verbatim copies may or may not include a + Compiled form of the Package. + + (3) You may apply any bug fixes, portability changes, and other + modifications made available from the Copyright Holder. The resulting + Package will still be considered the Standard Version, and as such + will be subject to the Original License. + + Distribution of Modified Versions of the Package as Source + + (4) You may Distribute your Modified Version as Source (either gratis + or for a Distributor Fee, and with or without a Compiled form of the + Modified Version) provided that you clearly document how it differs + from the Standard Version, including, but not limited to, documenting + any non-standard features, executables, or modules, and provided that + you do at least ONE of the following: + + (a) make the Modified Version available to the Copyright Holder + of the Standard Version, under the Original License, so that the + Copyright Holder may include your modifications in the Standard + Version. + + (b) ensure that installation of your Modified Version does not + prevent the user installing or running the Standard Version. In + addition, the Modified Version must bear a name that is different + from the name of the Standard Version. + + (c) allow anyone who receives a copy of the Modified Version to + make the Source form of the Modified Version available to others + under + + (i) the Original License or + + (ii) a license that permits the licensee to freely copy, + modify and redistribute the Modified Version using the same + licensing terms that apply to the copy that the licensee + received, and requires that the Source form of the Modified + Version, and of any works derived from it, be made freely + available in that license fees are prohibited but Distributor + Fees are allowed. + + Distribution of Compiled Forms of the Standard Version + or Modified Versions without the Source + + (5) You may Distribute Compiled forms of the Standard Version without + the Source, provided that you include complete instructions on how to + get the Source of the Standard Version. Such instructions must be + valid at the time of your distribution. If these instructions, at any + time while you are carrying out such distribution, become invalid, you + must provide new instructions on demand or cease further distribution. + If you provide valid instructions or cease distribution within thirty + days after you become aware that the instructions are invalid, then + you do not forfeit any of your rights under this license. + + (6) You may Distribute a Modified Version in Compiled form without + the Source, provided that you comply with Section 4 with respect to + the Source of the Modified Version. + + Aggregating or Linking the Package + + (7) You may aggregate the Package (either the Standard Version or + Modified Version) with other packages and Distribute the resulting + aggregation provided that you do not charge a licensing fee for the + Package. Distributor Fees are permitted, and licensing fees for other + components in the aggregation are permitted. The terms of this license + apply to the use and Distribution of the Standard or Modified Versions + as included in the aggregation. + + (8) You are permitted to link Modified and Standard Versions with + other works, to embed the Package in a larger work of your own, or to + build stand-alone binary or bytecode versions of applications that + include the Package, and Distribute the result without restriction, + provided the result does not expose a direct interface to the Package. + + Items That are Not Considered Part of a Modified Version + + (9) Works (including, but not limited to, modules and scripts) that + merely extend or make use of the Package, do not, by themselves, cause + the Package to be a Modified Version. In addition, such works are not + considered parts of the Package itself, and are not subject to the + terms of this license. + + General Provisions + + (10) Any use, modification, and distribution of the Standard or + Modified Versions is governed by this Artistic License. By using, + modifying or distributing the Package, you accept this license. Do not + use, modify, or distribute the Package, if you do not accept this + license. + + (11) If your Modified Version has been derived from a Modified + Version made by someone other than you, you are nevertheless required + to ensure that your Modified Version complies with the requirements of + this license. + + (12) This license does not grant you the right to use any trademark, + service mark, tradename, or logo of the Copyright Holder. + + (13) This license includes the non-exclusive, worldwide, + free-of-charge patent license to make, have made, use, offer to sell, + sell, import and otherwise transfer the Package with respect to any + patent claims licensable by the Copyright Holder that are necessarily + infringed by the Package. If you institute patent litigation + (including a cross-claim or counterclaim) against any party alleging + that the Package constitutes direct or contributory patent + infringement, then this Artistic License to you shall terminate on the + date that such litigation is filed. + + (14) Disclaimer of Warranty: + THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR + NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL + LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL + DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + -------- + """ + +- GYP, located at tools/gyp, is licensed as follows: + """ + Copyright (c) 2020 Node.js contributors. All rights reserved. + Copyright (c) 2009 Google Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- inspector_protocol, located at tools/inspector_protocol, is licensed as follows: + """ + // Copyright 2016 The Chromium Authors. All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions are + // met: + // + // * Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // * Redistributions in binary form must reproduce the above + // copyright notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // * Neither the name of Google Inc. nor the names of its + // contributors may be used to endorse or promote products derived from + // this software without specific prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- jinja2, located at tools/inspector_protocol/jinja2, is licensed as follows: + """ + Copyright (c) 2009 by the Jinja Team, see AUTHORS for more details. + + Some rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- markupsafe, located at tools/inspector_protocol/markupsafe, is licensed as follows: + """ + Copyright (c) 2010 by Armin Ronacher and contributors. See AUTHORS + for more details. + + Some rights reserved. + + Redistribution and use in source and binary forms of the software as well + as documentation, with or without modification, are permitted provided + that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + DAMAGE. + """ + +- cpplint.py, located at tools/cpplint.py, is licensed as follows: + """ + Copyright (c) 2009 Google Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- ESLint, located at tools/node_modules/eslint, is licensed as follows: + """ + Copyright OpenJS Foundation and other contributors, + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- gtest, located at deps/googletest, is licensed as follows: + """ + Copyright 2008, Google Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- nghttp2, located at deps/nghttp2, is licensed as follows: + """ + The MIT License + + Copyright (c) 2012, 2014, 2015, 2016 Tatsuhiro Tsujikawa + Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- large_pages, located at src/large_pages, is licensed as follows: + """ + Copyright (C) 2018 Intel Corporation + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES + OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- caja, located at lib/internal/freeze_intrinsics.js, is licensed as follows: + """ + Adapted from SES/Caja - Copyright (C) 2011 Google Inc. + Copyright (C) 2018 Agoric + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + """ + +- brotli, located at deps/brotli, is licensed as follows: + """ + Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- HdrHistogram, located at deps/histogram, is licensed as follows: + """ + The code in this repository code was Written by Gil Tene, Michael Barker, + and Matt Warren, and released to the public domain, as explained at + http://creativecommons.org/publicdomain/zero/1.0/ + + For users of this code who wish to consume it under the "BSD" license + rather than under the public domain or CC0 contribution text mentioned + above, the code found under this directory is *also* provided under the + following license (commonly referred to as the BSD 2-Clause License). This + license does not detract from the above stated release of the code into + the public domain, and simply represents an additional license granted by + the Author. + + ----------------------------------------------------------------------------- + ** Beginning of "BSD 2-Clause License" text. ** + + Copyright (c) 2012, 2013, 2014 Gil Tene + Copyright (c) 2014 Michael Barker + Copyright (c) 2014 Matt Warren + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + """ + +- highlight.js, located at doc/api_assets/highlight.pack.js, is licensed as follows: + """ + BSD 3-Clause License + + Copyright (c) 2006, Ivan Sagalaev. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- node-heapdump, located at src/heap_utils.cc, is licensed as follows: + """ + ISC License + + Copyright (c) 2012, Ben Noordhuis + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + === src/compat.h src/compat-inl.h === + + ISC License + + Copyright (c) 2014, StrongLoop Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- rimraf, located at lib/internal/fs/rimraf.js, is licensed as follows: + """ + The ISC License + + Copyright (c) Isaac Z. Schlueter and Contributors + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- uvwasi, located at deps/uvwasi, is licensed as follows: + """ + MIT License + + Copyright (c) 2019 Colin Ihrig and Contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + """ + +- ngtcp2, located at deps/ngtcp2/ngtcp2/, is licensed as follows: + """ + The MIT License + + Copyright (c) 2016 ngtcp2 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- nghttp3, located at deps/ngtcp2/nghttp3/, is licensed as follows: + """ + The MIT License + + Copyright (c) 2019 nghttp3 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- node-fs-extra, located at lib/internal/fs/cp, is licensed as follows: + """ + (The MIT License) + + Copyright (c) 2011-2017 JP Richardson + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files + (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, + merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ diff --git a/Kinc/Tools/linux_x64/tint b/Kinc/Tools/linux_x64/tint deleted file mode 100755 index 42a5527..0000000 Binary files a/Kinc/Tools/linux_x64/tint and /dev/null differ diff --git a/Kinc/Tools/macos/.gitattributes b/Kinc/Tools/macos/.gitattributes deleted file mode 100644 index 6254495..0000000 --- a/Kinc/Tools/macos/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* -text diff --git a/Kinc/Tools/macos/.gitignore b/Kinc/Tools/macos/.gitignore deleted file mode 100644 index e43b0f9..0000000 --- a/Kinc/Tools/macos/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store diff --git a/Kinc/Tools/macos/icon.png b/Kinc/Tools/macos/icon.png deleted file mode 100644 index 33cc846..0000000 Binary files a/Kinc/Tools/macos/icon.png and /dev/null differ diff --git a/Kinc/Tools/macos/kongruent b/Kinc/Tools/macos/kongruent deleted file mode 100755 index ef94259..0000000 Binary files a/Kinc/Tools/macos/kongruent and /dev/null differ diff --git a/Kinc/Tools/macos/kraffiti b/Kinc/Tools/macos/kraffiti deleted file mode 100755 index 0a94018..0000000 Binary files a/Kinc/Tools/macos/kraffiti and /dev/null differ diff --git a/Kinc/Tools/macos/krafix b/Kinc/Tools/macos/krafix deleted file mode 100755 index c951a66..0000000 Binary files a/Kinc/Tools/macos/krafix and /dev/null differ diff --git a/Kinc/Tools/macos/tint b/Kinc/Tools/macos/tint deleted file mode 100755 index 95791d3..0000000 Binary files a/Kinc/Tools/macos/tint and /dev/null differ diff --git a/Kinc/Tools/macos_arm64/icon.png b/Kinc/Tools/macos_arm64/icon.png new file mode 100644 index 0000000..5dd0e8d Binary files /dev/null and b/Kinc/Tools/macos_arm64/icon.png differ diff --git a/Kinc/Tools/macos_arm64/kmake b/Kinc/Tools/macos_arm64/kmake new file mode 100755 index 0000000..2334a3a Binary files /dev/null and b/Kinc/Tools/macos_arm64/kmake differ diff --git a/Kinc/Tools/macos_arm64/kmake_old b/Kinc/Tools/macos_arm64/kmake_old new file mode 100755 index 0000000..7af6a2a Binary files /dev/null and b/Kinc/Tools/macos_arm64/kmake_old differ diff --git a/Kinc/Tools/macos_arm64/kongruent b/Kinc/Tools/macos_arm64/kongruent new file mode 100755 index 0000000..afcc8d3 Binary files /dev/null and b/Kinc/Tools/macos_arm64/kongruent differ diff --git a/Kinc/Tools/macos_arm64/kraffiti b/Kinc/Tools/macos_arm64/kraffiti new file mode 100755 index 0000000..d4d1402 Binary files /dev/null and b/Kinc/Tools/macos_arm64/kraffiti differ diff --git a/Kinc/Tools/macos_arm64/krafix b/Kinc/Tools/macos_arm64/krafix new file mode 100755 index 0000000..85e795d Binary files /dev/null and b/Kinc/Tools/macos_arm64/krafix differ diff --git a/Kinc/Tools/macos_arm64/licenses.txt b/Kinc/Tools/macos_arm64/licenses.txt new file mode 100644 index 0000000..7025946 --- /dev/null +++ b/Kinc/Tools/macos_arm64/licenses.txt @@ -0,0 +1,1764 @@ +kmake is licensed for use as follows: + +""" +Copyright kmake contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +This license applies to parts of kmake originating from the +https://github.com/nodejs/node repository: + +""" +Copyright Node.js contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +This license applies to parts of kmake originating from the +https://github.com/joyent/node repository: + +""" +Copyright Joyent, Inc. and other Node contributors. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +The kmake license applies to all parts of kmake that are not externally +maintained libraries. + +The externally maintained libraries used by kmake are: + +- Acorn, located at deps/acorn, is licensed as follows: + """ + MIT License + + Copyright (C) 2012-2020 by various contributors (see AUTHORS) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- c-ares, located at deps/cares, is licensed as follows: + """ + Copyright (c) 2007 - 2018, Daniel Stenberg with many contributors, see AUTHORS + file. + + Copyright 1998 by the Massachusetts Institute of Technology. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose and without fee is hereby granted, provided that + the above copyright notice appear in all copies and that both that copyright + notice and this permission notice appear in supporting documentation, and that + the name of M.I.T. not be used in advertising or publicity pertaining to + distribution of the software without specific, written prior permission. + M.I.T. makes no representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied warranty. + """ + +- cjs-module-lexer, located at deps/cjs-module-lexer, is licensed as follows: + """ + MIT License + ----------- + + Copyright (C) 2018-2020 Guy Bedford + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- ICU, located at deps/icu-small, is licensed as follows: + """ + COPYRIGHT AND PERMISSION NOTICE (ICU 58 and later) + + Copyright © 1991-2020 Unicode, Inc. All rights reserved. + Distributed under the Terms of Use in https://www.unicode.org/copyright.html. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of the Unicode data files and any associated documentation + (the "Data Files") or Unicode software and any associated documentation + (the "Software") to deal in the Data Files or Software + without restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, and/or sell copies of + the Data Files or Software, and to permit persons to whom the Data Files + or Software are furnished to do so, provided that either + (a) this copyright and permission notice appear with all copies + of the Data Files or Software, or + (b) this copyright and permission notice appear in associated + Documentation. + + THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF + ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT OF THIRD PARTY RIGHTS. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS + NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL + DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THE DATA FILES OR SOFTWARE. + + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, + use or other dealings in these Data Files or Software without prior + written authorization of the copyright holder. + + --------------------- + + Third-Party Software Licenses + + This section contains third-party software notices and/or additional + terms for licensed third-party software components included within ICU + libraries. + + 1. ICU License - ICU 1.8.1 to ICU 57.1 + + COPYRIGHT AND PERMISSION NOTICE + + Copyright (c) 1995-2016 International Business Machines Corporation and others + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, and/or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, provided that the above + copyright notice(s) and this permission notice appear in all copies of + the Software and that both the above copyright notice(s) and this + permission notice appear in supporting documentation. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, use + or other dealings in this Software without prior written authorization + of the copyright holder. + + All trademarks and registered trademarks mentioned herein are the + property of their respective owners. + + 2. Chinese/Japanese Word Break Dictionary Data (cjdict.txt) + + # The Google Chrome software developed by Google is licensed under + # the BSD license. Other software included in this distribution is + # provided under other licenses, as set forth below. + # + # The BSD License + # http://opensource.org/licenses/bsd-license.php + # Copyright (C) 2006-2008, Google Inc. + # + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # Redistributions of source code must retain the above copyright notice, + # this list of conditions and the following disclaimer. + # Redistributions in binary form must reproduce the above + # copyright notice, this list of conditions and the following + # disclaimer in the documentation and/or other materials provided with + # the distribution. + # Neither the name of Google Inc. nor the names of its + # contributors may be used to endorse or promote products derived from + # this software without specific prior written permission. + # + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # + # + # The word list in cjdict.txt are generated by combining three word lists + # listed below with further processing for compound word breaking. The + # frequency is generated with an iterative training against Google web + # corpora. + # + # * Libtabe (Chinese) + # - https://sourceforge.net/project/?group_id=1519 + # - Its license terms and conditions are shown below. + # + # * IPADIC (Japanese) + # - http://chasen.aist-nara.ac.jp/chasen/distribution.html + # - Its license terms and conditions are shown below. + # + # ---------COPYING.libtabe ---- BEGIN-------------------- + # + # /* + # * Copyright (c) 1999 TaBE Project. + # * Copyright (c) 1999 Pai-Hsiang Hsiao. + # * All rights reserved. + # * + # * Redistribution and use in source and binary forms, with or without + # * modification, are permitted provided that the following conditions + # * are met: + # * + # * . Redistributions of source code must retain the above copyright + # * notice, this list of conditions and the following disclaimer. + # * . Redistributions in binary form must reproduce the above copyright + # * notice, this list of conditions and the following disclaimer in + # * the documentation and/or other materials provided with the + # * distribution. + # * . Neither the name of the TaBE Project nor the names of its + # * contributors may be used to endorse or promote products derived + # * from this software without specific prior written permission. + # * + # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + # * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # * OF THE POSSIBILITY OF SUCH DAMAGE. + # */ + # + # /* + # * Copyright (c) 1999 Computer Systems and Communication Lab, + # * Institute of Information Science, Academia + # * Sinica. All rights reserved. + # * + # * Redistribution and use in source and binary forms, with or without + # * modification, are permitted provided that the following conditions + # * are met: + # * + # * . Redistributions of source code must retain the above copyright + # * notice, this list of conditions and the following disclaimer. + # * . Redistributions in binary form must reproduce the above copyright + # * notice, this list of conditions and the following disclaimer in + # * the documentation and/or other materials provided with the + # * distribution. + # * . Neither the name of the Computer Systems and Communication Lab + # * nor the names of its contributors may be used to endorse or + # * promote products derived from this software without specific + # * prior written permission. + # * + # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + # * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # * OF THE POSSIBILITY OF SUCH DAMAGE. + # */ + # + # Copyright 1996 Chih-Hao Tsai @ Beckman Institute, + # University of Illinois + # c-tsai4@uiuc.edu http://casper.beckman.uiuc.edu/~c-tsai4 + # + # ---------------COPYING.libtabe-----END-------------------------------- + # + # + # ---------------COPYING.ipadic-----BEGIN------------------------------- + # + # Copyright 2000, 2001, 2002, 2003 Nara Institute of Science + # and Technology. All Rights Reserved. + # + # Use, reproduction, and distribution of this software is permitted. + # Any copy of this software, whether in its original form or modified, + # must include both the above copyright notice and the following + # paragraphs. + # + # Nara Institute of Science and Technology (NAIST), + # the copyright holders, disclaims all warranties with regard to this + # software, including all implied warranties of merchantability and + # fitness, in no event shall NAIST be liable for + # any special, indirect or consequential damages or any damages + # whatsoever resulting from loss of use, data or profits, whether in an + # action of contract, negligence or other tortuous action, arising out + # of or in connection with the use or performance of this software. + # + # A large portion of the dictionary entries + # originate from ICOT Free Software. The following conditions for ICOT + # Free Software applies to the current dictionary as well. + # + # Each User may also freely distribute the Program, whether in its + # original form or modified, to any third party or parties, PROVIDED + # that the provisions of Section 3 ("NO WARRANTY") will ALWAYS appear + # on, or be attached to, the Program, which is distributed substantially + # in the same form as set out herein and that such intended + # distribution, if actually made, will neither violate or otherwise + # contravene any of the laws and regulations of the countries having + # jurisdiction over the User or the intended distribution itself. + # + # NO WARRANTY + # + # The program was produced on an experimental basis in the course of the + # research and development conducted during the project and is provided + # to users as so produced on an experimental basis. Accordingly, the + # program is provided without any warranty whatsoever, whether express, + # implied, statutory or otherwise. The term "warranty" used herein + # includes, but is not limited to, any warranty of the quality, + # performance, merchantability and fitness for a particular purpose of + # the program and the nonexistence of any infringement or violation of + # any right of any third party. + # + # Each user of the program will agree and understand, and be deemed to + # have agreed and understood, that there is no warranty whatsoever for + # the program and, accordingly, the entire risk arising from or + # otherwise connected with the program is assumed by the user. + # + # Therefore, neither ICOT, the copyright holder, or any other + # organization that participated in or was otherwise related to the + # development of the program and their respective officials, directors, + # officers and other employees shall be held liable for any and all + # damages, including, without limitation, general, special, incidental + # and consequential damages, arising out of or otherwise in connection + # with the use or inability to use the program or any product, material + # or result produced or otherwise obtained by using the program, + # regardless of whether they have been advised of, or otherwise had + # knowledge of, the possibility of such damages at any time during the + # project or thereafter. Each user will be deemed to have agreed to the + # foregoing by his or her commencement of use of the program. The term + # "use" as used herein includes, but is not limited to, the use, + # modification, copying and distribution of the program and the + # production of secondary products from the program. + # + # In the case where the program, whether in its original form or + # modified, was distributed or delivered to or received by a user from + # any person, organization or entity other than ICOT, unless it makes or + # grants independently of ICOT any specific warranty to the user in + # writing, such person, organization or entity, will also be exempted + # from and not be held liable to the user for any such damages as noted + # above as far as the program is concerned. + # + # ---------------COPYING.ipadic-----END---------------------------------- + + 3. Lao Word Break Dictionary Data (laodict.txt) + + # Copyright (C) 2016 and later: Unicode, Inc. and others. + # License & terms of use: http://www.unicode.org/copyright.html + # Copyright (c) 2015 International Business Machines Corporation + # and others. All Rights Reserved. + # + # Project: https://github.com/rober42539/lao-dictionary + # Dictionary: https://github.com/rober42539/lao-dictionary/laodict.txt + # License: https://github.com/rober42539/lao-dictionary/LICENSE.txt + # (copied below) + # + # This file is derived from the above dictionary version of Nov 22, 2020 + # ---------------------------------------------------------------------- + # Copyright (C) 2013 Brian Eugene Wilson, Robert Martin Campbell. + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # Redistributions of source code must retain the above copyright notice, this + # list of conditions and the following disclaimer. Redistributions in binary + # form must reproduce the above copyright notice, this list of conditions and + # the following disclaimer in the documentation and/or other materials + # provided with the distribution. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # OF THE POSSIBILITY OF SUCH DAMAGE. + # -------------------------------------------------------------------------- + + 4. Burmese Word Break Dictionary Data (burmesedict.txt) + + # Copyright (c) 2014 International Business Machines Corporation + # and others. All Rights Reserved. + # + # This list is part of a project hosted at: + # github.com/kanyawtech/myanmar-karen-word-lists + # + # -------------------------------------------------------------------------- + # Copyright (c) 2013, LeRoy Benjamin Sharon + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions + # are met: Redistributions of source code must retain the above + # copyright notice, this list of conditions and the following + # disclaimer. Redistributions in binary form must reproduce the + # above copyright notice, this list of conditions and the following + # disclaimer in the documentation and/or other materials provided + # with the distribution. + # + # Neither the name Myanmar Karen Word Lists, nor the names of its + # contributors may be used to endorse or promote products derived + # from this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS + # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + # SUCH DAMAGE. + # -------------------------------------------------------------------------- + + 5. Time Zone Database + + ICU uses the public domain data and code derived from Time Zone + Database for its time zone support. The ownership of the TZ database + is explained in BCP 175: Procedure for Maintaining the Time Zone + Database section 7. + + # 7. Database Ownership + # + # The TZ database itself is not an IETF Contribution or an IETF + # document. Rather it is a pre-existing and regularly updated work + # that is in the public domain, and is intended to remain in the + # public domain. Therefore, BCPs 78 [RFC5378] and 79 [RFC3979] do + # not apply to the TZ Database or contributions that individuals make + # to it. Should any claims be made and substantiated against the TZ + # Database, the organization that is providing the IANA + # Considerations defined in this RFC, under the memorandum of + # understanding with the IETF, currently ICANN, may act in accordance + # with all competent court orders. No ownership claims will be made + # by ICANN or the IETF Trust on the database or the code. Any person + # making a contribution to the database or code waives all rights to + # future claims in that contribution or in the TZ Database. + + 6. Google double-conversion + + Copyright 2006-2011, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- libuv, located at deps/uv, is licensed as follows: + """ + libuv is licensed for use as follows: + + ==== + Copyright (c) 2015-present libuv project contributors. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + ==== + + This license applies to parts of libuv originating from the + https://github.com/joyent/libuv repository: + + ==== + + Copyright Joyent, Inc. and other Node contributors. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + ==== + + This license applies to all parts of libuv that are not externally + maintained libraries. + + The externally maintained libraries used by libuv are: + + - tree.h (from FreeBSD), copyright Niels Provos. Two clause BSD license. + + - inet_pton and inet_ntop implementations, contained in src/inet.c, are + copyright the Internet Systems Consortium, Inc., and licensed under the ISC + license. + + - stdint-msvc2008.h (from msinttypes), copyright Alexander Chemeris. Three + clause BSD license. + + - pthread-fixes.c, copyright Google Inc. and Sony Mobile Communications AB. + Three clause BSD license. + + - android-ifaddrs.h, android-ifaddrs.c, copyright Berkeley Software Design + Inc, Kenneth MacKay and Emergya (Cloud4all, FP7/2007-2013, grant agreement + n° 289016). Three clause BSD license. + """ + +- llhttp, located at deps/llhttp, is licensed as follows: + """ + This software is licensed under the MIT License. + + Copyright Fedor Indutny, 2018. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- corepack, located at deps/corepack, is licensed as follows: + """ + **Copyright © Corepack contributors** + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- undici, located at deps/undici, is licensed as follows: + """ + MIT License + + Copyright (c) Matteo Collina and Undici contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + """ + +- OpenSSL, located at deps/openssl, is licensed as follows: + """ + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + """ + +- Punycode.js, located at lib/punycode.js, is licensed as follows: + """ + Copyright Mathias Bynens + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- V8, located at deps/v8, is licensed as follows: + """ + This license applies to all parts of V8 that are not externally + maintained libraries. The externally maintained libraries used by V8 + are: + + - PCRE test suite, located in + test/mjsunit/third_party/regexp-pcre/regexp-pcre.js. This is based on the + test suite from PCRE-7.3, which is copyrighted by the University + of Cambridge and Google, Inc. The copyright notice and license + are embedded in regexp-pcre.js. + + - Layout tests, located in test/mjsunit/third_party/object-keys. These are + based on layout tests from webkit.org which are copyrighted by + Apple Computer, Inc. and released under a 3-clause BSD license. + + - Strongtalk assembler, the basis of the files assembler-arm-inl.h, + assembler-arm.cc, assembler-arm.h, assembler-ia32-inl.h, + assembler-ia32.cc, assembler-ia32.h, assembler-x64-inl.h, + assembler-x64.cc, assembler-x64.h, assembler-mips-inl.h, + assembler-mips.cc, assembler-mips.h, assembler.cc and assembler.h. + This code is copyrighted by Sun Microsystems Inc. and released + under a 3-clause BSD license. + + - Valgrind client API header, located at src/third_party/valgrind/valgrind.h + This is released under the BSD license. + + - The Wasm C/C++ API headers, located at third_party/wasm-api/wasm.{h,hh} + This is released under the Apache license. The API's upstream prototype + implementation also formed the basis of V8's implementation in + src/wasm/c-api.cc. + + These libraries have their own licenses; we recommend you read them, + as their terms may differ from the terms below. + + Further license information can be found in LICENSE files located in + sub-directories. + + Copyright 2014, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- SipHash, located at deps/v8/src/third_party/siphash, is licensed as follows: + """ + SipHash reference C implementation + + Copyright (c) 2016 Jean-Philippe Aumasson + + To the extent possible under law, the author(s) have dedicated all + copyright and related and neighboring rights to this software to the public + domain worldwide. This software is distributed without any warranty. + """ + +- zlib, located at deps/zlib, is licensed as follows: + """ + zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.11, January 15th, 2017 + + Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + """ + +- npm, located at deps/npm, is licensed as follows: + """ + The npm application + Copyright (c) npm, Inc. and Contributors + Licensed on the terms of The Artistic License 2.0 + + Node package dependencies of the npm application + Copyright (c) their respective copyright owners + Licensed on their respective license terms + + The npm public registry at https://registry.npmjs.org + and the npm website at https://www.npmjs.com + Operated by npm, Inc. + Use governed by terms published on https://www.npmjs.com + + "Node.js" + Trademark Joyent, Inc., https://joyent.com + Neither npm nor npm, Inc. are affiliated with Joyent, Inc. + + The Node.js application + Project of Node Foundation, https://nodejs.org + + The npm Logo + Copyright (c) Mathias Pettersson and Brian Hammond + + "Gubblebum Blocky" typeface + Copyright (c) Tjarda Koster, https://jelloween.deviantart.com + Used with permission + + -------- + + The Artistic License 2.0 + + Copyright (c) 2000-2006, The Perl Foundation. + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + This license establishes the terms under which a given free software + Package may be copied, modified, distributed, and/or redistributed. + The intent is that the Copyright Holder maintains some artistic + control over the development of that Package while still keeping the + Package available as open source and free software. + + You are always permitted to make arrangements wholly outside of this + license directly with the Copyright Holder of a given Package. If the + terms of this license do not permit the full use that you propose to + make of the Package, you should contact the Copyright Holder and seek + a different licensing arrangement. + + Definitions + + "Copyright Holder" means the individual(s) or organization(s) + named in the copyright notice for the entire Package. + + "Contributor" means any party that has contributed code or other + material to the Package, in accordance with the Copyright Holder's + procedures. + + "You" and "your" means any person who would like to copy, + distribute, or modify the Package. + + "Package" means the collection of files distributed by the + Copyright Holder, and derivatives of that collection and/or of + those files. A given Package may consist of either the Standard + Version, or a Modified Version. + + "Distribute" means providing a copy of the Package or making it + accessible to anyone else, or in the case of a company or + organization, to others outside of your company or organization. + + "Distributor Fee" means any fee that you charge for Distributing + this Package or providing support for this Package to another + party. It does not mean licensing fees. + + "Standard Version" refers to the Package if it has not been + modified, or has been modified only in ways explicitly requested + by the Copyright Holder. + + "Modified Version" means the Package, if it has been changed, and + such changes were not explicitly requested by the Copyright + Holder. + + "Original License" means this Artistic License as Distributed with + the Standard Version of the Package, in its current version or as + it may be modified by The Perl Foundation in the future. + + "Source" form means the source code, documentation source, and + configuration files for the Package. + + "Compiled" form means the compiled bytecode, object code, binary, + or any other form resulting from mechanical transformation or + translation of the Source form. + + Permission for Use and Modification Without Distribution + + (1) You are permitted to use the Standard Version and create and use + Modified Versions for any purpose without restriction, provided that + you do not Distribute the Modified Version. + + Permissions for Redistribution of the Standard Version + + (2) You may Distribute verbatim copies of the Source form of the + Standard Version of this Package in any medium without restriction, + either gratis or for a Distributor Fee, provided that you duplicate + all of the original copyright notices and associated disclaimers. At + your discretion, such verbatim copies may or may not include a + Compiled form of the Package. + + (3) You may apply any bug fixes, portability changes, and other + modifications made available from the Copyright Holder. The resulting + Package will still be considered the Standard Version, and as such + will be subject to the Original License. + + Distribution of Modified Versions of the Package as Source + + (4) You may Distribute your Modified Version as Source (either gratis + or for a Distributor Fee, and with or without a Compiled form of the + Modified Version) provided that you clearly document how it differs + from the Standard Version, including, but not limited to, documenting + any non-standard features, executables, or modules, and provided that + you do at least ONE of the following: + + (a) make the Modified Version available to the Copyright Holder + of the Standard Version, under the Original License, so that the + Copyright Holder may include your modifications in the Standard + Version. + + (b) ensure that installation of your Modified Version does not + prevent the user installing or running the Standard Version. In + addition, the Modified Version must bear a name that is different + from the name of the Standard Version. + + (c) allow anyone who receives a copy of the Modified Version to + make the Source form of the Modified Version available to others + under + + (i) the Original License or + + (ii) a license that permits the licensee to freely copy, + modify and redistribute the Modified Version using the same + licensing terms that apply to the copy that the licensee + received, and requires that the Source form of the Modified + Version, and of any works derived from it, be made freely + available in that license fees are prohibited but Distributor + Fees are allowed. + + Distribution of Compiled Forms of the Standard Version + or Modified Versions without the Source + + (5) You may Distribute Compiled forms of the Standard Version without + the Source, provided that you include complete instructions on how to + get the Source of the Standard Version. Such instructions must be + valid at the time of your distribution. If these instructions, at any + time while you are carrying out such distribution, become invalid, you + must provide new instructions on demand or cease further distribution. + If you provide valid instructions or cease distribution within thirty + days after you become aware that the instructions are invalid, then + you do not forfeit any of your rights under this license. + + (6) You may Distribute a Modified Version in Compiled form without + the Source, provided that you comply with Section 4 with respect to + the Source of the Modified Version. + + Aggregating or Linking the Package + + (7) You may aggregate the Package (either the Standard Version or + Modified Version) with other packages and Distribute the resulting + aggregation provided that you do not charge a licensing fee for the + Package. Distributor Fees are permitted, and licensing fees for other + components in the aggregation are permitted. The terms of this license + apply to the use and Distribution of the Standard or Modified Versions + as included in the aggregation. + + (8) You are permitted to link Modified and Standard Versions with + other works, to embed the Package in a larger work of your own, or to + build stand-alone binary or bytecode versions of applications that + include the Package, and Distribute the result without restriction, + provided the result does not expose a direct interface to the Package. + + Items That are Not Considered Part of a Modified Version + + (9) Works (including, but not limited to, modules and scripts) that + merely extend or make use of the Package, do not, by themselves, cause + the Package to be a Modified Version. In addition, such works are not + considered parts of the Package itself, and are not subject to the + terms of this license. + + General Provisions + + (10) Any use, modification, and distribution of the Standard or + Modified Versions is governed by this Artistic License. By using, + modifying or distributing the Package, you accept this license. Do not + use, modify, or distribute the Package, if you do not accept this + license. + + (11) If your Modified Version has been derived from a Modified + Version made by someone other than you, you are nevertheless required + to ensure that your Modified Version complies with the requirements of + this license. + + (12) This license does not grant you the right to use any trademark, + service mark, tradename, or logo of the Copyright Holder. + + (13) This license includes the non-exclusive, worldwide, + free-of-charge patent license to make, have made, use, offer to sell, + sell, import and otherwise transfer the Package with respect to any + patent claims licensable by the Copyright Holder that are necessarily + infringed by the Package. If you institute patent litigation + (including a cross-claim or counterclaim) against any party alleging + that the Package constitutes direct or contributory patent + infringement, then this Artistic License to you shall terminate on the + date that such litigation is filed. + + (14) Disclaimer of Warranty: + THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR + NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL + LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL + DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + -------- + """ + +- GYP, located at tools/gyp, is licensed as follows: + """ + Copyright (c) 2020 Node.js contributors. All rights reserved. + Copyright (c) 2009 Google Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- inspector_protocol, located at tools/inspector_protocol, is licensed as follows: + """ + // Copyright 2016 The Chromium Authors. All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions are + // met: + // + // * Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // * Redistributions in binary form must reproduce the above + // copyright notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // * Neither the name of Google Inc. nor the names of its + // contributors may be used to endorse or promote products derived from + // this software without specific prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- jinja2, located at tools/inspector_protocol/jinja2, is licensed as follows: + """ + Copyright (c) 2009 by the Jinja Team, see AUTHORS for more details. + + Some rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- markupsafe, located at tools/inspector_protocol/markupsafe, is licensed as follows: + """ + Copyright (c) 2010 by Armin Ronacher and contributors. See AUTHORS + for more details. + + Some rights reserved. + + Redistribution and use in source and binary forms of the software as well + as documentation, with or without modification, are permitted provided + that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + DAMAGE. + """ + +- cpplint.py, located at tools/cpplint.py, is licensed as follows: + """ + Copyright (c) 2009 Google Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- ESLint, located at tools/node_modules/eslint, is licensed as follows: + """ + Copyright OpenJS Foundation and other contributors, + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- gtest, located at deps/googletest, is licensed as follows: + """ + Copyright 2008, Google Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- nghttp2, located at deps/nghttp2, is licensed as follows: + """ + The MIT License + + Copyright (c) 2012, 2014, 2015, 2016 Tatsuhiro Tsujikawa + Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- large_pages, located at src/large_pages, is licensed as follows: + """ + Copyright (C) 2018 Intel Corporation + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES + OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- caja, located at lib/internal/freeze_intrinsics.js, is licensed as follows: + """ + Adapted from SES/Caja - Copyright (C) 2011 Google Inc. + Copyright (C) 2018 Agoric + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + """ + +- brotli, located at deps/brotli, is licensed as follows: + """ + Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- HdrHistogram, located at deps/histogram, is licensed as follows: + """ + The code in this repository code was Written by Gil Tene, Michael Barker, + and Matt Warren, and released to the public domain, as explained at + http://creativecommons.org/publicdomain/zero/1.0/ + + For users of this code who wish to consume it under the "BSD" license + rather than under the public domain or CC0 contribution text mentioned + above, the code found under this directory is *also* provided under the + following license (commonly referred to as the BSD 2-Clause License). This + license does not detract from the above stated release of the code into + the public domain, and simply represents an additional license granted by + the Author. + + ----------------------------------------------------------------------------- + ** Beginning of "BSD 2-Clause License" text. ** + + Copyright (c) 2012, 2013, 2014 Gil Tene + Copyright (c) 2014 Michael Barker + Copyright (c) 2014 Matt Warren + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + """ + +- highlight.js, located at doc/api_assets/highlight.pack.js, is licensed as follows: + """ + BSD 3-Clause License + + Copyright (c) 2006, Ivan Sagalaev. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- node-heapdump, located at src/heap_utils.cc, is licensed as follows: + """ + ISC License + + Copyright (c) 2012, Ben Noordhuis + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + === src/compat.h src/compat-inl.h === + + ISC License + + Copyright (c) 2014, StrongLoop Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- rimraf, located at lib/internal/fs/rimraf.js, is licensed as follows: + """ + The ISC License + + Copyright (c) Isaac Z. Schlueter and Contributors + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- uvwasi, located at deps/uvwasi, is licensed as follows: + """ + MIT License + + Copyright (c) 2019 Colin Ihrig and Contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + """ + +- ngtcp2, located at deps/ngtcp2/ngtcp2/, is licensed as follows: + """ + The MIT License + + Copyright (c) 2016 ngtcp2 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- nghttp3, located at deps/ngtcp2/nghttp3/, is licensed as follows: + """ + The MIT License + + Copyright (c) 2019 nghttp3 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- node-fs-extra, located at lib/internal/fs/cp, is licensed as follows: + """ + (The MIT License) + + Copyright (c) 2011-2017 JP Richardson + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files + (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, + merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ diff --git a/Kinc/Tools/macos_x64/icon.png b/Kinc/Tools/macos_x64/icon.png new file mode 100644 index 0000000..5dd0e8d Binary files /dev/null and b/Kinc/Tools/macos_x64/icon.png differ diff --git a/Kinc/Tools/macos/kmake b/Kinc/Tools/macos_x64/kmake similarity index 71% rename from Kinc/Tools/macos/kmake rename to Kinc/Tools/macos_x64/kmake index d235dfe..1d5eaf6 100755 Binary files a/Kinc/Tools/macos/kmake and b/Kinc/Tools/macos_x64/kmake differ diff --git a/Kinc/Tools/macos_x64/kongruent b/Kinc/Tools/macos_x64/kongruent new file mode 100755 index 0000000..7a6d56a Binary files /dev/null and b/Kinc/Tools/macos_x64/kongruent differ diff --git a/Kinc/Tools/macos_x64/kraffiti b/Kinc/Tools/macos_x64/kraffiti new file mode 100755 index 0000000..5881b93 Binary files /dev/null and b/Kinc/Tools/macos_x64/kraffiti differ diff --git a/Kinc/Tools/macos_x64/krafix b/Kinc/Tools/macos_x64/krafix new file mode 100755 index 0000000..cfa4d30 Binary files /dev/null and b/Kinc/Tools/macos_x64/krafix differ diff --git a/Kinc/Tools/macos_x64/licenses.txt b/Kinc/Tools/macos_x64/licenses.txt new file mode 100644 index 0000000..7025946 --- /dev/null +++ b/Kinc/Tools/macos_x64/licenses.txt @@ -0,0 +1,1764 @@ +kmake is licensed for use as follows: + +""" +Copyright kmake contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +This license applies to parts of kmake originating from the +https://github.com/nodejs/node repository: + +""" +Copyright Node.js contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +This license applies to parts of kmake originating from the +https://github.com/joyent/node repository: + +""" +Copyright Joyent, Inc. and other Node contributors. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +The kmake license applies to all parts of kmake that are not externally +maintained libraries. + +The externally maintained libraries used by kmake are: + +- Acorn, located at deps/acorn, is licensed as follows: + """ + MIT License + + Copyright (C) 2012-2020 by various contributors (see AUTHORS) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- c-ares, located at deps/cares, is licensed as follows: + """ + Copyright (c) 2007 - 2018, Daniel Stenberg with many contributors, see AUTHORS + file. + + Copyright 1998 by the Massachusetts Institute of Technology. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose and without fee is hereby granted, provided that + the above copyright notice appear in all copies and that both that copyright + notice and this permission notice appear in supporting documentation, and that + the name of M.I.T. not be used in advertising or publicity pertaining to + distribution of the software without specific, written prior permission. + M.I.T. makes no representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied warranty. + """ + +- cjs-module-lexer, located at deps/cjs-module-lexer, is licensed as follows: + """ + MIT License + ----------- + + Copyright (C) 2018-2020 Guy Bedford + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- ICU, located at deps/icu-small, is licensed as follows: + """ + COPYRIGHT AND PERMISSION NOTICE (ICU 58 and later) + + Copyright © 1991-2020 Unicode, Inc. All rights reserved. + Distributed under the Terms of Use in https://www.unicode.org/copyright.html. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of the Unicode data files and any associated documentation + (the "Data Files") or Unicode software and any associated documentation + (the "Software") to deal in the Data Files or Software + without restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, and/or sell copies of + the Data Files or Software, and to permit persons to whom the Data Files + or Software are furnished to do so, provided that either + (a) this copyright and permission notice appear with all copies + of the Data Files or Software, or + (b) this copyright and permission notice appear in associated + Documentation. + + THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF + ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT OF THIRD PARTY RIGHTS. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS + NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL + DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THE DATA FILES OR SOFTWARE. + + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, + use or other dealings in these Data Files or Software without prior + written authorization of the copyright holder. + + --------------------- + + Third-Party Software Licenses + + This section contains third-party software notices and/or additional + terms for licensed third-party software components included within ICU + libraries. + + 1. ICU License - ICU 1.8.1 to ICU 57.1 + + COPYRIGHT AND PERMISSION NOTICE + + Copyright (c) 1995-2016 International Business Machines Corporation and others + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, and/or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, provided that the above + copyright notice(s) and this permission notice appear in all copies of + the Software and that both the above copyright notice(s) and this + permission notice appear in supporting documentation. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, use + or other dealings in this Software without prior written authorization + of the copyright holder. + + All trademarks and registered trademarks mentioned herein are the + property of their respective owners. + + 2. Chinese/Japanese Word Break Dictionary Data (cjdict.txt) + + # The Google Chrome software developed by Google is licensed under + # the BSD license. Other software included in this distribution is + # provided under other licenses, as set forth below. + # + # The BSD License + # http://opensource.org/licenses/bsd-license.php + # Copyright (C) 2006-2008, Google Inc. + # + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # Redistributions of source code must retain the above copyright notice, + # this list of conditions and the following disclaimer. + # Redistributions in binary form must reproduce the above + # copyright notice, this list of conditions and the following + # disclaimer in the documentation and/or other materials provided with + # the distribution. + # Neither the name of Google Inc. nor the names of its + # contributors may be used to endorse or promote products derived from + # this software without specific prior written permission. + # + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # + # + # The word list in cjdict.txt are generated by combining three word lists + # listed below with further processing for compound word breaking. The + # frequency is generated with an iterative training against Google web + # corpora. + # + # * Libtabe (Chinese) + # - https://sourceforge.net/project/?group_id=1519 + # - Its license terms and conditions are shown below. + # + # * IPADIC (Japanese) + # - http://chasen.aist-nara.ac.jp/chasen/distribution.html + # - Its license terms and conditions are shown below. + # + # ---------COPYING.libtabe ---- BEGIN-------------------- + # + # /* + # * Copyright (c) 1999 TaBE Project. + # * Copyright (c) 1999 Pai-Hsiang Hsiao. + # * All rights reserved. + # * + # * Redistribution and use in source and binary forms, with or without + # * modification, are permitted provided that the following conditions + # * are met: + # * + # * . Redistributions of source code must retain the above copyright + # * notice, this list of conditions and the following disclaimer. + # * . Redistributions in binary form must reproduce the above copyright + # * notice, this list of conditions and the following disclaimer in + # * the documentation and/or other materials provided with the + # * distribution. + # * . Neither the name of the TaBE Project nor the names of its + # * contributors may be used to endorse or promote products derived + # * from this software without specific prior written permission. + # * + # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + # * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # * OF THE POSSIBILITY OF SUCH DAMAGE. + # */ + # + # /* + # * Copyright (c) 1999 Computer Systems and Communication Lab, + # * Institute of Information Science, Academia + # * Sinica. All rights reserved. + # * + # * Redistribution and use in source and binary forms, with or without + # * modification, are permitted provided that the following conditions + # * are met: + # * + # * . Redistributions of source code must retain the above copyright + # * notice, this list of conditions and the following disclaimer. + # * . Redistributions in binary form must reproduce the above copyright + # * notice, this list of conditions and the following disclaimer in + # * the documentation and/or other materials provided with the + # * distribution. + # * . Neither the name of the Computer Systems and Communication Lab + # * nor the names of its contributors may be used to endorse or + # * promote products derived from this software without specific + # * prior written permission. + # * + # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + # * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # * OF THE POSSIBILITY OF SUCH DAMAGE. + # */ + # + # Copyright 1996 Chih-Hao Tsai @ Beckman Institute, + # University of Illinois + # c-tsai4@uiuc.edu http://casper.beckman.uiuc.edu/~c-tsai4 + # + # ---------------COPYING.libtabe-----END-------------------------------- + # + # + # ---------------COPYING.ipadic-----BEGIN------------------------------- + # + # Copyright 2000, 2001, 2002, 2003 Nara Institute of Science + # and Technology. All Rights Reserved. + # + # Use, reproduction, and distribution of this software is permitted. + # Any copy of this software, whether in its original form or modified, + # must include both the above copyright notice and the following + # paragraphs. + # + # Nara Institute of Science and Technology (NAIST), + # the copyright holders, disclaims all warranties with regard to this + # software, including all implied warranties of merchantability and + # fitness, in no event shall NAIST be liable for + # any special, indirect or consequential damages or any damages + # whatsoever resulting from loss of use, data or profits, whether in an + # action of contract, negligence or other tortuous action, arising out + # of or in connection with the use or performance of this software. + # + # A large portion of the dictionary entries + # originate from ICOT Free Software. The following conditions for ICOT + # Free Software applies to the current dictionary as well. + # + # Each User may also freely distribute the Program, whether in its + # original form or modified, to any third party or parties, PROVIDED + # that the provisions of Section 3 ("NO WARRANTY") will ALWAYS appear + # on, or be attached to, the Program, which is distributed substantially + # in the same form as set out herein and that such intended + # distribution, if actually made, will neither violate or otherwise + # contravene any of the laws and regulations of the countries having + # jurisdiction over the User or the intended distribution itself. + # + # NO WARRANTY + # + # The program was produced on an experimental basis in the course of the + # research and development conducted during the project and is provided + # to users as so produced on an experimental basis. Accordingly, the + # program is provided without any warranty whatsoever, whether express, + # implied, statutory or otherwise. The term "warranty" used herein + # includes, but is not limited to, any warranty of the quality, + # performance, merchantability and fitness for a particular purpose of + # the program and the nonexistence of any infringement or violation of + # any right of any third party. + # + # Each user of the program will agree and understand, and be deemed to + # have agreed and understood, that there is no warranty whatsoever for + # the program and, accordingly, the entire risk arising from or + # otherwise connected with the program is assumed by the user. + # + # Therefore, neither ICOT, the copyright holder, or any other + # organization that participated in or was otherwise related to the + # development of the program and their respective officials, directors, + # officers and other employees shall be held liable for any and all + # damages, including, without limitation, general, special, incidental + # and consequential damages, arising out of or otherwise in connection + # with the use or inability to use the program or any product, material + # or result produced or otherwise obtained by using the program, + # regardless of whether they have been advised of, or otherwise had + # knowledge of, the possibility of such damages at any time during the + # project or thereafter. Each user will be deemed to have agreed to the + # foregoing by his or her commencement of use of the program. The term + # "use" as used herein includes, but is not limited to, the use, + # modification, copying and distribution of the program and the + # production of secondary products from the program. + # + # In the case where the program, whether in its original form or + # modified, was distributed or delivered to or received by a user from + # any person, organization or entity other than ICOT, unless it makes or + # grants independently of ICOT any specific warranty to the user in + # writing, such person, organization or entity, will also be exempted + # from and not be held liable to the user for any such damages as noted + # above as far as the program is concerned. + # + # ---------------COPYING.ipadic-----END---------------------------------- + + 3. Lao Word Break Dictionary Data (laodict.txt) + + # Copyright (C) 2016 and later: Unicode, Inc. and others. + # License & terms of use: http://www.unicode.org/copyright.html + # Copyright (c) 2015 International Business Machines Corporation + # and others. All Rights Reserved. + # + # Project: https://github.com/rober42539/lao-dictionary + # Dictionary: https://github.com/rober42539/lao-dictionary/laodict.txt + # License: https://github.com/rober42539/lao-dictionary/LICENSE.txt + # (copied below) + # + # This file is derived from the above dictionary version of Nov 22, 2020 + # ---------------------------------------------------------------------- + # Copyright (C) 2013 Brian Eugene Wilson, Robert Martin Campbell. + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # Redistributions of source code must retain the above copyright notice, this + # list of conditions and the following disclaimer. Redistributions in binary + # form must reproduce the above copyright notice, this list of conditions and + # the following disclaimer in the documentation and/or other materials + # provided with the distribution. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # OF THE POSSIBILITY OF SUCH DAMAGE. + # -------------------------------------------------------------------------- + + 4. Burmese Word Break Dictionary Data (burmesedict.txt) + + # Copyright (c) 2014 International Business Machines Corporation + # and others. All Rights Reserved. + # + # This list is part of a project hosted at: + # github.com/kanyawtech/myanmar-karen-word-lists + # + # -------------------------------------------------------------------------- + # Copyright (c) 2013, LeRoy Benjamin Sharon + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions + # are met: Redistributions of source code must retain the above + # copyright notice, this list of conditions and the following + # disclaimer. Redistributions in binary form must reproduce the + # above copyright notice, this list of conditions and the following + # disclaimer in the documentation and/or other materials provided + # with the distribution. + # + # Neither the name Myanmar Karen Word Lists, nor the names of its + # contributors may be used to endorse or promote products derived + # from this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS + # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + # SUCH DAMAGE. + # -------------------------------------------------------------------------- + + 5. Time Zone Database + + ICU uses the public domain data and code derived from Time Zone + Database for its time zone support. The ownership of the TZ database + is explained in BCP 175: Procedure for Maintaining the Time Zone + Database section 7. + + # 7. Database Ownership + # + # The TZ database itself is not an IETF Contribution or an IETF + # document. Rather it is a pre-existing and regularly updated work + # that is in the public domain, and is intended to remain in the + # public domain. Therefore, BCPs 78 [RFC5378] and 79 [RFC3979] do + # not apply to the TZ Database or contributions that individuals make + # to it. Should any claims be made and substantiated against the TZ + # Database, the organization that is providing the IANA + # Considerations defined in this RFC, under the memorandum of + # understanding with the IETF, currently ICANN, may act in accordance + # with all competent court orders. No ownership claims will be made + # by ICANN or the IETF Trust on the database or the code. Any person + # making a contribution to the database or code waives all rights to + # future claims in that contribution or in the TZ Database. + + 6. Google double-conversion + + Copyright 2006-2011, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- libuv, located at deps/uv, is licensed as follows: + """ + libuv is licensed for use as follows: + + ==== + Copyright (c) 2015-present libuv project contributors. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + ==== + + This license applies to parts of libuv originating from the + https://github.com/joyent/libuv repository: + + ==== + + Copyright Joyent, Inc. and other Node contributors. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + ==== + + This license applies to all parts of libuv that are not externally + maintained libraries. + + The externally maintained libraries used by libuv are: + + - tree.h (from FreeBSD), copyright Niels Provos. Two clause BSD license. + + - inet_pton and inet_ntop implementations, contained in src/inet.c, are + copyright the Internet Systems Consortium, Inc., and licensed under the ISC + license. + + - stdint-msvc2008.h (from msinttypes), copyright Alexander Chemeris. Three + clause BSD license. + + - pthread-fixes.c, copyright Google Inc. and Sony Mobile Communications AB. + Three clause BSD license. + + - android-ifaddrs.h, android-ifaddrs.c, copyright Berkeley Software Design + Inc, Kenneth MacKay and Emergya (Cloud4all, FP7/2007-2013, grant agreement + n° 289016). Three clause BSD license. + """ + +- llhttp, located at deps/llhttp, is licensed as follows: + """ + This software is licensed under the MIT License. + + Copyright Fedor Indutny, 2018. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- corepack, located at deps/corepack, is licensed as follows: + """ + **Copyright © Corepack contributors** + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- undici, located at deps/undici, is licensed as follows: + """ + MIT License + + Copyright (c) Matteo Collina and Undici contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + """ + +- OpenSSL, located at deps/openssl, is licensed as follows: + """ + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + """ + +- Punycode.js, located at lib/punycode.js, is licensed as follows: + """ + Copyright Mathias Bynens + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- V8, located at deps/v8, is licensed as follows: + """ + This license applies to all parts of V8 that are not externally + maintained libraries. The externally maintained libraries used by V8 + are: + + - PCRE test suite, located in + test/mjsunit/third_party/regexp-pcre/regexp-pcre.js. This is based on the + test suite from PCRE-7.3, which is copyrighted by the University + of Cambridge and Google, Inc. The copyright notice and license + are embedded in regexp-pcre.js. + + - Layout tests, located in test/mjsunit/third_party/object-keys. These are + based on layout tests from webkit.org which are copyrighted by + Apple Computer, Inc. and released under a 3-clause BSD license. + + - Strongtalk assembler, the basis of the files assembler-arm-inl.h, + assembler-arm.cc, assembler-arm.h, assembler-ia32-inl.h, + assembler-ia32.cc, assembler-ia32.h, assembler-x64-inl.h, + assembler-x64.cc, assembler-x64.h, assembler-mips-inl.h, + assembler-mips.cc, assembler-mips.h, assembler.cc and assembler.h. + This code is copyrighted by Sun Microsystems Inc. and released + under a 3-clause BSD license. + + - Valgrind client API header, located at src/third_party/valgrind/valgrind.h + This is released under the BSD license. + + - The Wasm C/C++ API headers, located at third_party/wasm-api/wasm.{h,hh} + This is released under the Apache license. The API's upstream prototype + implementation also formed the basis of V8's implementation in + src/wasm/c-api.cc. + + These libraries have their own licenses; we recommend you read them, + as their terms may differ from the terms below. + + Further license information can be found in LICENSE files located in + sub-directories. + + Copyright 2014, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- SipHash, located at deps/v8/src/third_party/siphash, is licensed as follows: + """ + SipHash reference C implementation + + Copyright (c) 2016 Jean-Philippe Aumasson + + To the extent possible under law, the author(s) have dedicated all + copyright and related and neighboring rights to this software to the public + domain worldwide. This software is distributed without any warranty. + """ + +- zlib, located at deps/zlib, is licensed as follows: + """ + zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.11, January 15th, 2017 + + Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + """ + +- npm, located at deps/npm, is licensed as follows: + """ + The npm application + Copyright (c) npm, Inc. and Contributors + Licensed on the terms of The Artistic License 2.0 + + Node package dependencies of the npm application + Copyright (c) their respective copyright owners + Licensed on their respective license terms + + The npm public registry at https://registry.npmjs.org + and the npm website at https://www.npmjs.com + Operated by npm, Inc. + Use governed by terms published on https://www.npmjs.com + + "Node.js" + Trademark Joyent, Inc., https://joyent.com + Neither npm nor npm, Inc. are affiliated with Joyent, Inc. + + The Node.js application + Project of Node Foundation, https://nodejs.org + + The npm Logo + Copyright (c) Mathias Pettersson and Brian Hammond + + "Gubblebum Blocky" typeface + Copyright (c) Tjarda Koster, https://jelloween.deviantart.com + Used with permission + + -------- + + The Artistic License 2.0 + + Copyright (c) 2000-2006, The Perl Foundation. + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + This license establishes the terms under which a given free software + Package may be copied, modified, distributed, and/or redistributed. + The intent is that the Copyright Holder maintains some artistic + control over the development of that Package while still keeping the + Package available as open source and free software. + + You are always permitted to make arrangements wholly outside of this + license directly with the Copyright Holder of a given Package. If the + terms of this license do not permit the full use that you propose to + make of the Package, you should contact the Copyright Holder and seek + a different licensing arrangement. + + Definitions + + "Copyright Holder" means the individual(s) or organization(s) + named in the copyright notice for the entire Package. + + "Contributor" means any party that has contributed code or other + material to the Package, in accordance with the Copyright Holder's + procedures. + + "You" and "your" means any person who would like to copy, + distribute, or modify the Package. + + "Package" means the collection of files distributed by the + Copyright Holder, and derivatives of that collection and/or of + those files. A given Package may consist of either the Standard + Version, or a Modified Version. + + "Distribute" means providing a copy of the Package or making it + accessible to anyone else, or in the case of a company or + organization, to others outside of your company or organization. + + "Distributor Fee" means any fee that you charge for Distributing + this Package or providing support for this Package to another + party. It does not mean licensing fees. + + "Standard Version" refers to the Package if it has not been + modified, or has been modified only in ways explicitly requested + by the Copyright Holder. + + "Modified Version" means the Package, if it has been changed, and + such changes were not explicitly requested by the Copyright + Holder. + + "Original License" means this Artistic License as Distributed with + the Standard Version of the Package, in its current version or as + it may be modified by The Perl Foundation in the future. + + "Source" form means the source code, documentation source, and + configuration files for the Package. + + "Compiled" form means the compiled bytecode, object code, binary, + or any other form resulting from mechanical transformation or + translation of the Source form. + + Permission for Use and Modification Without Distribution + + (1) You are permitted to use the Standard Version and create and use + Modified Versions for any purpose without restriction, provided that + you do not Distribute the Modified Version. + + Permissions for Redistribution of the Standard Version + + (2) You may Distribute verbatim copies of the Source form of the + Standard Version of this Package in any medium without restriction, + either gratis or for a Distributor Fee, provided that you duplicate + all of the original copyright notices and associated disclaimers. At + your discretion, such verbatim copies may or may not include a + Compiled form of the Package. + + (3) You may apply any bug fixes, portability changes, and other + modifications made available from the Copyright Holder. The resulting + Package will still be considered the Standard Version, and as such + will be subject to the Original License. + + Distribution of Modified Versions of the Package as Source + + (4) You may Distribute your Modified Version as Source (either gratis + or for a Distributor Fee, and with or without a Compiled form of the + Modified Version) provided that you clearly document how it differs + from the Standard Version, including, but not limited to, documenting + any non-standard features, executables, or modules, and provided that + you do at least ONE of the following: + + (a) make the Modified Version available to the Copyright Holder + of the Standard Version, under the Original License, so that the + Copyright Holder may include your modifications in the Standard + Version. + + (b) ensure that installation of your Modified Version does not + prevent the user installing or running the Standard Version. In + addition, the Modified Version must bear a name that is different + from the name of the Standard Version. + + (c) allow anyone who receives a copy of the Modified Version to + make the Source form of the Modified Version available to others + under + + (i) the Original License or + + (ii) a license that permits the licensee to freely copy, + modify and redistribute the Modified Version using the same + licensing terms that apply to the copy that the licensee + received, and requires that the Source form of the Modified + Version, and of any works derived from it, be made freely + available in that license fees are prohibited but Distributor + Fees are allowed. + + Distribution of Compiled Forms of the Standard Version + or Modified Versions without the Source + + (5) You may Distribute Compiled forms of the Standard Version without + the Source, provided that you include complete instructions on how to + get the Source of the Standard Version. Such instructions must be + valid at the time of your distribution. If these instructions, at any + time while you are carrying out such distribution, become invalid, you + must provide new instructions on demand or cease further distribution. + If you provide valid instructions or cease distribution within thirty + days after you become aware that the instructions are invalid, then + you do not forfeit any of your rights under this license. + + (6) You may Distribute a Modified Version in Compiled form without + the Source, provided that you comply with Section 4 with respect to + the Source of the Modified Version. + + Aggregating or Linking the Package + + (7) You may aggregate the Package (either the Standard Version or + Modified Version) with other packages and Distribute the resulting + aggregation provided that you do not charge a licensing fee for the + Package. Distributor Fees are permitted, and licensing fees for other + components in the aggregation are permitted. The terms of this license + apply to the use and Distribution of the Standard or Modified Versions + as included in the aggregation. + + (8) You are permitted to link Modified and Standard Versions with + other works, to embed the Package in a larger work of your own, or to + build stand-alone binary or bytecode versions of applications that + include the Package, and Distribute the result without restriction, + provided the result does not expose a direct interface to the Package. + + Items That are Not Considered Part of a Modified Version + + (9) Works (including, but not limited to, modules and scripts) that + merely extend or make use of the Package, do not, by themselves, cause + the Package to be a Modified Version. In addition, such works are not + considered parts of the Package itself, and are not subject to the + terms of this license. + + General Provisions + + (10) Any use, modification, and distribution of the Standard or + Modified Versions is governed by this Artistic License. By using, + modifying or distributing the Package, you accept this license. Do not + use, modify, or distribute the Package, if you do not accept this + license. + + (11) If your Modified Version has been derived from a Modified + Version made by someone other than you, you are nevertheless required + to ensure that your Modified Version complies with the requirements of + this license. + + (12) This license does not grant you the right to use any trademark, + service mark, tradename, or logo of the Copyright Holder. + + (13) This license includes the non-exclusive, worldwide, + free-of-charge patent license to make, have made, use, offer to sell, + sell, import and otherwise transfer the Package with respect to any + patent claims licensable by the Copyright Holder that are necessarily + infringed by the Package. If you institute patent litigation + (including a cross-claim or counterclaim) against any party alleging + that the Package constitutes direct or contributory patent + infringement, then this Artistic License to you shall terminate on the + date that such litigation is filed. + + (14) Disclaimer of Warranty: + THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR + NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL + LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL + DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + -------- + """ + +- GYP, located at tools/gyp, is licensed as follows: + """ + Copyright (c) 2020 Node.js contributors. All rights reserved. + Copyright (c) 2009 Google Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- inspector_protocol, located at tools/inspector_protocol, is licensed as follows: + """ + // Copyright 2016 The Chromium Authors. All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions are + // met: + // + // * Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // * Redistributions in binary form must reproduce the above + // copyright notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // * Neither the name of Google Inc. nor the names of its + // contributors may be used to endorse or promote products derived from + // this software without specific prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- jinja2, located at tools/inspector_protocol/jinja2, is licensed as follows: + """ + Copyright (c) 2009 by the Jinja Team, see AUTHORS for more details. + + Some rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- markupsafe, located at tools/inspector_protocol/markupsafe, is licensed as follows: + """ + Copyright (c) 2010 by Armin Ronacher and contributors. See AUTHORS + for more details. + + Some rights reserved. + + Redistribution and use in source and binary forms of the software as well + as documentation, with or without modification, are permitted provided + that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + DAMAGE. + """ + +- cpplint.py, located at tools/cpplint.py, is licensed as follows: + """ + Copyright (c) 2009 Google Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- ESLint, located at tools/node_modules/eslint, is licensed as follows: + """ + Copyright OpenJS Foundation and other contributors, + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- gtest, located at deps/googletest, is licensed as follows: + """ + Copyright 2008, Google Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- nghttp2, located at deps/nghttp2, is licensed as follows: + """ + The MIT License + + Copyright (c) 2012, 2014, 2015, 2016 Tatsuhiro Tsujikawa + Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- large_pages, located at src/large_pages, is licensed as follows: + """ + Copyright (C) 2018 Intel Corporation + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES + OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- caja, located at lib/internal/freeze_intrinsics.js, is licensed as follows: + """ + Adapted from SES/Caja - Copyright (C) 2011 Google Inc. + Copyright (C) 2018 Agoric + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + """ + +- brotli, located at deps/brotli, is licensed as follows: + """ + Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- HdrHistogram, located at deps/histogram, is licensed as follows: + """ + The code in this repository code was Written by Gil Tene, Michael Barker, + and Matt Warren, and released to the public domain, as explained at + http://creativecommons.org/publicdomain/zero/1.0/ + + For users of this code who wish to consume it under the "BSD" license + rather than under the public domain or CC0 contribution text mentioned + above, the code found under this directory is *also* provided under the + following license (commonly referred to as the BSD 2-Clause License). This + license does not detract from the above stated release of the code into + the public domain, and simply represents an additional license granted by + the Author. + + ----------------------------------------------------------------------------- + ** Beginning of "BSD 2-Clause License" text. ** + + Copyright (c) 2012, 2013, 2014 Gil Tene + Copyright (c) 2014 Michael Barker + Copyright (c) 2014 Matt Warren + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + """ + +- highlight.js, located at doc/api_assets/highlight.pack.js, is licensed as follows: + """ + BSD 3-Clause License + + Copyright (c) 2006, Ivan Sagalaev. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- node-heapdump, located at src/heap_utils.cc, is licensed as follows: + """ + ISC License + + Copyright (c) 2012, Ben Noordhuis + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + === src/compat.h src/compat-inl.h === + + ISC License + + Copyright (c) 2014, StrongLoop Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- rimraf, located at lib/internal/fs/rimraf.js, is licensed as follows: + """ + The ISC License + + Copyright (c) Isaac Z. Schlueter and Contributors + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- uvwasi, located at deps/uvwasi, is licensed as follows: + """ + MIT License + + Copyright (c) 2019 Colin Ihrig and Contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + """ + +- ngtcp2, located at deps/ngtcp2/ngtcp2/, is licensed as follows: + """ + The MIT License + + Copyright (c) 2016 ngtcp2 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- nghttp3, located at deps/ngtcp2/nghttp3/, is licensed as follows: + """ + The MIT License + + Copyright (c) 2019 nghttp3 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- node-fs-extra, located at lib/internal/fs/cp, is licensed as follows: + """ + (The MIT License) + + Copyright (c) 2011-2017 JP Richardson + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files + (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, + merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ diff --git a/Kinc/Tools/platform.sh b/Kinc/Tools/platform.sh index 10c9fd0..6d3abd9 100644 --- a/Kinc/Tools/platform.sh +++ b/Kinc/Tools/platform.sh @@ -1,22 +1,30 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then MACHINE_TYPE=`uname -m` if [[ "$MACHINE_TYPE" == "armv"* ]]; then - KINC_PLATFORM=linux_arm + KORE_PLATFORM=linux_arm elif [[ "$MACHINE_TYPE" == "aarch64"* ]]; then - KINC_PLATFORM=linux_arm64 + KORE_PLATFORM=linux_arm64 elif [[ "$MACHINE_TYPE" == "x86_64"* ]]; then - KINC_PLATFORM=linux_x64 + KORE_PLATFORM=linux_x64 else echo "Unknown Linux machine '$MACHINE_TYPE', please edit Tools/platform.sh" exit 1 fi elif [[ "$OSTYPE" == "darwin"* ]]; then - KINC_PLATFORM=macos + MACHINE_TYPE=`uname -m` + if [[ "$MACHINE_TYPE" == "arm64"* ]]; then + KORE_PLATFORM=macos_arm64 + elif [[ "$MACHINE_TYPE" == "x86_64"* ]]; then + KORE_PLATFORM=macos_x64 + else + echo "Unknown macOS machine '$MACHINE_TYPE', please edit Tools/platform.sh" + exit 1 + fi elif [[ "$OSTYPE" == "FreeBSD"* ]]; then - KINC_PLATFORM=freebsd_x64 + KORE_PLATFORM=freebsd_x64 elif [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then - KINC_PLATFORM=windows_x64 - KINC_EXE_SUFFIX=.exe + KORE_PLATFORM=windows_x64 + KORE_EXE_SUFFIX=.exe else echo "Unknown platform '$OSTYPE', please edit Tools/platform.sh" exit 1 diff --git a/Kinc/Tools/windows_x64/.DS_Store b/Kinc/Tools/windows_x64/.DS_Store new file mode 100644 index 0000000..834fc62 Binary files /dev/null and b/Kinc/Tools/windows_x64/.DS_Store differ diff --git a/Kinc/Tools/windows_x64/dxcompiler.dll b/Kinc/Tools/windows_x64/dxcompiler.dll new file mode 100644 index 0000000..30e6f68 Binary files /dev/null and b/Kinc/Tools/windows_x64/dxcompiler.dll differ diff --git a/Kinc/Tools/windows_x64/dxil.dll b/Kinc/Tools/windows_x64/dxil.dll new file mode 100644 index 0000000..db5a1ce Binary files /dev/null and b/Kinc/Tools/windows_x64/dxil.dll differ diff --git a/Kinc/Tools/windows_x64/icon.png b/Kinc/Tools/windows_x64/icon.png index 33cc846..5dd0e8d 100644 Binary files a/Kinc/Tools/windows_x64/icon.png and b/Kinc/Tools/windows_x64/icon.png differ diff --git a/Kinc/Tools/windows_x64/kmake.exe b/Kinc/Tools/windows_x64/kmake.exe index cefe38d..18655f4 100644 Binary files a/Kinc/Tools/windows_x64/kmake.exe and b/Kinc/Tools/windows_x64/kmake.exe differ diff --git a/Kinc/Tools/windows_x64/kongruent.exe b/Kinc/Tools/windows_x64/kongruent.exe index 04006b8..f16d7d8 100644 Binary files a/Kinc/Tools/windows_x64/kongruent.exe and b/Kinc/Tools/windows_x64/kongruent.exe differ diff --git a/Kinc/Tools/windows_x64/kraffiti.exe b/Kinc/Tools/windows_x64/kraffiti.exe index 2b3329d..c3c442b 100644 Binary files a/Kinc/Tools/windows_x64/kraffiti.exe and b/Kinc/Tools/windows_x64/kraffiti.exe differ diff --git a/Kinc/Tools/windows_x64/krafix.exe b/Kinc/Tools/windows_x64/krafix.exe index 33de945..5e81950 100644 Binary files a/Kinc/Tools/windows_x64/krafix.exe and b/Kinc/Tools/windows_x64/krafix.exe differ diff --git a/Kinc/Tools/windows_x64/licenses.txt b/Kinc/Tools/windows_x64/licenses.txt new file mode 100644 index 0000000..7025946 --- /dev/null +++ b/Kinc/Tools/windows_x64/licenses.txt @@ -0,0 +1,1764 @@ +kmake is licensed for use as follows: + +""" +Copyright kmake contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +This license applies to parts of kmake originating from the +https://github.com/nodejs/node repository: + +""" +Copyright Node.js contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +This license applies to parts of kmake originating from the +https://github.com/joyent/node repository: + +""" +Copyright Joyent, Inc. and other Node contributors. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +""" + +The kmake license applies to all parts of kmake that are not externally +maintained libraries. + +The externally maintained libraries used by kmake are: + +- Acorn, located at deps/acorn, is licensed as follows: + """ + MIT License + + Copyright (C) 2012-2020 by various contributors (see AUTHORS) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- c-ares, located at deps/cares, is licensed as follows: + """ + Copyright (c) 2007 - 2018, Daniel Stenberg with many contributors, see AUTHORS + file. + + Copyright 1998 by the Massachusetts Institute of Technology. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose and without fee is hereby granted, provided that + the above copyright notice appear in all copies and that both that copyright + notice and this permission notice appear in supporting documentation, and that + the name of M.I.T. not be used in advertising or publicity pertaining to + distribution of the software without specific, written prior permission. + M.I.T. makes no representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied warranty. + """ + +- cjs-module-lexer, located at deps/cjs-module-lexer, is licensed as follows: + """ + MIT License + ----------- + + Copyright (C) 2018-2020 Guy Bedford + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- ICU, located at deps/icu-small, is licensed as follows: + """ + COPYRIGHT AND PERMISSION NOTICE (ICU 58 and later) + + Copyright © 1991-2020 Unicode, Inc. All rights reserved. + Distributed under the Terms of Use in https://www.unicode.org/copyright.html. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of the Unicode data files and any associated documentation + (the "Data Files") or Unicode software and any associated documentation + (the "Software") to deal in the Data Files or Software + without restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, and/or sell copies of + the Data Files or Software, and to permit persons to whom the Data Files + or Software are furnished to do so, provided that either + (a) this copyright and permission notice appear with all copies + of the Data Files or Software, or + (b) this copyright and permission notice appear in associated + Documentation. + + THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF + ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT OF THIRD PARTY RIGHTS. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS + NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL + DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THE DATA FILES OR SOFTWARE. + + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, + use or other dealings in these Data Files or Software without prior + written authorization of the copyright holder. + + --------------------- + + Third-Party Software Licenses + + This section contains third-party software notices and/or additional + terms for licensed third-party software components included within ICU + libraries. + + 1. ICU License - ICU 1.8.1 to ICU 57.1 + + COPYRIGHT AND PERMISSION NOTICE + + Copyright (c) 1995-2016 International Business Machines Corporation and others + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, and/or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, provided that the above + copyright notice(s) and this permission notice appear in all copies of + the Software and that both the above copyright notice(s) and this + permission notice appear in supporting documentation. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + Except as contained in this notice, the name of a copyright holder + shall not be used in advertising or otherwise to promote the sale, use + or other dealings in this Software without prior written authorization + of the copyright holder. + + All trademarks and registered trademarks mentioned herein are the + property of their respective owners. + + 2. Chinese/Japanese Word Break Dictionary Data (cjdict.txt) + + # The Google Chrome software developed by Google is licensed under + # the BSD license. Other software included in this distribution is + # provided under other licenses, as set forth below. + # + # The BSD License + # http://opensource.org/licenses/bsd-license.php + # Copyright (C) 2006-2008, Google Inc. + # + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # Redistributions of source code must retain the above copyright notice, + # this list of conditions and the following disclaimer. + # Redistributions in binary form must reproduce the above + # copyright notice, this list of conditions and the following + # disclaimer in the documentation and/or other materials provided with + # the distribution. + # Neither the name of Google Inc. nor the names of its + # contributors may be used to endorse or promote products derived from + # this software without specific prior written permission. + # + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # + # + # The word list in cjdict.txt are generated by combining three word lists + # listed below with further processing for compound word breaking. The + # frequency is generated with an iterative training against Google web + # corpora. + # + # * Libtabe (Chinese) + # - https://sourceforge.net/project/?group_id=1519 + # - Its license terms and conditions are shown below. + # + # * IPADIC (Japanese) + # - http://chasen.aist-nara.ac.jp/chasen/distribution.html + # - Its license terms and conditions are shown below. + # + # ---------COPYING.libtabe ---- BEGIN-------------------- + # + # /* + # * Copyright (c) 1999 TaBE Project. + # * Copyright (c) 1999 Pai-Hsiang Hsiao. + # * All rights reserved. + # * + # * Redistribution and use in source and binary forms, with or without + # * modification, are permitted provided that the following conditions + # * are met: + # * + # * . Redistributions of source code must retain the above copyright + # * notice, this list of conditions and the following disclaimer. + # * . Redistributions in binary form must reproduce the above copyright + # * notice, this list of conditions and the following disclaimer in + # * the documentation and/or other materials provided with the + # * distribution. + # * . Neither the name of the TaBE Project nor the names of its + # * contributors may be used to endorse or promote products derived + # * from this software without specific prior written permission. + # * + # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + # * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # * OF THE POSSIBILITY OF SUCH DAMAGE. + # */ + # + # /* + # * Copyright (c) 1999 Computer Systems and Communication Lab, + # * Institute of Information Science, Academia + # * Sinica. All rights reserved. + # * + # * Redistribution and use in source and binary forms, with or without + # * modification, are permitted provided that the following conditions + # * are met: + # * + # * . Redistributions of source code must retain the above copyright + # * notice, this list of conditions and the following disclaimer. + # * . Redistributions in binary form must reproduce the above copyright + # * notice, this list of conditions and the following disclaimer in + # * the documentation and/or other materials provided with the + # * distribution. + # * . Neither the name of the Computer Systems and Communication Lab + # * nor the names of its contributors may be used to endorse or + # * promote products derived from this software without specific + # * prior written permission. + # * + # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + # * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # * OF THE POSSIBILITY OF SUCH DAMAGE. + # */ + # + # Copyright 1996 Chih-Hao Tsai @ Beckman Institute, + # University of Illinois + # c-tsai4@uiuc.edu http://casper.beckman.uiuc.edu/~c-tsai4 + # + # ---------------COPYING.libtabe-----END-------------------------------- + # + # + # ---------------COPYING.ipadic-----BEGIN------------------------------- + # + # Copyright 2000, 2001, 2002, 2003 Nara Institute of Science + # and Technology. All Rights Reserved. + # + # Use, reproduction, and distribution of this software is permitted. + # Any copy of this software, whether in its original form or modified, + # must include both the above copyright notice and the following + # paragraphs. + # + # Nara Institute of Science and Technology (NAIST), + # the copyright holders, disclaims all warranties with regard to this + # software, including all implied warranties of merchantability and + # fitness, in no event shall NAIST be liable for + # any special, indirect or consequential damages or any damages + # whatsoever resulting from loss of use, data or profits, whether in an + # action of contract, negligence or other tortuous action, arising out + # of or in connection with the use or performance of this software. + # + # A large portion of the dictionary entries + # originate from ICOT Free Software. The following conditions for ICOT + # Free Software applies to the current dictionary as well. + # + # Each User may also freely distribute the Program, whether in its + # original form or modified, to any third party or parties, PROVIDED + # that the provisions of Section 3 ("NO WARRANTY") will ALWAYS appear + # on, or be attached to, the Program, which is distributed substantially + # in the same form as set out herein and that such intended + # distribution, if actually made, will neither violate or otherwise + # contravene any of the laws and regulations of the countries having + # jurisdiction over the User or the intended distribution itself. + # + # NO WARRANTY + # + # The program was produced on an experimental basis in the course of the + # research and development conducted during the project and is provided + # to users as so produced on an experimental basis. Accordingly, the + # program is provided without any warranty whatsoever, whether express, + # implied, statutory or otherwise. The term "warranty" used herein + # includes, but is not limited to, any warranty of the quality, + # performance, merchantability and fitness for a particular purpose of + # the program and the nonexistence of any infringement or violation of + # any right of any third party. + # + # Each user of the program will agree and understand, and be deemed to + # have agreed and understood, that there is no warranty whatsoever for + # the program and, accordingly, the entire risk arising from or + # otherwise connected with the program is assumed by the user. + # + # Therefore, neither ICOT, the copyright holder, or any other + # organization that participated in or was otherwise related to the + # development of the program and their respective officials, directors, + # officers and other employees shall be held liable for any and all + # damages, including, without limitation, general, special, incidental + # and consequential damages, arising out of or otherwise in connection + # with the use or inability to use the program or any product, material + # or result produced or otherwise obtained by using the program, + # regardless of whether they have been advised of, or otherwise had + # knowledge of, the possibility of such damages at any time during the + # project or thereafter. Each user will be deemed to have agreed to the + # foregoing by his or her commencement of use of the program. The term + # "use" as used herein includes, but is not limited to, the use, + # modification, copying and distribution of the program and the + # production of secondary products from the program. + # + # In the case where the program, whether in its original form or + # modified, was distributed or delivered to or received by a user from + # any person, organization or entity other than ICOT, unless it makes or + # grants independently of ICOT any specific warranty to the user in + # writing, such person, organization or entity, will also be exempted + # from and not be held liable to the user for any such damages as noted + # above as far as the program is concerned. + # + # ---------------COPYING.ipadic-----END---------------------------------- + + 3. Lao Word Break Dictionary Data (laodict.txt) + + # Copyright (C) 2016 and later: Unicode, Inc. and others. + # License & terms of use: http://www.unicode.org/copyright.html + # Copyright (c) 2015 International Business Machines Corporation + # and others. All Rights Reserved. + # + # Project: https://github.com/rober42539/lao-dictionary + # Dictionary: https://github.com/rober42539/lao-dictionary/laodict.txt + # License: https://github.com/rober42539/lao-dictionary/LICENSE.txt + # (copied below) + # + # This file is derived from the above dictionary version of Nov 22, 2020 + # ---------------------------------------------------------------------- + # Copyright (C) 2013 Brian Eugene Wilson, Robert Martin Campbell. + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions are met: + # + # Redistributions of source code must retain the above copyright notice, this + # list of conditions and the following disclaimer. Redistributions in binary + # form must reproduce the above copyright notice, this list of conditions and + # the following disclaimer in the documentation and/or other materials + # provided with the distribution. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + # OF THE POSSIBILITY OF SUCH DAMAGE. + # -------------------------------------------------------------------------- + + 4. Burmese Word Break Dictionary Data (burmesedict.txt) + + # Copyright (c) 2014 International Business Machines Corporation + # and others. All Rights Reserved. + # + # This list is part of a project hosted at: + # github.com/kanyawtech/myanmar-karen-word-lists + # + # -------------------------------------------------------------------------- + # Copyright (c) 2013, LeRoy Benjamin Sharon + # All rights reserved. + # + # Redistribution and use in source and binary forms, with or without + # modification, are permitted provided that the following conditions + # are met: Redistributions of source code must retain the above + # copyright notice, this list of conditions and the following + # disclaimer. Redistributions in binary form must reproduce the + # above copyright notice, this list of conditions and the following + # disclaimer in the documentation and/or other materials provided + # with the distribution. + # + # Neither the name Myanmar Karen Word Lists, nor the names of its + # contributors may be used to endorse or promote products derived + # from this software without specific prior written permission. + # + # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS + # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + # SUCH DAMAGE. + # -------------------------------------------------------------------------- + + 5. Time Zone Database + + ICU uses the public domain data and code derived from Time Zone + Database for its time zone support. The ownership of the TZ database + is explained in BCP 175: Procedure for Maintaining the Time Zone + Database section 7. + + # 7. Database Ownership + # + # The TZ database itself is not an IETF Contribution or an IETF + # document. Rather it is a pre-existing and regularly updated work + # that is in the public domain, and is intended to remain in the + # public domain. Therefore, BCPs 78 [RFC5378] and 79 [RFC3979] do + # not apply to the TZ Database or contributions that individuals make + # to it. Should any claims be made and substantiated against the TZ + # Database, the organization that is providing the IANA + # Considerations defined in this RFC, under the memorandum of + # understanding with the IETF, currently ICANN, may act in accordance + # with all competent court orders. No ownership claims will be made + # by ICANN or the IETF Trust on the database or the code. Any person + # making a contribution to the database or code waives all rights to + # future claims in that contribution or in the TZ Database. + + 6. Google double-conversion + + Copyright 2006-2011, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- libuv, located at deps/uv, is licensed as follows: + """ + libuv is licensed for use as follows: + + ==== + Copyright (c) 2015-present libuv project contributors. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + ==== + + This license applies to parts of libuv originating from the + https://github.com/joyent/libuv repository: + + ==== + + Copyright Joyent, Inc. and other Node contributors. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + ==== + + This license applies to all parts of libuv that are not externally + maintained libraries. + + The externally maintained libraries used by libuv are: + + - tree.h (from FreeBSD), copyright Niels Provos. Two clause BSD license. + + - inet_pton and inet_ntop implementations, contained in src/inet.c, are + copyright the Internet Systems Consortium, Inc., and licensed under the ISC + license. + + - stdint-msvc2008.h (from msinttypes), copyright Alexander Chemeris. Three + clause BSD license. + + - pthread-fixes.c, copyright Google Inc. and Sony Mobile Communications AB. + Three clause BSD license. + + - android-ifaddrs.h, android-ifaddrs.c, copyright Berkeley Software Design + Inc, Kenneth MacKay and Emergya (Cloud4all, FP7/2007-2013, grant agreement + n° 289016). Three clause BSD license. + """ + +- llhttp, located at deps/llhttp, is licensed as follows: + """ + This software is licensed under the MIT License. + + Copyright Fedor Indutny, 2018. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- corepack, located at deps/corepack, is licensed as follows: + """ + **Copyright © Corepack contributors** + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- undici, located at deps/undici, is licensed as follows: + """ + MIT License + + Copyright (c) Matteo Collina and Undici contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + """ + +- OpenSSL, located at deps/openssl, is licensed as follows: + """ + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + """ + +- Punycode.js, located at lib/punycode.js, is licensed as follows: + """ + Copyright Mathias Bynens + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- V8, located at deps/v8, is licensed as follows: + """ + This license applies to all parts of V8 that are not externally + maintained libraries. The externally maintained libraries used by V8 + are: + + - PCRE test suite, located in + test/mjsunit/third_party/regexp-pcre/regexp-pcre.js. This is based on the + test suite from PCRE-7.3, which is copyrighted by the University + of Cambridge and Google, Inc. The copyright notice and license + are embedded in regexp-pcre.js. + + - Layout tests, located in test/mjsunit/third_party/object-keys. These are + based on layout tests from webkit.org which are copyrighted by + Apple Computer, Inc. and released under a 3-clause BSD license. + + - Strongtalk assembler, the basis of the files assembler-arm-inl.h, + assembler-arm.cc, assembler-arm.h, assembler-ia32-inl.h, + assembler-ia32.cc, assembler-ia32.h, assembler-x64-inl.h, + assembler-x64.cc, assembler-x64.h, assembler-mips-inl.h, + assembler-mips.cc, assembler-mips.h, assembler.cc and assembler.h. + This code is copyrighted by Sun Microsystems Inc. and released + under a 3-clause BSD license. + + - Valgrind client API header, located at src/third_party/valgrind/valgrind.h + This is released under the BSD license. + + - The Wasm C/C++ API headers, located at third_party/wasm-api/wasm.{h,hh} + This is released under the Apache license. The API's upstream prototype + implementation also formed the basis of V8's implementation in + src/wasm/c-api.cc. + + These libraries have their own licenses; we recommend you read them, + as their terms may differ from the terms below. + + Further license information can be found in LICENSE files located in + sub-directories. + + Copyright 2014, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- SipHash, located at deps/v8/src/third_party/siphash, is licensed as follows: + """ + SipHash reference C implementation + + Copyright (c) 2016 Jean-Philippe Aumasson + + To the extent possible under law, the author(s) have dedicated all + copyright and related and neighboring rights to this software to the public + domain worldwide. This software is distributed without any warranty. + """ + +- zlib, located at deps/zlib, is licensed as follows: + """ + zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.11, January 15th, 2017 + + Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + """ + +- npm, located at deps/npm, is licensed as follows: + """ + The npm application + Copyright (c) npm, Inc. and Contributors + Licensed on the terms of The Artistic License 2.0 + + Node package dependencies of the npm application + Copyright (c) their respective copyright owners + Licensed on their respective license terms + + The npm public registry at https://registry.npmjs.org + and the npm website at https://www.npmjs.com + Operated by npm, Inc. + Use governed by terms published on https://www.npmjs.com + + "Node.js" + Trademark Joyent, Inc., https://joyent.com + Neither npm nor npm, Inc. are affiliated with Joyent, Inc. + + The Node.js application + Project of Node Foundation, https://nodejs.org + + The npm Logo + Copyright (c) Mathias Pettersson and Brian Hammond + + "Gubblebum Blocky" typeface + Copyright (c) Tjarda Koster, https://jelloween.deviantart.com + Used with permission + + -------- + + The Artistic License 2.0 + + Copyright (c) 2000-2006, The Perl Foundation. + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + This license establishes the terms under which a given free software + Package may be copied, modified, distributed, and/or redistributed. + The intent is that the Copyright Holder maintains some artistic + control over the development of that Package while still keeping the + Package available as open source and free software. + + You are always permitted to make arrangements wholly outside of this + license directly with the Copyright Holder of a given Package. If the + terms of this license do not permit the full use that you propose to + make of the Package, you should contact the Copyright Holder and seek + a different licensing arrangement. + + Definitions + + "Copyright Holder" means the individual(s) or organization(s) + named in the copyright notice for the entire Package. + + "Contributor" means any party that has contributed code or other + material to the Package, in accordance with the Copyright Holder's + procedures. + + "You" and "your" means any person who would like to copy, + distribute, or modify the Package. + + "Package" means the collection of files distributed by the + Copyright Holder, and derivatives of that collection and/or of + those files. A given Package may consist of either the Standard + Version, or a Modified Version. + + "Distribute" means providing a copy of the Package or making it + accessible to anyone else, or in the case of a company or + organization, to others outside of your company or organization. + + "Distributor Fee" means any fee that you charge for Distributing + this Package or providing support for this Package to another + party. It does not mean licensing fees. + + "Standard Version" refers to the Package if it has not been + modified, or has been modified only in ways explicitly requested + by the Copyright Holder. + + "Modified Version" means the Package, if it has been changed, and + such changes were not explicitly requested by the Copyright + Holder. + + "Original License" means this Artistic License as Distributed with + the Standard Version of the Package, in its current version or as + it may be modified by The Perl Foundation in the future. + + "Source" form means the source code, documentation source, and + configuration files for the Package. + + "Compiled" form means the compiled bytecode, object code, binary, + or any other form resulting from mechanical transformation or + translation of the Source form. + + Permission for Use and Modification Without Distribution + + (1) You are permitted to use the Standard Version and create and use + Modified Versions for any purpose without restriction, provided that + you do not Distribute the Modified Version. + + Permissions for Redistribution of the Standard Version + + (2) You may Distribute verbatim copies of the Source form of the + Standard Version of this Package in any medium without restriction, + either gratis or for a Distributor Fee, provided that you duplicate + all of the original copyright notices and associated disclaimers. At + your discretion, such verbatim copies may or may not include a + Compiled form of the Package. + + (3) You may apply any bug fixes, portability changes, and other + modifications made available from the Copyright Holder. The resulting + Package will still be considered the Standard Version, and as such + will be subject to the Original License. + + Distribution of Modified Versions of the Package as Source + + (4) You may Distribute your Modified Version as Source (either gratis + or for a Distributor Fee, and with or without a Compiled form of the + Modified Version) provided that you clearly document how it differs + from the Standard Version, including, but not limited to, documenting + any non-standard features, executables, or modules, and provided that + you do at least ONE of the following: + + (a) make the Modified Version available to the Copyright Holder + of the Standard Version, under the Original License, so that the + Copyright Holder may include your modifications in the Standard + Version. + + (b) ensure that installation of your Modified Version does not + prevent the user installing or running the Standard Version. In + addition, the Modified Version must bear a name that is different + from the name of the Standard Version. + + (c) allow anyone who receives a copy of the Modified Version to + make the Source form of the Modified Version available to others + under + + (i) the Original License or + + (ii) a license that permits the licensee to freely copy, + modify and redistribute the Modified Version using the same + licensing terms that apply to the copy that the licensee + received, and requires that the Source form of the Modified + Version, and of any works derived from it, be made freely + available in that license fees are prohibited but Distributor + Fees are allowed. + + Distribution of Compiled Forms of the Standard Version + or Modified Versions without the Source + + (5) You may Distribute Compiled forms of the Standard Version without + the Source, provided that you include complete instructions on how to + get the Source of the Standard Version. Such instructions must be + valid at the time of your distribution. If these instructions, at any + time while you are carrying out such distribution, become invalid, you + must provide new instructions on demand or cease further distribution. + If you provide valid instructions or cease distribution within thirty + days after you become aware that the instructions are invalid, then + you do not forfeit any of your rights under this license. + + (6) You may Distribute a Modified Version in Compiled form without + the Source, provided that you comply with Section 4 with respect to + the Source of the Modified Version. + + Aggregating or Linking the Package + + (7) You may aggregate the Package (either the Standard Version or + Modified Version) with other packages and Distribute the resulting + aggregation provided that you do not charge a licensing fee for the + Package. Distributor Fees are permitted, and licensing fees for other + components in the aggregation are permitted. The terms of this license + apply to the use and Distribution of the Standard or Modified Versions + as included in the aggregation. + + (8) You are permitted to link Modified and Standard Versions with + other works, to embed the Package in a larger work of your own, or to + build stand-alone binary or bytecode versions of applications that + include the Package, and Distribute the result without restriction, + provided the result does not expose a direct interface to the Package. + + Items That are Not Considered Part of a Modified Version + + (9) Works (including, but not limited to, modules and scripts) that + merely extend or make use of the Package, do not, by themselves, cause + the Package to be a Modified Version. In addition, such works are not + considered parts of the Package itself, and are not subject to the + terms of this license. + + General Provisions + + (10) Any use, modification, and distribution of the Standard or + Modified Versions is governed by this Artistic License. By using, + modifying or distributing the Package, you accept this license. Do not + use, modify, or distribute the Package, if you do not accept this + license. + + (11) If your Modified Version has been derived from a Modified + Version made by someone other than you, you are nevertheless required + to ensure that your Modified Version complies with the requirements of + this license. + + (12) This license does not grant you the right to use any trademark, + service mark, tradename, or logo of the Copyright Holder. + + (13) This license includes the non-exclusive, worldwide, + free-of-charge patent license to make, have made, use, offer to sell, + sell, import and otherwise transfer the Package with respect to any + patent claims licensable by the Copyright Holder that are necessarily + infringed by the Package. If you institute patent litigation + (including a cross-claim or counterclaim) against any party alleging + that the Package constitutes direct or contributory patent + infringement, then this Artistic License to you shall terminate on the + date that such litigation is filed. + + (14) Disclaimer of Warranty: + THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS + IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR + NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL + LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL + DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + -------- + """ + +- GYP, located at tools/gyp, is licensed as follows: + """ + Copyright (c) 2020 Node.js contributors. All rights reserved. + Copyright (c) 2009 Google Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- inspector_protocol, located at tools/inspector_protocol, is licensed as follows: + """ + // Copyright 2016 The Chromium Authors. All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions are + // met: + // + // * Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // * Redistributions in binary form must reproduce the above + // copyright notice, this list of conditions and the following disclaimer + // in the documentation and/or other materials provided with the + // distribution. + // * Neither the name of Google Inc. nor the names of its + // contributors may be used to endorse or promote products derived from + // this software without specific prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- jinja2, located at tools/inspector_protocol/jinja2, is licensed as follows: + """ + Copyright (c) 2009 by the Jinja Team, see AUTHORS for more details. + + Some rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- markupsafe, located at tools/inspector_protocol/markupsafe, is licensed as follows: + """ + Copyright (c) 2010 by Armin Ronacher and contributors. See AUTHORS + for more details. + + Some rights reserved. + + Redistribution and use in source and binary forms of the software as well + as documentation, with or without modification, are permitted provided + that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + DAMAGE. + """ + +- cpplint.py, located at tools/cpplint.py, is licensed as follows: + """ + Copyright (c) 2009 Google Inc. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- ESLint, located at tools/node_modules/eslint, is licensed as follows: + """ + Copyright OpenJS Foundation and other contributors, + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- gtest, located at deps/googletest, is licensed as follows: + """ + Copyright 2008, Google Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- nghttp2, located at deps/nghttp2, is licensed as follows: + """ + The MIT License + + Copyright (c) 2012, 2014, 2015, 2016 Tatsuhiro Tsujikawa + Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- large_pages, located at src/large_pages, is licensed as follows: + """ + Copyright (C) 2018 Intel Corporation + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom + the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES + OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- caja, located at lib/internal/freeze_intrinsics.js, is licensed as follows: + """ + Adapted from SES/Caja - Copyright (C) 2011 Google Inc. + Copyright (C) 2018 Agoric + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + """ + +- brotli, located at deps/brotli, is licensed as follows: + """ + Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + """ + +- HdrHistogram, located at deps/histogram, is licensed as follows: + """ + The code in this repository code was Written by Gil Tene, Michael Barker, + and Matt Warren, and released to the public domain, as explained at + http://creativecommons.org/publicdomain/zero/1.0/ + + For users of this code who wish to consume it under the "BSD" license + rather than under the public domain or CC0 contribution text mentioned + above, the code found under this directory is *also* provided under the + following license (commonly referred to as the BSD 2-Clause License). This + license does not detract from the above stated release of the code into + the public domain, and simply represents an additional license granted by + the Author. + + ----------------------------------------------------------------------------- + ** Beginning of "BSD 2-Clause License" text. ** + + Copyright (c) 2012, 2013, 2014 Gil Tene + Copyright (c) 2014 Michael Barker + Copyright (c) 2014 Matt Warren + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + """ + +- highlight.js, located at doc/api_assets/highlight.pack.js, is licensed as follows: + """ + BSD 3-Clause License + + Copyright (c) 2006, Ivan Sagalaev. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + """ + +- node-heapdump, located at src/heap_utils.cc, is licensed as follows: + """ + ISC License + + Copyright (c) 2012, Ben Noordhuis + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + === src/compat.h src/compat-inl.h === + + ISC License + + Copyright (c) 2014, StrongLoop Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- rimraf, located at lib/internal/fs/rimraf.js, is licensed as follows: + """ + The ISC License + + Copyright (c) Isaac Z. Schlueter and Contributors + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + """ + +- uvwasi, located at deps/uvwasi, is licensed as follows: + """ + MIT License + + Copyright (c) 2019 Colin Ihrig and Contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + """ + +- ngtcp2, located at deps/ngtcp2/ngtcp2/, is licensed as follows: + """ + The MIT License + + Copyright (c) 2016 ngtcp2 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- nghttp3, located at deps/ngtcp2/nghttp3/, is licensed as follows: + """ + The MIT License + + Copyright (c) 2019 nghttp3 contributors + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ + +- node-fs-extra, located at lib/internal/fs/cp, is licensed as follows: + """ + (The MIT License) + + Copyright (c) 2011-2017 JP Richardson + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files + (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, + merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ diff --git a/Kinc/Tools/windows_x64/tint.exe b/Kinc/Tools/windows_x64/tint.exe deleted file mode 100644 index b46a684..0000000 Binary files a/Kinc/Tools/windows_x64/tint.exe and /dev/null differ diff --git a/Kinc/Tools/windows_x64/yasm-1.2.0-win32.exe b/Kinc/Tools/windows_x64/yasm-1.2.0-win32.exe deleted file mode 100644 index 6346550..0000000 Binary files a/Kinc/Tools/windows_x64/yasm-1.2.0-win32.exe and /dev/null differ diff --git a/Kinc/create_single_header_libs.js b/Kinc/create_single_header_libs.js index 70d86ac..b2082bf 100644 --- a/Kinc/create_single_header_libs.js +++ b/Kinc/create_single_header_libs.js @@ -136,7 +136,7 @@ let windows_backend = fs.readFileSync(path.resolve('Backends', 'Audio2', 'WASAPI windows_backend = windows_backend.replace('#include ', ''); windows_backend = miniPreprocessor(windows_backend); -lib = lib.replace('// BACKENDS-PLACEHOLDER', '#ifdef KORE_WINDOWS\n' + windows_backend + '\n#endif'); +lib = lib.replace('// BACKENDS-PLACEHOLDER', '#ifdef KINC_WINDOWS\n' + windows_backend + '\n#endif'); if (!fs.existsSync('single_header_libs')) { fs.mkdirSync('single_header_libs'); diff --git a/Kinc/format.js b/Kinc/format.js deleted file mode 100644 index 712ff51..0000000 --- a/Kinc/format.js +++ /dev/null @@ -1,61 +0,0 @@ -const child_process = require('child_process'); -const fs = require('fs'); -const path = require('path'); - -const excludes = [ - 'Backends/System/Android/Sources/android_native_app_glue.h', - 'Backends/System/Android/Sources/gl3stub.h', - 'Backends/System/Android/Sources/GLContext.cpp', - 'Backends/System/Android/Sources/GLContext.h', - 'Backends/System/Android/Sources/JNIHelper.cpp', - 'Backends/System/Android/Sources/JNIHelper.h', - 'Backends/System/Windows/Sources/d3dx12.h', - 'Backends/Graphics3/OpenGL1/Sources/GL/eglew.h', - 'Backends/Graphics3/OpenGL1/Sources/GL/glew.h', - 'Backends/Graphics3/OpenGL1/Sources/GL/glxew.h', - 'Backends/Graphics3/OpenGL1/Sources/GL/wglew.h', - 'Backends/Graphics4/OpenGL/Sources/GL/eglew.h', - 'Backends/Graphics4/OpenGL/Sources/GL/glew.h', - 'Backends/Graphics4/OpenGL/Sources/GL/glxew.h', - 'Backends/Graphics4/OpenGL/Sources/GL/wglew.h', - 'Backends/Graphics5/Direct3D12/Sources/d3dx12.h', - 'Backends/Graphics5/Vulkan/Sources/vulkan/vk_platform.h', - 'Backends/Graphics5/Vulkan/Sources/vulkan/vulkan.h', - 'Backends/System/Linux/Sources/kinc/backend/wayland/wayland-protocol.c.h', - 'Backends/System/Linux/Sources/kinc/backend/wayland/wayland-protocol.h', - 'Backends/System/Linux/Sources/kinc/backend/wayland/xdg-decoration.c.h', - 'Backends/System/Linux/Sources/kinc/backend/wayland/xdg-decoration.h', - 'Backends/System/Linux/Sources/kinc/backend/wayland/xdg-shell.c.h', - 'Backends/System/Linux/Sources/kinc/backend/wayland/xdg-shell.h', - 'Tests/Shader/Sources/stb_image_write.h' -]; - -function isExcluded(filepath) { - return excludes.indexOf(filepath.replace(/\\/g, '/')) >= 0 - || filepath.indexOf('Libraries') >= 0 - || filepath.indexOf('lz4') >= 0 - || filepath.indexOf('Tools') >= 0 - || filepath.indexOf('libs') >= 0 - || filepath.endsWith('.winrt.cpp'); -} - -function format(dir) { - const files = fs.readdirSync(dir); - for (let file of files) { - if (file.startsWith('.')) continue; - let filepath = path.join(dir, file); - let info = fs.statSync(filepath); - if (info.isDirectory()) { - format(filepath); - } - else { - if (isExcluded(filepath)) continue; - if (file.endsWith('.cpp') || file.endsWith('.h') || file.endsWith('.m') || file.endsWith('.mm')) { - console.log('Format ' + filepath); - child_process.execFileSync('clang-format', ['-style=file', '-i', filepath]); - } - } - } -} - -format('.'); diff --git a/Kinc/get_dlc b/Kinc/get_dlc index 24374c1..6a1ee85 100755 --- a/Kinc/get_dlc +++ b/Kinc/get_dlc @@ -1,4 +1,4 @@ #!/usr/bin/env bash . `dirname "$0"`/Tools/platform.sh -git -C `dirname "$0"` submodule update --depth 1 --init "Tools/$KINC_PLATFORM" +git -C `dirname "$0"` submodule update --depth 1 --init "Tools/$KORE_PLATFORM" diff --git a/Kinc/get_dlc_dangerously b/Kinc/get_dlc_dangerously index 9974f0d..1bd6e23 100755 --- a/Kinc/get_dlc_dangerously +++ b/Kinc/get_dlc_dangerously @@ -1,9 +1,9 @@ #!/usr/bin/env bash . `dirname "$0"`/Tools/platform.sh -if test -f "Tools/$KINC_PLATFORM/icon.png"; then -git -C `dirname "$0"` submodule update --remote --merge "Tools/$KINC_PLATFORM" +if test -f `dirname "$0"`"/Tools/$KORE_PLATFORM/icon.png"; then +git -C `dirname "$0"` submodule update --remote --merge "Tools/$KORE_PLATFORM" else -git -C `dirname "$0"` submodule update --init --remote "Tools/$KINC_PLATFORM" -git -C `dirname "$0"`/Tools/$KINC_PLATFORM checkout main +git -C `dirname "$0"` submodule update --init --remote "Tools/$KORE_PLATFORM" +git -C `dirname "$0"`/Tools/$KORE_PLATFORM checkout main fi \ No newline at end of file diff --git a/Kinc/kfile.js b/Kinc/kfile.js index 8a79a07..173763e 100644 --- a/Kinc/kfile.js +++ b/Kinc/kfile.js @@ -1,26 +1,31 @@ const fs = require('fs'); const path = require('path'); -const project = new Project('Kinc'); +const project = new Project('Kore'); + +function addKincDefine(name) { + project.addDefine('KINC_' + name); + project.addDefine('KORE_' + name); +} const g1 = true; -project.addDefine('KORE_G1'); +addKincDefine('G1'); const g2 = true; -project.addDefine('KORE_G2'); +addKincDefine('G2'); const g3 = true; -project.addDefine('KORE_G3'); +addKincDefine('G3'); let g4 = false; let g5 = false; const a1 = true; -project.addDefine('KORE_A1'); +addKincDefine('A1'); const a2 = true; -project.addDefine('KORE_A2'); +addKincDefine('A2'); let a3 = false; @@ -28,23 +33,20 @@ let a3 = false; // which is a little more restrictive than Kinc's zlib license. const lz4x = true; -project.addFile('Sources/**'); +project.addFile('Sources/kinc/**'); -if (Options.kong) { - project.addKongDir('KongShaders'); -} -else { - project.addFile('GLSLShaders/**'); -} +project.addFile('Shaders/**'); if (lz4x) { - project.addDefine('KORE_LZ4X'); + addKincDefine('LZ4X'); project.addExclude('Sources/kinc/io/lz4/**'); } project.addIncludeDir('Sources'); function addBackend(name) { - project.addFile('Backends/' + name + '/Sources/**'); + project.addFile('Backends/' + name + '/Sources/kinc/**'); + project.addFile('Backends/' + name + '/Sources/GL/**'); + project.addFile('Backends/' + name + '/Sources/Android/**'); project.addIncludeDir('Backends/' + name + '/Sources'); } @@ -62,7 +64,7 @@ if (platform === Platform.Windows) { project.addLib('ws2_32'); project.addLib('Winhttp'); - const directshow = (graphics !== GraphicsApi.Direct3D12 && graphics !== GraphicsApi.Default); + const directshow = (graphics !== GraphicsApi.Direct3D12 && graphics !== GraphicsApi.Vulkan && graphics !== GraphicsApi.Default); if (directshow) { project.addFile('Backends/System/Windows/Libraries/DirectShow/**'); project.addIncludeDir('Backends/System/Windows/Libraries/DirectShow/BaseClasses'); @@ -77,28 +79,28 @@ if (platform === Platform.Windows) { if (graphics === GraphicsApi.OpenGL1) { addBackend('Graphics3/OpenGL1'); - project.addDefine('KORE_OPENGL1'); + addKincDefine('OPENGL1'); project.addDefine('GLEW_STATIC'); } else if (graphics === GraphicsApi.OpenGL) { g4 = true; addBackend('Graphics4/OpenGL'); - project.addDefine('KORE_OPENGL'); + addKincDefine('OPENGL'); project.addDefine('GLEW_STATIC'); } else if (graphics === GraphicsApi.Direct3D11) { g4 = true; addBackend('Graphics4/Direct3D11'); - project.addDefine('KORE_DIRECT3D'); - project.addDefine('KORE_DIRECT3D11'); + addKincDefine('DIRECT3D'); + addKincDefine('DIRECT3D11'); project.addLib('d3d11'); } else if (graphics === GraphicsApi.Direct3D12 || graphics === GraphicsApi.Default) { g4 = true; g5 = true; addBackend('Graphics5/Direct3D12'); - project.addDefine('KORE_DIRECT3D'); - project.addDefine('KORE_DIRECT3D12'); + addKincDefine('DIRECT3D'); + addKincDefine('DIRECT3D12'); project.addLib('dxgi'); project.addLib('d3d12'); } @@ -106,7 +108,7 @@ if (platform === Platform.Windows) { g4 = true; g5 = true; addBackend('Graphics5/Vulkan'); - project.addDefine('KORE_VULKAN'); + addKincDefine('VULKAN'); project.addDefine('VK_USE_PLATFORM_WIN32_KHR'); if (!process.env.VULKAN_SDK) { throw 'Could not find a Vulkan SDK'; @@ -123,8 +125,8 @@ if (platform === Platform.Windows) { else if (graphics === GraphicsApi.Direct3D9) { g4 = true; addBackend('Graphics4/Direct3D9'); - project.addDefine('KORE_DIRECT3D'); - project.addDefine('KORE_DIRECT3D9'); + addKincDefine('DIRECT3D'); + addKincDefine('DIRECT3D9'); project.addLib('d3d9'); } else { @@ -142,8 +144,8 @@ if (platform === Platform.Windows) { } if (vr === VrApi.Oculus) { - project.addDefine('KORE_VR'); - project.addDefine('KORE_OCULUS'); + addKincDefine('VR'); + addKincDefine('OCULUS'); project.addLibFor('x64', 'Backends/System/Windows/Libraries/OculusSDK/LibOVR/Lib/Windows/x64/Release/VS2017/LibOVR'); project.addLibFor('Win32', 'Backends/System/Windows/Libraries/OculusSDK/LibOVR/Lib/Windows/Win32/Release/VS2017/LibOVR'); project.addFile('Backends/System/Windows/Libraries/OculusSDK/LibOVRKernel/Src/GL/**'); @@ -151,8 +153,8 @@ if (platform === Platform.Windows) { project.addIncludeDir('Backends/System/Windows/Libraries/OculusSDK/LibOVRKernel/Src/'); } else if (vr === VrApi.SteamVR) { - project.addDefine('KORE_VR'); - project.addDefine('KORE_STEAMVR'); + addKincDefine('VR'); + addKincDefine('STEAMVR'); project.addDefine('VR_API_PUBLIC'); project.addFile('Backends/System/Windows/Libraries/SteamVR/src/**'); project.addIncludeDir('Backends/System/Windows/Libraries/SteamVR/src'); @@ -165,10 +167,16 @@ if (platform === Platform.Windows) { else { throw new Error('VR API ' + vr + ' is not available for Windows.'); } + + if (Options.pix) { + addKincDefine('PIX'); + project.addIncludeDir('Backends/Graphics5/Direct3D12/pix/Include'); + project.addLib('Backends/Graphics5/Direct3D12/pix/bin/x64/WinPixEventRuntime'); + } } else if (platform === Platform.WindowsApp) { g4 = true; - project.addDefine('KORE_WINDOWSAPP'); + addKincDefine('WINDOWSAPP'); addBackend('System/WindowsApp'); addBackend('System/Microsoft'); addBackend('Graphics4/Direct3D11'); @@ -177,8 +185,8 @@ else if (platform === Platform.WindowsApp) { project.vsdeploy = true; if (vr === VrApi.HoloLens) { - project.addDefine('KORE_VR'); - project.addDefine('KORE_HOLOLENS'); + addKincDefine('VR'); + addKincDefine('HOLOLENS'); } else if (vr === VrApi.None) { @@ -195,19 +203,19 @@ else if (platform === Platform.OSX) { g4 = true; g5 = true; addBackend('Graphics5/Metal'); - project.addDefine('KORE_METAL'); + addKincDefine('METAL'); project.addLib('Metal'); project.addLib('MetalKit'); } else if (graphics === GraphicsApi.OpenGL1) { addBackend('Graphics3/OpenGL1'); - project.addDefine('KORE_OPENGL1'); + addKincDefine('OPENGL1'); project.addLib('OpenGL'); } else if (graphics === GraphicsApi.OpenGL) { g4 = true; addBackend('Graphics4/OpenGL'); - project.addDefine('KORE_OPENGL'); + addKincDefine('OPENGL'); project.addLib('OpenGL'); } else { @@ -225,7 +233,7 @@ else if (platform === Platform.OSX) { } else if (platform === Platform.iOS || platform === Platform.tvOS) { if (platform === Platform.tvOS) { - project.addDefine('KORE_TVOS'); + addKincDefine('TVOS'); } addBackend('System/Apple'); addBackend('System/iOS'); @@ -234,14 +242,14 @@ else if (platform === Platform.iOS || platform === Platform.tvOS) { g4 = true; g5 = true; addBackend('Graphics5/Metal'); - project.addDefine('KORE_METAL'); + addKincDefine('METAL'); project.addLib('Metal'); } else if (graphics === GraphicsApi.OpenGL) { g4 = true; addBackend('Graphics4/OpenGL'); - project.addDefine('KORE_OPENGL'); - project.addDefine('KORE_OPENGL_ES'); + addKincDefine('OPENGL'); + addKincDefine('OPENGL_ES'); project.addLib('OpenGLES'); } else { @@ -260,24 +268,24 @@ else if (platform === Platform.iOS || platform === Platform.tvOS) { project.addLib('CoreMedia'); } else if (platform === Platform.Android) { - project.addDefine('KORE_ANDROID'); + addKincDefine('ANDROID'); addBackend('System/Android'); addBackend('System/POSIX'); if (graphics === GraphicsApi.Vulkan || graphics === GraphicsApi.Default) { g4 = true; g5 = true; addBackend('Graphics5/Vulkan'); - project.addDefine('KORE_VULKAN'); + addKincDefine('VULKAN'); project.addDefine('VK_USE_PLATFORM_ANDROID_KHR'); project.addLib('vulkan'); - project.addDefine('KORE_ANDROID_API=24'); + addKincDefine('ANDROID_API=24'); } else if (graphics === GraphicsApi.OpenGL) { g4 = true; addBackend('Graphics4/OpenGL'); - project.addDefine('KORE_OPENGL'); - project.addDefine('KORE_OPENGL_ES'); - project.addDefine('KORE_ANDROID_API=19'); + addKincDefine('OPENGL'); + addKincDefine('OPENGL_ES'); + addKincDefine('ANDROID_API=19'); project.addDefine('KINC_EGL'); } else { @@ -286,42 +294,35 @@ else if (platform === Platform.Android) { project.addLib('log'); project.addLib('android'); project.addLib('EGL'); - if (Options.kong) { - project.addLib('GLESv3'); - } - else { - project.addLib('GLESv2'); - } + project.addLib('GLESv2'); project.addLib('OpenSLES'); project.addLib('OpenMAXAL'); } else if (platform === Platform.Emscripten) { - project.addDefine('KORE_EMSCRIPTEN'); + addKincDefine('EMSCRIPTEN'); //project.addLib('websocket.js -sPROXY_POSIX_SOCKETS -sUSE_PTHREADS -sPROXY_TO_PTHREAD'); addBackend('System/Emscripten'); - project.addLib('USE_GLFW=2'); + project.addLinkerFlag('-sUSE_GLFW=2'); if (graphics === GraphicsApi.WebGPU) { g4 = true; g5 = true; addBackend('Graphics5/WebGPU'); - project.addDefine('KORE_WEBGPU'); + addKincDefine('WEBGPU'); + project.addLinkerFlag('-sUSE_WEBGPU=1'); } else if (graphics === GraphicsApi.OpenGL || graphics === GraphicsApi.Default) { g4 = true; addBackend('Graphics4/OpenGL'); project.addExclude('Backends/Graphics4/OpenGL/Sources/GL/**'); - project.addDefine('KORE_OPENGL'); - project.addDefine('KORE_OPENGL_ES'); - if (Options.kong) { - project.addLib('USE_WEBGL2=1'); - } + addKincDefine('OPENGL'); + addKincDefine('OPENGL_ES'); } else { throw new Error('Graphics API ' + graphics + ' is not available for Emscripten.'); } } else if (platform === Platform.Wasm) { - project.addDefine('KORE_WASM'); + addKincDefine('WASM'); addBackend('System/Wasm'); project.addIncludeDir('miniClib'); project.addFile('miniClib/**'); @@ -329,14 +330,14 @@ else if (platform === Platform.Wasm) { g4 = true; g5 = true; addBackend('Graphics5/WebGPU'); - project.addDefine('KORE_WEBGPU'); + addKincDefine('WEBGPU'); } else if (graphics === GraphicsApi.OpenGL || graphics === GraphicsApi.Default) { g4 = true; addBackend('Graphics4/OpenGL'); project.addExclude('Backends/Graphics4/OpenGL/Sources/GL/**'); - project.addDefine('KORE_OPENGL'); - project.addDefine('KORE_OPENGL_ES'); + addKincDefine('OPENGL'); + addKincDefine('OPENGL_ES'); } else { throw new Error('Graphics API ' + graphics + ' is not available for Wasm.'); @@ -344,7 +345,7 @@ else if (platform === Platform.Wasm) { } else if (platform === Platform.Linux || platform === Platform.FreeBSD) { if (platform === Platform.FreeBSD) { // TODO - project.addDefine('KORE_LINUX'); + addKincDefine('LINUX'); } addBackend('System/Linux'); addBackend('System/POSIX'); @@ -431,6 +432,7 @@ else if (platform === Platform.Linux || platform === Platform.FreeBSD) { wl_protocol('unstable/tablet/tablet-unstable-v2.xml', 'wayland-tablet'); wl_protocol('unstable/pointer-constraints/pointer-constraints-unstable-v1.xml', 'wayland-pointer-constraint'); wl_protocol('unstable/relative-pointer/relative-pointer-unstable-v1.xml', 'wayland-relative-pointer'); + wl_protocol('staging/fractional-scale/fractional-scale-v1.xml', 'wayland-fractional-scale'); if (good_wayland) { let cfile = '#include "wayland-protocol.c.h"\n'; @@ -461,14 +463,14 @@ else if (platform === Platform.Linux || platform === Platform.FreeBSD) { g5 = true; addBackend('Graphics5/Vulkan'); project.addLib('vulkan'); - project.addDefine('KORE_VULKAN'); + addKincDefine('VULKAN'); } else if (graphics === GraphicsApi.OpenGL || (platform === Platform.FreeBSD && graphics === GraphicsApi.Default)) { g4 = true; addBackend('Graphics4/OpenGL'); project.addExclude('Backends/Graphics4/OpenGL/Sources/GL/glew.c'); project.addLib('GL'); - project.addDefine('KORE_OPENGL'); + addKincDefine('OPENGL'); project.addLib('EGL'); project.addDefine('KINC_EGL'); } @@ -476,21 +478,21 @@ else if (platform === Platform.Linux || platform === Platform.FreeBSD) { throw new Error('Graphics API ' + graphics + ' is not available for Linux.'); } if (platform === Platform.FreeBSD) { // TODO - project.addDefine('KORE_POSIX'); + addKincDefine('POSIX'); } project.addDefine('_POSIX_C_SOURCE=200112L'); project.addDefine('_XOPEN_SOURCE=600'); } else if (platform === Platform.Pi) { g4 = true; - project.addDefine('KORE_PI'); + addKincDefine('RASPBERRY_PI'); addBackend('System/Pi'); addBackend('System/POSIX'); addBackend('Graphics4/OpenGL'); project.addExclude('Backends/Graphics4/OpenGL/Sources/GL/**'); - project.addDefine('KORE_OPENGL'); - project.addDefine('KORE_OPENGL_ES'); - project.addDefine('KORE_POSIX'); + addKincDefine('OPENGL'); + addKincDefine('OPENGL_ES'); + addKincDefine('POSIX'); project.addDefine('_POSIX_C_SOURCE=200112L'); project.addDefine('_XOPEN_SOURCE=600'); project.addIncludeDir('/opt/vc/include'); @@ -503,17 +505,6 @@ else if (platform === Platform.Pi) { project.addLib('asound'); project.addLib('X11'); } -else if (platform === Platform.Tizen) { - g4 = true; - project.addDefine('KORE_TIZEN'); - addBackend('System/Tizen'); - addBackend('System/POSIX'); - addBackend('Graphics4/OpenGL'); - project.addExclude('Backends/Graphics4/OpenGL/Sources/GL/**'); - project.addDefine('KORE_OPENGL'); - project.addDefine('KORE_OPENGL_ES'); - project.addDefine('KORE_POSIX'); -} else { plugin = true; g4 = true; @@ -521,7 +512,7 @@ else { } if (g4) { - project.addDefine('KORE_G4'); + addKincDefine('G4'); } else { project.addExclude('Sources/Kore/Graphics4/**'); @@ -529,20 +520,20 @@ else { } if (g5) { - project.addDefine('KORE_G5'); - project.addDefine('KORE_G4ONG5'); + addKincDefine('G5'); + addKincDefine('G4ONG5'); addBackend('Graphics4/G4onG5'); } else { - project.addDefine('KORE_G5'); - project.addDefine('KORE_G5ONG4'); + addKincDefine('G5'); + addKincDefine('G5ONG4'); addBackend('Graphics5/G5onG4'); } if (!a3) { if (cpp) { a3 = true; - project.addDefine('KORE_A3'); + addKincDefine('A3'); addBackend('Audio3/A3onA2'); } } @@ -561,13 +552,22 @@ if (plugin) { else if (platform === Platform.Switch) { backend = 'Switch'; } - else if (platform === Platform.XboxScarlett) { + else if (platform === Platform.XboxSeries) { backend = 'Xbox'; } else if (platform === Platform.PS5) { backend = 'PlayStation5' } - const pluginPath = path.join(__dirname, '..', 'Backends', backend); + + let ancestor = project; + while (ancestor.parent != null) { + ancestor = ancestor.parent; + } + + let pluginPath = path.join(ancestor.basedir, 'Backends', backend); + if (!fs.existsSync(pluginPath)) { + pluginPath = path.join(__dirname, '..', 'Backends', backend); + } if (!fs.existsSync(pluginPath)) { log.error('Was looking for a backend in ' + pluginPath + ' but it wasn\'t there.'); throw 'backend not found'; diff --git a/Kinc/license.txt b/Kinc/license.txt index dc3386b..ae08eec 100644 --- a/Kinc/license.txt +++ b/Kinc/license.txt @@ -1,4 +1,4 @@ -Copyright (c) 2017 the Kinc Development Team +Copyright (c) 2025 the Kore Development Team This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/Kinc/make b/Kinc/make index a22011d..9ba7390 100755 --- a/Kinc/make +++ b/Kinc/make @@ -1,7 +1,7 @@ #!/usr/bin/env bash . `dirname "$0"`/Tools/platform.sh -MAKE="`dirname "$0"`/Tools/$KINC_PLATFORM/kmake$KINC_EXE_SUFFIX" +MAKE="`dirname "$0"`/Tools/$KORE_PLATFORM/kmake$KORE_EXE_SUFFIX" if [ -f "$MAKE" ]; then exec $MAKE "$@" diff --git a/Kinc/miniClib/math.c b/Kinc/miniClib/math.c index fe36778..a47319e 100644 --- a/Kinc/miniClib/math.c +++ b/Kinc/miniClib/math.c @@ -1,100 +1,100 @@ -#include "math.h" - -#ifdef KORE_WASM -__attribute__((import_module("imports"), import_name("js_pow"))) float js_pow(float base, float exponent); -__attribute__((import_module("imports"), import_name("js_floor"))) float js_floor(float x); -__attribute__((import_module("imports"), import_name("js_sin"))) float js_sin(float x); -__attribute__((import_module("imports"), import_name("js_cos"))) float js_cos(float x); -__attribute__((import_module("imports"), import_name("js_tan"))) float js_tan(float x); -__attribute__((import_module("imports"), import_name("js_log"))) float js_log(float x); -__attribute__((import_module("imports"), import_name("js_exp"))) float js_exp(float x); -__attribute__((import_module("imports"), import_name("js_sqrt"))) float js_sqrt(float x); -#endif - -double ldexp(double x, int exp) { - return 0.0; -} - -double pow(double base, double exponent) { -#ifdef KORE_WASM - return js_pow(base, exponent); -#endif - return 0.0; -} - -double floor(double x) { -#ifdef KORE_WASM - return js_floor(x); -#endif - return 0.0; -} - -float floorf(float x) { -#ifdef KORE_WASM - return js_floor(x); -#endif - return 0.0f; -} - -double sin(double x) { -#ifdef KORE_WASM - return js_sin(x); -#endif - return 0.0; -} - -float sinf(float x) { -#ifdef KORE_WASM - return js_sin(x); -#endif - return 0.0f; -} - -double cos(double x) { -#ifdef KORE_WASM - return js_cos(x); -#endif - return 0.0; -} - -float cosf(float x) { -#ifdef KORE_WASM - return js_cos(x); -#endif - return 0.0f; -} - -double tan(double x) { -#ifdef KORE_WASM - return js_tan(x); -#endif - return 0.0; -} - -float tanf(float x) { -#ifdef KORE_WASM - return js_tan(x); -#endif - return 0.0f; -} - -double log(double x) { -#ifdef KORE_WASM - return js_log(x); -#endif - return 0.0; -} - -double exp(double x) { -#ifdef KORE_WASM - return js_exp(x); -#endif - return 0.0; -} - -double sqrt(double x) { -#ifdef KORE_WASM - return js_sqrt(x); -#endif - return 0.0; -} +#include "math.h" + +#ifdef KINC_WASM +__attribute__((import_module("imports"), import_name("js_pow"))) float js_pow(float base, float exponent); +__attribute__((import_module("imports"), import_name("js_floor"))) float js_floor(float x); +__attribute__((import_module("imports"), import_name("js_sin"))) float js_sin(float x); +__attribute__((import_module("imports"), import_name("js_cos"))) float js_cos(float x); +__attribute__((import_module("imports"), import_name("js_tan"))) float js_tan(float x); +__attribute__((import_module("imports"), import_name("js_log"))) float js_log(float x); +__attribute__((import_module("imports"), import_name("js_exp"))) float js_exp(float x); +__attribute__((import_module("imports"), import_name("js_sqrt"))) float js_sqrt(float x); +#endif + +double ldexp(double x, int exp) { + return 0.0; +} + +double pow(double base, double exponent) { +#ifdef KINC_WASM + return js_pow(base, exponent); +#endif + return 0.0; +} + +double floor(double x) { +#ifdef KINC_WASM + return js_floor(x); +#endif + return 0.0; +} + +float floorf(float x) { +#ifdef KINC_WASM + return js_floor(x); +#endif + return 0.0f; +} + +double sin(double x) { +#ifdef KINC_WASM + return js_sin(x); +#endif + return 0.0; +} + +float sinf(float x) { +#ifdef KINC_WASM + return js_sin(x); +#endif + return 0.0f; +} + +double cos(double x) { +#ifdef KINC_WASM + return js_cos(x); +#endif + return 0.0; +} + +float cosf(float x) { +#ifdef KINC_WASM + return js_cos(x); +#endif + return 0.0f; +} + +double tan(double x) { +#ifdef KINC_WASM + return js_tan(x); +#endif + return 0.0; +} + +float tanf(float x) { +#ifdef KINC_WASM + return js_tan(x); +#endif + return 0.0f; +} + +double log(double x) { +#ifdef KINC_WASM + return js_log(x); +#endif + return 0.0; +} + +double exp(double x) { +#ifdef KINC_WASM + return js_exp(x); +#endif + return 0.0; +} + +double sqrt(double x) { +#ifdef KINC_WASM + return js_sqrt(x); +#endif + return 0.0; +} diff --git a/Kinc/miniClib/memory.c b/Kinc/miniClib/memory.c index a909917..ee54a10 100644 --- a/Kinc/miniClib/memory.c +++ b/Kinc/miniClib/memory.c @@ -1,6 +1,6 @@ #include "stdlib.h" -#ifdef KORE_WASM +#ifdef KINC_WASM __attribute__((import_module("imports"), import_name("js_fprintf"))) void js_fprintf(const char *format); #define HEAP_SIZE 1024 * 1024 * 8 @@ -8,8 +8,12 @@ static unsigned char heap[HEAP_SIZE]; static size_t heap_top = 4; #endif -void *malloc(size_t size) { -#ifdef KORE_WASM +#ifdef KINC_WASM +__attribute__((export_name("malloc"))) +#endif +void * +malloc(size_t size) { +#ifdef KINC_WASM // Align to 4 bytes to make js typed arrays work if (size % 4 != 0) { size += 4 - size % 4; @@ -32,9 +36,7 @@ void *realloc(void *mem, size_t size) { return NULL; } -void free(void *mem) { - -} +void free(void *mem) {} void *memset(void *ptr, int value, size_t num) { unsigned char *data = (unsigned char *)ptr; diff --git a/Kinc/miniClib/stdio.c b/Kinc/miniClib/stdio.c index f6fc81d..799c5da 100644 --- a/Kinc/miniClib/stdio.c +++ b/Kinc/miniClib/stdio.c @@ -1,62 +1,62 @@ -#include "stdio.h" - -#ifdef KORE_WASM -__attribute__((import_module("imports"), import_name("js_fprintf"))) void js_fprintf(const char *format); -__attribute__((import_module("imports"), import_name("js_fopen"))) FILE *js_fopen(const char *filename); -__attribute__((import_module("imports"), import_name("js_ftell"))) long int js_ftell(FILE *stream); -__attribute__((import_module("imports"), import_name("js_fseek"))) int js_fseek(FILE *stream, long int offset, int origin); -__attribute__((import_module("imports"), import_name("js_fread"))) size_t js_fread(void *ptr, size_t size, size_t count, FILE *stream); -#endif - -FILE *stdout = NULL, *stderr = NULL; - -int fprintf(FILE *stream, const char *format, ...) { -#ifdef KORE_WASM - js_fprintf(format); -#endif - return 0; -} - -int vsnprintf(char *s, size_t n, const char *format, va_list arg) { - return 0; -} - -size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream) { - return 0; -} - -FILE *fopen(const char *filename, const char *mode) { -#ifdef KORE_WASM - return js_fopen(filename); -#endif - return NULL; -} - -int fclose(FILE *stream) { - return 0; -} - -long int ftell(FILE *stream) { -#ifdef KORE_WASM - return js_ftell(stream); -#endif - return 0; -} - -int fseek(FILE *stream, long int offset, int origin) { -#ifdef KORE_WASM - return js_fseek(stream, offset, origin); -#endif - return 0; -} - -size_t fread(void *ptr, size_t size, size_t count, FILE *stream) { -#ifdef KORE_WASM - return js_fread(ptr, size, count, stream); -#endif - return 0; -} - -int fputs(const char *str, FILE *stream) { - return 0; -} +#include "stdio.h" + +#ifdef KINC_WASM +__attribute__((import_module("imports"), import_name("js_fprintf"))) void js_fprintf(const char *format); +__attribute__((import_module("imports"), import_name("js_fopen"))) FILE *js_fopen(const char *filename); +__attribute__((import_module("imports"), import_name("js_ftell"))) long int js_ftell(FILE *stream); +__attribute__((import_module("imports"), import_name("js_fseek"))) int js_fseek(FILE *stream, long int offset, int origin); +__attribute__((import_module("imports"), import_name("js_fread"))) size_t js_fread(void *ptr, size_t size, size_t count, FILE *stream); +#endif + +FILE *stdout = NULL, *stderr = NULL; + +int fprintf(FILE *stream, const char *format, ...) { +#ifdef KINC_WASM + js_fprintf(format); +#endif + return 0; +} + +int vsnprintf(char *s, size_t n, const char *format, va_list arg) { + return 0; +} + +size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream) { + return 0; +} + +FILE *fopen(const char *filename, const char *mode) { +#ifdef KINC_WASM + return js_fopen(filename); +#endif + return NULL; +} + +int fclose(FILE *stream) { + return 0; +} + +long int ftell(FILE *stream) { +#ifdef KINC_WASM + return js_ftell(stream); +#endif + return 0; +} + +int fseek(FILE *stream, long int offset, int origin) { +#ifdef KINC_WASM + return js_fseek(stream, offset, origin); +#endif + return 0; +} + +size_t fread(void *ptr, size_t size, size_t count, FILE *stream) { +#ifdef KINC_WASM + return js_fread(ptr, size, count, stream); +#endif + return 0; +} + +int fputs(const char *str, FILE *stream) { + return 0; +} diff --git a/Kinc/miniClib/stdlib.c b/Kinc/miniClib/stdlib.c index 08a813a..c2fdf4a 100644 --- a/Kinc/miniClib/stdlib.c +++ b/Kinc/miniClib/stdlib.c @@ -1,21 +1,19 @@ -#include "stdlib.h" - -void exit(int code) { - exit(code); -} - -long int strtol(const char *str, char **endptr, int base) { - return 0; -} - -int abs(int n) { - return n < 0 ? -n : n; -} - -long long int llabs(long long int n) { - return n < 0 ? -n : n; -} - -void qsort(void *base, size_t num, size_t size, int (*compar)(const void*,const void*)) { - -} +#include "stdlib.h" + +void exit(int code) { + exit(code); +} + +long int strtol(const char *str, char **endptr, int base) { + return 0; +} + +int abs(int n) { + return n < 0 ? -n : n; +} + +long long int llabs(long long int n) { + return n < 0 ? -n : n; +} + +void qsort(void *base, size_t num, size_t size, int (*compar)(const void *, const void *)) {} diff --git a/Kinc/miniClib/string.c b/Kinc/miniClib/string.c index 16ee1ca..8e7fa91 100644 --- a/Kinc/miniClib/string.c +++ b/Kinc/miniClib/string.c @@ -55,7 +55,7 @@ char *strstr(const char *str1, const char *str2) { } for (size_t i2 = 0;; ++i2) { if (str2[i2] == 0) { - return (char*)&str1[i1]; + return (char *)&str1[i1]; } if (str1[i1 + i2] != str2[i2]) { break; diff --git a/Kinc/readme.md b/Kinc/readme.md index 3143730..8c69e4c 100644 --- a/Kinc/readme.md +++ b/Kinc/readme.md @@ -1,7 +1,12 @@ -## Kinc +## Kore 2 -Kinc projects are built using kmake, a meta-build-tool that resides in -a git-submodule of Kinc. In your project's directory call `path/to/Kinc/make`, +Kore 2 (also known as Kinc aka Kore in C) is a low level toolkit +for cross-platform game engine development and similar endeavors. It is comparable +to SDL but bigger in scope as it also takes care of cross-platform GPU programming +with multiple portable APIs to choose from. + +Kore projects are built using kmake, a meta-build-tool that resides in +a git-submodule of Kore. In your project's directory call `path/to/Kore/make`, this will create a project file for your IDE in a subdirectory called build. kmake by default creates a project for the system you are currently using, but you can also put one of windows, linux, android, windowsapp, osx, ios @@ -10,3 +15,6 @@ Depending on the capabilities of the target system you can also choose your graphics api (-g direct3d9/direct3d11/direct3d12/opengl/vulkan/metal). Console support is implemented via separate plugins because the code can not be provided publicly - contact Robert for details if you are interested in it. + +If you are looking for Kore's original C++-API, go to the [v1-branch](https://github.com/Kode/Kore/tree/v1). +For the very latest things, visit the [v3-branch](https://github.com/Kode/Kore/tree/v3). diff --git a/Kinc/updates.md b/Kinc/updates.md index 0279db5..4599ba6 100644 --- a/Kinc/updates.md +++ b/Kinc/updates.md @@ -1,3 +1,8 @@ +* 2025-02-22: Kinc is now also called Kore 2 (and there is something called Kore 3 as well). +* 2024-02-03: audio2 has been reworked to use a separate buffer for each channel. Also the buffers are typed as float-arrays now - just always write floats and increment write_location by one for each float. +* 2024-01-28: kinc_a2_set_callback/a2_callback has a userdata-parameter now. Set to NULL and ignore if you don't need it. +* 2024-01-17: Compute support was overhauled. It is now part of G4/G5 respectively and reuses most of those APIs. See https://github.com/Kode/Kinc-Samples/commit/c6582219615381177955b4cb8ff0dcc5004e6b97 for an example of how to update. +* 2023-12-16: Dave is at it again and now the gamepad-callbacks also take an additional data-parameter. * 2023-03-23: The socket-API is getting some revisions... * 2023-03-11: The index-buffer-API was revised. It can now lock partially (like the vertex-buffers) and the return-value of locks was changed to void\*. To fix your code, simply append "\_all" to your lock/unlock-calls and maybe add a cast to int\* - or better yet cast to the proper types which will be uint16_t\* or uint32_t\* depending on the format-parameter of your index-buffer. * 2023-02-11: The randomizer now uses xoshiro256** instead of a mermeme-twister. diff --git a/README.md b/README.md index 47e0f58..90f1450 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Leenkx RunT - Runtime for Leenkx Full Stack SDK. -Based on [Krom](https://github.com/Kode/Krom). Powered by [Kinc](https://github.com/Kode/Kinc). +Based on [Krom](https://github.com/Kode/Krom). Powered by [Kore](https://github.com/Kode/Kore). ```bash git clone --recursive https://dev.leenkx.com/LeenkxTeam/LNXRNT @@ -20,14 +20,22 @@ Kinc\make -g direct3d11 **Linux** ```bash -Kinc/make -g opengl --compiler clang --compile +Kore/make -g opengl --compiler clang --compile cd Deployment strip RunT ``` **macOS** ```bash -Kinc/make -g metal +Kore/make -g opengl # Open generated Xcode project at `build/RunT.xcodeproj` # Build ``` + + +**LibreSSL for MacOS** +```bash +git clone https://github.com/jeroen/apple-libressl-sdk.git +cd apple-libressl-sdk +git checkout fce8ffe30c9939fa1d71076745d9b3c811b8a90e +``` \ No newline at end of file diff --git a/Sources/connection_pool.cpp b/Sources/connection_pool.cpp index 8a6a3c1..3823950 100644 --- a/Sources/connection_pool.cpp +++ b/Sources/connection_pool.cpp @@ -11,6 +11,8 @@ #include #include #include +#define INVALID_SOCKET -1 +#define SOCKET_ERROR -1 #endif // global diff --git a/Sources/httprequest.h b/Sources/httprequest.h index 4604c48..e499f59 100644 --- a/Sources/httprequest.h +++ b/Sources/httprequest.h @@ -126,13 +126,13 @@ namespace HttpRequestWrapper { void* ssl_cred_handle_; void* ssl_context_handle_; bool ssl_context_initialized_; - int ssl_socket_; - std::vector ssl_buffer_; #else SSL_CTX* ssl_ctx_; SSL* ssl_; bool ssl_initialized_; #endif + int ssl_socket_; + std::vector ssl_buffer_; bool initSSL(); void cleanupSSL(); bool performSSLHandshake(int socket, const std::string& host); diff --git a/Sources/main.cpp b/Sources/main.cpp index 277ffd8..159ede3 100644 --- a/Sources/main.cpp +++ b/Sources/main.cpp @@ -60,12 +60,12 @@ extern "C" void websocket_run_groupchat_test(int rate, int duration); #include #define STB_IMAGE_IMPLEMENTATION #include -#ifdef KORE_DIRECT3D11 +#ifdef KINC_DIRECT3D11 #include #endif #include -#ifdef KORE_LINUX // xlib defines conflicting with v8 +#ifdef KINC_LINUX // xlib defines conflicting with v8 #undef True #undef False #undef None @@ -74,7 +74,7 @@ extern "C" void websocket_run_groupchat_test(int rate, int duration); #include #include -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS #include // AttachConsole #include #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE @@ -107,7 +107,7 @@ bool show_window = false; using namespace v8; -#ifdef KORE_MACOS +#ifdef KINC_MACOS extern "C" const char *macgetresourcepath(); #endif @@ -165,7 +165,7 @@ namespace { kinc_mutex_t mutex; kinc_a2_buffer_t audio_buffer; int audio_read_location = 0; - void update_audio(kinc_a2_buffer_t *buffer, int samples); + void update_audio(kinc_a2_buffer_t *buffer, uint32_t samples, void *userdata); #endif bool save_and_quit_func_set = false; @@ -192,15 +192,15 @@ namespace { void pen_down(int window, int x, int y, float pressure); void pen_up(int window, int x, int y, float pressure); void pen_move(int window, int x, int y, float pressure); - void gamepad_axis(int gamepad, int axis, float value); - void gamepad_button(int gamepad, int button, float value); + void gamepad_axis(int gamepad, int axis, float value, void *data); + void gamepad_button(int gamepad, int button, float value, void *data); char temp_string[4096]; char temp_string_vs[1024 * 1024]; char temp_string_fs[1024 * 1024]; char temp_string_vstruct[4][32][32]; std::string assetsdir; - #ifdef KORE_WINDOWS + #ifdef KINC_WINDOWS wchar_t temp_wstring[1024]; wchar_t temp_wstring1[1024]; #endif @@ -214,7 +214,7 @@ namespace { void write_stack_trace(const char *stack_trace) { kinc_log(KINC_LOG_LEVEL_INFO, "Trace: %s", stack_trace); - #ifdef KORE_WINDOWS + #ifdef KINC_WINDOWS FILE *file = fopen("stderr.txt", stderr_created ? "a" : "w"); if (file == nullptr) { // Running from protected path strcpy(temp_string, kinc_internal_save_path()); @@ -271,7 +271,7 @@ namespace { win.width = width; win.height = height; win.display_index = -1; - #ifdef KORE_WINDOWS + #ifdef KINC_WINDOWS win.visible = false; // Prevent white flicker when opening the window #else win.visible = enable_window; @@ -288,7 +288,7 @@ namespace { kinc_init(*title, width, height, &win, &frame); kinc_random_init((int)(kinc_time() * 1000)); - #ifdef KORE_WINDOWS + #ifdef KINC_WINDOWS // Maximized window has x < -1, prevent window centering done by kinc if (x < -1 && y < -1) { kinc_window_move(0, x, y); @@ -308,11 +308,14 @@ namespace { kinc_mutex_init(&mutex); kinc_a1_init(); kinc_a2_init(); - kinc_a2_set_callback(update_audio); + kinc_a2_set_callback(update_audio, NULL); audio_buffer.read_location = 0; audio_buffer.write_location = 0; audio_buffer.data_size = 128 * 1024; - audio_buffer.data = new uint8_t[audio_buffer.data_size]; + audio_buffer.channel_count = 2; + for (int i = 0; i < 2; ++i) { + audio_buffer.channels[i] = new float[audio_buffer.data_size]; + } } #endif @@ -340,8 +343,8 @@ namespace { kinc_pen_set_press_callback(pen_down); kinc_pen_set_move_callback(pen_move); kinc_pen_set_release_callback(pen_up); - kinc_gamepad_set_axis_callback(gamepad_axis); - kinc_gamepad_set_button_callback(gamepad_button); + kinc_gamepad_set_axis_callback(gamepad_axis, NULL); + kinc_gamepad_set_button_callback(gamepad_button, NULL); } void runt_set_application_name(const FunctionCallbackInfo &args) { @@ -1138,6 +1141,19 @@ namespace { kinc_log(KINC_LOG_LEVEL_ERROR, stbi_failure_reason()); success = false; } + else { + // Premultiply alpha to match HTML5/HL texture contract + int pixel_count = width * height; + for (int i = 0; i < pixel_count; ++i) { + unsigned char *pixel = output + i * 4; + unsigned char a = pixel[3]; + if (a < 255) { + pixel[0] = (unsigned char)((pixel[0] * a + 127) / 255); + pixel[1] = (unsigned char)((pixel[1] * a + 127) / 255); + pixel[2] = (unsigned char)((pixel[2] * a + 127) / 255); + } + } + } } free(data); return success; @@ -1260,8 +1276,21 @@ namespace { to[i * 2 ] = (float)(left [i] / 32767.0); to[i * 2 + 1] = (float)(right[i] / 32767.0); } - args.GetReturnValue().Set(buffer); + + int sample_rate = sound->samples_per_second; + int channels = sound->channel_count; + double length = (double)sound->size / (double)sample_rate; + kinc_a1_sound_destroy(sound); + + Local templ = ObjectTemplate::New(isolate); + Local obj = templ->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); + + obj->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "buffer").ToLocalChecked(), buffer); + obj->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "sampleRate").ToLocalChecked(), Int32::New(isolate, sample_rate)); + obj->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "channels").ToLocalChecked(), Int32::New(isolate, channels)); + obj->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "length").ToLocalChecked(), Number::New(isolate, length)); + args.GetReturnValue().Set(obj); } void runt_write_audio_buffer(const FunctionCallbackInfo &args) { @@ -1275,15 +1304,19 @@ namespace { float value = values[audio_read_location / 4]; audio_read_location += 4; if (audio_read_location >= content->ByteLength()) audio_read_location = 0; - *(float *)&audio_buffer.data[audio_buffer.write_location] = value; - audio_buffer.write_location += 4; - if (audio_buffer.write_location >= audio_buffer.data_size) audio_buffer.write_location = 0; + int channel = i % audio_buffer.channel_count; + audio_buffer.channels[channel][audio_buffer.write_location] = value; + if (channel == audio_buffer.channel_count - 1) { + audio_buffer.write_location++; + if (audio_buffer.write_location >= audio_buffer.data_size) audio_buffer.write_location = 0; + } } } int runt_get_samples_per_second_fast(Local receiver) { - kinc_log(KINC_LOG_LEVEL_INFO, "Samples per second: %d Hz.", kinc_a2_samples_per_second); - return kinc_a2_samples_per_second; + int rate = kinc_a2_samples_per_second(); + kinc_log(KINC_LOG_LEVEL_INFO, "Samples per second: %d Hz.", rate); + return rate; } void runt_get_samples_per_second(const FunctionCallbackInfo &args) { @@ -1292,12 +1325,14 @@ namespace { } - void update_audio(kinc_a2_buffer_t *buffer, int samples) { + void update_audio(kinc_a2_buffer_t *buffer, uint32_t samples, void *userdata) { if (!isolate || isolate->IsExecutionTerminating()) { // TODO: Re-investigate fill buffer with silence during shutdown for (int i = 0; i < samples; ++i) { - *(float *)&buffer->data[buffer->write_location] = 0.0f; - buffer->write_location += 4; + for (int ch = 0; ch < buffer->channel_count; ++ch) { + buffer->channels[ch][buffer->write_location] = 0.0f; + } + buffer->write_location++; if (buffer->write_location >= buffer->data_size) { buffer->write_location = 0; } @@ -1316,8 +1351,10 @@ namespace { kinc_mutex_unlock(&mutex); // TODO: re-investigate for (int i = 0; i < samples; ++i) { - *(float *)&buffer->data[buffer->write_location] = 0.0f; - buffer->write_location += 4; + for (int ch = 0; ch < buffer->channel_count; ++ch) { + buffer->channels[ch][buffer->write_location] = 0.0f; + } + buffer->write_location++; if (buffer->write_location >= buffer->data_size) { buffer->write_location = 0; } @@ -1332,20 +1369,20 @@ namespace { Local func = Local::New(isolate, audio_func); Local result; const int argc = 1; - Local argv[argc] = {Int32::New(isolate, samples)}; + Local argv[argc] = {Int32::New(isolate, samples * buffer->channel_count)}; if (!func->Call(context, context->Global(), argc, argv).ToLocal(&result)) { handle_exception(&try_catch); } - for (int i = 0; i < samples; ++i) { - float sample = *(float *)&audio_buffer.data[audio_buffer.read_location]; - audio_buffer.read_location += 4; + for (uint32_t i = 0; i < samples; ++i) { + for (int ch = 0; ch < buffer->channel_count; ++ch) { + buffer->channels[ch][buffer->write_location] = audio_buffer.channels[ch][audio_buffer.read_location]; + } + audio_buffer.read_location++; if (audio_buffer.read_location >= audio_buffer.data_size) { audio_buffer.read_location = 0; } - - *(float *)&buffer->data[buffer->write_location] = sample; - buffer->write_location += 4; + buffer->write_location++; if (buffer->write_location >= buffer->data_size) { buffer->write_location = 0; } @@ -1762,7 +1799,7 @@ namespace { void runt_display_is_primary(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); int index = args[0]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(); - #ifdef KORE_LINUX // TODO: Primary display detection broken in Kinc + #ifdef KINC_LINUX // TODO: Primary display detection broken in Kinc args.GetReturnValue().Set(Int32::New(isolate, true)); #else args.GetReturnValue().Set(Int32::New(isolate, index == kinc_primary_display())); @@ -1801,7 +1838,7 @@ namespace { void runt_create_render_target(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); kinc_g4_render_target_t *render_target = (kinc_g4_render_target_t *)malloc(sizeof(kinc_g4_render_target_t)); - kinc_g4_render_target_init(render_target, args[0]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), (kinc_g4_render_target_format_t)args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), args[3]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), args[4]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value()); + kinc_g4_render_target_init(render_target, args[0]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), (kinc_g4_render_target_format_t)args[3]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), args[4]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value()); Local templ = ObjectTemplate::New(isolate); templ->SetInternalFieldCount(1); @@ -1816,7 +1853,7 @@ namespace { void runt_create_render_target_cube_map(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); kinc_g4_render_target_t *render_target = (kinc_g4_render_target_t *)malloc(sizeof(kinc_g4_render_target_t)); - kinc_g4_render_target_init_cube(render_target, args[0]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), (kinc_g4_render_target_format_t)args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), args[3]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value()); + kinc_g4_render_target_init_cube(render_target, args[0]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), (kinc_g4_render_target_format_t)args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(), args[3]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value()); Local templ = ObjectTemplate::New(isolate); templ->SetInternalFieldCount(1); @@ -1983,6 +2020,19 @@ namespace { int comp; image_data = stbi_load_from_memory(content_data, content_length, &image_width, &image_height, &comp, 4); image_format = KINC_IMAGE_FORMAT_RGBA32; + // Premultiply alpha to match HTML5/HL texture contract + if (image_data != nullptr) { + int pixel_count = image_width * image_height; + for (int i = 0; i < pixel_count; ++i) { + unsigned char *pixel = image_data + i * 4; + unsigned char a = pixel[3]; + if (a < 255) { + pixel[0] = (unsigned char)((pixel[0] * a + 127) / 255); + pixel[1] = (unsigned char)((pixel[1] * a + 127) / 255); + pixel[2] = (unsigned char)((pixel[2] * a + 127) / 255); + } + } + } } kinc_image_init(image, image_data, image_width, image_height, image_format); @@ -2219,7 +2269,7 @@ namespace { int byteLength = hasLengthArg ? args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value() : (int)content->ByteLength(); if (byteLength > (int)content->ByteLength()) byteLength = (int)content->ByteLength(); - #ifdef KORE_WINDOWS + #ifdef KINC_WINDOWS MultiByteToWideChar(CP_UTF8, 0, *utf8_path, -1, temp_wstring, 1024); FILE *file = _wfopen(temp_wstring, L"wb"); #else @@ -2231,7 +2281,7 @@ namespace { } int sys_command(const char *cmd) { - #ifdef KORE_WINDOWS + #ifdef KINC_WINDOWS int wlen = MultiByteToWideChar(CP_UTF8, 0, cmd, -1, NULL, 0); wchar_t *wstr = new wchar_t[wlen]; MultiByteToWideChar(CP_UTF8, 0, cmd, -1, wstr, wlen); @@ -2268,11 +2318,11 @@ namespace { void runt_get_files_location(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); - #ifdef KORE_MACOS + #ifdef KINC_MACOS char path[1024]; strcpy(path, macgetresourcepath()); strcat(path, "/"); - strcat(path, KORE_DEBUGDIR); + strcat(path, KINC_DEBUGDIR); strcat(path, "/"); args.GetReturnValue().Set(String::NewFromUtf8(isolate, path).ToLocalChecked()); #else @@ -2281,7 +2331,7 @@ namespace { } void runt_http_callback(int error, int response, const char *body, void *callbackdata) { - #if defined(KORE_MACOS) + #if defined(KINC_MACOS) Locker locker{isolate}; #endif @@ -2337,171 +2387,169 @@ namespace { void runt_set_bool_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local locationfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)locationfield->Value(); + kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)locationfield->Value(); int32_t value = args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(); - kinc_compute_set_bool(*location, value != 0); + kinc_g4_set_bool(*location, value != 0); } void runt_set_int_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local locationfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)locationfield->Value(); + kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)locationfield->Value(); int32_t value = args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(); - kinc_compute_set_int(*location, value); + kinc_g4_set_int(*location, value); } void runt_set_float_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local locationfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)locationfield->Value(); + kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)locationfield->Value(); float value = (float)args[1]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value(); - kinc_compute_set_float(*location, value); + kinc_g4_set_float(*location, value); } void runt_set_float2_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local locationfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)locationfield->Value(); + kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)locationfield->Value(); float value1 = (float)args[1]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value(); float value2 = (float)args[2]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value(); - kinc_compute_set_float2(*location, value1, value2); + kinc_g4_set_float2(*location, value1, value2); } void runt_set_float3_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local locationfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)locationfield->Value(); + kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)locationfield->Value(); float value1 = (float)args[1]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value(); float value2 = (float)args[2]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value(); float value3 = (float)args[3]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value(); - kinc_compute_set_float3(*location, value1, value2, value3); + kinc_g4_set_float3(*location, value1, value2, value3); } void runt_set_float4_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local locationfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)locationfield->Value(); + kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)locationfield->Value(); float value1 = (float)args[1]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value(); float value2 = (float)args[2]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value(); float value3 = (float)args[3]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value(); float value4 = (float)args[4]->ToNumber(isolate->GetCurrentContext()).ToLocalChecked()->Value(); - kinc_compute_set_float4(*location, value1, value2, value3, value4); + kinc_g4_set_float4(*location, value1, value2, value3, value4); } void runt_set_floats_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local locationfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)locationfield->Value(); + kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)locationfield->Value(); Local buffer = Local::Cast(args[1]); std::shared_ptr content = buffer->GetBackingStore(); float *from = (float *)content->Data(); - kinc_compute_set_floats(*location, from, int(content->ByteLength() / 4)); + kinc_g4_set_floats(*location, from, int(content->ByteLength() / 4)); } void runt_set_matrix_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local locationfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)locationfield->Value(); + kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)locationfield->Value(); Local buffer = Local::Cast(args[1]); std::shared_ptr content = buffer->GetBackingStore(); float *from = (float *)content->Data(); - kinc_compute_set_matrix4(*location, (kinc_matrix4x4_t *)from); + kinc_g4_set_matrix4(*location, (kinc_matrix4x4_t *)from); } void runt_set_matrix3_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local locationfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)locationfield->Value(); + kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)locationfield->Value(); Local buffer = Local::Cast(args[1]); std::shared_ptr content = buffer->GetBackingStore(); float *from = (float *)content->Data(); - kinc_compute_set_matrix3(*location, (kinc_matrix3x3_t *)from); + kinc_g4_set_matrix3(*location, (kinc_matrix3x3_t *)from); } void runt_set_texture_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local unitfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_texture_unit_t *unit = (kinc_compute_texture_unit_t *)unitfield->Value(); + kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)unitfield->Value(); Local texfield = Local::Cast(args[1]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); kinc_g4_texture_t *texture = (kinc_g4_texture_t *)texfield->Value(); - int access = args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust(); - kinc_compute_set_texture(*unit, texture, (kinc_compute_access_t)access); + kinc_g4_set_texture(*unit, texture); } void runt_set_render_target_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local unitfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_texture_unit_t *unit = (kinc_compute_texture_unit_t *)unitfield->Value(); + kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)unitfield->Value(); Local rtfield = Local::Cast(args[1]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); kinc_g4_render_target_t *render_target = (kinc_g4_render_target_t *)rtfield->Value(); - int access = args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust(); - kinc_compute_set_render_target(*unit, render_target, (kinc_compute_access_t)access); + kinc_g4_render_target_use_color_as_texture(render_target, *unit); } void runt_set_sampled_texture_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local unitfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_texture_unit_t *unit = (kinc_compute_texture_unit_t *)unitfield->Value(); + kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)unitfield->Value(); Local texfield = Local::Cast(args[1]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); kinc_g4_texture_t *texture = (kinc_g4_texture_t *)texfield->Value(); - kinc_compute_set_sampled_texture(*unit, texture); + kinc_g4_set_texture(*unit, texture); } void runt_set_sampled_render_target_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local unitfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_texture_unit_t *unit = (kinc_compute_texture_unit_t *)unitfield->Value(); + kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)unitfield->Value(); Local rtfield = Local::Cast(args[1]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); kinc_g4_render_target_t *render_target = (kinc_g4_render_target_t *)rtfield->Value(); - kinc_compute_set_sampled_render_target(*unit, render_target); + kinc_g4_render_target_use_color_as_texture(render_target, *unit); } void runt_set_sampled_depth_texture_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local unitfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_texture_unit_t *unit = (kinc_compute_texture_unit_t *)unitfield->Value(); + kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)unitfield->Value(); Local rtfield = Local::Cast(args[1]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); kinc_g4_render_target_t *render_target = (kinc_g4_render_target_t *)rtfield->Value(); - kinc_compute_set_sampled_depth_from_render_target(*unit, render_target); + kinc_g4_render_target_use_depth_as_texture(render_target, *unit); } void runt_set_texture_parameters_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local unitfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_texture_unit_t *unit = (kinc_compute_texture_unit_t *)unitfield->Value(); - kinc_compute_set_texture_addressing(*unit, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); - kinc_compute_set_texture_addressing(*unit, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); - kinc_compute_set_texture_minification_filter(*unit, (kinc_g4_texture_filter_t)args[3]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); - kinc_compute_set_texture_magnification_filter(*unit, (kinc_g4_texture_filter_t)args[4]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); - kinc_compute_set_texture_mipmap_filter(*unit, (kinc_g4_mipmap_filter_t)args[5]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)unitfield->Value(); + kinc_g4_set_texture_addressing(*unit, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_set_texture_addressing(*unit, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_set_texture_minification_filter(*unit, (kinc_g4_texture_filter_t)args[3]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_set_texture_magnification_filter(*unit, (kinc_g4_texture_filter_t)args[4]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_set_texture_mipmap_filter(*unit, (kinc_g4_mipmap_filter_t)args[5]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); } void runt_set_texture3d_parameters_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local unitfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_texture_unit_t *unit = (kinc_compute_texture_unit_t *)unitfield->Value(); - kinc_compute_set_texture3d_addressing(*unit, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); - kinc_compute_set_texture3d_addressing(*unit, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); - kinc_compute_set_texture3d_addressing(*unit, KINC_G4_TEXTURE_DIRECTION_W, (kinc_g4_texture_addressing_t)args[3]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); - kinc_compute_set_texture3d_minification_filter(*unit, (kinc_g4_texture_filter_t)args[4]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); - kinc_compute_set_texture3d_magnification_filter(*unit, (kinc_g4_texture_filter_t)args[5]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); - kinc_compute_set_texture3d_mipmap_filter(*unit, (kinc_g4_mipmap_filter_t)args[6]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)unitfield->Value(); + kinc_g4_set_texture3d_addressing(*unit, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_set_texture3d_addressing(*unit, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_set_texture3d_addressing(*unit, KINC_G4_TEXTURE_DIRECTION_W, (kinc_g4_texture_addressing_t)args[3]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_set_texture3d_minification_filter(*unit, (kinc_g4_texture_filter_t)args[4]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_set_texture3d_magnification_filter(*unit, (kinc_g4_texture_filter_t)args[5]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); + kinc_g4_set_texture3d_mipmap_filter(*unit, (kinc_g4_mipmap_filter_t)args[6]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).FromJust()); } void runt_set_shader_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local shaderfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_shader *shader = (kinc_compute_shader *)shaderfield->Value(); - kinc_compute_set_shader(shader); + kinc_g4_compute_shader *shader = (kinc_g4_compute_shader *)shaderfield->Value(); + kinc_g4_set_compute_shader(shader); } void runt_create_shader_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local buffer = Local::Cast(args[0]); std::shared_ptr content = buffer->GetBackingStore(); - kinc_compute_shader *shader = (kinc_compute_shader *)malloc(sizeof(kinc_compute_shader)); - kinc_compute_shader_init(shader, content->Data(), (int)content->ByteLength()); + kinc_g4_compute_shader *shader = (kinc_g4_compute_shader *)malloc(sizeof(kinc_g4_compute_shader)); + kinc_g4_compute_shader_init(shader, content->Data(), (int)content->ByteLength()); Local templ = ObjectTemplate::New(isolate); templ->SetInternalFieldCount(1); @@ -2515,25 +2563,25 @@ namespace { HandleScope scope(args.GetIsolate()); Local shaderobj = args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked(); Local shaderfield = Local::Cast(shaderobj->GetInternalField(0)); - kinc_compute_shader *shader = (kinc_compute_shader *)shaderfield->Value(); - kinc_compute_shader_destroy(shader); + kinc_g4_compute_shader *shader = (kinc_g4_compute_shader *)shaderfield->Value(); + kinc_g4_compute_shader_destroy(shader); free(shader); } void runt_get_constant_location_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local shaderfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_shader *shader = (kinc_compute_shader *)shaderfield->Value(); + kinc_g4_compute_shader *shader = (kinc_g4_compute_shader *)shaderfield->Value(); String::Utf8Value utf8_value(isolate, args[1]); - kinc_compute_constant_location_t location = kinc_compute_shader_get_constant_location(shader, *utf8_value); + kinc_g4_constant_location_t location = kinc_g4_compute_shader_get_constant_location(shader, *utf8_value); Local templ = ObjectTemplate::New(isolate); templ->SetInternalFieldCount(1); Local obj = templ->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); - kinc_compute_constant_location_t *location_copy = (kinc_compute_constant_location_t *)malloc(sizeof(kinc_compute_constant_location_t)); // TODO - memcpy(location_copy, &location, sizeof(kinc_compute_constant_location_t)); + kinc_g4_constant_location_t *location_copy = (kinc_g4_constant_location_t *)malloc(sizeof(kinc_g4_constant_location_t)); // TODO + memcpy(location_copy, &location, sizeof(kinc_g4_constant_location_t)); obj->SetInternalField(0, External::New(isolate, location_copy)); args.GetReturnValue().Set(obj); } @@ -2541,17 +2589,17 @@ namespace { void runt_get_texture_unit_compute(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); Local shaderfield = Local::Cast(args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked()->GetInternalField(0)); - kinc_compute_shader *shader = (kinc_compute_shader *)shaderfield->Value(); + kinc_g4_compute_shader *shader = (kinc_g4_compute_shader *)shaderfield->Value(); String::Utf8Value utf8_value(isolate, args[1]); - kinc_compute_texture_unit_t unit = kinc_compute_shader_get_texture_unit(shader, *utf8_value); + kinc_g4_texture_unit_t unit = kinc_g4_compute_shader_get_texture_unit(shader, *utf8_value); Local templ = ObjectTemplate::New(isolate); templ->SetInternalFieldCount(1); Local obj = templ->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); - kinc_compute_texture_unit_t *unit_copy = (kinc_compute_texture_unit_t *)malloc(sizeof(kinc_compute_texture_unit_t)); // TODO - memcpy(unit_copy, &unit, sizeof(kinc_compute_texture_unit_t)); + kinc_g4_texture_unit_t *unit_copy = (kinc_g4_texture_unit_t *)malloc(sizeof(kinc_g4_texture_unit_t)); // TODO + memcpy(unit_copy, &unit, sizeof(kinc_g4_texture_unit_t)); obj->SetInternalField(0, External::New(isolate, unit_copy)); args.GetReturnValue().Set(obj); } @@ -2561,7 +2609,7 @@ namespace { int x = args[0]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(); int y = args[1]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(); int z = args[2]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(); - kinc_compute(x, y, z); + kinc_g4_compute(x, y, z); } #endif @@ -2582,7 +2630,7 @@ namespace { HandleScope scope(args.GetIsolate()); int id = args[0]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(); kinc_mouse_set_cursor(id); - #ifdef KORE_WINDOWS + #ifdef KINC_WINDOWS // Set hand icon for drag even when mouse button is pressed if (id == 1) SetCursor(LoadCursor(NULL, IDC_HAND)); #endif @@ -2613,7 +2661,7 @@ namespace { void runt_delete_file(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); String::Utf8Value utf8_value(isolate, args[0]); - #if defined(KORE_WINDOWS) + #if defined(KINC_WINDOWS) char path[1024]; strcpy(path, "del /f \""); strcat(path, *utf8_value); @@ -2660,7 +2708,7 @@ namespace { void runt_window_set_foreground(const FunctionCallbackInfo &args) { HandleScope scope(args.GetIsolate()); int windowId = args[0]->ToInt32(isolate->GetCurrentContext()).ToLocalChecked()->Value(); - kinc_window_set_foreground(windowId); + // kinc_window_set_foreground(windowId); // TODO: add to Kore } #define SET_FUNCTION_FAST(object, name, fn)\ @@ -3065,7 +3113,7 @@ namespace { } void update(void *data) { - #ifdef KORE_WINDOWS + #ifdef KINC_WINDOWS if (show_window && enable_window) { show_window = false; @@ -3155,7 +3203,7 @@ namespace { void drop_files(wchar_t *file_path, void *data) { // Update mouse position - #ifdef KORE_WINDOWS + #ifdef KINC_WINDOWS POINT p; GetCursorPos(&p); ScreenToClient(kinc_windows_window_handle(0), &p); @@ -3579,7 +3627,7 @@ namespace { } } - void gamepad_axis(int gamepad, int axis, float value) { + void gamepad_axis(int gamepad, int axis, float value, void *data) { Locker locker{isolate}; Isolate::Scope isolate_scope(isolate); @@ -3597,7 +3645,7 @@ namespace { } } - void gamepad_button(int gamepad, int button, float value) { + void gamepad_button(int gamepad, int button, float value, void *data) { Locker locker{isolate}; Isolate::Scope isolate_scope(isolate); @@ -3746,14 +3794,14 @@ int kickstart(int argc, char **argv) { _argv = argv; std::string bindir(argv[0]); -#ifdef KORE_WINDOWS // Handle non-ascii path +#ifdef KINC_WINDOWS // Handle non-ascii path HMODULE hModule = GetModuleHandleW(NULL); GetModuleFileNameW(hModule, temp_wstring, 1024); WideCharToMultiByte(CP_UTF8, 0, temp_wstring, -1, temp_string, 4096, nullptr, nullptr); bindir = temp_string; #endif -#ifdef KORE_WINDOWS +#ifdef KINC_WINDOWS bindir = bindir.substr(0, bindir.find_last_of("\\")); #else bindir = bindir.substr(0, bindir.find_last_of("/")); @@ -3806,7 +3854,7 @@ int kickstart(int argc, char **argv) { snapshot = true; } else if (read_console_pid) { - #ifdef KORE_WINDOWS + #ifdef KINC_WINDOWS AttachConsole(atoi(argv[i])); #endif read_console_pid = false; @@ -3853,11 +3901,11 @@ int kickstart(int argc, char **argv) { //#endif } -#if !defined(KORE_MACOS) +#if !defined(KINC_MACOS) kinc_internal_set_files_location(&assetsdir[0u]); #endif -#ifdef KORE_MACOS +#ifdef KINC_MACOS // Handle loading assets located outside of '.app/Contents/Resources/Deployment' folder // when assets and shaders dir is passed as an argument if (argc > 2) { diff --git a/Sources/socket_bridge.cpp b/Sources/socket_bridge.cpp index b7f38f8..bb1a9ad 100644 --- a/Sources/socket_bridge.cpp +++ b/Sources/socket_bridge.cpp @@ -24,6 +24,7 @@ #else #include #include +#include #include #include #include diff --git a/Sources/socket_optimization.h b/Sources/socket_optimization.h index ea68e28..f20f92b 100644 --- a/Sources/socket_optimization.h +++ b/Sources/socket_optimization.h @@ -41,8 +41,8 @@ namespace SocketOptimization { // disable Nagle int tcp_quickack = 1; - #ifndef _WIN32 - setsockopt(socket_fd, IPPROTO_TCP, TCP_QUICKACK, + #ifdef __linux__ + setsockopt(socket_fd, IPPROTO_TCP, TCP_QUICKACK, (const char*)&tcp_quickack, sizeof(tcp_quickack)); #endif @@ -63,8 +63,12 @@ namespace SocketOptimization { int keepidle = 30; // start probes after 30 seconds int keepintvl = 5; // probe every 5 seconds int keepcnt = 3; // 3 failed probes before timeout - + + #ifdef __linux__ setsockopt(socket_fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepidle, sizeof(keepidle)); + #elif defined(__APPLE__) + setsockopt(socket_fd, IPPROTO_TCP, TCP_KEEPALIVE, &keepidle, sizeof(keepidle)); + #endif setsockopt(socket_fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepintvl, sizeof(keepintvl)); setsockopt(socket_fd, IPPROTO_TCP, TCP_KEEPCNT, &keepcnt, sizeof(keepcnt)); #endif diff --git a/Sources/sse2neon.h b/Sources/sse2neon.h new file mode 100644 index 0000000..16ef2f8 --- /dev/null +++ b/Sources/sse2neon.h @@ -0,0 +1,11744 @@ +#ifndef SSE2NEON_H +#define SSE2NEON_H + +/* + * sse2neon is freely redistributable under the MIT License. + * + * Copyright (c) 2015-2026 SSE2NEON Contributors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// This header file provides a simple API translation layer +// between SSE intrinsics to their corresponding Arm/Aarch64 NEON versions +// +// Contributors to this work are: +// John W. Ratcliff +// Brandon Rowlett +// Ken Fast +// Eric van Beurden +// Alexander Potylitsin +// Hasindu Gamaarachchi +// Jim Huang +// Mark Cheng +// Malcolm James MacLeod +// Devin Hussey (easyaspi314) +// Sebastian Pop +// Developer Ecosystem Engineering +// Danila Kutenin +// François Turban (JishinMaster) +// Pei-Hsuan Hung +// Yang-Hao Yuan +// Syoyo Fujita +// Brecht Van Lommel +// Jonathan Hue +// Cuda Chen +// Aymen Qader +// Anthony Roberts +// Sean Luchen +// Marcin Serwin +// Ben Niu +// Even Rouault +// Marcus Buretorp + +/* Tunable configurations */ + +/* PRECISION FLAGS + * + * These flags control the precision/performance trade-off for operations where + * NEON behavior diverges from x86 SSE. Default is 0 (performance over + * precision). Set to 1 before including this header for x86-compatible + * behavior. + * + * Example: + * #define SSE2NEON_PRECISE_MINMAX 1 // Enable before include + * #include "sse2neon.h" + * + * Recommended configurations: + * - Performance: No flags (default) + * - Balanced: SSE2NEON_PRECISE_MINMAX=1, SSE2NEON_PRECISE_SQRT=1 + * (ARMv7: also consider SSE2NEON_PRECISE_DIV=1 for division) + * - Exact: All flags set to 1 + */ + +/* SSE2NEON_PRECISE_MINMAX + * Affects: _mm_min_ps, _mm_max_ps, _mm_min_ss, _mm_max_ss, + * _mm_min_pd, _mm_max_pd, _mm_min_sd, _mm_max_sd + * + * Issue: NEON fmin/fmax propagate NaN differently than SSE. When one operand + * is NaN, SSE returns the second operand while NEON may return NaN. + * + * Default (0): Fast NEON min/max, potential NaN divergence + * Enabled (1): Additional comparison to match x86 NaN handling + * + * Symptoms when disabled: NaN "holes" in rendered images, unexpected NaN + * propagation in signal processing + */ +#ifndef SSE2NEON_PRECISE_MINMAX +#define SSE2NEON_PRECISE_MINMAX (0) +#endif + +/* SSE2NEON_PRECISE_DIV + * Affects: _mm_rcp_ps, _mm_rcp_ss (all architectures) + * _mm_div_ps, _mm_div_ss (ARMv7 only, ARMv8 uses native vdivq_f32) + * + * Issue: NEON reciprocal estimate (vrecpe) has ~11-bit precision. SSE's rcpps + * provides ~12-bit precision. For division on ARMv7, we use reciprocal + * approximation since there's no native divide instruction. + * + * Default (0): Single Newton-Raphson refinement (~12-bit precision) + * Enabled (1): Two N-R refinements (~24-bit precision) + * + * Note on reciprocals: Enabling this flag makes _mm_rcp_ps MORE accurate than + * SSE's specified ~12-bit precision. This improves ARMv7 division accuracy but + * may differ from code expecting SSE's coarser reciprocal approximation. + * + * WARNING: This flag improves numerical precision only. It does NOT fix + * IEEE-754 corner-case divergence (NaN propagation, signed zero, infinity + * handling). ARMv7 division behavior will still differ from x86 SSE for these + * edge cases. + * + * Symptoms when disabled: Slight precision differences in division-heavy code + */ +#ifndef SSE2NEON_PRECISE_DIV +#define SSE2NEON_PRECISE_DIV (0) +#endif + +/* SSE2NEON_PRECISE_SQRT + * Affects: _mm_sqrt_ps, _mm_sqrt_ss, _mm_rsqrt_ps, _mm_rsqrt_ss + * + * Issue: NEON reciprocal square root estimate (vrsqrte) has lower precision + * than x86 SSE's rsqrtps/sqrtps. + * + * Default (0): Single Newton-Raphson refinement + * Enabled (1): Two N-R refinements for improved precision + * + * Symptoms when disabled: Precision loss in physics simulations, graphics + * normalization, or iterative algorithms + */ +#ifndef SSE2NEON_PRECISE_SQRT +#define SSE2NEON_PRECISE_SQRT (0) +#endif + +/* SSE2NEON_PRECISE_DP + * Affects: _mm_dp_ps, _mm_dp_pd + * + * Issue: The dot product mask parameter controls which elements participate. + * When an element is masked out, x86 multiplies by 0.0 while NEON + * skips the multiply entirely. + * + * Default (0): Skip masked elements (faster, but 0.0 * NaN = NaN divergence) + * Enabled (1): Multiply masked elements by 0.0 (matches x86 NaN propagation) + * + * Symptoms when disabled: Different results when dot product inputs contain + * NaN in masked-out lanes + */ +#ifndef SSE2NEON_PRECISE_DP +#define SSE2NEON_PRECISE_DP (0) +#endif + +/* SSE2NEON_UNDEFINED_ZERO + * Affects: _mm_undefined_ps, _mm_undefined_si128, _mm_undefined_pd + * + * Issue: These intrinsics return vectors with "undefined" contents per Intel + * spec. On x86, this means truly uninitialized memory (garbage values). + * + * MSVC Semantic Drift: MSVC on ARM forces zero-initialization for these + * intrinsics, which differs from x86 behavior where garbage is returned. + * GCC/Clang on ARM match x86 by returning uninitialized memory. + * + * This macro provides explicit control over the behavior: + * Default (0): Compiler-dependent (MSVC=zero, GCC/Clang=undefined) + * Enabled (1): Force zero-initialization on all compilers (safer, portable) + * + * When to enable: + * - Deterministic behavior across compilers is required + * - Debugging memory-related issues where undefined values cause problems + * - Security-sensitive code where uninitialized memory is a concern + * + * Note: Using undefined values without first writing to them is undefined + * behavior. Well-formed code should not depend on either behavior. + */ +#ifndef SSE2NEON_UNDEFINED_ZERO +#define SSE2NEON_UNDEFINED_ZERO (0) +#endif + +/* SSE2NEON_MWAIT_POLICY + * Affects: _mm_mwait + * + * Issue: x86 MONITOR/MWAIT allows a thread to sleep until a write occurs to a + * monitored address range. ARM has no userspace equivalent for address- + * range monitoring. _mm_monitor is a no-op; _mm_mwait can only provide + * low-power wait hints without true "wake on store" semantics. + * + * Note: The x86 extensions/hints parameters (C-state hints) are ignored on ARM + * as there is no architectural equivalent. No memory ordering is provided + * beyond what the hint instruction itself offers. + * + * WARNING: Policies 1 and 2 (WFE/WFI) may cause issues: + * - WFE: May sleep until event/interrupt; can wake spuriously. Always check + * your condition in a loop. May trap in EL0 (SCTLR_EL1.nTWE). + * - WFI: May trap (SIGILL) in EL0 on Linux, iOS, macOS (SCTLR_EL1.nTWI). + * - Neither provides "wake on address write" semantics. + * + * Policy values: + * 0 (default): yield - Safe everywhere, never blocks, just a hint + * 1: wfe - Event wait, may sleep until event/interrupt + * 2: wfi - Interrupt wait, may trap in EL0 on many platforms + * + * Recommended usage: + * - Policy 0: General-purpose code, spin-wait loops (safe default) + * - Policy 1: Only if you control both reader/writer and use SEV/SEVL + * - Policy 2: Only for bare-metal or kernel code with known OS support + * + * Migration note: Code relying on x86 MONITOR/MWAIT for lock-free waiting + * should migrate to proper atomics + OS wait primitives (futex, condition + * variables) for correct cross-platform behavior. + */ +#ifndef SSE2NEON_MWAIT_POLICY +#define SSE2NEON_MWAIT_POLICY (0) +#endif + +/* Enable inclusion of windows.h on MSVC platforms + * This makes _mm_clflush functional on windows, as there is no builtin. + */ +#ifndef SSE2NEON_INCLUDE_WINDOWS_H +#define SSE2NEON_INCLUDE_WINDOWS_H (0) +#endif + +/* Consolidated Platform Detection + * + * These macros simplify platform-specific code throughout the header by + * providing single-point definitions for architecture and compiler detection. + * This reduces the 147+ verbose architecture checks to simple macro usage. + * + * Architecture: + * SSE2NEON_ARCH_AARCH64 - 64-bit ARM (AArch64, including Apple Silicon) + * Encompasses: __aarch64__, __arm64__, _M_ARM64, _M_ARM64EC + * + * Compiler: + * SSE2NEON_COMPILER_GCC_COMPAT - GCC or Clang (supports GNU extensions) + * SSE2NEON_COMPILER_MSVC - Microsoft Visual C++ + * SSE2NEON_COMPILER_CLANG - Clang specifically (subset of GCC_COMPAT) + */ + +/* Compiler detection + * + * Check Clang first: it defines __GNUC__ for compatibility. + * Clang-CL also defines _MSC_VER for MSVC ABI compatibility. + * + * Compiler matrix: + * Compiler | GCC_COMPAT | CLANG | MSVC + * -----------+------------+-------+------ + * GCC | 1 | 0 | 0 + * Clang | 1 | 1 | 0 + * Clang-CL | 1 | 1 | 1 + * MSVC | 0 | 0 | 1 + */ +#if defined(__clang__) +/* Clang compiler detected (including Apple Clang) */ +#define SSE2NEON_COMPILER_CLANG 1 +#define SSE2NEON_COMPILER_GCC_COMPAT 1 /* Clang supports GCC extensions */ +#if defined(_MSC_VER) +#define SSE2NEON_COMPILER_MSVC 1 /* Clang-CL: Clang with MSVC on Windows */ +#else +#define SSE2NEON_COMPILER_MSVC 0 +#endif +/* Clang < 11 has known NEON codegen bugs (issue #622) */ +#if __clang_major__ < 11 +#error "Clang versions earlier than 11 are not supported." +#endif + +#elif defined(__GNUC__) +/* GCC compiler (only reached if not Clang, since Clang also defines __GNUC__) + */ +#define SSE2NEON_COMPILER_CLANG 0 +#define SSE2NEON_COMPILER_GCC_COMPAT 1 +#define SSE2NEON_COMPILER_MSVC 0 +/* GCC < 10 has incomplete ARM intrinsics support */ +#if __GNUC__ < 10 +#error "GCC versions earlier than 10 are not supported." +#endif + +#elif defined(_MSC_VER) +/* Microsoft Visual C++ (native, not Clang-CL) */ +#define SSE2NEON_COMPILER_CLANG 0 +#define SSE2NEON_COMPILER_GCC_COMPAT 0 /* No GCC extensions available */ +#define SSE2NEON_COMPILER_MSVC 1 + +#else +#error "Unsupported compiler. SSE2NEON requires GCC 10+, Clang 11+, or MSVC." +#endif + +/* Architecture detection */ +#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || \ + defined(_M_ARM64EC) +#define SSE2NEON_ARCH_AARCH64 1 +#else +#define SSE2NEON_ARCH_AARCH64 0 +#endif + +/* ARM64EC Support - EXPERIMENTAL with known limitations + * + * ARM64EC is Microsoft's hybrid ABI bridging x64 and ARM64 within a single + * Windows process, enabling incremental migration of x64 applications to ARM64. + * Compiler support remains incomplete (limited LLVM/GCC coverage). + * + * Compiler behavior: + * - MSVC defines both _M_AMD64 and _M_ARM64EC (but NOT _M_ARM64) + * - Requires arm64_neon.h instead of arm_neon.h + * + * Known limitations: + * 1. Windows headers: SSE2NEON_INCLUDE_WINDOWS_H must be 0 (default). + * Include sse2neon.h BEFORE any Windows headers to avoid type conflicts. + * 2. Include order: sse2neon.h must be included BEFORE or any C++ + * standard headers that pull it in (e.g., , ). + * 3. ABI boundary: __m128/SSE types must NOT cross x64/ARM64EC module + * boundaries (exports/imports) as layouts differ between ABIs. + * Users needing cross-ABI SIMD interop should use MSVC's softintrin. + * 4. CRC32 hardware intrinsics are disabled; software fallback is used. + * + * SSE2NEON_ARM64EC is 1 when compiling for ARM64EC with MSVC, 0 otherwise. + * Note: clang-cl ARM64EC builds are not currently detected by this macro. + * + * Recommendation: Use native ARM64 compilation when possible. + */ +#if SSE2NEON_COMPILER_MSVC && defined(_M_ARM64EC) +#define SSE2NEON_ARM64EC 1 +#else +#define SSE2NEON_ARM64EC 0 +#endif + +/* Early ARM64EC + SSE2NEON_INCLUDE_WINDOWS_H check. + * This must come BEFORE any standard includes because and other + * headers can trigger winnt.h, which fails with "Must define a target + * architecture" on ARM64EC before we could emit our own error. + */ +#if SSE2NEON_ARM64EC && SSE2NEON_INCLUDE_WINDOWS_H +#error \ + "SSE2NEON_INCLUDE_WINDOWS_H=1 is not supported on ARM64EC. " \ + "Include separately AFTER sse2neon.h instead." +#endif + +/* Endianness check + * + * SSE2NEON assumes little-endian byte ordering for lane-to-memory mappings. + * Big-endian ARM targets would produce silently incorrect results because + * SSE intrinsics define lane ordering relative to little-endian memory layout. + * + * GCC/Clang define __BYTE_ORDER__. For compilers that don't (e.g., MSVC), + * we check for explicit big-endian ARM macros. MSVC only targets little-endian + * ARM, so no additional check is needed there. + */ +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__) +#error "sse2neon requires little-endian target; big-endian is not supported" +#elif defined(__ARMEB__) || defined(__AARCH64EB__) || defined(__BIG_ENDIAN__) +#error "sse2neon requires little-endian target; big-endian is not supported" +#endif + +/* compiler specific definitions */ +#if SSE2NEON_COMPILER_GCC_COMPAT +#pragma push_macro("FORCE_INLINE") +#pragma push_macro("ALIGN_STRUCT") +#define FORCE_INLINE static inline __attribute__((always_inline)) +#define ALIGN_STRUCT(x) __attribute__((aligned(x))) +#define _sse2neon_likely(x) __builtin_expect(!!(x), 1) +#define _sse2neon_unlikely(x) __builtin_expect(!!(x), 0) +#elif SSE2NEON_COMPILER_MSVC +#if _MSVC_TRADITIONAL +#error Using the traditional MSVC preprocessor is not supported! Use /Zc:preprocessor instead. +#endif +#ifndef FORCE_INLINE +#define FORCE_INLINE static inline +#endif +#ifndef ALIGN_STRUCT +#define ALIGN_STRUCT(x) __declspec(align(x)) +#endif +#define _sse2neon_likely(x) (x) +#define _sse2neon_unlikely(x) (x) +#endif + +/* C language does not allow initializing a variable with a function call. */ +#ifdef __cplusplus +#define _sse2neon_const static const +#else +#define _sse2neon_const const +#endif + +#if defined(__cplusplus) +#define _sse2neon_reinterpret_cast(t, e) reinterpret_cast(e) +#define _sse2neon_static_cast(t, e) static_cast(e) +#define _sse2neon_const_cast(t, e) const_cast(e) +#else +#define _sse2neon_reinterpret_cast(t, e) ((t) (e)) +#define _sse2neon_static_cast(t, e) ((t) (e)) +#define _sse2neon_const_cast(t, e) ((t) (e)) +#endif + +/* ARM64EC winnt.h workaround: define architecture macros before any headers + * that might include winnt.h. Windows SDK 10.0.26100.0+ requires _ARM64EC_ or + * _ARM64_ but MSVC 17.x only defines _M_ARM64EC. + */ +#if SSE2NEON_ARM64EC +/* Warn if winnt.h was already included - the workaround won't help */ +#ifdef _WINNT_ +#pragma message( \ + "warning: sse2neon.h included after winnt.h; ARM64EC workaround may fail") +#endif +/* Define _ARM64EC_ for winnt.h architecture check (kept for user detection) */ +#if !defined(_ARM64EC_) +#define _ARM64EC_ 1 +#define _SSE2NEON_DEFINED_ARM64EC_ +#endif +/* Define _M_ARM64 temporarily for headers that derive _ARM64_ from it */ +#if !defined(_M_ARM64) +#define _M_ARM64 1 +#define _SSE2NEON_DEFINED_M_ARM64 +#endif +#endif /* SSE2NEON_ARM64EC */ + +#include +#include +#include +#include + +FORCE_INLINE double sse2neon_recast_u64_f64(uint64_t val) +{ + double tmp; + memcpy(&tmp, &val, sizeof(uint64_t)); + return tmp; +} + +FORCE_INLINE int64_t sse2neon_recast_f64_s64(double val) +{ + int64_t tmp; + memcpy(&tmp, &val, sizeof(uint64_t)); + return tmp; +} + +/* MSVC provides _mm_{malloc,free} in ; MinGW needs our definitions + * but still uses _aligned_malloc/_aligned_free from . + */ +#if SSE2NEON_COMPILER_MSVC +#define SSE2NEON_ALLOC_DEFINED +#endif + +/* If using MSVC */ +#if SSE2NEON_COMPILER_MSVC + +/* ARM64EC SSE header blocking: pre-define include guards to prevent MSVC SSE + * headers (mmintrin.h, xmmintrin.h, etc.) and Windows SDK softintrin.h from + * loading, as their __m128 union types conflict with sse2neon's NEON types. + */ +#if SSE2NEON_ARM64EC || defined(_M_ARM64EC) +/* Detect if was already included - SSE types may have leaked. + * Check both _INTRIN_H_ and _INTRIN_H to cover different MSVC versions. */ +#if defined(_INTRIN_H_) || defined(_INTRIN_H) +#error \ + "sse2neon.h must be included BEFORE or C++ headers on ARM64EC. " \ + "SSE type definitions from conflict with sse2neon's NEON types." +#endif +#define _INCLUDED_MM2 +#define _MMINTRIN_H_INCLUDED +#define _XMMINTRIN_H_INCLUDED +#define _EMMINTRIN_H_INCLUDED +#define _PMMINTRIN_H_INCLUDED +#define _TMMINTRIN_H_INCLUDED +#define _SMMINTRIN_H_INCLUDED +#define _NMMINTRIN_H_INCLUDED +#define _WMMINTRIN_H_INCLUDED +#define _IMMINTRIN_H_INCLUDED +#define _ZMMINTRIN_H_INCLUDED +#define _AMMINTRIN_H_INCLUDED +/* Block Windows SDK softintrin */ +#define _SOFTINTRIN_H_ +#define _DISABLE_SOFTINTRIN_ 1 +#endif /* SSE2NEON_ARM64EC */ +#include + +/* Windows headers inclusion. + * ARM64EC case is blocked by early check near SSE2NEON_ARM64EC definition. + */ +#if SSE2NEON_INCLUDE_WINDOWS_H +#include +#include +#endif + +/* Clean up _M_ARM64 (could mislead into pure ARM64 paths). Keep _ARM64EC_. */ +#ifdef _SSE2NEON_DEFINED_ARM64EC_ +#undef _SSE2NEON_DEFINED_ARM64EC_ +#endif +#ifdef _SSE2NEON_DEFINED_M_ARM64 +#undef _M_ARM64 +#undef _SSE2NEON_DEFINED_M_ARM64 +#endif + +#ifdef SSE2NEON_ALLOC_DEFINED +#include +#endif + +/* 64-bit bit scanning available on x64 and AArch64 (including ARM64EC) */ +#if (defined(_M_AMD64) || defined(__x86_64__)) || SSE2NEON_ARCH_AARCH64 +#define SSE2NEON_HAS_BITSCAN64 +#endif + +#endif /* SSE2NEON_COMPILER_MSVC */ + +/* MinGW uses _aligned_malloc/_aligned_free from */ +#if defined(__MINGW32__) +#include +#endif + +/* Statement expression helpers for macro-based intrinsics. + * + * For GCC/Clang (C and C++): Uses __extension__({}) statement expressions + * which provide local variables and natural access to surrounding scope. + * + * For MSVC C++: Uses immediately-invoked lambdas. The distinction between + * _sse2neon_define0 ([=] capture) and _sse2neon_define1 ([] no capture) + * exists for lambda capture semantics, though in practice both work the same + * since 'imm' parameters are compile-time constants substituted before the + * lambda is created. + * + * For pure C (MSVC C mode): Standard C has no block-expression mechanism, so + * _sse2neon_define0/1/2 are absent. Each intrinsic that requires them provides + * a FORCE_INLINE function fallback guarded by + * #if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) ... #else ... + * #endif at its definition site. + */ +#if SSE2NEON_COMPILER_GCC_COMPAT +#define _sse2neon_define0(type, s, body) \ + __extension__({ \ + type _a = (s); \ + body \ + }) +#define _sse2neon_define1(type, s, body) _sse2neon_define0(type, s, body) +#define _sse2neon_define2(type, a, b, body) \ + __extension__({ \ + type _a = (a), _b = (b); \ + body \ + }) +#define _sse2neon_return(ret) (ret) +#elif defined(__cplusplus) +/* MSVC in C++ mode: use immediately-invoked lambdas */ +#define _sse2neon_define0(type, a, body) [=](type _a) { body }(a) +#define _sse2neon_define1(type, a, body) [](type _a) { body }(a) +#define _sse2neon_define2(type, a, b, body) \ + [](type _a, type _b) { body }((a), (b)) +#define _sse2neon_return(ret) return ret +#else +/* Pure C (MSVC C mode): _sse2neon_define0/1/2 unavailable; each intrinsic + * provides a FORCE_INLINE function fallback at its own definition site. */ +#define _sse2neon_return(ret) (ret) +#endif + +#define _sse2neon_init(...) {__VA_ARGS__} + +/* Compiler barrier */ +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG +#define SSE2NEON_BARRIER() _ReadWriteBarrier() +#else +#define SSE2NEON_BARRIER() \ + do { \ + __asm__ __volatile__("" ::: "memory"); \ + (void) 0; \ + } while (0) +#endif + +/* Memory barriers + * __atomic_thread_fence does not include a compiler barrier; instead, + * the barrier is part of __atomic_load/__atomic_store's "volatile-like" + * semantics. + */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +#include +#endif + +FORCE_INLINE void _sse2neon_smp_mb(void) +{ + SSE2NEON_BARRIER(); +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ + !defined(__STDC_NO_ATOMICS__) + atomic_thread_fence(memory_order_seq_cst); +#elif SSE2NEON_COMPILER_GCC_COMPAT + __atomic_thread_fence(__ATOMIC_SEQ_CST); +#else /* MSVC */ + __dmb(_ARM64_BARRIER_ISH); +#endif +} + +/* Architecture-specific build options. + * #pragma GCC push_options/target are GCC-specific; Clang ignores these. + * MSVC on ARM always has NEON/SIMD available. + */ +#if SSE2NEON_COMPILER_GCC_COMPAT +#if defined(__arm__) +/* 32-bit ARM: ARMv7-A or ARMv8-A in AArch32 mode */ +#if !defined(__ARM_NEON) || !defined(__ARM_NEON__) +#error "You must enable NEON instructions (e.g. -mfpu=neon) to use SSE2NEON." +#endif +#if !SSE2NEON_COMPILER_CLANG +#pragma GCC push_options +#if __ARM_ARCH >= 8 +#pragma GCC target("fpu=neon-fp-armv8") +#else +#pragma GCC target("fpu=neon") +#endif +#endif +#elif SSE2NEON_ARCH_AARCH64 +#if !SSE2NEON_COMPILER_CLANG +#pragma GCC push_options +#pragma GCC target("+simd") +#endif +#else +#error "Unsupported target. Must be ARMv7-A+NEON, ARMv8-A, or AArch64." +#endif +#endif + +/* ARM64EC: use arm64_neon.h (arm_neon.h guards with _M_ARM||_M_ARM64) */ +#if SSE2NEON_ARM64EC || defined(_M_ARM64EC) +#include +#else +#include +#endif + +/* Include ACLE for CRC32 and other intrinsics on ARMv8+ */ +#if SSE2NEON_ARCH_AARCH64 || __ARM_ARCH >= 8 +#if defined __has_include && __has_include() +#include +#define SSE2NEON_HAS_ACLE 1 +#else +#define SSE2NEON_HAS_ACLE 0 +#endif +#else +#define SSE2NEON_HAS_ACLE 0 +#endif + +/* Apple Silicon cache lines are double of what is commonly used by Intel, AMD + * and other Arm microarchitectures use. + * From sysctl -a on Apple M1: + * hw.cachelinesize: 128 + */ +#if defined(__APPLE__) && (defined(__aarch64__) || defined(__arm64__)) +#define SSE2NEON_CACHELINE_SIZE 128 +#else +#define SSE2NEON_CACHELINE_SIZE 64 +#endif + +/* Rounding functions require either Aarch64 instructions or libm fallback */ +#if !SSE2NEON_ARCH_AARCH64 +#include +#endif + +/* On ARMv7, some registers, such as PMUSERENR and PMCCNTR, are read-only or + * even not accessible in user mode. + * To write or access to these registers in user mode, we have to perform + * syscall instead. + */ +#if !SSE2NEON_ARCH_AARCH64 +#include +#endif + +/* "__has_builtin" can be used to query support for built-in functions + * provided by gcc/clang and other compilers that support it. + * GCC 10+ and Clang 11+ have native __has_builtin support. + * MSVC does not provide these GCC/Clang builtins. + */ +#ifndef __has_builtin +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG +#define __has_builtin(x) 0 +#else +#error "Unsupported compiler: __has_builtin not available" +#endif +#endif + +/** + * MACRO for shuffle parameter for _mm_shuffle_ps(). + * Argument fp3 is a digit[0123] that represents the fp from argument "b" + * of mm_shuffle_ps that will be placed in fp3 of result. fp2 is the same + * for fp2 in result. fp1 is a digit[0123] that represents the fp from + * argument "a" of mm_shuffle_ps that will be places in fp1 of result. + * fp0 is the same for fp0 of result. + */ +#ifndef _MM_SHUFFLE +#define _MM_SHUFFLE(fp3, fp2, fp1, fp0) \ + (((fp3) << 6) | ((fp2) << 4) | ((fp1) << 2) | ((fp0))) +#endif + +/** + * MACRO for shuffle parameter for _mm_shuffle_pd(). + * Argument fp1 is a digit[01] that represents the fp from argument "b" + * of mm_shuffle_pd that will be placed in fp1 of result. + * fp0 is a digit[01] that represents the fp from argument "a" of mm_shuffle_pd + * that will be placed in fp0 of result. + */ +#ifndef _MM_SHUFFLE2 +#define _MM_SHUFFLE2(fp1, fp0) (((fp1) << 1) | (fp0)) +#endif + +#if __has_builtin(__builtin_shufflevector) +#define _sse2neon_shuffle(type, a, b, ...) \ + __builtin_shufflevector(a, b, __VA_ARGS__) +#elif __has_builtin(__builtin_shuffle) +#define _sse2neon_shuffle(type, a, b, ...) \ + __extension__({ \ + type tmp = {__VA_ARGS__}; \ + __builtin_shuffle(a, b, tmp); \ + }) +#endif + +#ifdef _sse2neon_shuffle +#define vshuffle_s16(a, b, ...) _sse2neon_shuffle(int16x4_t, a, b, __VA_ARGS__) +#define vshuffleq_s16(a, b, ...) _sse2neon_shuffle(int16x8_t, a, b, __VA_ARGS__) +#define vshuffle_s32(a, b, ...) _sse2neon_shuffle(int32x2_t, a, b, __VA_ARGS__) +#define vshuffleq_s32(a, b, ...) _sse2neon_shuffle(int32x4_t, a, b, __VA_ARGS__) +#define vshuffle_s64(a, b, ...) _sse2neon_shuffle(int64x1_t, a, b, __VA_ARGS__) +#define vshuffleq_s64(a, b, ...) _sse2neon_shuffle(int64x2_t, a, b, __VA_ARGS__) +#endif + +/* Rounding mode macros. */ +#define _MM_FROUND_TO_NEAREST_INT 0x00 +#define _MM_FROUND_TO_NEG_INF 0x01 +#define _MM_FROUND_TO_POS_INF 0x02 +#define _MM_FROUND_TO_ZERO 0x03 +#define _MM_FROUND_CUR_DIRECTION 0x04 +#define _MM_FROUND_NO_EXC 0x08 +#define _MM_FROUND_RAISE_EXC 0x00 +#ifndef _MM_FROUND_NINT +#define _MM_FROUND_NINT (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_RAISE_EXC) +#endif +#ifndef _MM_FROUND_FLOOR +#define _MM_FROUND_FLOOR (_MM_FROUND_TO_NEG_INF | _MM_FROUND_RAISE_EXC) +#endif +#ifndef _MM_FROUND_CEIL +#define _MM_FROUND_CEIL (_MM_FROUND_TO_POS_INF | _MM_FROUND_RAISE_EXC) +#endif +#ifndef _MM_FROUND_TRUNC +#define _MM_FROUND_TRUNC (_MM_FROUND_TO_ZERO | _MM_FROUND_RAISE_EXC) +#endif +#ifndef _MM_FROUND_RINT +#define _MM_FROUND_RINT (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_RAISE_EXC) +#endif +#ifndef _MM_FROUND_NEARBYINT +#define _MM_FROUND_NEARBYINT (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_NO_EXC) +#endif +#ifndef _MM_ROUND_NEAREST +#define _MM_ROUND_NEAREST 0x0000 +#endif +#ifndef _MM_ROUND_DOWN +#define _MM_ROUND_DOWN 0x2000 +#endif +#ifndef _MM_ROUND_UP +#define _MM_ROUND_UP 0x4000 +#endif +#ifndef _MM_ROUND_TOWARD_ZERO +#define _MM_ROUND_TOWARD_ZERO 0x6000 +#endif +#ifndef _MM_ROUND_MASK +#define _MM_ROUND_MASK 0x6000 +#endif +/* Flush-to-zero (FTZ) mode macros. + * On x86, FTZ (MXCSR bit 15) flushes denormal outputs to zero. + * On ARM, FPCR/FPSCR bit 24 provides unified FZ+DAZ behavior. + * ARMv7 NEON: Per ARM ARM, Advanced SIMD has "Flush-to-zero mode always + * enabled" - denormals flush regardless of FPSCR.FZ (some impls may vary). + * ARMv8: FPCR.FZ correctly controls denormal handling for NEON ops. + */ +#ifndef _MM_FLUSH_ZERO_MASK +#define _MM_FLUSH_ZERO_MASK 0x8000 +#endif +#ifndef _MM_FLUSH_ZERO_ON +#define _MM_FLUSH_ZERO_ON 0x8000 +#endif +#ifndef _MM_FLUSH_ZERO_OFF +#define _MM_FLUSH_ZERO_OFF 0x0000 +#endif +/* Denormals-are-zero (DAZ) mode macros. + * On x86, DAZ (MXCSR bit 6) treats denormal inputs as zero. + * On ARM, setting DAZ enables the same FPCR/FPSCR bit 24 as FTZ, + * providing unified handling for both input and output denormals. + */ +#ifndef _MM_DENORMALS_ZERO_MASK +#define _MM_DENORMALS_ZERO_MASK 0x0040 +#endif +#ifndef _MM_DENORMALS_ZERO_ON +#define _MM_DENORMALS_ZERO_ON 0x0040 +#endif +#ifndef _MM_DENORMALS_ZERO_OFF +#define _MM_DENORMALS_ZERO_OFF 0x0000 +#endif + +/* MXCSR Exception Flags - NOT EMULATED + * + * SSE provides floating-point exception flags in the MXCSR register (bits 0-5) + * that are NOT emulated on ARM NEON. Code relying on _mm_getcsr() to detect + * floating-point exceptions will silently fail to detect them. + * + * MXCSR Exception Flag Layout (x86): + * Bit 0 (IE): Invalid Operation Exception - NOT EMULATED + * Bit 1 (DE): Denormal Exception - NOT EMULATED + * Bit 2 (ZE): Divide-by-Zero Exception - NOT EMULATED + * Bit 3 (OE): Overflow Exception - NOT EMULATED + * Bit 4 (UE): Underflow Exception - NOT EMULATED + * Bit 5 (PE): Precision Exception - NOT EMULATED + * + * MXCSR Exception Mask Layout (x86): + * Bits 7-12: Exception masks (mask = suppress exception) - NOT EMULATED + * + * Why Not Emulated: + * - ARM NEON does not set sticky exception flags like x86 SSE + * - ARM FPSR (Floating-Point Status Register) has different semantics + * - Emulating per-operation exception tracking would require wrapping every + * floating-point intrinsic with software checks, severely impacting + * performance + * - Thread-local exception state tracking would add significant complexity + * + * Impact: + * - Scientific computing code checking for overflow/underflow will miss events + * - Financial applications validating precision will not detect precision loss + * - Numerical code checking for invalid operations (NaN generation) won't + * detect them + * + * Workarounds: + * - Use explicit NaN/Inf checks after critical operations: isnan(), isinf() + * - Implement application-level range validation for overflow detection + * - Use higher precision arithmetic where precision loss is critical + * + * The macros below are defined for API compatibility but provide no + * functionality. + */ + +/* Exception flag macros (MXCSR bits 0-5) - defined for API compatibility only + */ +#ifndef _MM_EXCEPT_INVALID +#define _MM_EXCEPT_INVALID 0x0001 +#endif +#ifndef _MM_EXCEPT_DENORM +#define _MM_EXCEPT_DENORM 0x0002 +#endif +#ifndef _MM_EXCEPT_DIV_ZERO +#define _MM_EXCEPT_DIV_ZERO 0x0004 +#endif +#ifndef _MM_EXCEPT_OVERFLOW +#define _MM_EXCEPT_OVERFLOW 0x0008 +#endif +#ifndef _MM_EXCEPT_UNDERFLOW +#define _MM_EXCEPT_UNDERFLOW 0x0010 +#endif +#ifndef _MM_EXCEPT_INEXACT +#define _MM_EXCEPT_INEXACT 0x0020 +#endif +#ifndef _MM_EXCEPT_MASK +#define _MM_EXCEPT_MASK \ + (_MM_EXCEPT_INVALID | _MM_EXCEPT_DENORM | _MM_EXCEPT_DIV_ZERO | \ + _MM_EXCEPT_OVERFLOW | _MM_EXCEPT_UNDERFLOW | _MM_EXCEPT_INEXACT) +#endif + +/* Exception mask macros (MXCSR bits 7-12) - defined for API compatibility only + */ +#ifndef _MM_MASK_INVALID +#define _MM_MASK_INVALID 0x0080 +#endif +#ifndef _MM_MASK_DENORM +#define _MM_MASK_DENORM 0x0100 +#endif +#ifndef _MM_MASK_DIV_ZERO +#define _MM_MASK_DIV_ZERO 0x0200 +#endif +#ifndef _MM_MASK_OVERFLOW +#define _MM_MASK_OVERFLOW 0x0400 +#endif +#ifndef _MM_MASK_UNDERFLOW +#define _MM_MASK_UNDERFLOW 0x0800 +#endif +#ifndef _MM_MASK_INEXACT +#define _MM_MASK_INEXACT 0x1000 +#endif +#ifndef _MM_MASK_MASK +#define _MM_MASK_MASK \ + (_MM_MASK_INVALID | _MM_MASK_DENORM | _MM_MASK_DIV_ZERO | \ + _MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW | _MM_MASK_INEXACT) +#endif + +/* Exception state accessor macros - silent stubs for API compatibility. + * These macros exist for API compatibility but provide NO functionality. + * On ARM, exception flags are never set by sse2neon intrinsics. + * + * _MM_GET_EXCEPTION_STATE() - Always returns 0 (no exceptions detected) + * _MM_SET_EXCEPTION_STATE() - Silently ignored (cannot clear nonexistent flags) + * _MM_GET_EXCEPTION_MASK() - Always returns all-masked (0x1F80) + * _MM_SET_EXCEPTION_MASK() - Silently ignored (no effect on ARM) + */ +#ifndef _MM_GET_EXCEPTION_STATE +#define _MM_GET_EXCEPTION_STATE() (0) +#endif +#ifndef _MM_SET_EXCEPTION_STATE +#define _MM_SET_EXCEPTION_STATE(x) ((void) (x)) +#endif +#ifndef _MM_GET_EXCEPTION_MASK +#define _MM_GET_EXCEPTION_MASK() (_MM_MASK_MASK) +#endif +#ifndef _MM_SET_EXCEPTION_MASK +#define _MM_SET_EXCEPTION_MASK(x) ((void) (x)) +#endif + +/* Compile-time validation for immediate constant arguments. + * This macro validates that: + * 1. The argument is a compile-time constant (via __builtin_constant_p) + * 2. The argument is within the specified range [min, max] + * + * When validation fails, __builtin_unreachable() is called to trigger + * compiler diagnostics. This pattern follows SIMDe's approach but adapted + * for use within macro bodies rather than as function attributes. + * + * Usage: Place at the beginning of macro bodies that require immediate + * constant arguments. The macro expands to a statement, so use a semicolon: + * SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + */ +#if defined(__has_builtin) +#if __has_builtin(__builtin_constant_p) && __has_builtin(__builtin_unreachable) +#define SSE2NEON_REQUIRE_CONST_RANGE(arg, min, max) \ + (void) ((__builtin_constant_p(arg) && ((arg) < (min) || (arg) > (max))) \ + ? (__builtin_unreachable(), 0) \ + : 0) +#endif +#endif +#if !defined(SSE2NEON_REQUIRE_CONST_RANGE) +/* Fallback: no compile-time validation */ +#define SSE2NEON_REQUIRE_CONST_RANGE(arg, min, max) ((void) 0) +#endif + +/* Allow users to disable constant validation if needed for testing */ +#ifdef SSE2NEON_DISABLE_CONSTANT_VALIDATION +#undef SSE2NEON_REQUIRE_CONST_RANGE +#define SSE2NEON_REQUIRE_CONST_RANGE(arg, min, max) ((void) 0) +#endif + +/* A few intrinsics accept traditional data types like ints or floats, but + * most operate on data types that are specific to SSE. + * If a vector type ends in d, it contains doubles, and if it does not have + * a suffix, it contains floats. An integer vector type can contain any type + * of integer, from chars to shorts to unsigned long longs. + */ +typedef int64x1_t __m64; +typedef float32x4_t __m128; /* 128-bit vector containing 4 floats */ +// On ARM 32-bit architecture, the float64x2_t is not supported. +// The data type __m128d should be represented in a different way for related +// intrinsic conversion. +#if SSE2NEON_ARCH_AARCH64 +typedef float64x2_t __m128d; /* 128-bit vector containing 2 doubles */ +#else +typedef float32x4_t __m128d; +#endif +typedef int64x2_t __m128i; /* 128-bit vector containing integers */ + +// Some intrinsics operate on unaligned data types. +typedef int16_t ALIGN_STRUCT(1) unaligned_int16_t; +typedef int32_t ALIGN_STRUCT(1) unaligned_int32_t; +typedef int64_t ALIGN_STRUCT(1) unaligned_int64_t; + +// __int64 is defined in the Intrinsics Guide which maps to different datatype +// in different data model +#if !(defined(_WIN32) || defined(_WIN64) || defined(__int64)) +#if (defined(__x86_64__) || defined(__i386__)) +#define __int64 long long +#else +#define __int64 int64_t +#endif +#endif + +/* type-safe casting between types */ + +#define vreinterpretq_m128_f16(x) vreinterpretq_f32_f16(x) +#define vreinterpretq_m128_f32(x) (x) +#define vreinterpretq_m128_f64(x) vreinterpretq_f32_f64(x) + +#define vreinterpretq_m128_u8(x) vreinterpretq_f32_u8(x) +#define vreinterpretq_m128_u16(x) vreinterpretq_f32_u16(x) +#define vreinterpretq_m128_u32(x) vreinterpretq_f32_u32(x) +#define vreinterpretq_m128_u64(x) vreinterpretq_f32_u64(x) + +#define vreinterpretq_m128_s8(x) vreinterpretq_f32_s8(x) +#define vreinterpretq_m128_s16(x) vreinterpretq_f32_s16(x) +#define vreinterpretq_m128_s32(x) vreinterpretq_f32_s32(x) +#define vreinterpretq_m128_s64(x) vreinterpretq_f32_s64(x) + +#define vreinterpretq_f16_m128(x) vreinterpretq_f16_f32(x) +#define vreinterpretq_f32_m128(x) (x) +#define vreinterpretq_f64_m128(x) vreinterpretq_f64_f32(x) + +#define vreinterpretq_u8_m128(x) vreinterpretq_u8_f32(x) +#define vreinterpretq_u16_m128(x) vreinterpretq_u16_f32(x) +#define vreinterpretq_u32_m128(x) vreinterpretq_u32_f32(x) +#define vreinterpretq_u64_m128(x) vreinterpretq_u64_f32(x) + +#define vreinterpretq_s8_m128(x) vreinterpretq_s8_f32(x) +#define vreinterpretq_s16_m128(x) vreinterpretq_s16_f32(x) +#define vreinterpretq_s32_m128(x) vreinterpretq_s32_f32(x) +#define vreinterpretq_s64_m128(x) vreinterpretq_s64_f32(x) + +#define vreinterpretq_m128i_s8(x) vreinterpretq_s64_s8(x) +#define vreinterpretq_m128i_s16(x) vreinterpretq_s64_s16(x) +#define vreinterpretq_m128i_s32(x) vreinterpretq_s64_s32(x) +#define vreinterpretq_m128i_s64(x) (x) + +#define vreinterpretq_m128i_u8(x) vreinterpretq_s64_u8(x) +#define vreinterpretq_m128i_u16(x) vreinterpretq_s64_u16(x) +#define vreinterpretq_m128i_u32(x) vreinterpretq_s64_u32(x) +#define vreinterpretq_m128i_u64(x) vreinterpretq_s64_u64(x) + +#define vreinterpretq_f32_m128i(x) vreinterpretq_f32_s64(x) +#define vreinterpretq_f64_m128i(x) vreinterpretq_f64_s64(x) + +#define vreinterpretq_s8_m128i(x) vreinterpretq_s8_s64(x) +#define vreinterpretq_s16_m128i(x) vreinterpretq_s16_s64(x) +#define vreinterpretq_s32_m128i(x) vreinterpretq_s32_s64(x) +#define vreinterpretq_s64_m128i(x) (x) + +#define vreinterpretq_u8_m128i(x) vreinterpretq_u8_s64(x) +#define vreinterpretq_u16_m128i(x) vreinterpretq_u16_s64(x) +#define vreinterpretq_u32_m128i(x) vreinterpretq_u32_s64(x) +#define vreinterpretq_u64_m128i(x) vreinterpretq_u64_s64(x) + +#define vreinterpret_m64_s8(x) vreinterpret_s64_s8(x) +#define vreinterpret_m64_s16(x) vreinterpret_s64_s16(x) +#define vreinterpret_m64_s32(x) vreinterpret_s64_s32(x) +#define vreinterpret_m64_s64(x) (x) + +#define vreinterpret_m64_u8(x) vreinterpret_s64_u8(x) +#define vreinterpret_m64_u16(x) vreinterpret_s64_u16(x) +#define vreinterpret_m64_u32(x) vreinterpret_s64_u32(x) +#define vreinterpret_m64_u64(x) vreinterpret_s64_u64(x) + +#define vreinterpret_m64_f16(x) vreinterpret_s64_f16(x) +#define vreinterpret_m64_f32(x) vreinterpret_s64_f32(x) +#define vreinterpret_m64_f64(x) vreinterpret_s64_f64(x) + +#define vreinterpret_u8_m64(x) vreinterpret_u8_s64(x) +#define vreinterpret_u16_m64(x) vreinterpret_u16_s64(x) +#define vreinterpret_u32_m64(x) vreinterpret_u32_s64(x) +#define vreinterpret_u64_m64(x) vreinterpret_u64_s64(x) + +#define vreinterpret_s8_m64(x) vreinterpret_s8_s64(x) +#define vreinterpret_s16_m64(x) vreinterpret_s16_s64(x) +#define vreinterpret_s32_m64(x) vreinterpret_s32_s64(x) +#define vreinterpret_s64_m64(x) (x) + +#define vreinterpret_f32_m64(x) vreinterpret_f32_s64(x) + +#if SSE2NEON_ARCH_AARCH64 +#define vreinterpretq_m128d_s32(x) vreinterpretq_f64_s32(x) +#define vreinterpretq_m128d_s64(x) vreinterpretq_f64_s64(x) + +#define vreinterpretq_m128d_u64(x) vreinterpretq_f64_u64(x) + +#define vreinterpretq_m128d_f32(x) vreinterpretq_f64_f32(x) +#define vreinterpretq_m128d_f64(x) (x) + +#define vreinterpretq_s64_m128d(x) vreinterpretq_s64_f64(x) + +#define vreinterpretq_u32_m128d(x) vreinterpretq_u32_f64(x) +#define vreinterpretq_u64_m128d(x) vreinterpretq_u64_f64(x) + +#define vreinterpretq_f64_m128d(x) (x) +#define vreinterpretq_f32_m128d(x) vreinterpretq_f32_f64(x) +#else +#define vreinterpretq_m128d_s32(x) vreinterpretq_f32_s32(x) +#define vreinterpretq_m128d_s64(x) vreinterpretq_f32_s64(x) + +#define vreinterpretq_m128d_u32(x) vreinterpretq_f32_u32(x) +#define vreinterpretq_m128d_u64(x) vreinterpretq_f32_u64(x) + +#define vreinterpretq_m128d_f32(x) (x) + +#define vreinterpretq_s64_m128d(x) vreinterpretq_s64_f32(x) + +#define vreinterpretq_u32_m128d(x) vreinterpretq_u32_f32(x) +#define vreinterpretq_u64_m128d(x) vreinterpretq_u64_f32(x) + +#define vreinterpretq_f32_m128d(x) (x) +#endif + +// A struct is defined in this header file called 'SIMDVec' which can be used +// by applications which attempt to access the contents of an __m128 struct +// directly. It is important to note that accessing the __m128 struct directly +// is bad coding practice by Microsoft: @see: +// https://learn.microsoft.com/en-us/cpp/cpp/m128 +// +// However, some legacy source code may try to access the contents of an __m128 +// struct directly so the developer can use the SIMDVec as an alias for it. Any +// casting must be done manually by the developer, as you cannot cast or +// otherwise alias the base NEON data type for intrinsic operations. +// +// union intended to allow direct access to an __m128 variable using the names +// that the MSVC compiler provides. This union should really only be used when +// trying to access the members of the vector as integer values. GCC/clang +// allow native access to the float members through a simple array access +// operator (in C since 4.6, in C++ since 4.8). +// +// Ideally direct accesses to SIMD vectors should not be used since it can cause +// a performance hit. If it really is needed however, the original __m128 +// variable can be aliased with a pointer to this union and used to access +// individual components. The use of this union should be hidden behind a macro +// that is used throughout the codebase to access the members instead of always +// declaring this type of variable. +typedef union ALIGN_STRUCT(16) SIMDVec { + float m128_f32[4]; // as floats - DON'T USE. Added for convenience. + int8_t m128_i8[16]; // as signed 8-bit integers. + int16_t m128_i16[8]; // as signed 16-bit integers. + int32_t m128_i32[4]; // as signed 32-bit integers. + int64_t m128_i64[2]; // as signed 64-bit integers. + uint8_t m128_u8[16]; // as unsigned 8-bit integers. + uint16_t m128_u16[8]; // as unsigned 16-bit integers. + uint32_t m128_u32[4]; // as unsigned 32-bit integers. + uint64_t m128_u64[2]; // as unsigned 64-bit integers. +} SIMDVec; + +// casting using SIMDVec +#define vreinterpretq_nth_u64_m128i(x, n) \ + (_sse2neon_reinterpret_cast(SIMDVec *, &x)->m128_u64[n]) +#define vreinterpretq_nth_u32_m128i(x, n) \ + (_sse2neon_reinterpret_cast(SIMDVec *, &x)->m128_u32[n]) +#define vreinterpretq_nth_u8_m128i(x, n) \ + (_sse2neon_reinterpret_cast(SIMDVec *, &x)->m128_u8[n]) + +/* Portable infinity check using IEEE 754 bit representation. + * Infinity has all exponent bits set and zero mantissa bits. + * This avoids dependency on math.h INFINITY macro or compiler builtins. + */ +FORCE_INLINE int _sse2neon_isinf_f32(float v) +{ + union { + float f; + uint32_t u; + } u = {v}; + /* Mask out sign bit, check if remaining bits equal infinity pattern */ + return (u.u & 0x7FFFFFFF) == 0x7F800000; +} + +FORCE_INLINE int _sse2neon_isinf_f64(double v) +{ + union { + double d; + uint64_t u; + } u = {v}; + return (u.u & 0x7FFFFFFFFFFFFFFFULL) == 0x7FF0000000000000ULL; +} + +/* Safe helper to load double[2] as float32x4_t without strict aliasing + * violation. Used in ARMv7 fallback paths where float64x2_t is not natively + * supported. + */ +FORCE_INLINE float32x4_t sse2neon_vld1q_f32_from_f64pair(const double *p) +{ + float32x4_t tmp; + memcpy(&tmp, p, sizeof(tmp)); + return tmp; +} + +/* Safe float/double to integer conversion with x86 SSE semantics. + * x86 SSE returns the "integer indefinite" value (0x80000000 for int32, + * 0x8000000000000000 for int64) for all out-of-range conversions including + * NaN, infinity, and values exceeding the representable range. + * ARM NEON differs by saturating to INT_MAX/INT_MIN for overflows and + * returning 0 for NaN, so we need these helpers to ensure x86 compatibility. + */ +FORCE_INLINE int32_t _sse2neon_cvtd_s32(double v) +{ + /* Check for NaN or infinity first */ + if (v != v || _sse2neon_isinf_f64(v)) + return INT32_MIN; + /* INT32_MAX is exactly representable as double (2147483647.0) */ + if (v >= _sse2neon_static_cast(double, INT32_MAX) + 1.0) + return INT32_MIN; + if (v < _sse2neon_static_cast(double, INT32_MIN)) + return INT32_MIN; + return _sse2neon_static_cast(int32_t, v); +} + +FORCE_INLINE int32_t _sse2neon_cvtf_s32(float v) +{ + if (v != v || _sse2neon_isinf_f32(v)) + return INT32_MIN; + /* (float)INT32_MAX rounds up to 2147483648.0f, which is out of range. + * Use the double representation for accurate comparison. + */ + if (v >= _sse2neon_static_cast(double, INT32_MAX) + 1.0) + return INT32_MIN; + if (v < _sse2neon_static_cast(double, INT32_MIN)) + return INT32_MIN; + return _sse2neon_static_cast(int32_t, v); +} + +FORCE_INLINE int64_t _sse2neon_cvtd_s64(double v) +{ + if (v != v || _sse2neon_isinf_f64(v)) + return INT64_MIN; + /* (double)INT64_MAX rounds up to 2^63 which is out of range. + * Any double >= 2^63 is out of range for int64. + */ + if (v >= _sse2neon_static_cast(double, INT64_MAX)) + return INT64_MIN; + if (v < _sse2neon_static_cast(double, INT64_MIN)) + return INT64_MIN; + return _sse2neon_static_cast(int64_t, v); +} + +FORCE_INLINE int64_t _sse2neon_cvtf_s64(float v) +{ + if (v != v || _sse2neon_isinf_f32(v)) + return INT64_MIN; + /* (float)INT64_MAX rounds up significantly beyond INT64_MAX */ + if (v >= _sse2neon_static_cast(float, INT64_MAX)) + return INT64_MIN; + if (v < _sse2neon_static_cast(float, INT64_MIN)) + return INT64_MIN; + return _sse2neon_static_cast(int64_t, v); +} + +/* Vectorized helper: apply x86 saturation semantics to NEON conversion result. + * ARM returns 0 for NaN and INT32_MAX for positive overflow, but x86 returns + * INT32_MIN ("integer indefinite") for both. This function fixes up the result. + */ +FORCE_INLINE int32x4_t _sse2neon_cvtps_epi32_fixup(float32x4_t f, int32x4_t cvt) +{ + /* Detect values >= 2147483648.0f (out of INT32 range) */ + float32x4_t max_f = vdupq_n_f32(2147483648.0f); + uint32x4_t overflow = vcgeq_f32(f, max_f); + + /* Detect NaN: x != x for NaN values */ + uint32x4_t is_nan = vmvnq_u32(vceqq_f32(f, f)); + + /* Combine: any overflow or NaN should produce INT32_MIN */ + uint32x4_t need_indefinite = vorrq_u32(overflow, is_nan); + + /* Blend: select INT32_MIN where needed */ + int32x4_t indefinite = vdupq_n_s32(INT32_MIN); + return vbslq_s32(need_indefinite, indefinite, cvt); +} + +/* SSE macros */ +#define _MM_GET_FLUSH_ZERO_MODE _sse2neon_mm_get_flush_zero_mode +#define _MM_SET_FLUSH_ZERO_MODE _sse2neon_mm_set_flush_zero_mode +#define _MM_GET_DENORMALS_ZERO_MODE _sse2neon_mm_get_denormals_zero_mode +#define _MM_SET_DENORMALS_ZERO_MODE _sse2neon_mm_set_denormals_zero_mode + +// Function declaration +// SSE +FORCE_INLINE unsigned int _MM_GET_ROUNDING_MODE(void); +FORCE_INLINE unsigned int _sse2neon_mm_get_denormals_zero_mode(void); +FORCE_INLINE void _sse2neon_mm_set_denormals_zero_mode(unsigned int); +FORCE_INLINE __m128 _mm_move_ss(__m128, __m128); +FORCE_INLINE __m128 _mm_or_ps(__m128, __m128); +FORCE_INLINE __m128 _mm_set_ps1(float); +FORCE_INLINE __m128 _mm_setzero_ps(void); +// SSE2 +FORCE_INLINE __m128i _mm_and_si128(__m128i, __m128i); +FORCE_INLINE __m128i _mm_castps_si128(__m128); +FORCE_INLINE __m128i _mm_cmpeq_epi32(__m128i, __m128i); +FORCE_INLINE __m128i _mm_cvtps_epi32(__m128); +FORCE_INLINE __m128d _mm_move_sd(__m128d, __m128d); +FORCE_INLINE __m128i _mm_or_si128(__m128i, __m128i); +FORCE_INLINE __m128i _mm_set_epi32(int, int, int, int); +FORCE_INLINE __m128i _mm_set_epi64x(int64_t, int64_t); +FORCE_INLINE __m128d _mm_set_pd(double, double); +FORCE_INLINE __m128i _mm_set1_epi32(int); +FORCE_INLINE __m128i _mm_setzero_si128(void); +// SSE4.1 +FORCE_INLINE __m128d _mm_ceil_pd(__m128d); +FORCE_INLINE __m128 _mm_ceil_ps(__m128); +FORCE_INLINE __m128d _mm_floor_pd(__m128d); +FORCE_INLINE __m128 _mm_floor_ps(__m128); +FORCE_INLINE __m128d _mm_round_pd(__m128d, int); +FORCE_INLINE __m128 _mm_round_ps(__m128, int); +// SSE4.2 +FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t, uint8_t); + +/* Backwards compatibility for compilers with lack of specific type support */ + +// Older gcc does not define vld1q_u8_x4 type +#if defined(__GNUC__) && !defined(__clang__) && \ + ((__GNUC__ <= 13 && defined(__arm__)) || \ + (__GNUC__ == 10 && __GNUC_MINOR__ < 3 && defined(__aarch64__))) +FORCE_INLINE uint8x16x4_t _sse2neon_vld1q_u8_x4(const uint8_t *p) +{ + uint8x16x4_t ret; + ret.val[0] = vld1q_u8(p + 0); + ret.val[1] = vld1q_u8(p + 16); + ret.val[2] = vld1q_u8(p + 32); + ret.val[3] = vld1q_u8(p + 48); + return ret; +} +#else +// Wraps vld1q_u8_x4 +FORCE_INLINE uint8x16x4_t _sse2neon_vld1q_u8_x4(const uint8_t *p) +{ + return vld1q_u8_x4(p); +} +#endif + +/* Wrapper for vcreate_u64 to handle Apple iOS toolchain variations. + * On iOS, vcreate_u64 may be defined as a macro in arm_neon.h, which can + * cause parsing issues in complex macro expansions. + * This wrapper provides a function-call interface using vdup_n_u64(), which + * is bit-exact and avoids macro expansion pitfalls. + * + * Other AArch64 platforms (Linux, macOS, Android) use native vcreate_u64. + * + * User override: Define SSE2NEON_IOS_COMPAT=1 to enable, + * or SSE2NEON_IOS_COMPAT=0 to disable. + */ +#if defined(__APPLE__) && SSE2NEON_ARCH_AARCH64 +#include +#endif + +#ifndef SSE2NEON_IOS_COMPAT +#if defined(__APPLE__) && SSE2NEON_ARCH_AARCH64 && TARGET_OS_IOS +#define SSE2NEON_IOS_COMPAT 1 +#else +#define SSE2NEON_IOS_COMPAT 0 +#endif +#endif + +#if SSE2NEON_IOS_COMPAT +FORCE_INLINE uint64x1_t _sse2neon_vcreate_u64(uint64_t a) +{ + return vdup_n_u64(a); +} +#else +#define _sse2neon_vcreate_u64(a) vcreate_u64(a) +#endif + +#if !SSE2NEON_ARCH_AARCH64 +/* emulate vaddv u8 variant */ +FORCE_INLINE uint8_t _sse2neon_vaddv_u8(uint8x8_t v8) +{ + const uint64x1_t v1 = vpaddl_u32(vpaddl_u16(vpaddl_u8(v8))); + return vget_lane_u8(vreinterpret_u8_u64(v1), 0); +} +#else +// Wraps vaddv_u8 +FORCE_INLINE uint8_t _sse2neon_vaddv_u8(uint8x8_t v8) +{ + return vaddv_u8(v8); +} +#endif + +#if !SSE2NEON_ARCH_AARCH64 +/* emulate vaddvq u8 variant */ +FORCE_INLINE uint8_t _sse2neon_vaddvq_u8(uint8x16_t a) +{ + uint8x8_t tmp = vpadd_u8(vget_low_u8(a), vget_high_u8(a)); + uint8_t res = 0; + for (int i = 0; i < 8; ++i) + res += tmp[i]; + return res; +} +#else +// Wraps vaddvq_u8 +FORCE_INLINE uint8_t _sse2neon_vaddvq_u8(uint8x16_t a) +{ + return vaddvq_u8(a); +} +#endif + +#if !SSE2NEON_ARCH_AARCH64 +/* emulate vaddvq u16 variant */ +FORCE_INLINE uint16_t _sse2neon_vaddvq_u16(uint16x8_t a) +{ + uint32x4_t m = vpaddlq_u16(a); + uint64x2_t n = vpaddlq_u32(m); + uint64x1_t o = vget_low_u64(n) + vget_high_u64(n); + + return vget_lane_u32(vreinterpret_u32_u64(o), 0); +} +#else +// Wraps vaddvq_u16 +FORCE_INLINE uint16_t _sse2neon_vaddvq_u16(uint16x8_t a) +{ + return vaddvq_u16(a); +} +#endif + +/* Fast "any nonzero" check for horizontal reduction in PCMPXSTR operations. + * These helpers are optimized for the "any match" test pattern common in + * string comparison intrinsics. On ARMv7, OR-based reduction is used instead + * of max-based reduction for slightly better performance on some cores. + * + * For NEON comparison results (0x00 or 0xFF per lane), OR-based reduction + * correctly detects any nonzero element because: max(a,b) > 0 IFF OR(a,b) != 0 + */ +#if !SSE2NEON_ARCH_AARCH64 +/* ARMv7: OR-based reduction - 3 ops vs 4 ops for vpmax cascade */ +FORCE_INLINE uint32_t _sse2neon_any_nonzero_u8x16(uint8x16_t v) +{ + uint32x4_t as_u32 = vreinterpretq_u32_u8(v); + uint32x2_t or_half = vorr_u32(vget_low_u32(as_u32), vget_high_u32(as_u32)); + uint32x2_t or_final = vorr_u32(or_half, vrev64_u32(or_half)); + return vget_lane_u32(or_final, 0); +} + +FORCE_INLINE uint32_t _sse2neon_any_nonzero_u16x8(uint16x8_t v) +{ + uint32x4_t as_u32 = vreinterpretq_u32_u16(v); + uint32x2_t or_half = vorr_u32(vget_low_u32(as_u32), vget_high_u32(as_u32)); + uint32x2_t or_final = vorr_u32(or_half, vrev64_u32(or_half)); + return vget_lane_u32(or_final, 0); +} +#endif + +/* Function Naming Conventions + * The naming convention of SSE intrinsics is straightforward. A generic SSE + * intrinsic function is given as follows: + * _mm__ + * + * The parts of this format are given as follows: + * 1. describes the operation performed by the intrinsic + * 2. identifies the data type of the function's primary arguments + * + * This last part, , is a little complicated. It identifies the + * content of the input values, and can be set to any of the following values: + * + ps - vectors contain floats (ps stands for packed single-precision) + * + pd - vectors contain doubles (pd stands for packed double-precision) + * + epi8/epi16/epi32/epi64 - vectors contain 8-bit/16-bit/32-bit/64-bit + * signed integers + * + epu8/epu16/epu32/epu64 - vectors contain 8-bit/16-bit/32-bit/64-bit + * unsigned integers + * + si128 - unspecified 128-bit vector or 256-bit vector + * + m128/m128i/m128d - identifies input vector types when they are different + * than the type of the returned vector + * + * For example, _mm_setzero_ps. The _mm implies that the function returns + * a 128-bit vector. The _ps at the end implies that the argument vectors + * contain floats. + * + * A complete example: Byte Shuffle - pshufb (_mm_shuffle_epi8) + * // Set packed 16-bit integers. 128 bits, 8 short, per 16 bits + * __m128i v_in = _mm_setr_epi16(1, 2, 3, 4, 5, 6, 7, 8); + * // Set packed 8-bit integers + * // 128 bits, 16 chars, per 8 bits + * __m128i v_perm = _mm_setr_epi8(1, 0, 2, 3, 8, 9, 10, 11, + * 4, 5, 12, 13, 6, 7, 14, 15); + * // Shuffle packed 8-bit integers + * __m128i v_out = _mm_shuffle_epi8(v_in, v_perm); // pshufb + */ + +/* Constants for use with _mm_prefetch. */ +#if SSE2NEON_ARM64EC +/* winnt.h defines these as macros; undef to allow our enum definition */ +#undef _MM_HINT_NTA +#undef _MM_HINT_T0 +#undef _MM_HINT_T1 +#undef _MM_HINT_T2 +#endif +enum _mm_hint { + _MM_HINT_NTA = 0, /* load data to L1 and L2 cache, mark it as NTA */ + _MM_HINT_T0 = 1, /* load data to L1 and L2 cache */ + _MM_HINT_T1 = 2, /* load data to L2 cache only */ + _MM_HINT_T2 = 3, /* load data to L2 cache only, mark it as NTA */ +}; + +// The bit field mapping to the FPCR(floating-point control register) +typedef struct { + uint16_t res0; + uint8_t res1 : 6; + uint8_t bit22 : 1; + uint8_t bit23 : 1; + uint8_t bit24 : 1; + uint8_t res2 : 7; +#if SSE2NEON_ARCH_AARCH64 + uint32_t res3; +#endif +} fpcr_bitfield; + +// Takes the upper 64 bits of a and places it in the low end of the result +// Takes the lower 64 bits of b and places it into the high end of the result. +FORCE_INLINE __m128 _mm_shuffle_ps_1032(__m128 a, __m128 b) +{ + float32x2_t a32 = vget_high_f32(vreinterpretq_f32_m128(a)); + float32x2_t b10 = vget_low_f32(vreinterpretq_f32_m128(b)); + return vreinterpretq_m128_f32(vcombine_f32(a32, b10)); +} + +// takes the lower two 32-bit values from a and swaps them and places in high +// end of result takes the higher two 32 bit values from b and swaps them and +// places in low end of result. +FORCE_INLINE __m128 _mm_shuffle_ps_2301(__m128 a, __m128 b) +{ + float32x2_t a01 = vrev64_f32(vget_low_f32(vreinterpretq_f32_m128(a))); + float32x2_t b23 = vrev64_f32(vget_high_f32(vreinterpretq_f32_m128(b))); + return vreinterpretq_m128_f32(vcombine_f32(a01, b23)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_0321(__m128 a, __m128 b) +{ + float32x2_t a21 = vget_high_f32( + vextq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a), 3)); + float32x2_t b03 = vget_low_f32( + vextq_f32(vreinterpretq_f32_m128(b), vreinterpretq_f32_m128(b), 3)); + return vreinterpretq_m128_f32(vcombine_f32(a21, b03)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_2103(__m128 a, __m128 b) +{ + float32x2_t a03 = vget_low_f32( + vextq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a), 3)); + float32x2_t b21 = vget_high_f32( + vextq_f32(vreinterpretq_f32_m128(b), vreinterpretq_f32_m128(b), 3)); + return vreinterpretq_m128_f32(vcombine_f32(a03, b21)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_1010(__m128 a, __m128 b) +{ + float32x2_t a10 = vget_low_f32(vreinterpretq_f32_m128(a)); + float32x2_t b10 = vget_low_f32(vreinterpretq_f32_m128(b)); + return vreinterpretq_m128_f32(vcombine_f32(a10, b10)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_1001(__m128 a, __m128 b) +{ + float32x2_t a01 = vrev64_f32(vget_low_f32(vreinterpretq_f32_m128(a))); + float32x2_t b10 = vget_low_f32(vreinterpretq_f32_m128(b)); + return vreinterpretq_m128_f32(vcombine_f32(a01, b10)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_0101(__m128 a, __m128 b) +{ + float32x2_t a01 = vrev64_f32(vget_low_f32(vreinterpretq_f32_m128(a))); + float32x2_t b01 = vrev64_f32(vget_low_f32(vreinterpretq_f32_m128(b))); + return vreinterpretq_m128_f32(vcombine_f32(a01, b01)); +} + +// keeps the low 64 bits of b in the low and puts the high 64 bits of a in the +// high +FORCE_INLINE __m128 _mm_shuffle_ps_3210(__m128 a, __m128 b) +{ + float32x2_t a10 = vget_low_f32(vreinterpretq_f32_m128(a)); + float32x2_t b32 = vget_high_f32(vreinterpretq_f32_m128(b)); + return vreinterpretq_m128_f32(vcombine_f32(a10, b32)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_0011(__m128 a, __m128 b) +{ + float32x2_t a11 = vdup_lane_f32(vget_low_f32(vreinterpretq_f32_m128(a)), 1); + float32x2_t b00 = vdup_lane_f32(vget_low_f32(vreinterpretq_f32_m128(b)), 0); + return vreinterpretq_m128_f32(vcombine_f32(a11, b00)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_0022(__m128 a, __m128 b) +{ + float32x2_t a22 = + vdup_lane_f32(vget_high_f32(vreinterpretq_f32_m128(a)), 0); + float32x2_t b00 = vdup_lane_f32(vget_low_f32(vreinterpretq_f32_m128(b)), 0); + return vreinterpretq_m128_f32(vcombine_f32(a22, b00)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_2200(__m128 a, __m128 b) +{ + float32x2_t a00 = vdup_lane_f32(vget_low_f32(vreinterpretq_f32_m128(a)), 0); + float32x2_t b22 = + vdup_lane_f32(vget_high_f32(vreinterpretq_f32_m128(b)), 0); + return vreinterpretq_m128_f32(vcombine_f32(a00, b22)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_3202(__m128 a, __m128 b) +{ + float32x4_t _a = vreinterpretq_f32_m128(a); + float32x4_t _b = vreinterpretq_f32_m128(b); + /* vtrn interleaves elements: trn1({a[2],a[3]}, {a[0],a[1]}) = {a[2], a[0]} + */ +#if SSE2NEON_ARCH_AARCH64 + float32x2_t a02 = vtrn1_f32(vget_high_f32(_a), vget_low_f32(_a)); +#else + float32x2_t a02 = vtrn_f32(vget_high_f32(_a), vget_low_f32(_a)).val[0]; +#endif + float32x2_t b32 = vget_high_f32(_b); + return vreinterpretq_m128_f32(vcombine_f32(a02, b32)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_1133(__m128 a, __m128 b) +{ + float32x2_t a33 = + vdup_lane_f32(vget_high_f32(vreinterpretq_f32_m128(a)), 1); + float32x2_t b11 = vdup_lane_f32(vget_low_f32(vreinterpretq_f32_m128(b)), 1); + return vreinterpretq_m128_f32(vcombine_f32(a33, b11)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_2010(__m128 a, __m128 b) +{ + float32x2_t a10 = vget_low_f32(vreinterpretq_f32_m128(a)); + float32_t b2 = vgetq_lane_f32(vreinterpretq_f32_m128(b), 2); + float32x2_t b00 = vdup_lane_f32(vget_low_f32(vreinterpretq_f32_m128(b)), 0); + float32x2_t b20 = vset_lane_f32(b2, b00, 1); + return vreinterpretq_m128_f32(vcombine_f32(a10, b20)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_2001(__m128 a, __m128 b) +{ + float32x2_t a01 = vrev64_f32(vget_low_f32(vreinterpretq_f32_m128(a))); + float32_t b2 = vgetq_lane_f32(b, 2); + float32x2_t b00 = vdup_lane_f32(vget_low_f32(vreinterpretq_f32_m128(b)), 0); + float32x2_t b20 = vset_lane_f32(b2, b00, 1); + return vreinterpretq_m128_f32(vcombine_f32(a01, b20)); +} + +FORCE_INLINE __m128 _mm_shuffle_ps_2032(__m128 a, __m128 b) +{ + float32x2_t a32 = vget_high_f32(vreinterpretq_f32_m128(a)); + float32_t b2 = vgetq_lane_f32(b, 2); + float32x2_t b00 = vdup_lane_f32(vget_low_f32(vreinterpretq_f32_m128(b)), 0); + float32x2_t b20 = vset_lane_f32(b2, b00, 1); + return vreinterpretq_m128_f32(vcombine_f32(a32, b20)); +} + +// For MSVC, we check only if it is ARM64, as every single ARM64 processor +// supported by WoA has crypto extensions. If this changes in the future, +// this can be verified via the runtime-only method of: +// IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) +#if ((defined(_M_ARM64) || SSE2NEON_ARM64EC) && !defined(__clang__)) || \ + (defined(__ARM_FEATURE_CRYPTO) && \ + (defined(__aarch64__) || __has_builtin(__builtin_arm_crypto_vmullp64))) +// Wraps vmull_p64 +FORCE_INLINE uint64x2_t _sse2neon_vmull_p64(uint64x1_t _a, uint64x1_t _b) +{ + poly64_t a = vget_lane_p64(vreinterpret_p64_u64(_a), 0); + poly64_t b = vget_lane_p64(vreinterpret_p64_u64(_b), 0); +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG + __n64 a1 = {a}, b1 = {b}; + return vreinterpretq_u64_p128(vmull_p64(a1, b1)); +#else + return vreinterpretq_u64_p128(vmull_p64(a, b)); +#endif +} +#else // ARMv7 polyfill +// ARMv7/some A64 lacks vmull_p64, but it has vmull_p8. +// +// vmull_p8 calculates 8 8-bit->16-bit polynomial multiplies, but we need a +// 64-bit->128-bit polynomial multiply. +// +// It needs some work and is somewhat slow, but it is still faster than all +// known scalar methods. +// +// Algorithm adapted to C from +// https://www.workofard.com/2017/07/ghash-for-low-end-cores/, which is adapted +// from "Fast Software Polynomial Multiplication on ARM Processors Using the +// NEON Engine" by Danilo Camara, Conrado Gouvea, Julio Lopez and Ricardo Dahab +// (https://hal.inria.fr/hal-01506572) +static uint64x2_t _sse2neon_vmull_p64(uint64x1_t _a, uint64x1_t _b) +{ + poly8x8_t a = vreinterpret_p8_u64(_a); + poly8x8_t b = vreinterpret_p8_u64(_b); + + // Masks + uint8x16_t k48_32 = vcombine_u8(vcreate_u8(0x0000ffffffffffff), + vcreate_u8(0x00000000ffffffff)); + uint8x16_t k16_00 = vcombine_u8(vcreate_u8(0x000000000000ffff), + vcreate_u8(0x0000000000000000)); + + // Do the multiplies, rotating with vext to get all combinations + uint8x16_t d = vreinterpretq_u8_p16(vmull_p8(a, b)); // D = A0 * B0 + uint8x16_t e = + vreinterpretq_u8_p16(vmull_p8(a, vext_p8(b, b, 1))); // E = A0 * B1 + uint8x16_t f = + vreinterpretq_u8_p16(vmull_p8(vext_p8(a, a, 1), b)); // F = A1 * B0 + uint8x16_t g = + vreinterpretq_u8_p16(vmull_p8(a, vext_p8(b, b, 2))); // G = A0 * B2 + uint8x16_t h = + vreinterpretq_u8_p16(vmull_p8(vext_p8(a, a, 2), b)); // H = A2 * B0 + uint8x16_t i = + vreinterpretq_u8_p16(vmull_p8(a, vext_p8(b, b, 3))); // I = A0 * B3 + uint8x16_t j = + vreinterpretq_u8_p16(vmull_p8(vext_p8(a, a, 3), b)); // J = A3 * B0 + uint8x16_t k = + vreinterpretq_u8_p16(vmull_p8(a, vext_p8(b, b, 4))); // L = A0 * B4 + + // Add cross products + uint8x16_t l = veorq_u8(e, f); // L = E + F + uint8x16_t m = veorq_u8(g, h); // M = G + H + uint8x16_t n = veorq_u8(i, j); // N = I + J + + // Interleave. Using vzip1 and vzip2 prevents Clang from emitting TBL + // instructions. +#if SSE2NEON_ARCH_AARCH64 + uint8x16_t lm_p0 = vreinterpretq_u8_u64( + vzip1q_u64(vreinterpretq_u64_u8(l), vreinterpretq_u64_u8(m))); + uint8x16_t lm_p1 = vreinterpretq_u8_u64( + vzip2q_u64(vreinterpretq_u64_u8(l), vreinterpretq_u64_u8(m))); + uint8x16_t nk_p0 = vreinterpretq_u8_u64( + vzip1q_u64(vreinterpretq_u64_u8(n), vreinterpretq_u64_u8(k))); + uint8x16_t nk_p1 = vreinterpretq_u8_u64( + vzip2q_u64(vreinterpretq_u64_u8(n), vreinterpretq_u64_u8(k))); +#else + uint8x16_t lm_p0 = vcombine_u8(vget_low_u8(l), vget_low_u8(m)); + uint8x16_t lm_p1 = vcombine_u8(vget_high_u8(l), vget_high_u8(m)); + uint8x16_t nk_p0 = vcombine_u8(vget_low_u8(n), vget_low_u8(k)); + uint8x16_t nk_p1 = vcombine_u8(vget_high_u8(n), vget_high_u8(k)); +#endif + // t0 = (L) (P0 + P1) << 8 + // t1 = (M) (P2 + P3) << 16 + uint8x16_t t0t1_tmp = veorq_u8(lm_p0, lm_p1); + uint8x16_t t0t1_h = vandq_u8(lm_p1, k48_32); + uint8x16_t t0t1_l = veorq_u8(t0t1_tmp, t0t1_h); + + // t2 = (N) (P4 + P5) << 24 + // t3 = (K) (P6 + P7) << 32 + uint8x16_t t2t3_tmp = veorq_u8(nk_p0, nk_p1); + uint8x16_t t2t3_h = vandq_u8(nk_p1, k16_00); + uint8x16_t t2t3_l = veorq_u8(t2t3_tmp, t2t3_h); + + // De-interleave +#if SSE2NEON_ARCH_AARCH64 + uint8x16_t t0 = vreinterpretq_u8_u64( + vuzp1q_u64(vreinterpretq_u64_u8(t0t1_l), vreinterpretq_u64_u8(t0t1_h))); + uint8x16_t t1 = vreinterpretq_u8_u64( + vuzp2q_u64(vreinterpretq_u64_u8(t0t1_l), vreinterpretq_u64_u8(t0t1_h))); + uint8x16_t t2 = vreinterpretq_u8_u64( + vuzp1q_u64(vreinterpretq_u64_u8(t2t3_l), vreinterpretq_u64_u8(t2t3_h))); + uint8x16_t t3 = vreinterpretq_u8_u64( + vuzp2q_u64(vreinterpretq_u64_u8(t2t3_l), vreinterpretq_u64_u8(t2t3_h))); +#else + uint8x16_t t1 = vcombine_u8(vget_high_u8(t0t1_l), vget_high_u8(t0t1_h)); + uint8x16_t t0 = vcombine_u8(vget_low_u8(t0t1_l), vget_low_u8(t0t1_h)); + uint8x16_t t3 = vcombine_u8(vget_high_u8(t2t3_l), vget_high_u8(t2t3_h)); + uint8x16_t t2 = vcombine_u8(vget_low_u8(t2t3_l), vget_low_u8(t2t3_h)); +#endif + // Shift the cross products + uint8x16_t t0_shift = vextq_u8(t0, t0, 15); // t0 << 8 + uint8x16_t t1_shift = vextq_u8(t1, t1, 14); // t1 << 16 + uint8x16_t t2_shift = vextq_u8(t2, t2, 13); // t2 << 24 + uint8x16_t t3_shift = vextq_u8(t3, t3, 12); // t3 << 32 + + // Accumulate the products + uint8x16_t cross1 = veorq_u8(t0_shift, t1_shift); + uint8x16_t cross2 = veorq_u8(t2_shift, t3_shift); + uint8x16_t mix = veorq_u8(d, cross1); + uint8x16_t r = veorq_u8(mix, cross2); + return vreinterpretq_u64_u8(r); +} +#endif // ARMv7 polyfill + + +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _sse2neon_vgetq_lane_s32 vgetq_lane_s32 +#else +// this inline macro is used as a wrapper around vgetq_lane_s32 to ensure its +// second argument is a compile time constant. +FORCE_INLINE int32_t _sse2neon_vgetq_lane_s32(int32x4_t vec, int lane) +{ + switch (lane) { + case 0: + return vgetq_lane_s32(vec, 0); + case 1: + return vgetq_lane_s32(vec, 1); + case 2: + return vgetq_lane_s32(vec, 2); + default: // case 3 + return vgetq_lane_s32(vec, 3); + } +} +#endif + +// C equivalent: +// __m128i _mm_shuffle_epi32_default(__m128i a, const int imm) { +// // imm must be a compile-time constant in range [0, 255] +// __m128i ret; +// ret[0] = a[(imm) & 0x3]; ret[1] = a[((imm) >> 2) & 0x3]; +// ret[2] = a[((imm) >> 4) & 0x03]; ret[3] = a[((imm) >> 6) & 0x03]; +// return ret; +// } +#define _mm_shuffle_epi32_default(a, imm) \ + vreinterpretq_m128i_s32(vsetq_lane_s32( \ + _sse2neon_vgetq_lane_s32(vreinterpretq_s32_m128i(a), \ + ((imm) >> 6) & 0x3), \ + vsetq_lane_s32( \ + _sse2neon_vgetq_lane_s32(vreinterpretq_s32_m128i(a), \ + ((imm) >> 4) & 0x3), \ + vsetq_lane_s32( \ + _sse2neon_vgetq_lane_s32(vreinterpretq_s32_m128i(a), \ + ((imm) >> 2) & 0x3), \ + vmovq_n_s32(_sse2neon_vgetq_lane_s32( \ + vreinterpretq_s32_m128i(a), (imm) & (0x3))), \ + 1), \ + 2), \ + 3)) + +// Takes the upper 64 bits of a and places it in the low end of the result +// Takes the lower 64 bits of a and places it into the high end of the result. +FORCE_INLINE __m128i _mm_shuffle_epi_1032(__m128i a) +{ + int32x2_t a32 = vget_high_s32(vreinterpretq_s32_m128i(a)); + int32x2_t a10 = vget_low_s32(vreinterpretq_s32_m128i(a)); + return vreinterpretq_m128i_s32(vcombine_s32(a32, a10)); +} + +// takes the lower two 32-bit values from a and swaps them and places in low end +// of result takes the higher two 32 bit values from a and swaps them and places +// in high end of result. +FORCE_INLINE __m128i _mm_shuffle_epi_2301(__m128i a) +{ + int32x2_t a01 = vrev64_s32(vget_low_s32(vreinterpretq_s32_m128i(a))); + int32x2_t a23 = vrev64_s32(vget_high_s32(vreinterpretq_s32_m128i(a))); + return vreinterpretq_m128i_s32(vcombine_s32(a01, a23)); +} + +// rotates the least significant 32 bits into the most significant 32 bits, and +// shifts the rest down +FORCE_INLINE __m128i _mm_shuffle_epi_0321(__m128i a) +{ + return vreinterpretq_m128i_s32( + vextq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(a), 1)); +} + +// rotates the most significant 32 bits into the least significant 32 bits, and +// shifts the rest up +FORCE_INLINE __m128i _mm_shuffle_epi_2103(__m128i a) +{ + return vreinterpretq_m128i_s32( + vextq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(a), 3)); +} + +// gets the lower 64 bits of a, and places it in the upper 64 bits +// gets the lower 64 bits of a and places it in the lower 64 bits +FORCE_INLINE __m128i _mm_shuffle_epi_1010(__m128i a) +{ + int32x2_t a10 = vget_low_s32(vreinterpretq_s32_m128i(a)); + return vreinterpretq_m128i_s32(vcombine_s32(a10, a10)); +} + +// gets the lower 64 bits of a, swaps the 0 and 1 elements, and places it in the +// lower 64 bits gets the lower 64 bits of a, and places it in the upper 64 bits +FORCE_INLINE __m128i _mm_shuffle_epi_1001(__m128i a) +{ + int32x2_t a01 = vrev64_s32(vget_low_s32(vreinterpretq_s32_m128i(a))); + int32x2_t a10 = vget_low_s32(vreinterpretq_s32_m128i(a)); + return vreinterpretq_m128i_s32(vcombine_s32(a01, a10)); +} + +// gets the lower 64 bits of a, swaps the 0 and 1 elements and places it in the +// upper 64 bits gets the lower 64 bits of a, swaps the 0 and 1 elements, and +// places it in the lower 64 bits +FORCE_INLINE __m128i _mm_shuffle_epi_0101(__m128i a) +{ + int32x2_t a01 = vrev64_s32(vget_low_s32(vreinterpretq_s32_m128i(a))); + return vreinterpretq_m128i_s32(vcombine_s32(a01, a01)); +} + +FORCE_INLINE __m128i _mm_shuffle_epi_2211(__m128i a) +{ + int32x2_t a11 = vdup_lane_s32(vget_low_s32(vreinterpretq_s32_m128i(a)), 1); + int32x2_t a22 = vdup_lane_s32(vget_high_s32(vreinterpretq_s32_m128i(a)), 0); + return vreinterpretq_m128i_s32(vcombine_s32(a11, a22)); +} + +FORCE_INLINE __m128i _mm_shuffle_epi_0122(__m128i a) +{ + int32x2_t a22 = vdup_lane_s32(vget_high_s32(vreinterpretq_s32_m128i(a)), 0); + int32x2_t a01 = vrev64_s32(vget_low_s32(vreinterpretq_s32_m128i(a))); + return vreinterpretq_m128i_s32(vcombine_s32(a22, a01)); +} + +FORCE_INLINE __m128i _mm_shuffle_epi_3332(__m128i a) +{ + int32x2_t a32 = vget_high_s32(vreinterpretq_s32_m128i(a)); + int32x2_t a33 = vdup_lane_s32(vget_high_s32(vreinterpretq_s32_m128i(a)), 1); + return vreinterpretq_m128i_s32(vcombine_s32(a32, a33)); +} + +#if SSE2NEON_ARCH_AARCH64 +#define _mm_shuffle_epi32_splat(a, imm) \ + vreinterpretq_m128i_s32(vdupq_laneq_s32(vreinterpretq_s32_m128i(a), (imm))) +#else +#define _mm_shuffle_epi32_splat(a, imm) \ + vreinterpretq_m128i_s32( \ + vdupq_n_s32(vgetq_lane_s32(vreinterpretq_s32_m128i(a), (imm)))) +#endif + +// NEON does not support a general purpose permute intrinsic. +// Shuffle single-precision (32-bit) floating-point elements in a using the +// control in imm8, and store the results in dst. +// +// C equivalent: +// __m128 _mm_shuffle_ps_default(__m128 a, __m128 b, const int imm) { +// // imm must be a compile-time constant in range [0, 255] +// __m128 ret; +// ret[0] = a[(imm) & 0x3]; ret[1] = a[((imm) >> 2) & 0x3]; +// ret[2] = b[((imm) >> 4) & 0x03]; ret[3] = b[((imm) >> 6) & 0x03]; +// return ret; +// } +// +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_ps + +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _sse2neon_vgetq_lane_f32 vgetq_lane_f32 +#define _sse2neon_vsetq_lane_f32 vsetq_lane_f32 +#else +// these inline macros are used as a wrappers to ensure the lane argument is a +// compile time constant. +FORCE_INLINE float32_t _sse2neon_vgetq_lane_f32(float32x4_t vec, int lane) +{ + switch (lane) { + case 0: + return vgetq_lane_f32(vec, 0); + case 1: + return vgetq_lane_f32(vec, 1); + case 2: + return vgetq_lane_f32(vec, 2); + default: // case 3 + return vgetq_lane_f32(vec, 3); + } +} +FORCE_INLINE float32x4_t _sse2neon_vsetq_lane_f32(float32_t value, + float32x4_t vec, + int lane) +{ + switch (lane) { + case 0: + return vsetq_lane_f32(value, vec, 0); + case 1: + return vsetq_lane_f32(value, vec, 1); + case 2: + return vsetq_lane_f32(value, vec, 2); + default: // case 3 + return vsetq_lane_f32(value, vec, 3); + } +} +#endif + +#define _mm_shuffle_ps_default(a, b, imm) \ + vreinterpretq_m128_f32(vsetq_lane_f32( \ + _sse2neon_vgetq_lane_f32(vreinterpretq_f32_m128(b), \ + ((imm) >> 6) & 0x3), \ + vsetq_lane_f32( \ + _sse2neon_vgetq_lane_f32(vreinterpretq_f32_m128(b), \ + ((imm) >> 4) & 0x3), \ + vsetq_lane_f32(_sse2neon_vgetq_lane_f32(vreinterpretq_f32_m128(a), \ + ((imm) >> 2) & 0x3), \ + vmovq_n_f32(_sse2neon_vgetq_lane_f32( \ + vreinterpretq_f32_m128(a), (imm) & (0x3))), \ + 1), \ + 2), \ + 3)) + +// Shuffle 16-bit integers in the low 64 bits of a using the control in imm8. +// Store the results in the low 64 bits of dst, with the high 64 bits being +// copied from a to dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shufflelo_epi16 +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_shufflelo_epi16_function(a, imm) \ + _sse2neon_define1( \ + __m128i, a, int16x8_t ret = vreinterpretq_s16_m128i(_a); \ + int16x4_t lowBits = vget_low_s16(ret); \ + ret = vsetq_lane_s16(vget_lane_s16(lowBits, (imm) & (0x3)), ret, 0); \ + ret = vsetq_lane_s16(vget_lane_s16(lowBits, ((imm) >> 2) & 0x3), ret, \ + 1); \ + ret = vsetq_lane_s16(vget_lane_s16(lowBits, ((imm) >> 4) & 0x3), ret, \ + 2); \ + ret = vsetq_lane_s16(vget_lane_s16(lowBits, ((imm) >> 6) & 0x3), ret, \ + 3); \ + _sse2neon_return(vreinterpretq_m128i_s16(ret));) +#else + +// this inline macro is used as a wrapper around vget_lane_s16 to ensure its +// second argument is a compile time constant. +FORCE_INLINE int16_t _sse2neon_vget_lane_s16(int16x4_t vec, int lane) +{ + switch (lane) { + case 0: + return vget_lane_s16(vec, 0); + case 1: + return vget_lane_s16(vec, 1); + case 2: + return vget_lane_s16(vec, 2); + default: // case 3 + return vget_lane_s16(vec, 3); + } +} + +FORCE_INLINE __m128i _mm_shufflelo_epi16_function(__m128i a, int imm) +{ + int16x8_t ret = vreinterpretq_s16_m128i(a); + int16x4_t lowBits = vget_low_s16(ret); + ret = + vsetq_lane_s16(_sse2neon_vget_lane_s16(lowBits, (imm) & (0x3)), ret, 0); + ret = vsetq_lane_s16(_sse2neon_vget_lane_s16(lowBits, ((imm) >> 2) & 0x3), + ret, 1); + ret = vsetq_lane_s16(_sse2neon_vget_lane_s16(lowBits, ((imm) >> 4) & 0x3), + ret, 2); + ret = vsetq_lane_s16(_sse2neon_vget_lane_s16(lowBits, ((imm) >> 6) & 0x3), + ret, 3); + return vreinterpretq_m128i_s16(ret); +} +#endif + +// Shuffle 16-bit integers in the high 64 bits of a using the control in imm8. +// Store the results in the high 64 bits of dst, with the low 64 bits being +// copied from a to dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shufflehi_epi16 +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_shufflehi_epi16_function(a, imm) \ + _sse2neon_define1( \ + __m128i, a, int16x8_t ret = vreinterpretq_s16_m128i(_a); \ + int16x4_t highBits = vget_high_s16(ret); \ + ret = vsetq_lane_s16(vget_lane_s16(highBits, (imm) & (0x3)), ret, 4); \ + ret = vsetq_lane_s16(vget_lane_s16(highBits, ((imm) >> 2) & 0x3), ret, \ + 5); \ + ret = vsetq_lane_s16(vget_lane_s16(highBits, ((imm) >> 4) & 0x3), ret, \ + 6); \ + ret = vsetq_lane_s16(vget_lane_s16(highBits, ((imm) >> 6) & 0x3), ret, \ + 7); \ + _sse2neon_return(vreinterpretq_m128i_s16(ret));) +#else +FORCE_INLINE __m128i _mm_shufflehi_epi16_function(__m128i a, int imm) +{ + int16x8_t ret = vreinterpretq_s16_m128i(a); + int16x4_t highBits = vget_high_s16(ret); + ret = vsetq_lane_s16(_sse2neon_vget_lane_s16(highBits, (imm) & (0x3)), ret, + 4); + ret = vsetq_lane_s16(_sse2neon_vget_lane_s16(highBits, ((imm) >> 2) & 0x3), + ret, 5); + ret = vsetq_lane_s16(_sse2neon_vget_lane_s16(highBits, ((imm) >> 4) & 0x3), + ret, 6); + ret = vsetq_lane_s16(_sse2neon_vget_lane_s16(highBits, ((imm) >> 6) & 0x3), + ret, 7); + return vreinterpretq_m128i_s16(ret); +} +#endif + +/* MMX */ + +//_mm_empty is a no-op on arm +FORCE_INLINE void _mm_empty(void) {} + +/* SSE */ + +// Add packed single-precision (32-bit) floating-point elements in a and b, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_ps +FORCE_INLINE __m128 _mm_add_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_f32( + vaddq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +} + +// Add the lower single-precision (32-bit) floating-point element in a and b, +// store the result in the lower element of dst, and copy the upper 3 packed +// elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_ss +FORCE_INLINE __m128 _mm_add_ss(__m128 a, __m128 b) +{ + float32_t b0 = vgetq_lane_f32(vreinterpretq_f32_m128(b), 0); + float32x4_t value = vsetq_lane_f32(b0, vdupq_n_f32(0), 0); + // the upper values in the result must be the remnants of . + return vreinterpretq_m128_f32(vaddq_f32(a, value)); +} + +// Compute the bitwise AND of packed single-precision (32-bit) floating-point +// elements in a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_and_ps +FORCE_INLINE __m128 _mm_and_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_s32( + vandq_s32(vreinterpretq_s32_m128(a), vreinterpretq_s32_m128(b))); +} + +// Compute the bitwise NOT of packed single-precision (32-bit) floating-point +// elements in a and then AND with b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_andnot_ps +FORCE_INLINE __m128 _mm_andnot_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_s32( + vbicq_s32(vreinterpretq_s32_m128(b), + vreinterpretq_s32_m128(a))); // *NOTE* argument swap +} + +// Average packed unsigned 16-bit integers in a and b, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_avg_pu16 +FORCE_INLINE __m64 _mm_avg_pu16(__m64 a, __m64 b) +{ + return vreinterpret_m64_u16( + vrhadd_u16(vreinterpret_u16_m64(a), vreinterpret_u16_m64(b))); +} + +// Average packed unsigned 8-bit integers in a and b, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_avg_pu8 +FORCE_INLINE __m64 _mm_avg_pu8(__m64 a, __m64 b) +{ + return vreinterpret_m64_u8( + vrhadd_u8(vreinterpret_u8_m64(a), vreinterpret_u8_m64(b))); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// for equality, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_ps +FORCE_INLINE __m128 _mm_cmpeq_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_u32( + vceqq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b for equality, store the result in the lower element of dst, and copy the +// upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_ss +FORCE_INLINE __m128 _mm_cmpeq_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmpeq_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// for greater-than-or-equal, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpge_ps +FORCE_INLINE __m128 _mm_cmpge_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_u32( + vcgeq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b for greater-than-or-equal, store the result in the lower element of dst, +// and copy the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpge_ss +FORCE_INLINE __m128 _mm_cmpge_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmpge_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// for greater-than, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_ps +FORCE_INLINE __m128 _mm_cmpgt_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_u32( + vcgtq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b for greater-than, store the result in the lower element of dst, and copy +// the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_ss +FORCE_INLINE __m128 _mm_cmpgt_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmpgt_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// for less-than-or-equal, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmple_ps +FORCE_INLINE __m128 _mm_cmple_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_u32( + vcleq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b for less-than-or-equal, store the result in the lower element of dst, and +// copy the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmple_ss +FORCE_INLINE __m128 _mm_cmple_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmple_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// for less-than, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_ps +FORCE_INLINE __m128 _mm_cmplt_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_u32( + vcltq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b for less-than, store the result in the lower element of dst, and copy the +// upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_ss +FORCE_INLINE __m128 _mm_cmplt_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmplt_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// for not-equal, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpneq_ps +FORCE_INLINE __m128 _mm_cmpneq_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_u32(vmvnq_u32( + vceqq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b)))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b for not-equal, store the result in the lower element of dst, and copy the +// upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpneq_ss +FORCE_INLINE __m128 _mm_cmpneq_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmpneq_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// for not-greater-than-or-equal, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnge_ps +FORCE_INLINE __m128 _mm_cmpnge_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_u32(vmvnq_u32( + vcgeq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b)))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b for not-greater-than-or-equal, store the result in the lower element of +// dst, and copy the upper 3 packed elements from a to the upper elements of +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnge_ss +FORCE_INLINE __m128 _mm_cmpnge_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmpnge_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// for not-greater-than, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpngt_ps +FORCE_INLINE __m128 _mm_cmpngt_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_u32(vmvnq_u32( + vcgtq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b)))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b for not-greater-than, store the result in the lower element of dst, and +// copy the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpngt_ss +FORCE_INLINE __m128 _mm_cmpngt_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmpngt_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// for not-less-than-or-equal, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnle_ps +FORCE_INLINE __m128 _mm_cmpnle_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_u32(vmvnq_u32( + vcleq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b)))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b for not-less-than-or-equal, store the result in the lower element of dst, +// and copy the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnle_ss +FORCE_INLINE __m128 _mm_cmpnle_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmpnle_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// for not-less-than, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnlt_ps +FORCE_INLINE __m128 _mm_cmpnlt_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_u32(vmvnq_u32( + vcltq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b)))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b for not-less-than, store the result in the lower element of dst, and copy +// the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnlt_ss +FORCE_INLINE __m128 _mm_cmpnlt_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmpnlt_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// to see if neither is NaN, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpord_ps +// +// See also: +// http://stackoverflow.com/questions/8627331/what-does-ordered-unordered-comparison-mean +// http://stackoverflow.com/questions/29349621/neon-isnanval-intrinsics +FORCE_INLINE __m128 _mm_cmpord_ps(__m128 a, __m128 b) +{ + // Note: NEON does not have ordered compare builtin + // Need to compare a eq a and b eq b to check for NaN + // Do AND of results to get final + uint32x4_t ceqaa = + vceqq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a)); + uint32x4_t ceqbb = + vceqq_f32(vreinterpretq_f32_m128(b), vreinterpretq_f32_m128(b)); + return vreinterpretq_m128_u32(vandq_u32(ceqaa, ceqbb)); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b to see if neither is NaN, store the result in the lower element of dst, and +// copy the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpord_ss +FORCE_INLINE __m128 _mm_cmpord_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmpord_ps(a, b)); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b +// to see if either is NaN, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpunord_ps +FORCE_INLINE __m128 _mm_cmpunord_ps(__m128 a, __m128 b) +{ + uint32x4_t f32a = + vceqq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a)); + uint32x4_t f32b = + vceqq_f32(vreinterpretq_f32_m128(b), vreinterpretq_f32_m128(b)); + return vreinterpretq_m128_u32(vmvnq_u32(vandq_u32(f32a, f32b))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b to see if either is NaN, store the result in the lower element of dst, and +// copy the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpunord_ss +FORCE_INLINE __m128 _mm_cmpunord_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_cmpunord_ps(a, b)); +} + +// Compare the lower single-precision (32-bit) floating-point element in a and b +// for equality, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comieq_ss +FORCE_INLINE int _mm_comieq_ss(__m128 a, __m128 b) +{ + uint32x4_t a_eq_b = + vceqq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b)); + return vgetq_lane_u32(a_eq_b, 0) & 0x1; +} + +// Compare the lower single-precision (32-bit) floating-point element in a and b +// for greater-than-or-equal, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comige_ss +FORCE_INLINE int _mm_comige_ss(__m128 a, __m128 b) +{ + uint32x4_t a_ge_b = + vcgeq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b)); + return vgetq_lane_u32(a_ge_b, 0) & 0x1; +} + +// Compare the lower single-precision (32-bit) floating-point element in a and b +// for greater-than, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comigt_ss +FORCE_INLINE int _mm_comigt_ss(__m128 a, __m128 b) +{ + uint32x4_t a_gt_b = + vcgtq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b)); + return vgetq_lane_u32(a_gt_b, 0) & 0x1; +} + +// Compare the lower single-precision (32-bit) floating-point element in a and b +// for less-than-or-equal, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comile_ss +FORCE_INLINE int _mm_comile_ss(__m128 a, __m128 b) +{ + uint32x4_t a_le_b = + vcleq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b)); + return vgetq_lane_u32(a_le_b, 0) & 0x1; +} + +// Compare the lower single-precision (32-bit) floating-point element in a and b +// for less-than, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comilt_ss +FORCE_INLINE int _mm_comilt_ss(__m128 a, __m128 b) +{ + uint32x4_t a_lt_b = + vcltq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b)); + return vgetq_lane_u32(a_lt_b, 0) & 0x1; +} + +// Compare the lower single-precision (32-bit) floating-point element in a and b +// for not-equal, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comineq_ss +FORCE_INLINE int _mm_comineq_ss(__m128 a, __m128 b) +{ + return !_mm_comieq_ss(a, b); +} + +// Convert packed signed 32-bit integers in b to packed single-precision +// (32-bit) floating-point elements, store the results in the lower 2 elements +// of dst, and copy the upper 2 packed elements from a to the upper elements of +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvt_pi2ps +FORCE_INLINE __m128 _mm_cvt_pi2ps(__m128 a, __m64 b) +{ + return vreinterpretq_m128_f32( + vcombine_f32(vcvt_f32_s32(vreinterpret_s32_m64(b)), + vget_high_f32(vreinterpretq_f32_m128(a)))); +} + +// Convert packed single-precision (32-bit) floating-point elements in a to +// packed 32-bit integers, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvt_ps2pi +FORCE_INLINE __m64 _mm_cvt_ps2pi(__m128 a) +{ +#if SSE2NEON_ARCH_AARCH64 || defined(__ARM_FEATURE_DIRECTED_ROUNDING) + return vreinterpret_m64_s32( + vget_low_s32(vcvtnq_s32_f32(vrndiq_f32(vreinterpretq_f32_m128(a))))); +#else + return vreinterpret_m64_s32(vcvt_s32_f32(vget_low_f32( + vreinterpretq_f32_m128(_mm_round_ps(a, _MM_FROUND_CUR_DIRECTION))))); +#endif +} + +// Convert the signed 32-bit integer b to a single-precision (32-bit) +// floating-point element, store the result in the lower element of dst, and +// copy the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvt_si2ss +FORCE_INLINE __m128 _mm_cvt_si2ss(__m128 a, int b) +{ + return vreinterpretq_m128_f32(vsetq_lane_f32( + _sse2neon_static_cast(float, b), vreinterpretq_f32_m128(a), 0)); +} + +// Convert the lower single-precision (32-bit) floating-point element in a to a +// 32-bit integer, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvt_ss2si +FORCE_INLINE int _mm_cvt_ss2si(__m128 a) +{ +#if SSE2NEON_ARCH_AARCH64 || defined(__ARM_FEATURE_DIRECTED_ROUNDING) + return vgetq_lane_s32(vcvtnq_s32_f32(vrndiq_f32(vreinterpretq_f32_m128(a))), + 0); +#else + float32_t data = vgetq_lane_f32( + vreinterpretq_f32_m128(_mm_round_ps(a, _MM_FROUND_CUR_DIRECTION)), 0); + return _sse2neon_static_cast(int32_t, data); +#endif +} + +// Convert packed 16-bit integers in a to packed single-precision (32-bit) +// floating-point elements, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpi16_ps +FORCE_INLINE __m128 _mm_cvtpi16_ps(__m64 a) +{ + return vreinterpretq_m128_f32( + vcvtq_f32_s32(vmovl_s16(vreinterpret_s16_m64(a)))); +} + +// Convert packed 32-bit integers in b to packed single-precision (32-bit) +// floating-point elements, store the results in the lower 2 elements of dst, +// and copy the upper 2 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpi32_ps +FORCE_INLINE __m128 _mm_cvtpi32_ps(__m128 a, __m64 b) +{ + return vreinterpretq_m128_f32( + vcombine_f32(vcvt_f32_s32(vreinterpret_s32_m64(b)), + vget_high_f32(vreinterpretq_f32_m128(a)))); +} + +// Convert packed signed 32-bit integers in a to packed single-precision +// (32-bit) floating-point elements, store the results in the lower 2 elements +// of dst, then convert the packed signed 32-bit integers in b to +// single-precision (32-bit) floating-point element, and store the results in +// the upper 2 elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpi32x2_ps +FORCE_INLINE __m128 _mm_cvtpi32x2_ps(__m64 a, __m64 b) +{ + return vreinterpretq_m128_f32(vcvtq_f32_s32( + vcombine_s32(vreinterpret_s32_m64(a), vreinterpret_s32_m64(b)))); +} + +// Convert the lower packed 8-bit integers in a to packed single-precision +// (32-bit) floating-point elements, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpi8_ps +FORCE_INLINE __m128 _mm_cvtpi8_ps(__m64 a) +{ + return vreinterpretq_m128_f32(vcvtq_f32_s32( + vmovl_s16(vget_low_s16(vmovl_s8(vreinterpret_s8_m64(a)))))); +} + +// Convert packed single-precision (32-bit) floating-point elements in a to +// packed 16-bit integers, and store the results in dst. Note: this intrinsic +// will generate 0x7FFF, rather than 0x8000, for input values between 0x7FFF and +// 0x7FFFFFFF. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_pi16 +FORCE_INLINE __m64 _mm_cvtps_pi16(__m128 a) +{ + return vreinterpret_m64_s16( + vqmovn_s32(vreinterpretq_s32_m128i(_mm_cvtps_epi32(a)))); +} + +// Convert packed single-precision (32-bit) floating-point elements in a to +// packed 32-bit integers, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_pi32 +#define _mm_cvtps_pi32(a) _mm_cvt_ps2pi(a) + +// Convert packed single-precision (32-bit) floating-point elements in a to +// packed 8-bit integers, and store the results in lower 4 elements of dst. +// Note: this intrinsic will generate 0x7F, rather than 0x80, for input values +// between 0x7F and 0x7FFFFFFF. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_pi8 +FORCE_INLINE __m64 _mm_cvtps_pi8(__m128 a) +{ + return vreinterpret_m64_s8(vqmovn_s16( + vcombine_s16(vreinterpret_s16_m64(_mm_cvtps_pi16(a)), vdup_n_s16(0)))); +} + +// Convert packed unsigned 16-bit integers in a to packed single-precision +// (32-bit) floating-point elements, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpu16_ps +FORCE_INLINE __m128 _mm_cvtpu16_ps(__m64 a) +{ + return vreinterpretq_m128_f32( + vcvtq_f32_u32(vmovl_u16(vreinterpret_u16_m64(a)))); +} + +// Convert the lower packed unsigned 8-bit integers in a to packed +// single-precision (32-bit) floating-point elements, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpu8_ps +FORCE_INLINE __m128 _mm_cvtpu8_ps(__m64 a) +{ + return vreinterpretq_m128_f32(vcvtq_f32_u32( + vmovl_u16(vget_low_u16(vmovl_u8(vreinterpret_u8_m64(a)))))); +} + +// Convert the signed 32-bit integer b to a single-precision (32-bit) +// floating-point element, store the result in the lower element of dst, and +// copy the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi32_ss +#define _mm_cvtsi32_ss(a, b) _mm_cvt_si2ss(a, b) + +// Convert the signed 64-bit integer b to a single-precision (32-bit) +// floating-point element, store the result in the lower element of dst, and +// copy the upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi64_ss +FORCE_INLINE __m128 _mm_cvtsi64_ss(__m128 a, int64_t b) +{ + return vreinterpretq_m128_f32(vsetq_lane_f32( + _sse2neon_static_cast(float, b), vreinterpretq_f32_m128(a), 0)); +} + +// Copy the lower single-precision (32-bit) floating-point element of a to dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtss_f32 +FORCE_INLINE float _mm_cvtss_f32(__m128 a) +{ + return vgetq_lane_f32(vreinterpretq_f32_m128(a), 0); +} + +// Convert the lower single-precision (32-bit) floating-point element in a to a +// 32-bit integer, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtss_si32 +#define _mm_cvtss_si32(a) _mm_cvt_ss2si(a) + +// Convert the lower single-precision (32-bit) floating-point element in a to a +// 64-bit integer, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtss_si64 +FORCE_INLINE int64_t _mm_cvtss_si64(__m128 a) +{ +#if SSE2NEON_ARCH_AARCH64 || defined(__ARM_FEATURE_DIRECTED_ROUNDING) + return _sse2neon_static_cast( + int64_t, vgetq_lane_f32(vrndiq_f32(vreinterpretq_f32_m128(a)), 0)); +#else + float32_t data = vgetq_lane_f32( + vreinterpretq_f32_m128(_mm_round_ps(a, _MM_FROUND_CUR_DIRECTION)), 0); + return _sse2neon_static_cast(int64_t, data); +#endif +} + +// Convert packed single-precision (32-bit) floating-point elements in a to +// packed 32-bit integers with truncation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtt_ps2pi +FORCE_INLINE __m64 _mm_cvtt_ps2pi(__m128 a) +{ + float32x4_t f = vreinterpretq_f32_m128(a); + int32x4_t cvt = vcvtq_s32_f32(f); + int32x4_t result = _sse2neon_cvtps_epi32_fixup(f, cvt); + return vreinterpret_m64_s32(vget_low_s32(result)); +} + +// Convert the lower single-precision (32-bit) floating-point element in a to a +// 32-bit integer with truncation, and store the result in dst. +// x86 returns INT32_MIN for NaN and out-of-range values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtt_ss2si +FORCE_INLINE int _mm_cvtt_ss2si(__m128 a) +{ + return _sse2neon_cvtf_s32(vgetq_lane_f32(vreinterpretq_f32_m128(a), 0)); +} + +// Convert packed single-precision (32-bit) floating-point elements in a to +// packed 32-bit integers with truncation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttps_pi32 +#define _mm_cvttps_pi32(a) _mm_cvtt_ps2pi(a) + +// Convert the lower single-precision (32-bit) floating-point element in a to a +// 32-bit integer with truncation, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttss_si32 +#define _mm_cvttss_si32(a) _mm_cvtt_ss2si(a) + +// Convert the lower single-precision (32-bit) floating-point element in a to a +// 64-bit integer with truncation, and store the result in dst. +// x86 returns INT64_MIN for NaN and out-of-range values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttss_si64 +FORCE_INLINE int64_t _mm_cvttss_si64(__m128 a) +{ + return _sse2neon_cvtf_s64(vgetq_lane_f32(vreinterpretq_f32_m128(a), 0)); +} + +// Divide packed single-precision (32-bit) floating-point elements in a by +// packed elements in b, and store the results in dst. +// Due to ARMv7-A NEON's lack of a precise division intrinsic, we implement +// division by multiplying a by b's reciprocal before using the Newton-Raphson +// method to approximate the results. Use SSE2NEON_PRECISE_DIV for improved +// precision on ARMv7. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_div_ps +FORCE_INLINE __m128 _mm_div_ps(__m128 a, __m128 b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128_f32( + vdivq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +#else + float32x4_t _a = vreinterpretq_f32_m128(a); + float32x4_t _b = vreinterpretq_f32_m128(b); + float32x4_t recip = vrecpeq_f32(_b); + recip = vmulq_f32(recip, vrecpsq_f32(recip, _b)); +#if SSE2NEON_PRECISE_DIV + // Additional Newton-Raphson iteration for accuracy + recip = vmulq_f32(recip, vrecpsq_f32(recip, _b)); +#endif + return vreinterpretq_m128_f32(vmulq_f32(_a, recip)); +#endif +} + +// Divide the lower single-precision (32-bit) floating-point element in a by the +// lower single-precision (32-bit) floating-point element in b, store the result +// in the lower element of dst, and copy the upper 3 packed elements from a to +// the upper elements of dst. +// Warning: ARMv7-A does not produce the same result compared to Intel and not +// IEEE-compliant. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_div_ss +FORCE_INLINE __m128 _mm_div_ss(__m128 a, __m128 b) +{ + float32_t value = + vgetq_lane_f32(vreinterpretq_f32_m128(_mm_div_ps(a, b)), 0); + return vreinterpretq_m128_f32( + vsetq_lane_f32(value, vreinterpretq_f32_m128(a), 0)); +} + +// Extract a 16-bit integer from a, selected with imm8, and store the result in +// the lower element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_extract_pi16 +// imm must be a compile-time constant in range [0, 3] +#define _mm_extract_pi16(a, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 3), \ + _sse2neon_static_cast(int32_t, \ + vget_lane_u16(vreinterpret_u16_m64(a), (imm)))) + +// Free aligned memory that was allocated with _mm_malloc. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_free +// +// WARNING: Only use on pointers from _mm_malloc(). On Windows, passing memory +// from malloc/calloc/new corrupts the heap. See _mm_malloc() for details. +#if !defined(SSE2NEON_ALLOC_DEFINED) +FORCE_INLINE void _mm_free(void *addr) +{ +#if defined(_WIN32) + _aligned_free(addr); +#else + free(addr); +#endif +} +#endif + +FORCE_INLINE uint64_t _sse2neon_get_fpcr(void) +{ + uint64_t value; +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG + value = _ReadStatusReg(ARM64_FPCR); +#else + __asm__ __volatile__("mrs %0, FPCR" : "=r"(value)); /* read */ +#endif + return value; +} + +FORCE_INLINE void _sse2neon_set_fpcr(uint64_t value) +{ +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG + _WriteStatusReg(ARM64_FPCR, value); +#else + __asm__ __volatile__("msr FPCR, %0" ::"r"(value)); /* write */ +#endif +} + +// Macro: Get the flush zero bits from the MXCSR control and status register. +// The flush zero may contain any of the following flags: _MM_FLUSH_ZERO_ON or +// _MM_FLUSH_ZERO_OFF +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_GET_FLUSH_ZERO_MODE +FORCE_INLINE unsigned int _sse2neon_mm_get_flush_zero_mode(void) +{ + union { + fpcr_bitfield field; +#if SSE2NEON_ARCH_AARCH64 + uint64_t value; +#else + uint32_t value; +#endif + } r; + +#if SSE2NEON_ARCH_AARCH64 + r.value = _sse2neon_get_fpcr(); +#else + __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ +#endif + + return r.field.bit24 ? _MM_FLUSH_ZERO_ON : _MM_FLUSH_ZERO_OFF; +} + +// Macro: Get the rounding mode bits from the MXCSR control and status register. +// The rounding mode may contain any of the following flags: _MM_ROUND_NEAREST, +// _MM_ROUND_DOWN, _MM_ROUND_UP, _MM_ROUND_TOWARD_ZERO +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_GET_ROUNDING_MODE +FORCE_INLINE unsigned int _MM_GET_ROUNDING_MODE(void) +{ + const int mask = FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO; + switch (fegetround() & mask) { + case FE_TONEAREST: + return _MM_ROUND_NEAREST; + case FE_DOWNWARD: + return _MM_ROUND_DOWN; + case FE_UPWARD: + return _MM_ROUND_UP; + case FE_TOWARDZERO: + return _MM_ROUND_TOWARD_ZERO; + default: + // fegetround() must return _MM_ROUND_NEAREST, _MM_ROUND_DOWN, + // _MM_ROUND_UP, _MM_ROUND_TOWARD_ZERO on success. all the other error + // cases we treat them as FE_TOWARDZERO (truncate). + return _MM_ROUND_TOWARD_ZERO; + } +} + +// Copy a to dst, and insert the 16-bit integer i into dst at the location +// specified by imm8. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_insert_pi16 +// imm must be a compile-time constant in range [0, 3] +#define _mm_insert_pi16(a, b, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 3), \ + vreinterpret_m64_s16(vset_lane_s16((b), vreinterpret_s16_m64(a), (imm)))) + +// Load 128-bits (composed of 4 packed single-precision (32-bit) floating-point +// elements) from memory into dst. mem_addr must be aligned on a 16-byte +// boundary or a general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_ps +FORCE_INLINE __m128 _mm_load_ps(const float *p) +{ + return vreinterpretq_m128_f32(vld1q_f32(p)); +} + +// Load a single-precision (32-bit) floating-point element from memory into all +// elements of dst. +// +// dst[31:0] := MEM[mem_addr+31:mem_addr] +// dst[63:32] := MEM[mem_addr+31:mem_addr] +// dst[95:64] := MEM[mem_addr+31:mem_addr] +// dst[127:96] := MEM[mem_addr+31:mem_addr] +// +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_ps1 +#define _mm_load_ps1 _mm_load1_ps + +// Load a single-precision (32-bit) floating-point element from memory into the +// lower of dst, and zero the upper 3 elements. mem_addr does not need to be +// aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_ss +FORCE_INLINE __m128 _mm_load_ss(const float *p) +{ + return vreinterpretq_m128_f32(vsetq_lane_f32(*p, vdupq_n_f32(0), 0)); +} + +// Load a single-precision (32-bit) floating-point element from memory into all +// elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load1_ps +FORCE_INLINE __m128 _mm_load1_ps(const float *p) +{ + return vreinterpretq_m128_f32(vld1q_dup_f32(p)); +} + +// Load 2 single-precision (32-bit) floating-point elements from memory into the +// upper 2 elements of dst, and copy the lower 2 elements from a to dst. +// mem_addr does not need to be aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadh_pi +FORCE_INLINE __m128 _mm_loadh_pi(__m128 a, __m64 const *p) +{ + return vreinterpretq_m128_f32(vcombine_f32( + vget_low_f32(a), + vld1_f32(_sse2neon_reinterpret_cast(const float32_t *, p)))); +} + +// Load 2 single-precision (32-bit) floating-point elements from memory into the +// lower 2 elements of dst, and copy the upper 2 elements from a to dst. +// mem_addr does not need to be aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadl_pi +FORCE_INLINE __m128 _mm_loadl_pi(__m128 a, __m64 const *p) +{ + return vreinterpretq_m128_f32( + vcombine_f32(vld1_f32(_sse2neon_reinterpret_cast(const float32_t *, p)), + vget_high_f32(a))); +} + +// Load 4 single-precision (32-bit) floating-point elements from memory into dst +// in reverse order. mem_addr must be aligned on a 16-byte boundary or a +// general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadr_ps +FORCE_INLINE __m128 _mm_loadr_ps(const float *p) +{ + float32x4_t v = vrev64q_f32(vld1q_f32(p)); + return vreinterpretq_m128_f32(vextq_f32(v, v, 2)); +} + +// Load 128-bits (composed of 4 packed single-precision (32-bit) floating-point +// elements) from memory into dst. mem_addr does not need to be aligned on any +// particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_ps +FORCE_INLINE __m128 _mm_loadu_ps(const float *p) +{ + // for neon, alignment doesn't matter, so _mm_load_ps and _mm_loadu_ps are + // equivalent for neon + return vreinterpretq_m128_f32(vld1q_f32(p)); +} + +// Load unaligned 16-bit integer from memory into the first element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si16 +FORCE_INLINE __m128i _mm_loadu_si16(const void *p) +{ + return vreinterpretq_m128i_s16(vsetq_lane_s16( + *_sse2neon_reinterpret_cast(const unaligned_int16_t *, p), + vdupq_n_s16(0), 0)); +} + +// Load unaligned 64-bit integer from memory into the first element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si64 +FORCE_INLINE __m128i _mm_loadu_si64(const void *p) +{ + return vreinterpretq_m128i_s64(vsetq_lane_s64( + *_sse2neon_reinterpret_cast(const unaligned_int64_t *, p), + vdupq_n_s64(0), 0)); +} + +// Allocate size bytes of memory, aligned to the alignment specified in align, +// and return a pointer to the allocated memory. _mm_free should be used to free +// memory that is allocated with _mm_malloc. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_malloc +// +// Memory allocated by this function MUST be freed with _mm_free(), NOT with +// standard free() or delete. Mixing allocators: +// - Windows: CORRUPTS HEAP (free on _aligned_malloc memory is invalid) +// - Other platforms: Works (maps to free), but pair for Windows portability +// +// Incorrect usage (causes memory corruption on Windows): +// void *ptr = _mm_malloc(1024, 16); +// free(ptr); // WRONG - use _mm_free() instead +// +// Implementation notes: +// - Windows: Uses _aligned_malloc() +// - Other platforms: Uses posix_memalign() or malloc() for small alignments +// +// See also: _mm_free() for deallocation requirements. +#if !defined(SSE2NEON_ALLOC_DEFINED) +FORCE_INLINE void *_mm_malloc(size_t size, size_t align) +{ +#if defined(_WIN32) + return _aligned_malloc(size, align); +#else + void *ptr; + if (align == 1) + return malloc(size); + if (align == 2 || (sizeof(void *) == 8 && align == 4)) + align = sizeof(void *); + if (!posix_memalign(&ptr, align, size)) + return ptr; + return NULL; +#endif +} +#endif + +// Conditionally store 8-bit integer elements from a into memory using mask +// (elements are not stored when the highest bit is not set in the corresponding +// element) and a non-temporal memory hint. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskmove_si64 +FORCE_INLINE void _mm_maskmove_si64(__m64 a, __m64 mask, char *mem_addr) +{ + int8x8_t shr_mask = vshr_n_s8(vreinterpret_s8_m64(mask), 7); + __m128 b = _mm_load_ps(_sse2neon_reinterpret_cast(const float *, mem_addr)); + int8x8_t masked = + vbsl_s8(vreinterpret_u8_s8(shr_mask), vreinterpret_s8_m64(a), + vreinterpret_s8_u64(vget_low_u64(vreinterpretq_u64_m128(b)))); + vst1_s8(_sse2neon_reinterpret_cast(int8_t *, mem_addr), masked); +} + +// Conditionally store 8-bit integer elements from a into memory using mask +// (elements are not stored when the highest bit is not set in the corresponding +// element) and a non-temporal memory hint. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_maskmovq +#define _m_maskmovq(a, mask, mem_addr) _mm_maskmove_si64(a, mask, mem_addr) + +// Compare packed signed 16-bit integers in a and b, and store packed maximum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_pi16 +FORCE_INLINE __m64 _mm_max_pi16(__m64 a, __m64 b) +{ + return vreinterpret_m64_s16( + vmax_s16(vreinterpret_s16_m64(a), vreinterpret_s16_m64(b))); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b, +// and store packed maximum values in dst. dst does not follow the IEEE Standard +// for Floating-Point Arithmetic (IEEE 754) maximum value when inputs are NaN or +// signed-zero values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_ps +FORCE_INLINE __m128 _mm_max_ps(__m128 a, __m128 b) +{ +#if SSE2NEON_PRECISE_MINMAX + float32x4_t _a = vreinterpretq_f32_m128(a); + float32x4_t _b = vreinterpretq_f32_m128(b); + return vreinterpretq_m128_f32(vbslq_f32(vcgtq_f32(_a, _b), _a, _b)); +#else + return vreinterpretq_m128_f32( + vmaxq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +#endif +} + +// Compare packed unsigned 8-bit integers in a and b, and store packed maximum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_pu8 +FORCE_INLINE __m64 _mm_max_pu8(__m64 a, __m64 b) +{ + return vreinterpret_m64_u8( + vmax_u8(vreinterpret_u8_m64(a), vreinterpret_u8_m64(b))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b, store the maximum value in the lower element of dst, and copy the upper 3 +// packed elements from a to the upper element of dst. dst does not follow the +// IEEE Standard for Floating-Point Arithmetic (IEEE 754) maximum value when +// inputs are NaN or signed-zero values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_ss +FORCE_INLINE __m128 _mm_max_ss(__m128 a, __m128 b) +{ + float32_t value = vgetq_lane_f32(_mm_max_ps(a, b), 0); + return vreinterpretq_m128_f32( + vsetq_lane_f32(value, vreinterpretq_f32_m128(a), 0)); +} + +// Compare packed signed 16-bit integers in a and b, and store packed minimum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_pi16 +FORCE_INLINE __m64 _mm_min_pi16(__m64 a, __m64 b) +{ + return vreinterpret_m64_s16( + vmin_s16(vreinterpret_s16_m64(a), vreinterpret_s16_m64(b))); +} + +// Compare packed single-precision (32-bit) floating-point elements in a and b, +// and store packed minimum values in dst. dst does not follow the IEEE Standard +// for Floating-Point Arithmetic (IEEE 754) minimum value when inputs are NaN or +// signed-zero values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_ps +FORCE_INLINE __m128 _mm_min_ps(__m128 a, __m128 b) +{ +#if SSE2NEON_PRECISE_MINMAX + float32x4_t _a = vreinterpretq_f32_m128(a); + float32x4_t _b = vreinterpretq_f32_m128(b); + return vreinterpretq_m128_f32(vbslq_f32(vcltq_f32(_a, _b), _a, _b)); +#else + return vreinterpretq_m128_f32( + vminq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +#endif +} + +// Compare packed unsigned 8-bit integers in a and b, and store packed minimum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_pu8 +FORCE_INLINE __m64 _mm_min_pu8(__m64 a, __m64 b) +{ + return vreinterpret_m64_u8( + vmin_u8(vreinterpret_u8_m64(a), vreinterpret_u8_m64(b))); +} + +// Compare the lower single-precision (32-bit) floating-point elements in a and +// b, store the minimum value in the lower element of dst, and copy the upper 3 +// packed elements from a to the upper element of dst. dst does not follow the +// IEEE Standard for Floating-Point Arithmetic (IEEE 754) minimum value when +// inputs are NaN or signed-zero values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_ss +FORCE_INLINE __m128 _mm_min_ss(__m128 a, __m128 b) +{ + float32_t value = vgetq_lane_f32(_mm_min_ps(a, b), 0); + return vreinterpretq_m128_f32( + vsetq_lane_f32(value, vreinterpretq_f32_m128(a), 0)); +} + +// Move the lower single-precision (32-bit) floating-point element from b to the +// lower element of dst, and copy the upper 3 packed elements from a to the +// upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_move_ss +FORCE_INLINE __m128 _mm_move_ss(__m128 a, __m128 b) +{ + return vreinterpretq_m128_f32( + vsetq_lane_f32(vgetq_lane_f32(vreinterpretq_f32_m128(b), 0), + vreinterpretq_f32_m128(a), 0)); +} + +// Move the upper 2 single-precision (32-bit) floating-point elements from b to +// the lower 2 elements of dst, and copy the upper 2 elements from a to the +// upper 2 elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movehl_ps +FORCE_INLINE __m128 _mm_movehl_ps(__m128 a, __m128 b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128_u64( + vzip2q_u64(vreinterpretq_u64_m128(b), vreinterpretq_u64_m128(a))); +#else + float32x2_t a32 = vget_high_f32(vreinterpretq_f32_m128(a)); + float32x2_t b32 = vget_high_f32(vreinterpretq_f32_m128(b)); + return vreinterpretq_m128_f32(vcombine_f32(b32, a32)); +#endif +} + +// Move the lower 2 single-precision (32-bit) floating-point elements from b to +// the upper 2 elements of dst, and copy the lower 2 elements from a to the +// lower 2 elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movelh_ps +FORCE_INLINE __m128 _mm_movelh_ps(__m128 __A, __m128 __B) +{ + float32x2_t a10 = vget_low_f32(vreinterpretq_f32_m128(__A)); + float32x2_t b10 = vget_low_f32(vreinterpretq_f32_m128(__B)); + return vreinterpretq_m128_f32(vcombine_f32(a10, b10)); +} + +// Create mask from the most significant bit of each 8-bit element in a, and +// store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movemask_pi8 +FORCE_INLINE int _mm_movemask_pi8(__m64 a) +{ + uint8x8_t input = vreinterpret_u8_m64(a); +#if SSE2NEON_ARCH_AARCH64 + static const int8_t shift[8] = {0, 1, 2, 3, 4, 5, 6, 7}; + uint8x8_t tmp = vshr_n_u8(input, 7); + return vaddv_u8(vshl_u8(tmp, vld1_s8(shift))); +#else + // Note: Uses the same method as _mm_movemask_epi8. + uint8x8_t msbs = vshr_n_u8(input, 7); + uint32x2_t bits = vreinterpret_u32_u8(msbs); + bits = vsra_n_u32(bits, bits, 7); + bits = vsra_n_u32(bits, bits, 14); + uint8x8_t output = vreinterpret_u8_u32(bits); + return (vget_lane_u8(output, 4) << 4) | vget_lane_u8(output, 0); +#endif +} + +// Set each bit of mask dst based on the most significant bit of the +// corresponding packed single-precision (32-bit) floating-point element in a. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movemask_ps +FORCE_INLINE int _mm_movemask_ps(__m128 a) +{ + uint32x4_t input = vreinterpretq_u32_m128(a); +#if SSE2NEON_ARCH_AARCH64 + static const int32_t shift[4] = {0, 1, 2, 3}; + uint32x4_t tmp = vshrq_n_u32(input, 31); + return _sse2neon_static_cast(int, + vaddvq_u32(vshlq_u32(tmp, vld1q_s32(shift)))); +#else + // Note: Uses the same method as _mm_movemask_epi8. + uint32x4_t msbs = vshrq_n_u32(input, 31); + uint64x2_t bits = vreinterpretq_u64_u32(msbs); + bits = vsraq_n_u64(bits, bits, 31); + uint8x16_t output = vreinterpretq_u8_u64(bits); + return (vgetq_lane_u8(output, 8) << 2) | vgetq_lane_u8(output, 0); +#endif +} + +// Multiply packed single-precision (32-bit) floating-point elements in a and b, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_ps +FORCE_INLINE __m128 _mm_mul_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_f32( + vmulq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +} + +// Multiply the lower single-precision (32-bit) floating-point element in a and +// b, store the result in the lower element of dst, and copy the upper 3 packed +// elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_ss +FORCE_INLINE __m128 _mm_mul_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_mul_ps(a, b)); +} + +// Multiply the packed unsigned 16-bit integers in a and b, producing +// intermediate 32-bit integers, and store the high 16 bits of the intermediate +// integers in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhi_pu16 +FORCE_INLINE __m64 _mm_mulhi_pu16(__m64 a, __m64 b) +{ + return vreinterpret_m64_u16(vshrn_n_u32( + vmull_u16(vreinterpret_u16_m64(a), vreinterpret_u16_m64(b)), 16)); +} + +// Compute the bitwise OR of packed single-precision (32-bit) floating-point +// elements in a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_or_ps +FORCE_INLINE __m128 _mm_or_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_s32( + vorrq_s32(vreinterpretq_s32_m128(a), vreinterpretq_s32_m128(b))); +} + +// Average packed unsigned 8-bit integers in a and b, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pavgb +#define _m_pavgb(a, b) _mm_avg_pu8(a, b) + +// Average packed unsigned 16-bit integers in a and b, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pavgw +#define _m_pavgw(a, b) _mm_avg_pu16(a, b) + +// Extract a 16-bit integer from a, selected with imm8, and store the result in +// the lower element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pextrw +#define _m_pextrw(a, imm) _mm_extract_pi16(a, imm) + +// Copy a to dst, and insert the 16-bit integer i into dst at the location +// specified by imm8. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=m_pinsrw +#define _m_pinsrw(a, i, imm) _mm_insert_pi16(a, i, imm) + +// Compare packed signed 16-bit integers in a and b, and store packed maximum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pmaxsw +#define _m_pmaxsw(a, b) _mm_max_pi16(a, b) + +// Compare packed unsigned 8-bit integers in a and b, and store packed maximum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pmaxub +#define _m_pmaxub(a, b) _mm_max_pu8(a, b) + +// Compare packed signed 16-bit integers in a and b, and store packed minimum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pminsw +#define _m_pminsw(a, b) _mm_min_pi16(a, b) + +// Compare packed unsigned 8-bit integers in a and b, and store packed minimum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pminub +#define _m_pminub(a, b) _mm_min_pu8(a, b) + +// Create mask from the most significant bit of each 8-bit element in a, and +// store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pmovmskb +#define _m_pmovmskb(a) _mm_movemask_pi8(a) + +// Multiply the packed unsigned 16-bit integers in a and b, producing +// intermediate 32-bit integers, and store the high 16 bits of the intermediate +// integers in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pmulhuw +#define _m_pmulhuw(a, b) _mm_mulhi_pu16(a, b) + +// Fetch the line of data from memory that contains address p to a location in +// the cache hierarchy specified by the locality hint i. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_prefetch +FORCE_INLINE void _mm_prefetch(char const *p, int i) +{ + (void) i; +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG + switch (i) { + case _MM_HINT_NTA: + __prefetch2(p, 1); + break; + case _MM_HINT_T0: + __prefetch2(p, 0); + break; + case _MM_HINT_T1: + __prefetch2(p, 2); + break; + case _MM_HINT_T2: + __prefetch2(p, 4); + break; + } +#else + switch (i) { + case _MM_HINT_NTA: + __builtin_prefetch(p, 0, 0); + break; + case _MM_HINT_T0: + __builtin_prefetch(p, 0, 3); + break; + case _MM_HINT_T1: + __builtin_prefetch(p, 0, 2); + break; + case _MM_HINT_T2: + __builtin_prefetch(p, 0, 1); + break; + } +#endif +} + +// Compute the absolute differences of packed unsigned 8-bit integers in a and +// b, then horizontally sum each consecutive 8 differences to produce four +// unsigned 16-bit integers, and pack these unsigned 16-bit integers in the low +// 16 bits of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=m_psadbw +#define _m_psadbw(a, b) _mm_sad_pu8(a, b) + +// Shuffle 16-bit integers in a using the control in imm8, and store the results +// in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_m_pshufw +#define _m_pshufw(a, imm) _mm_shuffle_pi16(a, imm) + +// Compute the approximate reciprocal of packed single-precision (32-bit) +// floating-point elements in a, and store the results in dst. The maximum +// relative error for this approximation is less than 1.5*2^-12. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_rcp_ps +FORCE_INLINE __m128 _mm_rcp_ps(__m128 in) +{ + float32x4_t _in = vreinterpretq_f32_m128(in); + float32x4_t recip = vrecpeq_f32(_in); + recip = vmulq_f32(recip, vrecpsq_f32(recip, _in)); +#if SSE2NEON_PRECISE_DIV + // Additional Newton-Raphson iteration for accuracy + recip = vmulq_f32(recip, vrecpsq_f32(recip, _in)); +#endif + return vreinterpretq_m128_f32(recip); +} + +// Compute the approximate reciprocal of the lower single-precision (32-bit) +// floating-point element in a, store the result in the lower element of dst, +// and copy the upper 3 packed elements from a to the upper elements of dst. The +// maximum relative error for this approximation is less than 1.5*2^-12. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_rcp_ss +FORCE_INLINE __m128 _mm_rcp_ss(__m128 a) +{ + return _mm_move_ss(a, _mm_rcp_ps(a)); +} + +// Compute the approximate reciprocal square root of packed single-precision +// (32-bit) floating-point elements in a, and store the results in dst. The +// maximum relative error for this approximation is less than 1.5*2^-12. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_rsqrt_ps +FORCE_INLINE __m128 _mm_rsqrt_ps(__m128 in) +{ + float32x4_t _in = vreinterpretq_f32_m128(in); + float32x4_t out = vrsqrteq_f32(_in); + + // Generate masks for detecting whether input has any 0.0f/-0.0f + // (which becomes positive/negative infinity by IEEE-754 arithmetic rules). + const uint32x4_t pos_inf = vdupq_n_u32(0x7F800000); + const uint32x4_t neg_inf = vdupq_n_u32(0xFF800000); + const uint32x4_t has_pos_zero = + vceqq_u32(pos_inf, vreinterpretq_u32_f32(out)); + const uint32x4_t has_neg_zero = + vceqq_u32(neg_inf, vreinterpretq_u32_f32(out)); + + out = vmulq_f32(out, vrsqrtsq_f32(vmulq_f32(_in, out), out)); +#if SSE2NEON_PRECISE_SQRT + // Additional Newton-Raphson iteration for accuracy + out = vmulq_f32(out, vrsqrtsq_f32(vmulq_f32(_in, out), out)); +#endif + + // Set output vector element to infinity/negative-infinity if + // the corresponding input vector element is 0.0f/-0.0f. + out = vbslq_f32(has_pos_zero, vreinterpretq_f32_u32(pos_inf), out); + out = vbslq_f32(has_neg_zero, vreinterpretq_f32_u32(neg_inf), out); + + return vreinterpretq_m128_f32(out); +} + +// Compute the approximate reciprocal square root of the lower single-precision +// (32-bit) floating-point element in a, store the result in the lower element +// of dst, and copy the upper 3 packed elements from a to the upper elements of +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_rsqrt_ss +FORCE_INLINE __m128 _mm_rsqrt_ss(__m128 in) +{ + return vsetq_lane_f32(vgetq_lane_f32(_mm_rsqrt_ps(in), 0), in, 0); +} + +// Compute the absolute differences of packed unsigned 8-bit integers in a and +// b, then horizontally sum each consecutive 8 differences to produce four +// unsigned 16-bit integers, and pack these unsigned 16-bit integers in the low +// 16 bits of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sad_pu8 +FORCE_INLINE __m64 _mm_sad_pu8(__m64 a, __m64 b) +{ + uint64x1_t t = vpaddl_u32(vpaddl_u16( + vpaddl_u8(vabd_u8(vreinterpret_u8_m64(a), vreinterpret_u8_m64(b))))); + return vreinterpret_m64_u16( + vset_lane_u16(_sse2neon_static_cast(uint16_t, vget_lane_u64(t, 0)), + vdup_n_u16(0), 0)); +} + +// Macro: Set the flush zero bits of the MXCSR control and status register to +// the value in unsigned 32-bit integer a. The flush zero may contain any of the +// following flags: _MM_FLUSH_ZERO_ON or _MM_FLUSH_ZERO_OFF +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_SET_FLUSH_ZERO_MODE +FORCE_INLINE void _sse2neon_mm_set_flush_zero_mode(unsigned int flag) +{ + // AArch32 Advanced SIMD arithmetic always uses the Flush-to-zero setting, + // regardless of the value of the FZ bit. + union { + fpcr_bitfield field; +#if SSE2NEON_ARCH_AARCH64 + uint64_t value; +#else + uint32_t value; +#endif + } r; + +#if SSE2NEON_ARCH_AARCH64 + r.value = _sse2neon_get_fpcr(); +#else + __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ +#endif + + r.field.bit24 = (flag & _MM_FLUSH_ZERO_MASK) == _MM_FLUSH_ZERO_ON; + +#if SSE2NEON_ARCH_AARCH64 + _sse2neon_set_fpcr(r.value); +#else + __asm__ __volatile__("vmsr FPSCR, %0" ::"r"(r)); /* write */ +#endif +} + +// Set packed single-precision (32-bit) floating-point elements in dst with the +// supplied values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_ps +FORCE_INLINE __m128 _mm_set_ps(float w, float z, float y, float x) +{ + float ALIGN_STRUCT(16) data[4] = {x, y, z, w}; + return vreinterpretq_m128_f32(vld1q_f32(data)); +} + +// Broadcast single-precision (32-bit) floating-point value a to all elements of +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_ps1 +FORCE_INLINE __m128 _mm_set_ps1(float _w) +{ + return vreinterpretq_m128_f32(vdupq_n_f32(_w)); +} + +// Macro: Set the rounding mode bits of the MXCSR control and status register to +// the value in unsigned 32-bit integer a. The rounding mode may contain any of +// the following flags: _MM_ROUND_NEAREST, _MM_ROUND_DOWN, _MM_ROUND_UP, +// _MM_ROUND_TOWARD_ZERO +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_SET_ROUNDING_MODE +FORCE_INLINE void _MM_SET_ROUNDING_MODE(int rounding) +{ + switch (rounding) { + case _MM_ROUND_NEAREST: + rounding = FE_TONEAREST; + break; + case _MM_ROUND_DOWN: + rounding = FE_DOWNWARD; + break; + case _MM_ROUND_UP: + rounding = FE_UPWARD; + break; + case _MM_ROUND_TOWARD_ZERO: + rounding = FE_TOWARDZERO; + break; + default: + // rounding must be _MM_ROUND_NEAREST, _MM_ROUND_DOWN, _MM_ROUND_UP, + // _MM_ROUND_TOWARD_ZERO. all the other invalid values we treat them as + // FE_TOWARDZERO (truncate). + rounding = FE_TOWARDZERO; + } + fesetround(rounding); +} + +// Copy single-precision (32-bit) floating-point element a to the lower element +// of dst, and zero the upper 3 elements. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_ss +FORCE_INLINE __m128 _mm_set_ss(float a) +{ + return vreinterpretq_m128_f32(vsetq_lane_f32(a, vdupq_n_f32(0), 0)); +} + +// Broadcast single-precision (32-bit) floating-point value a to all elements of +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_ps +FORCE_INLINE __m128 _mm_set1_ps(float _w) +{ + return vreinterpretq_m128_f32(vdupq_n_f32(_w)); +} + +// Set the MXCSR control and status register with the value in unsigned 32-bit +// integer a. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setcsr +// +// Supported MXCSR fields: +// - Bits 13-14: Rounding mode (RM) - SUPPORTED via ARM FPCR/FPSCR +// - Bit 15 (FZ): Flush-to-zero mode - SUPPORTED via ARM FPCR/FPSCR bit 24 +// - Bit 6 (DAZ): Denormals-are-zero mode - SUPPORTED (unified with FZ on ARM) +// +// Unsupported MXCSR fields (silently ignored): +// - Bits 0-5: Exception flags (IE, DE, ZE, OE, UE, PE) - NOT EMULATED +// - Bits 7-12: Exception masks - NOT EMULATED +// See "MXCSR Exception Flags - NOT EMULATED" documentation block for details. +// +// ARM Platform Behavior: +// - ARM FPCR/FPSCR bit 24 provides unified FZ+DAZ behavior. Setting either +// _MM_FLUSH_ZERO_ON or _MM_DENORMALS_ZERO_ON enables the same ARM bit. +// - ARMv7 NEON: "Flush-to-zero mode always enabled" per ARM ARM (impl may vary) +// - ARMv8: FPCR.FZ correctly controls denormal handling for NEON operations +FORCE_INLINE void _mm_setcsr(unsigned int a) +{ + _MM_SET_ROUNDING_MODE(a & _MM_ROUND_MASK); + // ARM FPCR.bit24 handles both FZ and DAZ - set if either is requested + _MM_SET_FLUSH_ZERO_MODE( + (a & _MM_FLUSH_ZERO_MASK) | + ((a & _MM_DENORMALS_ZERO_MASK) ? _MM_FLUSH_ZERO_ON : 0)); +} + +// Get the unsigned 32-bit value of the MXCSR control and status register. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_getcsr +// +// Returned MXCSR fields: +// - Bits 13-14: Rounding mode (RM) - Reflects current ARM FPCR/FPSCR setting +// - Bit 15 (FZ): Flush-to-zero mode - Reflects ARM FPCR/FPSCR bit 24 +// - Bit 6 (DAZ): Denormals-are-zero mode - Mirrors FZ (unified on ARM) +// +// Fields always returned as zero (NOT EMULATED): +// - Bits 0-5: Exception flags - ALWAYS 0 (exceptions not tracked) +// - Bits 7-12: Exception masks - ALWAYS 0 (use _MM_GET_EXCEPTION_MASK() +// instead) See "MXCSR Exception Flags - NOT EMULATED" documentation block for +// details. +// +// ARM Platform Behavior: +// - When ARM FPCR/FPSCR bit 24 is enabled, both FZ and DAZ bits are reported +// as set (the original setting cannot be distinguished). +// - ARMv7 NEON: Returned bits reflect FPSCR, but NEON always flushes denormals +FORCE_INLINE unsigned int _mm_getcsr(void) +{ + return _MM_GET_ROUNDING_MODE() | _MM_GET_FLUSH_ZERO_MODE() | + _MM_GET_DENORMALS_ZERO_MODE(); +} + +// Set packed single-precision (32-bit) floating-point elements in dst with the +// supplied values in reverse order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_ps +FORCE_INLINE __m128 _mm_setr_ps(float w, float z, float y, float x) +{ + float ALIGN_STRUCT(16) data[4] = {w, z, y, x}; + return vreinterpretq_m128_f32(vld1q_f32(data)); +} + +// Return vector of type __m128 with all elements set to zero. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setzero_ps +FORCE_INLINE __m128 _mm_setzero_ps(void) +{ + return vreinterpretq_m128_f32(vdupq_n_f32(0)); +} + +// Shuffle 16-bit integers in a using the control in imm8, and store the results +// in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_pi16 +// imm must be a compile-time constant in range [0, 255] +#ifdef _sse2neon_shuffle +#define _mm_shuffle_pi16(a, imm) \ + __extension__({ \ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); \ + vreinterpret_m64_s16( \ + vshuffle_s16(vreinterpret_s16_m64(a), vreinterpret_s16_m64(a), \ + ((imm) & 0x3), (((imm) >> 2) & 0x3), \ + (((imm) >> 4) & 0x3), (((imm) >> 6) & 0x3))); \ + }) +#elif SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_shuffle_pi16(a, imm) \ + _sse2neon_define1( \ + __m64, a, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); int16x4_t ret; \ + ret = vmov_n_s16( \ + vget_lane_s16(vreinterpret_s16_m64(_a), (imm) & (0x3))); \ + ret = vset_lane_s16( \ + vget_lane_s16(vreinterpret_s16_m64(_a), ((imm) >> 2) & 0x3), ret, \ + 1); \ + ret = vset_lane_s16( \ + vget_lane_s16(vreinterpret_s16_m64(_a), ((imm) >> 4) & 0x3), ret, \ + 2); \ + ret = vset_lane_s16( \ + vget_lane_s16(vreinterpret_s16_m64(_a), ((imm) >> 6) & 0x3), ret, \ + 3); \ + _sse2neon_return(vreinterpret_m64_s16(ret));) +#else +FORCE_INLINE __m64 _mm_shuffle_pi16(__m64 a, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + int16x4_t ret; + ret = vmov_n_s16( + _sse2neon_vget_lane_s16(vreinterpret_s16_m64(a), (imm) & (0x3))); + ret = vset_lane_s16( + _sse2neon_vget_lane_s16(vreinterpret_s16_m64(a), ((imm) >> 2) & 0x3), + ret, 1); + ret = vset_lane_s16( + _sse2neon_vget_lane_s16(vreinterpret_s16_m64(a), ((imm) >> 4) & 0x3), + ret, 2); + ret = vset_lane_s16( + _sse2neon_vget_lane_s16(vreinterpret_s16_m64(a), ((imm) >> 6) & 0x3), + ret, 3); + return vreinterpret_m64_s16(ret); +} +#endif + +// Perform a serializing operation on all store-to-memory instructions that were +// issued prior to this instruction. Guarantees that every store instruction +// that precedes, in program order, is globally visible before any store +// instruction which follows the fence in program order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sfence +FORCE_INLINE void _mm_sfence(void) +{ + _sse2neon_smp_mb(); +} + +// Perform a serializing operation on all load-from-memory and store-to-memory +// instructions that were issued prior to this instruction. Guarantees that +// every memory access that precedes, in program order, the memory fence +// instruction is globally visible before any memory instruction which follows +// the fence in program order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mfence +FORCE_INLINE void _mm_mfence(void) +{ + _sse2neon_smp_mb(); +} + +// Perform a serializing operation on all load-from-memory instructions that +// were issued prior to this instruction. Guarantees that every load instruction +// that precedes, in program order, is globally visible before any load +// instruction which follows the fence in program order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_lfence +FORCE_INLINE void _mm_lfence(void) +{ + _sse2neon_smp_mb(); +} + +// FORCE_INLINE __m128 _mm_shuffle_ps(__m128 a, __m128 b, const int imm) +// imm must be a compile-time constant in range [0, 255] +#ifdef _sse2neon_shuffle +#define _mm_shuffle_ps(a, b, imm) \ + __extension__({ \ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); \ + float32x4_t _input1 = vreinterpretq_f32_m128(a); \ + float32x4_t _input2 = vreinterpretq_f32_m128(b); \ + float32x4_t _shuf = \ + vshuffleq_s32(_input1, _input2, (imm) & (0x3), ((imm) >> 2) & 0x3, \ + (((imm) >> 4) & 0x3) + 4, (((imm) >> 6) & 0x3) + 4); \ + vreinterpretq_m128_f32(_shuf); \ + }) +#elif SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) // generic +#define _mm_shuffle_ps(a, b, imm) \ + _sse2neon_define2( \ + __m128, a, b, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); __m128 ret; \ + switch (imm) { \ + case _MM_SHUFFLE(1, 0, 3, 2): \ + ret = _mm_shuffle_ps_1032(_a, _b); \ + break; \ + case _MM_SHUFFLE(2, 3, 0, 1): \ + ret = _mm_shuffle_ps_2301(_a, _b); \ + break; \ + case _MM_SHUFFLE(0, 3, 2, 1): \ + ret = _mm_shuffle_ps_0321(_a, _b); \ + break; \ + case _MM_SHUFFLE(2, 1, 0, 3): \ + ret = _mm_shuffle_ps_2103(_a, _b); \ + break; \ + case _MM_SHUFFLE(1, 0, 1, 0): \ + ret = _mm_movelh_ps(_a, _b); \ + break; \ + case _MM_SHUFFLE(1, 0, 0, 1): \ + ret = _mm_shuffle_ps_1001(_a, _b); \ + break; \ + case _MM_SHUFFLE(0, 1, 0, 1): \ + ret = _mm_shuffle_ps_0101(_a, _b); \ + break; \ + case _MM_SHUFFLE(3, 2, 1, 0): \ + ret = _mm_shuffle_ps_3210(_a, _b); \ + break; \ + case _MM_SHUFFLE(0, 0, 1, 1): \ + ret = _mm_shuffle_ps_0011(_a, _b); \ + break; \ + case _MM_SHUFFLE(0, 0, 2, 2): \ + ret = _mm_shuffle_ps_0022(_a, _b); \ + break; \ + case _MM_SHUFFLE(2, 2, 0, 0): \ + ret = _mm_shuffle_ps_2200(_a, _b); \ + break; \ + case _MM_SHUFFLE(3, 2, 0, 2): \ + ret = _mm_shuffle_ps_3202(_a, _b); \ + break; \ + case _MM_SHUFFLE(3, 2, 3, 2): \ + ret = _mm_movehl_ps(_b, _a); \ + break; \ + case _MM_SHUFFLE(1, 1, 3, 3): \ + ret = _mm_shuffle_ps_1133(_a, _b); \ + break; \ + case _MM_SHUFFLE(2, 0, 1, 0): \ + ret = _mm_shuffle_ps_2010(_a, _b); \ + break; \ + case _MM_SHUFFLE(2, 0, 0, 1): \ + ret = _mm_shuffle_ps_2001(_a, _b); \ + break; \ + case _MM_SHUFFLE(2, 0, 3, 2): \ + ret = _mm_shuffle_ps_2032(_a, _b); \ + break; \ + default: \ + ret = _mm_shuffle_ps_default(_a, _b, (imm)); \ + break; \ + } _sse2neon_return(ret);) +#else // pure C (MSVC C mode) +FORCE_INLINE __m128 _mm_shuffle_ps(__m128 a, __m128 b, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + __m128 ret; + switch (imm) { + case _MM_SHUFFLE(1, 0, 3, 2): + ret = _mm_shuffle_ps_1032(a, b); + break; + case _MM_SHUFFLE(2, 3, 0, 1): + ret = _mm_shuffle_ps_2301(a, b); + break; + case _MM_SHUFFLE(0, 3, 2, 1): + ret = _mm_shuffle_ps_0321(a, b); + break; + case _MM_SHUFFLE(2, 1, 0, 3): + ret = _mm_shuffle_ps_2103(a, b); + break; + case _MM_SHUFFLE(1, 0, 1, 0): + ret = _mm_movelh_ps(a, b); + break; + case _MM_SHUFFLE(1, 0, 0, 1): + ret = _mm_shuffle_ps_1001(a, b); + break; + case _MM_SHUFFLE(0, 1, 0, 1): + ret = _mm_shuffle_ps_0101(a, b); + break; + case _MM_SHUFFLE(3, 2, 1, 0): + ret = _mm_shuffle_ps_3210(a, b); + break; + case _MM_SHUFFLE(0, 0, 1, 1): + ret = _mm_shuffle_ps_0011(a, b); + break; + case _MM_SHUFFLE(0, 0, 2, 2): + ret = _mm_shuffle_ps_0022(a, b); + break; + case _MM_SHUFFLE(2, 2, 0, 0): + ret = _mm_shuffle_ps_2200(a, b); + break; + case _MM_SHUFFLE(3, 2, 0, 2): + ret = _mm_shuffle_ps_3202(a, b); + break; + case _MM_SHUFFLE(3, 2, 3, 2): + ret = _mm_movehl_ps(b, a); + break; + case _MM_SHUFFLE(1, 1, 3, 3): + ret = _mm_shuffle_ps_1133(a, b); + break; + case _MM_SHUFFLE(2, 0, 1, 0): + ret = _mm_shuffle_ps_2010(a, b); + break; + case _MM_SHUFFLE(2, 0, 0, 1): + ret = _mm_shuffle_ps_2001(a, b); + break; + case _MM_SHUFFLE(2, 0, 3, 2): + ret = _mm_shuffle_ps_2032(a, b); + break; + default: + ret = _mm_shuffle_ps_default(a, b, imm); + break; + } + return ret; +} +#endif + +// Compute the square root of packed single-precision (32-bit) floating-point +// elements in a, and store the results in dst. +// Due to ARMv7-A NEON's lack of a precise square root intrinsic, we implement +// square root by multiplying input in with its reciprocal square root before +// using the Newton-Raphson method to approximate the results. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sqrt_ps +FORCE_INLINE __m128 _mm_sqrt_ps(__m128 in) +{ +#if SSE2NEON_ARCH_AARCH64 && !SSE2NEON_PRECISE_SQRT + return vreinterpretq_m128_f32(vsqrtq_f32(vreinterpretq_f32_m128(in))); +#else + float32x4_t _in = vreinterpretq_f32_m128(in); + float32x4_t recip = vrsqrteq_f32(_in); + + // Test for vrsqrteq_f32(0) -> infinity case (both +Inf and -Inf). + // vrsqrteq_f32(+0) = +Inf, vrsqrteq_f32(-0) = -Inf + // Change recip to zero so that s * 1/sqrt(s) preserves signed zero: + // +0 * 0 = +0, -0 * 0 = -0 (IEEE-754 sign rule) + const uint32x4_t abs_mask = vdupq_n_u32(0x7FFFFFFF); + const uint32x4_t pos_inf = vdupq_n_u32(0x7F800000); + const uint32x4_t div_by_zero = + vceqq_u32(pos_inf, vandq_u32(abs_mask, vreinterpretq_u32_f32(recip))); + recip = vreinterpretq_f32_u32( + vandq_u32(vmvnq_u32(div_by_zero), vreinterpretq_u32_f32(recip))); + + recip = vmulq_f32(vrsqrtsq_f32(vmulq_f32(recip, recip), _in), recip); + // Additional Newton-Raphson iteration for accuracy + recip = vmulq_f32(vrsqrtsq_f32(vmulq_f32(recip, recip), _in), recip); + + // sqrt(s) = s * 1/sqrt(s) + return vreinterpretq_m128_f32(vmulq_f32(_in, recip)); +#endif +} + +// Compute the square root of the lower single-precision (32-bit) floating-point +// element in a, store the result in the lower element of dst, and copy the +// upper 3 packed elements from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sqrt_ss +FORCE_INLINE __m128 _mm_sqrt_ss(__m128 in) +{ + float32_t value = + vgetq_lane_f32(vreinterpretq_f32_m128(_mm_sqrt_ps(in)), 0); + return vreinterpretq_m128_f32( + vsetq_lane_f32(value, vreinterpretq_f32_m128(in), 0)); +} + +// Store 128-bits (composed of 4 packed single-precision (32-bit) floating-point +// elements) from a into memory. mem_addr must be aligned on a 16-byte boundary +// or a general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_ps +FORCE_INLINE void _mm_store_ps(float *p, __m128 a) +{ + vst1q_f32(p, vreinterpretq_f32_m128(a)); +} + +// Store the lower single-precision (32-bit) floating-point element from a into +// 4 contiguous elements in memory. mem_addr must be aligned on a 16-byte +// boundary or a general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_ps1 +FORCE_INLINE void _mm_store_ps1(float *p, __m128 a) +{ + float32_t a0 = vgetq_lane_f32(vreinterpretq_f32_m128(a), 0); + vst1q_f32(p, vdupq_n_f32(a0)); +} + +// Store the lower single-precision (32-bit) floating-point element from a into +// memory. mem_addr does not need to be aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_ss +FORCE_INLINE void _mm_store_ss(float *p, __m128 a) +{ + vst1q_lane_f32(p, vreinterpretq_f32_m128(a), 0); +} + +// Store the lower single-precision (32-bit) floating-point element from a into +// 4 contiguous elements in memory. mem_addr must be aligned on a 16-byte +// boundary or a general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store1_ps +#define _mm_store1_ps _mm_store_ps1 + +// Store the upper 2 single-precision (32-bit) floating-point elements from a +// into memory. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeh_pi +FORCE_INLINE void _mm_storeh_pi(__m64 *p, __m128 a) +{ + *p = vreinterpret_m64_f32(vget_high_f32(a)); +} + +// Store the lower 2 single-precision (32-bit) floating-point elements from a +// into memory. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storel_pi +FORCE_INLINE void _mm_storel_pi(__m64 *p, __m128 a) +{ + *p = vreinterpret_m64_f32(vget_low_f32(a)); +} + +// Store 4 single-precision (32-bit) floating-point elements from a into memory +// in reverse order. mem_addr must be aligned on a 16-byte boundary or a +// general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storer_ps +FORCE_INLINE void _mm_storer_ps(float *p, __m128 a) +{ + float32x4_t tmp = vrev64q_f32(vreinterpretq_f32_m128(a)); + float32x4_t rev = vextq_f32(tmp, tmp, 2); + vst1q_f32(p, rev); +} + +// Store 128-bits (composed of 4 packed single-precision (32-bit) floating-point +// elements) from a into memory. mem_addr does not need to be aligned on any +// particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_ps +FORCE_INLINE void _mm_storeu_ps(float *p, __m128 a) +{ + vst1q_f32(p, vreinterpretq_f32_m128(a)); +} + +// Stores 16-bits of integer data a at the address p. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si16 +FORCE_INLINE void _mm_storeu_si16(void *p, __m128i a) +{ + vst1q_lane_s16(_sse2neon_reinterpret_cast(int16_t *, p), + vreinterpretq_s16_m128i(a), 0); +} + +// Stores 64-bits of integer data a at the address p. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si64 +FORCE_INLINE void _mm_storeu_si64(void *p, __m128i a) +{ + vst1q_lane_s64(_sse2neon_reinterpret_cast(int64_t *, p), + vreinterpretq_s64_m128i(a), 0); +} + +// Store 64-bits of integer data from a into memory using a non-temporal memory +// hint. +// Note: ARM lacks direct non-temporal store for single 64-bit value. STNP +// requires pair stores; __builtin_nontemporal_store may generate regular store +// on AArch64 for sub-128-bit types. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_pi +FORCE_INLINE void _mm_stream_pi(__m64 *p, __m64 a) +{ +#if __has_builtin(__builtin_nontemporal_store) + __builtin_nontemporal_store(a, p); +#else + vst1_s64(_sse2neon_reinterpret_cast(int64_t *, p), vreinterpret_s64_m64(a)); +#endif +} + +// Store 128-bits (composed of 4 packed single-precision (32-bit) floating- +// point elements) from a into memory using a non-temporal memory hint. +// Note: On AArch64, __builtin_nontemporal_store generates STNP (Store +// Non-temporal Pair), providing true non-temporal hint for 128-bit stores. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_ps +FORCE_INLINE void _mm_stream_ps(float *p, __m128 a) +{ +#if __has_builtin(__builtin_nontemporal_store) + __builtin_nontemporal_store(a, + _sse2neon_reinterpret_cast(float32x4_t *, p)); +#else + vst1q_f32(p, vreinterpretq_f32_m128(a)); +#endif +} + +// Subtract packed single-precision (32-bit) floating-point elements in b from +// packed single-precision (32-bit) floating-point elements in a, and store the +// results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_ps +FORCE_INLINE __m128 _mm_sub_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_f32( + vsubq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +} + +// Subtract the lower single-precision (32-bit) floating-point element in b from +// the lower single-precision (32-bit) floating-point element in a, store the +// result in the lower element of dst, and copy the upper 3 packed elements from +// a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_ss +FORCE_INLINE __m128 _mm_sub_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_sub_ps(a, b)); +} + +// Macro: Transpose the 4x4 matrix formed by the 4 rows of single-precision +// (32-bit) floating-point elements in row0, row1, row2, and row3, and store the +// transposed matrix in these vectors (row0 now contains column 0, etc.). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=MM_TRANSPOSE4_PS +#ifndef _MM_TRANSPOSE4_PS +#define _MM_TRANSPOSE4_PS(row0, row1, row2, row3) \ + do { \ + float32x4x2_t ROW01 = vtrnq_f32(row0, row1); \ + float32x4x2_t ROW23 = vtrnq_f32(row2, row3); \ + row0 = vcombine_f32(vget_low_f32(ROW01.val[0]), \ + vget_low_f32(ROW23.val[0])); \ + row1 = vcombine_f32(vget_low_f32(ROW01.val[1]), \ + vget_low_f32(ROW23.val[1])); \ + row2 = vcombine_f32(vget_high_f32(ROW01.val[0]), \ + vget_high_f32(ROW23.val[0])); \ + row3 = vcombine_f32(vget_high_f32(ROW01.val[1]), \ + vget_high_f32(ROW23.val[1])); \ + } while (0) +#endif + +// according to the documentation, these intrinsics behave the same as the +// non-'u' versions. We'll just alias them here. +#define _mm_ucomieq_ss _mm_comieq_ss +#define _mm_ucomige_ss _mm_comige_ss +#define _mm_ucomigt_ss _mm_comigt_ss +#define _mm_ucomile_ss _mm_comile_ss +#define _mm_ucomilt_ss _mm_comilt_ss +#define _mm_ucomineq_ss _mm_comineq_ss + +// Return vector of type __m128i with undefined elements. +// Note: MSVC forces zero-initialization while GCC/Clang return truly undefined +// memory. Use SSE2NEON_UNDEFINED_ZERO=1 to force zero on all compilers. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_undefined_si128 +FORCE_INLINE __m128i _mm_undefined_si128(void) +{ +#if SSE2NEON_UNDEFINED_ZERO || \ + (SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG) + return _mm_setzero_si128(); +#else +#if SSE2NEON_COMPILER_GCC_COMPAT +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#endif + __m128i a; + return a; +#if SSE2NEON_COMPILER_GCC_COMPAT +#pragma GCC diagnostic pop +#endif +#endif +} + +// Return vector of type __m128 with undefined elements. +// Note: MSVC forces zero-initialization while GCC/Clang return truly undefined +// memory. Use SSE2NEON_UNDEFINED_ZERO=1 to force zero on all compilers. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_undefined_ps +FORCE_INLINE __m128 _mm_undefined_ps(void) +{ +#if SSE2NEON_UNDEFINED_ZERO || \ + (SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG) + return _mm_setzero_ps(); +#else +#if SSE2NEON_COMPILER_GCC_COMPAT +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#endif + __m128 a; + return a; +#if SSE2NEON_COMPILER_GCC_COMPAT +#pragma GCC diagnostic pop +#endif +#endif +} + +// Unpack and interleave single-precision (32-bit) floating-point elements from +// the high half a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_ps +FORCE_INLINE __m128 _mm_unpackhi_ps(__m128 a, __m128 b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128_f32( + vzip2q_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +#else + float32x2_t a1 = vget_high_f32(vreinterpretq_f32_m128(a)); + float32x2_t b1 = vget_high_f32(vreinterpretq_f32_m128(b)); + float32x2x2_t result = vzip_f32(a1, b1); + return vreinterpretq_m128_f32(vcombine_f32(result.val[0], result.val[1])); +#endif +} + +// Unpack and interleave single-precision (32-bit) floating-point elements from +// the low half of a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_ps +FORCE_INLINE __m128 _mm_unpacklo_ps(__m128 a, __m128 b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128_f32( + vzip1q_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +#else + float32x2_t a1 = vget_low_f32(vreinterpretq_f32_m128(a)); + float32x2_t b1 = vget_low_f32(vreinterpretq_f32_m128(b)); + float32x2x2_t result = vzip_f32(a1, b1); + return vreinterpretq_m128_f32(vcombine_f32(result.val[0], result.val[1])); +#endif +} + +// Compute the bitwise XOR of packed single-precision (32-bit) floating-point +// elements in a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_xor_ps +FORCE_INLINE __m128 _mm_xor_ps(__m128 a, __m128 b) +{ + return vreinterpretq_m128_s32( + veorq_s32(vreinterpretq_s32_m128(a), vreinterpretq_s32_m128(b))); +} + +/* SSE2 */ + +// Add packed 16-bit integers in a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_epi16 +FORCE_INLINE __m128i _mm_add_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s16( + vaddq_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +} + +// Add packed 32-bit integers in a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_epi32 +FORCE_INLINE __m128i _mm_add_epi32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s32( + vaddq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +// Add packed 64-bit integers in a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_epi64 +FORCE_INLINE __m128i _mm_add_epi64(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s64( + vaddq_s64(vreinterpretq_s64_m128i(a), vreinterpretq_s64_m128i(b))); +} + +// Add packed 8-bit integers in a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_epi8 +FORCE_INLINE __m128i _mm_add_epi8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s8( + vaddq_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +} + +// Add packed double-precision (64-bit) floating-point elements in a and b, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_pd +FORCE_INLINE __m128d _mm_add_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vaddq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + double c[2]; + c[0] = a0 + b0; + c[1] = a1 + b1; + return sse2neon_vld1q_f32_from_f64pair(c); +#endif +} + +// Add the lower double-precision (64-bit) floating-point element in a and b, +// store the result in the lower element of dst, and copy the upper element from +// a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_sd +FORCE_INLINE __m128d _mm_add_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return _mm_move_sd(a, _mm_add_pd(a, b)); +#else + double a0, a1, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + a1 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double c[2]; + c[0] = a0 + b0; + c[1] = a1; + return sse2neon_vld1q_f32_from_f64pair(c); +#endif +} + +// Add 64-bit integers a and b, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_add_si64 +FORCE_INLINE __m64 _mm_add_si64(__m64 a, __m64 b) +{ + return vreinterpret_m64_s64( + vadd_s64(vreinterpret_s64_m64(a), vreinterpret_s64_m64(b))); +} + +// Add packed signed 16-bit integers in a and b using saturation, and store the +// results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_adds_epi16 +FORCE_INLINE __m128i _mm_adds_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s16( + vqaddq_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +} + +// Add packed signed 8-bit integers in a and b using saturation, and store the +// results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_adds_epi8 +FORCE_INLINE __m128i _mm_adds_epi8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s8( + vqaddq_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +} + +// Add packed unsigned 16-bit integers in a and b using saturation, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_adds_epu16 +FORCE_INLINE __m128i _mm_adds_epu16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u16( + vqaddq_u16(vreinterpretq_u16_m128i(a), vreinterpretq_u16_m128i(b))); +} + +// Add packed unsigned 8-bit integers in a and b using saturation, and store the +// results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_adds_epu8 +FORCE_INLINE __m128i _mm_adds_epu8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u8( + vqaddq_u8(vreinterpretq_u8_m128i(a), vreinterpretq_u8_m128i(b))); +} + +// Compute the bitwise AND of packed double-precision (64-bit) floating-point +// elements in a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_and_pd +FORCE_INLINE __m128d _mm_and_pd(__m128d a, __m128d b) +{ + return vreinterpretq_m128d_s64( + vandq_s64(vreinterpretq_s64_m128d(a), vreinterpretq_s64_m128d(b))); +} + +// Compute the bitwise AND of 128 bits (representing integer data) in a and b, +// and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_and_si128 +FORCE_INLINE __m128i _mm_and_si128(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s32( + vandq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +// Compute the bitwise NOT of packed double-precision (64-bit) floating-point +// elements in a and then AND with b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_andnot_pd +FORCE_INLINE __m128d _mm_andnot_pd(__m128d a, __m128d b) +{ + // *NOTE* argument swap + return vreinterpretq_m128d_s64( + vbicq_s64(vreinterpretq_s64_m128d(b), vreinterpretq_s64_m128d(a))); +} + +// Compute the bitwise NOT of 128 bits (representing integer data) in a and then +// AND with b, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_andnot_si128 +FORCE_INLINE __m128i _mm_andnot_si128(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s32( + vbicq_s32(vreinterpretq_s32_m128i(b), + vreinterpretq_s32_m128i(a))); // *NOTE* argument swap +} + +// Average packed unsigned 16-bit integers in a and b, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_avg_epu16 +FORCE_INLINE __m128i _mm_avg_epu16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u16( + vrhaddq_u16(vreinterpretq_u16_m128i(a), vreinterpretq_u16_m128i(b))); +} + +// Average packed unsigned 8-bit integers in a and b, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_avg_epu8 +FORCE_INLINE __m128i _mm_avg_epu8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u8( + vrhaddq_u8(vreinterpretq_u8_m128i(a), vreinterpretq_u8_m128i(b))); +} + +// Shift a left by imm8 bytes while shifting in zeros, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_bslli_si128 +#define _mm_bslli_si128(a, imm) _mm_slli_si128(a, imm) + +// Shift a right by imm8 bytes while shifting in zeros, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_bsrli_si128 +#define _mm_bsrli_si128(a, imm) _mm_srli_si128(a, imm) + +/* Cast Intrinsics - Zero-Cost Type Reinterpretation + * + * The _mm_cast* intrinsics reinterpret vector types (__m128, __m128d, __m128i) + * without generating any instructions. These are pure type annotations that + * perform bitwise reinterpretation, NOT value conversion. + * + * Maps to ARM NEON vreinterpret_* / vreinterpretq_* (also zero-cost bitcasts). + * https://developer.arm.com/architectures/instruction-sets/intrinsics/#q=vreinterpret + */ + +// Cast vector of type __m128d to type __m128. This intrinsic is only used for +// compilation and does not generate any instructions, thus it has zero latency. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castpd_ps +FORCE_INLINE __m128 _mm_castpd_ps(__m128d a) +{ + return vreinterpretq_m128_s64(vreinterpretq_s64_m128d(a)); +} + +// Cast vector of type __m128d to type __m128i. This intrinsic is only used for +// compilation and does not generate any instructions, thus it has zero latency. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castpd_si128 +FORCE_INLINE __m128i _mm_castpd_si128(__m128d a) +{ + return vreinterpretq_m128i_s64(vreinterpretq_s64_m128d(a)); +} + +// Cast vector of type __m128 to type __m128d. This intrinsic is only used for +// compilation and does not generate any instructions, thus it has zero latency. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castps_pd +FORCE_INLINE __m128d _mm_castps_pd(__m128 a) +{ + return vreinterpretq_m128d_s32(vreinterpretq_s32_m128(a)); +} + +// Cast vector of type __m128 to type __m128i. This intrinsic is only used for +// compilation and does not generate any instructions, thus it has zero latency. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castps_si128 +FORCE_INLINE __m128i _mm_castps_si128(__m128 a) +{ + return vreinterpretq_m128i_s32(vreinterpretq_s32_m128(a)); +} + +// Cast vector of type __m128i to type __m128d. This intrinsic is only used for +// compilation and does not generate any instructions, thus it has zero latency. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castsi128_pd +FORCE_INLINE __m128d _mm_castsi128_pd(__m128i a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vreinterpretq_f64_m128i(a)); +#else + return vreinterpretq_m128d_f32(vreinterpretq_f32_m128i(a)); +#endif +} + +// Cast vector of type __m128i to type __m128. This intrinsic is only used for +// compilation and does not generate any instructions, thus it has zero latency. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_castsi128_ps +FORCE_INLINE __m128 _mm_castsi128_ps(__m128i a) +{ + return vreinterpretq_m128_s32(vreinterpretq_s32_m128i(a)); +} + +// Invalidate and flush the cache line that contains p from all levels of the +// cache hierarchy. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_clflush +#if defined(__APPLE__) +#include +#endif +FORCE_INLINE void _mm_clflush(void const *p) +{ + (void) p; + + /* sys_icache_invalidate is supported since macOS 10.5. + * However, it does not work on non-jailbroken iOS devices, although the + * compilation is successful. + */ +#if defined(__APPLE__) + sys_icache_invalidate(_sse2neon_const_cast(void *, p), + SSE2NEON_CACHELINE_SIZE); +#elif SSE2NEON_COMPILER_GCC_COMPAT + uintptr_t ptr = _sse2neon_reinterpret_cast(uintptr_t, p); + __builtin___clear_cache( + _sse2neon_reinterpret_cast(char *, ptr), + _sse2neon_reinterpret_cast(char *, ptr) + SSE2NEON_CACHELINE_SIZE); +#elif SSE2NEON_COMPILER_MSVC && SSE2NEON_INCLUDE_WINDOWS_H + FlushInstructionCache(GetCurrentProcess(), p, SSE2NEON_CACHELINE_SIZE); +#endif +} + +// Compare packed 16-bit integers in a and b for equality, and store the results +// in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_epi16 +FORCE_INLINE __m128i _mm_cmpeq_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u16( + vceqq_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +} + +// Compare packed 32-bit integers in a and b for equality, and store the results +// in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_epi32 +FORCE_INLINE __m128i _mm_cmpeq_epi32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u32( + vceqq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +// Compare packed 8-bit integers in a and b for equality, and store the results +// in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_epi8 +FORCE_INLINE __m128i _mm_cmpeq_epi8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u8( + vceqq_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// for equality, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_pd +FORCE_INLINE __m128d _mm_cmpeq_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_u64( + vceqq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = a0 == b0 ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1 == b1 ? ~UINT64_C(0) : UINT64_C(0); + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b for equality, store the result in the lower element of dst, and copy the +// upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpeq_sd +FORCE_INLINE __m128d _mm_cmpeq_sd(__m128d a, __m128d b) +{ + return _mm_move_sd(a, _mm_cmpeq_pd(a, b)); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// for greater-than-or-equal, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpge_pd +FORCE_INLINE __m128d _mm_cmpge_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_u64( + vcgeq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = a0 >= b0 ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1 >= b1 ? ~UINT64_C(0) : UINT64_C(0); + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b for greater-than-or-equal, store the result in the lower element of dst, +// and copy the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpge_sd +FORCE_INLINE __m128d _mm_cmpge_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return _mm_move_sd(a, _mm_cmpge_pd(a, b)); +#else + // expand "_mm_cmpge_pd()" to reduce unnecessary operations + double a0, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + uint64_t a1 = vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + uint64_t d[2]; + d[0] = a0 >= b0 ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1; + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare packed signed 16-bit integers in a and b for greater-than, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_epi16 +FORCE_INLINE __m128i _mm_cmpgt_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u16( + vcgtq_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +} + +// Compare packed signed 32-bit integers in a and b for greater-than, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_epi32 +FORCE_INLINE __m128i _mm_cmpgt_epi32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u32( + vcgtq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +// Compare packed signed 8-bit integers in a and b for greater-than, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_epi8 +FORCE_INLINE __m128i _mm_cmpgt_epi8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u8( + vcgtq_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// for greater-than, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_pd +FORCE_INLINE __m128d _mm_cmpgt_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_u64( + vcgtq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = a0 > b0 ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1 > b1 ? ~UINT64_C(0) : UINT64_C(0); + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b for greater-than, store the result in the lower element of dst, and copy +// the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpgt_sd +FORCE_INLINE __m128d _mm_cmpgt_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return _mm_move_sd(a, _mm_cmpgt_pd(a, b)); +#else + // expand "_mm_cmpge_pd()" to reduce unnecessary operations + double a0, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + uint64_t a1 = vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + uint64_t d[2]; + d[0] = a0 > b0 ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1; + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// for less-than-or-equal, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmple_pd +FORCE_INLINE __m128d _mm_cmple_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_u64( + vcleq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = a0 <= b0 ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1 <= b1 ? ~UINT64_C(0) : UINT64_C(0); + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b for less-than-or-equal, store the result in the lower element of dst, and +// copy the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmple_sd +FORCE_INLINE __m128d _mm_cmple_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return _mm_move_sd(a, _mm_cmple_pd(a, b)); +#else + // expand "_mm_cmpge_pd()" to reduce unnecessary operations + double a0, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + uint64_t a1 = vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + uint64_t d[2]; + d[0] = a0 <= b0 ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1; + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare packed signed 16-bit integers in a and b for less-than, and store the +// results in dst. Note: This intrinsic emits the pcmpgtw instruction with the +// order of the operands switched. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_epi16 +FORCE_INLINE __m128i _mm_cmplt_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u16( + vcltq_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +} + +// Compare packed signed 32-bit integers in a and b for less-than, and store the +// results in dst. Note: This intrinsic emits the pcmpgtd instruction with the +// order of the operands switched. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_epi32 +FORCE_INLINE __m128i _mm_cmplt_epi32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u32( + vcltq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +// Compare packed signed 8-bit integers in a and b for less-than, and store the +// results in dst. Note: This intrinsic emits the pcmpgtb instruction with the +// order of the operands switched. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_epi8 +FORCE_INLINE __m128i _mm_cmplt_epi8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u8( + vcltq_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// for less-than, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_pd +FORCE_INLINE __m128d _mm_cmplt_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_u64( + vcltq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = a0 < b0 ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1 < b1 ? ~UINT64_C(0) : UINT64_C(0); + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b for less-than, store the result in the lower element of dst, and copy the +// upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmplt_sd +FORCE_INLINE __m128d _mm_cmplt_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return _mm_move_sd(a, _mm_cmplt_pd(a, b)); +#else + double a0, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + uint64_t a1 = vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + uint64_t d[2]; + d[0] = a0 < b0 ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1; + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// for not-equal, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpneq_pd +FORCE_INLINE __m128d _mm_cmpneq_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_s32(vmvnq_s32(vreinterpretq_s32_u64( + vceqq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = a0 != b0 ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1 != b1 ? ~UINT64_C(0) : UINT64_C(0); + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b for not-equal, store the result in the lower element of dst, and copy the +// upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpneq_sd +FORCE_INLINE __m128d _mm_cmpneq_sd(__m128d a, __m128d b) +{ + return _mm_move_sd(a, _mm_cmpneq_pd(a, b)); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// for not-greater-than-or-equal, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnge_pd +FORCE_INLINE __m128d _mm_cmpnge_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_u64(veorq_u64( + vcgeq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b)), + vdupq_n_u64(UINT64_MAX))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = !(a0 >= b0) ? ~UINT64_C(0) : UINT64_C(0); + d[1] = !(a1 >= b1) ? ~UINT64_C(0) : UINT64_C(0); + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b for not-greater-than-or-equal, store the result in the lower element of +// dst, and copy the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnge_sd +FORCE_INLINE __m128d _mm_cmpnge_sd(__m128d a, __m128d b) +{ + return _mm_move_sd(a, _mm_cmpnge_pd(a, b)); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// for not-greater-than, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_cmpngt_pd +FORCE_INLINE __m128d _mm_cmpngt_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_u64(veorq_u64( + vcgtq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b)), + vdupq_n_u64(UINT64_MAX))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = !(a0 > b0) ? ~UINT64_C(0) : UINT64_C(0); + d[1] = !(a1 > b1) ? ~UINT64_C(0) : UINT64_C(0); + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b for not-greater-than, store the result in the lower element of dst, and +// copy the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpngt_sd +FORCE_INLINE __m128d _mm_cmpngt_sd(__m128d a, __m128d b) +{ + return _mm_move_sd(a, _mm_cmpngt_pd(a, b)); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// for not-less-than-or-equal, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnle_pd +FORCE_INLINE __m128d _mm_cmpnle_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_u64(veorq_u64( + vcleq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b)), + vdupq_n_u64(UINT64_MAX))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = !(a0 <= b0) ? ~UINT64_C(0) : UINT64_C(0); + d[1] = !(a1 <= b1) ? ~UINT64_C(0) : UINT64_C(0); + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b for not-less-than-or-equal, store the result in the lower element of dst, +// and copy the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnle_sd +FORCE_INLINE __m128d _mm_cmpnle_sd(__m128d a, __m128d b) +{ + return _mm_move_sd(a, _mm_cmpnle_pd(a, b)); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// for not-less-than, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnlt_pd +FORCE_INLINE __m128d _mm_cmpnlt_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_u64(veorq_u64( + vcltq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b)), + vdupq_n_u64(UINT64_MAX))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = !(a0 < b0) ? ~UINT64_C(0) : UINT64_C(0); + d[1] = !(a1 < b1) ? ~UINT64_C(0) : UINT64_C(0); + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b for not-less-than, store the result in the lower element of dst, and copy +// the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpnlt_sd +FORCE_INLINE __m128d _mm_cmpnlt_sd(__m128d a, __m128d b) +{ + return _mm_move_sd(a, _mm_cmpnlt_pd(a, b)); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// to see if neither is NaN, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpord_pd +FORCE_INLINE __m128d _mm_cmpord_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + // Excluding NaNs, any two floating point numbers can be compared. + uint64x2_t not_nan_a = + vceqq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(a)); + uint64x2_t not_nan_b = + vceqq_f64(vreinterpretq_f64_m128d(b), vreinterpretq_f64_m128d(b)); + return vreinterpretq_m128d_u64(vandq_u64(not_nan_a, not_nan_b)); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = (a0 == a0 && b0 == b0) ? ~UINT64_C(0) : UINT64_C(0); + d[1] = (a1 == a1 && b1 == b1) ? ~UINT64_C(0) : UINT64_C(0); + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b to see if neither is NaN, store the result in the lower element of dst, and +// copy the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpord_sd +FORCE_INLINE __m128d _mm_cmpord_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return _mm_move_sd(a, _mm_cmpord_pd(a, b)); +#else + double a0, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + uint64_t a1 = vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + uint64_t d[2]; + d[0] = (a0 == a0 && b0 == b0) ? ~UINT64_C(0) : UINT64_C(0); + d[1] = a1; + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b +// to see if either is NaN, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpunord_pd +FORCE_INLINE __m128d _mm_cmpunord_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + // Two NaNs are not equal in comparison operation. + uint64x2_t not_nan_a = + vceqq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(a)); + uint64x2_t not_nan_b = + vceqq_f64(vreinterpretq_f64_m128d(b), vreinterpretq_f64_m128d(b)); + return vreinterpretq_m128d_s32( + vmvnq_s32(vreinterpretq_s32_u64(vandq_u64(not_nan_a, not_nan_b)))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + uint64_t d[2]; + d[0] = (a0 == a0 && b0 == b0) ? UINT64_C(0) : ~UINT64_C(0); + d[1] = (a1 == a1 && b1 == b1) ? UINT64_C(0) : ~UINT64_C(0); + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b to see if either is NaN, store the result in the lower element of dst, and +// copy the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpunord_sd +FORCE_INLINE __m128d _mm_cmpunord_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return _mm_move_sd(a, _mm_cmpunord_pd(a, b)); +#else + double a0, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + uint64_t a1 = vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + uint64_t d[2]; + d[0] = (a0 == a0 && b0 == b0) ? UINT64_C(0) : ~UINT64_C(0); + d[1] = a1; + + return vreinterpretq_m128d_u64(vld1q_u64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point element in a and b +// for greater-than-or-equal, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comige_sd +FORCE_INLINE int _mm_comige_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vgetq_lane_u64(vcgeq_f64(a, b), 0) & 0x1; +#else + double a0, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + return a0 >= b0; +#endif +} + +// Compare the lower double-precision (64-bit) floating-point element in a and b +// for greater-than, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comigt_sd +FORCE_INLINE int _mm_comigt_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vgetq_lane_u64(vcgtq_f64(a, b), 0) & 0x1; +#else + double a0, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + + return a0 > b0; +#endif +} + +// Compare the lower double-precision (64-bit) floating-point element in a and b +// for less-than-or-equal, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comile_sd +FORCE_INLINE int _mm_comile_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vgetq_lane_u64(vcleq_f64(a, b), 0) & 0x1; +#else + double a0, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + + return a0 <= b0; +#endif +} + +// Compare the lower double-precision (64-bit) floating-point element in a and b +// for less-than, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comilt_sd +FORCE_INLINE int _mm_comilt_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vgetq_lane_u64(vcltq_f64(a, b), 0) & 0x1; +#else + double a0, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + + return a0 < b0; +#endif +} + +// Compare the lower double-precision (64-bit) floating-point element in a and b +// for equality, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comieq_sd +FORCE_INLINE int _mm_comieq_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vgetq_lane_u64(vceqq_f64(a, b), 0) & 0x1; +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + return a0 == b0 ? 1 : 0; +#endif +} + +// Compare the lower double-precision (64-bit) floating-point element in a and b +// for not-equal, and return the boolean result (0 or 1). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_comineq_sd +FORCE_INLINE int _mm_comineq_sd(__m128d a, __m128d b) +{ + return !_mm_comieq_sd(a, b); +} + +// Convert packed signed 32-bit integers in a to packed double-precision +// (64-bit) floating-point elements, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi32_pd +FORCE_INLINE __m128d _mm_cvtepi32_pd(__m128i a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vcvtq_f64_s64(vmovl_s32(vget_low_s32(vreinterpretq_s32_m128i(a))))); +#else + double a0 = _sse2neon_static_cast( + double, vgetq_lane_s32(vreinterpretq_s32_m128i(a), 0)); + double a1 = _sse2neon_static_cast( + double, vgetq_lane_s32(vreinterpretq_s32_m128i(a), 1)); + return _mm_set_pd(a1, a0); +#endif +} + +// Convert packed signed 32-bit integers in a to packed single-precision +// (32-bit) floating-point elements, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi32_ps +FORCE_INLINE __m128 _mm_cvtepi32_ps(__m128i a) +{ + return vreinterpretq_m128_f32(vcvtq_f32_s32(vreinterpretq_s32_m128i(a))); +} + +// Convert packed double-precision (64-bit) floating-point elements in a to +// packed 32-bit integers, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpd_epi32 +FORCE_INLINE __m128i _mm_cvtpd_epi32(__m128d a) +{ + __m128d rnd = _mm_round_pd(a, _MM_FROUND_CUR_DIRECTION); + double d0, d1; + d0 = sse2neon_recast_u64_f64( + vgetq_lane_u64(vreinterpretq_u64_m128d(rnd), 0)); + d1 = sse2neon_recast_u64_f64( + vgetq_lane_u64(vreinterpretq_u64_m128d(rnd), 1)); + return _mm_set_epi32(0, 0, _sse2neon_cvtd_s32(d1), _sse2neon_cvtd_s32(d0)); +} + +// Convert packed double-precision (64-bit) floating-point elements in a to +// packed 32-bit integers, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpd_pi32 +FORCE_INLINE __m64 _mm_cvtpd_pi32(__m128d a) +{ + __m128d rnd = _mm_round_pd(a, _MM_FROUND_CUR_DIRECTION); + double d0, d1; + d0 = sse2neon_recast_u64_f64( + vgetq_lane_u64(vreinterpretq_u64_m128d(rnd), 0)); + d1 = sse2neon_recast_u64_f64( + vgetq_lane_u64(vreinterpretq_u64_m128d(rnd), 1)); + int32_t ALIGN_STRUCT(16) data[2] = { + _sse2neon_cvtd_s32(d0), + _sse2neon_cvtd_s32(d1), + }; + return vreinterpret_m64_s32(vld1_s32(data)); +} + +// Convert packed double-precision (64-bit) floating-point elements in a to +// packed single-precision (32-bit) floating-point elements, and store the +// results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpd_ps +FORCE_INLINE __m128 _mm_cvtpd_ps(__m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + float32x2_t tmp = vcvt_f32_f64(vreinterpretq_f64_m128d(a)); + return vreinterpretq_m128_f32(vcombine_f32(tmp, vdup_n_f32(0))); +#else + double a0, a1; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + a1 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + return _mm_set_ps(0, 0, _sse2neon_static_cast(float, a1), + _sse2neon_static_cast(float, a0)); +#endif +} + +// Convert packed signed 32-bit integers in a to packed double-precision +// (64-bit) floating-point elements, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtpi32_pd +FORCE_INLINE __m128d _mm_cvtpi32_pd(__m64 a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vcvtq_f64_s64(vmovl_s32(vreinterpret_s32_m64(a)))); +#else + double a0 = _sse2neon_static_cast( + double, vget_lane_s32(vreinterpret_s32_m64(a), 0)); + double a1 = _sse2neon_static_cast( + double, vget_lane_s32(vreinterpret_s32_m64(a), 1)); + return _mm_set_pd(a1, a0); +#endif +} + +// Convert packed single-precision (32-bit) floating-point elements in a to +// packed 32-bit integers, and store the results in dst. +// x86 returns INT32_MIN ("integer indefinite") for NaN and out-of-range values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_epi32 +// *NOTE*. The default rounding mode on SSE is 'round to even', which ARMv7-A +// does not support! It is supported on ARMv8-A however. +FORCE_INLINE __m128i _mm_cvtps_epi32(__m128 a) +{ +#if defined(__ARM_FEATURE_FRINT) + float32x4_t f = vreinterpretq_f32_m128(a); + int32x4_t cvt = vcvtq_s32_f32(vrnd32xq_f32(f)); + return vreinterpretq_m128i_s32(_sse2neon_cvtps_epi32_fixup(f, cvt)); +#elif SSE2NEON_ARCH_AARCH64 || defined(__ARM_FEATURE_DIRECTED_ROUNDING) + float32x4_t f = vreinterpretq_f32_m128(a); + int32x4_t cvt; + switch (_MM_GET_ROUNDING_MODE()) { + case _MM_ROUND_NEAREST: + cvt = vcvtnq_s32_f32(f); + break; + case _MM_ROUND_DOWN: + cvt = vcvtmq_s32_f32(f); + break; + case _MM_ROUND_UP: + cvt = vcvtpq_s32_f32(f); + break; + default: // _MM_ROUND_TOWARD_ZERO + cvt = vcvtq_s32_f32(f); + break; + } + return vreinterpretq_m128i_s32(_sse2neon_cvtps_epi32_fixup(f, cvt)); +#else + float *f = _sse2neon_reinterpret_cast(float *, &a); + switch (_MM_GET_ROUNDING_MODE()) { + case _MM_ROUND_NEAREST: { + float32x4_t fv = vreinterpretq_f32_m128(a); + uint32x4_t signmask = vdupq_n_u32(0x80000000); + float32x4_t half = + vbslq_f32(signmask, fv, vdupq_n_f32(0.5f)); /* +/- 0.5 */ + int32x4_t r_normal = + vcvtq_s32_f32(vaddq_f32(fv, half)); /* round to integer: [a + 0.5]*/ + int32x4_t r_trunc = vcvtq_s32_f32(fv); /* truncate to integer: [a] */ + int32x4_t plusone = vreinterpretq_s32_u32(vshrq_n_u32( + vreinterpretq_u32_s32(vnegq_s32(r_trunc)), 31)); /* 1 or 0 */ + int32x4_t r_even = vbicq_s32(vaddq_s32(r_trunc, plusone), + vdupq_n_s32(1)); /* ([a] + {0,1}) & ~1 */ + float32x4_t delta = vsubq_f32( + fv, vcvtq_f32_s32(r_trunc)); /* compute delta: delta = (a - [a]) */ + uint32x4_t is_delta_half = + vceqq_f32(delta, half); /* delta == +/- 0.5 */ + int32x4_t result = vbslq_s32(is_delta_half, r_even, r_normal); + return vreinterpretq_m128i_s32(_sse2neon_cvtps_epi32_fixup(fv, result)); + } + case _MM_ROUND_DOWN: + return _mm_set_epi32( + _sse2neon_cvtf_s32(floorf(f[3])), _sse2neon_cvtf_s32(floorf(f[2])), + _sse2neon_cvtf_s32(floorf(f[1])), _sse2neon_cvtf_s32(floorf(f[0]))); + case _MM_ROUND_UP: + return _mm_set_epi32( + _sse2neon_cvtf_s32(ceilf(f[3])), _sse2neon_cvtf_s32(ceilf(f[2])), + _sse2neon_cvtf_s32(ceilf(f[1])), _sse2neon_cvtf_s32(ceilf(f[0]))); + default: // _MM_ROUND_TOWARD_ZERO + return _mm_set_epi32(_sse2neon_cvtf_s32(f[3]), _sse2neon_cvtf_s32(f[2]), + _sse2neon_cvtf_s32(f[1]), + _sse2neon_cvtf_s32(f[0])); + } +#endif +} + +// Convert packed single-precision (32-bit) floating-point elements in a to +// packed double-precision (64-bit) floating-point elements, and store the +// results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_pd +FORCE_INLINE __m128d _mm_cvtps_pd(__m128 a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vcvt_f64_f32(vget_low_f32(vreinterpretq_f32_m128(a)))); +#else + double a0 = _sse2neon_static_cast( + double, vgetq_lane_f32(vreinterpretq_f32_m128(a), 0)); + double a1 = _sse2neon_static_cast( + double, vgetq_lane_f32(vreinterpretq_f32_m128(a), 1)); + return _mm_set_pd(a1, a0); +#endif +} + +// Copy the lower double-precision (64-bit) floating-point element of a to dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_f64 +FORCE_INLINE double _mm_cvtsd_f64(__m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + return _sse2neon_static_cast(double, + vgetq_lane_f64(vreinterpretq_f64_m128d(a), 0)); +#else + double _a = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + return _a; +#endif +} + +// Convert the lower double-precision (64-bit) floating-point element in a to a +// 32-bit integer, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_si32 +FORCE_INLINE int32_t _mm_cvtsd_si32(__m128d a) +{ + __m128d rnd = _mm_round_pd(a, _MM_FROUND_CUR_DIRECTION); + double ret = sse2neon_recast_u64_f64( + vgetq_lane_u64(vreinterpretq_u64_m128d(rnd), 0)); + return _sse2neon_cvtd_s32(ret); +} + +// Convert the lower double-precision (64-bit) floating-point element in a to a +// 64-bit integer, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_si64 +FORCE_INLINE int64_t _mm_cvtsd_si64(__m128d a) +{ + __m128d rnd = _mm_round_pd(a, _MM_FROUND_CUR_DIRECTION); + double ret = sse2neon_recast_u64_f64( + vgetq_lane_u64(vreinterpretq_u64_m128d(rnd), 0)); + return _sse2neon_cvtd_s64(ret); +} + +// Convert the lower double-precision (64-bit) floating-point element in a to a +// 64-bit integer, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_si64x +#define _mm_cvtsd_si64x _mm_cvtsd_si64 + +// Convert the lower double-precision (64-bit) floating-point element in b to a +// single-precision (32-bit) floating-point element, store the result in the +// lower element of dst, and copy the upper 3 packed elements from a to the +// upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsd_ss +FORCE_INLINE __m128 _mm_cvtsd_ss(__m128 a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128_f32(vsetq_lane_f32( + vget_lane_f32(vcvt_f32_f64(vreinterpretq_f64_m128d(b)), 0), + vreinterpretq_f32_m128(a), 0)); +#else + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + return vreinterpretq_m128_f32(vsetq_lane_f32( + _sse2neon_static_cast(float, b0), vreinterpretq_f32_m128(a), 0)); +#endif +} + +// Copy the lower 32-bit integer in a to dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi128_si32 +FORCE_INLINE int _mm_cvtsi128_si32(__m128i a) +{ + return vgetq_lane_s32(vreinterpretq_s32_m128i(a), 0); +} + +// Copy the lower 64-bit integer in a to dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi128_si64 +FORCE_INLINE int64_t _mm_cvtsi128_si64(__m128i a) +{ + return vgetq_lane_s64(vreinterpretq_s64_m128i(a), 0); +} + +// Copy the lower 64-bit integer in a to dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi128_si64x +#define _mm_cvtsi128_si64x(a) _mm_cvtsi128_si64(a) + +// Convert the signed 32-bit integer b to a double-precision (64-bit) +// floating-point element, store the result in the lower element of dst, and +// copy the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi32_sd +FORCE_INLINE __m128d _mm_cvtsi32_sd(__m128d a, int32_t b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vsetq_lane_f64( + _sse2neon_static_cast(double, b), vreinterpretq_f64_m128d(a), 0)); +#else + int64_t _b = sse2neon_recast_f64_s64(_sse2neon_static_cast(double, b)); + return vreinterpretq_m128d_s64( + vsetq_lane_s64(_b, vreinterpretq_s64_m128d(a), 0)); +#endif +} + +// Copy the lower 64-bit integer in a to dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi128_si64x +#define _mm_cvtsi128_si64x(a) _mm_cvtsi128_si64(a) + +// Copy 32-bit integer a to the lower elements of dst, and zero the upper +// elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi32_si128 +FORCE_INLINE __m128i _mm_cvtsi32_si128(int a) +{ + return vreinterpretq_m128i_s32(vsetq_lane_s32(a, vdupq_n_s32(0), 0)); +} + +// Convert the signed 64-bit integer b to a double-precision (64-bit) +// floating-point element, store the result in the lower element of dst, and +// copy the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi64_sd +FORCE_INLINE __m128d _mm_cvtsi64_sd(__m128d a, int64_t b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vsetq_lane_f64( + _sse2neon_static_cast(double, b), vreinterpretq_f64_m128d(a), 0)); +#else + int64_t _b = sse2neon_recast_f64_s64(_sse2neon_static_cast(double, b)); + return vreinterpretq_m128d_s64( + vsetq_lane_s64(_b, vreinterpretq_s64_m128d(a), 0)); +#endif +} + +// Copy 64-bit integer a to the lower element of dst, and zero the upper +// element. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi64_si128 +FORCE_INLINE __m128i _mm_cvtsi64_si128(int64_t a) +{ + return vreinterpretq_m128i_s64(vsetq_lane_s64(a, vdupq_n_s64(0), 0)); +} + +// Copy 64-bit integer a to the lower element of dst, and zero the upper +// element. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi64x_si128 +#define _mm_cvtsi64x_si128(a) _mm_cvtsi64_si128(a) + +// Convert the signed 64-bit integer b to a double-precision (64-bit) +// floating-point element, store the result in the lower element of dst, and +// copy the upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtsi64x_sd +#define _mm_cvtsi64x_sd(a, b) _mm_cvtsi64_sd(a, b) + +// Convert the lower single-precision (32-bit) floating-point element in b to a +// double-precision (64-bit) floating-point element, store the result in the +// lower element of dst, and copy the upper element from a to the upper element +// of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtss_sd +FORCE_INLINE __m128d _mm_cvtss_sd(__m128d a, __m128 b) +{ + double d = _sse2neon_static_cast( + double, vgetq_lane_f32(vreinterpretq_f32_m128(b), 0)); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vsetq_lane_f64(d, vreinterpretq_f64_m128d(a), 0)); +#else + return vreinterpretq_m128d_s64(vsetq_lane_s64( + sse2neon_recast_f64_s64(d), vreinterpretq_s64_m128d(a), 0)); +#endif +} + +// Convert packed double-precision (64-bit) floating-point elements in a to +// packed 32-bit integers with truncation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttpd_epi32 +FORCE_INLINE __m128i _mm_cvttpd_epi32(__m128d a) +{ + double a0, a1; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + a1 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + return _mm_set_epi32(0, 0, _sse2neon_cvtd_s32(a1), _sse2neon_cvtd_s32(a0)); +} + +// Convert packed double-precision (64-bit) floating-point elements in a to +// packed 32-bit integers with truncation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttpd_pi32 +FORCE_INLINE __m64 _mm_cvttpd_pi32(__m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + /* Vectorized AArch64 path - branchless, no memory round-trip */ + float64x2_t f = vreinterpretq_f64_m128d(a); + + /* Convert f64 to i64 with truncation toward zero. + * Out-of-range values produce undefined results, but we mask them below. + */ + int64x2_t i64 = vcvtq_s64_f64(f); + + /* Detect values outside INT32 range: >= 2147483648.0 or < -2147483648.0 + * x86 returns INT32_MIN (0x80000000) for these cases. + */ + float64x2_t max_f = vdupq_n_f64(2147483648.0); /* INT32_MAX + 1 */ + float64x2_t min_f = vdupq_n_f64(-2147483648.0); + uint64x2_t overflow = vorrq_u64(vcgeq_f64(f, max_f), vcltq_f64(f, min_f)); + + /* Detect NaN: a value is NaN if it's not equal to itself. + * Use XOR with all-ones since vmvnq_u64 doesn't exist. */ + uint64x2_t eq_self = vceqq_f64(f, f); + uint64x2_t is_nan = veorq_u64(eq_self, vdupq_n_u64(UINT64_MAX)); + + /* Combine: any overflow or NaN should produce INT32_MIN */ + uint64x2_t need_indefinite = vorrq_u64(overflow, is_nan); + + /* Narrow i64 to i32 (simple truncation of upper 32 bits) */ + int32x2_t i32 = vmovn_s64(i64); + + /* Blend: select INT32_MIN where needed, otherwise use converted value */ + uint32x2_t mask32 = vmovn_u64(need_indefinite); + int32x2_t indefinite = vdup_n_s32(INT32_MIN); + return vreinterpret_m64_s32(vbsl_s32(mask32, indefinite, i32)); +#else + /* Scalar fallback for ARMv7 (no f64 SIMD support) */ + double a0, a1; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + a1 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + int32_t ALIGN_STRUCT(16) data[2] = {_sse2neon_cvtd_s32(a0), + _sse2neon_cvtd_s32(a1)}; + return vreinterpret_m64_s32(vld1_s32(data)); +#endif +} + +// Convert packed single-precision (32-bit) floating-point elements in a to +// packed 32-bit integers with truncation, and store the results in dst. +// x86 returns INT32_MIN ("integer indefinite") for NaN and out-of-range values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttps_epi32 +FORCE_INLINE __m128i _mm_cvttps_epi32(__m128 a) +{ + float32x4_t f = vreinterpretq_f32_m128(a); + int32x4_t cvt = vcvtq_s32_f32(f); + return vreinterpretq_m128i_s32(_sse2neon_cvtps_epi32_fixup(f, cvt)); +} + +// Convert the lower double-precision (64-bit) floating-point element in a to a +// 32-bit integer with truncation, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttsd_si32 +FORCE_INLINE int32_t _mm_cvttsd_si32(__m128d a) +{ + double _a = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + return _sse2neon_cvtd_s32(_a); +} + +// Convert the lower double-precision (64-bit) floating-point element in a to a +// 64-bit integer with truncation, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttsd_si64 +FORCE_INLINE int64_t _mm_cvttsd_si64(__m128d a) +{ + double _a = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + return _sse2neon_cvtd_s64(_a); +} + +// Convert the lower double-precision (64-bit) floating-point element in a to a +// 64-bit integer with truncation, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvttsd_si64x +#define _mm_cvttsd_si64x(a) _mm_cvttsd_si64(a) + +// Divide packed double-precision (64-bit) floating-point elements in a by +// packed elements in b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_div_pd +FORCE_INLINE __m128d _mm_div_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vdivq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + double c[2]; + c[0] = a0 / b0; + c[1] = a1 / b1; + return sse2neon_vld1q_f32_from_f64pair(c); +#endif +} + +// Divide the lower double-precision (64-bit) floating-point element in a by the +// lower double-precision (64-bit) floating-point element in b, store the result +// in the lower element of dst, and copy the upper element from a to the upper +// element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_div_sd +FORCE_INLINE __m128d _mm_div_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + float64x2_t tmp = + vdivq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b)); + return vreinterpretq_m128d_f64( + vsetq_lane_f64(vgetq_lane_f64(vreinterpretq_f64_m128d(a), 1), tmp, 1)); +#else + return _mm_move_sd(a, _mm_div_pd(a, b)); +#endif +} + +// Extract a 16-bit integer from a, selected with imm8, and store the result in +// the lower element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_extract_epi16 +// FORCE_INLINE int _mm_extract_epi16(__m128i a, const int imm) +// imm must be a compile-time constant in range [0, 7] +#define _mm_extract_epi16(a, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 7), \ + vgetq_lane_u16(vreinterpretq_u16_m128i(a), (imm))) + +// Copy a to dst, and insert the 16-bit integer i into dst at the location +// specified by imm8. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_insert_epi16 +// FORCE_INLINE __m128i _mm_insert_epi16(__m128i a, int b, const int imm) +// imm must be a compile-time constant in range [0, 7] +#define _mm_insert_epi16(a, b, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 7), \ + vreinterpretq_m128i_s16( \ + vsetq_lane_s16((b), vreinterpretq_s16_m128i(a), (imm)))) + +// Load 128-bits (composed of 2 packed double-precision (64-bit) floating-point +// elements) from memory into dst. mem_addr must be aligned on a 16-byte +// boundary or a general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_pd +FORCE_INLINE __m128d _mm_load_pd(const double *p) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vld1q_f64(p)); +#else + const float *fp = _sse2neon_reinterpret_cast(const float *, p); + float ALIGN_STRUCT(16) data[4] = {fp[0], fp[1], fp[2], fp[3]}; + return vreinterpretq_m128d_f32(vld1q_f32(data)); +#endif +} + +// Load a double-precision (64-bit) floating-point element from memory into both +// elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_pd1 +#define _mm_load_pd1 _mm_load1_pd + +// Load a double-precision (64-bit) floating-point element from memory into the +// lower of dst, and zero the upper element. mem_addr does not need to be +// aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_sd +FORCE_INLINE __m128d _mm_load_sd(const double *p) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vsetq_lane_f64(*p, vdupq_n_f64(0), 0)); +#else + const float *fp = _sse2neon_reinterpret_cast(const float *, p); + float ALIGN_STRUCT(16) data[4] = {fp[0], fp[1], 0, 0}; + return vreinterpretq_m128d_f32(vld1q_f32(data)); +#endif +} + +// Load 128-bits of integer data from memory into dst. mem_addr must be aligned +// on a 16-byte boundary or a general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load_si128 +FORCE_INLINE __m128i _mm_load_si128(const __m128i *p) +{ + return vreinterpretq_m128i_s32( + vld1q_s32(_sse2neon_reinterpret_cast(const int32_t *, p))); +} + +// Load a double-precision (64-bit) floating-point element from memory into both +// elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_load1_pd +FORCE_INLINE __m128d _mm_load1_pd(const double *p) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vld1q_dup_f64(p)); +#else + return vreinterpretq_m128d_s64( + vdupq_n_s64(*_sse2neon_reinterpret_cast(const int64_t *, p))); +#endif +} + +// Load a double-precision (64-bit) floating-point element from memory into the +// upper element of dst, and copy the lower element from a to dst. mem_addr does +// not need to be aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadh_pd +FORCE_INLINE __m128d _mm_loadh_pd(__m128d a, const double *p) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vcombine_f64(vget_low_f64(vreinterpretq_f64_m128d(a)), vld1_f64(p))); +#else + return vreinterpretq_m128d_f32( + vcombine_f32(vget_low_f32(vreinterpretq_f32_m128d(a)), + vld1_f32(_sse2neon_reinterpret_cast(const float *, p)))); +#endif +} + +// Load 64-bit integer from memory into the first element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadl_epi64 +FORCE_INLINE __m128i _mm_loadl_epi64(__m128i const *p) +{ + /* Load the lower 64 bits of the value pointed to by p into the + * lower 64 bits of the result, zeroing the upper 64 bits of the result. + */ + return vreinterpretq_m128i_s32( + vcombine_s32(vld1_s32(_sse2neon_reinterpret_cast(int32_t const *, p)), + vcreate_s32(0))); +} + +// Load a double-precision (64-bit) floating-point element from memory into the +// lower element of dst, and copy the upper element from a to dst. mem_addr does +// not need to be aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadl_pd +FORCE_INLINE __m128d _mm_loadl_pd(__m128d a, const double *p) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vcombine_f64(vld1_f64(p), vget_high_f64(vreinterpretq_f64_m128d(a)))); +#else + return vreinterpretq_m128d_f32( + vcombine_f32(vld1_f32(_sse2neon_reinterpret_cast(const float *, p)), + vget_high_f32(vreinterpretq_f32_m128d(a)))); +#endif +} + +// Load 2 double-precision (64-bit) floating-point elements from memory into dst +// in reverse order. mem_addr must be aligned on a 16-byte boundary or a +// general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadr_pd +FORCE_INLINE __m128d _mm_loadr_pd(const double *p) +{ +#if SSE2NEON_ARCH_AARCH64 + float64x2_t v = vld1q_f64(p); + return vreinterpretq_m128d_f64(vextq_f64(v, v, 1)); +#else + int64x2_t v = vld1q_s64(_sse2neon_reinterpret_cast(const int64_t *, p)); + return vreinterpretq_m128d_s64(vextq_s64(v, v, 1)); +#endif +} + +// Loads two double-precision from unaligned memory, floating-point values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_pd +FORCE_INLINE __m128d _mm_loadu_pd(const double *p) +{ + return _mm_load_pd(p); +} + +// Load 128-bits of integer data from memory into dst. mem_addr does not need to +// be aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si128 +FORCE_INLINE __m128i _mm_loadu_si128(const __m128i *p) +{ + return vreinterpretq_m128i_s32( + vld1q_s32(_sse2neon_reinterpret_cast(const unaligned_int32_t *, p))); +} + +// Load unaligned 32-bit integer from memory into the first element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loadu_si32 +FORCE_INLINE __m128i _mm_loadu_si32(const void *p) +{ + return vreinterpretq_m128i_s32(vsetq_lane_s32( + *_sse2neon_reinterpret_cast(const unaligned_int32_t *, p), + vdupq_n_s32(0), 0)); +} + +// Multiply packed signed 16-bit integers in a and b, producing intermediate +// signed 32-bit integers. Horizontally add adjacent pairs of intermediate +// 32-bit integers, and pack the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_madd_epi16 +FORCE_INLINE __m128i _mm_madd_epi16(__m128i a, __m128i b) +{ + int32x4_t low = vmull_s16(vget_low_s16(vreinterpretq_s16_m128i(a)), + vget_low_s16(vreinterpretq_s16_m128i(b))); +#if SSE2NEON_ARCH_AARCH64 + int32x4_t high = + vmull_high_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b)); + + return vreinterpretq_m128i_s32(vpaddq_s32(low, high)); +#else + int32x4_t high = vmull_s16(vget_high_s16(vreinterpretq_s16_m128i(a)), + vget_high_s16(vreinterpretq_s16_m128i(b))); + + int32x2_t low_sum = vpadd_s32(vget_low_s32(low), vget_high_s32(low)); + int32x2_t high_sum = vpadd_s32(vget_low_s32(high), vget_high_s32(high)); + + return vreinterpretq_m128i_s32(vcombine_s32(low_sum, high_sum)); +#endif +} + +// Conditionally store 8-bit integer elements from a into memory using mask +// (elements are not stored when the highest bit is not set in the corresponding +// element) and a non-temporal memory hint. mem_addr does not need to be aligned +// on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskmoveu_si128 +FORCE_INLINE void _mm_maskmoveu_si128(__m128i a, __m128i mask, char *mem_addr) +{ + int8x16_t shr_mask = vshrq_n_s8(vreinterpretq_s8_m128i(mask), 7); + __m128 b = _mm_load_ps(_sse2neon_reinterpret_cast(const float *, mem_addr)); + int8x16_t masked = + vbslq_s8(vreinterpretq_u8_s8(shr_mask), vreinterpretq_s8_m128i(a), + vreinterpretq_s8_m128(b)); + vst1q_s8(_sse2neon_reinterpret_cast(int8_t *, mem_addr), masked); +} + +// Compare packed signed 16-bit integers in a and b, and store packed maximum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epi16 +FORCE_INLINE __m128i _mm_max_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s16( + vmaxq_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +} + +// Compare packed unsigned 8-bit integers in a and b, and store packed maximum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epu8 +FORCE_INLINE __m128i _mm_max_epu8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u8( + vmaxq_u8(vreinterpretq_u8_m128i(a), vreinterpretq_u8_m128i(b))); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b, +// and store packed maximum values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_pd +FORCE_INLINE __m128d _mm_max_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 +#if SSE2NEON_PRECISE_MINMAX + float64x2_t _a = vreinterpretq_f64_m128d(a); + float64x2_t _b = vreinterpretq_f64_m128d(b); + return vreinterpretq_m128d_f64(vbslq_f64(vcgtq_f64(_a, _b), _a, _b)); +#else + return vreinterpretq_m128d_f64( + vmaxq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#endif +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + int64_t d[2]; + d[0] = a0 > b0 ? sse2neon_recast_f64_s64(a0) : sse2neon_recast_f64_s64(b0); + d[1] = a1 > b1 ? sse2neon_recast_f64_s64(a1) : sse2neon_recast_f64_s64(b1); + + return vreinterpretq_m128d_s64(vld1q_s64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b, store the maximum value in the lower element of dst, and copy the upper +// element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_sd +FORCE_INLINE __m128d _mm_max_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return _mm_move_sd(a, _mm_max_pd(a, b)); +#else + double a0, a1, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + a1 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double c[2] = {a0 > b0 ? a0 : b0, a1}; + return vreinterpretq_m128d_f32(sse2neon_vld1q_f32_from_f64pair(c)); +#endif +} + +// Compare packed signed 16-bit integers in a and b, and store packed minimum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_epi16 +FORCE_INLINE __m128i _mm_min_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s16( + vminq_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +} + +// Compare packed unsigned 8-bit integers in a and b, and store packed minimum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_epu8 +FORCE_INLINE __m128i _mm_min_epu8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u8( + vminq_u8(vreinterpretq_u8_m128i(a), vreinterpretq_u8_m128i(b))); +} + +// Compare packed double-precision (64-bit) floating-point elements in a and b, +// and store packed minimum values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_pd +FORCE_INLINE __m128d _mm_min_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 +#if SSE2NEON_PRECISE_MINMAX + float64x2_t _a = vreinterpretq_f64_m128d(a); + float64x2_t _b = vreinterpretq_f64_m128d(b); + return vreinterpretq_m128d_f64(vbslq_f64(vcltq_f64(_a, _b), _a, _b)); +#else + return vreinterpretq_m128d_f64( + vminq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#endif +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + int64_t d[2]; + d[0] = a0 < b0 ? sse2neon_recast_f64_s64(a0) : sse2neon_recast_f64_s64(b0); + d[1] = a1 < b1 ? sse2neon_recast_f64_s64(a1) : sse2neon_recast_f64_s64(b1); + return vreinterpretq_m128d_s64(vld1q_s64(d)); +#endif +} + +// Compare the lower double-precision (64-bit) floating-point elements in a and +// b, store the minimum value in the lower element of dst, and copy the upper +// element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_sd +FORCE_INLINE __m128d _mm_min_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return _mm_move_sd(a, _mm_min_pd(a, b)); +#else + double a0, a1, b0; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + a1 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + b0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double c[2] = {a0 < b0 ? a0 : b0, a1}; + return vreinterpretq_m128d_f32(sse2neon_vld1q_f32_from_f64pair(c)); +#endif +} + +// Copy the lower 64-bit integer in a to the lower element of dst, and zero the +// upper element. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_move_epi64 +FORCE_INLINE __m128i _mm_move_epi64(__m128i a) +{ + return vreinterpretq_m128i_s64( + vsetq_lane_s64(0, vreinterpretq_s64_m128i(a), 1)); +} + +// Move the lower double-precision (64-bit) floating-point element from b to the +// lower element of dst, and copy the upper element from a to the upper element +// of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_move_sd +FORCE_INLINE __m128d _mm_move_sd(__m128d a, __m128d b) +{ + return vreinterpretq_m128d_f32( + vcombine_f32(vget_low_f32(vreinterpretq_f32_m128d(b)), + vget_high_f32(vreinterpretq_f32_m128d(a)))); +} + +// Create mask from the most significant bit of each 8-bit element in a, and +// store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movemask_epi8 +// +// Input (__m128i): 16 bytes, extract bit 7 (MSB) of each +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// |0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F| byte index +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | ... | +// MSB MSB +// v v v v v v v v v v v v v v v +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// |0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F| bit position in result +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// |<-- low byte ->|<-- high byte->| +// +// Output (int): 16-bit mask where bit[i] = MSB of input byte[i] +FORCE_INLINE int _mm_movemask_epi8(__m128i a) +{ + uint8x16_t input = vreinterpretq_u8_m128i(a); + +#if SSE2NEON_ARCH_AARCH64 + // AArch64: Variable shift + horizontal add (vaddv). + // + // Step 1: Extract MSB of each byte (vshr #7: 0x80->1, 0x7F->0) + uint8x16_t msbs = vshrq_n_u8(input, 7); + + // Step 2: Shift each byte left by its bit position (0-7 per half) + // + // msbs: [ 1 ][ 0 ][ 1 ][ 1 ][ 0 ][ 1 ][ 0 ][ 1 ] (example) + // shifts: [ 0 ][ 1 ][ 2 ][ 3 ][ 4 ][ 5 ][ 6 ][ 7 ] + // | | | | | | | | + // <<0 <<1 <<2 <<3 <<4 <<5 <<6 <<7 + // v v v v v v v v + // result: [0x01][0x00][0x04][0x08][0x00][0x20][0x00][0x80] + // + // Horizontal sum: 0x01+0x04+0x08+0x20+0x80 = 0xAD = 0b10101101 + // Each bit in sum corresponds to one input byte's MSB. + static const int8_t shift_table[16] = {0, 1, 2, 3, 4, 5, 6, 7, + 0, 1, 2, 3, 4, 5, 6, 7}; + int8x16_t shifts = vld1q_s8(shift_table); + uint8x16_t positioned = vshlq_u8(msbs, shifts); + + // Step 3: Sum each half -> bits [7:0] and [15:8] + return vaddv_u8(vget_low_u8(positioned)) | + (vaddv_u8(vget_high_u8(positioned)) << 8); +#else + // ARMv7: Shift-right-accumulate (no vaddv). + // + // Step 1: Extract MSB of each byte + uint8x16_t msbs = vshrq_n_u8(input, 7); + uint64x2_t bits = vreinterpretq_u64_u8(msbs); + + // Step 2: Parallel bit collection via shift-right-accumulate + // + // Initial (8 bytes shown): + // byte: [ 0 ][ 1 ][ 2 ][ 3 ][ 4 ][ 5 ][ 6 ][ 7 ] + // value: [ 01 ][ 00 ][ 01 ][ 01 ][ 00 ][ 01 ][ 00 ][ 01 ] + // + // vsra(..., 7): add original + (original >> 7) + // byte 1 gets: orig[1] + orig[0] = b1|b0 in bits [1:0] + // byte 3 gets: orig[3] + orig[2] = b3|b2 in bits [1:0] + // ... + // Result: pairs combined into odd bytes + // + // vsra(..., 14): combine pairs -> 4 bits in bytes 3,7 + // vsra(..., 28): combine all -> 8 bits in byte 7 (actually byte 0) + bits = vsraq_n_u64(bits, bits, 7); + bits = vsraq_n_u64(bits, bits, 14); + bits = vsraq_n_u64(bits, bits, 28); + + // Step 3: Extract packed result from byte 0 of each half + uint8x16_t output = vreinterpretq_u8_u64(bits); + return vgetq_lane_u8(output, 0) | (vgetq_lane_u8(output, 8) << 8); +#endif +} + +// Set each bit of mask dst based on the most significant bit of the +// corresponding packed double-precision (64-bit) floating-point element in a. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movemask_pd +FORCE_INLINE int _mm_movemask_pd(__m128d a) +{ + uint64x2_t input = vreinterpretq_u64_m128d(a); + uint64x2_t high_bits = vshrq_n_u64(input, 63); + return _sse2neon_static_cast(int, vgetq_lane_u64(high_bits, 0) | + (vgetq_lane_u64(high_bits, 1) << 1)); +} + +// Copy the lower 64-bit integer in a to dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movepi64_pi64 +FORCE_INLINE __m64 _mm_movepi64_pi64(__m128i a) +{ + return vreinterpret_m64_s64(vget_low_s64(vreinterpretq_s64_m128i(a))); +} + +// Copy the 64-bit integer a to the lower element of dst, and zero the upper +// element. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movpi64_epi64 +FORCE_INLINE __m128i _mm_movpi64_epi64(__m64 a) +{ + return vreinterpretq_m128i_s64( + vcombine_s64(vreinterpret_s64_m64(a), vdup_n_s64(0))); +} + +// Multiply the low unsigned 32-bit integers from each packed 64-bit element in +// a and b, and store the unsigned 64-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_epu32 +FORCE_INLINE __m128i _mm_mul_epu32(__m128i a, __m128i b) +{ + // vmull_u32 upcasts instead of masking, so we downcast. + uint32x2_t a_lo = vmovn_u64(vreinterpretq_u64_m128i(a)); + uint32x2_t b_lo = vmovn_u64(vreinterpretq_u64_m128i(b)); + return vreinterpretq_m128i_u64(vmull_u32(a_lo, b_lo)); +} + +// Multiply packed double-precision (64-bit) floating-point elements in a and b, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_pd +FORCE_INLINE __m128d _mm_mul_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vmulq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + double c[2]; + c[0] = a0 * b0; + c[1] = a1 * b1; + return sse2neon_vld1q_f32_from_f64pair(c); +#endif +} + +// Multiply the lower double-precision (64-bit) floating-point element in a and +// b, store the result in the lower element of dst, and copy the upper element +// from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_mul_sd +FORCE_INLINE __m128d _mm_mul_sd(__m128d a, __m128d b) +{ + return _mm_move_sd(a, _mm_mul_pd(a, b)); +} + +// Multiply the low unsigned 32-bit integers from a and b, and store the +// unsigned 64-bit result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_su32 +FORCE_INLINE __m64 _mm_mul_su32(__m64 a, __m64 b) +{ + return vreinterpret_m64_u64(vget_low_u64( + vmull_u32(vreinterpret_u32_m64(a), vreinterpret_u32_m64(b)))); +} + +// Multiply the packed signed 16-bit integers in a and b, producing intermediate +// 32-bit integers, and store the high 16 bits of the intermediate integers in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhi_epi16 +FORCE_INLINE __m128i _mm_mulhi_epi16(__m128i a, __m128i b) +{ + // vmull_s16 is used instead of vqdmulhq_s16 to avoid saturation issues + // with large values (e.g., -32768 * -32768). vmull_s16 produces full 32-bit + // products without saturation. + int16x4_t a3210 = vget_low_s16(vreinterpretq_s16_m128i(a)); + int16x4_t b3210 = vget_low_s16(vreinterpretq_s16_m128i(b)); + int32x4_t ab3210 = vmull_s16(a3210, b3210); /* 3333222211110000 */ + int16x4_t a7654 = vget_high_s16(vreinterpretq_s16_m128i(a)); + int16x4_t b7654 = vget_high_s16(vreinterpretq_s16_m128i(b)); + int32x4_t ab7654 = vmull_s16(a7654, b7654); /* 7777666655554444 */ + uint16x8x2_t r = + vuzpq_u16(vreinterpretq_u16_s32(ab3210), vreinterpretq_u16_s32(ab7654)); + return vreinterpretq_m128i_u16(r.val[1]); +} + +// Multiply the packed unsigned 16-bit integers in a and b, producing +// intermediate 32-bit integers, and store the high 16 bits of the intermediate +// integers in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhi_epu16 +FORCE_INLINE __m128i _mm_mulhi_epu16(__m128i a, __m128i b) +{ + uint16x4_t a3210 = vget_low_u16(vreinterpretq_u16_m128i(a)); + uint16x4_t b3210 = vget_low_u16(vreinterpretq_u16_m128i(b)); + uint32x4_t ab3210 = vmull_u16(a3210, b3210); +#if SSE2NEON_ARCH_AARCH64 + uint32x4_t ab7654 = + vmull_high_u16(vreinterpretq_u16_m128i(a), vreinterpretq_u16_m128i(b)); + uint16x8_t r = vuzp2q_u16(vreinterpretq_u16_u32(ab3210), + vreinterpretq_u16_u32(ab7654)); + return vreinterpretq_m128i_u16(r); +#else + uint16x4_t a7654 = vget_high_u16(vreinterpretq_u16_m128i(a)); + uint16x4_t b7654 = vget_high_u16(vreinterpretq_u16_m128i(b)); + uint32x4_t ab7654 = vmull_u16(a7654, b7654); + uint16x8x2_t r = + vuzpq_u16(vreinterpretq_u16_u32(ab3210), vreinterpretq_u16_u32(ab7654)); + return vreinterpretq_m128i_u16(r.val[1]); +#endif +} + +// Multiply the packed 16-bit integers in a and b, producing intermediate 32-bit +// integers, and store the low 16 bits of the intermediate integers in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mullo_epi16 +FORCE_INLINE __m128i _mm_mullo_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s16( + vmulq_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +} + +// Compute the bitwise OR of packed double-precision (64-bit) floating-point +// elements in a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_or_pd +FORCE_INLINE __m128d _mm_or_pd(__m128d a, __m128d b) +{ + return vreinterpretq_m128d_s64( + vorrq_s64(vreinterpretq_s64_m128d(a), vreinterpretq_s64_m128d(b))); +} + +// Compute the bitwise OR of 128 bits (representing integer data) in a and b, +// and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_or_si128 +FORCE_INLINE __m128i _mm_or_si128(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s32( + vorrq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +// Convert packed signed 16-bit integers from a and b to packed 8-bit integers +// using signed saturation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packs_epi16 +FORCE_INLINE __m128i _mm_packs_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s8( + vcombine_s8(vqmovn_s16(vreinterpretq_s16_m128i(a)), + vqmovn_s16(vreinterpretq_s16_m128i(b)))); +} + +// Convert packed signed 32-bit integers from a and b to packed 16-bit integers +// using signed saturation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packs_epi32 +FORCE_INLINE __m128i _mm_packs_epi32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s16( + vcombine_s16(vqmovn_s32(vreinterpretq_s32_m128i(a)), + vqmovn_s32(vreinterpretq_s32_m128i(b)))); +} + +// Convert packed signed 16-bit integers from a and b to packed 8-bit integers +// using unsigned saturation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packus_epi16 +FORCE_INLINE __m128i _mm_packus_epi16(const __m128i a, const __m128i b) +{ + return vreinterpretq_m128i_u8( + vcombine_u8(vqmovun_s16(vreinterpretq_s16_m128i(a)), + vqmovun_s16(vreinterpretq_s16_m128i(b)))); +} + +// Pause the processor. This is typically used in spin-wait loops and depending +// on the x86 processor typical values are in the 40-100 cycle range. The +// 'yield' instruction isn't a good fit because it's effectively a nop on most +// Arm cores. Experience with several databases has shown has shown an 'isb' is +// a reasonable approximation. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_pause +FORCE_INLINE void _mm_pause(void) +{ +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG + __isb(_ARM64_BARRIER_SY); +#else + __asm__ __volatile__("isb\n"); +#endif +} + +// Compute the absolute differences of packed unsigned 8-bit integers in a and +// b, then horizontally sum each consecutive 8 differences to produce two +// unsigned 16-bit integers, and pack these unsigned 16-bit integers in the low +// 16 bits of 64-bit elements in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sad_epu8 +FORCE_INLINE __m128i _mm_sad_epu8(__m128i a, __m128i b) +{ + uint16x8_t t = vpaddlq_u8( + vabdq_u8(vreinterpretq_u8_m128i(a), vreinterpretq_u8_m128i(b))); + return vreinterpretq_m128i_u64(vpaddlq_u32(vpaddlq_u16(t))); +} + +// Set packed 16-bit integers in dst with the supplied values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_epi16 +FORCE_INLINE __m128i _mm_set_epi16(short i7, + short i6, + short i5, + short i4, + short i3, + short i2, + short i1, + short i0) +{ + int16_t ALIGN_STRUCT(16) data[8] = {i0, i1, i2, i3, i4, i5, i6, i7}; + return vreinterpretq_m128i_s16(vld1q_s16(data)); +} + +// Set packed 32-bit integers in dst with the supplied values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_epi32 +FORCE_INLINE __m128i _mm_set_epi32(int i3, int i2, int i1, int i0) +{ + int32_t ALIGN_STRUCT(16) data[4] = {i0, i1, i2, i3}; + return vreinterpretq_m128i_s32(vld1q_s32(data)); +} + +// Set packed 64-bit integers in dst with the supplied values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_epi64 +FORCE_INLINE __m128i _mm_set_epi64(__m64 i1, __m64 i2) +{ + return _mm_set_epi64x(vget_lane_s64(i1, 0), vget_lane_s64(i2, 0)); +} + +// Set packed 64-bit integers in dst with the supplied values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_epi64x +FORCE_INLINE __m128i _mm_set_epi64x(int64_t i1, int64_t i2) +{ + return vreinterpretq_m128i_s64( + vcombine_s64(vcreate_s64(i2), vcreate_s64(i1))); +} + +// Set packed 8-bit integers in dst with the supplied values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_epi8 +FORCE_INLINE __m128i _mm_set_epi8(signed char b15, + signed char b14, + signed char b13, + signed char b12, + signed char b11, + signed char b10, + signed char b9, + signed char b8, + signed char b7, + signed char b6, + signed char b5, + signed char b4, + signed char b3, + signed char b2, + signed char b1, + signed char b0) +{ + int8_t ALIGN_STRUCT(16) data[16] = { + _sse2neon_static_cast(int8_t, b0), _sse2neon_static_cast(int8_t, b1), + _sse2neon_static_cast(int8_t, b2), _sse2neon_static_cast(int8_t, b3), + _sse2neon_static_cast(int8_t, b4), _sse2neon_static_cast(int8_t, b5), + _sse2neon_static_cast(int8_t, b6), _sse2neon_static_cast(int8_t, b7), + _sse2neon_static_cast(int8_t, b8), _sse2neon_static_cast(int8_t, b9), + _sse2neon_static_cast(int8_t, b10), _sse2neon_static_cast(int8_t, b11), + _sse2neon_static_cast(int8_t, b12), _sse2neon_static_cast(int8_t, b13), + _sse2neon_static_cast(int8_t, b14), _sse2neon_static_cast(int8_t, b15)}; + return vreinterpretq_m128i_s8(vld1q_s8(data)); +} + +// Set packed double-precision (64-bit) floating-point elements in dst with the +// supplied values. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_pd +FORCE_INLINE __m128d _mm_set_pd(double e1, double e0) +{ + double ALIGN_STRUCT(16) data[2] = {e0, e1}; +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vld1q_f64(_sse2neon_reinterpret_cast(float64_t *, data))); +#else + return vreinterpretq_m128d_f32(sse2neon_vld1q_f32_from_f64pair(data)); +#endif +} + +// Broadcast double-precision (64-bit) floating-point value a to all elements of +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_pd1 +#define _mm_set_pd1 _mm_set1_pd + +// Copy double-precision (64-bit) floating-point element a to the lower element +// of dst, and zero the upper element. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set_sd +FORCE_INLINE __m128d _mm_set_sd(double a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vsetq_lane_f64(a, vdupq_n_f64(0), 0)); +#else + return _mm_set_pd(0, a); +#endif +} + +// Broadcast 16-bit integer a to all elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_epi16 +FORCE_INLINE __m128i _mm_set1_epi16(short w) +{ + return vreinterpretq_m128i_s16(vdupq_n_s16(w)); +} + +// Broadcast 32-bit integer a to all elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_epi32 +FORCE_INLINE __m128i _mm_set1_epi32(int _i) +{ + return vreinterpretq_m128i_s32(vdupq_n_s32(_i)); +} + +// Broadcast 64-bit integer a to all elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_epi64 +FORCE_INLINE __m128i _mm_set1_epi64(__m64 _i) +{ + return vreinterpretq_m128i_s64(vdupq_lane_s64(_i, 0)); +} + +// Broadcast 64-bit integer a to all elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_epi64x +FORCE_INLINE __m128i _mm_set1_epi64x(int64_t _i) +{ + return vreinterpretq_m128i_s64(vdupq_n_s64(_i)); +} + +// Broadcast 8-bit integer a to all elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_epi8 +FORCE_INLINE __m128i _mm_set1_epi8(signed char w) +{ + return vreinterpretq_m128i_s8(vdupq_n_s8(w)); +} + +// Broadcast double-precision (64-bit) floating-point value a to all elements of +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_set1_pd +FORCE_INLINE __m128d _mm_set1_pd(double d) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vdupq_n_f64(d)); +#else + int64_t _d = sse2neon_recast_f64_s64(d); + return vreinterpretq_m128d_s64(vdupq_n_s64(_d)); +#endif +} + +// Set packed 16-bit integers in dst with the supplied values in reverse order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_epi16 +FORCE_INLINE __m128i _mm_setr_epi16(short w0, + short w1, + short w2, + short w3, + short w4, + short w5, + short w6, + short w7) +{ + int16_t ALIGN_STRUCT(16) data[8] = {w0, w1, w2, w3, w4, w5, w6, w7}; + return vreinterpretq_m128i_s16( + vld1q_s16(_sse2neon_reinterpret_cast(int16_t *, data))); +} + +// Set packed 32-bit integers in dst with the supplied values in reverse order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_epi32 +FORCE_INLINE __m128i _mm_setr_epi32(int i3, int i2, int i1, int i0) +{ + int32_t ALIGN_STRUCT(16) data[4] = {i3, i2, i1, i0}; + return vreinterpretq_m128i_s32(vld1q_s32(data)); +} + +// Set packed 64-bit integers in dst with the supplied values in reverse order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_epi64 +FORCE_INLINE __m128i _mm_setr_epi64(__m64 e1, __m64 e0) +{ + return vreinterpretq_m128i_s64(vcombine_s64(e1, e0)); +} + +// Set packed 8-bit integers in dst with the supplied values in reverse order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_epi8 +FORCE_INLINE __m128i _mm_setr_epi8(signed char b0, + signed char b1, + signed char b2, + signed char b3, + signed char b4, + signed char b5, + signed char b6, + signed char b7, + signed char b8, + signed char b9, + signed char b10, + signed char b11, + signed char b12, + signed char b13, + signed char b14, + signed char b15) +{ + int8_t ALIGN_STRUCT(16) data[16] = { + _sse2neon_static_cast(int8_t, b0), _sse2neon_static_cast(int8_t, b1), + _sse2neon_static_cast(int8_t, b2), _sse2neon_static_cast(int8_t, b3), + _sse2neon_static_cast(int8_t, b4), _sse2neon_static_cast(int8_t, b5), + _sse2neon_static_cast(int8_t, b6), _sse2neon_static_cast(int8_t, b7), + _sse2neon_static_cast(int8_t, b8), _sse2neon_static_cast(int8_t, b9), + _sse2neon_static_cast(int8_t, b10), _sse2neon_static_cast(int8_t, b11), + _sse2neon_static_cast(int8_t, b12), _sse2neon_static_cast(int8_t, b13), + _sse2neon_static_cast(int8_t, b14), _sse2neon_static_cast(int8_t, b15)}; + return vreinterpretq_m128i_s8(vld1q_s8(data)); +} + +// Set packed double-precision (64-bit) floating-point elements in dst with the +// supplied values in reverse order. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setr_pd +FORCE_INLINE __m128d _mm_setr_pd(double e1, double e0) +{ + return _mm_set_pd(e0, e1); +} + +// Return vector of type __m128d with all elements set to zero. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setzero_pd +FORCE_INLINE __m128d _mm_setzero_pd(void) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vdupq_n_f64(0)); +#else + return vreinterpretq_m128d_f32(vdupq_n_f32(0)); +#endif +} + +// Return vector of type __m128i with all elements set to zero. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_setzero_si128 +FORCE_INLINE __m128i _mm_setzero_si128(void) +{ + return vreinterpretq_m128i_s32(vdupq_n_s32(0)); +} + +// Shuffle 32-bit integers in a using the control in imm8, and store the results +// in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_epi32 +// FORCE_INLINE __m128i _mm_shuffle_epi32(__m128i a, const int imm) +// imm must be a compile-time constant in range [0, 255] +#if defined(_sse2neon_shuffle) +#define _mm_shuffle_epi32(a, imm) \ + __extension__({ \ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); \ + int32x4_t _input = vreinterpretq_s32_m128i(a); \ + int32x4_t _shuf = \ + vshuffleq_s32(_input, _input, (imm) & (0x3), ((imm) >> 2) & 0x3, \ + ((imm) >> 4) & 0x3, ((imm) >> 6) & 0x3); \ + vreinterpretq_m128i_s32(_shuf); \ + }) +#elif SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) // generic +#define _mm_shuffle_epi32(a, imm) \ + _sse2neon_define1( \ + __m128i, a, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); __m128i ret; \ + switch (imm) { \ + case _MM_SHUFFLE(1, 0, 3, 2): \ + ret = _mm_shuffle_epi_1032(_a); \ + break; \ + case _MM_SHUFFLE(2, 3, 0, 1): \ + ret = _mm_shuffle_epi_2301(_a); \ + break; \ + case _MM_SHUFFLE(0, 3, 2, 1): \ + ret = _mm_shuffle_epi_0321(_a); \ + break; \ + case _MM_SHUFFLE(2, 1, 0, 3): \ + ret = _mm_shuffle_epi_2103(_a); \ + break; \ + case _MM_SHUFFLE(1, 0, 1, 0): \ + ret = _mm_shuffle_epi_1010(_a); \ + break; \ + case _MM_SHUFFLE(1, 0, 0, 1): \ + ret = _mm_shuffle_epi_1001(_a); \ + break; \ + case _MM_SHUFFLE(0, 1, 0, 1): \ + ret = _mm_shuffle_epi_0101(_a); \ + break; \ + case _MM_SHUFFLE(2, 2, 1, 1): \ + ret = _mm_shuffle_epi_2211(_a); \ + break; \ + case _MM_SHUFFLE(0, 1, 2, 2): \ + ret = _mm_shuffle_epi_0122(_a); \ + break; \ + case _MM_SHUFFLE(3, 3, 3, 2): \ + ret = _mm_shuffle_epi_3332(_a); \ + break; \ + case _MM_SHUFFLE(0, 0, 0, 0): \ + ret = _mm_shuffle_epi32_splat(_a, 0); \ + break; \ + case _MM_SHUFFLE(1, 1, 1, 1): \ + ret = _mm_shuffle_epi32_splat(_a, 1); \ + break; \ + case _MM_SHUFFLE(2, 2, 2, 2): \ + ret = _mm_shuffle_epi32_splat(_a, 2); \ + break; \ + case _MM_SHUFFLE(3, 3, 3, 3): \ + ret = _mm_shuffle_epi32_splat(_a, 3); \ + break; \ + default: \ + ret = _mm_shuffle_epi32_default(_a, (imm)); \ + break; \ + } _sse2neon_return(ret);) +#else // pure C (MSVC C mode) +FORCE_INLINE __m128i _mm_shuffle_epi32(__m128i a, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + __m128i ret; + switch (imm) { + case _MM_SHUFFLE(1, 0, 3, 2): + ret = _mm_shuffle_epi_1032(a); + break; + case _MM_SHUFFLE(2, 3, 0, 1): + ret = _mm_shuffle_epi_2301(a); + break; + case _MM_SHUFFLE(0, 3, 2, 1): + ret = _mm_shuffle_epi_0321(a); + break; + case _MM_SHUFFLE(2, 1, 0, 3): + ret = _mm_shuffle_epi_2103(a); + break; + case _MM_SHUFFLE(1, 0, 1, 0): + ret = _mm_shuffle_epi_1010(a); + break; + case _MM_SHUFFLE(1, 0, 0, 1): + ret = _mm_shuffle_epi_1001(a); + break; + case _MM_SHUFFLE(0, 1, 0, 1): + ret = _mm_shuffle_epi_0101(a); + break; + case _MM_SHUFFLE(2, 2, 1, 1): + ret = _mm_shuffle_epi_2211(a); + break; + case _MM_SHUFFLE(0, 1, 2, 2): + ret = _mm_shuffle_epi_0122(a); + break; + case _MM_SHUFFLE(3, 3, 3, 2): + ret = _mm_shuffle_epi_3332(a); + break; + case _MM_SHUFFLE(0, 0, 0, 0): + ret = _mm_shuffle_epi32_splat(a, 0); + break; + case _MM_SHUFFLE(1, 1, 1, 1): + ret = _mm_shuffle_epi32_splat(a, 1); + break; + case _MM_SHUFFLE(2, 2, 2, 2): + ret = _mm_shuffle_epi32_splat(a, 2); + break; + case _MM_SHUFFLE(3, 3, 3, 3): + ret = _mm_shuffle_epi32_splat(a, 3); + break; + default: + ret = _mm_shuffle_epi32_default(a, imm); + break; + } + return ret; +} +#endif + +// Shuffle double-precision (64-bit) floating-point elements using the control +// in imm8, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_pd +// imm8 must be a compile-time constant in range [0, 3] +#ifdef _sse2neon_shuffle +#define _mm_shuffle_pd(a, b, imm8) \ + __extension__({ \ + SSE2NEON_REQUIRE_CONST_RANGE(imm8, 0, 3); \ + vreinterpretq_m128d_s64(vshuffleq_s64( \ + vreinterpretq_s64_m128d(a), vreinterpretq_s64_m128d(b), \ + (imm8) & 0x1, (((imm8) & 0x2) >> 1) + 2)); \ + }) +#else +#define _mm_shuffle_pd(a, b, imm8) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm8, 0, 3), \ + _mm_castsi128_pd(_mm_set_epi64x( \ + vgetq_lane_s64(vreinterpretq_s64_m128d(b), ((imm8) & 0x2) >> 1), \ + vgetq_lane_s64(vreinterpretq_s64_m128d(a), (imm8) & 0x1)))) +#endif + +// FORCE_INLINE __m128i _mm_shufflehi_epi16(__m128i a, const int imm) +// imm must be a compile-time constant in range [0, 255] +#if defined(_sse2neon_shuffle) +#define _mm_shufflehi_epi16(a, imm) \ + __extension__({ \ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); \ + int16x8_t _input = vreinterpretq_s16_m128i(a); \ + int16x8_t _shuf = \ + vshuffleq_s16(_input, _input, 0, 1, 2, 3, ((imm) & (0x3)) + 4, \ + (((imm) >> 2) & 0x3) + 4, (((imm) >> 4) & 0x3) + 4, \ + (((imm) >> 6) & 0x3) + 4); \ + vreinterpretq_m128i_s16(_shuf); \ + }) +#else +#define _mm_shufflehi_epi16(a, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255), \ + _mm_shufflehi_epi16_function((a), (imm))) +#endif + +// FORCE_INLINE __m128i _mm_shufflelo_epi16(__m128i a, const int imm) +// imm must be a compile-time constant in range [0, 255] +#if defined(_sse2neon_shuffle) +#define _mm_shufflelo_epi16(a, imm) \ + __extension__({ \ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); \ + int16x8_t _input = vreinterpretq_s16_m128i(a); \ + int16x8_t _shuf = vshuffleq_s16( \ + _input, _input, ((imm) & (0x3)), (((imm) >> 2) & 0x3), \ + (((imm) >> 4) & 0x3), (((imm) >> 6) & 0x3), 4, 5, 6, 7); \ + vreinterpretq_m128i_s16(_shuf); \ + }) +#else +#define _mm_shufflelo_epi16(a, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255), \ + _mm_shufflelo_epi16_function((a), (imm))) +#endif + +// Shift packed 16-bit integers in a left by count while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sll_epi16 +FORCE_INLINE __m128i _mm_sll_epi16(__m128i a, __m128i count) +{ + uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); + if (_sse2neon_unlikely(c > 15)) + return _mm_setzero_si128(); + + int16x8_t vc = vdupq_n_s16(_sse2neon_static_cast(int16_t, c)); + return vreinterpretq_m128i_s16(vshlq_s16(vreinterpretq_s16_m128i(a), vc)); +} + +// Shift packed 32-bit integers in a left by count while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sll_epi32 +FORCE_INLINE __m128i _mm_sll_epi32(__m128i a, __m128i count) +{ + uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); + if (_sse2neon_unlikely(c > 31)) + return _mm_setzero_si128(); + + int32x4_t vc = vdupq_n_s32(_sse2neon_static_cast(int32_t, c)); + return vreinterpretq_m128i_s32(vshlq_s32(vreinterpretq_s32_m128i(a), vc)); +} + +// Shift packed 64-bit integers in a left by count while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sll_epi64 +FORCE_INLINE __m128i _mm_sll_epi64(__m128i a, __m128i count) +{ + uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); + if (_sse2neon_unlikely(c > 63)) + return _mm_setzero_si128(); + + int64x2_t vc = vdupq_n_s64(_sse2neon_static_cast(int64_t, c)); + return vreinterpretq_m128i_s64(vshlq_s64(vreinterpretq_s64_m128i(a), vc)); +} + +// Shift packed 16-bit integers in a left by imm8 while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_epi16 +FORCE_INLINE __m128i _mm_slli_epi16(__m128i a, int imm) +{ + if (_sse2neon_unlikely(imm & ~15)) + return _mm_setzero_si128(); + return vreinterpretq_m128i_s16( + vshlq_s16(vreinterpretq_s16_m128i(a), + vdupq_n_s16(_sse2neon_static_cast(int16_t, imm)))); +} + +// Shift packed 32-bit integers in a left by imm8 while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_epi32 +FORCE_INLINE __m128i _mm_slli_epi32(__m128i a, int imm) +{ + if (_sse2neon_unlikely(imm & ~31)) + return _mm_setzero_si128(); + return vreinterpretq_m128i_s32( + vshlq_s32(vreinterpretq_s32_m128i(a), vdupq_n_s32(imm))); +} + +// Shift packed 64-bit integers in a left by imm8 while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_epi64 +FORCE_INLINE __m128i _mm_slli_epi64(__m128i a, int imm) +{ + if (_sse2neon_unlikely(imm & ~63)) + return _mm_setzero_si128(); + return vreinterpretq_m128i_s64( + vshlq_s64(vreinterpretq_s64_m128i(a), vdupq_n_s64(imm))); +} + +// Shift a left by imm8 bytes while shifting in zeros, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_slli_si128 +// imm must be a compile-time constant in range [0, 255] +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_slli_si128(a, imm) \ + _sse2neon_define1( \ + __m128i, a, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); int8x16_t ret; \ + if (_sse2neon_unlikely((imm) == 0)) ret = vreinterpretq_s8_m128i(_a); \ + else if (_sse2neon_unlikely((imm) & ~15)) ret = vdupq_n_s8(0); \ + else ret = vextq_s8(vdupq_n_s8(0), vreinterpretq_s8_m128i(_a), \ + (((imm) <= 0 || (imm) > 15) ? 0 : (16 - (imm)))); \ + _sse2neon_return(vreinterpretq_m128i_s8(ret));) +#else + +#define _sse2neon_vextq_s8_case_helper(val) \ + case val: \ + return vextq_s8(a, b, val) + +FORCE_INLINE int8x16_t _sse2neon_vextq_s8(int8x16_t a, int8x16_t b, int c) +{ + switch (c) { + _sse2neon_vextq_s8_case_helper(0); + _sse2neon_vextq_s8_case_helper(1); + _sse2neon_vextq_s8_case_helper(2); + _sse2neon_vextq_s8_case_helper(3); + _sse2neon_vextq_s8_case_helper(4); + _sse2neon_vextq_s8_case_helper(5); + _sse2neon_vextq_s8_case_helper(6); + _sse2neon_vextq_s8_case_helper(7); + _sse2neon_vextq_s8_case_helper(8); + _sse2neon_vextq_s8_case_helper(9); + _sse2neon_vextq_s8_case_helper(10); + _sse2neon_vextq_s8_case_helper(11); + _sse2neon_vextq_s8_case_helper(12); + _sse2neon_vextq_s8_case_helper(13); + _sse2neon_vextq_s8_case_helper(14); + default: // case 15 + return vextq_s8(a, b, 15); + } +} + +#define _sse2neon_vextq_u8_case_helper(val) \ + case val: \ + return vextq_u8(a, b, val) + +FORCE_INLINE uint8x16_t _sse2neon_vextq_u8(uint8x16_t a, uint8x16_t b, int c) +{ + switch (c) { + _sse2neon_vextq_u8_case_helper(0); + _sse2neon_vextq_u8_case_helper(1); + _sse2neon_vextq_u8_case_helper(2); + _sse2neon_vextq_u8_case_helper(3); + _sse2neon_vextq_u8_case_helper(4); + _sse2neon_vextq_u8_case_helper(5); + _sse2neon_vextq_u8_case_helper(6); + _sse2neon_vextq_u8_case_helper(7); + _sse2neon_vextq_u8_case_helper(8); + _sse2neon_vextq_u8_case_helper(9); + _sse2neon_vextq_u8_case_helper(10); + _sse2neon_vextq_u8_case_helper(11); + _sse2neon_vextq_u8_case_helper(12); + _sse2neon_vextq_u8_case_helper(13); + _sse2neon_vextq_u8_case_helper(14); + default: // case 15 + return vextq_u8(a, b, 15); + } +} + +#define _sse2neon_vext_u8_case_helper(val) \ + case val: \ + return vext_u8(a, b, val) + +FORCE_INLINE uint8x8_t _sse2neon_vext_u8(uint8x8_t a, uint8x8_t b, int c) +{ + switch (c) { + _sse2neon_vext_u8_case_helper(0); + _sse2neon_vext_u8_case_helper(1); + _sse2neon_vext_u8_case_helper(2); + _sse2neon_vext_u8_case_helper(3); + _sse2neon_vext_u8_case_helper(4); + _sse2neon_vext_u8_case_helper(5); + _sse2neon_vext_u8_case_helper(6); + default: // case 7 + return vext_u8(a, b, 7); + } +} + +FORCE_INLINE __m128i _mm_slli_si128(__m128i a, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + int8x16_t ret; + if (_sse2neon_unlikely(imm == 0)) + ret = vreinterpretq_s8_m128i(a); + else if (_sse2neon_unlikely(imm & ~15)) + ret = vdupq_n_s8(0); + else + ret = _sse2neon_vextq_s8(vdupq_n_s8(0), vreinterpretq_s8_m128i(a), + ((imm <= 0 || imm > 15) ? 0 : (16 - imm))); + return vreinterpretq_m128i_s8(ret); +} +#endif + +// Compute the square root of packed double-precision (64-bit) floating-point +// elements in a, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sqrt_pd +FORCE_INLINE __m128d _mm_sqrt_pd(__m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vsqrtq_f64(vreinterpretq_f64_m128d(a))); +#else + double a0, a1; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + a1 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double _a0 = sqrt(a0); + double _a1 = sqrt(a1); + return _mm_set_pd(_a1, _a0); +#endif +} + +// Compute the square root of the lower double-precision (64-bit) floating-point +// element in b, store the result in the lower element of dst, and copy the +// upper element from a to the upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sqrt_sd +FORCE_INLINE __m128d _mm_sqrt_sd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return _mm_move_sd(a, _mm_sqrt_pd(b)); +#else + double _a, _b; + _a = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + _b = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + return _mm_set_pd(_a, sqrt(_b)); +#endif +} + +// Shift packed 16-bit integers in a right by count while shifting in sign bits, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sra_epi16 +FORCE_INLINE __m128i _mm_sra_epi16(__m128i a, __m128i count) +{ + uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); + if (_sse2neon_unlikely(c > 15)) + return _mm_cmplt_epi16(a, _mm_setzero_si128()); + return vreinterpretq_m128i_s16( + vshlq_s16(vreinterpretq_s16_m128i(a), + vdupq_n_s16(-_sse2neon_static_cast(int16_t, c)))); +} + +// Shift packed 32-bit integers in a right by count while shifting in sign bits, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sra_epi32 +FORCE_INLINE __m128i _mm_sra_epi32(__m128i a, __m128i count) +{ + uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); + if (_sse2neon_unlikely(c > 31)) + return _mm_cmplt_epi32(a, _mm_setzero_si128()); + return vreinterpretq_m128i_s32( + vshlq_s32(vreinterpretq_s32_m128i(a), + vdupq_n_s32(-_sse2neon_static_cast(int32_t, c)))); +} + +// Shift packed 16-bit integers in a right by imm8 while shifting in sign +// bits, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srai_epi16 +FORCE_INLINE __m128i _mm_srai_epi16(__m128i a, int imm) +{ + const int16_t count = + (imm & ~15) ? 15 : _sse2neon_static_cast(int16_t, imm); + return vreinterpretq_m128i_s16( + vshlq_s16(vreinterpretq_s16_m128i(a), vdupq_n_s16(-count))); +} + +// Shift packed 32-bit integers in a right by imm8 while shifting in sign bits, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srai_epi32 +// FORCE_INLINE __m128i _mm_srai_epi32(__m128i a, const int imm) +// imm must be a compile-time constant in range [0, 255] +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_srai_epi32(a, imm) \ + _sse2neon_define0( \ + __m128i, a, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); __m128i ret; \ + if (_sse2neon_unlikely((imm) == 0)) { \ + ret = _a; \ + } else if (_sse2neon_likely(0 < (imm) && (imm) < 32)) { \ + ret = vreinterpretq_m128i_s32( \ + vshlq_s32(vreinterpretq_s32_m128i(_a), vdupq_n_s32(-(imm)))); \ + } else { \ + ret = vreinterpretq_m128i_s32( \ + vshrq_n_s32(vreinterpretq_s32_m128i(_a), 31)); \ + } _sse2neon_return(ret);) +#else +FORCE_INLINE __m128i _mm_srai_epi32(__m128i a, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + __m128i ret; + if (_sse2neon_unlikely(imm == 0)) { + ret = a; + } else if (_sse2neon_likely(0 < imm && imm < 32)) { + ret = vreinterpretq_m128i_s32( + vshlq_s32(vreinterpretq_s32_m128i(a), vdupq_n_s32(-imm))); + } else { + ret = vreinterpretq_m128i_s32( + vshrq_n_s32(vreinterpretq_s32_m128i(a), 31)); + } + return ret; +} +#endif + +// Shift packed 16-bit integers in a right by count while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srl_epi16 +FORCE_INLINE __m128i _mm_srl_epi16(__m128i a, __m128i count) +{ + uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); + if (_sse2neon_unlikely(c > 15)) + return _mm_setzero_si128(); + + int16x8_t vc = vdupq_n_s16(-_sse2neon_static_cast(int16_t, c)); + return vreinterpretq_m128i_u16(vshlq_u16(vreinterpretq_u16_m128i(a), vc)); +} + +// Shift packed 32-bit integers in a right by count while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srl_epi32 +FORCE_INLINE __m128i _mm_srl_epi32(__m128i a, __m128i count) +{ + uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); + if (_sse2neon_unlikely(c > 31)) + return _mm_setzero_si128(); + + int32x4_t vc = vdupq_n_s32(-_sse2neon_static_cast(int32_t, c)); + return vreinterpretq_m128i_u32(vshlq_u32(vreinterpretq_u32_m128i(a), vc)); +} + +// Shift packed 64-bit integers in a right by count while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srl_epi64 +FORCE_INLINE __m128i _mm_srl_epi64(__m128i a, __m128i count) +{ + uint64_t c = vreinterpretq_nth_u64_m128i(count, 0); + if (_sse2neon_unlikely(c > 63)) + return _mm_setzero_si128(); + + int64x2_t vc = vdupq_n_s64(-_sse2neon_static_cast(int64_t, c)); + return vreinterpretq_m128i_u64(vshlq_u64(vreinterpretq_u64_m128i(a), vc)); +} + +// Shift packed 16-bit integers in a right by imm8 while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_epi16 +// imm must be a compile-time constant in range [0, 255] +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_srli_epi16(a, imm) \ + _sse2neon_define0( \ + __m128i, a, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); __m128i ret; \ + if (_sse2neon_unlikely((imm) & ~15)) { \ + ret = _mm_setzero_si128(); \ + } else { \ + ret = vreinterpretq_m128i_u16(vshlq_u16( \ + vreinterpretq_u16_m128i(_a), \ + vdupq_n_s16(_sse2neon_static_cast(int16_t, -(imm))))); \ + } _sse2neon_return(ret);) +#else +FORCE_INLINE __m128i _mm_srli_epi16(__m128i a, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + if (_sse2neon_unlikely(imm & ~15)) + return _mm_setzero_si128(); + return vreinterpretq_m128i_u16( + vshlq_u16(vreinterpretq_u16_m128i(a), + vdupq_n_s16(_sse2neon_static_cast(int16_t, -imm)))); +} +#endif + +// Shift packed 32-bit integers in a right by imm8 while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_epi32 +// FORCE_INLINE __m128i _mm_srli_epi32(__m128i a, const int imm) +// imm must be a compile-time constant in range [0, 255] +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_srli_epi32(a, imm) \ + _sse2neon_define0( \ + __m128i, a, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); __m128i ret; \ + if (_sse2neon_unlikely((imm) & ~31)) { \ + ret = _mm_setzero_si128(); \ + } else { \ + ret = vreinterpretq_m128i_u32( \ + vshlq_u32(vreinterpretq_u32_m128i(_a), vdupq_n_s32(-(imm)))); \ + } _sse2neon_return(ret);) +#else +FORCE_INLINE __m128i _mm_srli_epi32(__m128i a, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + if (_sse2neon_unlikely(imm & ~31)) + return _mm_setzero_si128(); + return vreinterpretq_m128i_u32( + vshlq_u32(vreinterpretq_u32_m128i(a), vdupq_n_s32(-imm))); +} +#endif + +// Shift packed 64-bit integers in a right by imm8 while shifting in zeros, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_epi64 +// imm must be a compile-time constant in range [0, 255] +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_srli_epi64(a, imm) \ + _sse2neon_define0( \ + __m128i, a, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); __m128i ret; \ + if (_sse2neon_unlikely((imm) & ~63)) { \ + ret = _mm_setzero_si128(); \ + } else { \ + ret = vreinterpretq_m128i_u64( \ + vshlq_u64(vreinterpretq_u64_m128i(_a), vdupq_n_s64(-(imm)))); \ + } _sse2neon_return(ret);) +#else +FORCE_INLINE __m128i _mm_srli_epi64(__m128i a, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + if (_sse2neon_unlikely(imm & ~63)) + return _mm_setzero_si128(); + return vreinterpretq_m128i_u64( + vshlq_u64(vreinterpretq_u64_m128i(a), vdupq_n_s64(-imm))); +} +#endif + +// Shift a right by imm8 bytes while shifting in zeros, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_srli_si128 +// imm must be a compile-time constant in range [0, 255] +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_srli_si128(a, imm) \ + _sse2neon_define1( \ + __m128i, a, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); int8x16_t ret; \ + if (_sse2neon_unlikely((imm) & ~15)) ret = vdupq_n_s8(0); \ + else ret = vextq_s8(vreinterpretq_s8_m128i(_a), vdupq_n_s8(0), \ + ((imm) > 15 ? 0 : (imm))); \ + _sse2neon_return(vreinterpretq_m128i_s8(ret));) +#else +FORCE_INLINE __m128i _mm_srli_si128(__m128i a, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + int8x16_t ret; + if (_sse2neon_unlikely(imm & ~15)) + ret = vdupq_n_s8(0); + else + ret = _sse2neon_vextq_s8(vreinterpretq_s8_m128i(a), vdupq_n_s8(0), + (imm > 15 ? 0 : imm)); + return vreinterpretq_m128i_s8(ret); +} +#endif + +// Store 128-bits (composed of 2 packed double-precision (64-bit) floating-point +// elements) from a into memory. mem_addr must be aligned on a 16-byte boundary +// or a general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_pd +FORCE_INLINE void _mm_store_pd(double *mem_addr, __m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + vst1q_f64(_sse2neon_reinterpret_cast(float64_t *, mem_addr), + vreinterpretq_f64_m128d(a)); +#else + vst1q_f32(_sse2neon_reinterpret_cast(float32_t *, mem_addr), + vreinterpretq_f32_m128d(a)); +#endif +} + +// Store the lower double-precision (64-bit) floating-point element from a into +// 2 contiguous elements in memory. mem_addr must be aligned on a 16-byte +// boundary or a general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_pd1 +FORCE_INLINE void _mm_store_pd1(double *mem_addr, __m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + float64x1_t a_low = vget_low_f64(vreinterpretq_f64_m128d(a)); + vst1q_f64(_sse2neon_reinterpret_cast(float64_t *, mem_addr), + vreinterpretq_f64_m128d(vcombine_f64(a_low, a_low))); +#else + float32x2_t a_low = vget_low_f32(vreinterpretq_f32_m128d(a)); + vst1q_f32(_sse2neon_reinterpret_cast(float32_t *, mem_addr), + vreinterpretq_f32_m128d(vcombine_f32(a_low, a_low))); +#endif +} + +// Store the lower double-precision (64-bit) floating-point element from a into +// memory. mem_addr does not need to be aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_store_sd +FORCE_INLINE void _mm_store_sd(double *mem_addr, __m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + vst1_f64(_sse2neon_reinterpret_cast(float64_t *, mem_addr), + vget_low_f64(vreinterpretq_f64_m128d(a))); +#else + vst1_u64(_sse2neon_reinterpret_cast(uint64_t *, mem_addr), + vget_low_u64(vreinterpretq_u64_m128d(a))); +#endif +} + +// Store 128-bits of integer data from a into memory. mem_addr must be aligned +// on a 16-byte boundary or a general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_store_si128 +FORCE_INLINE void _mm_store_si128(__m128i *p, __m128i a) +{ + vst1q_s32(_sse2neon_reinterpret_cast(int32_t *, p), + vreinterpretq_s32_m128i(a)); +} + +// Store the lower double-precision (64-bit) floating-point element from a into +// 2 contiguous elements in memory. mem_addr must be aligned on a 16-byte +// boundary or a general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#expand=9,526,5601&text=_mm_store1_pd +#define _mm_store1_pd _mm_store_pd1 + +// Store the upper double-precision (64-bit) floating-point element from a into +// memory. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeh_pd +FORCE_INLINE void _mm_storeh_pd(double *mem_addr, __m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + vst1_f64(_sse2neon_reinterpret_cast(float64_t *, mem_addr), + vget_high_f64(vreinterpretq_f64_m128d(a))); +#else + vst1_f32(_sse2neon_reinterpret_cast(float32_t *, mem_addr), + vget_high_f32(vreinterpretq_f32_m128d(a))); +#endif +} + +// Store 64-bit integer from the first element of a into memory. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storel_epi64 +FORCE_INLINE void _mm_storel_epi64(__m128i *a, __m128i b) +{ + vst1_u64(_sse2neon_reinterpret_cast(uint64_t *, a), + vget_low_u64(vreinterpretq_u64_m128i(b))); +} + +// Store the lower double-precision (64-bit) floating-point element from a into +// memory. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storel_pd +FORCE_INLINE void _mm_storel_pd(double *mem_addr, __m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + vst1_f64(_sse2neon_reinterpret_cast(float64_t *, mem_addr), + vget_low_f64(vreinterpretq_f64_m128d(a))); +#else + vst1_f32(_sse2neon_reinterpret_cast(float32_t *, mem_addr), + vget_low_f32(vreinterpretq_f32_m128d(a))); +#endif +} + +// Store 2 double-precision (64-bit) floating-point elements from a into memory +// in reverse order. mem_addr must be aligned on a 16-byte boundary or a +// general-protection exception may be generated. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storer_pd +FORCE_INLINE void _mm_storer_pd(double *mem_addr, __m128d a) +{ + float32x4_t f = vreinterpretq_f32_m128d(a); + _mm_store_pd(mem_addr, vreinterpretq_m128d_f32(vextq_f32(f, f, 2))); +} + +// Store 128-bits (composed of 2 packed double-precision (64-bit) floating-point +// elements) from a into memory. mem_addr does not need to be aligned on any +// particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_pd +FORCE_INLINE void _mm_storeu_pd(double *mem_addr, __m128d a) +{ + _mm_store_pd(mem_addr, a); +} + +// Store 128-bits of integer data from a into memory. mem_addr does not need to +// be aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si128 +FORCE_INLINE void _mm_storeu_si128(__m128i *p, __m128i a) +{ + vst1q_s32(_sse2neon_reinterpret_cast(int32_t *, p), + vreinterpretq_s32_m128i(a)); +} + +// Store 32-bit integer from the first element of a into memory. mem_addr does +// not need to be aligned on any particular boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_storeu_si32 +FORCE_INLINE void _mm_storeu_si32(void *p, __m128i a) +{ + vst1q_lane_s32(_sse2neon_reinterpret_cast(int32_t *, p), + vreinterpretq_s32_m128i(a), 0); +} + +// Store 128-bits (composed of 2 packed double-precision (64-bit) floating-point +// elements) from a into memory using a non-temporal memory hint. mem_addr must +// be aligned on a 16-byte boundary or a general-protection exception may be +// generated. +// Note: On AArch64, __builtin_nontemporal_store generates STNP (Store +// Non-temporal Pair), providing true non-temporal hint for 128-bit stores. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_pd +FORCE_INLINE void _mm_stream_pd(double *p, __m128d a) +{ +#if __has_builtin(__builtin_nontemporal_store) + __builtin_nontemporal_store(a, _sse2neon_reinterpret_cast(__m128d *, p)); +#elif SSE2NEON_ARCH_AARCH64 + vst1q_f64(p, vreinterpretq_f64_m128d(a)); +#else + vst1q_s64(_sse2neon_reinterpret_cast(int64_t *, p), + vreinterpretq_s64_m128d(a)); +#endif +} + +// Store 128-bits of integer data from a into memory using a non-temporal memory +// hint. mem_addr must be aligned on a 16-byte boundary or a general-protection +// exception may be generated. +// Note: On AArch64, __builtin_nontemporal_store generates STNP (Store +// Non-temporal Pair), providing true non-temporal hint for 128-bit stores. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_si128 +FORCE_INLINE void _mm_stream_si128(__m128i *p, __m128i a) +{ +#if __has_builtin(__builtin_nontemporal_store) + __builtin_nontemporal_store(a, p); +#else + vst1q_s64(_sse2neon_reinterpret_cast(int64_t *, p), + vreinterpretq_s64_m128i(a)); +#endif +} + +// Store 32-bit integer a into memory using a non-temporal hint to minimize +// cache pollution. If the cache line containing address mem_addr is already in +// the cache, the cache will be updated. +// Note: ARM lacks non-temporal store for 32-bit scalar. STNP requires pair +// stores; __builtin_nontemporal_store may generate regular store on AArch64. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_si32 +FORCE_INLINE void _mm_stream_si32(int *p, int a) +{ +#if __has_builtin(__builtin_nontemporal_store) + __builtin_nontemporal_store(a, p); +#else + vst1q_lane_s32(_sse2neon_reinterpret_cast(int32_t *, p), vdupq_n_s32(a), 0); +#endif +} + +// Store 64-bit integer a into memory using a non-temporal hint to minimize +// cache pollution. If the cache line containing address mem_addr is already in +// the cache, the cache will be updated. +// Note: ARM lacks direct non-temporal store for single 64-bit value. STNP +// requires pair stores; __builtin_nontemporal_store may generate regular store +// on AArch64. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_si64 +FORCE_INLINE void _mm_stream_si64(__int64 *p, __int64 a) +{ +#if __has_builtin(__builtin_nontemporal_store) + __builtin_nontemporal_store(a, p); +#else + vst1_s64(_sse2neon_reinterpret_cast(int64_t *, p), + vdup_n_s64(_sse2neon_static_cast(int64_t, a))); +#endif +} + +// Subtract packed 16-bit integers in b from packed 16-bit integers in a, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_epi16 +FORCE_INLINE __m128i _mm_sub_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s16( + vsubq_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +} + +// Subtract packed 32-bit integers in b from packed 32-bit integers in a, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_epi32 +FORCE_INLINE __m128i _mm_sub_epi32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s32( + vsubq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +// Subtract packed 64-bit integers in b from packed 64-bit integers in a, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_epi64 +FORCE_INLINE __m128i _mm_sub_epi64(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s64( + vsubq_s64(vreinterpretq_s64_m128i(a), vreinterpretq_s64_m128i(b))); +} + +// Subtract packed 8-bit integers in b from packed 8-bit integers in a, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_epi8 +FORCE_INLINE __m128i _mm_sub_epi8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s8( + vsubq_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +} + +// Subtract packed double-precision (64-bit) floating-point elements in b from +// packed double-precision (64-bit) floating-point elements in a, and store the +// results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_sub_pd +FORCE_INLINE __m128d _mm_sub_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vsubq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + double c[2]; + c[0] = a0 - b0; + c[1] = a1 - b1; + return sse2neon_vld1q_f32_from_f64pair(c); +#endif +} + +// Subtract the lower double-precision (64-bit) floating-point element in b from +// the lower double-precision (64-bit) floating-point element in a, store the +// result in the lower element of dst, and copy the upper element from a to the +// upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_sd +FORCE_INLINE __m128d _mm_sub_sd(__m128d a, __m128d b) +{ + return _mm_move_sd(a, _mm_sub_pd(a, b)); +} + +// Subtract 64-bit integer b from 64-bit integer a, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sub_si64 +FORCE_INLINE __m64 _mm_sub_si64(__m64 a, __m64 b) +{ + return vreinterpret_m64_s64( + vsub_s64(vreinterpret_s64_m64(a), vreinterpret_s64_m64(b))); +} + +// Subtract packed signed 16-bit integers in b from packed 16-bit integers in a +// using saturation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_subs_epi16 +FORCE_INLINE __m128i _mm_subs_epi16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s16( + vqsubq_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +} + +// Subtract packed signed 8-bit integers in b from packed 8-bit integers in a +// using saturation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_subs_epi8 +FORCE_INLINE __m128i _mm_subs_epi8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s8( + vqsubq_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +} + +// Subtract packed unsigned 16-bit integers in b from packed unsigned 16-bit +// integers in a using saturation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_subs_epu16 +FORCE_INLINE __m128i _mm_subs_epu16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u16( + vqsubq_u16(vreinterpretq_u16_m128i(a), vreinterpretq_u16_m128i(b))); +} + +// Subtract packed unsigned 8-bit integers in b from packed unsigned 8-bit +// integers in a using saturation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_subs_epu8 +FORCE_INLINE __m128i _mm_subs_epu8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u8( + vqsubq_u8(vreinterpretq_u8_m128i(a), vreinterpretq_u8_m128i(b))); +} + +#define _mm_ucomieq_sd _mm_comieq_sd +#define _mm_ucomige_sd _mm_comige_sd +#define _mm_ucomigt_sd _mm_comigt_sd +#define _mm_ucomile_sd _mm_comile_sd +#define _mm_ucomilt_sd _mm_comilt_sd +#define _mm_ucomineq_sd _mm_comineq_sd + +// Return vector of type __m128d with undefined elements. +// Note: MSVC forces zero-initialization while GCC/Clang return truly undefined +// memory. Use SSE2NEON_UNDEFINED_ZERO=1 to force zero on all compilers. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_undefined_pd +FORCE_INLINE __m128d _mm_undefined_pd(void) +{ +#if SSE2NEON_UNDEFINED_ZERO || \ + (SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG) + return _mm_setzero_pd(); +#else +#if SSE2NEON_COMPILER_GCC_COMPAT +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuninitialized" +#endif + __m128d a; + return a; +#if SSE2NEON_COMPILER_GCC_COMPAT +#pragma GCC diagnostic pop +#endif +#endif +} + +// Unpack and interleave 16-bit integers from the high half of a and b, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_epi16 +FORCE_INLINE __m128i _mm_unpackhi_epi16(__m128i a, __m128i b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s16( + vzip2q_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +#else + int16x4_t a1 = vget_high_s16(vreinterpretq_s16_m128i(a)); + int16x4_t b1 = vget_high_s16(vreinterpretq_s16_m128i(b)); + int16x4x2_t result = vzip_s16(a1, b1); + return vreinterpretq_m128i_s16(vcombine_s16(result.val[0], result.val[1])); +#endif +} + +// Unpack and interleave 32-bit integers from the high half of a and b, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_epi32 +FORCE_INLINE __m128i _mm_unpackhi_epi32(__m128i a, __m128i b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s32( + vzip2q_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +#else + int32x2_t a1 = vget_high_s32(vreinterpretq_s32_m128i(a)); + int32x2_t b1 = vget_high_s32(vreinterpretq_s32_m128i(b)); + int32x2x2_t result = vzip_s32(a1, b1); + return vreinterpretq_m128i_s32(vcombine_s32(result.val[0], result.val[1])); +#endif +} + +// Unpack and interleave 64-bit integers from the high half of a and b, and +// store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_epi64 +FORCE_INLINE __m128i _mm_unpackhi_epi64(__m128i a, __m128i b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s64( + vzip2q_s64(vreinterpretq_s64_m128i(a), vreinterpretq_s64_m128i(b))); +#else + int64x1_t a_h = vget_high_s64(vreinterpretq_s64_m128i(a)); + int64x1_t b_h = vget_high_s64(vreinterpretq_s64_m128i(b)); + return vreinterpretq_m128i_s64(vcombine_s64(a_h, b_h)); +#endif +} + +// Unpack and interleave 8-bit integers from the high half of a and b, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_epi8 +FORCE_INLINE __m128i _mm_unpackhi_epi8(__m128i a, __m128i b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s8( + vzip2q_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +#else + int8x8_t a1 = + vreinterpret_s8_s16(vget_high_s16(vreinterpretq_s16_m128i(a))); + int8x8_t b1 = + vreinterpret_s8_s16(vget_high_s16(vreinterpretq_s16_m128i(b))); + int8x8x2_t result = vzip_s8(a1, b1); + return vreinterpretq_m128i_s8(vcombine_s8(result.val[0], result.val[1])); +#endif +} + +// Unpack and interleave double-precision (64-bit) floating-point elements from +// the high half of a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpackhi_pd +FORCE_INLINE __m128d _mm_unpackhi_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vzip2q_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + return vreinterpretq_m128d_s64( + vcombine_s64(vget_high_s64(vreinterpretq_s64_m128d(a)), + vget_high_s64(vreinterpretq_s64_m128d(b)))); +#endif +} + +// Unpack and interleave 16-bit integers from the low half of a and b, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_epi16 +FORCE_INLINE __m128i _mm_unpacklo_epi16(__m128i a, __m128i b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s16( + vzip1q_s16(vreinterpretq_s16_m128i(a), vreinterpretq_s16_m128i(b))); +#else + int16x4_t a1 = vget_low_s16(vreinterpretq_s16_m128i(a)); + int16x4_t b1 = vget_low_s16(vreinterpretq_s16_m128i(b)); + int16x4x2_t result = vzip_s16(a1, b1); + return vreinterpretq_m128i_s16(vcombine_s16(result.val[0], result.val[1])); +#endif +} + +// Unpack and interleave 32-bit integers from the low half of a and b, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_epi32 +FORCE_INLINE __m128i _mm_unpacklo_epi32(__m128i a, __m128i b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s32( + vzip1q_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +#else + int32x2_t a1 = vget_low_s32(vreinterpretq_s32_m128i(a)); + int32x2_t b1 = vget_low_s32(vreinterpretq_s32_m128i(b)); + int32x2x2_t result = vzip_s32(a1, b1); + return vreinterpretq_m128i_s32(vcombine_s32(result.val[0], result.val[1])); +#endif +} + +// Unpack and interleave 64-bit integers from the low half of a and b, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_epi64 +FORCE_INLINE __m128i _mm_unpacklo_epi64(__m128i a, __m128i b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s64( + vzip1q_s64(vreinterpretq_s64_m128i(a), vreinterpretq_s64_m128i(b))); +#else + int64x1_t a_l = vget_low_s64(vreinterpretq_s64_m128i(a)); + int64x1_t b_l = vget_low_s64(vreinterpretq_s64_m128i(b)); + return vreinterpretq_m128i_s64(vcombine_s64(a_l, b_l)); +#endif +} + +// Unpack and interleave 8-bit integers from the low half of a and b, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_epi8 +FORCE_INLINE __m128i _mm_unpacklo_epi8(__m128i a, __m128i b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s8( + vzip1q_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +#else + int8x8_t a1 = vreinterpret_s8_s16(vget_low_s16(vreinterpretq_s16_m128i(a))); + int8x8_t b1 = vreinterpret_s8_s16(vget_low_s16(vreinterpretq_s16_m128i(b))); + int8x8x2_t result = vzip_s8(a1, b1); + return vreinterpretq_m128i_s8(vcombine_s8(result.val[0], result.val[1])); +#endif +} + +// Unpack and interleave double-precision (64-bit) floating-point elements from +// the low half of a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_unpacklo_pd +FORCE_INLINE __m128d _mm_unpacklo_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vzip1q_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + return vreinterpretq_m128d_s64( + vcombine_s64(vget_low_s64(vreinterpretq_s64_m128d(a)), + vget_low_s64(vreinterpretq_s64_m128d(b)))); +#endif +} + +// Compute the bitwise XOR of packed double-precision (64-bit) floating-point +// elements in a and b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_xor_pd +FORCE_INLINE __m128d _mm_xor_pd(__m128d a, __m128d b) +{ + return vreinterpretq_m128d_s64( + veorq_s64(vreinterpretq_s64_m128d(a), vreinterpretq_s64_m128d(b))); +} + +// Compute the bitwise XOR of 128 bits (representing integer data) in a and b, +// and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_xor_si128 +FORCE_INLINE __m128i _mm_xor_si128(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s32( + veorq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +/* SSE3 */ + +// Rounding mode note: The single-precision horizontal operations +// (_mm_addsub_ps, _mm_hadd_ps, _mm_hsub_ps) are sensitive to rounding mode +// on ARM. On x86, these intrinsics produce consistent results regardless of +// MXCSR rounding mode. On ARM NEON, the current FPCR/FPSCR rounding mode +// affects intermediate results. For consistent cross-platform behavior, call +// _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST) before using these intrinsics. + +// Alternatively add and subtract packed double-precision (64-bit) +// floating-point elements in a to/from packed elements in b, and store the +// results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_addsub_pd +FORCE_INLINE __m128d _mm_addsub_pd(__m128d a, __m128d b) +{ + _sse2neon_const __m128d mask = _mm_set_pd(1.0f, -1.0f); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vfmaq_f64(vreinterpretq_f64_m128d(a), + vreinterpretq_f64_m128d(b), + vreinterpretq_f64_m128d(mask))); +#else + return _mm_add_pd(_mm_mul_pd(b, mask), a); +#endif +} + +// Alternatively add and subtract packed single-precision (32-bit) +// floating-point elements in a to/from packed elements in b, and store the +// results in dst. See SSE3 rounding mode note above. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=addsub_ps +FORCE_INLINE __m128 _mm_addsub_ps(__m128 a, __m128 b) +{ + _sse2neon_const __m128 mask = _mm_setr_ps(-1.0f, 1.0f, -1.0f, 1.0f); +#if SSE2NEON_ARCH_AARCH64 || defined(__ARM_FEATURE_FMA) /* VFPv4+ */ + return vreinterpretq_m128_f32(vfmaq_f32(vreinterpretq_f32_m128(a), + vreinterpretq_f32_m128(mask), + vreinterpretq_f32_m128(b))); +#else + return _mm_add_ps(_mm_mul_ps(b, mask), a); +#endif +} + +// Horizontally add adjacent pairs of double-precision (64-bit) floating-point +// elements in a and b, and pack the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadd_pd +FORCE_INLINE __m128d _mm_hadd_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vpaddq_f64(vreinterpretq_f64_m128d(a), vreinterpretq_f64_m128d(b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + double c[] = {a0 + a1, b0 + b1}; + return vreinterpretq_m128d_u64( + vld1q_u64(_sse2neon_reinterpret_cast(uint64_t *, c))); +#endif +} + +// Horizontally add adjacent pairs of single-precision (32-bit) floating-point +// elements in a and b, and pack the results in dst. +// See SSE3 rounding mode note above. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadd_ps +FORCE_INLINE __m128 _mm_hadd_ps(__m128 a, __m128 b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128_f32( + vpaddq_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(b))); +#else + float32x2_t a10 = vget_low_f32(vreinterpretq_f32_m128(a)); + float32x2_t a32 = vget_high_f32(vreinterpretq_f32_m128(a)); + float32x2_t b10 = vget_low_f32(vreinterpretq_f32_m128(b)); + float32x2_t b32 = vget_high_f32(vreinterpretq_f32_m128(b)); + return vreinterpretq_m128_f32( + vcombine_f32(vpadd_f32(a10, a32), vpadd_f32(b10, b32))); +#endif +} + +// Horizontally subtract adjacent pairs of double-precision (64-bit) +// floating-point elements in a and b, and pack the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsub_pd +FORCE_INLINE __m128d _mm_hsub_pd(__m128d a, __m128d b) +{ +#if SSE2NEON_ARCH_AARCH64 + float64x2_t _a = vreinterpretq_f64_m128d(a); + float64x2_t _b = vreinterpretq_f64_m128d(b); + return vreinterpretq_m128d_f64( + vsubq_f64(vuzp1q_f64(_a, _b), vuzp2q_f64(_a, _b))); +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + double c[] = {a0 - a1, b0 - b1}; + return vreinterpretq_m128d_u64( + vld1q_u64(_sse2neon_reinterpret_cast(uint64_t *, c))); +#endif +} + +// Horizontally subtract adjacent pairs of single-precision (32-bit) +// floating-point elements in a and b, and pack the results in dst. +// See SSE3 rounding mode note above. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsub_ps +FORCE_INLINE __m128 _mm_hsub_ps(__m128 _a, __m128 _b) +{ + float32x4_t a = vreinterpretq_f32_m128(_a); + float32x4_t b = vreinterpretq_f32_m128(_b); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128_f32( + vsubq_f32(vuzp1q_f32(a, b), vuzp2q_f32(a, b))); +#else + float32x4x2_t c = vuzpq_f32(a, b); + return vreinterpretq_m128_f32(vsubq_f32(c.val[0], c.val[1])); +#endif +} + +// Load 128-bits of integer data from unaligned memory into dst. This intrinsic +// may perform better than _mm_loadu_si128 when the data crosses a cache line +// boundary. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_lddqu_si128 +#define _mm_lddqu_si128 _mm_loadu_si128 + +// Load a double-precision (64-bit) floating-point element from memory into both +// elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_loaddup_pd +#define _mm_loaddup_pd _mm_load1_pd + +// Sets up a linear address range to be monitored by hardware and activates the +// monitor. The address range should be a write-back memory caching type. +// +// ARM implementation notes: +// - This is a NO-OP. ARM has no userspace equivalent for "monitor a cacheline +// and wake on store". There is no "armed" address after calling this. +// - The extensions and hints parameters are ignored (no architectural +// equivalent for x86 C-state hints on ARM). +// - _mm_mwait provides only a low-power hint, not a monitor-armed wait. +// +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_monitor +FORCE_INLINE void _mm_monitor(void const *p, + unsigned int extensions, + unsigned int hints) +{ + (void) p; + (void) extensions; + (void) hints; +} + +// Duplicate the low double-precision (64-bit) floating-point element from a, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movedup_pd +FORCE_INLINE __m128d _mm_movedup_pd(__m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64( + vdupq_laneq_f64(vreinterpretq_f64_m128d(a), 0)); +#else + return vreinterpretq_m128d_u64( + vdupq_n_u64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0))); +#endif +} + +// Duplicate odd-indexed single-precision (32-bit) floating-point elements +// from a, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_movehdup_ps +FORCE_INLINE __m128 _mm_movehdup_ps(__m128 a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128_f32( + vtrn2q_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a))); +#elif defined(_sse2neon_shuffle) + return vreinterpretq_m128_f32(vshuffleq_s32( + vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a), 1, 1, 3, 3)); +#else + float32_t a1 = vgetq_lane_f32(vreinterpretq_f32_m128(a), 1); + float32_t a3 = vgetq_lane_f32(vreinterpretq_f32_m128(a), 3); + float ALIGN_STRUCT(16) data[4] = {a1, a1, a3, a3}; + return vreinterpretq_m128_f32(vld1q_f32(data)); +#endif +} + +// Duplicate even-indexed single-precision (32-bit) floating-point elements +// from a, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_moveldup_ps +FORCE_INLINE __m128 _mm_moveldup_ps(__m128 a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128_f32( + vtrn1q_f32(vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a))); +#elif defined(_sse2neon_shuffle) + return vreinterpretq_m128_f32(vshuffleq_s32( + vreinterpretq_f32_m128(a), vreinterpretq_f32_m128(a), 0, 0, 2, 2)); +#else + float32_t a0 = vgetq_lane_f32(vreinterpretq_f32_m128(a), 0); + float32_t a2 = vgetq_lane_f32(vreinterpretq_f32_m128(a), 2); + float ALIGN_STRUCT(16) data[4] = {a0, a0, a2, a2}; + return vreinterpretq_m128_f32(vld1q_f32(data)); +#endif +} + +// Provides a hint that allows the processor to enter an implementation- +// dependent optimized state while waiting for a memory write to the monitored +// address range set up by _mm_monitor. +// +// ARM implementation notes: +// - This is only a LOW-POWER HINT, not a monitor-armed wait. Since _mm_monitor +// is a no-op on ARM, there is no "armed" address range to wake on. +// - The extensions and hints parameters are ignored (no architectural +// equivalent for x86 C-state hints on ARM). +// - No memory ordering is guaranteed beyond what the hint instruction provides. +// - WFI/WFE in EL0 may trap depending on OS configuration (Linux can trap +// EL0 WFI/WFE via SCTLR_EL1; iOS/macOS may also restrict these). +// +// Behavior controlled by SSE2NEON_MWAIT_POLICY (see top of file for details). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mwait +FORCE_INLINE void _mm_mwait(unsigned int extensions, unsigned int hints) +{ + (void) extensions; + (void) hints; + + // ARM implementation: low-power hint via yield/wfe/wfi. + // x86: no-op for compilation (MONITOR/MWAIT require CPL0, trap in + // userspace). +#if SSE2NEON_ARCH_AARCH64 || defined(__arm__) || defined(_M_ARM) || \ + defined(_M_ARM64) + // Use MSVC intrinsics on Windows ARM, inline asm on GCC/Clang. + // Note: GCC's arm_acle.h may not define __yield/__wfe/__wfi on all + // versions. +#if SSE2NEON_MWAIT_POLICY == 0 + // Policy 0: yield - safe everywhere, never blocks +#if SSE2NEON_COMPILER_MSVC + __yield(); +#else + __asm__ __volatile__("yield" ::: "memory"); +#endif + +#elif SSE2NEON_MWAIT_POLICY == 1 + // Policy 1: wfe - event wait, requires SEV/SEVL, may block +#if SSE2NEON_COMPILER_MSVC + __wfe(); +#else + __asm__ __volatile__("wfe" ::: "memory"); +#endif + +#elif SSE2NEON_MWAIT_POLICY == 2 + // Policy 2: wfi - interrupt wait, may trap in EL0 +#if SSE2NEON_COMPILER_MSVC + __wfi(); +#else + __asm__ __volatile__("wfi" ::: "memory"); +#endif + +#else +#error "Invalid SSE2NEON_MWAIT_POLICY value (must be 0, 1, or 2)" +#endif +#endif /* ARM architecture */ +} + +/* SSSE3 */ + +// Compute the absolute value of packed signed 16-bit integers in a, and store +// the unsigned results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_epi16 +FORCE_INLINE __m128i _mm_abs_epi16(__m128i a) +{ + return vreinterpretq_m128i_s16(vabsq_s16(vreinterpretq_s16_m128i(a))); +} + +// Compute the absolute value of packed signed 32-bit integers in a, and store +// the unsigned results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_epi32 +FORCE_INLINE __m128i _mm_abs_epi32(__m128i a) +{ + return vreinterpretq_m128i_s32(vabsq_s32(vreinterpretq_s32_m128i(a))); +} + +// Compute the absolute value of packed signed 8-bit integers in a, and store +// the unsigned results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_epi8 +FORCE_INLINE __m128i _mm_abs_epi8(__m128i a) +{ + return vreinterpretq_m128i_s8(vabsq_s8(vreinterpretq_s8_m128i(a))); +} + +// Compute the absolute value of packed signed 16-bit integers in a, and store +// the unsigned results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_pi16 +FORCE_INLINE __m64 _mm_abs_pi16(__m64 a) +{ + return vreinterpret_m64_s16(vabs_s16(vreinterpret_s16_m64(a))); +} + +// Compute the absolute value of packed signed 32-bit integers in a, and store +// the unsigned results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_pi32 +FORCE_INLINE __m64 _mm_abs_pi32(__m64 a) +{ + return vreinterpret_m64_s32(vabs_s32(vreinterpret_s32_m64(a))); +} + +// Compute the absolute value of packed signed 8-bit integers in a, and store +// the unsigned results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_abs_pi8 +FORCE_INLINE __m64 _mm_abs_pi8(__m64 a) +{ + return vreinterpret_m64_s8(vabs_s8(vreinterpret_s8_m64(a))); +} + +// Concatenate 16-byte blocks in a and b into a 32-byte temporary result, shift +// the result right by imm8 bytes, and store the low 16 bytes in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_alignr_epi8 +// imm must be a compile-time constant in range [0, 255] +#if defined(__GNUC__) && !defined(__clang__) +#define _mm_alignr_epi8(a, b, imm) \ + __extension__({ \ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); \ + __m128i _a_m128i = (a); \ + uint8x16_t _a = vreinterpretq_u8_m128i(_a_m128i); \ + uint8x16_t _b = vreinterpretq_u8_m128i(b); \ + __m128i ret; \ + if (_sse2neon_unlikely((imm) & ~31)) \ + ret = vreinterpretq_m128i_u8(vdupq_n_u8(0)); \ + else if ((imm) >= 16) \ + ret = vreinterpretq_m128i_s8( \ + vextq_s8(vreinterpretq_s8_m128i(_a_m128i), vdupq_n_s8(0), \ + ((imm) >= 16 && (imm) < 32) ? (imm) - 16 : 0)); \ + else \ + ret = vreinterpretq_m128i_u8( \ + vextq_u8(_b, _a, (imm) < 16 ? (imm) : 0)); \ + ret; \ + }) + +// Clang path: inline _mm_srli_si128 logic to avoid both: +// 1. Variable shadowing: _mm_srli_si128(_a, ...) creates __m128i _a = (_a) +// 2. Double evaluation: _mm_srli_si128((a), ...) re-evaluates macro arg +#elif SSE2NEON_COMPILER_CLANG +#define _mm_alignr_epi8(a, b, imm) \ + _sse2neon_define2( \ + __m128i, a, b, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); \ + uint8x16_t __a = vreinterpretq_u8_m128i(_a); \ + uint8x16_t __b = vreinterpretq_u8_m128i(_b); __m128i ret; \ + if (_sse2neon_unlikely((imm) & ~31)) ret = \ + vreinterpretq_m128i_u8(vdupq_n_u8(0)); \ + else if ((imm) >= 16) ret = vreinterpretq_m128i_s8( \ + vextq_s8(vreinterpretq_s8_m128i(_a), vdupq_n_s8(0), \ + ((imm) >= 16 && (imm) < 32) ? (imm) - 16 : 0)); \ + else ret = vreinterpretq_m128i_u8( \ + vextq_u8(__b, __a, (imm) < 16 ? (imm) : 0)); \ + _sse2neon_return(ret);) + +// MSVC C++ path: use _a (lambda parameter) since lambda [] cannot capture (a). +// No shadowing issue because lambda parameters shadow captures properly. +#elif defined(__cplusplus) +#define _mm_alignr_epi8(a, b, imm) \ + _sse2neon_define2( \ + __m128i, a, b, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); \ + uint8x16_t __a = vreinterpretq_u8_m128i(_a); \ + uint8x16_t __b = vreinterpretq_u8_m128i(_b); __m128i ret; \ + if (_sse2neon_unlikely((imm) & ~31)) ret = \ + vreinterpretq_m128i_u8(vdupq_n_u8(0)); \ + else if ((imm) >= 16) ret = \ + _mm_srli_si128(_a, (imm) >= 16 ? (imm) - 16 : 0); \ + else ret = vreinterpretq_m128i_u8( \ + vextq_u8(__b, __a, (imm) < 16 ? (imm) : 0)); \ + _sse2neon_return(ret);) + +// Pure C (MSVC C mode): no lambda or statement expression available. +#else +FORCE_INLINE __m128i _mm_alignr_epi8(__m128i a, __m128i b, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + uint8x16_t ua = vreinterpretq_u8_m128i(a); + uint8x16_t ub = vreinterpretq_u8_m128i(b); + __m128i ret; + if (_sse2neon_unlikely(imm & ~31)) + ret = vreinterpretq_m128i_u8(vdupq_n_u8(0)); + else if (imm >= 16) + ret = vreinterpretq_m128i_s8( + _sse2neon_vextq_s8(vreinterpretq_s8_m128i(a), vdupq_n_s8(0), + (imm >= 16 && imm < 32) ? imm - 16 : 0)); + else + ret = vreinterpretq_m128i_u8( + _sse2neon_vextq_u8(ub, ua, imm < 16 ? imm : 0)); + return ret; +} +#endif + +// Concatenate 8-byte blocks in a and b into a 16-byte temporary result, shift +// the result right by imm8 bytes, and store the low 8 bytes in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_alignr_pi8 +// imm must be a compile-time constant in range [0, 255] +#if defined(__GNUC__) && !defined(__clang__) +#define _mm_alignr_pi8(a, b, imm) \ + __extension__({ \ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); \ + __m64 _a = (a), _b = (b); \ + __m64 ret; \ + if (_sse2neon_unlikely((imm) >= 16)) { \ + ret = vreinterpret_m64_s8(vdup_n_s8(0)); \ + } else if ((imm) >= 8) { \ + ret = vreinterpret_m64_u8( \ + vext_u8(vreinterpret_u8_m64(_a), vdup_n_u8(0), (imm) - 8)); \ + } else { \ + ret = vreinterpret_m64_u8(vext_u8( \ + vreinterpret_u8_m64(_b), vreinterpret_u8_m64(_a), (imm))); \ + } \ + ret; \ + }) + +#elif SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_alignr_pi8(a, b, imm) \ + _sse2neon_define2( \ + __m64, a, b, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); __m64 ret; \ + if (_sse2neon_unlikely((imm) >= 16)) { \ + ret = vreinterpret_m64_s8(vdup_n_s8(0)); \ + } else if ((imm) >= 8) { \ + ret = vreinterpret_m64_u8(vext_u8(vreinterpret_u8_m64(_a), \ + vdup_n_u8(0), ((imm) - 8) & 7)); \ + } else { \ + ret = vreinterpret_m64_u8(vext_u8( \ + vreinterpret_u8_m64(_b), vreinterpret_u8_m64(_a), (imm) & 7)); \ + } _sse2neon_return(ret);) +#else +FORCE_INLINE __m64 _mm_alignr_pi8(__m64 a, __m64 b, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + __m64 ret; + if (_sse2neon_unlikely(imm >= 16)) { + ret = vreinterpret_m64_s8(vdup_n_s8(0)); + } else if (imm >= 8) { + ret = vreinterpret_m64_u8(_sse2neon_vext_u8( + vreinterpret_u8_m64(a), vdup_n_u8(0), (imm - 8) & 7)); + } else { + ret = vreinterpret_m64_u8(_sse2neon_vext_u8( + vreinterpret_u8_m64(b), vreinterpret_u8_m64(a), imm & 7)); + } + return ret; +} +#endif + +// Horizontally add adjacent pairs of 16-bit integers in a and b, and pack the +// signed 16-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadd_epi16 +FORCE_INLINE __m128i _mm_hadd_epi16(__m128i _a, __m128i _b) +{ + int16x8_t a = vreinterpretq_s16_m128i(_a); + int16x8_t b = vreinterpretq_s16_m128i(_b); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s16(vpaddq_s16(a, b)); +#else + return vreinterpretq_m128i_s16( + vcombine_s16(vpadd_s16(vget_low_s16(a), vget_high_s16(a)), + vpadd_s16(vget_low_s16(b), vget_high_s16(b)))); +#endif +} + +// Horizontally add adjacent pairs of 32-bit integers in a and b, and pack the +// signed 32-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadd_epi32 +FORCE_INLINE __m128i _mm_hadd_epi32(__m128i _a, __m128i _b) +{ + int32x4_t a = vreinterpretq_s32_m128i(_a); + int32x4_t b = vreinterpretq_s32_m128i(_b); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s32(vpaddq_s32(a, b)); +#else + return vreinterpretq_m128i_s32( + vcombine_s32(vpadd_s32(vget_low_s32(a), vget_high_s32(a)), + vpadd_s32(vget_low_s32(b), vget_high_s32(b)))); +#endif +} + +// Horizontally add adjacent pairs of 16-bit integers in a and b, and pack the +// signed 16-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadd_pi16 +FORCE_INLINE __m64 _mm_hadd_pi16(__m64 a, __m64 b) +{ + return vreinterpret_m64_s16( + vpadd_s16(vreinterpret_s16_m64(a), vreinterpret_s16_m64(b))); +} + +// Horizontally add adjacent pairs of 32-bit integers in a and b, and pack the +// signed 32-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadd_pi32 +FORCE_INLINE __m64 _mm_hadd_pi32(__m64 a, __m64 b) +{ + return vreinterpret_m64_s32( + vpadd_s32(vreinterpret_s32_m64(a), vreinterpret_s32_m64(b))); +} + +// Horizontally add adjacent pairs of signed 16-bit integers in a and b using +// saturation, and pack the signed 16-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadds_epi16 +FORCE_INLINE __m128i _mm_hadds_epi16(__m128i _a, __m128i _b) +{ +#if SSE2NEON_ARCH_AARCH64 + int16x8_t a = vreinterpretq_s16_m128i(_a); + int16x8_t b = vreinterpretq_s16_m128i(_b); + return vreinterpretq_s64_s16( + vqaddq_s16(vuzp1q_s16(a, b), vuzp2q_s16(a, b))); +#else + int32x4_t a = vreinterpretq_s32_m128i(_a); + int32x4_t b = vreinterpretq_s32_m128i(_b); + // Interleave using vshrn/vmovn + // [a0|a2|a4|a6|b0|b2|b4|b6] + // [a1|a3|a5|a7|b1|b3|b5|b7] + int16x8_t ab0246 = vcombine_s16(vmovn_s32(a), vmovn_s32(b)); + int16x8_t ab1357 = vcombine_s16(vshrn_n_s32(a, 16), vshrn_n_s32(b, 16)); + // Saturated add + return vreinterpretq_m128i_s16(vqaddq_s16(ab0246, ab1357)); +#endif +} + +// Horizontally add adjacent pairs of signed 16-bit integers in a and b using +// saturation, and pack the signed 16-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hadds_pi16 +FORCE_INLINE __m64 _mm_hadds_pi16(__m64 _a, __m64 _b) +{ + int16x4_t a = vreinterpret_s16_m64(_a); + int16x4_t b = vreinterpret_s16_m64(_b); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpret_s64_s16(vqadd_s16(vuzp1_s16(a, b), vuzp2_s16(a, b))); +#else + int16x4x2_t res = vuzp_s16(a, b); + return vreinterpret_s64_s16(vqadd_s16(res.val[0], res.val[1])); +#endif +} + +// Horizontally subtract adjacent pairs of 16-bit integers in a and b, and pack +// the signed 16-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsub_epi16 +FORCE_INLINE __m128i _mm_hsub_epi16(__m128i _a, __m128i _b) +{ + int16x8_t a = vreinterpretq_s16_m128i(_a); + int16x8_t b = vreinterpretq_s16_m128i(_b); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s16( + vsubq_s16(vuzp1q_s16(a, b), vuzp2q_s16(a, b))); +#else + int16x8x2_t c = vuzpq_s16(a, b); + return vreinterpretq_m128i_s16(vsubq_s16(c.val[0], c.val[1])); +#endif +} + +// Horizontally subtract adjacent pairs of 32-bit integers in a and b, and pack +// the signed 32-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsub_epi32 +FORCE_INLINE __m128i _mm_hsub_epi32(__m128i _a, __m128i _b) +{ + int32x4_t a = vreinterpretq_s32_m128i(_a); + int32x4_t b = vreinterpretq_s32_m128i(_b); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s32( + vsubq_s32(vuzp1q_s32(a, b), vuzp2q_s32(a, b))); +#else + int32x4x2_t c = vuzpq_s32(a, b); + return vreinterpretq_m128i_s32(vsubq_s32(c.val[0], c.val[1])); +#endif +} + +// Horizontally subtract adjacent pairs of 16-bit integers in a and b, and pack +// the signed 16-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsub_pi16 +FORCE_INLINE __m64 _mm_hsub_pi16(__m64 _a, __m64 _b) +{ + int16x4_t a = vreinterpret_s16_m64(_a); + int16x4_t b = vreinterpret_s16_m64(_b); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpret_m64_s16(vsub_s16(vuzp1_s16(a, b), vuzp2_s16(a, b))); +#else + int16x4x2_t c = vuzp_s16(a, b); + return vreinterpret_m64_s16(vsub_s16(c.val[0], c.val[1])); +#endif +} + +// Horizontally subtract adjacent pairs of 32-bit integers in a and b, and pack +// the signed 32-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_hsub_pi32 +FORCE_INLINE __m64 _mm_hsub_pi32(__m64 _a, __m64 _b) +{ + int32x2_t a = vreinterpret_s32_m64(_a); + int32x2_t b = vreinterpret_s32_m64(_b); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpret_m64_s32(vsub_s32(vuzp1_s32(a, b), vuzp2_s32(a, b))); +#else + int32x2x2_t c = vuzp_s32(a, b); + return vreinterpret_m64_s32(vsub_s32(c.val[0], c.val[1])); +#endif +} + +// Horizontally subtract adjacent pairs of signed 16-bit integers in a and b +// using saturation, and pack the signed 16-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsubs_epi16 +FORCE_INLINE __m128i _mm_hsubs_epi16(__m128i _a, __m128i _b) +{ + int16x8_t a = vreinterpretq_s16_m128i(_a); + int16x8_t b = vreinterpretq_s16_m128i(_b); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s16( + vqsubq_s16(vuzp1q_s16(a, b), vuzp2q_s16(a, b))); +#else + int16x8x2_t c = vuzpq_s16(a, b); + return vreinterpretq_m128i_s16(vqsubq_s16(c.val[0], c.val[1])); +#endif +} + +// Horizontally subtract adjacent pairs of signed 16-bit integers in a and b +// using saturation, and pack the signed 16-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_hsubs_pi16 +FORCE_INLINE __m64 _mm_hsubs_pi16(__m64 _a, __m64 _b) +{ + int16x4_t a = vreinterpret_s16_m64(_a); + int16x4_t b = vreinterpret_s16_m64(_b); +#if SSE2NEON_ARCH_AARCH64 + return vreinterpret_m64_s16(vqsub_s16(vuzp1_s16(a, b), vuzp2_s16(a, b))); +#else + int16x4x2_t c = vuzp_s16(a, b); + return vreinterpret_m64_s16(vqsub_s16(c.val[0], c.val[1])); +#endif +} + +// Vertically multiply each unsigned 8-bit integer from a with the corresponding +// signed 8-bit integer from b, producing intermediate signed 16-bit integers. +// Horizontally add adjacent pairs of intermediate signed 16-bit integers, +// and pack the saturated results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maddubs_epi16 +FORCE_INLINE __m128i _mm_maddubs_epi16(__m128i _a, __m128i _b) +{ +#if SSE2NEON_ARCH_AARCH64 + uint8x16_t a = vreinterpretq_u8_m128i(_a); + int8x16_t b = vreinterpretq_s8_m128i(_b); + int16x8_t tl = vmulq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(a))), + vmovl_s8(vget_low_s8(b))); + int16x8_t th = vmulq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(a))), + vmovl_s8(vget_high_s8(b))); + return vreinterpretq_m128i_s16( + vqaddq_s16(vuzp1q_s16(tl, th), vuzp2q_s16(tl, th))); +#else + // This would be much simpler if x86 would choose to zero extend OR sign + // extend, not both. This could probably be optimized better. + uint16x8_t a = vreinterpretq_u16_m128i(_a); + int16x8_t b = vreinterpretq_s16_m128i(_b); + + // Zero extend a + int16x8_t a_odd = vreinterpretq_s16_u16(vshrq_n_u16(a, 8)); + int16x8_t a_even = vreinterpretq_s16_u16(vbicq_u16(a, vdupq_n_u16(0xff00))); + + // Sign extend by shifting left then shifting right. + int16x8_t b_even = vshrq_n_s16(vshlq_n_s16(b, 8), 8); + int16x8_t b_odd = vshrq_n_s16(b, 8); + + // multiply + int16x8_t prod1 = vmulq_s16(a_even, b_even); + int16x8_t prod2 = vmulq_s16(a_odd, b_odd); + + // saturated add + return vreinterpretq_m128i_s16(vqaddq_s16(prod1, prod2)); +#endif +} + +// Vertically multiply each unsigned 8-bit integer from a with the corresponding +// signed 8-bit integer from b, producing intermediate signed 16-bit integers. +// Horizontally add adjacent pairs of intermediate signed 16-bit integers, and +// pack the saturated results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maddubs_pi16 +FORCE_INLINE __m64 _mm_maddubs_pi16(__m64 _a, __m64 _b) +{ + uint16x4_t a = vreinterpret_u16_m64(_a); + int16x4_t b = vreinterpret_s16_m64(_b); + + // Zero extend a + int16x4_t a_odd = vreinterpret_s16_u16(vshr_n_u16(a, 8)); + int16x4_t a_even = vreinterpret_s16_u16(vand_u16(a, vdup_n_u16(0xff))); + + // Sign extend by shifting left then shifting right. + int16x4_t b_even = vshr_n_s16(vshl_n_s16(b, 8), 8); + int16x4_t b_odd = vshr_n_s16(b, 8); + + // multiply + int16x4_t prod1 = vmul_s16(a_even, b_even); + int16x4_t prod2 = vmul_s16(a_odd, b_odd); + + // saturated add + return vreinterpret_m64_s16(vqadd_s16(prod1, prod2)); +} + +// Multiply packed signed 16-bit integers in a and b, producing intermediate +// signed 32-bit integers. Shift right by 15 bits while rounding up, and store +// the packed 16-bit integers in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhrs_epi16 +FORCE_INLINE __m128i _mm_mulhrs_epi16(__m128i a, __m128i b) +{ + // Has issues due to saturation + // return vreinterpretq_m128i_s16(vqrdmulhq_s16(a, b)); + + // Multiply + int32x4_t mul_lo = vmull_s16(vget_low_s16(vreinterpretq_s16_m128i(a)), + vget_low_s16(vreinterpretq_s16_m128i(b))); + int32x4_t mul_hi = vmull_s16(vget_high_s16(vreinterpretq_s16_m128i(a)), + vget_high_s16(vreinterpretq_s16_m128i(b))); + + // Rounding narrowing shift right + // narrow = (int16_t)((mul + 16384) >> 15); + int16x4_t narrow_lo = vrshrn_n_s32(mul_lo, 15); + int16x4_t narrow_hi = vrshrn_n_s32(mul_hi, 15); + + // Join together + return vreinterpretq_m128i_s16(vcombine_s16(narrow_lo, narrow_hi)); +} + +// Multiply packed signed 16-bit integers in a and b, producing intermediate +// signed 32-bit integers. Truncate each intermediate integer to the 18 most +// significant bits, round by adding 1, and store bits [16:1] to dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhrs_pi16 +FORCE_INLINE __m64 _mm_mulhrs_pi16(__m64 a, __m64 b) +{ + int32x4_t mul_extend = + vmull_s16((vreinterpret_s16_m64(a)), (vreinterpret_s16_m64(b))); + + // Rounding narrowing shift right + return vreinterpret_m64_s16(vrshrn_n_s32(mul_extend, 15)); +} + +// Shuffle packed 8-bit integers in a according to shuffle control mask in the +// corresponding 8-bit element of b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_epi8 +FORCE_INLINE __m128i _mm_shuffle_epi8(__m128i a, __m128i b) +{ + int8x16_t tbl = vreinterpretq_s8_m128i(a); // input a + uint8x16_t idx = vreinterpretq_u8_m128i(b); // input b + uint8x16_t idx_masked = + vandq_u8(idx, vdupq_n_u8(0x8F)); // avoid using meaningless bits +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_s8(vqtbl1q_s8(tbl, idx_masked)); +#elif defined(__GNUC__) + int8x16_t ret; + // %e and %f represent the even and odd D registers + // respectively. + __asm__ __volatile__( + "vtbl.8 %e[ret], {%e[tbl], %f[tbl]}, %e[idx]\n" + "vtbl.8 %f[ret], {%e[tbl], %f[tbl]}, %f[idx]\n" + : [ret] "=&w"(ret) + : [tbl] "w"(tbl), [idx] "w"(idx_masked)); + return vreinterpretq_m128i_s8(ret); +#else + // use this line if testing on aarch64 + int8x8x2_t a_split = {vget_low_s8(tbl), vget_high_s8(tbl)}; + return vreinterpretq_m128i_s8( + vcombine_s8(vtbl2_s8(a_split, vget_low_u8(idx_masked)), + vtbl2_s8(a_split, vget_high_u8(idx_masked)))); +#endif +} + +// Shuffle packed 8-bit integers in a according to shuffle control mask in the +// corresponding 8-bit element of b, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_pi8 +FORCE_INLINE __m64 _mm_shuffle_pi8(__m64 a, __m64 b) +{ + const int8x8_t controlMask = + vand_s8(vreinterpret_s8_m64(b), + vdup_n_s8(_sse2neon_static_cast(int8_t, 0x1 << 7 | 0x07))); + int8x8_t res = vtbl1_s8(vreinterpret_s8_m64(a), controlMask); + return vreinterpret_m64_s8(res); +} + +// Negate packed 16-bit integers in a when the corresponding signed +// 16-bit integer in b is negative, and store the results in dst. +// Element in dst are zeroed out when the corresponding element +// in b is zero. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sign_epi16 +FORCE_INLINE __m128i _mm_sign_epi16(__m128i _a, __m128i _b) +{ + int16x8_t a = vreinterpretq_s16_m128i(_a); + int16x8_t b = vreinterpretq_s16_m128i(_b); + + // signed shift right: faster than vclt + // (b < 0) ? 0xFFFF : 0 + uint16x8_t ltMask = vreinterpretq_u16_s16(vshrq_n_s16(b, 15)); + // (b == 0) ? 0xFFFF : 0 +#if SSE2NEON_ARCH_AARCH64 + int16x8_t zeroMask = vreinterpretq_s16_u16(vceqzq_s16(b)); +#else + int16x8_t zeroMask = vreinterpretq_s16_u16(vceqq_s16(b, vdupq_n_s16(0))); +#endif + + // bitwise select either a or negative 'a' (vnegq_s16(a) equals to negative + // 'a') based on ltMask + int16x8_t masked = vbslq_s16(ltMask, vnegq_s16(a), a); + // res = masked & (~zeroMask) + int16x8_t res = vbicq_s16(masked, zeroMask); + return vreinterpretq_m128i_s16(res); +} + +// Negate packed 32-bit integers in a when the corresponding signed +// 32-bit integer in b is negative, and store the results in dst. +// Element in dst are zeroed out when the corresponding element +// in b is zero. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sign_epi32 +FORCE_INLINE __m128i _mm_sign_epi32(__m128i _a, __m128i _b) +{ + int32x4_t a = vreinterpretq_s32_m128i(_a); + int32x4_t b = vreinterpretq_s32_m128i(_b); + + // signed shift right: faster than vclt + // (b < 0) ? 0xFFFFFFFF : 0 + uint32x4_t ltMask = vreinterpretq_u32_s32(vshrq_n_s32(b, 31)); + + // (b == 0) ? 0xFFFFFFFF : 0 +#if SSE2NEON_ARCH_AARCH64 + int32x4_t zeroMask = vreinterpretq_s32_u32(vceqzq_s32(b)); +#else + int32x4_t zeroMask = vreinterpretq_s32_u32(vceqq_s32(b, vdupq_n_s32(0))); +#endif + + // bitwise select either a or negative 'a' (vnegq_s32(a) equals to negative + // 'a') based on ltMask + int32x4_t masked = vbslq_s32(ltMask, vnegq_s32(a), a); + // res = masked & (~zeroMask) + int32x4_t res = vbicq_s32(masked, zeroMask); + return vreinterpretq_m128i_s32(res); +} + +// Negate packed 8-bit integers in a when the corresponding signed +// 8-bit integer in b is negative, and store the results in dst. +// Element in dst are zeroed out when the corresponding element +// in b is zero. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sign_epi8 +FORCE_INLINE __m128i _mm_sign_epi8(__m128i _a, __m128i _b) +{ + int8x16_t a = vreinterpretq_s8_m128i(_a); + int8x16_t b = vreinterpretq_s8_m128i(_b); + + // signed shift right: faster than vclt + // (b < 0) ? 0xFF : 0 + uint8x16_t ltMask = vreinterpretq_u8_s8(vshrq_n_s8(b, 7)); + + // (b == 0) ? 0xFF : 0 +#if SSE2NEON_ARCH_AARCH64 + int8x16_t zeroMask = vreinterpretq_s8_u8(vceqzq_s8(b)); +#else + int8x16_t zeroMask = vreinterpretq_s8_u8(vceqq_s8(b, vdupq_n_s8(0))); +#endif + + // bitwise select either a or negative 'a' (vnegq_s8(a) return negative 'a') + // based on ltMask + int8x16_t masked = vbslq_s8(ltMask, vnegq_s8(a), a); + // res = masked & (~zeroMask) + int8x16_t res = vbicq_s8(masked, zeroMask); + + return vreinterpretq_m128i_s8(res); +} + +// Negate packed 16-bit integers in a when the corresponding signed 16-bit +// integer in b is negative, and store the results in dst. Element in dst are +// zeroed out when the corresponding element in b is zero. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sign_pi16 +FORCE_INLINE __m64 _mm_sign_pi16(__m64 _a, __m64 _b) +{ + int16x4_t a = vreinterpret_s16_m64(_a); + int16x4_t b = vreinterpret_s16_m64(_b); + + // signed shift right: faster than vclt + // (b < 0) ? 0xFFFF : 0 + uint16x4_t ltMask = vreinterpret_u16_s16(vshr_n_s16(b, 15)); + + // (b == 0) ? 0xFFFF : 0 +#if SSE2NEON_ARCH_AARCH64 + int16x4_t zeroMask = vreinterpret_s16_u16(vceqz_s16(b)); +#else + int16x4_t zeroMask = vreinterpret_s16_u16(vceq_s16(b, vdup_n_s16(0))); +#endif + + // bitwise select either a or negative 'a' (vneg_s16(a) return negative 'a') + // based on ltMask + int16x4_t masked = vbsl_s16(ltMask, vneg_s16(a), a); + // res = masked & (~zeroMask) + int16x4_t res = vbic_s16(masked, zeroMask); + + return vreinterpret_m64_s16(res); +} + +// Negate packed 32-bit integers in a when the corresponding signed 32-bit +// integer in b is negative, and store the results in dst. Element in dst are +// zeroed out when the corresponding element in b is zero. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sign_pi32 +FORCE_INLINE __m64 _mm_sign_pi32(__m64 _a, __m64 _b) +{ + int32x2_t a = vreinterpret_s32_m64(_a); + int32x2_t b = vreinterpret_s32_m64(_b); + + // signed shift right: faster than vclt + // (b < 0) ? 0xFFFFFFFF : 0 + uint32x2_t ltMask = vreinterpret_u32_s32(vshr_n_s32(b, 31)); + + // (b == 0) ? 0xFFFFFFFF : 0 +#if SSE2NEON_ARCH_AARCH64 + int32x2_t zeroMask = vreinterpret_s32_u32(vceqz_s32(b)); +#else + int32x2_t zeroMask = vreinterpret_s32_u32(vceq_s32(b, vdup_n_s32(0))); +#endif + + // bitwise select either a or negative 'a' (vneg_s32(a) return negative 'a') + // based on ltMask + int32x2_t masked = vbsl_s32(ltMask, vneg_s32(a), a); + // res = masked & (~zeroMask) + int32x2_t res = vbic_s32(masked, zeroMask); + + return vreinterpret_m64_s32(res); +} + +// Negate packed 8-bit integers in a when the corresponding signed 8-bit integer +// in b is negative, and store the results in dst. Element in dst are zeroed out +// when the corresponding element in b is zero. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sign_pi8 +FORCE_INLINE __m64 _mm_sign_pi8(__m64 _a, __m64 _b) +{ + int8x8_t a = vreinterpret_s8_m64(_a); + int8x8_t b = vreinterpret_s8_m64(_b); + + // signed shift right: faster than vclt + // (b < 0) ? 0xFF : 0 + uint8x8_t ltMask = vreinterpret_u8_s8(vshr_n_s8(b, 7)); + + // (b == 0) ? 0xFF : 0 +#if SSE2NEON_ARCH_AARCH64 + int8x8_t zeroMask = vreinterpret_s8_u8(vceqz_s8(b)); +#else + int8x8_t zeroMask = vreinterpret_s8_u8(vceq_s8(b, vdup_n_s8(0))); +#endif + + // bitwise select either a or negative 'a' (vneg_s8(a) return negative 'a') + // based on ltMask + int8x8_t masked = vbsl_s8(ltMask, vneg_s8(a), a); + // res = masked & (~zeroMask) + int8x8_t res = vbic_s8(masked, zeroMask); + + return vreinterpret_m64_s8(res); +} + +/* SSE4.1 */ + +// Blend packed 16-bit integers from a and b using control mask imm8, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blend_epi16 +// FORCE_INLINE __m128i _mm_blend_epi16(__m128i a, __m128i b, const int imm) +// imm must be a compile-time constant in range [0, 255] +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_blend_epi16(a, b, imm) \ + _sse2neon_define2( \ + __m128i, a, b, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); \ + const uint16_t _mask[8] = _sse2neon_init( \ + ((imm) & (1 << 0)) ? _sse2neon_static_cast(uint16_t, -1) : 0x0, \ + ((imm) & (1 << 1)) ? _sse2neon_static_cast(uint16_t, -1) : 0x0, \ + ((imm) & (1 << 2)) ? _sse2neon_static_cast(uint16_t, -1) : 0x0, \ + ((imm) & (1 << 3)) ? _sse2neon_static_cast(uint16_t, -1) : 0x0, \ + ((imm) & (1 << 4)) ? _sse2neon_static_cast(uint16_t, -1) : 0x0, \ + ((imm) & (1 << 5)) ? _sse2neon_static_cast(uint16_t, -1) : 0x0, \ + ((imm) & (1 << 6)) ? _sse2neon_static_cast(uint16_t, -1) : 0x0, \ + ((imm) & (1 << 7)) ? _sse2neon_static_cast(uint16_t, -1) : 0x0); \ + uint16x8_t _mask_vec = vld1q_u16(_mask); \ + uint16x8_t __a = vreinterpretq_u16_m128i(_a); \ + uint16x8_t __b = vreinterpretq_u16_m128i(_b); _sse2neon_return( \ + vreinterpretq_m128i_u16(vbslq_u16(_mask_vec, __b, __a)));) +#else +FORCE_INLINE __m128i _mm_blend_epi16(__m128i a, __m128i b, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 255); + const uint16_t mask[8] = { + (imm & (1 << 0)) ? (uint16_t) -1 : 0x0, + (imm & (1 << 1)) ? (uint16_t) -1 : 0x0, + (imm & (1 << 2)) ? (uint16_t) -1 : 0x0, + (imm & (1 << 3)) ? (uint16_t) -1 : 0x0, + (imm & (1 << 4)) ? (uint16_t) -1 : 0x0, + (imm & (1 << 5)) ? (uint16_t) -1 : 0x0, + (imm & (1 << 6)) ? (uint16_t) -1 : 0x0, + (imm & (1 << 7)) ? (uint16_t) -1 : 0x0, + }; + uint16x8_t mask_vec = vld1q_u16(mask); + uint16x8_t ua = vreinterpretq_u16_m128i(a); + uint16x8_t ub = vreinterpretq_u16_m128i(b); + return vreinterpretq_m128i_u16(vbslq_u16(mask_vec, ub, ua)); +} +#endif + +// Blend packed double-precision (64-bit) floating-point elements from a and b +// using control mask imm8, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blend_pd +// imm must be a compile-time constant in range [0, 3] +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_blend_pd(a, b, imm) \ + _sse2neon_define2( \ + __m128d, a, b, SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 3); \ + const uint64_t _mask[2] = \ + _sse2neon_init(((imm) & (1 << 0)) ? ~UINT64_C(0) : UINT64_C(0), \ + ((imm) & (1 << 1)) ? ~UINT64_C(0) : UINT64_C(0)); \ + uint64x2_t _mask_vec = vld1q_u64(_mask); \ + uint64x2_t __a = vreinterpretq_u64_m128d(_a); \ + uint64x2_t __b = vreinterpretq_u64_m128d(_b); _sse2neon_return( \ + vreinterpretq_m128d_u64(vbslq_u64(_mask_vec, __b, __a)));) +#else +FORCE_INLINE __m128d _mm_blend_pd(__m128d a, __m128d b, int imm) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 3); + const uint64_t mask[2] = { + (imm & (1 << 0)) ? ~UINT64_C(0) : UINT64_C(0), + (imm & (1 << 1)) ? ~UINT64_C(0) : UINT64_C(0), + }; + uint64x2_t mask_vec = vld1q_u64(mask); + uint64x2_t ua = vreinterpretq_u64_m128d(a); + uint64x2_t ub = vreinterpretq_u64_m128d(b); + return vreinterpretq_m128d_u64(vbslq_u64(mask_vec, ub, ua)); +} +#endif + +// Blend packed single-precision (32-bit) floating-point elements from a and b +// using mask, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blend_ps +// imm8 must be a compile-time constant in range [0, 15] +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_blend_ps(a, b, imm8) \ + _sse2neon_define2( \ + __m128, a, b, SSE2NEON_REQUIRE_CONST_RANGE(imm8, 0, 15); \ + const uint32_t _mask[4] = \ + _sse2neon_init(((imm8) & (1 << 0)) ? UINT32_MAX : 0, \ + ((imm8) & (1 << 1)) ? UINT32_MAX : 0, \ + ((imm8) & (1 << 2)) ? UINT32_MAX : 0, \ + ((imm8) & (1 << 3)) ? UINT32_MAX : 0); \ + uint32x4_t _mask_vec = vld1q_u32(_mask); \ + float32x4_t __a = vreinterpretq_f32_m128(_a); \ + float32x4_t __b = vreinterpretq_f32_m128(_b); _sse2neon_return( \ + vreinterpretq_m128_f32(vbslq_f32(_mask_vec, __b, __a)));) +#else +FORCE_INLINE __m128 _mm_blend_ps(__m128 a, __m128 b, int imm8) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm8, 0, 15); + const uint32_t mask[4] = { + (imm8 & (1 << 0)) ? UINT32_MAX : 0, + (imm8 & (1 << 1)) ? UINT32_MAX : 0, + (imm8 & (1 << 2)) ? UINT32_MAX : 0, + (imm8 & (1 << 3)) ? UINT32_MAX : 0, + }; + uint32x4_t mask_vec = vld1q_u32(mask); + float32x4_t fa = vreinterpretq_f32_m128(a); + float32x4_t fb = vreinterpretq_f32_m128(b); + return vreinterpretq_m128_f32(vbslq_f32(mask_vec, fb, fa)); +} +#endif + +// Blend packed 8-bit integers from a and b using mask, and store the results in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blendv_epi8 +FORCE_INLINE __m128i _mm_blendv_epi8(__m128i _a, __m128i _b, __m128i _mask) +{ + // Use a signed shift right to create a mask with the sign bit + uint8x16_t mask = + vreinterpretq_u8_s8(vshrq_n_s8(vreinterpretq_s8_m128i(_mask), 7)); + uint8x16_t a = vreinterpretq_u8_m128i(_a); + uint8x16_t b = vreinterpretq_u8_m128i(_b); + return vreinterpretq_m128i_u8(vbslq_u8(mask, b, a)); +} + +// Blend packed double-precision (64-bit) floating-point elements from a and b +// using mask, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blendv_pd +FORCE_INLINE __m128d _mm_blendv_pd(__m128d _a, __m128d _b, __m128d _mask) +{ + uint64x2_t mask = + vreinterpretq_u64_s64(vshrq_n_s64(vreinterpretq_s64_m128d(_mask), 63)); +#if SSE2NEON_ARCH_AARCH64 + float64x2_t a = vreinterpretq_f64_m128d(_a); + float64x2_t b = vreinterpretq_f64_m128d(_b); + return vreinterpretq_m128d_f64(vbslq_f64(mask, b, a)); +#else + uint64x2_t a = vreinterpretq_u64_m128d(_a); + uint64x2_t b = vreinterpretq_u64_m128d(_b); + return vreinterpretq_m128d_u64(vbslq_u64(mask, b, a)); +#endif +} + +// Blend packed single-precision (32-bit) floating-point elements from a and b +// using mask, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blendv_ps +FORCE_INLINE __m128 _mm_blendv_ps(__m128 _a, __m128 _b, __m128 _mask) +{ + // Use a signed shift right to create a mask with the sign bit + uint32x4_t mask = + vreinterpretq_u32_s32(vshrq_n_s32(vreinterpretq_s32_m128(_mask), 31)); + float32x4_t a = vreinterpretq_f32_m128(_a); + float32x4_t b = vreinterpretq_f32_m128(_b); + return vreinterpretq_m128_f32(vbslq_f32(mask, b, a)); +} + +// Round the packed double-precision (64-bit) floating-point elements in a up +// to an integer value, and store the results as packed double-precision +// floating-point elements in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ceil_pd +FORCE_INLINE __m128d _mm_ceil_pd(__m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vrndpq_f64(vreinterpretq_f64_m128d(a))); +#else + double a0, a1; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + a1 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + return _mm_set_pd(ceil(a1), ceil(a0)); +#endif +} + +// Round the packed single-precision (32-bit) floating-point elements in a up to +// an integer value, and store the results as packed single-precision +// floating-point elements in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ceil_ps +FORCE_INLINE __m128 _mm_ceil_ps(__m128 a) +{ +#if SSE2NEON_ARCH_AARCH64 || defined(__ARM_FEATURE_DIRECTED_ROUNDING) + return vreinterpretq_m128_f32(vrndpq_f32(vreinterpretq_f32_m128(a))); +#else + float *f = _sse2neon_reinterpret_cast(float *, &a); + return _mm_set_ps(ceilf(f[3]), ceilf(f[2]), ceilf(f[1]), ceilf(f[0])); +#endif +} + +// Round the lower double-precision (64-bit) floating-point element in b up to +// an integer value, store the result as a double-precision floating-point +// element in the lower element of dst, and copy the upper element from a to the +// upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ceil_sd +FORCE_INLINE __m128d _mm_ceil_sd(__m128d a, __m128d b) +{ + return _mm_move_sd(a, _mm_ceil_pd(b)); +} + +// Round the lower single-precision (32-bit) floating-point element in b up to +// an integer value, store the result as a single-precision floating-point +// element in the lower element of dst, and copy the upper 3 packed elements +// from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_ceil_ss +FORCE_INLINE __m128 _mm_ceil_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_ceil_ps(b)); +} + +// Compare packed 64-bit integers in a and b for equality, and store the results +// in dst +FORCE_INLINE __m128i _mm_cmpeq_epi64(__m128i a, __m128i b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_u64( + vceqq_u64(vreinterpretq_u64_m128i(a), vreinterpretq_u64_m128i(b))); +#else + // ARMv7 lacks vceqq_u64 + // (a == b) -> (a_lo == b_lo) && (a_hi == b_hi) + uint32x4_t cmp = + vceqq_u32(vreinterpretq_u32_m128i(a), vreinterpretq_u32_m128i(b)); + uint32x4_t swapped = vrev64q_u32(cmp); + return vreinterpretq_m128i_u32(vandq_u32(cmp, swapped)); +#endif +} + +// Sign extend packed 16-bit integers in a to packed 32-bit integers, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi16_epi32 +FORCE_INLINE __m128i _mm_cvtepi16_epi32(__m128i a) +{ + return vreinterpretq_m128i_s32( + vmovl_s16(vget_low_s16(vreinterpretq_s16_m128i(a)))); +} + +// Sign extend packed 16-bit integers in a to packed 64-bit integers, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi16_epi64 +FORCE_INLINE __m128i _mm_cvtepi16_epi64(__m128i a) +{ + int16x8_t s16x8 = vreinterpretq_s16_m128i(a); /* xxxx xxxx xxxx 0B0A */ + int32x4_t s32x4 = vmovl_s16(vget_low_s16(s16x8)); /* 000x 000x 000B 000A */ + int64x2_t s64x2 = vmovl_s32(vget_low_s32(s32x4)); /* 0000 000B 0000 000A */ + return vreinterpretq_m128i_s64(s64x2); +} + +// Sign extend packed 32-bit integers in a to packed 64-bit integers, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi32_epi64 +FORCE_INLINE __m128i _mm_cvtepi32_epi64(__m128i a) +{ + return vreinterpretq_m128i_s64( + vmovl_s32(vget_low_s32(vreinterpretq_s32_m128i(a)))); +} + +// Sign extend packed 8-bit integers in a to packed 16-bit integers, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi8_epi16 +FORCE_INLINE __m128i _mm_cvtepi8_epi16(__m128i a) +{ + int8x16_t s8x16 = vreinterpretq_s8_m128i(a); /* xxxx xxxx xxxx DCBA */ + int16x8_t s16x8 = vmovl_s8(vget_low_s8(s8x16)); /* 0x0x 0x0x 0D0C 0B0A */ + return vreinterpretq_m128i_s16(s16x8); +} + +// Sign extend packed 8-bit integers in a to packed 32-bit integers, and store +// the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi8_epi32 +FORCE_INLINE __m128i _mm_cvtepi8_epi32(__m128i a) +{ + int8x16_t s8x16 = vreinterpretq_s8_m128i(a); /* xxxx xxxx xxxx DCBA */ + int16x8_t s16x8 = vmovl_s8(vget_low_s8(s8x16)); /* 0x0x 0x0x 0D0C 0B0A */ + int32x4_t s32x4 = vmovl_s16(vget_low_s16(s16x8)); /* 000D 000C 000B 000A */ + return vreinterpretq_m128i_s32(s32x4); +} + +// Sign extend packed 8-bit integers in the low 8 bytes of a to packed 64-bit +// integers, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepi8_epi64 +FORCE_INLINE __m128i _mm_cvtepi8_epi64(__m128i a) +{ + int8x16_t s8x16 = vreinterpretq_s8_m128i(a); /* xxxx xxxx xxxx xxBA */ + int16x8_t s16x8 = vmovl_s8(vget_low_s8(s8x16)); /* 0x0x 0x0x 0x0x 0B0A */ + int32x4_t s32x4 = vmovl_s16(vget_low_s16(s16x8)); /* 000x 000x 000B 000A */ + int64x2_t s64x2 = vmovl_s32(vget_low_s32(s32x4)); /* 0000 000B 0000 000A */ + return vreinterpretq_m128i_s64(s64x2); +} + +// Zero extend packed unsigned 16-bit integers in a to packed 32-bit integers, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepu16_epi32 +FORCE_INLINE __m128i _mm_cvtepu16_epi32(__m128i a) +{ + return vreinterpretq_m128i_u32( + vmovl_u16(vget_low_u16(vreinterpretq_u16_m128i(a)))); +} + +// Zero extend packed unsigned 16-bit integers in a to packed 64-bit integers, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepu16_epi64 +FORCE_INLINE __m128i _mm_cvtepu16_epi64(__m128i a) +{ + uint16x8_t u16x8 = vreinterpretq_u16_m128i(a); /* xxxx xxxx xxxx 0B0A */ + uint32x4_t u32x4 = vmovl_u16(vget_low_u16(u16x8)); /* 000x 000x 000B 000A */ + uint64x2_t u64x2 = vmovl_u32(vget_low_u32(u32x4)); /* 0000 000B 0000 000A */ + return vreinterpretq_m128i_u64(u64x2); +} + +// Zero extend packed unsigned 32-bit integers in a to packed 64-bit integers, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepu32_epi64 +FORCE_INLINE __m128i _mm_cvtepu32_epi64(__m128i a) +{ + return vreinterpretq_m128i_u64( + vmovl_u32(vget_low_u32(vreinterpretq_u32_m128i(a)))); +} + +// Zero extend packed unsigned 8-bit integers in a to packed 16-bit integers, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepu8_epi16 +FORCE_INLINE __m128i _mm_cvtepu8_epi16(__m128i a) +{ + uint8x16_t u8x16 = vreinterpretq_u8_m128i(a); /* xxxx xxxx HGFE DCBA */ + uint16x8_t u16x8 = vmovl_u8(vget_low_u8(u8x16)); /* 0H0G 0F0E 0D0C 0B0A */ + return vreinterpretq_m128i_u16(u16x8); +} + +// Zero extend packed unsigned 8-bit integers in a to packed 32-bit integers, +// and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepu8_epi32 +FORCE_INLINE __m128i _mm_cvtepu8_epi32(__m128i a) +{ + uint8x16_t u8x16 = vreinterpretq_u8_m128i(a); /* xxxx xxxx xxxx DCBA */ + uint16x8_t u16x8 = vmovl_u8(vget_low_u8(u8x16)); /* 0x0x 0x0x 0D0C 0B0A */ + uint32x4_t u32x4 = vmovl_u16(vget_low_u16(u16x8)); /* 000D 000C 000B 000A */ + return vreinterpretq_m128i_u32(u32x4); +} + +// Zero extend packed unsigned 8-bit integers in the low 8 bytes of a to packed +// 64-bit integers, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtepu8_epi64 +FORCE_INLINE __m128i _mm_cvtepu8_epi64(__m128i a) +{ + uint8x16_t u8x16 = vreinterpretq_u8_m128i(a); /* xxxx xxxx xxxx xxBA */ + uint16x8_t u16x8 = vmovl_u8(vget_low_u8(u8x16)); /* 0x0x 0x0x 0x0x 0B0A */ + uint32x4_t u32x4 = vmovl_u16(vget_low_u16(u16x8)); /* 000x 000x 000B 000A */ + uint64x2_t u64x2 = vmovl_u32(vget_low_u32(u32x4)); /* 0000 000B 0000 000A */ + return vreinterpretq_m128i_u64(u64x2); +} + +// Conditionally multiply the packed double-precision (64-bit) floating-point +// elements in a and b using the high 4 bits in imm8, sum the four products, and +// conditionally store the sum in dst using the low 4 bits of imm8. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_dp_pd +FORCE_INLINE __m128d _mm_dp_pd(__m128d a, __m128d b, const int imm) +{ + // Generate mask value from constant immediate bit value + const int64_t bit0Mask = imm & 0x01 ? INT64_C(-1) : 0; + const int64_t bit1Mask = imm & 0x02 ? INT64_C(-1) : 0; +#if !SSE2NEON_PRECISE_DP + const int64_t bit4Mask = imm & 0x10 ? INT64_C(-1) : 0; + const int64_t bit5Mask = imm & 0x20 ? INT64_C(-1) : 0; +#endif + // Conditional multiplication +#if !SSE2NEON_PRECISE_DP + __m128d mul = _mm_mul_pd(a, b); + const __m128d mulMask = + _mm_castsi128_pd(_mm_set_epi64x(bit5Mask, bit4Mask)); + __m128d tmp = _mm_and_pd(mul, mulMask); +#else +#if SSE2NEON_ARCH_AARCH64 + double d0 = (imm & 0x10) ? vgetq_lane_f64(vreinterpretq_f64_m128d(a), 0) * + vgetq_lane_f64(vreinterpretq_f64_m128d(b), 0) + : 0; + double d1 = (imm & 0x20) ? vgetq_lane_f64(vreinterpretq_f64_m128d(a), 1) * + vgetq_lane_f64(vreinterpretq_f64_m128d(b), 1) + : 0; +#else + double a0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + double a1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + double b0 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 0)); + double b1 = + sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(b), 1)); + double d0 = (imm & 0x10) ? a0 * b0 : 0; + double d1 = (imm & 0x20) ? a1 * b1 : 0; +#endif + __m128d tmp = _mm_set_pd(d1, d0); +#endif + // Sum the products +#if SSE2NEON_ARCH_AARCH64 + double sum = vpaddd_f64(vreinterpretq_f64_m128d(tmp)); +#else + double _tmp0 = sse2neon_recast_u64_f64( + vgetq_lane_u64(vreinterpretq_u64_m128d(tmp), 0)); + double _tmp1 = sse2neon_recast_u64_f64( + vgetq_lane_u64(vreinterpretq_u64_m128d(tmp), 1)); + double sum = _tmp0 + _tmp1; +#endif + // Conditionally store the sum + const __m128d sumMask = + _mm_castsi128_pd(_mm_set_epi64x(bit1Mask, bit0Mask)); + __m128d res = _mm_and_pd(_mm_set_pd1(sum), sumMask); + return res; +} + +// Conditionally multiply the packed single-precision (32-bit) floating-point +// elements in a and b using the high 4 bits in imm8, sum the four products, +// and conditionally store the sum in dst using the low 4 bits of imm. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_dp_ps +FORCE_INLINE __m128 _mm_dp_ps(__m128 a, __m128 b, const int imm) +{ + /* Early exit: no input selected or no output lanes */ + if ((imm & 0xF0) == 0 || (imm & 0x0F) == 0) + return _mm_setzero_ps(); + + float32x4_t prod = vreinterpretq_f32_m128(_mm_mul_ps(a, b)); + +#if SSE2NEON_ARCH_AARCH64 + /* Fast path: all elements, broadcast to all lanes */ + if (imm == 0xFF) + return _mm_set1_ps(vaddvq_f32(prod)); + + /* Fast path: 3-element dot product (x,y,z), broadcast to all lanes */ + if (imm == 0x7F) { + prod = vsetq_lane_f32(0.0f, prod, 3); + return _mm_set1_ps(vaddvq_f32(prod)); + } + + /* Vectorized generic path: apply input mask, sum, apply output mask */ + const uint32_t input_mask[4] = { + (imm & (1 << 4)) ? ~UINT32_C(0) : UINT32_C(0), + (imm & (1 << 5)) ? ~UINT32_C(0) : UINT32_C(0), + (imm & (1 << 6)) ? ~UINT32_C(0) : UINT32_C(0), + (imm & (1 << 7)) ? ~UINT32_C(0) : UINT32_C(0), + }; + prod = vreinterpretq_f32_u32( + vandq_u32(vreinterpretq_u32_f32(prod), vld1q_u32(input_mask))); + + float32x4_t sum = vdupq_n_f32(vaddvq_f32(prod)); + + const uint32_t output_mask[4] = { + (imm & 0x1) ? ~UINT32_C(0) : UINT32_C(0), + (imm & 0x2) ? ~UINT32_C(0) : UINT32_C(0), + (imm & 0x4) ? ~UINT32_C(0) : UINT32_C(0), + (imm & 0x8) ? ~UINT32_C(0) : UINT32_C(0), + }; + return vreinterpretq_m128_f32(vreinterpretq_f32_u32( + vandq_u32(vreinterpretq_u32_f32(sum), vld1q_u32(output_mask)))); +#else + /* ARMv7: scalar fallback (no vaddvq_f32) */ + float s = 0.0f; + + if (imm & (1 << 4)) + s += vgetq_lane_f32(prod, 0); + if (imm & (1 << 5)) + s += vgetq_lane_f32(prod, 1); + if (imm & (1 << 6)) + s += vgetq_lane_f32(prod, 2); + if (imm & (1 << 7)) + s += vgetq_lane_f32(prod, 3); + + const float32_t res[4] = { + (imm & 0x1) ? s : 0.0f, + (imm & 0x2) ? s : 0.0f, + (imm & 0x4) ? s : 0.0f, + (imm & 0x8) ? s : 0.0f, + }; + return vreinterpretq_m128_f32(vld1q_f32(res)); +#endif +} + +// Extract a 32-bit integer from a, selected with imm8, and store the result in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_extract_epi32 +// FORCE_INLINE int _mm_extract_epi32(__m128i a, const int imm) +// imm must be a compile-time constant in range [0, 3] +#define _mm_extract_epi32(a, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 3), \ + vgetq_lane_s32(vreinterpretq_s32_m128i(a), (imm))) + +// Extract a 64-bit integer from a, selected with imm8, and store the result in +// dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_extract_epi64 +// FORCE_INLINE __int64 _mm_extract_epi64(__m128i a, const int imm) +// imm must be a compile-time constant in range [0, 1] +#define _mm_extract_epi64(a, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 1), \ + vgetq_lane_s64(vreinterpretq_s64_m128i(a), (imm))) + +// Extract an 8-bit integer from a, selected with imm8, and store the result in +// the lower element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_extract_epi8 +// FORCE_INLINE int _mm_extract_epi8(__m128i a, const int imm) +// imm must be a compile-time constant in range [0, 15] +#define _mm_extract_epi8(a, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 15), \ + vgetq_lane_u8(vreinterpretq_u8_m128i(a), (imm))) + +// Extracts the selected single-precision (32-bit) floating-point from a. +// FORCE_INLINE int _mm_extract_ps(__m128 a, const int imm) +// imm must be a compile-time constant in range [0, 3] +#define _mm_extract_ps(a, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 3), \ + vgetq_lane_s32(vreinterpretq_s32_m128(a), (imm))) + +// Round the packed double-precision (64-bit) floating-point elements in a down +// to an integer value, and store the results as packed double-precision +// floating-point elements in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_floor_pd +FORCE_INLINE __m128d _mm_floor_pd(__m128d a) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128d_f64(vrndmq_f64(vreinterpretq_f64_m128d(a))); +#else + double a0, a1; + a0 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 0)); + a1 = sse2neon_recast_u64_f64(vgetq_lane_u64(vreinterpretq_u64_m128d(a), 1)); + return _mm_set_pd(floor(a1), floor(a0)); +#endif +} + +// Round the packed single-precision (32-bit) floating-point elements in a down +// to an integer value, and store the results as packed single-precision +// floating-point elements in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_floor_ps +FORCE_INLINE __m128 _mm_floor_ps(__m128 a) +{ +#if SSE2NEON_ARCH_AARCH64 || defined(__ARM_FEATURE_DIRECTED_ROUNDING) + return vreinterpretq_m128_f32(vrndmq_f32(vreinterpretq_f32_m128(a))); +#else + float *f = _sse2neon_reinterpret_cast(float *, &a); + return _mm_set_ps(floorf(f[3]), floorf(f[2]), floorf(f[1]), floorf(f[0])); +#endif +} + +// Round the lower double-precision (64-bit) floating-point element in b down to +// an integer value, store the result as a double-precision floating-point +// element in the lower element of dst, and copy the upper element from a to the +// upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_floor_sd +FORCE_INLINE __m128d _mm_floor_sd(__m128d a, __m128d b) +{ + return _mm_move_sd(a, _mm_floor_pd(b)); +} + +// Round the lower single-precision (32-bit) floating-point element in b down to +// an integer value, store the result as a single-precision floating-point +// element in the lower element of dst, and copy the upper 3 packed elements +// from a to the upper elements of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_floor_ss +FORCE_INLINE __m128 _mm_floor_ss(__m128 a, __m128 b) +{ + return _mm_move_ss(a, _mm_floor_ps(b)); +} + +// Copy a to dst, and insert the 32-bit integer i into dst at the location +// specified by imm8. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_insert_epi32 +// FORCE_INLINE __m128i _mm_insert_epi32(__m128i a, int b, const int imm) +// imm must be a compile-time constant in range [0, 3] +#define _mm_insert_epi32(a, b, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 3), \ + vreinterpretq_m128i_s32( \ + vsetq_lane_s32((b), vreinterpretq_s32_m128i(a), (imm)))) + +// Copy a to dst, and insert the 64-bit integer i into dst at the location +// specified by imm8. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_insert_epi64 +// FORCE_INLINE __m128i _mm_insert_epi64(__m128i a, __int64 b, const int imm) +// imm must be a compile-time constant in range [0, 1] +#define _mm_insert_epi64(a, b, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 1), \ + vreinterpretq_m128i_s64( \ + vsetq_lane_s64((b), vreinterpretq_s64_m128i(a), (imm)))) + +// Copy a to dst, and insert the lower 8-bit integer from i into dst at the +// location specified by imm8. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_insert_epi8 +// FORCE_INLINE __m128i _mm_insert_epi8(__m128i a, int b, const int imm) +// imm must be a compile-time constant in range [0, 15] +#define _mm_insert_epi8(a, b, imm) \ + (SSE2NEON_REQUIRE_CONST_RANGE(imm, 0, 15), \ + vreinterpretq_m128i_s8( \ + vsetq_lane_s8((b), vreinterpretq_s8_m128i(a), (imm)))) + +// Copy a to tmp, then insert a single-precision (32-bit) floating-point +// element from b into tmp using the control in imm8. Store tmp to dst using +// the mask in imm8 (elements are zeroed out when the corresponding bit is set). +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=insert_ps +// imm8 must be a compile-time constant in range [0, 255] +#if SSE2NEON_COMPILER_GCC_COMPAT || defined(__cplusplus) +#define _mm_insert_ps(a, b, imm8) \ + _sse2neon_define2( \ + __m128, a, b, SSE2NEON_REQUIRE_CONST_RANGE(imm8, 0, 255); \ + float32x4_t tmp1 = \ + vsetq_lane_f32(vgetq_lane_f32(_b, ((imm8) >> 6) & 0x3), \ + vreinterpretq_f32_m128(_a), 0); \ + float32x4_t tmp2 = \ + vsetq_lane_f32(vgetq_lane_f32(tmp1, 0), \ + vreinterpretq_f32_m128(_a), (((imm8) >> 4) & 0x3)); \ + const uint32_t data[4] = \ + _sse2neon_init(((imm8) & (1 << 0)) ? UINT32_MAX : 0, \ + ((imm8) & (1 << 1)) ? UINT32_MAX : 0, \ + ((imm8) & (1 << 2)) ? UINT32_MAX : 0, \ + ((imm8) & (1 << 3)) ? UINT32_MAX : 0); \ + uint32x4_t mask = vld1q_u32(data); \ + float32x4_t all_zeros = vdupq_n_f32(0); \ + \ + _sse2neon_return(vreinterpretq_m128_f32( \ + vbslq_f32(mask, all_zeros, vreinterpretq_f32_m128(tmp2))));) +#else +FORCE_INLINE __m128 _mm_insert_ps(__m128 a, __m128 b, int imm8) +{ + SSE2NEON_REQUIRE_CONST_RANGE(imm8, 0, 255); + float32x4_t fa = vreinterpretq_f32_m128(a); + float32x4_t fb = vreinterpretq_f32_m128(b); + float32x4_t tmp1 = + vsetq_lane_f32(_sse2neon_vgetq_lane_f32(fb, (imm8 >> 6) & 0x3), fa, 0); + float32x4_t tmp2 = _sse2neon_vsetq_lane_f32(vgetq_lane_f32(tmp1, 0), fa, + (imm8 >> 4) & 0x3); + const uint32_t data[4] = { + (imm8 & (1 << 0)) ? UINT32_MAX : 0, + (imm8 & (1 << 1)) ? UINT32_MAX : 0, + (imm8 & (1 << 2)) ? UINT32_MAX : 0, + (imm8 & (1 << 3)) ? UINT32_MAX : 0, + }; + uint32x4_t mask = vld1q_u32(data); + float32x4_t all_zeros = vdupq_n_f32(0); + return vreinterpretq_m128_f32( + vbslq_f32(mask, all_zeros, vreinterpretq_f32_m128(tmp2))); +} +#endif + +// Compare packed signed 32-bit integers in a and b, and store packed maximum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epi32 +FORCE_INLINE __m128i _mm_max_epi32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s32( + vmaxq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +// Compare packed signed 8-bit integers in a and b, and store packed maximum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epi8 +FORCE_INLINE __m128i _mm_max_epi8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s8( + vmaxq_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +} + +// Compare packed unsigned 16-bit integers in a and b, and store packed maximum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epu16 +FORCE_INLINE __m128i _mm_max_epu16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u16( + vmaxq_u16(vreinterpretq_u16_m128i(a), vreinterpretq_u16_m128i(b))); +} + +// Compare packed unsigned 32-bit integers in a and b, and store packed maximum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epu32 +FORCE_INLINE __m128i _mm_max_epu32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u32( + vmaxq_u32(vreinterpretq_u32_m128i(a), vreinterpretq_u32_m128i(b))); +} + +// Compare packed signed 32-bit integers in a and b, and store packed minimum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_epi32 +FORCE_INLINE __m128i _mm_min_epi32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s32( + vminq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +// Compare packed signed 8-bit integers in a and b, and store packed minimum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_epi8 +FORCE_INLINE __m128i _mm_min_epi8(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s8( + vminq_s8(vreinterpretq_s8_m128i(a), vreinterpretq_s8_m128i(b))); +} + +// Compare packed unsigned 16-bit integers in a and b, and store packed minimum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_min_epu16 +FORCE_INLINE __m128i _mm_min_epu16(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u16( + vminq_u16(vreinterpretq_u16_m128i(a), vreinterpretq_u16_m128i(b))); +} + +// Compare packed unsigned 32-bit integers in a and b, and store packed minimum +// values in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_max_epu32 +FORCE_INLINE __m128i _mm_min_epu32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u32( + vminq_u32(vreinterpretq_u32_m128i(a), vreinterpretq_u32_m128i(b))); +} + +// Horizontally compute the minimum amongst the packed unsigned 16-bit integers +// in a, store the minimum and index in dst, and zero the remaining bits in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_minpos_epu16 +FORCE_INLINE __m128i _mm_minpos_epu16(__m128i a) +{ + uint16_t min, idx = 0; +#if SSE2NEON_ARCH_AARCH64 + uint16x8_t _a = vreinterpretq_u16_m128i(a); + // Find the minimum value + min = vminvq_u16(_a); + + // Get the index of the minimum value + static const uint16_t idxv[] = {0, 1, 2, 3, 4, 5, 6, 7}; + uint16x8_t minv = vdupq_n_u16(min); + uint16x8_t cmeq = vceqq_u16(minv, _a); + idx = vminvq_u16(vornq_u16(vld1q_u16(idxv), cmeq)); +#else + uint16x8_t _a = vreinterpretq_u16_m128i(a); + // Find the minimum value + uint16x4_t tmp = vmin_u16(vget_low_u16(_a), vget_high_u16(_a)); + tmp = vpmin_u16(tmp, tmp); + tmp = vpmin_u16(tmp, tmp); + min = vget_lane_u16(tmp, 0); + // Get the index of the minimum value + int i; + for (i = 0; i < 8; i++) { + if (min == vgetq_lane_u16(_a, 0)) { + idx = _sse2neon_static_cast(uint16_t, i); + break; + } + _a = vreinterpretq_u16_s8( + vextq_s8(vreinterpretq_s8_u16(_a), vreinterpretq_s8_u16(_a), 2)); + } +#endif + // Generate result + uint16x8_t result = vdupq_n_u16(0); + result = vsetq_lane_u16(min, result, 0); + result = vsetq_lane_u16(idx, result, 1); + return vreinterpretq_m128i_u16(result); +} + +// Compute the sum of absolute differences (SADs) of quadruplets of unsigned +// 8-bit integers in a compared to those in b, and store the 16-bit results in +// dst. Eight SADs are performed using one quadruplet from b and eight +// quadruplets from a. One quadruplet is selected from b starting at on the +// offset specified in imm8. Eight quadruplets are formed from sequential 8-bit +// integers selected from a starting at the offset specified in imm8. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mpsadbw_epu8 +FORCE_INLINE __m128i _mm_mpsadbw_epu8(__m128i a, __m128i b, const int imm) +{ + uint8x16_t _a, _b; + + switch (imm & 0x4) { + case 0: + // do nothing + _a = vreinterpretq_u8_m128i(a); + break; + case 4: + _a = vreinterpretq_u8_u32(vextq_u32(vreinterpretq_u32_m128i(a), + vreinterpretq_u32_m128i(a), 1)); + break; + default: +#if SSE2NEON_COMPILER_GCC_COMPAT + __builtin_unreachable(); +#elif SSE2NEON_COMPILER_MSVC + __assume(0); +#endif + break; + } + + switch (imm & 0x3) { + case 0: + _b = vreinterpretq_u8_u32( + vdupq_n_u32(vgetq_lane_u32(vreinterpretq_u32_m128i(b), 0))); + break; + case 1: + _b = vreinterpretq_u8_u32( + vdupq_n_u32(vgetq_lane_u32(vreinterpretq_u32_m128i(b), 1))); + break; + case 2: + _b = vreinterpretq_u8_u32( + vdupq_n_u32(vgetq_lane_u32(vreinterpretq_u32_m128i(b), 2))); + break; + case 3: + _b = vreinterpretq_u8_u32( + vdupq_n_u32(vgetq_lane_u32(vreinterpretq_u32_m128i(b), 3))); + break; + default: +#if SSE2NEON_COMPILER_GCC_COMPAT + __builtin_unreachable(); +#elif SSE2NEON_COMPILER_MSVC + __assume(0); +#endif + break; + } + + int16x8_t c04, c15, c26, c37; + uint8x8_t low_b = vget_low_u8(_b); + c04 = vreinterpretq_s16_u16(vabdl_u8(vget_low_u8(_a), low_b)); + uint8x16_t _a_1 = vextq_u8(_a, _a, 1); + c15 = vreinterpretq_s16_u16(vabdl_u8(vget_low_u8(_a_1), low_b)); + uint8x16_t _a_2 = vextq_u8(_a, _a, 2); + c26 = vreinterpretq_s16_u16(vabdl_u8(vget_low_u8(_a_2), low_b)); + uint8x16_t _a_3 = vextq_u8(_a, _a, 3); + c37 = vreinterpretq_s16_u16(vabdl_u8(vget_low_u8(_a_3), low_b)); +#if SSE2NEON_ARCH_AARCH64 + // |0|4|2|6| + c04 = vpaddq_s16(c04, c26); + // |1|5|3|7| + c15 = vpaddq_s16(c15, c37); + + int32x4_t trn1_c = + vtrn1q_s32(vreinterpretq_s32_s16(c04), vreinterpretq_s32_s16(c15)); + int32x4_t trn2_c = + vtrn2q_s32(vreinterpretq_s32_s16(c04), vreinterpretq_s32_s16(c15)); + return vreinterpretq_m128i_s16(vpaddq_s16(vreinterpretq_s16_s32(trn1_c), + vreinterpretq_s16_s32(trn2_c))); +#else + int16x4_t c01, c23, c45, c67; + c01 = vpadd_s16(vget_low_s16(c04), vget_low_s16(c15)); + c23 = vpadd_s16(vget_low_s16(c26), vget_low_s16(c37)); + c45 = vpadd_s16(vget_high_s16(c04), vget_high_s16(c15)); + c67 = vpadd_s16(vget_high_s16(c26), vget_high_s16(c37)); + + return vreinterpretq_m128i_s16( + vcombine_s16(vpadd_s16(c01, c23), vpadd_s16(c45, c67))); +#endif +} + +// Multiply the low signed 32-bit integers from each packed 64-bit element in +// a and b, and store the signed 64-bit results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mul_epi32 +FORCE_INLINE __m128i _mm_mul_epi32(__m128i a, __m128i b) +{ + // vmull_s32 upcasts instead of masking, so we downcast. + int32x2_t a_lo = vmovn_s64(vreinterpretq_s64_m128i(a)); + int32x2_t b_lo = vmovn_s64(vreinterpretq_s64_m128i(b)); + return vreinterpretq_m128i_s64(vmull_s32(a_lo, b_lo)); +} + +// Multiply the packed 32-bit integers in a and b, producing intermediate 64-bit +// integers, and store the low 32 bits of the intermediate integers in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mullo_epi32 +FORCE_INLINE __m128i _mm_mullo_epi32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_s32( + vmulq_s32(vreinterpretq_s32_m128i(a), vreinterpretq_s32_m128i(b))); +} + +// Convert packed signed 32-bit integers from a and b to packed 16-bit integers +// using unsigned saturation, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packus_epi32 +FORCE_INLINE __m128i _mm_packus_epi32(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u16( + vcombine_u16(vqmovun_s32(vreinterpretq_s32_m128i(a)), + vqmovun_s32(vreinterpretq_s32_m128i(b)))); +} + +// Round the packed double-precision (64-bit) floating-point elements in a using +// the rounding parameter, and store the results as packed double-precision +// floating-point elements in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_round_pd +FORCE_INLINE __m128d _mm_round_pd(__m128d a, int rounding) +{ + rounding &= ~(_MM_FROUND_RAISE_EXC | _MM_FROUND_NO_EXC); + +#if SSE2NEON_ARCH_AARCH64 + switch (rounding) { + case _MM_FROUND_TO_NEAREST_INT: + return vreinterpretq_m128d_f64(vrndnq_f64(vreinterpretq_f64_m128d(a))); + case _MM_FROUND_TO_NEG_INF: + return _mm_floor_pd(a); + case _MM_FROUND_TO_POS_INF: + return _mm_ceil_pd(a); + case _MM_FROUND_TO_ZERO: + return vreinterpretq_m128d_f64(vrndq_f64(vreinterpretq_f64_m128d(a))); + default: //_MM_FROUND_CUR_DIRECTION + return vreinterpretq_m128d_f64(vrndiq_f64(vreinterpretq_f64_m128d(a))); + } +#else + double *v_double = _sse2neon_reinterpret_cast(double *, &a); + + if (rounding == _MM_FROUND_TO_NEAREST_INT || + (rounding == _MM_FROUND_CUR_DIRECTION && + _MM_GET_ROUNDING_MODE() == _MM_ROUND_NEAREST)) { + double res[2], tmp; + for (int i = 0; i < 2; i++) { + tmp = (v_double[i] < 0) ? -v_double[i] : v_double[i]; + double roundDown = floor(tmp); // Round down value + double roundUp = ceil(tmp); // Round up value + double diffDown = tmp - roundDown; + double diffUp = roundUp - tmp; + if (diffDown < diffUp) { + /* If it's closer to the round down value, then use it */ + res[i] = roundDown; + } else if (diffDown > diffUp) { + /* If it's closer to the round up value, then use it */ + res[i] = roundUp; + } else { + /* If it's equidistant between round up and round down value, + * pick the one which is an even number */ + double half = roundDown / 2; + if (half != floor(half)) { + /* If the round down value is odd, return the round up value + */ + res[i] = roundUp; + } else { + /* If the round up value is odd, return the round down value + */ + res[i] = roundDown; + } + } + res[i] = (v_double[i] < 0) ? -res[i] : res[i]; + } + return _mm_set_pd(res[1], res[0]); + } else if (rounding == _MM_FROUND_TO_NEG_INF || + (rounding == _MM_FROUND_CUR_DIRECTION && + _MM_GET_ROUNDING_MODE() == _MM_ROUND_DOWN)) { + return _mm_floor_pd(a); + } else if (rounding == _MM_FROUND_TO_POS_INF || + (rounding == _MM_FROUND_CUR_DIRECTION && + _MM_GET_ROUNDING_MODE() == _MM_ROUND_UP)) { + return _mm_ceil_pd(a); + } + return _mm_set_pd(v_double[1] > 0 ? floor(v_double[1]) : ceil(v_double[1]), + v_double[0] > 0 ? floor(v_double[0]) : ceil(v_double[0])); +#endif +} + +// Round the packed single-precision (32-bit) floating-point elements in a using +// the rounding parameter, and store the results as packed single-precision +// floating-point elements in dst. +// software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_round_ps +FORCE_INLINE __m128 _mm_round_ps(__m128 a, int rounding) +{ + rounding &= ~(_MM_FROUND_RAISE_EXC | _MM_FROUND_NO_EXC); + +#if SSE2NEON_ARCH_AARCH64 || defined(__ARM_FEATURE_DIRECTED_ROUNDING) + switch (rounding) { + case _MM_FROUND_TO_NEAREST_INT: + return vreinterpretq_m128_f32(vrndnq_f32(vreinterpretq_f32_m128(a))); + case _MM_FROUND_TO_NEG_INF: + return _mm_floor_ps(a); + case _MM_FROUND_TO_POS_INF: + return _mm_ceil_ps(a); + case _MM_FROUND_TO_ZERO: + return vreinterpretq_m128_f32(vrndq_f32(vreinterpretq_f32_m128(a))); + default: //_MM_FROUND_CUR_DIRECTION + return vreinterpretq_m128_f32(vrndiq_f32(vreinterpretq_f32_m128(a))); + } +#else + float *v_float = _sse2neon_reinterpret_cast(float *, &a); + float32x4_t v = vreinterpretq_f32_m128(a); + + /* Detect values safe to convert to int32. Values outside this range + * (including infinity, NaN, and large finite values) must be preserved + * as-is since integer conversion would produce undefined results. */ + const float32x4_t max_representable = vdupq_n_f32(2147483520.0f); + uint32x4_t is_safe = + vcleq_f32(vabsq_f32(v), max_representable); /* |v| <= max int32 */ + + if (rounding == _MM_FROUND_TO_NEAREST_INT || + (rounding == _MM_FROUND_CUR_DIRECTION && + _MM_GET_ROUNDING_MODE() == _MM_ROUND_NEAREST)) { + uint32x4_t signmask = vdupq_n_u32(0x80000000); + float32x4_t half = + vbslq_f32(signmask, v, vdupq_n_f32(0.5f)); /* +/- 0.5 */ + int32x4_t r_normal = + vcvtq_s32_f32(vaddq_f32(v, half)); /* round to integer: [a + 0.5]*/ + int32x4_t r_trunc = vcvtq_s32_f32(v); /* truncate to integer: [a] */ + int32x4_t plusone = vreinterpretq_s32_u32(vshrq_n_u32( + vreinterpretq_u32_s32(vnegq_s32(r_trunc)), 31)); /* 1 or 0 */ + int32x4_t r_even = vbicq_s32(vaddq_s32(r_trunc, plusone), + vdupq_n_s32(1)); /* ([a] + {0,1}) & ~1 */ + float32x4_t delta = vsubq_f32( + v, vcvtq_f32_s32(r_trunc)); /* compute delta: delta = (a - [a]) */ + uint32x4_t is_delta_half = + vceqq_f32(delta, half); /* delta == +/- 0.5 */ + float32x4_t rounded = + vcvtq_f32_s32(vbslq_s32(is_delta_half, r_even, r_normal)); + /* Preserve original value for inputs outside int32 range */ + return vreinterpretq_m128_f32(vbslq_f32(is_safe, rounded, v)); + } else if (rounding == _MM_FROUND_TO_NEG_INF || + (rounding == _MM_FROUND_CUR_DIRECTION && + _MM_GET_ROUNDING_MODE() == _MM_ROUND_DOWN)) { + return _mm_floor_ps(a); + } else if (rounding == _MM_FROUND_TO_POS_INF || + (rounding == _MM_FROUND_CUR_DIRECTION && + _MM_GET_ROUNDING_MODE() == _MM_ROUND_UP)) { + return _mm_ceil_ps(a); + } + return _mm_set_ps(v_float[3] > 0 ? floorf(v_float[3]) : ceilf(v_float[3]), + v_float[2] > 0 ? floorf(v_float[2]) : ceilf(v_float[2]), + v_float[1] > 0 ? floorf(v_float[1]) : ceilf(v_float[1]), + v_float[0] > 0 ? floorf(v_float[0]) : ceilf(v_float[0])); +#endif +} + +// Round the lower double-precision (64-bit) floating-point element in b using +// the rounding parameter, store the result as a double-precision floating-point +// element in the lower element of dst, and copy the upper element from a to the +// upper element of dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_round_sd +FORCE_INLINE __m128d _mm_round_sd(__m128d a, __m128d b, int rounding) +{ + return _mm_move_sd(a, _mm_round_pd(b, rounding)); +} + +// Round the lower single-precision (32-bit) floating-point element in b using +// the rounding parameter, store the result as a single-precision floating-point +// element in the lower element of dst, and copy the upper 3 packed elements +// from a to the upper elements of dst. Rounding is done according to the +// rounding[3:0] parameter, which can be one of: +// (_MM_FROUND_TO_NEAREST_INT |_MM_FROUND_NO_EXC) // round to nearest, and +// suppress exceptions +// (_MM_FROUND_TO_NEG_INF |_MM_FROUND_NO_EXC) // round down, and +// suppress exceptions +// (_MM_FROUND_TO_POS_INF |_MM_FROUND_NO_EXC) // round up, and suppress +// exceptions +// (_MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC) // truncate, and suppress +// exceptions _MM_FROUND_CUR_DIRECTION // use MXCSR.RC; see +// _MM_SET_ROUNDING_MODE +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_round_ss +FORCE_INLINE __m128 _mm_round_ss(__m128 a, __m128 b, int rounding) +{ + return _mm_move_ss(a, _mm_round_ps(b, rounding)); +} + +// Load 128-bits of integer data from memory into dst using a non-temporal +// memory hint. mem_addr must be aligned on a 16-byte boundary or a +// general-protection exception may be generated. +// Note: On AArch64, __builtin_nontemporal_load generates LDNP (Load +// Non-temporal Pair), providing true non-temporal hint for 128-bit loads. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_stream_load_si128 +FORCE_INLINE __m128i _mm_stream_load_si128(__m128i *p) +{ +#if __has_builtin(__builtin_nontemporal_load) + return __builtin_nontemporal_load(p); +#else + return vreinterpretq_m128i_s64( + vld1q_s64(_sse2neon_reinterpret_cast(int64_t *, p))); +#endif +} + +// Compute the bitwise NOT of a and then AND with a 128-bit vector containing +// all 1's, and return 1 if the result is zero, otherwise return 0. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_test_all_ones +FORCE_INLINE int _mm_test_all_ones(__m128i a) +{ + return _sse2neon_static_cast(uint64_t, + vgetq_lane_s64(a, 0) & vgetq_lane_s64(a, 1)) == + ~_sse2neon_static_cast(uint64_t, 0); +} + +// Compute the bitwise AND of 128 bits (representing integer data) in a and +// mask, and return 1 if the result is zero, otherwise return 0. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_test_all_zeros +FORCE_INLINE int _mm_test_all_zeros(__m128i a, __m128i mask) +{ + int64x2_t a_and_mask = + vandq_s64(vreinterpretq_s64_m128i(a), vreinterpretq_s64_m128i(mask)); + return !(vgetq_lane_s64(a_and_mask, 0) | vgetq_lane_s64(a_and_mask, 1)); +} + +// Compute the bitwise AND of 128 bits (representing integer data) in a and +// mask, and set ZF to 1 if the result is zero, otherwise set ZF to 0. Compute +// the bitwise NOT of a and then AND with mask, and set CF to 1 if the result is +// zero, otherwise set CF to 0. Return 1 if both the ZF and CF values are zero, +// otherwise return 0. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm_test_mix_ones_zero +// Note: Argument names may be wrong in the Intel intrinsics guide. +FORCE_INLINE int _mm_test_mix_ones_zeros(__m128i a, __m128i mask) +{ + uint64x2_t v = vreinterpretq_u64_m128i(a); + uint64x2_t m = vreinterpretq_u64_m128i(mask); + + // find ones (set-bits) and zeros (clear-bits) under clip mask + uint64x2_t ones = vandq_u64(m, v); + uint64x2_t zeros = vbicq_u64(m, v); + + // If both 128-bit variables are populated (non-zero) then return 1. + // For comparison purposes, first compact each var down to 32-bits. + uint32x2_t reduced = vpmax_u32(vqmovn_u64(ones), vqmovn_u64(zeros)); + + // if folding minimum is non-zero then both vars must be non-zero + return (vget_lane_u32(vpmin_u32(reduced, reduced), 0) != 0); +} + +// Compute the bitwise AND of 128 bits (representing integer data) in a and b, +// and set ZF to 1 if the result is zero, otherwise set ZF to 0. Compute the +// bitwise NOT of a and then AND with b, and set CF to 1 if the result is zero, +// otherwise set CF to 0. Return the CF value. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_testc_si128 +FORCE_INLINE int _mm_testc_si128(__m128i a, __m128i b) +{ + int64x2_t s64_vec = + vbicq_s64(vreinterpretq_s64_m128i(b), vreinterpretq_s64_m128i(a)); + return !(vgetq_lane_s64(s64_vec, 0) | vgetq_lane_s64(s64_vec, 1)); +} + +// Compute the bitwise AND of 128 bits (representing integer data) in a and b, +// and set ZF to 1 if the result is zero, otherwise set ZF to 0. Compute the +// bitwise NOT of a and then AND with b, and set CF to 1 if the result is zero, +// otherwise set CF to 0. Return 1 if both the ZF and CF values are zero, +// otherwise return 0. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_testnzc_si128 +#define _mm_testnzc_si128(a, b) _mm_test_mix_ones_zeros(a, b) + +// Compute the bitwise AND of 128 bits (representing integer data) in a and b, +// and set ZF to 1 if the result is zero, otherwise set ZF to 0. Compute the +// bitwise NOT of a and then AND with b, and set CF to 1 if the result is zero, +// otherwise set CF to 0. Return the ZF value. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_testz_si128 +FORCE_INLINE int _mm_testz_si128(__m128i a, __m128i b) +{ + int64x2_t s64_vec = + vandq_s64(vreinterpretq_s64_m128i(a), vreinterpretq_s64_m128i(b)); + return !(vgetq_lane_s64(s64_vec, 0) | vgetq_lane_s64(s64_vec, 1)); +} + +/* SSE4.2 */ + +static const uint16_t ALIGN_STRUCT(16) _sse2neon_cmpestr_mask16b[8] = { + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, +}; +static const uint8_t ALIGN_STRUCT(16) _sse2neon_cmpestr_mask8b[16] = { + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, +}; + +/* specify the source data format */ +#define _SIDD_UBYTE_OPS 0x00 /* unsigned 8-bit characters */ +#define _SIDD_UWORD_OPS 0x01 /* unsigned 16-bit characters */ +#define _SIDD_SBYTE_OPS 0x02 /* signed 8-bit characters */ +#define _SIDD_SWORD_OPS 0x03 /* signed 16-bit characters */ + +/* specify the comparison operation */ +#define _SIDD_CMP_EQUAL_ANY 0x00 /* compare equal any: strchr */ +#define _SIDD_CMP_RANGES 0x04 /* compare ranges */ +#define _SIDD_CMP_EQUAL_EACH 0x08 /* compare equal each: strcmp */ +#define _SIDD_CMP_EQUAL_ORDERED 0x0C /* compare equal ordered */ + +/* specify the polarity */ +#define _SIDD_POSITIVE_POLARITY 0x00 +#define _SIDD_MASKED_POSITIVE_POLARITY 0x20 +#define _SIDD_NEGATIVE_POLARITY 0x10 /* negate results */ +#define _SIDD_MASKED_NEGATIVE_POLARITY \ + 0x30 /* negate results only before end of string */ + +/* specify the output selection in _mm_cmpXstri */ +#define _SIDD_LEAST_SIGNIFICANT 0x00 +#define _SIDD_MOST_SIGNIFICANT 0x40 + +/* specify the output selection in _mm_cmpXstrm */ +#define _SIDD_BIT_MASK 0x00 +#define _SIDD_UNIT_MASK 0x40 + +/* Pattern Matching for C macros. + * https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms + */ + +/* catenate */ +#define SSE2NEON_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__ +#define SSE2NEON_CAT(a, b) SSE2NEON_PRIMITIVE_CAT(a, b) + +#define SSE2NEON_IIF(c) SSE2NEON_PRIMITIVE_CAT(SSE2NEON_IIF_, c) +/* run the 2nd parameter */ +#define SSE2NEON_IIF_0(t, ...) __VA_ARGS__ +/* run the 1st parameter */ +#define SSE2NEON_IIF_1(t, ...) t + +#define SSE2NEON_COMPL(b) SSE2NEON_PRIMITIVE_CAT(SSE2NEON_COMPL_, b) +#define SSE2NEON_COMPL_0 1 +#define SSE2NEON_COMPL_1 0 + +#define SSE2NEON_DEC(x) SSE2NEON_PRIMITIVE_CAT(SSE2NEON_DEC_, x) +#define SSE2NEON_DEC_1 0 +#define SSE2NEON_DEC_2 1 +#define SSE2NEON_DEC_3 2 +#define SSE2NEON_DEC_4 3 +#define SSE2NEON_DEC_5 4 +#define SSE2NEON_DEC_6 5 +#define SSE2NEON_DEC_7 6 +#define SSE2NEON_DEC_8 7 +#define SSE2NEON_DEC_9 8 +#define SSE2NEON_DEC_10 9 +#define SSE2NEON_DEC_11 10 +#define SSE2NEON_DEC_12 11 +#define SSE2NEON_DEC_13 12 +#define SSE2NEON_DEC_14 13 +#define SSE2NEON_DEC_15 14 +#define SSE2NEON_DEC_16 15 + +/* detection */ +#define SSE2NEON_CHECK_N(x, n, ...) n +#define SSE2NEON_CHECK(...) SSE2NEON_CHECK_N(__VA_ARGS__, 0, ) +#define SSE2NEON_PROBE(x) x, 1, + +#define SSE2NEON_NOT(x) SSE2NEON_CHECK(SSE2NEON_PRIMITIVE_CAT(SSE2NEON_NOT_, x)) +#define SSE2NEON_NOT_0 SSE2NEON_PROBE(~) + +#define SSE2NEON_BOOL(x) SSE2NEON_COMPL(SSE2NEON_NOT(x)) +#define SSE2NEON_IF(c) SSE2NEON_IIF(SSE2NEON_BOOL(c)) + +#define SSE2NEON_EAT(...) +#define SSE2NEON_EXPAND(...) __VA_ARGS__ +#define SSE2NEON_WHEN(c) SSE2NEON_IF(c)(SSE2NEON_EXPAND, SSE2NEON_EAT) + +/* recursion */ +/* deferred expression */ +#define SSE2NEON_EMPTY() +#define SSE2NEON_DEFER(id) id SSE2NEON_EMPTY() +#define SSE2NEON_OBSTRUCT(...) __VA_ARGS__ SSE2NEON_DEFER(SSE2NEON_EMPTY)() +#define SSE2NEON_EXPAND(...) __VA_ARGS__ + +#define SSE2NEON_EVAL(...) \ + SSE2NEON_EVAL1(SSE2NEON_EVAL1(SSE2NEON_EVAL1(__VA_ARGS__))) +#define SSE2NEON_EVAL1(...) \ + SSE2NEON_EVAL2(SSE2NEON_EVAL2(SSE2NEON_EVAL2(__VA_ARGS__))) +#define SSE2NEON_EVAL2(...) \ + SSE2NEON_EVAL3(SSE2NEON_EVAL3(SSE2NEON_EVAL3(__VA_ARGS__))) +#define SSE2NEON_EVAL3(...) __VA_ARGS__ + +#define SSE2NEON_REPEAT(count, macro, ...) \ + SSE2NEON_WHEN(count) \ + (SSE2NEON_OBSTRUCT(SSE2NEON_REPEAT_INDIRECT)()( \ + SSE2NEON_DEC(count), macro, \ + __VA_ARGS__) SSE2NEON_OBSTRUCT(macro)(SSE2NEON_DEC(count), \ + __VA_ARGS__)) +#define SSE2NEON_REPEAT_INDIRECT() SSE2NEON_REPEAT + +#define SSE2NEON_SIZE_OF_byte 8 +#define SSE2NEON_NUMBER_OF_LANES_byte 16 +#define SSE2NEON_SIZE_OF_word 16 +#define SSE2NEON_NUMBER_OF_LANES_word 8 + +#define SSE2NEON_COMPARE_EQUAL_THEN_FILL_LANE(i, type) \ + mtx[i] = vreinterpretq_m128i_##type(vceqq_##type( \ + vdupq_n_##type(vgetq_lane_##type(vreinterpretq_##type##_m128i(b), i)), \ + vreinterpretq_##type##_m128i(a))); + +#define SSE2NEON_FILL_LANE(i, type) \ + vec_b[i] = \ + vdupq_n_##type(vgetq_lane_##type(vreinterpretq_##type##_m128i(b), i)); + +#define PCMPSTR_RANGES(a, b, mtx, data_type_prefix, type_prefix, size, \ + number_of_lanes, byte_or_word) \ + do { \ + SSE2NEON_CAT( \ + data_type_prefix, \ + SSE2NEON_CAT(size, \ + SSE2NEON_CAT(x, SSE2NEON_CAT(number_of_lanes, _t)))) \ + vec_b[number_of_lanes]; \ + __m128i mask = SSE2NEON_IIF(byte_or_word)( \ + vreinterpretq_m128i_u16(vdupq_n_u16(0xff)), \ + vreinterpretq_m128i_u32(vdupq_n_u32(0xffff))); \ + SSE2NEON_EVAL(SSE2NEON_REPEAT(number_of_lanes, SSE2NEON_FILL_LANE, \ + SSE2NEON_CAT(type_prefix, size))) \ + for (int i = 0; i < number_of_lanes; i++) { \ + mtx[i] = SSE2NEON_CAT(vreinterpretq_m128i_u, \ + size)(SSE2NEON_CAT(vbslq_u, size)( \ + SSE2NEON_CAT(vreinterpretq_u, \ + SSE2NEON_CAT(size, _m128i))(mask), \ + SSE2NEON_CAT(vcgeq_, SSE2NEON_CAT(type_prefix, size))( \ + vec_b[i], \ + SSE2NEON_CAT( \ + vreinterpretq_, \ + SSE2NEON_CAT(type_prefix, \ + SSE2NEON_CAT(size, _m128i(a))))), \ + SSE2NEON_CAT(vcleq_, SSE2NEON_CAT(type_prefix, size))( \ + vec_b[i], \ + SSE2NEON_CAT( \ + vreinterpretq_, \ + SSE2NEON_CAT(type_prefix, \ + SSE2NEON_CAT(size, _m128i(a))))))); \ + } \ + } while (0) + +#define PCMPSTR_EQ(a, b, mtx, size, number_of_lanes) \ + do { \ + SSE2NEON_EVAL(SSE2NEON_REPEAT(number_of_lanes, \ + SSE2NEON_COMPARE_EQUAL_THEN_FILL_LANE, \ + SSE2NEON_CAT(u, size))) \ + } while (0) + +#define SSE2NEON_CMP_EQUAL_ANY_IMPL(type) \ + static uint16_t _sse2neon_cmp_##type##_equal_any(__m128i a, int la, \ + __m128i b, int lb) \ + { \ + __m128i mtx[16]; \ + PCMPSTR_EQ(a, b, mtx, SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, type)); \ + return SSE2NEON_CAT( \ + _sse2neon_aggregate_equal_any_, \ + SSE2NEON_CAT( \ + SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(x, SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, \ + type))))(la, lb, mtx); \ + } + +#define SSE2NEON_CMP_RANGES_IMPL(type, data_type, us, byte_or_word) \ + static uint16_t _sse2neon_cmp_##us##type##_ranges(__m128i a, int la, \ + __m128i b, int lb) \ + { \ + __m128i mtx[16]; \ + PCMPSTR_RANGES( \ + a, b, mtx, data_type, us, SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, type), byte_or_word); \ + return SSE2NEON_CAT( \ + _sse2neon_aggregate_ranges_, \ + SSE2NEON_CAT( \ + SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(x, SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, \ + type))))(la, lb, mtx); \ + } + +#define SSE2NEON_CMP_EQUAL_ORDERED_IMPL(type) \ + static uint16_t _sse2neon_cmp_##type##_equal_ordered(__m128i a, int la, \ + __m128i b, int lb) \ + { \ + __m128i mtx[16]; \ + PCMPSTR_EQ(a, b, mtx, SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, type)); \ + return SSE2NEON_CAT( \ + _sse2neon_aggregate_equal_ordered_, \ + SSE2NEON_CAT( \ + SSE2NEON_CAT(SSE2NEON_SIZE_OF_, type), \ + SSE2NEON_CAT(x, \ + SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, type))))( \ + SSE2NEON_CAT(SSE2NEON_NUMBER_OF_LANES_, type), la, lb, mtx); \ + } + +static uint16_t _sse2neon_aggregate_equal_any_8x16(int la, + int lb, + __m128i mtx[16]) +{ + int m = (1 << la) - 1; + uint8x8_t vec_mask = vld1_u8(_sse2neon_cmpestr_mask8b); + uint8x8_t t_lo = + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, m & 0xff)), vec_mask); + uint8x8_t t_hi = + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, m >> 8)), vec_mask); + uint8x16_t vec = vcombine_u8(t_lo, t_hi); + + /* Process all 16 rows in parallel. + * For each row j, check if any element in mtx[j] (masked by vec) is + * non-zero. Result bit j = 1 if row j has any match. + * + * Key optimization: Process all rows, then mask by lb at the end. + * This allows full SIMD utilization without loop-carried dependencies. + */ +#if SSE2NEON_ARCH_AARCH64 + /* AArch64: Use vmaxvq for horizontal max (equivalent to OR for 0/1) */ +#define SSE2NEON_UMAXV_MATCH(i) \ + ((vmaxvq_u8(vandq_u8(vec, vreinterpretq_u8_m128i(mtx[i]))) ? 1U : 0U) \ + << (i)) + uint16_t res = _sse2neon_static_cast( + uint16_t, (SSE2NEON_UMAXV_MATCH(0) | SSE2NEON_UMAXV_MATCH(1) | + SSE2NEON_UMAXV_MATCH(2) | SSE2NEON_UMAXV_MATCH(3) | + SSE2NEON_UMAXV_MATCH(4) | SSE2NEON_UMAXV_MATCH(5) | + SSE2NEON_UMAXV_MATCH(6) | SSE2NEON_UMAXV_MATCH(7) | + SSE2NEON_UMAXV_MATCH(8) | SSE2NEON_UMAXV_MATCH(9) | + SSE2NEON_UMAXV_MATCH(10) | SSE2NEON_UMAXV_MATCH(11) | + SSE2NEON_UMAXV_MATCH(12) | SSE2NEON_UMAXV_MATCH(13) | + SSE2NEON_UMAXV_MATCH(14) | SSE2NEON_UMAXV_MATCH(15)) & + 0xFFFFu); +#undef SSE2NEON_UMAXV_MATCH +#else + /* ARMv7: Use OR-based horizontal reduction (faster than vpmax cascade). + * The _sse2neon_any_nonzero_u8x16 helper uses 3 OR ops vs 4 vpmax ops. + */ + uint16_t res = 0; + for (int j = 0; j < 16; j++) { + uint8x16_t masked = vandq_u8(vec, vreinterpretq_u8_m128i(mtx[j])); + res |= (_sse2neon_any_nonzero_u8x16(masked) ? 1U : 0U) << j; + } +#endif + /* Mask result to valid range based on lb */ + return res & _sse2neon_static_cast(uint16_t, (1 << lb) - 1); +} + +static uint16_t _sse2neon_aggregate_equal_any_16x8(int la, + int lb, + __m128i mtx[16]) +{ + uint16_t m = _sse2neon_static_cast(uint16_t, 1 << la) - 1; + uint16x8_t vec = + vtstq_u16(vdupq_n_u16(m), vld1q_u16(_sse2neon_cmpestr_mask16b)); + + /* Process all 8 rows in parallel for 16-bit word mode. + * Result bit j = 1 if any element in row j matches. + */ +#if SSE2NEON_ARCH_AARCH64 + /* AArch64: Use vmaxvq for horizontal max */ +#define SSE2NEON_UMAXV_MATCH16(i) \ + ((vmaxvq_u16(vandq_u16(vec, vreinterpretq_u16_m128i(mtx[i]))) ? 1U : 0U) \ + << (i)) + uint16_t res = _sse2neon_static_cast( + uint16_t, (SSE2NEON_UMAXV_MATCH16(0) | SSE2NEON_UMAXV_MATCH16(1) | + SSE2NEON_UMAXV_MATCH16(2) | SSE2NEON_UMAXV_MATCH16(3) | + SSE2NEON_UMAXV_MATCH16(4) | SSE2NEON_UMAXV_MATCH16(5) | + SSE2NEON_UMAXV_MATCH16(6) | SSE2NEON_UMAXV_MATCH16(7)) & + 0xFFu); +#undef SSE2NEON_UMAXV_MATCH16 +#else + /* ARMv7: Use OR-based horizontal reduction */ + uint16_t res = 0; + for (int j = 0; j < 8; j++) { + uint16x8_t masked = vandq_u16(vec, vreinterpretq_u16_m128i(mtx[j])); + res |= (_sse2neon_any_nonzero_u16x8(masked) ? 1U : 0U) << j; + } +#endif + /* Mask result to valid range based on lb */ + return res & _sse2neon_static_cast(uint16_t, (1 << lb) - 1); +} + +/* clang-format off */ +#define SSE2NEON_GENERATE_CMP_EQUAL_ANY(prefix) \ + prefix##IMPL(byte) \ + prefix##IMPL(word) +/* clang-format on */ + +SSE2NEON_GENERATE_CMP_EQUAL_ANY(SSE2NEON_CMP_EQUAL_ANY_) + +static uint16_t _sse2neon_aggregate_ranges_16x8(int la, int lb, __m128i mtx[16]) +{ + uint16_t m = _sse2neon_static_cast(uint16_t, 1 << la) - 1; + uint16x8_t vec = + vtstq_u16(vdupq_n_u16(m), vld1q_u16(_sse2neon_cmpestr_mask16b)); + +#if SSE2NEON_ARCH_AARCH64 + /* Vectorized: process all 8 rows in parallel using vmaxvq. + * For RANGES mode with word elements: + * - Each row has 8 u16 values representing comparisons with 4 range pairs + * - Adjacent u16 elements [2k, 2k+1] form a range: (char >= low, char <= + * high) + * - Result bit j = 1 if any range pair matches for haystack position j + * + * Algorithm per row: + * 1. Mask by la validity: vand(vec, mtx[i]) + * 2. Swap adjacent u16 pairs: vrev32 swaps within each 32-bit lane + * 3. Pair-AND: AND original with swapped to get [m0&m1, m0&m1, ...] + * 4. Horizontal OR via vmaxvq_u16 (faster than vmaxvq_u32) + */ +#define SSE2NEON_RANGES_MATCH16(i) \ + do { \ + uint16x8_t masked = vandq_u16(vec, vreinterpretq_u16_m128i(mtx[i])); \ + uint16x8_t swapped = vrev32q_u16(masked); \ + uint16x8_t pair_and = vandq_u16(masked, swapped); \ + res |= _sse2neon_static_cast(uint16_t, \ + (vmaxvq_u16(pair_and) ? 1U : 0U) << i); \ + } while (0) + + uint16_t res = 0; + SSE2NEON_RANGES_MATCH16(0); + SSE2NEON_RANGES_MATCH16(1); + SSE2NEON_RANGES_MATCH16(2); + SSE2NEON_RANGES_MATCH16(3); + SSE2NEON_RANGES_MATCH16(4); + SSE2NEON_RANGES_MATCH16(5); + SSE2NEON_RANGES_MATCH16(6); + SSE2NEON_RANGES_MATCH16(7); +#undef SSE2NEON_RANGES_MATCH16 + + /* Mask result to valid range based on lb */ + return res & _sse2neon_static_cast(uint16_t, (1 << lb) - 1); +#else + /* ARMv7 fallback: sequential loop */ + uint16_t res = 0; + for (int j = 0; j < lb; j++) { + mtx[j] = vreinterpretq_m128i_u16( + vandq_u16(vec, vreinterpretq_u16_m128i(mtx[j]))); + mtx[j] = vreinterpretq_m128i_u16( + vshrq_n_u16(vreinterpretq_u16_m128i(mtx[j]), 15)); + __m128i tmp = vreinterpretq_m128i_u32( + vshrq_n_u32(vreinterpretq_u32_m128i(mtx[j]), 16)); + uint32x4_t vec_res = vandq_u32(vreinterpretq_u32_m128i(mtx[j]), + vreinterpretq_u32_m128i(tmp)); + uint64x2_t sumh = vpaddlq_u32(vec_res); + uint16_t t = vgetq_lane_u64(sumh, 0) + vgetq_lane_u64(sumh, 1); + res |= (t << j); + } + return res; +#endif +} + +static uint16_t _sse2neon_aggregate_ranges_8x16(int la, int lb, __m128i mtx[16]) +{ + uint16_t m = _sse2neon_static_cast(uint16_t, (1 << la) - 1); + uint8x8_t vec_mask = vld1_u8(_sse2neon_cmpestr_mask8b); + uint8x8_t t_lo = + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, m & 0xff)), vec_mask); + uint8x8_t t_hi = + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, m >> 8)), vec_mask); + uint8x16_t vec = vcombine_u8(t_lo, t_hi); + +#if SSE2NEON_ARCH_AARCH64 + /* Vectorized: process all 16 rows in parallel using vmaxvq. + * For RANGES mode with byte elements: + * - Each row has 16 bytes representing comparisons with 8 range pairs + * - Adjacent bytes [2k, 2k+1] form a range: (char >= low, char <= high) + * - Result bit j = 1 if any range pair matches for haystack position j + * + * Algorithm per row: + * 1. Mask by la validity: vand(vec, mtx[i]) + * 2. Swap adjacent bytes: vrev16 swaps within each 16-bit lane + * 3. Pair-AND: AND original with swapped to get [b0&b1, b0&b1, ...] + * 4. Horizontal OR via vmaxvq_u8 (faster than vmaxvq_u16) + */ +#define SSE2NEON_RANGES_MATCH8(i) \ + do { \ + uint8x16_t masked = vandq_u8(vec, vreinterpretq_u8_m128i(mtx[i])); \ + uint8x16_t swapped = vrev16q_u8(masked); \ + uint8x16_t pair_and = vandq_u8(masked, swapped); \ + res |= _sse2neon_static_cast(uint16_t, (vmaxvq_u8(pair_and) ? 1U : 0U) \ + << i); \ + } while (0) + + uint16_t res = 0; + SSE2NEON_RANGES_MATCH8(0); + SSE2NEON_RANGES_MATCH8(1); + SSE2NEON_RANGES_MATCH8(2); + SSE2NEON_RANGES_MATCH8(3); + SSE2NEON_RANGES_MATCH8(4); + SSE2NEON_RANGES_MATCH8(5); + SSE2NEON_RANGES_MATCH8(6); + SSE2NEON_RANGES_MATCH8(7); + SSE2NEON_RANGES_MATCH8(8); + SSE2NEON_RANGES_MATCH8(9); + SSE2NEON_RANGES_MATCH8(10); + SSE2NEON_RANGES_MATCH8(11); + SSE2NEON_RANGES_MATCH8(12); + SSE2NEON_RANGES_MATCH8(13); + SSE2NEON_RANGES_MATCH8(14); + SSE2NEON_RANGES_MATCH8(15); +#undef SSE2NEON_RANGES_MATCH8 + + /* Mask result to valid range based on lb */ + return res & _sse2neon_static_cast(uint16_t, (1 << lb) - 1); +#else + /* ARMv7 fallback: sequential loop */ + uint16_t res = 0; + for (int j = 0; j < lb; j++) { + mtx[j] = vreinterpretq_m128i_u8( + vandq_u8(vec, vreinterpretq_u8_m128i(mtx[j]))); + mtx[j] = vreinterpretq_m128i_u8( + vshrq_n_u8(vreinterpretq_u8_m128i(mtx[j]), 7)); + __m128i tmp = vreinterpretq_m128i_u16( + vshrq_n_u16(vreinterpretq_u16_m128i(mtx[j]), 8)); + uint16x8_t vec_res = vandq_u16(vreinterpretq_u16_m128i(mtx[j]), + vreinterpretq_u16_m128i(tmp)); + uint16_t t = _sse2neon_vaddvq_u16(vec_res) ? 1 : 0; + res |= (t << j); + } + return res; +#endif +} + +#define SSE2NEON_CMP_RANGES_IS_BYTE 1 +#define SSE2NEON_CMP_RANGES_IS_WORD 0 + +/* clang-format off */ +#define SSE2NEON_GENERATE_CMP_RANGES(prefix) \ + prefix##IMPL(byte, uint, u, prefix##IS_BYTE) \ + prefix##IMPL(byte, int, s, prefix##IS_BYTE) \ + prefix##IMPL(word, uint, u, prefix##IS_WORD) \ + prefix##IMPL(word, int, s, prefix##IS_WORD) +/* clang-format on */ + +SSE2NEON_GENERATE_CMP_RANGES(SSE2NEON_CMP_RANGES_) + +#undef SSE2NEON_CMP_RANGES_IS_BYTE +#undef SSE2NEON_CMP_RANGES_IS_WORD + +static uint16_t _sse2neon_cmp_byte_equal_each(__m128i a, + int la, + __m128i b, + int lb) +{ + uint8x16_t mtx = + vceqq_u8(vreinterpretq_u8_m128i(a), vreinterpretq_u8_m128i(b)); + uint16_t m0 = + _sse2neon_static_cast(uint16_t, (la < lb) ? 0 : (1 << la) - (1 << lb)); + uint16_t m1 = _sse2neon_static_cast(uint16_t, 0x10000 - (1 << la)); + uint16_t tb = _sse2neon_static_cast(uint16_t, 0x10000 - (1 << lb)); + uint8x8_t vec_mask, vec0_lo, vec0_hi, vec1_lo, vec1_hi; + uint8x8_t tmp_lo, tmp_hi, res_lo, res_hi; + vec_mask = vld1_u8(_sse2neon_cmpestr_mask8b); + vec0_lo = vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, m0)), vec_mask); + vec0_hi = + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, m0 >> 8)), vec_mask); + vec1_lo = vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, m1)), vec_mask); + vec1_hi = + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, m1 >> 8)), vec_mask); + tmp_lo = vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, tb)), vec_mask); + tmp_hi = + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, tb >> 8)), vec_mask); + + res_lo = vbsl_u8(vec0_lo, vdup_n_u8(0), vget_low_u8(mtx)); + res_hi = vbsl_u8(vec0_hi, vdup_n_u8(0), vget_high_u8(mtx)); + res_lo = vbsl_u8(vec1_lo, tmp_lo, res_lo); + res_hi = vbsl_u8(vec1_hi, tmp_hi, res_hi); + res_lo = vand_u8(res_lo, vec_mask); + res_hi = vand_u8(res_hi, vec_mask); + + return _sse2neon_vaddv_u8(res_lo) + + _sse2neon_static_cast(uint16_t, _sse2neon_vaddv_u8(res_hi) << 8); +} + +static uint16_t _sse2neon_cmp_word_equal_each(__m128i a, + int la, + __m128i b, + int lb) +{ + uint16x8_t mtx = + vceqq_u16(vreinterpretq_u16_m128i(a), vreinterpretq_u16_m128i(b)); + uint16_t m0 = _sse2neon_static_cast( + uint16_t, (la < lb) ? 0 : ((1 << la) - (1 << lb))); + uint16_t m1 = _sse2neon_static_cast(uint16_t, 0x100 - (1 << la)); + uint16_t tb = _sse2neon_static_cast(uint16_t, 0x100 - (1 << lb)); + uint16x8_t vec_mask = vld1q_u16(_sse2neon_cmpestr_mask16b); + uint16x8_t vec0 = vtstq_u16(vdupq_n_u16(m0), vec_mask); + uint16x8_t vec1 = vtstq_u16(vdupq_n_u16(m1), vec_mask); + uint16x8_t tmp = vtstq_u16(vdupq_n_u16(tb), vec_mask); + mtx = vbslq_u16(vec0, vdupq_n_u16(0), mtx); + mtx = vbslq_u16(vec1, tmp, mtx); + mtx = vandq_u16(mtx, vec_mask); + return _sse2neon_vaddvq_u16(mtx); +} + +/* EQUAL_ORDERED aggregation for 8x16 (byte mode). + * The algorithm checks where string a appears in string b. + * For result bit i: AND together mtx[i][0] & mtx[i+1][1] & mtx[i+2][2] & ... + * + * Vectorization approach: transpose matrix FIRST, then apply masking to + * transposed matrix, then use vextq diagonal extraction. + * After transpose: mtx_T[j][i] = mtx[i][j] = (a[j] == b[i]) + * vextq on mtx_T gives: result[i] = mtx_T[0][i] & mtx_T[1][i+1] & ... + * = mtx[i][0] & mtx[i+1][1] & ... (correct!) + */ +static uint16_t _sse2neon_aggregate_equal_ordered_8x16(int bound, + int la, + int lb, + __m128i mtx[16]) +{ +#if SSE2NEON_ARCH_AARCH64 + uint8x16_t rows[16]; + for (int i = 0; i < 16; i++) + rows[i] = vreinterpretq_u8_m128i(mtx[i]); + + /* Transpose the 16x16 byte matrix using hierarchical vtrn operations. + * After transpose: rows[j][i] = original mtx[i][j] + */ + /* Level 1: Transpose 2x2 blocks of 8-bit elements */ + for (int i = 0; i < 16; i += 2) { + uint8x16x2_t t = vtrnq_u8(rows[i], rows[i + 1]); + rows[i] = t.val[0]; + rows[i + 1] = t.val[1]; + } + + /* Level 2: Transpose 2x2 blocks of 16-bit elements */ + for (int i = 0; i < 16; i += 4) { + uint16x8x2_t t0 = vtrnq_u16(vreinterpretq_u16_u8(rows[i]), + vreinterpretq_u16_u8(rows[i + 2])); + uint16x8x2_t t1 = vtrnq_u16(vreinterpretq_u16_u8(rows[i + 1]), + vreinterpretq_u16_u8(rows[i + 3])); + rows[i] = vreinterpretq_u8_u16(t0.val[0]); + rows[i + 2] = vreinterpretq_u8_u16(t0.val[1]); + rows[i + 1] = vreinterpretq_u8_u16(t1.val[0]); + rows[i + 3] = vreinterpretq_u8_u16(t1.val[1]); + } + + /* Level 3: Transpose 2x2 blocks of 32-bit elements */ + for (int i = 0; i < 16; i += 8) { + uint32x4x2_t t0 = vtrnq_u32(vreinterpretq_u32_u8(rows[i]), + vreinterpretq_u32_u8(rows[i + 4])); + uint32x4x2_t t1 = vtrnq_u32(vreinterpretq_u32_u8(rows[i + 1]), + vreinterpretq_u32_u8(rows[i + 5])); + uint32x4x2_t t2 = vtrnq_u32(vreinterpretq_u32_u8(rows[i + 2]), + vreinterpretq_u32_u8(rows[i + 6])); + uint32x4x2_t t3 = vtrnq_u32(vreinterpretq_u32_u8(rows[i + 3]), + vreinterpretq_u32_u8(rows[i + 7])); + rows[i] = vreinterpretq_u8_u32(t0.val[0]); + rows[i + 4] = vreinterpretq_u8_u32(t0.val[1]); + rows[i + 1] = vreinterpretq_u8_u32(t1.val[0]); + rows[i + 5] = vreinterpretq_u8_u32(t1.val[1]); + rows[i + 2] = vreinterpretq_u8_u32(t2.val[0]); + rows[i + 6] = vreinterpretq_u8_u32(t2.val[1]); + rows[i + 3] = vreinterpretq_u8_u32(t3.val[0]); + rows[i + 7] = vreinterpretq_u8_u32(t3.val[1]); + } + + /* Level 4: Swap 64-bit halves between row pairs */ + { + uint8x16_t tmp; +#define SSE2NEON_SWAP_HL_8(a, b) \ + tmp = vcombine_u8(vget_low_u8(a), vget_low_u8(b)); \ + b = vcombine_u8(vget_high_u8(a), vget_high_u8(b)); \ + a = tmp; + + SSE2NEON_SWAP_HL_8(rows[0], rows[8]); + SSE2NEON_SWAP_HL_8(rows[1], rows[9]); + SSE2NEON_SWAP_HL_8(rows[2], rows[10]); + SSE2NEON_SWAP_HL_8(rows[3], rows[11]); + SSE2NEON_SWAP_HL_8(rows[4], rows[12]); + SSE2NEON_SWAP_HL_8(rows[5], rows[13]); + SSE2NEON_SWAP_HL_8(rows[6], rows[14]); + SSE2NEON_SWAP_HL_8(rows[7], rows[15]); +#undef SSE2NEON_SWAP_HL_8 + } + + /* Apply masking to TRANSPOSED matrix: + * - Rows j >= la: set entire row to 0xFF (needle positions beyond la) + * - For rows j < la: columns k >= lb set to 0x00 (force AND fail for + * positions that would access haystack beyond lb) + * + * lb_valid has bits set for valid positions (0..lb-1) + * lb_clear has 0xFF for positions < lb, 0x00 for positions >= lb + */ + uint8x16_t vec_ff = vdupq_n_u8(0xFF); + uint16_t lb_valid = + _sse2neon_static_cast(uint16_t, (1U << lb) - 1); /* e.g. lb=6: 0x003F */ + uint8x8_t pos_mask = vld1_u8(_sse2neon_cmpestr_mask8b); + uint8x16_t lb_clear = vcombine_u8( + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, lb_valid)), pos_mask), + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, lb_valid >> 8)), + pos_mask)); + + for (int j = 0; j < la; j++) { + rows[j] = vandq_u8(rows[j], lb_clear); /* clear positions >= lb */ + } + for (int j = la; j < 16; j++) { + rows[j] = vec_ff; + } + + /* vextq diagonal extraction: shift row k by k, then AND all rows. + * result[i] = rows[0][i] & rows[1][i+1] & rows[2][i+2] & ... + */ + uint8x16_t result = vec_ff; + +/* Shift row K by K positions, filling with 0xFF, then AND into result */ +#define SSE2NEON_VEXT_AND_8(K) \ + do { \ + uint8x16_t shifted = vextq_u8(rows[K], vec_ff, K); \ + result = vandq_u8(result, shifted); \ + } while (0) + + SSE2NEON_VEXT_AND_8(0); + SSE2NEON_VEXT_AND_8(1); + SSE2NEON_VEXT_AND_8(2); + SSE2NEON_VEXT_AND_8(3); + SSE2NEON_VEXT_AND_8(4); + SSE2NEON_VEXT_AND_8(5); + SSE2NEON_VEXT_AND_8(6); + SSE2NEON_VEXT_AND_8(7); + SSE2NEON_VEXT_AND_8(8); + SSE2NEON_VEXT_AND_8(9); + SSE2NEON_VEXT_AND_8(10); + SSE2NEON_VEXT_AND_8(11); + SSE2NEON_VEXT_AND_8(12); + SSE2NEON_VEXT_AND_8(13); + SSE2NEON_VEXT_AND_8(14); + SSE2NEON_VEXT_AND_8(15); + +#undef SSE2NEON_VEXT_AND_8 + + /* Convert result to bitmask: each lane is 0xFF (match) or 0x00 (no match). + * Extract MSB of each byte to form 16-bit result using _mm_movemask_epi8 + * approach: shift right to get MSB in LSB, position each bit, sum halves. + */ + uint8x16_t msbs = vshrq_n_u8(result, 7); + static const int8_t shift_table[16] = {0, 1, 2, 3, 4, 5, 6, 7, + 0, 1, 2, 3, 4, 5, 6, 7}; + int8x16_t shifts = vld1q_s8(shift_table); + uint8x16_t positioned = vshlq_u8(msbs, shifts); + return _sse2neon_static_cast(uint16_t, + vaddv_u8(vget_low_u8(positioned)) | + (vaddv_u8(vget_high_u8(positioned)) << 8)); +#else + /* ARMv7 fallback: apply masking and use scalar extraction */ + uint16_t m1 = _sse2neon_static_cast(uint16_t, 0x10000 - (1 << la)); + uint8x8_t vec_mask = vld1_u8(_sse2neon_cmpestr_mask8b); + uint8x16_t vec1 = vcombine_u8( + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, m1)), vec_mask), + vtst_u8(vdup_n_u8(_sse2neon_static_cast(uint8_t, m1 >> 8)), vec_mask)); + uint8x16_t vec_minusone = vdupq_n_u8(0xFF); + uint8x16_t vec_zero = vdupq_n_u8(0); + + for (int j = 0; j < lb; j++) { + mtx[j] = vreinterpretq_m128i_u8( + vbslq_u8(vec1, vec_minusone, vreinterpretq_u8_m128i(mtx[j]))); + } + for (int j = lb; j < bound; j++) { + mtx[j] = vreinterpretq_m128i_u8(vbslq_u8(vec1, vec_minusone, vec_zero)); + } + + uint16_t res = 0; + unsigned char *ptr = _sse2neon_reinterpret_cast(unsigned char *, mtx); + for (int i = 0; i < bound; i++) { + int val = 1; + for (int j = 0, k = i; j < bound - i && k < bound; j++, k++) + val &= ptr[k * bound + j]; + res += _sse2neon_static_cast(uint16_t, val << i); + } + return res; +#endif +} + +/* EQUAL_ORDERED aggregation for 16x8 (word mode). + * Same algorithm as 8x16 but for 16-bit elements with 8 lanes. + * + * Vectorization approach: transpose matrix FIRST, then apply masking to + * transposed matrix, then use vextq diagonal extraction. + */ +static uint16_t _sse2neon_aggregate_equal_ordered_16x8(int bound, + int la, + int lb, + __m128i mtx[16]) +{ +#if SSE2NEON_ARCH_AARCH64 + uint16x8_t rows[8]; + for (int i = 0; i < 8; i++) + rows[i] = vreinterpretq_u16_m128i(mtx[i]); + + /* Transpose the 8x8 word matrix using hierarchical vtrn operations. + * After transpose: rows[j][i] = original mtx[i][j] + */ + /* Level 1: Transpose 2x2 blocks of 16-bit elements */ + for (int i = 0; i < 8; i += 2) { + uint16x8x2_t t = vtrnq_u16(rows[i], rows[i + 1]); + rows[i] = t.val[0]; + rows[i + 1] = t.val[1]; + } + + /* Level 2: Transpose 2x2 blocks of 32-bit elements */ + for (int i = 0; i < 8; i += 4) { + uint32x4x2_t t0 = vtrnq_u32(vreinterpretq_u32_u16(rows[i]), + vreinterpretq_u32_u16(rows[i + 2])); + uint32x4x2_t t1 = vtrnq_u32(vreinterpretq_u32_u16(rows[i + 1]), + vreinterpretq_u32_u16(rows[i + 3])); + rows[i] = vreinterpretq_u16_u32(t0.val[0]); + rows[i + 2] = vreinterpretq_u16_u32(t0.val[1]); + rows[i + 1] = vreinterpretq_u16_u32(t1.val[0]); + rows[i + 3] = vreinterpretq_u16_u32(t1.val[1]); + } + + /* Level 3: Swap 64-bit halves between row pairs */ + { + uint16x8_t tmp; +#define SSE2NEON_SWAP_HL_16(a, b) \ + tmp = vcombine_u16(vget_low_u16(a), vget_low_u16(b)); \ + b = vcombine_u16(vget_high_u16(a), vget_high_u16(b)); \ + a = tmp; + + SSE2NEON_SWAP_HL_16(rows[0], rows[4]); + SSE2NEON_SWAP_HL_16(rows[1], rows[5]); + SSE2NEON_SWAP_HL_16(rows[2], rows[6]); + SSE2NEON_SWAP_HL_16(rows[3], rows[7]); +#undef SSE2NEON_SWAP_HL_16 + } + + /* Apply masking to TRANSPOSED matrix: + * - Rows j >= la: set entire row to 0xFFFF + * - For rows j < la: columns k >= lb set to 0x0000 + */ + uint16x8_t vec_ff = vdupq_n_u16(0xFFFF); + uint16_t lb_valid = + _sse2neon_static_cast(uint16_t, (1U << lb) - 1); /* e.g. lb=6: 0x003F */ + uint16x8_t pos_mask = vld1q_u16(_sse2neon_cmpestr_mask16b); + uint16x8_t lb_clear = vtstq_u16(vdupq_n_u16(lb_valid), pos_mask); + + for (int j = 0; j < la; j++) { + rows[j] = vandq_u16(rows[j], lb_clear); + } + for (int j = la; j < 8; j++) { + rows[j] = vec_ff; + } + + /* vextq diagonal extraction: shift row k by k, then AND all rows */ + uint16x8_t result = vec_ff; + +#define SSE2NEON_VEXT_AND_16(K) \ + do { \ + uint16x8_t shifted = vextq_u16(rows[K], vec_ff, K); \ + result = vandq_u16(result, shifted); \ + } while (0) + + SSE2NEON_VEXT_AND_16(0); + SSE2NEON_VEXT_AND_16(1); + SSE2NEON_VEXT_AND_16(2); + SSE2NEON_VEXT_AND_16(3); + SSE2NEON_VEXT_AND_16(4); + SSE2NEON_VEXT_AND_16(5); + SSE2NEON_VEXT_AND_16(6); + SSE2NEON_VEXT_AND_16(7); + +#undef SSE2NEON_VEXT_AND_16 + + /* Convert result to bitmask: each lane is 0xFFFF or 0x0000. + * Extract MSB of each word and form 8-bit result. + */ + uint16x8_t msbs = vshrq_n_u16(result, 15); + uint16x8_t positioned = vmulq_u16(msbs, pos_mask); + return _sse2neon_static_cast(uint16_t, _sse2neon_vaddvq_u16(positioned)); +#else + /* ARMv7 fallback: apply masking and use scalar extraction */ + uint16_t m1 = _sse2neon_static_cast(uint16_t, 0x100 - (1 << la)); + uint16x8_t vec_mask = vld1q_u16(_sse2neon_cmpestr_mask16b); + uint16x8_t vec1 = vtstq_u16(vdupq_n_u16(m1), vec_mask); + uint16x8_t vec_minusone = vdupq_n_u16(0xFFFF); + uint16x8_t vec_zero = vdupq_n_u16(0); + + for (int j = 0; j < lb; j++) { + mtx[j] = vreinterpretq_m128i_u16( + vbslq_u16(vec1, vec_minusone, vreinterpretq_u16_m128i(mtx[j]))); + } + for (int j = lb; j < bound; j++) { + mtx[j] = + vreinterpretq_m128i_u16(vbslq_u16(vec1, vec_minusone, vec_zero)); + } + + uint16_t res = 0; + unsigned short *ptr = _sse2neon_reinterpret_cast(unsigned short *, mtx); + for (int i = 0; i < bound; i++) { + int val = 1; + for (int j = 0, k = i; j < bound - i && k < bound; j++, k++) + val &= ptr[k * bound + j]; + res += _sse2neon_static_cast(uint16_t, val << i); + } + return res; +#endif +} + +/* clang-format off */ +#define SSE2NEON_GENERATE_CMP_EQUAL_ORDERED(prefix) \ + prefix##IMPL(byte) \ + prefix##IMPL(word) +/* clang-format on */ + +SSE2NEON_GENERATE_CMP_EQUAL_ORDERED(SSE2NEON_CMP_EQUAL_ORDERED_) + +#define SSE2NEON_CMPESTR_LIST \ + _SSE2NEON(CMP_UBYTE_EQUAL_ANY, cmp_byte_equal_any) \ + _SSE2NEON(CMP_UWORD_EQUAL_ANY, cmp_word_equal_any) \ + _SSE2NEON(CMP_SBYTE_EQUAL_ANY, cmp_byte_equal_any) \ + _SSE2NEON(CMP_SWORD_EQUAL_ANY, cmp_word_equal_any) \ + _SSE2NEON(CMP_UBYTE_RANGES, cmp_ubyte_ranges) \ + _SSE2NEON(CMP_UWORD_RANGES, cmp_uword_ranges) \ + _SSE2NEON(CMP_SBYTE_RANGES, cmp_sbyte_ranges) \ + _SSE2NEON(CMP_SWORD_RANGES, cmp_sword_ranges) \ + _SSE2NEON(CMP_UBYTE_EQUAL_EACH, cmp_byte_equal_each) \ + _SSE2NEON(CMP_UWORD_EQUAL_EACH, cmp_word_equal_each) \ + _SSE2NEON(CMP_SBYTE_EQUAL_EACH, cmp_byte_equal_each) \ + _SSE2NEON(CMP_SWORD_EQUAL_EACH, cmp_word_equal_each) \ + _SSE2NEON(CMP_UBYTE_EQUAL_ORDERED, cmp_byte_equal_ordered) \ + _SSE2NEON(CMP_UWORD_EQUAL_ORDERED, cmp_word_equal_ordered) \ + _SSE2NEON(CMP_SBYTE_EQUAL_ORDERED, cmp_byte_equal_ordered) \ + _SSE2NEON(CMP_SWORD_EQUAL_ORDERED, cmp_word_equal_ordered) + +enum { +#define _SSE2NEON(name, func_suffix) name, + SSE2NEON_CMPESTR_LIST +#undef _SSE2NEON +}; +typedef uint16_t (*cmpestr_func_t)(__m128i a, int la, __m128i b, int lb); +static cmpestr_func_t _sse2neon_cmpfunc_table[] = { +#define _SSE2NEON(name, func_suffix) _sse2neon_##func_suffix, + SSE2NEON_CMPESTR_LIST +#undef _SSE2NEON +}; + +FORCE_INLINE uint16_t _sse2neon_sido_negative(int res, + int lb, + int imm8, + int bound) +{ + switch (imm8 & 0x30) { + case _SIDD_NEGATIVE_POLARITY: + res ^= 0xffffffff; + break; + case _SIDD_MASKED_POSITIVE_POLARITY: + res &= (1 << lb) - 1; + break; + case _SIDD_MASKED_NEGATIVE_POLARITY: + res ^= (1 << lb) - 1; + break; + default: + break; + } + + return _sse2neon_static_cast(uint16_t, res &((bound == 8) ? 0xFF : 0xFFFF)); +} + +FORCE_INLINE int _sse2neon_clz(unsigned int x) +{ +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG + unsigned long cnt = 0; + if (_BitScanReverse(&cnt, x)) + return 31 - cnt; + return 32; +#else + return x != 0 ? __builtin_clz(x) : 32; +#endif +} + +FORCE_INLINE int _sse2neon_ctz(unsigned int x) +{ +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG + unsigned long cnt = 0; + if (_BitScanForward(&cnt, x)) + return cnt; + return 32; +#else + return x != 0 ? __builtin_ctz(x) : 32; +#endif +} + +FORCE_INLINE int _sse2neon_ctzll(unsigned long long x) +{ +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG + unsigned long cnt; +#if defined(SSE2NEON_HAS_BITSCAN64) + if (_BitScanForward64(&cnt, x)) + return (int) (cnt); +#else + if (_BitScanForward(&cnt, (unsigned long) (x))) + return (int) cnt; + if (_BitScanForward(&cnt, (unsigned long) (x >> 32))) + return (int) (cnt + 32); +#endif /* SSE2NEON_HAS_BITSCAN64 */ + return 64; +#else /* assume GNU compatible compilers */ + return x != 0 ? __builtin_ctzll(x) : 64; +#endif +} + +#define SSE2NEON_MIN(x, y) (x) < (y) ? (x) : (y) + +#define SSE2NEON_CMPSTR_SET_UPPER(var, imm) \ + const int var = ((imm) & 0x01) ? 8 : 16 + +#define SSE2NEON_CMPESTRX_LEN_PAIR(a, b, la, lb) \ + int tmp1 = la ^ (la >> 31); \ + la = tmp1 - (la >> 31); \ + int tmp2 = lb ^ (lb >> 31); \ + lb = tmp2 - (lb >> 31); \ + la = SSE2NEON_MIN(la, bound); \ + lb = SSE2NEON_MIN(lb, bound) + +// Compare all pairs of character in string a and b, +// then aggregate the result. +// As the only difference of PCMPESTR* and PCMPISTR* is the way to calculate the +// length of string, we use SSE2NEON_CMP{I,E}STRX_GET_LEN to get the length of +// string a and b. +#define SSE2NEON_COMP_AGG(a, b, la, lb, imm8, IE) \ + SSE2NEON_CMPSTR_SET_UPPER(bound, imm8); \ + SSE2NEON_##IE##_LEN_PAIR(a, b, la, lb); \ + uint16_t r2 = (_sse2neon_cmpfunc_table[(imm8) & 0x0f])(a, la, b, lb); \ + r2 = _sse2neon_sido_negative(r2, lb, imm8, bound) + +#define SSE2NEON_CMPSTR_GENERATE_INDEX(r2, bound, imm8) \ + return (r2 == 0) ? bound \ + : (((imm8) & 0x40) ? (31 - _sse2neon_clz(r2)) \ + : _sse2neon_ctz(r2)) + +#define SSE2NEON_CMPSTR_GENERATE_MASK(dst) \ + __m128i dst = vreinterpretq_m128i_u8(vdupq_n_u8(0)); \ + if ((imm8) & 0x40) { \ + if (bound == 8) { \ + uint16x8_t tmp = vtstq_u16(vdupq_n_u16(r2), \ + vld1q_u16(_sse2neon_cmpestr_mask16b)); \ + dst = vreinterpretq_m128i_u16(vbslq_u16( \ + tmp, vdupq_n_u16(_sse2neon_static_cast(uint16_t, -1)), \ + vreinterpretq_u16_m128i(dst))); \ + } else { \ + uint8x16_t vec_r2 = vcombine_u8( \ + vdup_n_u8(_sse2neon_static_cast(uint8_t, r2)), \ + vdup_n_u8(_sse2neon_static_cast(uint8_t, r2 >> 8))); \ + uint8x16_t tmp = \ + vtstq_u8(vec_r2, vld1q_u8(_sse2neon_cmpestr_mask8b)); \ + dst = vreinterpretq_m128i_u8( \ + vbslq_u8(tmp, vdupq_n_u8(_sse2neon_static_cast(uint8_t, -1)), \ + vreinterpretq_u8_m128i(dst))); \ + } \ + } else { \ + if (bound == 16) { \ + dst = vreinterpretq_m128i_u16( \ + vsetq_lane_u16(r2 & 0xffff, vreinterpretq_u16_m128i(dst), 0)); \ + } else { \ + dst = vreinterpretq_m128i_u8( \ + vsetq_lane_u8(_sse2neon_static_cast(uint8_t, r2 & 0xff), \ + vreinterpretq_u8_m128i(dst), 0)); \ + } \ + } \ + return dst + +// Compare packed strings in a and b with lengths la and lb using the control +// in imm8, and returns 1 if b did not contain a null character and the +// resulting mask was zero, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestra +FORCE_INLINE int _mm_cmpestra(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + int lb_cpy = lb; + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPESTRX); + return !r2 & (lb_cpy >= bound); +} + +// Compare packed strings in a and b with lengths la and lb using the control in +// imm8, and returns 1 if the resulting mask was non-zero, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestrc +FORCE_INLINE int _mm_cmpestrc(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPESTRX); + return r2 != 0; +} + +// Compare packed strings in a and b with lengths la and lb using the control +// in imm8, and store the generated index in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestri +FORCE_INLINE int _mm_cmpestri(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPESTRX); + SSE2NEON_CMPSTR_GENERATE_INDEX(r2, bound, imm8); +} + +// Compare packed strings in a and b with lengths la and lb using the control +// in imm8, and store the generated mask in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestrm +FORCE_INLINE __m128i +_mm_cmpestrm(__m128i a, int la, __m128i b, int lb, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPESTRX); + SSE2NEON_CMPSTR_GENERATE_MASK(dst); +} + +// Compare packed strings in a and b with lengths la and lb using the control in +// imm8, and returns bit 0 of the resulting bit mask. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestro +FORCE_INLINE int _mm_cmpestro(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPESTRX); + return r2 & 1; +} + +// Compare packed strings in a and b with lengths la and lb using the control in +// imm8, and returns 1 if any character in a was null, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestrs +FORCE_INLINE int _mm_cmpestrs(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + (void) a; + (void) b; + (void) lb; + SSE2NEON_CMPSTR_SET_UPPER(bound, imm8); + return la <= (bound - 1); +} + +// Compare packed strings in a and b with lengths la and lb using the control in +// imm8, and returns 1 if any character in b was null, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestrz +FORCE_INLINE int _mm_cmpestrz(__m128i a, + int la, + __m128i b, + int lb, + const int imm8) +{ + (void) a; + (void) b; + (void) la; + SSE2NEON_CMPSTR_SET_UPPER(bound, imm8); + return lb <= (bound - 1); +} + +#define SSE2NEON_CMPISTRX_LENGTH(str, len, imm8) \ + do { \ + if ((imm8) & 0x01) { \ + uint16x8_t equal_mask_##str = \ + vceqq_u16(vreinterpretq_u16_m128i(str), vdupq_n_u16(0)); \ + uint8x8_t res_##str = vshrn_n_u16(equal_mask_##str, 4); \ + uint64_t matches_##str = \ + vget_lane_u64(vreinterpret_u64_u8(res_##str), 0); \ + len = _sse2neon_ctzll(matches_##str) >> 3; \ + } else { \ + uint16x8_t equal_mask_##str = vreinterpretq_u16_u8( \ + vceqq_u8(vreinterpretq_u8_m128i(str), vdupq_n_u8(0))); \ + uint8x8_t res_##str = vshrn_n_u16(equal_mask_##str, 4); \ + uint64_t matches_##str = \ + vget_lane_u64(vreinterpret_u64_u8(res_##str), 0); \ + len = _sse2neon_ctzll(matches_##str) >> 2; \ + } \ + } while (0) + +#define SSE2NEON_CMPISTRX_LEN_PAIR(a, b, la, lb) \ + int la, lb; \ + do { \ + SSE2NEON_CMPISTRX_LENGTH(a, la, imm8); \ + SSE2NEON_CMPISTRX_LENGTH(b, lb, imm8); \ + } while (0) + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and returns 1 if b did not contain a null character and the resulting +// mask was zero, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistra +FORCE_INLINE int _mm_cmpistra(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPISTRX); + return !r2 & (lb >= bound); +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and returns 1 if the resulting mask was non-zero, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistrc +FORCE_INLINE int _mm_cmpistrc(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPISTRX); + return r2 != 0; +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and store the generated index in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistri +FORCE_INLINE int _mm_cmpistri(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPISTRX); + SSE2NEON_CMPSTR_GENERATE_INDEX(r2, bound, imm8); +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and store the generated mask in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistrm +FORCE_INLINE __m128i _mm_cmpistrm(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPISTRX); + SSE2NEON_CMPSTR_GENERATE_MASK(dst); +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and returns bit 0 of the resulting bit mask. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistro +FORCE_INLINE int _mm_cmpistro(__m128i a, __m128i b, const int imm8) +{ + SSE2NEON_COMP_AGG(a, b, la, lb, imm8, CMPISTRX); + return r2 & 1; +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and returns 1 if any character in a was null, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistrs +FORCE_INLINE int _mm_cmpistrs(__m128i a, __m128i b, const int imm8) +{ + (void) b; + SSE2NEON_CMPSTR_SET_UPPER(bound, imm8); + int la; + SSE2NEON_CMPISTRX_LENGTH(a, la, imm8); + return la <= (bound - 1); +} + +// Compare packed strings with implicit lengths in a and b using the control in +// imm8, and returns 1 if any character in b was null, and 0 otherwise. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpistrz +FORCE_INLINE int _mm_cmpistrz(__m128i a, __m128i b, const int imm8) +{ + (void) a; + SSE2NEON_CMPSTR_SET_UPPER(bound, imm8); + int lb; + SSE2NEON_CMPISTRX_LENGTH(b, lb, imm8); + return lb <= (bound - 1); +} + +// Compares the 2 signed 64-bit integers in a and the 2 signed 64-bit integers +// in b for greater than. +FORCE_INLINE __m128i _mm_cmpgt_epi64(__m128i a, __m128i b) +{ +#if SSE2NEON_ARCH_AARCH64 + return vreinterpretq_m128i_u64( + vcgtq_s64(vreinterpretq_s64_m128i(a), vreinterpretq_s64_m128i(b))); +#else + return vreinterpretq_m128i_s64(vshrq_n_s64( + vqsubq_s64(vreinterpretq_s64_m128i(b), vreinterpretq_s64_m128i(a)), + 63)); +#endif +} + +/* A function-like macro to generate CRC-32C calculation using Barrett + * reduction. + * + * The input parameters depict as follows: + * - 'crc' means initial value or CRC. + * - 'v' means the element of input message. + * - 'bit' means the element size of input message (e.g., if each message is one + * byte then 'bit' will be 8 as 1 byte equals 8 bits. + * - 'shift' represents a toggle to perform shifting. + * + * For a reminder, the CRC calculation uses bit-reflected sense. + * + * As there are two mysterious variables 'p' and 'mu', here are what they serve: + * 1. 'p' stands for Polynomial P(x) in CRC calculation. + * As we are using CRC-32C, 'p' has the value of 0x105EC76F1 (0x1EDC6F41 in + * bit-reflected form). + * 2. 'mu' stands for the multiplicative inverse of 'p' in GF(64). + * 'mu' has the value of 0x1dea713f1. + * (mu_{64} = \lfloor 2^{64} / P(x) \rfloor = 0x11f91caf6) + * (the bit-reflected form of 0x11f91caf6 is 0x1dea713f1) + * + * The CRC value is calculated as follows: + * 1. Update (XOR) 'crc' with new input message element 'v'. + * 2. Create 'orig' and 'tmp' vector. + * Before creating the vectors, We store 'crc' in lower half of vector + * then shift left by 'bit' bits so that the result of carry-less + * multiplication will always appear in the upper half of destination vector. + * Doing so can reduce some masking and subtraction operations. + * For one exception is that there is no need to perform shifting if 'bit' + * is 64. + * 3. Do carry-less multiplication on the lower half of 'tmp' with 'mu'. + * 4. Do carry-less multiplication on the upper half of 'tmp' with 'p'. + * 5. Extract the lower (in bit-reflected sense) 32 bits in the upper half of + * 'tmp'. + */ +#define SSE2NEON_CRC32C_BASE(crc, v, bit, shift) \ + do { \ + crc ^= v; \ + uint64x2_t orig = \ + vcombine_u64(_sse2neon_vcreate_u64(SSE2NEON_IIF(shift)( \ + (uint64_t) (crc) << (bit), (uint64_t) (crc))), \ + _sse2neon_vcreate_u64(0x0)); \ + uint64x2_t tmp = orig; \ + uint64_t p = 0x105EC76F1; \ + uint64_t mu = 0x1dea713f1; \ + tmp = \ + _sse2neon_vmull_p64(vget_low_u64(tmp), _sse2neon_vcreate_u64(mu)); \ + tmp = \ + _sse2neon_vmull_p64(vget_high_u64(tmp), _sse2neon_vcreate_u64(p)); \ + crc = vgetq_lane_u32(vreinterpretq_u32_u64(tmp), 2); \ + } while (0) + +// Starting with the initial value in crc, accumulates a CRC32 value for +// unsigned 16-bit integer v, and stores the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_crc32_u16 +FORCE_INLINE uint32_t _mm_crc32_u16(uint32_t crc, uint16_t v) +{ +#if SSE2NEON_ARCH_AARCH64 && defined(__ARM_FEATURE_CRC32) && !SSE2NEON_ARM64EC + __asm__ __volatile__("crc32ch %w[c], %w[c], %w[v]\n\t" + : [c] "+r"(crc) + : [v] "r"(v)); +#elif ((__ARM_ARCH >= 8) && defined(__ARM_FEATURE_CRC32)) || \ + (SSE2NEON_COMPILER_MSVC && defined(_M_ARM64) && !SSE2NEON_ARM64EC && \ + !SSE2NEON_COMPILER_CLANG) + crc = __crc32ch(crc, v); +#elif defined(__ARM_FEATURE_CRYPTO) + SSE2NEON_CRC32C_BASE(crc, v, 16, 1); +#else + crc = _mm_crc32_u8(crc, _sse2neon_static_cast(uint8_t, v & 0xff)); + crc = _mm_crc32_u8(crc, _sse2neon_static_cast(uint8_t, (v >> 8) & 0xff)); +#endif + return crc; +} + +// Starting with the initial value in crc, accumulates a CRC32 value for +// unsigned 32-bit integer v, and stores the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_crc32_u32 +FORCE_INLINE uint32_t _mm_crc32_u32(uint32_t crc, uint32_t v) +{ +#if SSE2NEON_ARCH_AARCH64 && defined(__ARM_FEATURE_CRC32) && !SSE2NEON_ARM64EC + __asm__ __volatile__("crc32cw %w[c], %w[c], %w[v]\n\t" + : [c] "+r"(crc) + : [v] "r"(v)); +#elif ((__ARM_ARCH >= 8) && defined(__ARM_FEATURE_CRC32)) || \ + (SSE2NEON_COMPILER_MSVC && defined(_M_ARM64) && !SSE2NEON_ARM64EC && \ + !SSE2NEON_COMPILER_CLANG) + crc = __crc32cw(crc, v); +#elif defined(__ARM_FEATURE_CRYPTO) + SSE2NEON_CRC32C_BASE(crc, v, 32, 1); +#else + crc = _mm_crc32_u16(crc, _sse2neon_static_cast(uint16_t, v & 0xffff)); + crc = + _mm_crc32_u16(crc, _sse2neon_static_cast(uint16_t, (v >> 16) & 0xffff)); +#endif + return crc; +} + +// Starting with the initial value in crc, accumulates a CRC32 value for +// unsigned 64-bit integer v, and stores the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_crc32_u64 +FORCE_INLINE uint64_t _mm_crc32_u64(uint64_t crc, uint64_t v) +{ +#if SSE2NEON_ARCH_AARCH64 && defined(__ARM_FEATURE_CRC32) && !SSE2NEON_ARM64EC + __asm__ __volatile__("crc32cx %w[c], %w[c], %x[v]\n\t" + : [c] "+r"(crc) + : [v] "r"(v)); +#elif (SSE2NEON_COMPILER_MSVC && defined(_M_ARM64) && !SSE2NEON_ARM64EC && \ + !SSE2NEON_COMPILER_CLANG) + crc = __crc32cd(_sse2neon_static_cast(uint32_t, crc), v); +#elif defined(__ARM_FEATURE_CRYPTO) + SSE2NEON_CRC32C_BASE(crc, v, 64, 0); +#else + crc = _mm_crc32_u32(_sse2neon_static_cast(uint32_t, crc), + _sse2neon_static_cast(uint32_t, v & 0xffffffff)); + crc = + _mm_crc32_u32(_sse2neon_static_cast(uint32_t, crc), + _sse2neon_static_cast(uint32_t, (v >> 32) & 0xffffffff)); +#endif + return crc; +} + +// Starting with the initial value in crc, accumulates a CRC32 value for +// unsigned 8-bit integer v, and stores the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_crc32_u8 +FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t crc, uint8_t v) +{ +#if SSE2NEON_ARCH_AARCH64 && defined(__ARM_FEATURE_CRC32) && !SSE2NEON_ARM64EC + __asm__ __volatile__("crc32cb %w[c], %w[c], %w[v]\n\t" + : [c] "+r"(crc) + : [v] "r"(v)); +#elif ((__ARM_ARCH >= 8) && defined(__ARM_FEATURE_CRC32)) || \ + (SSE2NEON_COMPILER_MSVC && defined(_M_ARM64) && !SSE2NEON_ARM64EC && \ + !SSE2NEON_COMPILER_CLANG) + crc = __crc32cb(crc, v); +#elif defined(__ARM_FEATURE_CRYPTO) + SSE2NEON_CRC32C_BASE(crc, v, 8, 1); +#else // Fall back to the generic table lookup approach + // Adapted from: https://create.stephan-brumme.com/crc32/ + // Apply half-byte comparison algorithm for the best ratio between + // performance and lookup table. + + crc ^= v; + + // The lookup table just needs to store every 16th entry + // of the standard look-up table. + static const uint32_t crc32_half_byte_tbl[] = { + 0x00000000, 0x105ec76f, 0x20bd8ede, 0x30e349b1, 0x417b1dbc, 0x5125dad3, + 0x61c69362, 0x7198540d, 0x82f63b78, 0x92a8fc17, 0xa24bb5a6, 0xb21572c9, + 0xc38d26c4, 0xd3d3e1ab, 0xe330a81a, 0xf36e6f75, + }; + + crc = (crc >> 4) ^ crc32_half_byte_tbl[crc & 0x0F]; + crc = (crc >> 4) ^ crc32_half_byte_tbl[crc & 0x0F]; +#endif + return crc; +} + +/* AES */ + +/* AES software fallback tables. + * Needed when __ARM_FEATURE_CRYPTO is not available, OR on ARM64EC where + * hardware crypto intrinsics may not be accessible despite the feature macro. + */ +#if !defined(__ARM_FEATURE_CRYPTO) || SSE2NEON_ARM64EC || defined(_M_ARM64EC) +/* clang-format off */ +#define SSE2NEON_AES_SBOX(w) \ + { \ + w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), \ + w(0xc5), w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), \ + w(0xab), w(0x76), w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), \ + w(0x59), w(0x47), w(0xf0), w(0xad), w(0xd4), w(0xa2), w(0xaf), \ + w(0x9c), w(0xa4), w(0x72), w(0xc0), w(0xb7), w(0xfd), w(0x93), \ + w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc), w(0x34), w(0xa5), \ + w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15), w(0x04), \ + w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a), \ + w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), \ + w(0x75), w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), \ + w(0x5a), w(0xa0), w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), \ + w(0xe3), w(0x2f), w(0x84), w(0x53), w(0xd1), w(0x00), w(0xed), \ + w(0x20), w(0xfc), w(0xb1), w(0x5b), w(0x6a), w(0xcb), w(0xbe), \ + w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf), w(0xd0), w(0xef), \ + w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85), w(0x45), \ + w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8), \ + w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), \ + w(0xf5), w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), \ + w(0xf3), w(0xd2), w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), \ + w(0x97), w(0x44), w(0x17), w(0xc4), w(0xa7), w(0x7e), w(0x3d), \ + w(0x64), w(0x5d), w(0x19), w(0x73), w(0x60), w(0x81), w(0x4f), \ + w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88), w(0x46), w(0xee), \ + w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb), w(0xe0), \ + w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c), \ + w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), \ + w(0x79), w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), \ + w(0x4e), w(0xa9), w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), \ + w(0x7a), w(0xae), w(0x08), w(0xba), w(0x78), w(0x25), w(0x2e), \ + w(0x1c), w(0xa6), w(0xb4), w(0xc6), w(0xe8), w(0xdd), w(0x74), \ + w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a), w(0x70), w(0x3e), \ + w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e), w(0x61), \ + w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e), \ + w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), \ + w(0x94), w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), \ + w(0x28), w(0xdf), w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), \ + w(0xe6), w(0x42), w(0x68), w(0x41), w(0x99), w(0x2d), w(0x0f), \ + w(0xb0), w(0x54), w(0xbb), w(0x16) \ + } +#define SSE2NEON_AES_RSBOX(w) \ + { \ + w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), \ + w(0x38), w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), \ + w(0xd7), w(0xfb), w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), \ + w(0x2f), w(0xff), w(0x87), w(0x34), w(0x8e), w(0x43), w(0x44), \ + w(0xc4), w(0xde), w(0xe9), w(0xcb), w(0x54), w(0x7b), w(0x94), \ + w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d), w(0xee), w(0x4c), \ + w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e), w(0x08), \ + w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2), \ + w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), \ + w(0x25), w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), \ + w(0x98), w(0x16), w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), \ + w(0x65), w(0xb6), w(0x92), w(0x6c), w(0x70), w(0x48), w(0x50), \ + w(0xfd), w(0xed), w(0xb9), w(0xda), w(0x5e), w(0x15), w(0x46), \ + w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84), w(0x90), w(0xd8), \ + w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a), w(0xf7), \ + w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06), \ + w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), \ + w(0x02), w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), \ + w(0x8a), w(0x6b), w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), \ + w(0x67), w(0xdc), w(0xea), w(0x97), w(0xf2), w(0xcf), w(0xce), \ + w(0xf0), w(0xb4), w(0xe6), w(0x73), w(0x96), w(0xac), w(0x74), \ + w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85), w(0xe2), w(0xf9), \ + w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e), w(0x47), \ + w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89), \ + w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), \ + w(0x1b), w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), \ + w(0x79), w(0x20), w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), \ + w(0xcd), w(0x5a), w(0xf4), w(0x1f), w(0xdd), w(0xa8), w(0x33), \ + w(0x88), w(0x07), w(0xc7), w(0x31), w(0xb1), w(0x12), w(0x10), \ + w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f), w(0x60), w(0x51), \ + w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d), w(0x2d), \ + w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef), \ + w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), \ + w(0xb0), w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), \ + w(0x99), w(0x61), w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), \ + w(0x77), w(0xd6), w(0x26), w(0xe1), w(0x69), w(0x14), w(0x63), \ + w(0x55), w(0x21), w(0x0c), w(0x7d) \ + } +/* clang-format on */ + +/* X Macro trick. See https://en.wikipedia.org/wiki/X_Macro */ +#define SSE2NEON_AES_H0(x) (x) +static const uint8_t _sse2neon_sbox[256] = SSE2NEON_AES_SBOX(SSE2NEON_AES_H0); +static const uint8_t _sse2neon_rsbox[256] = SSE2NEON_AES_RSBOX(SSE2NEON_AES_H0); +#undef SSE2NEON_AES_H0 + +// File-scope constants for AES permutations - hoisted from inline functions +// to ensure single load across multiple intrinsic calls. +// ShiftRows permutation indices for encryption +static const uint8_t ALIGN_STRUCT(16) _sse2neon_aes_shift_rows[16] = { + 0x0, 0x5, 0xa, 0xf, 0x4, 0x9, 0xe, 0x3, + 0x8, 0xd, 0x2, 0x7, 0xc, 0x1, 0x6, 0xb, +}; +// InvShiftRows permutation indices for decryption +static const uint8_t ALIGN_STRUCT(16) _sse2neon_aes_inv_shift_rows[16] = { + 0x0, 0xd, 0xa, 0x7, 0x4, 0x1, 0xe, 0xb, + 0x8, 0x5, 0x2, 0xf, 0xc, 0x9, 0x6, 0x3, +}; +// Rotate right by 8 bits within each 32-bit word (for MixColumns) +static const uint8_t ALIGN_STRUCT(16) _sse2neon_aes_ror32by8[16] = { + 0x1, 0x2, 0x3, 0x0, 0x5, 0x6, 0x7, 0x4, + 0x9, 0xa, 0xb, 0x8, 0xd, 0xe, 0xf, 0xc, +}; + +#if SSE2NEON_ARCH_AARCH64 +// NEON S-box lookup using 4x64-byte tables; reused by aesenc/dec/keygenassist. +// Uses vsubq_u8 instead of C++ operator- for MSVC compatibility. +FORCE_INLINE uint8x16_t _sse2neon_aes_subbytes(uint8x16_t x) +{ + uint8x16_t v = vqtbl4q_u8(_sse2neon_vld1q_u8_x4(_sse2neon_sbox), x); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0x40), + vsubq_u8(x, vdupq_n_u8(0x40))); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0x80), + vsubq_u8(x, vdupq_n_u8(0x80))); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_sbox + 0xc0), + vsubq_u8(x, vdupq_n_u8(0xc0))); + return v; +} + +FORCE_INLINE uint8x16_t _sse2neon_aes_inv_subbytes(uint8x16_t x) +{ + uint8x16_t v = vqtbl4q_u8(_sse2neon_vld1q_u8_x4(_sse2neon_rsbox), x); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_rsbox + 0x40), + vsubq_u8(x, vdupq_n_u8(0x40))); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_rsbox + 0x80), + vsubq_u8(x, vdupq_n_u8(0x80))); + v = vqtbx4q_u8(v, _sse2neon_vld1q_u8_x4(_sse2neon_rsbox + 0xc0), + vsubq_u8(x, vdupq_n_u8(0xc0))); + return v; +} + +// AES xtime: multiply by {02} in GF(2^8) with reduction polynomial 0x11b +// Uses signed comparison to generate mask: if MSB set, XOR with 0x1b +FORCE_INLINE uint8x16_t _sse2neon_aes_xtime(uint8x16_t v) +{ + // Arithmetic right shift by 7 gives 0xFF for bytes >= 0x80, 0x00 otherwise + uint8x16_t mask = + vreinterpretq_u8_s8(vshrq_n_s8(vreinterpretq_s8_u8(v), 7)); + // AND with reduction polynomial 0x1b + uint8x16_t reduced = vandq_u8(mask, vdupq_n_u8(0x1b)); + // Shift left and XOR with reduction + return veorq_u8(vshlq_n_u8(v, 1), reduced); +} +#endif + +/* x_time function and matrix multiply function */ +#if !SSE2NEON_ARCH_AARCH64 +#define SSE2NEON_XT(x) (((x) << 1) ^ ((((x) >> 7) & 1) * 0x1b)) +#define SSE2NEON_MULTIPLY(x, y) \ + (((y & 1) * x) ^ ((y >> 1 & 1) * SSE2NEON_XT(x)) ^ \ + ((y >> 2 & 1) * SSE2NEON_XT(SSE2NEON_XT(x))) ^ \ + ((y >> 3 & 1) * SSE2NEON_XT(SSE2NEON_XT(SSE2NEON_XT(x)))) ^ \ + ((y >> 4 & 1) * SSE2NEON_XT(SSE2NEON_XT(SSE2NEON_XT(SSE2NEON_XT(x)))))) +#endif + +// In the absence of crypto extensions, implement aesenc using regular NEON +// intrinsics instead. See: +// https://www.workofard.com/2017/01/accelerated-aes-for-the-arm64-linux-kernel/ +// https://www.workofard.com/2017/07/ghash-for-low-end-cores/ and +// for more information. +FORCE_INLINE __m128i _mm_aesenc_si128(__m128i a, __m128i RoundKey) +{ +#if SSE2NEON_ARCH_AARCH64 + uint8x16_t v; + uint8x16_t w = vreinterpretq_u8_m128i(a); + + /* shift rows */ + w = vqtbl1q_u8(w, vld1q_u8(_sse2neon_aes_shift_rows)); + + /* sub bytes */ + v = _sse2neon_aes_subbytes(w); + + /* mix columns: + * MixColumns multiplies each column by the matrix: + * [02 03 01 01] + * [01 02 03 01] + * [01 01 02 03] + * [03 01 01 02] + * Using: out = xtime(v) ^ ror8(xtime(v)^v) ^ rot16(v) + */ + w = _sse2neon_aes_xtime(v); // w = v * {02} + w = veorq_u8(w, vreinterpretq_u8_u16(vrev32q_u16(vreinterpretq_u16_u8(v)))); + w = veorq_u8(w, + vqtbl1q_u8(veorq_u8(v, w), vld1q_u8(_sse2neon_aes_ror32by8))); + + /* add round key */ + return vreinterpretq_m128i_u8( + veorq_u8(w, vreinterpretq_u8_m128i(RoundKey))); + +#else /* ARMv7-A implementation for a table-based AES */ +#define SSE2NEON_AES_B2W(b0, b1, b2, b3) \ + ((_sse2neon_static_cast(uint32_t, b3) << 24) | \ + (_sse2neon_static_cast(uint32_t, b2) << 16) | \ + (_sse2neon_static_cast(uint32_t, b1) << 8) | \ + _sse2neon_static_cast(uint32_t, b0)) +// multiplying 'x' by 2 in GF(2^8) +#define SSE2NEON_AES_F2(x) ((x << 1) ^ (((x >> 7) & 1) * 0x011b /* WPOLY */)) +// multiplying 'x' by 3 in GF(2^8) +#define SSE2NEON_AES_F3(x) (SSE2NEON_AES_F2(x) ^ x) +#define SSE2NEON_AES_U0(p) \ + SSE2NEON_AES_B2W(SSE2NEON_AES_F2(p), p, p, SSE2NEON_AES_F3(p)) +#define SSE2NEON_AES_U1(p) \ + SSE2NEON_AES_B2W(SSE2NEON_AES_F3(p), SSE2NEON_AES_F2(p), p, p) +#define SSE2NEON_AES_U2(p) \ + SSE2NEON_AES_B2W(p, SSE2NEON_AES_F3(p), SSE2NEON_AES_F2(p), p) +#define SSE2NEON_AES_U3(p) \ + SSE2NEON_AES_B2W(p, p, SSE2NEON_AES_F3(p), SSE2NEON_AES_F2(p)) + + // this generates a table containing every possible permutation of + // shift_rows() and sub_bytes() with mix_columns(). + static const uint32_t ALIGN_STRUCT(16) aes_table[4][256] = { + SSE2NEON_AES_SBOX(SSE2NEON_AES_U0), + SSE2NEON_AES_SBOX(SSE2NEON_AES_U1), + SSE2NEON_AES_SBOX(SSE2NEON_AES_U2), + SSE2NEON_AES_SBOX(SSE2NEON_AES_U3), + }; +#undef SSE2NEON_AES_B2W +#undef SSE2NEON_AES_F2 +#undef SSE2NEON_AES_F3 +#undef SSE2NEON_AES_U0 +#undef SSE2NEON_AES_U1 +#undef SSE2NEON_AES_U2 +#undef SSE2NEON_AES_U3 + + uint32_t x0 = _mm_cvtsi128_si32(a); // get a[31:0] + uint32_t x1 = + _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0x55)); // get a[63:32] + uint32_t x2 = + _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0xAA)); // get a[95:64] + uint32_t x3 = + _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0xFF)); // get a[127:96] + + // finish the modulo addition step in mix_columns() + __m128i out = _mm_set_epi32( + (aes_table[0][x3 & 0xff] ^ aes_table[1][(x0 >> 8) & 0xff] ^ + aes_table[2][(x1 >> 16) & 0xff] ^ aes_table[3][x2 >> 24]), + (aes_table[0][x2 & 0xff] ^ aes_table[1][(x3 >> 8) & 0xff] ^ + aes_table[2][(x0 >> 16) & 0xff] ^ aes_table[3][x1 >> 24]), + (aes_table[0][x1 & 0xff] ^ aes_table[1][(x2 >> 8) & 0xff] ^ + aes_table[2][(x3 >> 16) & 0xff] ^ aes_table[3][x0 >> 24]), + (aes_table[0][x0 & 0xff] ^ aes_table[1][(x1 >> 8) & 0xff] ^ + aes_table[2][(x2 >> 16) & 0xff] ^ aes_table[3][x3 >> 24])); + + return _mm_xor_si128(out, RoundKey); +#endif +} + +// Perform one round of an AES decryption flow on data (state) in a using the +// round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdec_si128 +FORCE_INLINE __m128i _mm_aesdec_si128(__m128i a, __m128i RoundKey) +{ +#if SSE2NEON_ARCH_AARCH64 + uint8x16_t v; + uint8x16_t w = vreinterpretq_u8_m128i(a); + + // inverse shift rows + w = vqtbl1q_u8(w, vld1q_u8(_sse2neon_aes_inv_shift_rows)); + + // inverse sub bytes + v = _sse2neon_aes_inv_subbytes(w); + + /* inverse mix columns: + * InvMixColumns multiplies each column by the matrix: + * [0E 0B 0D 09] + * [09 0E 0B 0D] + * [0D 09 0E 0B] + * [0B 0D 09 0E] + * Computed as: v*{04} ^ v ^ rotate(v*{04}, 16) then standard MixColumns + */ + // v*{04} = xtime(xtime(v)) + w = _sse2neon_aes_xtime(v); + w = _sse2neon_aes_xtime(w); + v = veorq_u8(v, w); + v = veorq_u8(v, vreinterpretq_u8_u16(vrev32q_u16(vreinterpretq_u16_u8(w)))); + + // Apply standard MixColumns to transformed v + w = _sse2neon_aes_xtime(v); + w = veorq_u8(w, vreinterpretq_u8_u16(vrev32q_u16(vreinterpretq_u16_u8(v)))); + w = veorq_u8(w, + vqtbl1q_u8(veorq_u8(v, w), vld1q_u8(_sse2neon_aes_ror32by8))); + + // add round key + return vreinterpretq_m128i_u8( + veorq_u8(w, vreinterpretq_u8_m128i(RoundKey))); + +#else /* ARMv7-A implementation using inverse T-tables */ + // GF(2^8) multiplication helpers for InvMixColumns coefficients +#define SSE2NEON_AES_DEC_B2W(b0, b1, b2, b3) \ + ((_sse2neon_static_cast(uint32_t, b3) << 24) | \ + (_sse2neon_static_cast(uint32_t, b2) << 16) | \ + (_sse2neon_static_cast(uint32_t, b1) << 8) | \ + _sse2neon_static_cast(uint32_t, b0)) + // xtime: multiply by 2 in GF(2^8), using 0x011b to clear bit 8 +#define SSE2NEON_AES_DEC_X2(x) ((x << 1) ^ (((x >> 7) & 1) * 0x011b)) + // multiply by 4 in GF(2^8) +#define SSE2NEON_AES_DEC_X4(x) SSE2NEON_AES_DEC_X2(SSE2NEON_AES_DEC_X2(x)) + // multiply by 8 in GF(2^8) +#define SSE2NEON_AES_DEC_X8(x) SSE2NEON_AES_DEC_X2(SSE2NEON_AES_DEC_X4(x)) + // InvMixColumns coefficients: 0x09, 0x0b, 0x0d, 0x0e +#define SSE2NEON_AES_DEC_F9(x) (SSE2NEON_AES_DEC_X8(x) ^ (x)) +#define SSE2NEON_AES_DEC_FB(x) \ + (SSE2NEON_AES_DEC_X8(x) ^ SSE2NEON_AES_DEC_X2(x) ^ (x)) +#define SSE2NEON_AES_DEC_FD(x) \ + (SSE2NEON_AES_DEC_X8(x) ^ SSE2NEON_AES_DEC_X4(x) ^ (x)) +#define SSE2NEON_AES_DEC_FE(x) \ + (SSE2NEON_AES_DEC_X8(x) ^ SSE2NEON_AES_DEC_X4(x) ^ SSE2NEON_AES_DEC_X2(x)) + // Inverse T-table generators combining InvSubBytes + InvMixColumns +#define SSE2NEON_AES_DEC_V0(p) \ + SSE2NEON_AES_DEC_B2W(SSE2NEON_AES_DEC_FE(p), SSE2NEON_AES_DEC_F9(p), \ + SSE2NEON_AES_DEC_FD(p), SSE2NEON_AES_DEC_FB(p)) +#define SSE2NEON_AES_DEC_V1(p) \ + SSE2NEON_AES_DEC_B2W(SSE2NEON_AES_DEC_FB(p), SSE2NEON_AES_DEC_FE(p), \ + SSE2NEON_AES_DEC_F9(p), SSE2NEON_AES_DEC_FD(p)) +#define SSE2NEON_AES_DEC_V2(p) \ + SSE2NEON_AES_DEC_B2W(SSE2NEON_AES_DEC_FD(p), SSE2NEON_AES_DEC_FB(p), \ + SSE2NEON_AES_DEC_FE(p), SSE2NEON_AES_DEC_F9(p)) +#define SSE2NEON_AES_DEC_V3(p) \ + SSE2NEON_AES_DEC_B2W(SSE2NEON_AES_DEC_F9(p), SSE2NEON_AES_DEC_FD(p), \ + SSE2NEON_AES_DEC_FB(p), SSE2NEON_AES_DEC_FE(p)) + + // Inverse T-tables: combine InvShiftRows + InvSubBytes + InvMixColumns + // Each table entry is the InvMixColumns result for that S-box output + static const uint32_t ALIGN_STRUCT(16) aes_inv_table[4][256] = { + SSE2NEON_AES_RSBOX(SSE2NEON_AES_DEC_V0), + SSE2NEON_AES_RSBOX(SSE2NEON_AES_DEC_V1), + SSE2NEON_AES_RSBOX(SSE2NEON_AES_DEC_V2), + SSE2NEON_AES_RSBOX(SSE2NEON_AES_DEC_V3), + }; +#undef SSE2NEON_AES_DEC_B2W +#undef SSE2NEON_AES_DEC_X2 +#undef SSE2NEON_AES_DEC_X4 +#undef SSE2NEON_AES_DEC_X8 +#undef SSE2NEON_AES_DEC_F9 +#undef SSE2NEON_AES_DEC_FB +#undef SSE2NEON_AES_DEC_FD +#undef SSE2NEON_AES_DEC_FE +#undef SSE2NEON_AES_DEC_V0 +#undef SSE2NEON_AES_DEC_V1 +#undef SSE2NEON_AES_DEC_V2 +#undef SSE2NEON_AES_DEC_V3 + + uint32_t x0 = _mm_cvtsi128_si32(a); + uint32_t x1 = _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0x55)); + uint32_t x2 = _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0xAA)); + uint32_t x3 = _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0xFF)); + + // InvShiftRows is integrated into table indexing: + // Row 0: no shift, Row 1: right by 1, Row 2: right by 2, Row 3: right by 3 + __m128i out = _mm_set_epi32( + (aes_inv_table[0][x3 & 0xff] ^ aes_inv_table[1][(x2 >> 8) & 0xff] ^ + aes_inv_table[2][(x1 >> 16) & 0xff] ^ aes_inv_table[3][x0 >> 24]), + (aes_inv_table[0][x2 & 0xff] ^ aes_inv_table[1][(x1 >> 8) & 0xff] ^ + aes_inv_table[2][(x0 >> 16) & 0xff] ^ aes_inv_table[3][x3 >> 24]), + (aes_inv_table[0][x1 & 0xff] ^ aes_inv_table[1][(x0 >> 8) & 0xff] ^ + aes_inv_table[2][(x3 >> 16) & 0xff] ^ aes_inv_table[3][x2 >> 24]), + (aes_inv_table[0][x0 & 0xff] ^ aes_inv_table[1][(x3 >> 8) & 0xff] ^ + aes_inv_table[2][(x2 >> 16) & 0xff] ^ aes_inv_table[3][x1 >> 24])); + + return _mm_xor_si128(out, RoundKey); +#endif +} + +// Perform the last round of an AES encryption flow on data (state) in a using +// the round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesenclast_si128 +FORCE_INLINE __m128i _mm_aesenclast_si128(__m128i a, __m128i RoundKey) +{ +#if SSE2NEON_ARCH_AARCH64 + uint8x16_t v; + uint8x16_t w = vreinterpretq_u8_m128i(a); + + // shift rows - use file-scope constant + w = vqtbl1q_u8(w, vld1q_u8(_sse2neon_aes_shift_rows)); + + // sub bytes + v = _sse2neon_aes_subbytes(w); + + // add round key + return vreinterpretq_m128i_u8( + veorq_u8(v, vreinterpretq_u8_m128i(RoundKey))); + +#else /* ARMv7-A implementation */ + uint8_t v[16] = { + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 0)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 5)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 10)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 15)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 4)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 9)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 14)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 3)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 8)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 13)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 2)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 7)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 12)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 1)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 6)], + _sse2neon_sbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 11)], + }; + + return _mm_xor_si128(vreinterpretq_m128i_u8(vld1q_u8(v)), RoundKey); +#endif +} + +FORCE_INLINE uint8x16_t _sse2neon_vqtbl1q_u8(uint8x16_t t, uint8x16_t idx) +{ +#if SSE2NEON_ARCH_AARCH64 + return vqtbl1q_u8(t, idx); +#else + // Split 'idx' into two D registers. + uint8x8_t idx_low = vget_low_u8(idx); + uint8x8_t idx_high = vget_high_u8(idx); + + uint8x8x2_t tbl = { + vget_low_u8(t), + vget_high_u8(t), + }; + + // Perform Lookup using vtbl2_u8. + // Perform lookup for the first 8 bytes of the result. + uint8x8_t ret_low = vtbl2_u8(tbl, idx_low); + // Perform lookup for the second 8 bytes of the result. + uint8x8_t ret_high = vtbl2_u8(tbl, idx_high); + + // Combine the retults. + return vcombine_u8(ret_low, ret_high); +#endif +} + +FORCE_INLINE uint8x16_t _sse2neon_vqtbl4q_u8(uint8x16x4_t t, uint8x16_t idx) +{ +#if SSE2NEON_ARCH_AARCH64 + return vqtbl4q_u8(t, idx); +#else + // Split 'idx' into two D registers. + uint8x8_t idx_lo = vget_low_u8(idx); + uint8x8_t idx_hi = vget_high_u8(idx); + + uint8x8x4_t tbl_chunk_0 = { + vget_low_u8(t.val[0]), + vget_high_u8(t.val[0]), + vget_low_u8(t.val[1]), + vget_high_u8(t.val[1]), + }; + + uint8x8x4_t tbl_chunk_1 = { + vget_low_u8(t.val[2]), + vget_high_u8(t.val[2]), + vget_low_u8(t.val[3]), + vget_high_u8(t.val[3]), + }; + + // Shift indices down by 32 so index 32 becomes 0 for the new table. + uint8x16_t idx_minus_32 = vsubq_u8(idx, vdupq_n_u8(32)); + uint8x8_t idx_lo_mod = vget_low_u8(idx_minus_32); + uint8x8_t idx_hi_mod = vget_high_u8(idx_minus_32); + + // Pass 1: Use vtbl4_u8 (VTBL). + // NOTE: VTBL produces 0 of the indices are larger than 31. + uint8x8_t ret_lo = vtbl4_u8(tbl_chunk_0, idx_lo); + uint8x8_t ret_hi = vtbl4_u8(tbl_chunk_0, idx_hi); + + // Use vtbx4_u8 (VTBX). + // It takes the result of Pass 1 as the accumulator. + ret_lo = vtbx4_u8(ret_lo, tbl_chunk_1, idx_lo_mod); + ret_hi = vtbx4_u8(ret_hi, tbl_chunk_1, idx_hi_mod); + + // Combine the results + return vcombine_u8(ret_lo, ret_hi); +#endif +} + +FORCE_INLINE uint8x16_t _sse2neon_vqtbx4q_u8(uint8x16_t acc, + uint8x16x4_t t, + uint8x16_t idx) +{ +#if SSE2NEON_ARCH_AARCH64 + return vqtbx4q_u8(acc, t, idx); +#else + // Split 'acc' into two D registers. + uint8x8_t ret_low = vget_low_u8(acc); + uint8x8_t ret_high = vget_high_u8(acc); + // Split 'idx' into two D registers. + uint8x8_t idx_low = vget_low_u8(idx); + uint8x8_t idx_high = vget_high_u8(idx); + + uint8x8x4_t tbl_chunk_0 = { + vget_low_u8(t.val[0]), + vget_high_u8(t.val[0]), + vget_low_u8(t.val[1]), + vget_high_u8(t.val[1]), + }; + + uint8x8x4_t tbl_chunk_1 = { + vget_low_u8(t.val[2]), + vget_high_u8(t.val[2]), + vget_low_u8(t.val[3]), + vget_high_u8(t.val[3]), + }; + + // Adjust indices: We want to map index 32 to index 0 of this new table. + // To do so, we subtract 32 from all indices. + // NOTE: If the original index is smaller than 32, the adjusted index wraps + // around due to unsigned underflow (e.g., 5 - 32 = 229). + // Since 229 > 31, vtbx4_u8 (VTBX) preserves the result from Pass 1. + // This is the intended behavior. + uint8x16_t idx_minus_32 = vsubq_u8(idx, vdupq_n_u8(32)); + uint8x8_t idx_low_mod = vget_low_u8(idx_minus_32); + uint8x8_t idx_high_mod = vget_high_u8(idx_minus_32); + + // Perform vtbx4_u8 in the first chunk. + ret_low = vtbx4_u8(ret_low, tbl_chunk_0, idx_low); + ret_high = vtbx4_u8(ret_high, tbl_chunk_0, idx_high); + + // Perform vtbx4_u8 on the second chunk. + ret_low = vtbx4_u8(ret_low, tbl_chunk_1, idx_low_mod); + ret_high = vtbx4_u8(ret_high, tbl_chunk_1, idx_high_mod); + + // Combine the results. + return vcombine_u8(ret_low, ret_high); +#endif +} + +// Perform the last round of an AES decryption flow on data (state) in a using +// the round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdeclast_si128 +FORCE_INLINE __m128i _mm_aesdeclast_si128(__m128i a, __m128i RoundKey) +{ +#if SSE2NEON_ARCH_AARCH64 + uint8x16_t v; + uint8x16_t w = vreinterpretq_u8_m128i(a); + + // inverse shift rows - use file-scope constant + w = vqtbl1q_u8(w, vld1q_u8(_sse2neon_aes_inv_shift_rows)); + + // inverse sub bytes + v = _sse2neon_aes_inv_subbytes(w); + + // add round key + return vreinterpretq_m128i_u8( + veorq_u8(v, vreinterpretq_u8_m128i(RoundKey))); + +#else /* ARMv7-A implementation */ + // Inverse shift rows indices: 0,13,10,7,4,1,14,11,8,5,2,15,12,9,6,3 + uint8_t v[16] = { + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 0)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 13)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 10)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 7)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 4)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 1)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 14)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 11)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 8)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 5)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 2)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 15)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 12)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 9)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 6)], + _sse2neon_rsbox[vgetq_lane_u8(vreinterpretq_u8_m128i(a), 3)], + }; + + return _mm_xor_si128(vreinterpretq_m128i_u8(vld1q_u8(v)), RoundKey); +#endif +} + +// Perform the InvMixColumns transformation on a and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesimc_si128 +FORCE_INLINE __m128i _mm_aesimc_si128(__m128i a) +{ +#if SSE2NEON_ARCH_AARCH64 + uint8x16_t v = vreinterpretq_u8_m128i(a); + uint8x16_t w; + + /* InvMixColumns: same algorithm as in _mm_aesdec_si128 */ + // v*{04} = xtime(xtime(v)) + w = _sse2neon_aes_xtime(v); + w = _sse2neon_aes_xtime(w); + v = veorq_u8(v, w); + v = veorq_u8(v, vreinterpretq_u8_u16(vrev32q_u16(vreinterpretq_u16_u8(w)))); + + // Apply standard MixColumns pattern + w = _sse2neon_aes_xtime(v); + w = veorq_u8(w, vreinterpretq_u8_u16(vrev32q_u16(vreinterpretq_u16_u8(v)))); + w = veorq_u8(w, + vqtbl1q_u8(veorq_u8(v, w), vld1q_u8(_sse2neon_aes_ror32by8))); + return vreinterpretq_m128i_u8(w); + +#else /* ARMv7-A NEON implementation */ + uint8_t i, e, f, g, h, v[4][4]; + vst1q_u8(_sse2neon_reinterpret_cast(uint8_t *, v), + vreinterpretq_u8_m128i(a)); + for (i = 0; i < 4; ++i) { + e = v[i][0]; + f = v[i][1]; + g = v[i][2]; + h = v[i][3]; + + v[i][0] = SSE2NEON_MULTIPLY(e, 0x0e) ^ SSE2NEON_MULTIPLY(f, 0x0b) ^ + SSE2NEON_MULTIPLY(g, 0x0d) ^ SSE2NEON_MULTIPLY(h, 0x09); + v[i][1] = SSE2NEON_MULTIPLY(e, 0x09) ^ SSE2NEON_MULTIPLY(f, 0x0e) ^ + SSE2NEON_MULTIPLY(g, 0x0b) ^ SSE2NEON_MULTIPLY(h, 0x0d); + v[i][2] = SSE2NEON_MULTIPLY(e, 0x0d) ^ SSE2NEON_MULTIPLY(f, 0x09) ^ + SSE2NEON_MULTIPLY(g, 0x0e) ^ SSE2NEON_MULTIPLY(h, 0x0b); + v[i][3] = SSE2NEON_MULTIPLY(e, 0x0b) ^ SSE2NEON_MULTIPLY(f, 0x0d) ^ + SSE2NEON_MULTIPLY(g, 0x09) ^ SSE2NEON_MULTIPLY(h, 0x0e); + } + + return vreinterpretq_m128i_u8( + vld1q_u8(_sse2neon_reinterpret_cast(uint8_t *, v))); +#endif +} + +// Assist in expanding the AES cipher key by computing steps towards generating +// a round key for encryption cipher using data from a and an 8-bit round +// constant specified in imm8, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aeskeygenassist_si128 +// +// Emits the Advanced Encryption Standard (AES) instruction aeskeygenassist. +// This instruction generates a round key for AES encryption. See +// https://kazakov.life/2017/11/01/cryptocurrency-mining-on-ios-devices/ +// for details. +FORCE_INLINE __m128i _mm_aeskeygenassist_si128(__m128i a, const int rcon) +{ +#if SSE2NEON_ARCH_AARCH64 + uint8x16_t _a = vreinterpretq_u8_m128i(a); + uint8x16_t sub = _sse2neon_aes_subbytes(_a); + + uint32x4_t sub_u32 = vreinterpretq_u32_u8(sub); + uint32x4_t rot = + vorrq_u32(vshrq_n_u32(sub_u32, 8), vshlq_n_u32(sub_u32, 24)); + uint32x4_t rcon_vec = + vdupq_n_u32(_sse2neon_static_cast(uint32_t, rcon)); // lane-wise xor + uint32x4_t rot_xor = veorq_u32(rot, rcon_vec); + + return vreinterpretq_m128i_u32(vtrn2q_u32(sub_u32, rot_xor)); + +#else /* ARMv7-A NEON implementation */ + uint32_t X1 = _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0x55)); + uint32_t X3 = _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0xFF)); + for (int i = 0; i < 4; ++i) { + (_sse2neon_reinterpret_cast(uint8_t *, &X1))[i] = + _sse2neon_sbox[(_sse2neon_reinterpret_cast(uint8_t *, &X1))[i]]; + (_sse2neon_reinterpret_cast(uint8_t *, &X3))[i] = + _sse2neon_sbox[(_sse2neon_reinterpret_cast(uint8_t *, &X3))[i]]; + } + return _mm_set_epi32(((X3 >> 8) | (X3 << 24)) ^ rcon, X3, + ((X1 >> 8) | (X1 << 24)) ^ rcon, X1); +#endif +} +#undef SSE2NEON_AES_SBOX +#undef SSE2NEON_AES_RSBOX + +#if SSE2NEON_ARCH_AARCH64 +#undef SSE2NEON_XT +#undef SSE2NEON_MULTIPLY +#endif + +#else /* __ARM_FEATURE_CRYPTO */ +// Implements equivalent of 'aesenc' by combining AESE (with an empty key) and +// AESMC and then manually applying the real key as an xor operation. This +// unfortunately means an additional xor op; the compiler should be able to +// optimize this away for repeated calls however. See +// https://blog.michaelbrase.com/2018/05/08/emulating-x86-aes-intrinsics-on-armv8-a +// for more details. +FORCE_INLINE __m128i _mm_aesenc_si128(__m128i a, __m128i b) +{ + return vreinterpretq_m128i_u8(veorq_u8( + vaesmcq_u8(vaeseq_u8(vreinterpretq_u8_m128i(a), vdupq_n_u8(0))), + vreinterpretq_u8_m128i(b))); +} + +// Perform one round of an AES decryption flow on data (state) in a using the +// round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdec_si128 +FORCE_INLINE __m128i _mm_aesdec_si128(__m128i a, __m128i RoundKey) +{ + return vreinterpretq_m128i_u8(veorq_u8( + vaesimcq_u8(vaesdq_u8(vreinterpretq_u8_m128i(a), vdupq_n_u8(0))), + vreinterpretq_u8_m128i(RoundKey))); +} + +// Perform the last round of an AES encryption flow on data (state) in a using +// the round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesenclast_si128 +FORCE_INLINE __m128i _mm_aesenclast_si128(__m128i a, __m128i RoundKey) +{ + return _mm_xor_si128(vreinterpretq_m128i_u8(vaeseq_u8( + vreinterpretq_u8_m128i(a), vdupq_n_u8(0))), + RoundKey); +} + +// Perform the last round of an AES decryption flow on data (state) in a using +// the round key in RoundKey, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdeclast_si128 +FORCE_INLINE __m128i _mm_aesdeclast_si128(__m128i a, __m128i RoundKey) +{ + return vreinterpretq_m128i_u8( + veorq_u8(vaesdq_u8(vreinterpretq_u8_m128i(a), vdupq_n_u8(0)), + vreinterpretq_u8_m128i(RoundKey))); +} + +// Perform the InvMixColumns transformation on a and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesimc_si128 +FORCE_INLINE __m128i _mm_aesimc_si128(__m128i a) +{ + return vreinterpretq_m128i_u8(vaesimcq_u8(vreinterpretq_u8_m128i(a))); +} + +// Assist in expanding the AES cipher key by computing steps towards generating +// a round key for encryption cipher using data from a and an 8-bit round +// constant specified in imm8, and store the result in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aeskeygenassist_si128 +FORCE_INLINE __m128i _mm_aeskeygenassist_si128(__m128i a, const int rcon) +{ + // AESE does ShiftRows and SubBytes on A + uint8x16_t sb_ = vaeseq_u8(vreinterpretq_u8_m128i(a), vdupq_n_u8(0)); + +#if !SSE2NEON_COMPILER_MSVC || SSE2NEON_COMPILER_CLANG + uint8x16_t dest = { + // Undo ShiftRows step from AESE and extract X1 and X3 + sb_[0x4], sb_[0x1], sb_[0xE], sb_[0xB], // SubBytes(X1) + sb_[0x1], sb_[0xE], sb_[0xB], sb_[0x4], // ROT(SubBytes(X1)) + sb_[0xC], sb_[0x9], sb_[0x6], sb_[0x3], // SubBytes(X3) + sb_[0x9], sb_[0x6], sb_[0x3], sb_[0xC], // ROT(SubBytes(X3)) + }; + uint32x4_t r = {0, _sse2neon_static_cast(unsigned, rcon), 0, + _sse2neon_static_cast(unsigned, rcon)}; + return vreinterpretq_m128i_u8(dest) ^ vreinterpretq_m128i_u32(r); +#else + // We have to use explicit field assignment because MSVC in C mode does not + // support C++ brace-initialization syntax for aggregate types, and even + // in C++ mode it adheres to C++03 8.5.1 sub-section 15 which requires + // unions to be initialized by their first member type. + + // As per the Windows ARM64 ABI, it is always little endian, so this works + __n128 dest; + dest.n128_u64[0] = ((uint64_t) sb_.n128_u8[0x4] << 0) | + ((uint64_t) sb_.n128_u8[0x1] << 8) | + ((uint64_t) sb_.n128_u8[0xE] << 16) | + ((uint64_t) sb_.n128_u8[0xB] << 24) | + ((uint64_t) sb_.n128_u8[0x1] << 32) | + ((uint64_t) sb_.n128_u8[0xE] << 40) | + ((uint64_t) sb_.n128_u8[0xB] << 48) | + ((uint64_t) sb_.n128_u8[0x4] << 56); + dest.n128_u64[1] = ((uint64_t) sb_.n128_u8[0xC] << 0) | + ((uint64_t) sb_.n128_u8[0x9] << 8) | + ((uint64_t) sb_.n128_u8[0x6] << 16) | + ((uint64_t) sb_.n128_u8[0x3] << 24) | + ((uint64_t) sb_.n128_u8[0x9] << 32) | + ((uint64_t) sb_.n128_u8[0x6] << 40) | + ((uint64_t) sb_.n128_u8[0x3] << 48) | + ((uint64_t) sb_.n128_u8[0xC] << 56); + + dest.n128_u32[1] = dest.n128_u32[1] ^ rcon; + dest.n128_u32[3] = dest.n128_u32[3] ^ rcon; + + return dest; +#endif +} +#endif + +/* Others */ + +// Perform a carry-less multiplication of two 64-bit integers, selected from a +// and b according to imm8, and store the results in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_clmulepi64_si128 +FORCE_INLINE __m128i _mm_clmulepi64_si128(__m128i _a, __m128i _b, const int imm) +{ + uint64x2_t a = vreinterpretq_u64_m128i(_a); + uint64x2_t b = vreinterpretq_u64_m128i(_b); + switch (imm & 0x11) { + case 0x00: + return vreinterpretq_m128i_u64( + _sse2neon_vmull_p64(vget_low_u64(a), vget_low_u64(b))); + case 0x01: + return vreinterpretq_m128i_u64( + _sse2neon_vmull_p64(vget_high_u64(a), vget_low_u64(b))); + case 0x10: + return vreinterpretq_m128i_u64( + _sse2neon_vmull_p64(vget_low_u64(a), vget_high_u64(b))); + case 0x11: + return vreinterpretq_m128i_u64( + _sse2neon_vmull_p64(vget_high_u64(a), vget_high_u64(b))); + default: + abort(); + } +} + +FORCE_INLINE unsigned int _sse2neon_mm_get_denormals_zero_mode(void) +{ + union { + fpcr_bitfield field; +#if SSE2NEON_ARCH_AARCH64 + uint64_t value; +#else + uint32_t value; +#endif + } r; + +#if SSE2NEON_ARCH_AARCH64 + r.value = _sse2neon_get_fpcr(); +#else + __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ +#endif + + return r.field.bit24 ? _MM_DENORMALS_ZERO_ON : _MM_DENORMALS_ZERO_OFF; +} + +// Count the number of bits set to 1 in unsigned 32-bit integer a, and +// return that count in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_popcnt_u32 +FORCE_INLINE int _mm_popcnt_u32(unsigned int a) +{ +#if SSE2NEON_ARCH_AARCH64 +#if __has_builtin(__builtin_popcount) + return __builtin_popcount(a); +#elif SSE2NEON_COMPILER_MSVC + return _CountOneBits(a); +#else + return (int) vaddlv_u8(vcnt_u8(vcreate_u8((uint64_t) a))); +#endif +#else + uint32_t count = 0; + uint8x8_t input_val, count8x8_val; + uint16x4_t count16x4_val; + uint32x2_t count32x2_val; + + input_val = vld1_u8(_sse2neon_reinterpret_cast(uint8_t *, &a)); + count8x8_val = vcnt_u8(input_val); + count16x4_val = vpaddl_u8(count8x8_val); + count32x2_val = vpaddl_u16(count16x4_val); + + vst1_u32(&count, count32x2_val); + return count; +#endif +} + +// Count the number of bits set to 1 in unsigned 64-bit integer a, and +// return that count in dst. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_popcnt_u64 +FORCE_INLINE int64_t _mm_popcnt_u64(uint64_t a) +{ +#if SSE2NEON_ARCH_AARCH64 +#if __has_builtin(__builtin_popcountll) + return __builtin_popcountll(a); +#elif SSE2NEON_COMPILER_MSVC + return _CountOneBits64(a); +#else + return (int64_t) vaddlv_u8(vcnt_u8(vcreate_u8(a))); +#endif +#else + uint64_t count = 0; + uint8x8_t input_val, count8x8_val; + uint16x4_t count16x4_val; + uint32x2_t count32x2_val; + uint64x1_t count64x1_val; + + input_val = vld1_u8(_sse2neon_reinterpret_cast(uint8_t *, &a)); + count8x8_val = vcnt_u8(input_val); + count16x4_val = vpaddl_u8(count8x8_val); + count32x2_val = vpaddl_u16(count16x4_val); + count64x1_val = vpaddl_u32(count32x2_val); + vst1_u64(&count, count64x1_val); + return count; +#endif +} + +FORCE_INLINE void _sse2neon_mm_set_denormals_zero_mode(unsigned int flag) +{ + // AArch32 Advanced SIMD arithmetic always uses the Flush-to-zero setting, + // regardless of the value of the FZ bit. + union { + fpcr_bitfield field; +#if SSE2NEON_ARCH_AARCH64 + uint64_t value; +#else + uint32_t value; +#endif + } r; + +#if SSE2NEON_ARCH_AARCH64 + r.value = _sse2neon_get_fpcr(); +#else + __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ +#endif + + r.field.bit24 = (flag & _MM_DENORMALS_ZERO_MASK) == _MM_DENORMALS_ZERO_ON; + +#if SSE2NEON_ARCH_AARCH64 + _sse2neon_set_fpcr(r.value); +#else + __asm__ __volatile__("vmsr FPSCR, %0" ::"r"(r)); /* write */ +#endif +} + +// Return the current 64-bit value of the processor's time-stamp counter. +// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=rdtsc +FORCE_INLINE uint64_t _rdtsc(void) +{ +#if SSE2NEON_ARCH_AARCH64 + uint64_t val; + + /* According to ARM DDI 0487F.c, from Armv8.0 to Armv8.5 inclusive, the + * system counter is at least 56 bits wide; from Armv8.6, the counter must + * be 64 bits wide. So the system counter could be less than 64 bits wide + * and it is attributed with the flag 'cap_user_time_short' is true. + */ +#if SSE2NEON_COMPILER_MSVC && !SSE2NEON_COMPILER_CLANG + val = _ReadStatusReg(ARM64_SYSREG(3, 3, 14, 0, 2)); +#else + __asm__ __volatile__("mrs %0, cntvct_el0" : "=r"(val)); +#endif + + return val; +#else + uint32_t pmccntr, pmuseren, pmcntenset; + // Read the user mode Performance Monitoring Unit (PMU) + // User Enable Register (PMUSERENR) access permissions. + __asm__ __volatile__("mrc p15, 0, %0, c9, c14, 0" : "=r"(pmuseren)); + if (pmuseren & 1) { // Allows reading PMUSERENR for user mode code. + __asm__ __volatile__("mrc p15, 0, %0, c9, c12, 1" : "=r"(pmcntenset)); + if (pmcntenset & 0x80000000UL) { // Is it counting? + __asm__ __volatile__("mrc p15, 0, %0, c9, c13, 0" : "=r"(pmccntr)); + // The counter is set up to count every 64th cycle + return (uint64_t) (pmccntr) << 6; + } + } + + // Fallback to syscall as we can't enable PMUSERENR in user mode. + struct timeval tv; + gettimeofday(&tv, NULL); + return (uint64_t) (tv.tv_sec) * 1000000 + tv.tv_usec; +#endif +} + +#if SSE2NEON_COMPILER_GCC_COMPAT +#pragma pop_macro("ALIGN_STRUCT") +#pragma pop_macro("FORCE_INLINE") +#endif + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC pop_options +#endif + +#endif diff --git a/Sources/viewport_server.h b/Sources/viewport_server.h index ac4e71f..99f710b 100644 --- a/Sources/viewport_server.h +++ b/Sources/viewport_server.h @@ -15,6 +15,8 @@ #include #include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/Sources/websocket.cpp b/Sources/websocket.cpp index 095f5fa..a817fe6 100644 --- a/Sources/websocket.cpp +++ b/Sources/websocket.cpp @@ -4,7 +4,12 @@ #include "socket_optimization.h" #include #include -#include // SSE2 +// SSE2 for x86/x64, SSE2 to NEON translation for ARM64 +#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) +#include +#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) +#include "sse2neon.h" +#endif #include #include #include @@ -67,6 +72,7 @@ namespace WebSocketWrapper { void initialize() { if (!winsock_initialized.exchange(true)) { + #ifdef _WIN32 WSADATA wsaData; int result = WSAStartup(MAKEWORD(2, 2), &wsaData); if (result != 0) { @@ -77,16 +83,19 @@ namespace WebSocketWrapper { kinc_log(KINC_LOG_LEVEL_INFO, "WebSocket client support initialized successfully"); } #endif + #endif } } void cleanup() { active_websockets.clear(); if (winsock_initialized.exchange(false)) { + #ifdef _WIN32 WSACleanup(); #ifdef DEBUG_NETWORK kinc_log(KINC_LOG_LEVEL_INFO, "WebSocket cleanup complete"); #endif + #endif } } @@ -347,7 +356,7 @@ namespace WebSocketWrapper { int sock = static_cast(reinterpret_cast(ws_)); int sendResult; - if (is_ssl_ && ssl_context_initialized_) { + if (is_ssl_ && isSSLReady()) { sendResult = webSocketSSLSend(frame.data(), static_cast(frame.size())); } else { sendResult = ::send(sock, reinterpret_cast(frame.data()), static_cast(frame.size()), 0); @@ -397,7 +406,7 @@ namespace WebSocketWrapper { int sock = static_cast(reinterpret_cast(ws_)); int sendResult; - if (is_ssl_ && ssl_context_initialized_) { + if (is_ssl_ && isSSLReady()) { sendResult = webSocketSSLSend(frame.data(), static_cast(frame.size())); } else { sendResult = ::send(sock, reinterpret_cast(frame.data()), static_cast(frame.size()), 0); @@ -651,6 +660,7 @@ namespace WebSocketWrapper { kinc_log(KINC_LOG_LEVEL_INFO, "WebSocket: webSocketSSLReceive called with bufferSize=%d", bufferSize); #endif + #ifdef _WIN32 if (!ssl_context_initialized_) { #ifdef DEBUG_NETWORK kinc_log(KINC_LOG_LEVEL_ERROR, "WebSocket: SSL not initialized for receive"); @@ -881,6 +891,32 @@ namespace WebSocketWrapper { ssl_buffer_.clear(); return -1; } + #else + // LibreSSL/OpenSSL implementation for macOS/Linux + if (!ssl_initialized_ || !ssl_) { + #ifdef DEBUG_NETWORK + kinc_log(KINC_LOG_LEVEL_ERROR, "WebSocket: SSL not initialized for receive"); + #endif + return -1; + } + + int result = SSL_read(ssl_, buffer, bufferSize); + if (result <= 0) { + int error = SSL_get_error(ssl_, result); + if (error == SSL_ERROR_WANT_READ || error == SSL_ERROR_WANT_WRITE) { + return 0; // need more data + } + #ifdef DEBUG_NETWORK + kinc_log(KINC_LOG_LEVEL_ERROR, "WebSocket: SSL_read failed with error %d", error); + #endif + return -1; + } + + #ifdef DEBUG_NETWORK + kinc_log(KINC_LOG_LEVEL_INFO, "WebSocket: SSL_read returned %d bytes", result); + #endif + return result; + #endif } bool WebSocketClient::connectToServer(const std::string& host, int port, const std::string& path) { @@ -1010,7 +1046,7 @@ namespace WebSocketWrapper { #endif int sendResult; - if (is_ssl_ && ssl_context_initialized_) { + if (is_ssl_ && isSSLReady()) { sendResult = webSocketSSLSend(handshakeRequest.c_str(), static_cast(handshakeRequest.length())); } else { sendResult = ::send(sock, handshakeRequest.c_str(), static_cast(handshakeRequest.length()), 0); @@ -1025,7 +1061,7 @@ namespace WebSocketWrapper { char buffer[SocketOptimization::SMALL_BUFFER_SIZE]; int bytesReceived; - if (is_ssl_ && ssl_context_initialized_) { + if (is_ssl_ && isSSLReady()) { bytesReceived = webSocketSSLReceive(buffer, sizeof(buffer) - 1); } else { bytesReceived = recv(sock, buffer, sizeof(buffer) - 1, 0); @@ -1158,7 +1194,7 @@ namespace WebSocketWrapper { { std::vector pongFrame = createPongFrame(payload); int sock = static_cast(reinterpret_cast(ws_)); - if (is_ssl_ && ssl_context_initialized_) { + if (is_ssl_ && isSSLReady()) { webSocketSSLSend(pongFrame.data(), static_cast(pongFrame.size())); } else { ::send(sock, reinterpret_cast(pongFrame.data()), static_cast(pongFrame.size()), 0); @@ -1230,7 +1266,7 @@ namespace WebSocketWrapper { } int bytesReceived; - if (is_ssl_ && ssl_context_initialized_) { + if (is_ssl_ && isSSLReady()) { bytesReceived = webSocketSSLReceive(reinterpret_cast(writePtr), static_cast(contiguousSpace)); } else { bytesReceived = recv(sock, reinterpret_cast(writePtr), static_cast(contiguousSpace), 0); @@ -1431,7 +1467,7 @@ namespace WebSocketWrapper { int sock = static_cast(reinterpret_cast(ws_)); int sendResult; - if (is_ssl_ && ssl_context_initialized_) { + if (is_ssl_ && isSSLReady()) { sendResult = webSocketSSLSend(pongFrame.data(), static_cast(pongFrame.size())); } else { sendResult = ::send(sock, reinterpret_cast(pongFrame.data()), static_cast(pongFrame.size()), 0); @@ -1706,18 +1742,7 @@ namespace WebSocketWrapper { } int WebSocketClient::webSocketSSLSend(const void* data, int len) { - #ifdef WITH_SSL - #ifdef _WIN32 - if (!ssl_context_initialized_) { - return ::send(ssl_socket_, reinterpret_cast(data), len, 0); - } return webSocketSSLSend(reinterpret_cast(data), len); - #else - return ::send(ssl_socket_, reinterpret_cast(data), len, 0); - #endif - #else - return ::send(ssl_socket_, reinterpret_cast(data), len, 0); - #endif } #ifdef WITH_SSL @@ -2862,4 +2887,4 @@ void createWebSocketEventClasses(Isolate* isolate, Local& global global->Set(isolate, "CloseEvent", closeEventTpl); } -#endif \ No newline at end of file +#endif diff --git a/Sources/websocket.h b/Sources/websocket.h index 9e1c823..6aced00 100644 --- a/Sources/websocket.h +++ b/Sources/websocket.h @@ -104,14 +104,14 @@ namespace WebSocketWrapper { void* ssl_cred_handle_; void* ssl_context_handle_; bool ssl_context_initialized_; - int ssl_socket_; - std::vector ssl_buffer_; #else SSL_CTX* ssl_ctx_; SSL* ssl_; bool ssl_initialized_; #endif + int ssl_socket_; + std::vector ssl_buffer_; bool initWSL(); void cleanupWSL(); bool performWSLHandshake(int socket, const std::string& host); @@ -119,6 +119,13 @@ namespace WebSocketWrapper { int webSocketSSLSend(const void* data, int len); int webSocketSSLSend(const char* buffer, int length); int webSocketSSLReceive(char* buffer, int bufferSize); + inline bool isSSLReady() const { + #ifdef _WIN32 + return ssl_context_initialized_; + #else + return ssl_initialized_; + #endif + } #endif std::string base64Encode(const std::string& data); diff --git a/kfile.js b/kfile.js index 98a10e1..652fed3 100644 --- a/kfile.js +++ b/kfile.js @@ -11,6 +11,7 @@ let flags = { with_networking: true, with_viewport: true, with_uws: false, + with_ssl: true, debug_network: true }; @@ -27,10 +28,11 @@ let root = __dirname; const libdir = root + '/v8/libraries/' + system + '/' + build + '/'; let project = new Project(flags.name); -await project.addProject('Kinc'); project.cppStd = "c++17"; project.setDebugDir('Deployment'); +await project.addProject('Kore'); + if (fs.existsSync(process.cwd() + '/icon.png')) { project.icon = path.relative(__dirname, process.cwd()) + '/icon.png'; } @@ -140,11 +142,14 @@ else if (platform === Platform.Linux) { } } else if (platform === Platform.OSX) { - project.addLib('v8/libraries/macos/release/libv8_monolith.a'); + project.addLib('v8_monolith -L' + libdir); if (flags.with_networking) { - project.addLib('-framework Foundation'); - project.addLib('-framework Security'); - project.addLib('-framework SystemConfiguration'); + project.addIncludeDir('apple-libressl-sdk/include'); + project.addLinkerFlag('-L' + root + '/apple-libressl-sdk/lib'); + project.addLinkerFlag('-lssl'); + project.addLinkerFlag('-lcrypto'); + project.addLinkerFlag('-framework Security'); + project.addLinkerFlag('-framework SystemConfiguration'); } }