Merge branch 'nightly' of https://github.com/KiritoDv/sm64pc into nightly

This commit is contained in:
NoHomoBoi 2020-06-11 22:40:55 -05:00
commit 2fa7e4f4ba
29 changed files with 33658 additions and 113 deletions

114
Makefile
View File

@ -54,9 +54,16 @@ DISCORDRPC ?= 0
NO_BZERO_BCOPY ?= 0
NO_LDIV ?= 0
# Use OpenGL 1.3 renderer
# Backend selection
LEGACY_GL ?= 0
# Renderers: GL, GL_LEGACY, D3D11, D3D12
RENDER_API ?= GL
# Window managers: SDL2, DXGI (forced if D3D11 or D3D12 in RENDER_API)
WINDOW_API ?= SDL2
# Audio backends: SDL2
AUDIO_API ?= SDL2
# Controller backends (can have multiple, space separated): SDL2
CONTROLLER_API ?= SDL2
# Misc settings for EXTERNAL_DATA
@ -207,6 +214,22 @@ ifeq ($(TARGET_WEB),1)
VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_WEB
endif
# Check backends
ifneq (,$(filter $(RENDER_API),D3D11 D3D12))
ifneq ($(WINDOWS_BUILD),1)
$(error DirectX is only supported on Windows)
endif
ifneq ($(WINDOW_API),DXGI)
$(warning DirectX renderers require DXGI, forcing WINDOW_API value)
WINDOW_API := DXGI
endif
else
ifeq ($(WINDOW_API),DXGI)
$(error DXGI can only be used with DirectX renderers)
endif
endif
################### Universal Dependencies ###################
# (This is a bit hacky, but a lot of rules implicitly depend
@ -515,18 +538,69 @@ endif
PYTHON := python3
SDLCONFIG := $(CROSS)sdl2-config
# configure backend flags
BACKEND_CFLAGS := -DRAPI_$(RENDER_API)=1 -DWAPI_$(WINDOW_API)=1 -DAAPI_$(AUDIO_API)=1
# can have multiple controller APIs
BACKEND_CFLAGS += $(foreach capi,$(CONTROLLER_API),-DCAPI_$(capi)=1)
BACKEND_LDFLAGS :=
SDL2_USED := 0
# for now, it's either SDL+GL or DXGI+DirectX, so choose based on WAPI
ifeq ($(WINDOW_API),DXGI)
DXBITS := `cat $(ENDIAN_BITWIDTH) | tr ' ' '\n' | tail -1`
ifeq ($(RENDER_API),D3D11)
BACKEND_LDFLAGS += -ld3d11
else ifeq ($(RENDER_API),D3D12)
BACKEND_LDFLAGS += -ld3d12
BACKEND_CFLAGS += -Iinclude/dxsdk
endif
BACKEND_LDFLAGS += -ld3dcompiler -ldxgi -ldxguid
BACKEND_LDFLAGS += -lsetupapi -ldinput8 -luser32 -lgdi32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion -luuid -static
else ifeq ($(WINDOW_API),SDL2)
ifeq ($(WINDOWS_BUILD),1)
BACKEND_LDFLAGS += -lglew32 -lglu32 -lopengl32
else ifeq ($(TARGET_RPI),1)
BACKEND_LDFLAGS += -lGLESv2
else ifeq ($(OSX_BUILD),1)
BACKEND_LDFLAGS += -framework OpenGL `pkg-config --libs glew`
else
BACKEND_LDFLAGS += -lGL
endif
SDL_USED := 2
endif
ifeq ($(AUDIO_API),SDL2)
SDL_USED := 2
endif
ifneq (,$(findstring SDL,$(CONTROLLER_API)))
SDL_USED := 2
endif
# SDL can be used by different systems, so we consolidate all of that shit into this
ifeq ($(SDL_USED),2)
BACKEND_CFLAGS += -DHAVE_SDL2=1 `$(SDLCONFIG) --cflags`
ifeq ($(WINDOWS_BUILD),1)
BACKEND_LDFLAGS += `$(SDLCONFIG) --static-libs` -lsetupapi -luser32 -limm32 -lOle32 -loleaut32 -lshell32 -lwinmm -lversion
else
BACKEND_LDFLAGS += `$(SDLCONFIG) --libs`
endif
endif
ifeq ($(WINDOWS_BUILD),1)
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) `$(SDLCONFIG) --cflags` -DUSE_SDL=2
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv `$(SDLCONFIG) --cflags` -DUSE_SDL=2
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv
else ifeq ($(TARGET_WEB),1)
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -s USE_SDL=2
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv -s USE_SDL=2
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -s USE_SDL=2
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv -s USE_SDL=2
# Linux / Other builds below
else
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) `$(SDLCONFIG) --cflags` -DUSE_SDL=2
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv `$(SDLCONFIG) --cflags` -DUSE_SDL=2
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv
endif
# Check for enhancement options
@ -598,26 +672,28 @@ ASFLAGS := -I include -I $(BUILD_DIR) $(VERSION_ASFLAGS)
ifeq ($(TARGET_WEB),1)
LDFLAGS := -lm -lGL -lSDL2 -no-pie -s TOTAL_MEMORY=20MB -g4 --source-map-base http://localhost:8080/ -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain']"
else ifeq ($(WINDOWS_BUILD),1)
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -Llib -lpthread -lglew32 `$(SDLCONFIG) --static-libs` -lm -lglu32 -lsetupapi -ldinput8 -luser32 -lgdi32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion -luuid -lopengl32 -static
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -Llib -lpthread $(BACKEND_LDFLAGS) -static
ifeq ($(CROSS),)
LDFLAGS += -no-pie
endif
ifeq ($(WINDOWS_CONSOLE),1)
LDFLAGS += -mconsole
endif
else ifeq ($(TARGET_RPI),1)
# Linux / Other builds below
LDFLAGS := $(OPT_FLAGS) -lm -lGLESv2 `$(SDLCONFIG) --libs` -no-pie
LDFLAGS := $(OPT_FLAGS) -lm $(BACKEND_LDFLAGS) -no-pie
else ifeq ($(OSX_BUILD),1)
LDFLAGS := -lm $(BACKEND_LDFLAGS) -no-pie -lpthread
else
ifeq ($(OSX_BUILD),1)
LDFLAGS := -lm -framework OpenGL `$(SDLCONFIG) --libs` -no-pie -lpthread `pkg-config --libs libusb-1.0 glfw3 glew`
else
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -lm -lGL `$(SDLCONFIG) --libs` -no-pie -lpthread
ifeq ($(DISCORDRPC),1)
LDFLAGS += -ldl -Wl,-rpath .
endif
endif
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -lm $(BACKEND_LDFLAGS) -no-pie -lpthread
ifeq ($(DISCORDRPC),1)
LDFLAGS += -ldl -Wl,-rpath .
endif
endif # End of LDFLAGS
# Prevent a crash with -sopt

17258
include/dxsdk/d3d12.h Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

459
include/dxsdk/d3d12shader.h Normal file
View File

@ -0,0 +1,459 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: D3D12Shader.h
// Content: D3D12 Shader Types and APIs
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __D3D12SHADER_H__
#define __D3D12SHADER_H__
#include "d3dcommon.h"
typedef enum D3D12_SHADER_VERSION_TYPE
{
D3D12_SHVER_PIXEL_SHADER = 0,
D3D12_SHVER_VERTEX_SHADER = 1,
D3D12_SHVER_GEOMETRY_SHADER = 2,
// D3D11 Shaders
D3D12_SHVER_HULL_SHADER = 3,
D3D12_SHVER_DOMAIN_SHADER = 4,
D3D12_SHVER_COMPUTE_SHADER = 5,
D3D12_SHVER_RESERVED0 = 0xFFF0,
} D3D12_SHADER_VERSION_TYPE;
#define D3D12_SHVER_GET_TYPE(_Version) \
(((_Version) >> 16) & 0xffff)
#define D3D12_SHVER_GET_MAJOR(_Version) \
(((_Version) >> 4) & 0xf)
#define D3D12_SHVER_GET_MINOR(_Version) \
(((_Version) >> 0) & 0xf)
// Slot ID for library function return
#define D3D_RETURN_PARAMETER_INDEX (-1)
typedef D3D_RESOURCE_RETURN_TYPE D3D12_RESOURCE_RETURN_TYPE;
typedef D3D_CBUFFER_TYPE D3D12_CBUFFER_TYPE;
typedef struct _D3D12_SIGNATURE_PARAMETER_DESC
{
LPCSTR SemanticName; // Name of the semantic
UINT SemanticIndex; // Index of the semantic
UINT Register; // Number of member variables
D3D_NAME SystemValueType;// A predefined system value, or D3D_NAME_UNDEFINED if not applicable
D3D_REGISTER_COMPONENT_TYPE ComponentType; // Scalar type (e.g. uint, float, etc.)
BYTE Mask; // Mask to indicate which components of the register
// are used (combination of D3D10_COMPONENT_MASK values)
BYTE ReadWriteMask; // Mask to indicate whether a given component is
// never written (if this is an output signature) or
// always read (if this is an input signature).
// (combination of D3D_MASK_* values)
UINT Stream; // Stream index
D3D_MIN_PRECISION MinPrecision; // Minimum desired interpolation precision
} D3D12_SIGNATURE_PARAMETER_DESC;
typedef struct _D3D12_SHADER_BUFFER_DESC
{
LPCSTR Name; // Name of the constant buffer
D3D_CBUFFER_TYPE Type; // Indicates type of buffer content
UINT Variables; // Number of member variables
UINT Size; // Size of CB (in bytes)
UINT uFlags; // Buffer description flags
} D3D12_SHADER_BUFFER_DESC;
typedef struct _D3D12_SHADER_VARIABLE_DESC
{
LPCSTR Name; // Name of the variable
UINT StartOffset; // Offset in constant buffer's backing store
UINT Size; // Size of variable (in bytes)
UINT uFlags; // Variable flags
LPVOID DefaultValue; // Raw pointer to default value
UINT StartTexture; // First texture index (or -1 if no textures used)
UINT TextureSize; // Number of texture slots possibly used.
UINT StartSampler; // First sampler index (or -1 if no textures used)
UINT SamplerSize; // Number of sampler slots possibly used.
} D3D12_SHADER_VARIABLE_DESC;
typedef struct _D3D12_SHADER_TYPE_DESC
{
D3D_SHADER_VARIABLE_CLASS Class; // Variable class (e.g. object, matrix, etc.)
D3D_SHADER_VARIABLE_TYPE Type; // Variable type (e.g. float, sampler, etc.)
UINT Rows; // Number of rows (for matrices, 1 for other numeric, 0 if not applicable)
UINT Columns; // Number of columns (for vectors & matrices, 1 for other numeric, 0 if not applicable)
UINT Elements; // Number of elements (0 if not an array)
UINT Members; // Number of members (0 if not a structure)
UINT Offset; // Offset from the start of structure (0 if not a structure member)
LPCSTR Name; // Name of type, can be NULL
} D3D12_SHADER_TYPE_DESC;
typedef D3D_TESSELLATOR_DOMAIN D3D12_TESSELLATOR_DOMAIN;
typedef D3D_TESSELLATOR_PARTITIONING D3D12_TESSELLATOR_PARTITIONING;
typedef D3D_TESSELLATOR_OUTPUT_PRIMITIVE D3D12_TESSELLATOR_OUTPUT_PRIMITIVE;
typedef struct _D3D12_SHADER_DESC
{
UINT Version; // Shader version
LPCSTR Creator; // Creator string
UINT Flags; // Shader compilation/parse flags
UINT ConstantBuffers; // Number of constant buffers
UINT BoundResources; // Number of bound resources
UINT InputParameters; // Number of parameters in the input signature
UINT OutputParameters; // Number of parameters in the output signature
UINT InstructionCount; // Number of emitted instructions
UINT TempRegisterCount; // Number of temporary registers used
UINT TempArrayCount; // Number of temporary arrays used
UINT DefCount; // Number of constant defines
UINT DclCount; // Number of declarations (input + output)
UINT TextureNormalInstructions; // Number of non-categorized texture instructions
UINT TextureLoadInstructions; // Number of texture load instructions
UINT TextureCompInstructions; // Number of texture comparison instructions
UINT TextureBiasInstructions; // Number of texture bias instructions
UINT TextureGradientInstructions; // Number of texture gradient instructions
UINT FloatInstructionCount; // Number of floating point arithmetic instructions used
UINT IntInstructionCount; // Number of signed integer arithmetic instructions used
UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used
UINT StaticFlowControlCount; // Number of static flow control instructions used
UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used
UINT MacroInstructionCount; // Number of macro instructions used
UINT ArrayInstructionCount; // Number of array instructions used
UINT CutInstructionCount; // Number of cut instructions used
UINT EmitInstructionCount; // Number of emit instructions used
D3D_PRIMITIVE_TOPOLOGY GSOutputTopology; // Geometry shader output topology
UINT GSMaxOutputVertexCount; // Geometry shader maximum output vertex count
D3D_PRIMITIVE InputPrimitive; // GS/HS input primitive
UINT PatchConstantParameters; // Number of parameters in the patch constant signature
UINT cGSInstanceCount; // Number of Geometry shader instances
UINT cControlPoints; // Number of control points in the HS->DS stage
D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive; // Primitive output by the tessellator
D3D_TESSELLATOR_PARTITIONING HSPartitioning; // Partitioning mode of the tessellator
D3D_TESSELLATOR_DOMAIN TessellatorDomain; // Domain of the tessellator (quad, tri, isoline)
// instruction counts
UINT cBarrierInstructions; // Number of barrier instructions in a compute shader
UINT cInterlockedInstructions; // Number of interlocked instructions
UINT cTextureStoreInstructions; // Number of texture writes
} D3D12_SHADER_DESC;
typedef struct _D3D12_SHADER_INPUT_BIND_DESC
{
LPCSTR Name; // Name of the resource
D3D_SHADER_INPUT_TYPE Type; // Type of resource (e.g. texture, cbuffer, etc.)
UINT BindPoint; // Starting bind point
UINT BindCount; // Number of contiguous bind points (for arrays)
UINT uFlags; // Input binding flags
D3D_RESOURCE_RETURN_TYPE ReturnType; // Return type (if texture)
D3D_SRV_DIMENSION Dimension; // Dimension (if texture)
UINT NumSamples; // Number of samples (0 if not MS texture)
UINT Space; // Register space
UINT uID; // Range ID in the bytecode
} D3D12_SHADER_INPUT_BIND_DESC;
#define D3D_SHADER_REQUIRES_DOUBLES 0x00000001
#define D3D_SHADER_REQUIRES_EARLY_DEPTH_STENCIL 0x00000002
#define D3D_SHADER_REQUIRES_UAVS_AT_EVERY_STAGE 0x00000004
#define D3D_SHADER_REQUIRES_64_UAVS 0x00000008
#define D3D_SHADER_REQUIRES_MINIMUM_PRECISION 0x00000010
#define D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS 0x00000020
#define D3D_SHADER_REQUIRES_11_1_SHADER_EXTENSIONS 0x00000040
#define D3D_SHADER_REQUIRES_LEVEL_9_COMPARISON_FILTERING 0x00000080
#define D3D_SHADER_REQUIRES_TILED_RESOURCES 0x00000100
#define D3D_SHADER_REQUIRES_STENCIL_REF 0x00000200
#define D3D_SHADER_REQUIRES_INNER_COVERAGE 0x00000400
#define D3D_SHADER_REQUIRES_TYPED_UAV_LOAD_ADDITIONAL_FORMATS 0x00000800
#define D3D_SHADER_REQUIRES_ROVS 0x00001000
#define D3D_SHADER_REQUIRES_VIEWPORT_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER_FEEDING_RASTERIZER 0x00002000
typedef struct _D3D12_LIBRARY_DESC
{
LPCSTR Creator; // The name of the originator of the library.
UINT Flags; // Compilation flags.
UINT FunctionCount; // Number of functions exported from the library.
} D3D12_LIBRARY_DESC;
typedef struct _D3D12_FUNCTION_DESC
{
UINT Version; // Shader version
LPCSTR Creator; // Creator string
UINT Flags; // Shader compilation/parse flags
UINT ConstantBuffers; // Number of constant buffers
UINT BoundResources; // Number of bound resources
UINT InstructionCount; // Number of emitted instructions
UINT TempRegisterCount; // Number of temporary registers used
UINT TempArrayCount; // Number of temporary arrays used
UINT DefCount; // Number of constant defines
UINT DclCount; // Number of declarations (input + output)
UINT TextureNormalInstructions; // Number of non-categorized texture instructions
UINT TextureLoadInstructions; // Number of texture load instructions
UINT TextureCompInstructions; // Number of texture comparison instructions
UINT TextureBiasInstructions; // Number of texture bias instructions
UINT TextureGradientInstructions; // Number of texture gradient instructions
UINT FloatInstructionCount; // Number of floating point arithmetic instructions used
UINT IntInstructionCount; // Number of signed integer arithmetic instructions used
UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used
UINT StaticFlowControlCount; // Number of static flow control instructions used
UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used
UINT MacroInstructionCount; // Number of macro instructions used
UINT ArrayInstructionCount; // Number of array instructions used
UINT MovInstructionCount; // Number of mov instructions used
UINT MovcInstructionCount; // Number of movc instructions used
UINT ConversionInstructionCount; // Number of type conversion instructions used
UINT BitwiseInstructionCount; // Number of bitwise arithmetic instructions used
D3D_FEATURE_LEVEL MinFeatureLevel; // Min target of the function byte code
UINT64 RequiredFeatureFlags; // Required feature flags
LPCSTR Name; // Function name
INT FunctionParameterCount; // Number of logical parameters in the function signature (not including return)
BOOL HasReturn; // TRUE, if function returns a value, false - it is a subroutine
BOOL Has10Level9VertexShader; // TRUE, if there is a 10L9 VS blob
BOOL Has10Level9PixelShader; // TRUE, if there is a 10L9 PS blob
} D3D12_FUNCTION_DESC;
typedef struct _D3D12_PARAMETER_DESC
{
LPCSTR Name; // Parameter name.
LPCSTR SemanticName; // Parameter semantic name (+index).
D3D_SHADER_VARIABLE_TYPE Type; // Element type.
D3D_SHADER_VARIABLE_CLASS Class; // Scalar/Vector/Matrix.
UINT Rows; // Rows are for matrix parameters.
UINT Columns; // Components or Columns in matrix.
D3D_INTERPOLATION_MODE InterpolationMode; // Interpolation mode.
D3D_PARAMETER_FLAGS Flags; // Parameter modifiers.
UINT FirstInRegister; // The first input register for this parameter.
UINT FirstInComponent; // The first input register component for this parameter.
UINT FirstOutRegister; // The first output register for this parameter.
UINT FirstOutComponent; // The first output register component for this parameter.
} D3D12_PARAMETER_DESC;
//////////////////////////////////////////////////////////////////////////////
// Interfaces ////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
typedef interface ID3D12ShaderReflectionType ID3D12ShaderReflectionType;
typedef interface ID3D12ShaderReflectionType *LPD3D12SHADERREFLECTIONTYPE;
typedef interface ID3D12ShaderReflectionVariable ID3D12ShaderReflectionVariable;
typedef interface ID3D12ShaderReflectionVariable *LPD3D12SHADERREFLECTIONVARIABLE;
typedef interface ID3D12ShaderReflectionConstantBuffer ID3D12ShaderReflectionConstantBuffer;
typedef interface ID3D12ShaderReflectionConstantBuffer *LPD3D12SHADERREFLECTIONCONSTANTBUFFER;
typedef interface ID3D12ShaderReflection ID3D12ShaderReflection;
typedef interface ID3D12ShaderReflection *LPD3D12SHADERREFLECTION;
typedef interface ID3D12LibraryReflection ID3D12LibraryReflection;
typedef interface ID3D12LibraryReflection *LPD3D12LIBRARYREFLECTION;
typedef interface ID3D12FunctionReflection ID3D12FunctionReflection;
typedef interface ID3D12FunctionReflection *LPD3D12FUNCTIONREFLECTION;
typedef interface ID3D12FunctionParameterReflection ID3D12FunctionParameterReflection;
typedef interface ID3D12FunctionParameterReflection *LPD3D12FUNCTIONPARAMETERREFLECTION;
// {E913C351-783D-48CA-A1D1-4F306284AD56}
interface DECLSPEC_UUID("E913C351-783D-48CA-A1D1-4F306284AD56") ID3D12ShaderReflectionType;
DEFINE_GUID(IID_ID3D12ShaderReflectionType,
0xe913c351, 0x783d, 0x48ca, 0xa1, 0xd1, 0x4f, 0x30, 0x62, 0x84, 0xad, 0x56);
#undef INTERFACE
#define INTERFACE ID3D12ShaderReflectionType
DECLARE_INTERFACE(ID3D12ShaderReflectionType)
{
STDMETHOD(GetDesc)(THIS_ _Out_ D3D12_SHADER_TYPE_DESC *pDesc) PURE;
STDMETHOD_(ID3D12ShaderReflectionType*, GetMemberTypeByIndex)(THIS_ _In_ UINT Index) PURE;
STDMETHOD_(ID3D12ShaderReflectionType*, GetMemberTypeByName)(THIS_ _In_ LPCSTR Name) PURE;
STDMETHOD_(LPCSTR, GetMemberTypeName)(THIS_ _In_ UINT Index) PURE;
STDMETHOD(IsEqual)(THIS_ _In_ ID3D12ShaderReflectionType* pType) PURE;
STDMETHOD_(ID3D12ShaderReflectionType*, GetSubType)(THIS) PURE;
STDMETHOD_(ID3D12ShaderReflectionType*, GetBaseClass)(THIS) PURE;
STDMETHOD_(UINT, GetNumInterfaces)(THIS) PURE;
STDMETHOD_(ID3D12ShaderReflectionType*, GetInterfaceByIndex)(THIS_ _In_ UINT uIndex) PURE;
STDMETHOD(IsOfType)(THIS_ _In_ ID3D12ShaderReflectionType* pType) PURE;
STDMETHOD(ImplementsInterface)(THIS_ _In_ ID3D12ShaderReflectionType* pBase) PURE;
};
// {8337A8A6-A216-444A-B2F4-314733A73AEA}
interface DECLSPEC_UUID("8337A8A6-A216-444A-B2F4-314733A73AEA") ID3D12ShaderReflectionVariable;
DEFINE_GUID(IID_ID3D12ShaderReflectionVariable,
0x8337a8a6, 0xa216, 0x444a, 0xb2, 0xf4, 0x31, 0x47, 0x33, 0xa7, 0x3a, 0xea);
#undef INTERFACE
#define INTERFACE ID3D12ShaderReflectionVariable
DECLARE_INTERFACE(ID3D12ShaderReflectionVariable)
{
STDMETHOD(GetDesc)(THIS_ _Out_ D3D12_SHADER_VARIABLE_DESC *pDesc) PURE;
STDMETHOD_(ID3D12ShaderReflectionType*, GetType)(THIS) PURE;
STDMETHOD_(ID3D12ShaderReflectionConstantBuffer*, GetBuffer)(THIS) PURE;
STDMETHOD_(UINT, GetInterfaceSlot)(THIS_ _In_ UINT uArrayIndex) PURE;
};
// {C59598B4-48B3-4869-B9B1-B1618B14A8B7}
interface DECLSPEC_UUID("C59598B4-48B3-4869-B9B1-B1618B14A8B7") ID3D12ShaderReflectionConstantBuffer;
DEFINE_GUID(IID_ID3D12ShaderReflectionConstantBuffer,
0xc59598b4, 0x48b3, 0x4869, 0xb9, 0xb1, 0xb1, 0x61, 0x8b, 0x14, 0xa8, 0xb7);
#undef INTERFACE
#define INTERFACE ID3D12ShaderReflectionConstantBuffer
DECLARE_INTERFACE(ID3D12ShaderReflectionConstantBuffer)
{
STDMETHOD(GetDesc)(THIS_ D3D12_SHADER_BUFFER_DESC *pDesc) PURE;
STDMETHOD_(ID3D12ShaderReflectionVariable*, GetVariableByIndex)(THIS_ _In_ UINT Index) PURE;
STDMETHOD_(ID3D12ShaderReflectionVariable*, GetVariableByName)(THIS_ _In_ LPCSTR Name) PURE;
};
// The ID3D12ShaderReflection IID may change from SDK version to SDK version
// if the reflection API changes. This prevents new code with the new API
// from working with an old binary. Recompiling with the new header
// will pick up the new IID.
// {5A58797D-A72C-478D-8BA2-EFC6B0EFE88E}
interface DECLSPEC_UUID("5A58797D-A72C-478D-8BA2-EFC6B0EFE88E") ID3D12ShaderReflection;
DEFINE_GUID(IID_ID3D12ShaderReflection,
0x5a58797d, 0xa72c, 0x478d, 0x8b, 0xa2, 0xef, 0xc6, 0xb0, 0xef, 0xe8, 0x8e);
#undef INTERFACE
#define INTERFACE ID3D12ShaderReflection
DECLARE_INTERFACE_(ID3D12ShaderReflection, IUnknown)
{
STDMETHOD(QueryInterface)(THIS_ _In_ REFIID iid,
_Out_ LPVOID *ppv) PURE;
STDMETHOD_(ULONG, AddRef)(THIS) PURE;
STDMETHOD_(ULONG, Release)(THIS) PURE;
STDMETHOD(GetDesc)(THIS_ _Out_ D3D12_SHADER_DESC *pDesc) PURE;
STDMETHOD_(ID3D12ShaderReflectionConstantBuffer*, GetConstantBufferByIndex)(THIS_ _In_ UINT Index) PURE;
STDMETHOD_(ID3D12ShaderReflectionConstantBuffer*, GetConstantBufferByName)(THIS_ _In_ LPCSTR Name) PURE;
STDMETHOD(GetResourceBindingDesc)(THIS_ _In_ UINT ResourceIndex,
_Out_ D3D12_SHADER_INPUT_BIND_DESC *pDesc) PURE;
STDMETHOD(GetInputParameterDesc)(THIS_ _In_ UINT ParameterIndex,
_Out_ D3D12_SIGNATURE_PARAMETER_DESC *pDesc) PURE;
STDMETHOD(GetOutputParameterDesc)(THIS_ _In_ UINT ParameterIndex,
_Out_ D3D12_SIGNATURE_PARAMETER_DESC *pDesc) PURE;
STDMETHOD(GetPatchConstantParameterDesc)(THIS_ _In_ UINT ParameterIndex,
_Out_ D3D12_SIGNATURE_PARAMETER_DESC *pDesc) PURE;
STDMETHOD_(ID3D12ShaderReflectionVariable*, GetVariableByName)(THIS_ _In_ LPCSTR Name) PURE;
STDMETHOD(GetResourceBindingDescByName)(THIS_ _In_ LPCSTR Name,
_Out_ D3D12_SHADER_INPUT_BIND_DESC *pDesc) PURE;
STDMETHOD_(UINT, GetMovInstructionCount)(THIS) PURE;
STDMETHOD_(UINT, GetMovcInstructionCount)(THIS) PURE;
STDMETHOD_(UINT, GetConversionInstructionCount)(THIS) PURE;
STDMETHOD_(UINT, GetBitwiseInstructionCount)(THIS) PURE;
STDMETHOD_(D3D_PRIMITIVE, GetGSInputPrimitive)(THIS) PURE;
STDMETHOD_(BOOL, IsSampleFrequencyShader)(THIS) PURE;
STDMETHOD_(UINT, GetNumInterfaceSlots)(THIS) PURE;
STDMETHOD(GetMinFeatureLevel)(THIS_ _Out_ enum D3D_FEATURE_LEVEL* pLevel) PURE;
STDMETHOD_(UINT, GetThreadGroupSize)(THIS_
_Out_opt_ UINT* pSizeX,
_Out_opt_ UINT* pSizeY,
_Out_opt_ UINT* pSizeZ) PURE;
STDMETHOD_(UINT64, GetRequiresFlags)(THIS) PURE;
};
// {8E349D19-54DB-4A56-9DC9-119D87BDB804}
interface DECLSPEC_UUID("8E349D19-54DB-4A56-9DC9-119D87BDB804") ID3D12LibraryReflection;
DEFINE_GUID(IID_ID3D12LibraryReflection,
0x8e349d19, 0x54db, 0x4a56, 0x9d, 0xc9, 0x11, 0x9d, 0x87, 0xbd, 0xb8, 0x4);
#undef INTERFACE
#define INTERFACE ID3D12LibraryReflection
DECLARE_INTERFACE_(ID3D12LibraryReflection, IUnknown)
{
STDMETHOD(QueryInterface)(THIS_ _In_ REFIID iid, _Out_ LPVOID * ppv) PURE;
STDMETHOD_(ULONG, AddRef)(THIS) PURE;
STDMETHOD_(ULONG, Release)(THIS) PURE;
STDMETHOD(GetDesc)(THIS_ _Out_ D3D12_LIBRARY_DESC * pDesc) PURE;
STDMETHOD_(ID3D12FunctionReflection *, GetFunctionByIndex)(THIS_ _In_ INT FunctionIndex) PURE;
};
// {1108795C-2772-4BA9-B2A8-D464DC7E2799}
interface DECLSPEC_UUID("1108795C-2772-4BA9-B2A8-D464DC7E2799") ID3D12FunctionReflection;
DEFINE_GUID(IID_ID3D12FunctionReflection,
0x1108795c, 0x2772, 0x4ba9, 0xb2, 0xa8, 0xd4, 0x64, 0xdc, 0x7e, 0x27, 0x99);
#undef INTERFACE
#define INTERFACE ID3D12FunctionReflection
DECLARE_INTERFACE(ID3D12FunctionReflection)
{
STDMETHOD(GetDesc)(THIS_ _Out_ D3D12_FUNCTION_DESC * pDesc) PURE;
STDMETHOD_(ID3D12ShaderReflectionConstantBuffer *, GetConstantBufferByIndex)(THIS_ _In_ UINT BufferIndex) PURE;
STDMETHOD_(ID3D12ShaderReflectionConstantBuffer *, GetConstantBufferByName)(THIS_ _In_ LPCSTR Name) PURE;
STDMETHOD(GetResourceBindingDesc)(THIS_ _In_ UINT ResourceIndex,
_Out_ D3D12_SHADER_INPUT_BIND_DESC * pDesc) PURE;
STDMETHOD_(ID3D12ShaderReflectionVariable *, GetVariableByName)(THIS_ _In_ LPCSTR Name) PURE;
STDMETHOD(GetResourceBindingDescByName)(THIS_ _In_ LPCSTR Name,
_Out_ D3D12_SHADER_INPUT_BIND_DESC * pDesc) PURE;
// Use D3D_RETURN_PARAMETER_INDEX to get description of the return value.
STDMETHOD_(ID3D12FunctionParameterReflection *, GetFunctionParameter)(THIS_ _In_ INT ParameterIndex) PURE;
};
// {EC25F42D-7006-4F2B-B33E-02CC3375733F}
interface DECLSPEC_UUID("EC25F42D-7006-4F2B-B33E-02CC3375733F") ID3D12FunctionParameterReflection;
DEFINE_GUID(IID_ID3D12FunctionParameterReflection,
0xec25f42d, 0x7006, 0x4f2b, 0xb3, 0x3e, 0x2, 0xcc, 0x33, 0x75, 0x73, 0x3f);
#undef INTERFACE
#define INTERFACE ID3D12FunctionParameterReflection
DECLARE_INTERFACE(ID3D12FunctionParameterReflection)
{
STDMETHOD(GetDesc)(THIS_ _Out_ D3D12_PARAMETER_DESC * pDesc) PURE;
};
//////////////////////////////////////////////////////////////////////////////
// APIs //////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
#ifdef __cplusplus
}
#endif //__cplusplus
#endif //__D3D12SHADER_H__

1009
include/dxsdk/d3dcommon.h Normal file

File diff suppressed because it is too large Load Diff

586
include/dxsdk/d3dcompiler.h Normal file
View File

@ -0,0 +1,586 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: D3DCompiler.h
// Content: D3D Compilation Types and APIs
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __D3DCOMPILER_H__
#define __D3DCOMPILER_H__
#include <winapifamily.h>
// Current name of the DLL shipped in the same SDK as this header.
#define D3DCOMPILER_DLL_W L"d3dcompiler_47.dll"
#define D3DCOMPILER_DLL_A "d3dcompiler_47.dll"
// Current HLSL compiler version.
#define D3D_COMPILER_VERSION 47
#ifdef UNICODE
#define D3DCOMPILER_DLL D3DCOMPILER_DLL_W
#else
#define D3DCOMPILER_DLL D3DCOMPILER_DLL_A
#endif
#include "d3d11shader.h"
#include "d3d12shader.h"
//////////////////////////////////////////////////////////////////////////////
// APIs //////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
//----------------------------------------------------------------------------
// D3DReadFileToBlob:
// -----------------
// Simple helper routine to read a file on disk into memory
// for passing to other routines in this API.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DReadFileToBlob(_In_ LPCWSTR pFileName,
_Out_ ID3DBlob** ppContents);
//----------------------------------------------------------------------------
// D3DWriteBlobToFile:
// ------------------
// Simple helper routine to write a memory blob to a file on disk.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DWriteBlobToFile(_In_ ID3DBlob* pBlob,
_In_ LPCWSTR pFileName,
_In_ BOOL bOverwrite);
//----------------------------------------------------------------------------
// D3DCOMPILE flags:
// -----------------
// D3DCOMPILE_DEBUG
// Insert debug file/line/type/symbol information.
//
// D3DCOMPILE_SKIP_VALIDATION
// Do not validate the generated code against known capabilities and
// constraints. This option is only recommended when compiling shaders
// you KNOW will work. (ie. have compiled before without this option.)
// Shaders are always validated by D3D before they are set to the device.
//
// D3DCOMPILE_SKIP_OPTIMIZATION
// Instructs the compiler to skip optimization steps during code generation.
// Unless you are trying to isolate a problem in your code using this option
// is not recommended.
//
// D3DCOMPILE_PACK_MATRIX_ROW_MAJOR
// Unless explicitly specified, matrices will be packed in row-major order
// on input and output from the shader.
//
// D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR
// Unless explicitly specified, matrices will be packed in column-major
// order on input and output from the shader. This is generally more
// efficient, since it allows vector-matrix multiplication to be performed
// using a series of dot-products.
//
// D3DCOMPILE_PARTIAL_PRECISION
// Force all computations in resulting shader to occur at partial precision.
// This may result in faster evaluation of shaders on some hardware.
//
// D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT
// Force compiler to compile against the next highest available software
// target for vertex shaders. This flag also turns optimizations off,
// and debugging on.
//
// D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT
// Force compiler to compile against the next highest available software
// target for pixel shaders. This flag also turns optimizations off,
// and debugging on.
//
// D3DCOMPILE_NO_PRESHADER
// Disables Preshaders. Using this flag will cause the compiler to not
// pull out static expression for evaluation on the host cpu
//
// D3DCOMPILE_AVOID_FLOW_CONTROL
// Hint compiler to avoid flow-control constructs where possible.
//
// D3DCOMPILE_PREFER_FLOW_CONTROL
// Hint compiler to prefer flow-control constructs where possible.
//
// D3DCOMPILE_ENABLE_STRICTNESS
// By default, the HLSL/Effect compilers are not strict on deprecated syntax.
// Specifying this flag enables the strict mode. Deprecated syntax may be
// removed in a future release, and enabling syntax is a good way to make
// sure your shaders comply to the latest spec.
//
// D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY
// This enables older shaders to compile to 4_0 targets.
//
// D3DCOMPILE_DEBUG_NAME_FOR_SOURCE
// This enables a debug name to be generated based on source information.
// It requires D3DCOMPILE_DEBUG to be set, and is exclusive with
// D3DCOMPILE_DEBUG_NAME_FOR_BINARY.
//
// D3DCOMPILE_DEBUG_NAME_FOR_BINARY
// This enables a debug name to be generated based on compiled information.
// It requires D3DCOMPILE_DEBUG to be set, and is exclusive with
// D3DCOMPILE_DEBUG_NAME_FOR_SOURCE.
//
//----------------------------------------------------------------------------
#define D3DCOMPILE_DEBUG (1 << 0)
#define D3DCOMPILE_SKIP_VALIDATION (1 << 1)
#define D3DCOMPILE_SKIP_OPTIMIZATION (1 << 2)
#define D3DCOMPILE_PACK_MATRIX_ROW_MAJOR (1 << 3)
#define D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR (1 << 4)
#define D3DCOMPILE_PARTIAL_PRECISION (1 << 5)
#define D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT (1 << 6)
#define D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT (1 << 7)
#define D3DCOMPILE_NO_PRESHADER (1 << 8)
#define D3DCOMPILE_AVOID_FLOW_CONTROL (1 << 9)
#define D3DCOMPILE_PREFER_FLOW_CONTROL (1 << 10)
#define D3DCOMPILE_ENABLE_STRICTNESS (1 << 11)
#define D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY (1 << 12)
#define D3DCOMPILE_IEEE_STRICTNESS (1 << 13)
#define D3DCOMPILE_OPTIMIZATION_LEVEL0 (1 << 14)
#define D3DCOMPILE_OPTIMIZATION_LEVEL1 0
#define D3DCOMPILE_OPTIMIZATION_LEVEL2 ((1 << 14) | (1 << 15))
#define D3DCOMPILE_OPTIMIZATION_LEVEL3 (1 << 15)
#define D3DCOMPILE_RESERVED16 (1 << 16)
#define D3DCOMPILE_RESERVED17 (1 << 17)
#define D3DCOMPILE_WARNINGS_ARE_ERRORS (1 << 18)
#define D3DCOMPILE_RESOURCES_MAY_ALIAS (1 << 19)
#define D3DCOMPILE_ENABLE_UNBOUNDED_DESCRIPTOR_TABLES (1 << 20)
#define D3DCOMPILE_ALL_RESOURCES_BOUND (1 << 21)
#define D3DCOMPILE_DEBUG_NAME_FOR_SOURCE (1 << 22)
#define D3DCOMPILE_DEBUG_NAME_FOR_BINARY (1 << 23)
//----------------------------------------------------------------------------
// D3DCOMPILE_EFFECT flags:
// -------------------------------------
// These flags are passed in when creating an effect, and affect
// either compilation behavior or runtime effect behavior
//
// D3DCOMPILE_EFFECT_CHILD_EFFECT
// Compile this .fx file to a child effect. Child effects have no
// initializers for any shared values as these are initialied in the
// master effect (pool).
//
// D3DCOMPILE_EFFECT_ALLOW_SLOW_OPS
// By default, performance mode is enabled. Performance mode
// disallows mutable state objects by preventing non-literal
// expressions from appearing in state object definitions.
// Specifying this flag will disable the mode and allow for mutable
// state objects.
//
//----------------------------------------------------------------------------
#define D3DCOMPILE_EFFECT_CHILD_EFFECT (1 << 0)
#define D3DCOMPILE_EFFECT_ALLOW_SLOW_OPS (1 << 1)
//----------------------------------------------------------------------------
// D3DCOMPILE Flags2:
// -----------------
// Root signature flags. (passed in Flags2)
#define D3DCOMPILE_FLAGS2_FORCE_ROOT_SIGNATURE_LATEST 0
#define D3DCOMPILE_FLAGS2_FORCE_ROOT_SIGNATURE_1_0 (1 << 4)
#define D3DCOMPILE_FLAGS2_FORCE_ROOT_SIGNATURE_1_1 (1 << 5)
//----------------------------------------------------------------------------
// D3DCompile:
// ----------
// Compile source text into bytecode appropriate for the given target.
//----------------------------------------------------------------------------
// D3D_COMPILE_STANDARD_FILE_INCLUDE can be passed for pInclude in any
// API and indicates that a simple default include handler should be
// used. The include handler will include files relative to the
// current directory and files relative to the directory of the initial source
// file. When used with APIs like D3DCompile pSourceName must be a
// file name and the initial relative directory will be derived from it.
#define D3D_COMPILE_STANDARD_FILE_INCLUDE ((ID3DInclude*)(UINT_PTR)1)
HRESULT WINAPI
D3DCompile(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_opt_ LPCSTR pSourceName,
_In_reads_opt_(_Inexpressible_(pDefines->Name != NULL)) CONST D3D_SHADER_MACRO* pDefines,
_In_opt_ ID3DInclude* pInclude,
_In_opt_ LPCSTR pEntrypoint,
_In_ LPCSTR pTarget,
_In_ UINT Flags1,
_In_ UINT Flags2,
_Out_ ID3DBlob** ppCode,
_Always_(_Outptr_opt_result_maybenull_) ID3DBlob** ppErrorMsgs);
typedef HRESULT (WINAPI *pD3DCompile)
(LPCVOID pSrcData,
SIZE_T SrcDataSize,
LPCSTR pFileName,
CONST D3D_SHADER_MACRO* pDefines,
ID3DInclude* pInclude,
LPCSTR pEntrypoint,
LPCSTR pTarget,
UINT Flags1,
UINT Flags2,
ID3DBlob** ppCode,
ID3DBlob** ppErrorMsgs);
#define D3DCOMPILE_SECDATA_MERGE_UAV_SLOTS 0x00000001
#define D3DCOMPILE_SECDATA_PRESERVE_TEMPLATE_SLOTS 0x00000002
#define D3DCOMPILE_SECDATA_REQUIRE_TEMPLATE_MATCH 0x00000004
HRESULT WINAPI
D3DCompile2(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_opt_ LPCSTR pSourceName,
_In_reads_opt_(_Inexpressible_(pDefines->Name != NULL)) CONST D3D_SHADER_MACRO* pDefines,
_In_opt_ ID3DInclude* pInclude,
_In_ LPCSTR pEntrypoint,
_In_ LPCSTR pTarget,
_In_ UINT Flags1,
_In_ UINT Flags2,
_In_ UINT SecondaryDataFlags,
_In_reads_bytes_opt_(SecondaryDataSize) LPCVOID pSecondaryData,
_In_ SIZE_T SecondaryDataSize,
_Out_ ID3DBlob** ppCode,
_Always_(_Outptr_opt_result_maybenull_) ID3DBlob** ppErrorMsgs);
HRESULT WINAPI
D3DCompileFromFile(_In_ LPCWSTR pFileName,
_In_reads_opt_(_Inexpressible_(pDefines->Name != NULL)) CONST D3D_SHADER_MACRO* pDefines,
_In_opt_ ID3DInclude* pInclude,
_In_ LPCSTR pEntrypoint,
_In_ LPCSTR pTarget,
_In_ UINT Flags1,
_In_ UINT Flags2,
_Out_ ID3DBlob** ppCode,
_Always_(_Outptr_opt_result_maybenull_) ID3DBlob** ppErrorMsgs);
//----------------------------------------------------------------------------
// D3DPreprocess:
// -------------
// Process source text with the compiler's preprocessor and return
// the resulting text.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DPreprocess(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_opt_ LPCSTR pSourceName,
_In_opt_ CONST D3D_SHADER_MACRO* pDefines,
_In_opt_ ID3DInclude* pInclude,
_Out_ ID3DBlob** ppCodeText,
_Always_(_Outptr_opt_result_maybenull_) ID3DBlob** ppErrorMsgs);
typedef HRESULT (WINAPI *pD3DPreprocess)
(LPCVOID pSrcData,
SIZE_T SrcDataSize,
LPCSTR pFileName,
CONST D3D_SHADER_MACRO* pDefines,
ID3DInclude* pInclude,
ID3DBlob** ppCodeText,
ID3DBlob** ppErrorMsgs);
//----------------------------------------------------------------------------
// D3DGetDebugInfo:
// -----------------------
// Gets shader debug info. Debug info is generated by D3DCompile and is
// embedded in the body of the shader.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DGetDebugInfo(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_Out_ ID3DBlob** ppDebugInfo);
//----------------------------------------------------------------------------
// D3DReflect:
// ----------
// Shader code contains metadata that can be inspected via the
// reflection APIs.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DReflect(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_ REFIID pInterface,
_Out_ void** ppReflector);
//----------------------------------------------------------------------------
// D3DReflectLibrary:
// ----------
// Library code contains metadata that can be inspected via the library
// reflection APIs.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DReflectLibrary(__in_bcount(SrcDataSize) LPCVOID pSrcData,
__in SIZE_T SrcDataSize,
__in REFIID riid,
__out LPVOID * ppReflector);
//----------------------------------------------------------------------------
// D3DDisassemble:
// ----------------------
// Takes a binary shader and returns a buffer containing text assembly.
//----------------------------------------------------------------------------
#define D3D_DISASM_ENABLE_COLOR_CODE 0x00000001
#define D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS 0x00000002
#define D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING 0x00000004
#define D3D_DISASM_ENABLE_INSTRUCTION_CYCLE 0x00000008
#define D3D_DISASM_DISABLE_DEBUG_INFO 0x00000010
#define D3D_DISASM_ENABLE_INSTRUCTION_OFFSET 0x00000020
#define D3D_DISASM_INSTRUCTION_ONLY 0x00000040
#define D3D_DISASM_PRINT_HEX_LITERALS 0x00000080
HRESULT WINAPI
D3DDisassemble(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_ UINT Flags,
_In_opt_ LPCSTR szComments,
_Out_ ID3DBlob** ppDisassembly);
typedef HRESULT (WINAPI *pD3DDisassemble)
(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_ UINT Flags,
_In_opt_ LPCSTR szComments,
_Out_ ID3DBlob** ppDisassembly);
HRESULT WINAPI
D3DDisassembleRegion(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_ UINT Flags,
_In_opt_ LPCSTR szComments,
_In_ SIZE_T StartByteOffset,
_In_ SIZE_T NumInsts,
_Out_opt_ SIZE_T* pFinishByteOffset,
_Out_ ID3DBlob** ppDisassembly);
//----------------------------------------------------------------------------
// Shader linking and Function Linking Graph (FLG) APIs
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DCreateLinker(__out interface ID3D11Linker ** ppLinker);
HRESULT WINAPI
D3DLoadModule(_In_ LPCVOID pSrcData,
_In_ SIZE_T cbSrcDataSize,
_Out_ interface ID3D11Module ** ppModule);
HRESULT WINAPI
D3DCreateFunctionLinkingGraph(_In_ UINT uFlags,
_Out_ interface ID3D11FunctionLinkingGraph ** ppFunctionLinkingGraph);
//----------------------------------------------------------------------------
// D3DGetTraceInstructionOffsets:
// -----------------------
// Determines byte offsets for instructions within a shader blob.
// This information is useful for going between trace instruction
// indices and byte offsets that are used in debug information.
//----------------------------------------------------------------------------
#define D3D_GET_INST_OFFSETS_INCLUDE_NON_EXECUTABLE 0x00000001
HRESULT WINAPI
D3DGetTraceInstructionOffsets(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_ UINT Flags,
_In_ SIZE_T StartInstIndex,
_In_ SIZE_T NumInsts,
_Out_writes_to_opt_(NumInsts, min(NumInsts, *pTotalInsts)) SIZE_T* pOffsets,
_Out_opt_ SIZE_T* pTotalInsts);
//----------------------------------------------------------------------------
// D3DGetInputSignatureBlob:
// -----------------------
// Retrieve the input signature from a compilation result.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DGetInputSignatureBlob(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_Out_ ID3DBlob** ppSignatureBlob);
//----------------------------------------------------------------------------
// D3DGetOutputSignatureBlob:
// -----------------------
// Retrieve the output signature from a compilation result.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DGetOutputSignatureBlob(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_Out_ ID3DBlob** ppSignatureBlob);
//----------------------------------------------------------------------------
// D3DGetInputAndOutputSignatureBlob:
// -----------------------
// Retrieve the input and output signatures from a compilation result.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DGetInputAndOutputSignatureBlob(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_Out_ ID3DBlob** ppSignatureBlob);
//----------------------------------------------------------------------------
// D3DStripShader:
// -----------------------
// Removes unwanted blobs from a compilation result
//----------------------------------------------------------------------------
typedef enum D3DCOMPILER_STRIP_FLAGS
{
D3DCOMPILER_STRIP_REFLECTION_DATA = 0x00000001,
D3DCOMPILER_STRIP_DEBUG_INFO = 0x00000002,
D3DCOMPILER_STRIP_TEST_BLOBS = 0x00000004,
D3DCOMPILER_STRIP_PRIVATE_DATA = 0x00000008,
D3DCOMPILER_STRIP_ROOT_SIGNATURE = 0x00000010,
D3DCOMPILER_STRIP_FORCE_DWORD = 0x7fffffff,
} D3DCOMPILER_STRIP_FLAGS;
HRESULT WINAPI
D3DStripShader(_In_reads_bytes_(BytecodeLength) LPCVOID pShaderBytecode,
_In_ SIZE_T BytecodeLength,
_In_ UINT uStripFlags,
_Out_ ID3DBlob** ppStrippedBlob);
//----------------------------------------------------------------------------
// D3DGetBlobPart:
// -----------------------
// Extracts information from a compilation result.
//----------------------------------------------------------------------------
typedef enum D3D_BLOB_PART
{
D3D_BLOB_INPUT_SIGNATURE_BLOB,
D3D_BLOB_OUTPUT_SIGNATURE_BLOB,
D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB,
D3D_BLOB_PATCH_CONSTANT_SIGNATURE_BLOB,
D3D_BLOB_ALL_SIGNATURE_BLOB,
D3D_BLOB_DEBUG_INFO,
D3D_BLOB_LEGACY_SHADER,
D3D_BLOB_XNA_PREPASS_SHADER,
D3D_BLOB_XNA_SHADER,
D3D_BLOB_PDB,
D3D_BLOB_PRIVATE_DATA,
D3D_BLOB_ROOT_SIGNATURE,
D3D_BLOB_DEBUG_NAME,
// Test parts are only produced by special compiler versions and so
// are usually not present in shaders.
D3D_BLOB_TEST_ALTERNATE_SHADER = 0x8000,
D3D_BLOB_TEST_COMPILE_DETAILS,
D3D_BLOB_TEST_COMPILE_PERF,
D3D_BLOB_TEST_COMPILE_REPORT,
} D3D_BLOB_PART;
HRESULT WINAPI
D3DGetBlobPart(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_ D3D_BLOB_PART Part,
_In_ UINT Flags,
_Out_ ID3DBlob** ppPart);
//----------------------------------------------------------------------------
// D3DSetBlobPart:
// -----------------------
// Update information in a compilation result.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DSetBlobPart(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_ D3D_BLOB_PART Part,
_In_ UINT Flags,
_In_reads_bytes_(PartSize) LPCVOID pPart,
_In_ SIZE_T PartSize,
_Out_ ID3DBlob** ppNewShader);
//----------------------------------------------------------------------------
// D3DCreateBlob:
// -----------------------
// Create an ID3DBlob instance.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DCreateBlob(_In_ SIZE_T Size,
_Out_ ID3DBlob** ppBlob);
//----------------------------------------------------------------------------
// D3DCompressShaders:
// -----------------------
// Compresses a set of shaders into a more compact form.
//----------------------------------------------------------------------------
typedef struct _D3D_SHADER_DATA
{
LPCVOID pBytecode;
SIZE_T BytecodeLength;
} D3D_SHADER_DATA;
#define D3D_COMPRESS_SHADER_KEEP_ALL_PARTS 0x00000001
HRESULT WINAPI
D3DCompressShaders(_In_ UINT uNumShaders,
_In_reads_(uNumShaders) D3D_SHADER_DATA* pShaderData,
_In_ UINT uFlags,
_Out_ ID3DBlob** ppCompressedData);
//----------------------------------------------------------------------------
// D3DDecompressShaders:
// -----------------------
// Decompresses one or more shaders from a compressed set.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DDecompressShaders(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData,
_In_ SIZE_T SrcDataSize,
_In_ UINT uNumShaders,
_In_ UINT uStartIndex,
_In_reads_opt_(uNumShaders) UINT* pIndices,
_In_ UINT uFlags,
_Out_writes_(uNumShaders) ID3DBlob** ppShaders,
_Out_opt_ UINT* pTotalShaders);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
//----------------------------------------------------------------------------
// D3DDisassemble10Effect:
// -----------------------
// Takes a D3D10 effect interface and returns a
// buffer containing text assembly.
//----------------------------------------------------------------------------
HRESULT WINAPI
D3DDisassemble10Effect(_In_ interface ID3D10Effect *pEffect,
_In_ UINT Flags,
_Out_ ID3DBlob** ppDisassembly);
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
#pragma endregion
#ifdef __cplusplus
}
#endif //__cplusplus
#endif // #ifndef __D3DCOMPILER_H__

3440
include/dxsdk/d3dx12.h Normal file

File diff suppressed because it is too large Load Diff

2958
include/dxsdk/dxgi.h Normal file

File diff suppressed because it is too large Load Diff

1494
include/dxsdk/dxgi1_4.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -51,6 +51,8 @@
#define TEXT_OPT_DOUBLE _("DOUBLE")
#define TEXT_RESET_WINDOW _("RESET WINDOW")
#define TEXT_OPT_HUD _("HUD")
#define TEXT_OPT_THREEPOINT _("THREE POINT")
#define TEXT_OPT_APPLY _("APPLY")
#define TEXT_BIND_A _("A BUTTON")
#define TEXT_BIND_B _("B BUTTON")
@ -110,6 +112,8 @@
#define TEXT_OPT_DOUBLE _("Double")
#define TEXT_RESET_WINDOW _("Reset Window")
#define TEXT_OPT_HUD _("HUD")
#define TEXT_OPT_THREEPOINT _("Three-point")
#define TEXT_OPT_APPLY _("Apply")
#define TEXT_BIND_A _("A Button")
#define TEXT_BIND_B _("B Button")

View File

@ -80,6 +80,8 @@ static const u8 optsVideoStr[][32] = {
{ TEXT_OPT_VSYNC },
{ TEXT_OPT_DOUBLE },
{ TEXT_OPT_HUD },
{ TEXT_OPT_THREEPOINT },
{ TEXT_OPT_APPLY },
};
static const u8 optsAudioStr[][32] = {
@ -123,6 +125,7 @@ static const u8 bindStr[][32] = {
static const u8 *filterChoices[] = {
optsVideoStr[2],
optsVideoStr[3],
optsVideoStr[8],
};
static const u8 *vsyncChoices[] = {
@ -205,6 +208,10 @@ static void optvideo_reset_window(UNUSED struct Option *self, s32 arg) {
}
}
static void optvideo_apply(UNUSED struct Option *self, s32 arg) {
if (!arg) configWindow.settings_changed = true;
}
/* submenu option lists */
#ifdef BETTERCAMERA
@ -246,8 +253,9 @@ static struct Option optsVideo[] = {
DEF_OPT_TOGGLE( optsVideoStr[0], &configWindow.fullscreen ),
DEF_OPT_CHOICE( optsVideoStr[5], &configWindow.vsync, vsyncChoices ),
DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ),
DEF_OPT_BUTTON( optsVideoStr[4], optvideo_reset_window ),
DEF_OPT_TOGGLE( optsVideoStr[7], &configHUD ),
DEF_OPT_BUTTON( optsVideoStr[4], optvideo_reset_window ),
DEF_OPT_BUTTON( optsVideoStr[9], optvideo_apply ),
};
static struct Option optsAudio[] = {

View File

@ -1,3 +1,5 @@
#ifdef AAPI_SDL2
#include <SDL2/SDL.h>
#include "audio_api.h"
@ -57,4 +59,6 @@ struct AudioAPI audio_sdl = {
audio_sdl_get_desired_buffered,
audio_sdl_play,
audio_sdl_shutdown
};
};
#endif

View File

@ -1,6 +1,8 @@
#ifndef AUDIO_SDL_H
#define AUDIO_SDL_H
#include "audio_api.h"
extern struct AudioAPI audio_sdl;
#endif

View File

@ -6,17 +6,11 @@
#include <assert.h>
#include <ctype.h>
#if USE_SDL == 2
# include <SDL2/SDL.h>
# define WINDOWPOS_CENTERED SDL_WINDOWPOS_CENTERED
#else
# define WINDOWPOS_CENTERED 0
#endif
#include "platform.h"
#include "configfile.h"
#include "cliopts.h"
#include "gfx/gfx_screen_config.h"
#include "gfx/gfx_window_manager_api.h"
#include "controller/controller_api.h"
#include "fs/fs.h"
@ -45,8 +39,8 @@ struct ConfigOption {
// Video/audio stuff
ConfigWindow configWindow = {
.x = WINDOWPOS_CENTERED,
.y = WINDOWPOS_CENTERED,
.x = WAPI_WIN_CENTERPOS,
.y = WAPI_WIN_CENTERPOS,
.w = DESIRED_SCREEN_WIDTH,
.h = DESIRED_SCREEN_HEIGHT,
.vsync = 1,

View File

@ -1,3 +1,5 @@
#ifdef CAPI_SDL2
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
@ -296,3 +298,5 @@ struct ControllerAPI controller_sdl = {
controller_sdl_bind,
controller_sdl_shutdown
};
#endif // CAPI_SDL2

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
#ifndef GFX_DIRECT3D11_H
#define GFX_DIRECT3D11_H
#include "gfx_window_manager_api.h"
#include "gfx_rendering_api.h"
extern struct GfxWindowManagerAPI gfx_dxgi;
extern struct GfxRenderingAPI gfx_d3d11_api;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
#ifndef GFX_DIRECT3D12_H
#define GFX_DIRECT3D12_H
#include "gfx_window_manager_api.h"
#include "gfx_rendering_api.h"
extern struct GfxWindowManagerAPI gfx_dxgi;
extern struct GfxRenderingAPI gfx_d3d12_api;
#endif

View File

@ -0,0 +1,143 @@
#if (defined(RAPI_D3D11) || defined(RAPI_D3D12)) && (defined(_WIN32) || defined(_WIN64))
#include <cstdio>
extern "C" {
#include "../platform.h"
}
#include "gfx_direct3d_common.h"
#include "gfx_cc.h"
void ThrowIfFailed(HRESULT res) {
if (FAILED(res))
sys_fatal("error while initializing D3D:\nerror code 0x%08X", res);
}
void ThrowIfFailed(HRESULT res, HWND h_wnd, const char *message) {
if (FAILED(res))
sys_fatal("%s\nerror code 0x%08X", message, res);
}
void get_cc_features(uint32_t shader_id, CCFeatures *cc_features) {
for (int i = 0; i < 4; i++) {
cc_features->c[0][i] = (shader_id >> (i * 3)) & 7;
cc_features->c[1][i] = (shader_id >> (12 + i * 3)) & 7;
}
cc_features->opt_alpha = (shader_id & SHADER_OPT_ALPHA) != 0;
cc_features->opt_fog = (shader_id & SHADER_OPT_FOG) != 0;
cc_features->opt_texture_edge = (shader_id & SHADER_OPT_TEXTURE_EDGE) != 0;
cc_features->opt_noise = (shader_id & SHADER_OPT_NOISE) != 0;
cc_features->used_textures[0] = false;
cc_features->used_textures[1] = false;
cc_features->num_inputs = 0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
if (cc_features->c[i][j] >= SHADER_INPUT_1 && cc_features->c[i][j] <= SHADER_INPUT_4) {
if (cc_features->c[i][j] > cc_features->num_inputs) {
cc_features->num_inputs = cc_features->c[i][j];
}
}
if (cc_features->c[i][j] == SHADER_TEXEL0 || cc_features->c[i][j] == SHADER_TEXEL0A) {
cc_features->used_textures[0] = true;
}
if (cc_features->c[i][j] == SHADER_TEXEL1) {
cc_features->used_textures[1] = true;
}
}
}
cc_features->do_single[0] = cc_features->c[0][2] == 0;
cc_features->do_single[1] = cc_features->c[1][2] == 0;
cc_features->do_multiply[0] = cc_features->c[0][1] == 0 && cc_features->c[0][3] == 0;
cc_features->do_multiply[1] = cc_features->c[1][1] == 0 && cc_features->c[1][3] == 0;
cc_features->do_mix[0] = cc_features->c[0][1] == cc_features->c[0][3];
cc_features->do_mix[1] = cc_features->c[1][1] == cc_features->c[1][3];
cc_features->color_alpha_same = (shader_id & 0xfff) == ((shader_id >> 12) & 0xfff);
}
void append_str(char *buf, size_t *len, const char *str) {
while (*str != '\0') buf[(*len)++] = *str++;
}
void append_line(char *buf, size_t *len, const char *str) {
while (*str != '\0') buf[(*len)++] = *str++;
buf[(*len)++] = '\r';
buf[(*len)++] = '\n';
}
const char *shader_item_to_str(uint32_t item, bool with_alpha, bool only_alpha, bool inputs_have_alpha, bool hint_single_element) {
if (!only_alpha) {
switch (item) {
default:
case SHADER_0:
return with_alpha ? "float4(0.0, 0.0, 0.0, 0.0)" : "float3(0.0, 0.0, 0.0)";
case SHADER_INPUT_1:
return with_alpha || !inputs_have_alpha ? "input.input1" : "input.input1.rgb";
case SHADER_INPUT_2:
return with_alpha || !inputs_have_alpha ? "input.input2" : "input.input2.rgb";
case SHADER_INPUT_3:
return with_alpha || !inputs_have_alpha ? "input.input3" : "input.input3.rgb";
case SHADER_INPUT_4:
return with_alpha || !inputs_have_alpha ? "input.input4" : "input.input4.rgb";
case SHADER_TEXEL0:
return with_alpha ? "texVal0" : "texVal0.rgb";
case SHADER_TEXEL0A:
return hint_single_element ? "texVal0.a" : (with_alpha ? "float4(texVal0.a, texVal0.a, texVal0.a, texVal0.a)" : "float3(texVal0.a, texVal0.a, texVal0.a)");
case SHADER_TEXEL1:
return with_alpha ? "texVal1" : "texVal1.rgb";
}
} else {
switch (item) {
default:
case SHADER_0:
return "0.0";
case SHADER_INPUT_1:
return "input.input1.a";
case SHADER_INPUT_2:
return "input.input2.a";
case SHADER_INPUT_3:
return "input.input3.a";
case SHADER_INPUT_4:
return "input.input4.a";
case SHADER_TEXEL0:
return "texVal0.a";
case SHADER_TEXEL0A:
return "texVal0.a";
case SHADER_TEXEL1:
return "texVal1.a";
}
}
}
void append_formula(char *buf, size_t *len, uint8_t c[2][4], bool do_single, bool do_multiply, bool do_mix, bool with_alpha, bool only_alpha, bool opt_alpha) {
if (do_single) {
append_str(buf, len, shader_item_to_str(c[only_alpha][3], with_alpha, only_alpha, opt_alpha, false));
} else if (do_multiply) {
append_str(buf, len, shader_item_to_str(c[only_alpha][0], with_alpha, only_alpha, opt_alpha, false));
append_str(buf, len, " * ");
append_str(buf, len, shader_item_to_str(c[only_alpha][2], with_alpha, only_alpha, opt_alpha, true));
} else if (do_mix) {
append_str(buf, len, "lerp(");
append_str(buf, len, shader_item_to_str(c[only_alpha][1], with_alpha, only_alpha, opt_alpha, false));
append_str(buf, len, ", ");
append_str(buf, len, shader_item_to_str(c[only_alpha][0], with_alpha, only_alpha, opt_alpha, false));
append_str(buf, len, ", ");
append_str(buf, len, shader_item_to_str(c[only_alpha][2], with_alpha, only_alpha, opt_alpha, true));
append_str(buf, len, ")");
} else {
append_str(buf, len, "(");
append_str(buf, len, shader_item_to_str(c[only_alpha][0], with_alpha, only_alpha, opt_alpha, false));
append_str(buf, len, " - ");
append_str(buf, len, shader_item_to_str(c[only_alpha][1], with_alpha, only_alpha, opt_alpha, false));
append_str(buf, len, ") * ");
append_str(buf, len, shader_item_to_str(c[only_alpha][2], with_alpha, only_alpha, opt_alpha, true));
append_str(buf, len, " + ");
append_str(buf, len, shader_item_to_str(c[only_alpha][3], with_alpha, only_alpha, opt_alpha, false));
}
}
#endif

View File

@ -0,0 +1,33 @@
#if defined(RAPI_D3D11) || defined(RAPI_D3D12)
#ifndef GFX_DIRECT3D_COMMON_H
#define GFX_DIRECT3D_COMMON_H
#include <stdint.h>
#include <windows.h>
struct CCFeatures {
uint8_t c[2][4];
bool opt_alpha;
bool opt_fog;
bool opt_texture_edge;
bool opt_noise;
bool used_textures[2];
uint32_t num_inputs;
bool do_single[2];
bool do_multiply[2];
bool do_mix[2];
bool color_alpha_same;
};
void ThrowIfFailed(HRESULT res);
void ThrowIfFailed(HRESULT res, HWND h_wnd, const char *message);
void get_cc_features(uint32_t shader_id, CCFeatures *shader_features);
void append_str(char *buf, size_t *len, const char *str);
void append_line(char *buf, size_t *len, const char *str);
const char *shader_item_to_str(uint32_t item, bool with_alpha, bool only_alpha, bool inputs_have_alpha, bool hint_single_element);
void append_formula(char *buf, size_t *len, uint8_t c[2][4], bool do_single, bool do_multiply, bool do_mix, bool with_alpha, bool only_alpha, bool opt_alpha);
#endif
#endif

View File

@ -1,4 +1,4 @@
#ifndef LEGACY_GL
#ifdef RAPI_GL
#include <stdint.h>
#include <stdbool.h>
@ -29,9 +29,12 @@
#endif
#include "../platform.h"
#include "../configfile.h"
#include "gfx_cc.h"
#include "gfx_rendering_api.h"
#define TEX_CACHE_STEP 512
struct ShaderProgram {
uint32_t shader_id;
GLuint opengl_program_id;
@ -39,19 +42,31 @@ struct ShaderProgram {
bool used_textures[2];
uint8_t num_floats;
GLint attrib_locations[7];
GLint uniform_locations[5];
uint8_t attrib_sizes[7];
uint8_t num_attribs;
bool used_noise;
GLint frame_count_location;
GLint window_height_location;
};
struct GLTexture {
GLuint gltex;
GLfloat size[2];
bool filter;
};
static struct ShaderProgram shader_program_pool[64];
static uint8_t shader_program_pool_size;
static GLuint opengl_vbo;
static int tex_cache_size = 0;
static int num_textures = 0;
static struct GLTexture *tex_cache = NULL;
static struct ShaderProgram *opengl_prg = NULL;
static struct GLTexture *opengl_tex[2];
static int opengl_curtex = 0;
static uint32_t frame_count;
static uint32_t current_height;
static bool gfx_opengl_z_is_from_0_to_1(void) {
return false;
@ -68,25 +83,36 @@ static void gfx_opengl_vertex_array_set_attribs(struct ShaderProgram *prg) {
}
}
static void gfx_opengl_set_uniforms(struct ShaderProgram *prg) {
if (prg->used_noise) {
glUniform1i(prg->frame_count_location, frame_count);
glUniform1i(prg->window_height_location, current_height);
static inline void gfx_opengl_set_shader_uniforms(struct ShaderProgram *prg) {
if (prg->used_noise)
glUniform1f(prg->uniform_locations[4], (float)frame_count);
}
static inline void gfx_opengl_set_texture_uniforms(struct ShaderProgram *prg, const int tile) {
if (prg->used_textures[tile] && opengl_tex[tile]) {
glUniform2f(prg->uniform_locations[tile*2 + 0], opengl_tex[tile]->size[0], opengl_tex[tile]->size[1]);
glUniform1i(prg->uniform_locations[tile*2 + 1], opengl_tex[tile]->filter);
}
}
static void gfx_opengl_unload_shader(struct ShaderProgram *old_prg) {
if (old_prg != NULL) {
for (int i = 0; i < old_prg->num_attribs; i++) {
for (int i = 0; i < old_prg->num_attribs; i++)
glDisableVertexAttribArray(old_prg->attrib_locations[i]);
}
if (old_prg == opengl_prg)
opengl_prg = NULL;
} else {
opengl_prg = NULL;
}
}
static void gfx_opengl_load_shader(struct ShaderProgram *new_prg) {
opengl_prg = new_prg;
glUseProgram(new_prg->opengl_program_id);
gfx_opengl_vertex_array_set_attribs(new_prg);
gfx_opengl_set_uniforms(new_prg);
gfx_opengl_set_shader_uniforms(new_prg);
gfx_opengl_set_texture_uniforms(new_prg, 0);
gfx_opengl_set_texture_uniforms(new_prg, 1);
}
static void append_str(char *buf, size_t *len, const char *str) {
@ -206,7 +232,7 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(uint32_t shad
bool color_alpha_same = (shader_id & 0xfff) == ((shader_id >> 12) & 0xfff);
char vs_buf[1024];
char fs_buf[1024];
char fs_buf[2048];
size_t vs_len = 0;
size_t fs_len = 0;
size_t num_floats = 4;
@ -265,14 +291,45 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(uint32_t shad
}
if (used_textures[0]) {
append_line(fs_buf, &fs_len, "uniform sampler2D uTex0;");
append_line(fs_buf, &fs_len, "uniform vec2 uTex0Size;");
append_line(fs_buf, &fs_len, "uniform bool uTex0Filter;");
}
if (used_textures[1]) {
append_line(fs_buf, &fs_len, "uniform sampler2D uTex1;");
append_line(fs_buf, &fs_len, "uniform vec2 uTex1Size;");
append_line(fs_buf, &fs_len, "uniform bool uTex1Filter;");
}
// 3 point texture filtering
// Original author: ArthurCarvalho
// Slightly modified GLSL implementation by twinaphex, mupen64plus-libretro project.
if (used_textures[0] || used_textures[1]) {
if (configFiltering == 2) {
append_line(fs_buf, &fs_len, "#define TEX_OFFSET(off) texture2D(tex, texCoord - (off)/texSize)");
append_line(fs_buf, &fs_len, "vec4 filter3point(in sampler2D tex, in vec2 texCoord, in vec2 texSize) {");
append_line(fs_buf, &fs_len, " vec2 offset = fract(texCoord*texSize - vec2(0.5));");
append_line(fs_buf, &fs_len, " offset -= step(1.0, offset.x + offset.y);");
append_line(fs_buf, &fs_len, " vec4 c0 = TEX_OFFSET(offset);");
append_line(fs_buf, &fs_len, " vec4 c1 = TEX_OFFSET(vec2(offset.x - sign(offset.x), offset.y));");
append_line(fs_buf, &fs_len, " vec4 c2 = TEX_OFFSET(vec2(offset.x, offset.y - sign(offset.y)));");
append_line(fs_buf, &fs_len, " return c0 + abs(offset.x)*(c1-c0) + abs(offset.y)*(c2-c0);");
append_line(fs_buf, &fs_len, "}");
append_line(fs_buf, &fs_len, "vec4 sampleTex(in sampler2D tex, in vec2 uv, in vec2 texSize, in bool filter) {");
append_line(fs_buf, &fs_len, "if (filter)");
append_line(fs_buf, &fs_len, "return filter3point(tex, uv, texSize);");
append_line(fs_buf, &fs_len, "else");
append_line(fs_buf, &fs_len, "return texture2D(tex, uv);");
append_line(fs_buf, &fs_len, "}");
} else {
append_line(fs_buf, &fs_len, "vec4 sampleTex(in sampler2D tex, in vec2 uv, in vec2 texSize, in bool filter) {");
append_line(fs_buf, &fs_len, "return texture2D(tex, uv);");
append_line(fs_buf, &fs_len, "}");
}
}
if (opt_alpha && opt_noise) {
append_line(fs_buf, &fs_len, "uniform int frame_count;");
append_line(fs_buf, &fs_len, "uniform int window_height;");
append_line(fs_buf, &fs_len, "uniform float frame_count;");
append_line(fs_buf, &fs_len, "float random(in vec3 value) {");
append_line(fs_buf, &fs_len, " float random = dot(sin(value), vec3(12.9898, 78.233, 37.719));");
@ -283,10 +340,10 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(uint32_t shad
append_line(fs_buf, &fs_len, "void main() {");
if (used_textures[0]) {
append_line(fs_buf, &fs_len, "vec4 texVal0 = texture2D(uTex0, vTexCoord);");
append_line(fs_buf, &fs_len, "vec4 texVal0 = sampleTex(uTex0, vTexCoord, uTex0Size, uTex0Filter);");
}
if (used_textures[1]) {
append_line(fs_buf, &fs_len, "vec4 texVal1 = texture2D(uTex1, vTexCoord);");
append_line(fs_buf, &fs_len, "vec4 texVal1 = sampleTex(uTex1, vTexCoord, uTex1Size, uTex1Filter);");
}
append_str(fs_buf, &fs_len, opt_alpha ? "vec4 texel = " : "vec3 texel = ");
@ -313,9 +370,8 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(uint32_t shad
}
}
if (opt_alpha && opt_noise) {
append_line(fs_buf, &fs_len, "texel.a *= floor(random(vec3(floor(gl_FragCoord.xy * float(window_height)), float(frame_count))) + 0.5);");
}
if (opt_alpha && opt_noise)
append_line(fs_buf, &fs_len, "texel.a *= floor(random(floor(vec3(gl_FragCoord.xy, frame_count))) + 0.5);");
if (opt_alpha) {
append_line(fs_buf, &fs_len, "gl_FragColor = texel;");
@ -409,16 +465,19 @@ static struct ShaderProgram *gfx_opengl_create_and_load_new_shader(uint32_t shad
if (used_textures[0]) {
GLint sampler_location = glGetUniformLocation(shader_program, "uTex0");
prg->uniform_locations[0] = glGetUniformLocation(shader_program, "uTex0Size");
prg->uniform_locations[1] = glGetUniformLocation(shader_program, "uTex0Filter");
glUniform1i(sampler_location, 0);
}
if (used_textures[1]) {
GLint sampler_location = glGetUniformLocation(shader_program, "uTex1");
prg->uniform_locations[2] = glGetUniformLocation(shader_program, "uTex1Size");
prg->uniform_locations[3] = glGetUniformLocation(shader_program, "uTex1Filter");
glUniform1i(sampler_location, 1);
}
if (opt_alpha && opt_noise) {
prg->frame_count_location = glGetUniformLocation(shader_program, "frame_count");
prg->window_height_location = glGetUniformLocation(shader_program, "window_height");
prg->uniform_locations[4] = glGetUniformLocation(shader_program, "frame_count");
prg->used_noise = true;
} else {
prg->used_noise = false;
@ -443,18 +502,30 @@ static void gfx_opengl_shader_get_info(struct ShaderProgram *prg, uint8_t *num_i
}
static GLuint gfx_opengl_new_texture(void) {
GLuint ret;
glGenTextures(1, &ret);
return ret;
if (num_textures >= tex_cache_size) {
tex_cache_size += TEX_CACHE_STEP;
tex_cache = realloc(tex_cache, sizeof(struct GLTexture) * tex_cache_size);
if (!tex_cache) sys_fatal("out of memory allocating texture cache");
// invalidate these because they might be pointing to garbage now
opengl_tex[0] = NULL;
opengl_tex[1] = NULL;
}
glGenTextures(1, &tex_cache[num_textures].gltex);
return num_textures++;
}
static void gfx_opengl_select_texture(int tile, GLuint texture_id) {
glActiveTexture(GL_TEXTURE0 + tile);
glBindTexture(GL_TEXTURE_2D, texture_id);
opengl_tex[tile] = tex_cache + texture_id;
opengl_curtex = tile;
glActiveTexture(GL_TEXTURE0 + tile);
glBindTexture(GL_TEXTURE_2D, opengl_tex[tile]->gltex);
gfx_opengl_set_texture_uniforms(opengl_prg, tile);
}
static void gfx_opengl_upload_texture(uint8_t *rgba32_buf, int width, int height) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgba32_buf);
opengl_tex[opengl_curtex]->size[0] = width;
opengl_tex[opengl_curtex]->size[1] = height;
}
static uint32_t gfx_cm_to_opengl(uint32_t val) {
@ -471,6 +542,11 @@ static void gfx_opengl_set_sampler_parameters(int tile, bool linear_filter, uint
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gfx_cm_to_opengl(cms));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gfx_cm_to_opengl(cmt));
opengl_curtex = tile;
if (opengl_tex[tile]) {
opengl_tex[tile]->filter = linear_filter;
gfx_opengl_set_texture_uniforms(opengl_prg, tile);
}
}
static void gfx_opengl_set_depth_test(bool depth_test) {
@ -497,7 +573,6 @@ static void gfx_opengl_set_zmode_decal(bool zmode_decal) {
static void gfx_opengl_set_viewport(int x, int y, int width, int height) {
glViewport(x, y, width, height);
current_height = height;
}
static void gfx_opengl_set_scissor(int x, int y, int width, int height) {
@ -540,6 +615,10 @@ static void gfx_opengl_init(void) {
sys_fatal("could not init GLEW:\n%s", glewGetErrorString(err));
#endif
tex_cache_size = TEX_CACHE_STEP;
tex_cache = calloc(tex_cache_size, sizeof(struct GLTexture));
if (!tex_cache) sys_fatal("out of memory allocating texture cache");
// check GL version
int vmajor, vminor;
bool is_es = false;
@ -591,4 +670,4 @@ struct GfxRenderingAPI gfx_opengl_api = {
gfx_opengl_shutdown
};
#endif // !LEGACY_GL
#endif // RAPI_GL

View File

@ -1,4 +1,4 @@
#ifdef LEGACY_GL
#ifdef RAPI_GL_LEGACY
#include <stdint.h>
#include <stdbool.h>
@ -603,4 +603,4 @@ struct GfxRenderingAPI gfx_opengl_api = {
gfx_opengl_shutdown
};
#endif // LEGACY_GL
#endif // RAPI_GL_LEGACY

View File

@ -1718,10 +1718,10 @@ void gfx_get_dimensions(uint32_t *width, uint32_t *height) {
gfx_wapi->get_dimensions(width, height);
}
void gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi) {
void gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi, const char *window_title) {
gfx_wapi = wapi;
gfx_rapi = rapi;
gfx_wapi->init();
gfx_wapi->init(window_title);
gfx_rapi->init();
// Used in the 120 star TAS

View File

@ -11,7 +11,7 @@ struct GfxDimensions {
extern struct GfxDimensions gfx_current_dimensions;
void gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi);
void gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi, const char *window_title);
void gfx_start_frame(void);
void gfx_run(Gfx *commands);
void gfx_end_frame(void);

View File

@ -1,3 +1,5 @@
#ifdef WAPI_SDL2
#ifdef __MINGW32__
#define FOR_WINDOWS 1
#else
@ -50,33 +52,36 @@ static SDL_GLContext ctx = NULL;
static int inverted_scancode_table[512];
static Uint32 frame_start = 0;
const SDL_Scancode windows_scancode_table[] =
{
/* 0 1 2 3 4 5 6 7 */
/* 8 9 A B C D E F */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, /* 0 */
SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, /* 0 */
static kb_callback_t kb_key_down = NULL;
static kb_callback_t kb_key_up = NULL;
static void (*kb_all_keys_up)(void) = NULL;
SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, /* 1 */
SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, /* 1 */
const SDL_Scancode windows_scancode_table[] = {
/* 0 1 2 3 4 5 6 7 */
/* 8 9 A B C D E F */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, /* 0 */
SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, /* 0 */
SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, /* 2 */
SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, /* 2 */
SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, /* 1 */
SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, /* 1 */
SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,/* 3 */
SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, /* 3 */
SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, /* 2 */
SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, /* 2 */
SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_HOME, /* 4 */
SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, /* 4 */
SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,/* 3 */
SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, /* 3 */
SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_NONUSBACKSLASH,SDL_SCANCODE_F11, /* 5 */
SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 5 */
SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_HOME, /* 4 */
SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, /* 4 */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F13, SDL_SCANCODE_F14, SDL_SCANCODE_F15, SDL_SCANCODE_F16, /* 6 */
SDL_SCANCODE_F17, SDL_SCANCODE_F18, SDL_SCANCODE_F19, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 6 */
SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_NONUSBACKSLASH, SDL_SCANCODE_F11, /* 5 */
SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 5 */
SDL_SCANCODE_INTERNATIONAL2, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL1, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 7 */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL4, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL5, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL3, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN /* 7 */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F13, SDL_SCANCODE_F14, SDL_SCANCODE_F15, SDL_SCANCODE_F16, /* 6 */
SDL_SCANCODE_F17, SDL_SCANCODE_F18, SDL_SCANCODE_F19, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 6 */
SDL_SCANCODE_INTERNATIONAL2, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL1, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 7 */
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL4, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL5, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL3, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN /* 7 */
};
const SDL_Scancode scancode_rmapping_extended[][2] = {
@ -116,12 +121,12 @@ static void gfx_sdl_set_fullscreen() {
}
}
static void gfx_sdl_reset_dimension_and_pos() {
static void gfx_sdl_reset_dimension_and_pos(void) {
if (configWindow.exiting_fullscreen) {
configWindow.exiting_fullscreen = false;
} else if (configWindow.reset) {
configWindow.x = SDL_WINDOWPOS_CENTERED;
configWindow.y = SDL_WINDOWPOS_CENTERED;
configWindow.x = WAPI_WIN_CENTERPOS;
configWindow.y = WAPI_WIN_CENTERPOS;
configWindow.w = DESIRED_SCREEN_WIDTH;
configWindow.h = DESIRED_SCREEN_HEIGHT;
configWindow.reset = false;
@ -134,13 +139,15 @@ static void gfx_sdl_reset_dimension_and_pos() {
return;
}
configWindow.settings_changed = false;
int xpos = (configWindow.x = WAPI_WIN_CENTERPOS) ? SDL_WINDOWPOS_CENTERED : configWindow.x;
int ypos = (configWindow.y = WAPI_WIN_CENTERPOS) ? SDL_WINDOWPOS_CENTERED : configWindow.y;
SDL_SetWindowSize(wnd, configWindow.w, configWindow.h);
SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y);
SDL_SetWindowPosition(wnd, xpos, ypos);
SDL_GL_SetSwapInterval(configWindow.vsync); // in case vsync changed
}
static void gfx_sdl_init(void) {
static void gfx_sdl_init(const char *window_title) {
SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
@ -155,25 +162,12 @@ static void gfx_sdl_init(void) {
//SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
//SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
if (gCLIOpts.FullScreen == 1)
configWindow.fullscreen = true;
else if (gCLIOpts.FullScreen == 2)
configWindow.fullscreen = false;
char window_title[96] =
#ifndef USE_GLES
"Super Mario 64 PC port (OpenGL)";
#else
"Super Mario 64 PC port (OpenGL_ES2)";
#endif
#ifdef NIGHTLY
strcat(window_title, " nightly " GIT_HASH);
#endif
int xpos = (configWindow.x = WAPI_WIN_CENTERPOS) ? SDL_WINDOWPOS_CENTERED : configWindow.x;
int ypos = (configWindow.y = WAPI_WIN_CENTERPOS) ? SDL_WINDOWPOS_CENTERED : configWindow.y;
wnd = SDL_CreateWindow(
window_title,
configWindow.x, configWindow.y, configWindow.w, configWindow.h,
xpos, ypos, configWindow.w, configWindow.h,
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
);
ctx = SDL_GL_CreateContext(wnd);
@ -223,7 +217,8 @@ static int translate_scancode(int scancode) {
}
static void gfx_sdl_onkeydown(int scancode) {
keyboard_on_key_down(translate_scancode(scancode));
if (kb_key_down)
kb_key_down(translate_scancode(scancode));
const Uint8 *state = SDL_GetKeyboardState(NULL);
@ -234,7 +229,8 @@ static void gfx_sdl_onkeydown(int scancode) {
}
static void gfx_sdl_onkeyup(int scancode) {
keyboard_on_key_up(translate_scancode(scancode));
if (kb_key_up)
kb_key_up(translate_scancode(scancode));
}
static void gfx_sdl_handle_events(void) {
@ -273,8 +269,17 @@ static void gfx_sdl_handle_events(void) {
}
}
gfx_sdl_reset_dimension_and_pos();
gfx_sdl_set_fullscreen();
if (configWindow.settings_changed) {
gfx_sdl_reset_dimension_and_pos();
gfx_sdl_set_fullscreen();
configWindow.settings_changed = false;
}
}
static void gfx_sdl_set_keyboard_callbacks(kb_callback_t on_key_down, kb_callback_t on_key_up, void (*on_all_keys_up)(void)) {
kb_key_down = on_key_down;
kb_key_up = on_key_up;
kb_all_keys_up = on_all_keys_up;
}
static bool gfx_sdl_start_frame(void) {
@ -304,6 +309,7 @@ static void gfx_sdl_shutdown(void) {
struct GfxWindowManagerAPI gfx_sdl = {
gfx_sdl_init,
gfx_sdl_set_keyboard_callbacks,
gfx_sdl_main_loop,
gfx_sdl_get_dimensions,
gfx_sdl_handle_events,
@ -313,3 +319,5 @@ struct GfxWindowManagerAPI gfx_sdl = {
gfx_sdl_get_time,
gfx_sdl_shutdown
};
#endif // BACKEND_WM

View File

@ -4,8 +4,14 @@
#include <stdint.h>
#include <stdbool.h>
// special value for window position that signifies centered position
#define WAPI_WIN_CENTERPOS 0xFFFFFFFF
typedef bool (*kb_callback_t)(int code);
struct GfxWindowManagerAPI {
void (*init)(void);
void (*init)(const char *window_title);
void (*set_keyboard_callbacks)(kb_callback_t on_key_down, kb_callback_t on_key_up, void (*on_all_keys_up)(void));
void (*main_loop)(void (*run_one_game_iter)(void));
void (*get_dimensions)(uint32_t *width, uint32_t *height);
void (*handle_events)(void);

View File

@ -13,6 +13,8 @@
#include "gfx/gfx_pc.h"
#include "gfx/gfx_opengl.h"
#include "gfx/gfx_direct3d11.h"
#include "gfx/gfx_direct3d12.h"
#include "gfx/gfx_sdl.h"
#include "audio/audio_api.h"
@ -23,6 +25,7 @@
#include "cliopts.h"
#include "configfile.h"
#include "controller/controller_api.h"
#include "controller/controller_keyboard.h"
#include "fs/fs.h"
#include "game/game_init.h"
@ -165,9 +168,45 @@ void main_func(void) {
configfile_load(configfile_name());
if (gCLIOpts.FullScreen == 1)
configWindow.fullscreen = true;
else if (gCLIOpts.FullScreen == 2)
configWindow.fullscreen = false;
#if defined(WAPI_SDL1) || defined(WAPI_SDL2)
wm_api = &gfx_sdl;
#elif defined(WAPI_DXGI)
wm_api = &gfx_dxgi;
#else
#error No window API!
#endif
#if defined(RAPI_D3D11)
rendering_api = &gfx_d3d11_api;
# define RAPI_NAME "DirectX 11"
#elif defined(RAPI_D3D12)
rendering_api = &gfx_d3d12_api;
# define RAPI_NAME "DirectX 12"
#elif defined(RAPI_GL) || defined(RAPI_GL_LEGACY)
rendering_api = &gfx_opengl_api;
gfx_init(wm_api, rendering_api);
# ifdef USE_GLES
# define RAPI_NAME "OpenGL ES"
# else
# define RAPI_NAME "OpenGL"
# endif
#else
#error No rendering API!
#endif
char window_title[96] =
"Super Mario 64 PC port (" RAPI_NAME ")"
#ifdef NIGHTLY
" nightly " GIT_HASH
#endif
;
gfx_init(wm_api, rendering_api, window_title);
wm_api->set_keyboard_callbacks(keyboard_on_key_down, keyboard_on_key_up, keyboard_on_all_keys_up);
if (audio_api == NULL && audio_sdl.init())
audio_api = &audio_sdl;
@ -196,7 +235,8 @@ void main_func(void) {
emscripten_set_main_loop(em_main_loop, 0, 0);
request_anim_frame(on_anim_frame);
#else
wm_api->main_loop(produce_one_frame);
while (true)
wm_api->main_loop(produce_one_frame);
#endif
}

View File

@ -79,7 +79,7 @@ void sys_fatal(const char *fmt, ...) {
sys_fatal_impl(msg);
}
#if USE_SDL
#ifdef HAVE_SDL2
// we can just ask SDL for most of this shit if we have it
#include <SDL2/SDL.h>