Skip to content

Commit

Permalink
Make a pipeline compile
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 2, 2024
1 parent 8e0449e commit 9eaa786
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
#include "commandlist.cpp"
#include "device.cpp"
#include "pipeline.cpp"
#include "shader.cpp"
#include "texture.cpp"
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "pipeline_functions.h"
#include "pipeline_structs.h"

#include "shader_structs.h"

#include <kinc/log.h>

#include <kinc/backend/SystemMicrosoft.h>
Expand Down Expand Up @@ -147,14 +145,14 @@ static void set_blend_state(D3D12_BLEND_DESC *desc, const kope_d3d12_color_targe
desc->RenderTarget[target].SrcBlendAlpha = convert_blend_factor(target_state->blend.alpha.src_factor);
desc->RenderTarget[target].DestBlendAlpha = convert_blend_factor(target_state->blend.alpha.dst_factor);
desc->RenderTarget[target].BlendOpAlpha = convert_blend_operation(target_state->blend.alpha.operation);
desc->RenderTarget[target].RenderTargetWriteMask = target_state->write_mask;
desc->RenderTarget[target].RenderTargetWriteMask = (UINT8)target_state->write_mask;
}

void kope_d3d12_pipeline_init(kope_d3d12_device *device, kope_d3d12_pipeline *pipe, const kope_d3d12_pipeline_parameters *parameters) {
D3D12_GRAPHICS_PIPELINE_STATE_DESC desc = {0};

desc.VS.BytecodeLength = parameters->vertex.shader->size;
desc.VS.pShaderBytecode = parameters->vertex.shader->data;
desc.VS.BytecodeLength = parameters->vertex.shader.size;
desc.VS.pShaderBytecode = parameters->vertex.shader.data;

assert(parameters->vertex.buffers_count <= KOPE_D3D12_MAX_VERTEX_ATTRIBUTES);
D3D12_INPUT_ELEMENT_DESC input_elements[KOPE_D3D12_MAX_VERTEX_ATTRIBUTES] = {0};
Expand Down Expand Up @@ -279,7 +277,7 @@ void kope_d3d12_pipeline_init(kope_d3d12_device *device, kope_d3d12_pipeline *pi

desc.PrimitiveTopologyType = convert_primitive_topology(parameters->primitive.topology);

desc.RasterizerState.FrontCounterClockwise = parameters->primitive.frontFace == KOPE_D3D12_FRONT_FACE_CCW ? TRUE : FALSE;
desc.RasterizerState.FrontCounterClockwise = parameters->primitive.front_face == KOPE_D3D12_FRONT_FACE_CCW ? TRUE : FALSE;
desc.RasterizerState.CullMode = convert_cull_mode(parameters->primitive.cull_mode);

desc.RasterizerState.DepthClipEnable = parameters->primitive.unclipped_depth ? FALSE : TRUE;
Expand Down Expand Up @@ -319,8 +317,8 @@ void kope_d3d12_pipeline_init(kope_d3d12_device *device, kope_d3d12_pipeline *pi
desc.SampleMask = 0xFFFFFFFF;
desc.BlendState.AlphaToCoverageEnable = parameters->multisample.alpha_to_coverage_enabled ? TRUE : FALSE;

desc.PS.BytecodeLength = parameters->fragment.shader->size;
desc.PS.pShaderBytecode = parameters->fragment.shader->data;
desc.PS.BytecodeLength = parameters->fragment.shader.size;
desc.PS.pShaderBytecode = parameters->fragment.shader.data;

desc.NumRenderTargets = (UINT)parameters->fragment.targets_count;
assert(parameters->fragment.targets_count <= KOPE_D3D12_MAX_COLOR_TARGETS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef KOPE_D3D12_PIPELINE_STRUCTS_HEADER
#define KOPE_D3D12_PIPELINE_STRUCTS_HEADER

#include "shader_structs.h"

#include <kope/graphics5/buffer.h>
#include <kope/graphics5/commandlist.h>
#include <kope/graphics5/device.h>
#include <kope/graphics5/texture.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -61,10 +61,15 @@ typedef struct kope_d3d12_vertex_buffer_layout {
size_t attributes_count;
} kope_d3d12_vertex_buffer_layout;

typedef struct kope_d3d12_shader {
uint8_t *data;
size_t size;
} kope_d3d12_shader;

#define KOPE_D3D12_MAX_VERTEX_BUFFERS 16

typedef struct kope_d3d12_vertex_state {
kope_d3d12_shader *shader;
kope_d3d12_shader shader;
kope_d3d12_vertex_buffer_layout buffers[KOPE_D3D12_MAX_VERTEX_BUFFERS];
size_t buffers_count;
} kope_d3d12_vertex_state;
Expand All @@ -84,7 +89,7 @@ typedef enum kope_d3d12_cull_mode { KOPE_D3D12_CULL_MODE_NONE, KOPE_D3D12_CULL_M
typedef struct kope_d3d12_primitive_state {
kope_d3d12_primitive_topology topology;
kope_g5_index_format strip_index_format;
kope_d3d12_front_face frontFace;
kope_d3d12_front_face front_face;
kope_d3d12_cull_mode cull_mode;
bool unclipped_depth;
} kope_d3d12_primitive_state;
Expand Down Expand Up @@ -189,7 +194,7 @@ typedef struct kope_d3d12_color_target_state {
#define KOPE_D3D12_MAX_COLOR_TARGETS 8

typedef struct kope_d3d12_fragment_state {
kope_d3d12_shader *shader;
kope_d3d12_shader shader;
kope_d3d12_color_target_state targets[KOPE_D3D12_MAX_COLOR_TARGETS];
size_t targets_count;
} kope_d3d12_fragment_state;
Expand Down
12 changes: 0 additions & 12 deletions Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/shader.cpp

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 6 additions & 7 deletions Backends/System/Windows/Sources/kinc/backend/system.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1076,9 +1076,8 @@ 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)
{
// if gamepad is greater than XInput max, treat it as DINPUT.
if (gamepad >= XUSER_MAX_COUNT) {
return false;
}
XINPUT_STATE state;
Expand Down Expand Up @@ -1169,9 +1168,9 @@ bool kinc_internal_handle_messages() {
}
}
else {
if (handleDirectInputPad(i)) {
gamepadFound = true;
}
if (handleDirectInputPad(i)) {
gamepadFound = true;
}
}
}
}
Expand Down Expand Up @@ -1416,7 +1415,7 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi
loadXInput();
initializeDirectInput();

#ifdef KINC_KONG
#if defined(KINC_KONG) && !defined(KOPE)
kong_init();
#endif

Expand Down
22 changes: 16 additions & 6 deletions Sources/kinc/graphics1/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <kinc/io/filereader.h>
#include <kinc/log.h>

#ifndef KOPE

#ifdef KINC_KONG
#include <kong.h>
#endif
Expand Down Expand Up @@ -36,9 +38,12 @@ void kinc_g1_begin(void) {

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;
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);
Expand All @@ -47,9 +52,12 @@ static inline kinc_g4_texture_filter_t map_texture_filter(kinc_g1_texture_filter

static inline kinc_g4_texture_filter_t map_mipmap_filter(kinc_g1_texture_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;
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);
Expand Down Expand Up @@ -214,3 +222,5 @@ void kinc_g1_set_texture_mipmap_filter(kinc_g1_mipmap_filter_t filter) {
}

#endif

#endif
2 changes: 1 addition & 1 deletion Sources/kinc/graphics2/g2unit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef KINC_KONG
#if defined(KINC_KONG) && !defined(KOPE)
#include "colored_painter.c.h"
#include "image_painter.c.h"
#include "text_painter.c.h"
Expand Down

0 comments on commit 9eaa786

Please sign in to comment.