Skip to content

Commit

Permalink
Fix compute things
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Jan 19, 2024
1 parent 4cea48a commit fea7124
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 238 deletions.
157 changes: 0 additions & 157 deletions Sources/Kore/Compute/Compute.cpp

This file was deleted.

80 changes: 0 additions & 80 deletions Sources/Kore/Compute/Compute.h

This file was deleted.

51 changes: 51 additions & 0 deletions Sources/Kore/Graphics4/Compute.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "Compute.h"

#include <string.h>

using namespace Kore;

Graphics4::ComputeShader::ComputeShader(void *source, int length) {
kinc_g4_compute_shader_init(&kincImpl, source, length);
}

Graphics4::ComputeShader::~ComputeShader() {
kinc_g4_compute_shader_destroy(&kincImpl);
}

Graphics4::ConstantLocation Graphics4::ComputeShader::getConstantLocation(const char *name) {
Graphics4::ConstantLocation location;
location.kincConstant = kinc_g4_compute_shader_get_constant_location(&kincImpl, name);
return location;
}

Graphics4::TextureUnit Graphics4::ComputeShader::getTextureUnit(const char *name) {
Graphics4::TextureUnit unit;
unit.kincUnit = kinc_g4_compute_shader_get_texture_unit(&kincImpl, name);
return unit;
}

#ifdef KORE_OPENGL
Graphics4::ShaderStorageBuffer::ShaderStorageBuffer(int count, Graphics4::VertexData type) {
kinc_shader_storage_buffer_init(&kincImpl, count, (kinc_g4_vertex_data_t)type);
}

Graphics4::ShaderStorageBuffer::~ShaderStorageBuffer() {
kinc_shader_storage_buffer_destroy(&kincImpl);
}

int *Graphics4::ShaderStorageBuffer::lock() {
return kinc_shader_storage_buffer_lock(&kincImpl);
}

void Graphics4::ShaderStorageBuffer::unlock() {
kinc_shader_storage_buffer_unlock(&kincImpl);
}

int Graphics4::ShaderStorageBuffer::count() {
return kinc_shader_storage_buffer_count(&kincImpl);
}

void Graphics4::ShaderStorageBuffer::_set() {
kinc_shader_storage_buffer_internal_set(&kincImpl);
}
#endif
38 changes: 38 additions & 0 deletions Sources/Kore/Graphics4/Compute.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <kinc/graphics4/compute.h>

#ifdef KORE_OPENGL
#include <kinc/backend/graphics4/ShaderStorageBufferImpl.h>
#endif
#include <Kore/Graphics4/Graphics.h>
#include <Kore/Math/Matrix.h>

namespace Kore {
namespace Graphics4 {
class Texture;
class RenderTarget;

class ComputeShader {
public:
ComputeShader(void *source, int length);
~ComputeShader();
ConstantLocation getConstantLocation(const char *name);
TextureUnit getTextureUnit(const char *name);
kinc_g4_compute_shader kincImpl;
};

#ifdef KORE_OPENGL
class ShaderStorageBuffer {
public:
ShaderStorageBuffer(int count, Graphics4::VertexData type);
virtual ~ShaderStorageBuffer();
int *lock();
void unlock();
int count();
void _set();
kinc_shader_storage_buffer_t kincImpl;
};
#endif
}
}
15 changes: 15 additions & 0 deletions Sources/Kore/Graphics4/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <kinc/graphics4/graphics.h>

#include <Kore/Graphics4/Compute.h>
#include <Kore/Graphics4/TextureArray.h>

#include <assert.h>
Expand Down Expand Up @@ -285,4 +286,18 @@ void Graphics4::_changeFramebuffer(int window, struct kinc_framebuffer_options *
kinc_internal_change_framebuffer(window, frame);
}

#ifdef KORE_OPENGL
void Graphics4::setShaderStorageBuffer(ShaderStorageBuffer *buffer, int index) {
kinc_g4_set_shader_storage_buffer(&buffer->kincImpl, index);
}
#endif

void Graphics4::setComputeShader(ComputeShader *shader) {
kinc_g4_set_compute_shader(&shader->kincImpl);
}

void Graphics4::compute(int x, int y, int z) {
kinc_g4_compute(x, y, z);
}

#endif
10 changes: 10 additions & 0 deletions Sources/Kore/Graphics4/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ struct kinc_framebuffer_options;

namespace Kore {
namespace Graphics4 {
class ComputeShader;
class PipelineState;
class TextureArray;
#ifdef KORE_OPENGL
class ShaderStorageBuffer;
#endif

class VertexBuffer {
public:
Expand Down Expand Up @@ -178,6 +182,12 @@ namespace Kore {
void setRenderTargetFace(RenderTarget *texture, int face = 0);
void restoreRenderTarget();

#ifdef KORE_OPENGL
void setShaderStorageBuffer(ShaderStorageBuffer *buffer, int index);
#endif
void setComputeShader(ComputeShader *shader);
void compute(int x, int y, int z);

void begin(int window = 0);
void end(int window = 0);
bool swapBuffers();
Expand Down
Loading

0 comments on commit fea7124

Please sign in to comment.