Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Oct 25, 2024
1 parent 4c82278 commit 72fede0
Show file tree
Hide file tree
Showing 121 changed files with 598 additions and 2,599 deletions.
8 changes: 0 additions & 8 deletions sources/backends/android/kinc/backend/system.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1182,10 +1182,6 @@ void android_main(struct android_app *application) {
(*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);

Expand All @@ -1206,10 +1202,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

kinc_internal_gamepad_trigger_connect(0);

return 0;
Expand Down
122 changes: 0 additions & 122 deletions sources/backends/direct3d11/kinc/backend/graphics4/Direct3D11.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
// #include <Kore/Application.h>
#include <kinc/graphics4/pipeline.h>
#include <kinc/graphics4/shader.h>
#include <kinc/graphics4/texturearray.h>

#include <kinc/graphics4/constantbuffer.h>
#include <kinc/graphics4/graphics.h>
#include <kinc/graphics4/indexbuffer.h>
#include <kinc/graphics4/rendertarget.h>
Expand All @@ -29,16 +27,6 @@ int antialiasingSamples(void) {
}
#endif

#ifdef KINC_WINDOWSAPP
IUnknown *kinc_winapp_internal_get_window(void);
#endif

#ifdef KINC_HOLOLENS
#include "DeviceResources.winrt.h"
#include "Hololens.winrt.h"
#include <windows.graphics.directx.direct3d11.interop.h>
#endif

// MinGW workaround for missing defines
#ifndef D3D11_MIN_DEPTH
#define D3D11_MIN_DEPTH (0.0f)
Expand All @@ -60,11 +48,7 @@ bool kinc_internal_scissoring = false;
// static bool vsync;

static D3D_FEATURE_LEVEL featureLevel;
// #ifdef KINC_WINDOWSAPP
// static IDXGISwapChain1 *swapChain = NULL;
// #else
// static IDXGISwapChain *swapChain = NULL;
// #endif
static D3D11_SAMPLER_DESC lastSamplers[16];

struct Sampler {
Expand Down Expand Up @@ -202,9 +186,6 @@ static bool isWindows10OrGreater(void) {

void kinc_g4_internal_init(void) {
D3D_FEATURE_LEVEL featureLevels[] = {
#ifdef KINC_WINDOWSAPP
D3D_FEATURE_LEVEL_11_1,
#endif
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
Expand All @@ -216,9 +197,6 @@ void kinc_g4_internal_init(void) {
#endif

IDXGIAdapter *adapter = NULL;
#ifdef KINC_HOLOLENS
adapter = holographicFrameController->getCompatibleDxgiAdapter().Get();
#endif
HRESULT result = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION,
&dx_ctx.device, &featureLevel, &dx_ctx.context);

Expand Down Expand Up @@ -248,7 +226,6 @@ void kinc_g4_internal_init_window(int windowId, int depthBufferBits, int stencil
fragmentConstants[i] = 0;

struct dx_window *window = &dx_ctx.windows[windowId];
// TODO: make WindowsApp actually work again
#ifdef KINC_WINDOWS
window->hwnd = kinc_windows_window_handle(windowId);
#endif
Expand Down Expand Up @@ -335,11 +312,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 KINC_WINDOWSAPP
rtbd.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
#else
rtbd.RenderTargetWriteMask = D3D10_COLOR_WRITE_ENABLE_ALL;
#endif

blendDesc.AlphaToCoverageEnable = false;
blendDesc.RenderTarget[0] = rtbd;
Expand Down Expand Up @@ -474,10 +447,6 @@ void kinc_g4_begin(int windowId) {
createBackbuffer(window, kinc_g4_antialiasing_samples());
}
kinc_g4_restore_render_target();
// #ifdef KINC_WINDOWSAPP
// // TODO (DK) do i need to do something here?
// dx_ctx.context->lpVtbl->OMSetRenderTargets(dx_ctx.context, 1, &renderTargetView, depthStencilView);
// #endif
}

void kinc_g4_viewport(int x, int y, int width, int height) {
Expand Down Expand Up @@ -1207,102 +1176,18 @@ 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);

void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, kinc_g4_texture_t *texture) {
kinc_internal_texture_set_image(texture, unit);
}

static unsigned queryCount = 0;
#define QUERY_POOL_MAX_SIZE 256
static uint32_t query_pool_size = 0;
static ID3D11Query *queryPool[QUERY_POOL_MAX_SIZE];

bool kinc_g4_init_occlusion_query(unsigned *occlusionQuery) {
D3D11_QUERY_DESC queryDesc;
queryDesc.Query = D3D11_QUERY_OCCLUSION;
queryDesc.MiscFlags = 0;
ID3D11Query *pQuery = NULL;
HRESULT result = dx_ctx.device->lpVtbl->CreateQuery(dx_ctx.device, &queryDesc, &pQuery);

if (FAILED(result)) {
kinc_log(KINC_LOG_LEVEL_INFO, "Internal query creation failed, result: 0x%X.", result);
return false;
}

assert(query_pool_size < QUERY_POOL_MAX_SIZE);
queryPool[query_pool_size++] = pQuery;
*occlusionQuery = queryCount;
++queryCount;

return true;
}

void kinc_g4_delete_occlusion_query(unsigned occlusionQuery) {
if (occlusionQuery < query_pool_size) {
queryPool[occlusionQuery] = NULL;
}
}

void kinc_g4_start_occlusion_query(unsigned occlusionQuery) {
ID3D11Query *pQuery = queryPool[occlusionQuery];
if (pQuery != NULL) {
dx_ctx.context->lpVtbl->Begin(dx_ctx.context, (ID3D11Asynchronous *)pQuery);
}
}

void kinc_g4_end_occlusion_query(unsigned occlusionQuery) {
ID3D11Query *pQuery = queryPool[occlusionQuery];
if (pQuery != NULL) {
dx_ctx.context->lpVtbl->End(dx_ctx.context, (ID3D11Asynchronous *)pQuery);
}
}

bool kinc_g4_are_query_results_available(unsigned occlusionQuery) {
ID3D11Query *pQuery = queryPool[occlusionQuery];
if (pQuery != NULL) {
if (S_OK == dx_ctx.context->lpVtbl->GetData(dx_ctx.context, (ID3D11Asynchronous *)pQuery, 0, 0, 0)) {
return true;
}
}
return false;
}

void kinc_g4_get_query_results(unsigned occlusionQuery, unsigned *pixelCount) {
ID3D11Query *pQuery = queryPool[occlusionQuery];
if (pQuery != NULL) {
UINT64 numberOfPixelsDrawn;
HRESULT result = dx_ctx.context->lpVtbl->GetData(dx_ctx.context, (ID3D11Asynchronous *)pQuery, &numberOfPixelsDrawn, sizeof(UINT64), 0);
if (S_OK == result) {
*pixelCount = (unsigned)numberOfPixelsDrawn;
}
else {
kinc_log(KINC_LOG_LEVEL_INFO, "Check first if results are available");
*pixelCount = 0;
}
}
}

void kinc_internal_texture_array_set(kinc_g4_texture_array_t *array, kinc_g4_texture_unit_t unit);

void kinc_g4_set_texture_array(kinc_g4_texture_unit_t unit, kinc_g4_texture_array_t *array) {
kinc_internal_texture_array_set(array, unit);
}

void kinc_internal_resize(int windowId, int width, int height) {
struct dx_window *window = &dx_ctx.windows[windowId];
window->new_width = width;
Expand Down Expand Up @@ -1339,10 +1224,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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ void kinc_g4_compute_shader_init(kinc_g4_compute_shader *shader, void *_data, in
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) {
Expand Down Expand Up @@ -71,7 +70,6 @@ void kinc_g4_compute_shader_init(kinc_g4_compute_shader *shader, void *_data, in
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);
Expand All @@ -86,7 +84,6 @@ void kinc_g4_compute_shader_init(kinc_g4_compute_shader *shader, void *_data, in
return;
}

#ifndef KINC_KONG
D3D11_BUFFER_DESC desc;
desc.ByteWidth = getMultipleOf16(shader->impl.constantsSize);
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
Expand All @@ -95,7 +92,6 @@ void kinc_g4_compute_shader_init(kinc_g4_compute_shader *shader, void *_data, in
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_g4_compute_shader_destroy(kinc_g4_compute_shader *shader) {}
Expand All @@ -118,7 +114,6 @@ static kinc_internal_hash_index_t *compute_findTextureUnit(kinc_internal_hash_in
return NULL;
}

#ifndef KINC_KONG
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};

Expand Down Expand Up @@ -185,14 +180,11 @@ kinc_g4_texture_unit_t kinc_g4_compute_shader_get_texture_unit(kinc_g4_compute_s
}
return unit;
}
#endif

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);
#ifndef KINC_KONG
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);
#endif
}

void kinc_g4_compute(int x, int y, int z) {
Expand Down
2 changes: 0 additions & 2 deletions sources/backends/direct3d11/kinc/backend/graphics4/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ typedef struct kinc_g4_compute_internal_shader_constant {
} kinc_g4_compute_internal_shader_constant;

typedef struct kinc_g4_compute_shader_impl {
#ifndef KINC_KONG
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;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@

#include <kinc/backend/SystemMicrosoft.h>

#ifdef KINC_WINDOWSAPP
#include <d3d11_1.h>
#else
#pragma warning(disable : 4005)
#include <d3d11.h>
#endif

#include "Direct3D11.h"

Expand Down Expand Up @@ -103,11 +99,9 @@ static size_t get_multiple_of_16(size_t value) {
#include "Direct3D11.c.h"
#include "ShaderHash.c.h"
#include "compute.c.h"
#include "constantbuffer.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"
Loading

0 comments on commit 72fede0

Please sign in to comment.