mirror of https://github.com/bjornbytes/lovr.git
Compare commits
14 Commits
dd4fa5c382
...
7efd19c45c
Author | SHA1 | Date |
---|---|---|
bjorn | 7efd19c45c | |
bjorn | 642388709b | |
bjorn | c41188c4b4 | |
bjorn | 8b2fe0aa31 | |
bjorn | 246cbdfcdc | |
bjorn | b09519cdf4 | |
bjorn | 88ab8e5e5b | |
bjorn | 6213dfb844 | |
bjorn | d81d906f58 | |
bjorn | 8952476e35 | |
Josip Miskovic | 31ca502034 | |
Kelsey Higham | 50b321fb64 | |
bjorn | ff39a7485b | |
bjorn | 2b7b513824 |
|
@ -68,7 +68,9 @@ elseif(ANDROID)
|
|||
endif()
|
||||
elseif(UNIX)
|
||||
find_package(PkgConfig)
|
||||
if(NOT APPLE)
|
||||
if(APPLE)
|
||||
set(LOVR_USE_OPENXR OFF)
|
||||
else()
|
||||
set(CMAKE_SKIP_RPATH OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -4,12 +4,26 @@ clone_depth: 1
|
|||
|
||||
only_commits:
|
||||
files:
|
||||
- etc/
|
||||
- src/
|
||||
- deps/
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- dev
|
||||
|
||||
environment:
|
||||
VULKAN_SDK: C:/VulkanSDK
|
||||
|
||||
cache:
|
||||
- VulkanSDK.exe
|
||||
|
||||
install:
|
||||
- if not exist VulkanSDK.exe curl -L --silent --show-error --output VulkanSDK.exe https://sdk.lunarg.com/sdk/download/1.3.216.0/windows/VulkanSDK-1.3.216.0-Installer.exe?Human=true
|
||||
- VulkanSDK.exe --root C:\VulkanSDK --accept-licenses --default-answer --confirm-command install
|
||||
|
||||
image: Visual Studio 2022
|
||||
|
||||
before_build:
|
||||
- cd C:\projects\lovr
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#version 460
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#include "lovr.glsl"
|
||||
|
||||
layout(local_size_x = 32, local_size_x_id = 0) in;
|
||||
|
||||
|
@ -25,9 +28,9 @@ layout(set = 0, binding = 1) buffer restrict writeonly VertexOut { ModelVertex v
|
|||
layout(set = 0, binding = 2) buffer restrict readonly VertexWeights { SkinVertex skin[]; };
|
||||
layout(set = 0, binding = 3) uniform JointTransforms { mat4 joints[256]; };
|
||||
|
||||
void main() {
|
||||
if (gl_GlobalInvocationID.x >= vertexCount) return;
|
||||
uint vertexIndex = baseVertex + gl_GlobalInvocationID.x;
|
||||
void lovrmain() {
|
||||
if (GlobalThreadID.x >= vertexCount) return;
|
||||
uint vertexIndex = baseVertex + GlobalThreadID.x;
|
||||
|
||||
uint indices = skin[vertexIndex].indices;
|
||||
uint i0 = (indices >> 0) & 0xff;
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
#include "lovr.glsl"
|
||||
|
||||
#define PI 3.141592653589793238462643383
|
||||
|
||||
layout(location = 0) in vec3 Direction;
|
||||
|
||||
vec4 lovrmain() {
|
||||
|
|
|
@ -18,9 +18,10 @@ struct Draw {
|
|||
vec4 color;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 0) uniform CameraBuffer { Camera Cameras[6]; };
|
||||
layout(set = 0, binding = 1) uniform DrawBuffer { Draw Draws[256]; };
|
||||
layout(set = 0, binding = 2) uniform sampler Sampler;
|
||||
layout(set = 0, binding = 0) uniform Globals { vec4 Resolution; float Time; };
|
||||
layout(set = 0, binding = 1) uniform CameraBuffer { Camera Cameras[6]; };
|
||||
layout(set = 0, binding = 2) uniform DrawBuffer { Draw Draws[256]; };
|
||||
layout(set = 0, binding = 3) uniform sampler Sampler;
|
||||
|
||||
struct MaterialData {
|
||||
vec4 color;
|
||||
|
@ -33,7 +34,6 @@ struct MaterialData {
|
|||
float clearcoat;
|
||||
float clearcoatRoughness;
|
||||
float occlusionStrength;
|
||||
float glowStrength;
|
||||
float normalScale;
|
||||
float alphaCutoff;
|
||||
float pointSize;
|
||||
|
@ -81,7 +81,13 @@ layout(location = 12) in vec2 UV;
|
|||
|
||||
// Macros
|
||||
#ifdef GL_COMPUTE_SHADER
|
||||
//
|
||||
#define SubgroupCount gl_NumSubgroups
|
||||
#define WorkgroupCount gl_NumWorkGroups
|
||||
#define WorkgroupSize gl_WorkGroupSize
|
||||
#define WorkgroupID gl_WorkGroupID
|
||||
#define GlobalThreadID gl_GlobalInvocationID
|
||||
#define LocalThreadID gl_LocalInvocationID
|
||||
#define LocalThreadIndex gl_LocalInvocationIndex
|
||||
#else
|
||||
#define BaseInstance gl_BaseInstance
|
||||
#define BaseVertex gl_BaseVertex
|
||||
|
@ -95,36 +101,46 @@ layout(location = 12) in vec2 UV;
|
|||
#define PointCoord gl_PointCoord
|
||||
#define PointSize gl_PointSize
|
||||
#define Position gl_Position
|
||||
#define PrimitiveId gl_PrimitiveID
|
||||
#define SampleId gl_SampleID
|
||||
#define PrimitiveID gl_PrimitiveID
|
||||
#define SampleID gl_SampleID
|
||||
#define SampleMaskIn gl_SampleMaskIn
|
||||
#define SampleMask gl_SampleMask
|
||||
#define SamplePosition gl_SamplePosition
|
||||
#define VertexIndex gl_VertexIndex
|
||||
#define ViewIndex gl_ViewIndex
|
||||
|
||||
#define DrawId gl_BaseInstance
|
||||
#define DrawID gl_BaseInstance
|
||||
#define Projection Cameras[ViewIndex].projection
|
||||
#define View Cameras[ViewIndex].view
|
||||
#define ViewProjection Cameras[ViewIndex].viewProjection
|
||||
#define InverseProjection Cameras[ViewIndex].inverseProjection
|
||||
#define Transform Draws[DrawId].transform
|
||||
#define NormalMatrix mat3(Draws[DrawId].normalMatrix)
|
||||
#define PassColor Draws[DrawId].color
|
||||
#define Transform Draws[DrawID].transform
|
||||
#define NormalMatrix mat3(Draws[DrawID].normalMatrix)
|
||||
#define PassColor Draws[DrawID].color
|
||||
|
||||
#define ClipFromLocal (ViewProjection * Transform)
|
||||
#define ClipFromWorld (ViewProjection)
|
||||
#define ClipFromView (Projection)
|
||||
#define ViewFromLocal (View * Transform)
|
||||
#define ViewFromWorld (View)
|
||||
#define ViewFromClip (InverseProjection)
|
||||
#define WorldFromLocal (Transform)
|
||||
#define WorldFromView (inverse(View))
|
||||
#define WorldFromClip (inverse(ViewProjection))
|
||||
|
||||
#define CameraPositionWorld (-View[3].xyz * mat3(View))
|
||||
|
||||
#define DefaultPosition (ClipFromLocal * VertexPosition)
|
||||
#define DefaultColor (Color * getPixel(ColorTexture, UV))
|
||||
#endif
|
||||
|
||||
// Constants
|
||||
#define PI 3.141592653589793238462643383279502f
|
||||
#define TAU (2.f * PI)
|
||||
#define PI_2 (.5f * PI)
|
||||
|
||||
// Helpers
|
||||
#ifdef GL_FRAGMENT_SHADER
|
||||
#ifndef GL_COMPUTE_SHADER
|
||||
vec4 getPixel(texture2D t, vec2 uv) { return texture(sampler2D(t, Sampler), uv); }
|
||||
vec4 getPixel(texture3D t, vec3 uvw) { return texture(sampler3D(t, Sampler), uvw); }
|
||||
vec4 getPixel(textureCube t, vec3 dir) { return texture(samplerCube(t, Sampler), dir); }
|
||||
|
@ -156,7 +172,7 @@ void main() {
|
|||
PixelColors[0] = lovrmain();
|
||||
|
||||
if (applyGlow) {
|
||||
PixelColors[0].rgb += getPixel(GlowTexture, UV).rgb * Material.glow.rgb;
|
||||
PixelColors[0].rgb += getPixel(GlowTexture, UV).rgb * Material.glow.rgb * Material.glow.a;
|
||||
}
|
||||
|
||||
if (applyAlphaCutoff && PixelColors[0].a <= Material.alphaCutoff) {
|
||||
|
@ -166,7 +182,7 @@ void main() {
|
|||
#endif
|
||||
|
||||
#ifdef GL_COMPUTE_SHADER
|
||||
vec4 lovrmain();
|
||||
void lovrmain();
|
||||
void main() {
|
||||
lovrmain();
|
||||
}
|
||||
|
|
|
@ -607,7 +607,6 @@ static int l_lovrModelDataGetMaterial(lua_State* L) {
|
|||
lua_pushnumber(L, material->clearcoat), lua_setfield(L, -2, "clearcoat");
|
||||
lua_pushnumber(L, material->clearcoatRoughness), lua_setfield(L, -2, "clearcoatRoughness");
|
||||
lua_pushnumber(L, material->occlusionStrength), lua_setfield(L, -2, "occlusionStrength");
|
||||
lua_pushnumber(L, material->glowStrength), lua_setfield(L, -2, "glowStrength");
|
||||
lua_pushnumber(L, material->normalScale), lua_setfield(L, -2, "normalScale");
|
||||
lua_pushnumber(L, material->alphaCutoff), lua_setfield(L, -2, "alphaCutoff");
|
||||
lua_pushnumber(L, material->pointSize), lua_setfield(L, -2, "pointSize");
|
||||
|
|
|
@ -771,18 +771,18 @@ static int l_lovrGraphicsGetLimits(lua_State* L) {
|
|||
lua_pushinteger(L, limits.clipAndCullDistances), lua_setfield(L, -2, "clipAndCullDistances");
|
||||
|
||||
lua_createtable(L, 3, 0);
|
||||
lua_pushinteger(L, limits.computeDispatchCount[0]), lua_rawseti(L, -2, 1);
|
||||
lua_pushinteger(L, limits.computeDispatchCount[1]), lua_rawseti(L, -2, 2);
|
||||
lua_pushinteger(L, limits.computeDispatchCount[2]), lua_rawseti(L, -2, 3);
|
||||
lua_setfield(L, -2, "computeDispatchCount");
|
||||
lua_pushinteger(L, limits.workgroupCount[0]), lua_rawseti(L, -2, 1);
|
||||
lua_pushinteger(L, limits.workgroupCount[1]), lua_rawseti(L, -2, 2);
|
||||
lua_pushinteger(L, limits.workgroupCount[2]), lua_rawseti(L, -2, 3);
|
||||
lua_setfield(L, -2, "workgroupCount");
|
||||
|
||||
lua_createtable(L, 3, 0);
|
||||
lua_pushinteger(L, limits.computeWorkgroupSize[0]), lua_rawseti(L, -2, 1);
|
||||
lua_pushinteger(L, limits.computeWorkgroupSize[1]), lua_rawseti(L, -2, 2);
|
||||
lua_pushinteger(L, limits.computeWorkgroupSize[2]), lua_rawseti(L, -2, 3);
|
||||
lua_setfield(L, -2, "computeWorkgroupSize");
|
||||
lua_pushinteger(L, limits.workgroupSize[0]), lua_rawseti(L, -2, 1);
|
||||
lua_pushinteger(L, limits.workgroupSize[1]), lua_rawseti(L, -2, 2);
|
||||
lua_pushinteger(L, limits.workgroupSize[2]), lua_rawseti(L, -2, 3);
|
||||
lua_setfield(L, -2, "workgroupSize");
|
||||
|
||||
lua_pushinteger(L, limits.computeWorkgroupVolume), lua_setfield(L, -2, "computeWorkgroupVolume");
|
||||
lua_pushinteger(L, limits.totalWorkgroupSize), lua_setfield(L, -2, "totalWorkgroupSize");
|
||||
lua_pushinteger(L, limits.computeSharedMemory), lua_setfield(L, -2, "computeSharedMemory");
|
||||
lua_pushinteger(L, limits.shaderConstantSize), lua_setfield(L, -2, "shaderConstantSize");
|
||||
lua_pushinteger(L, limits.indirectDrawCount), lua_setfield(L, -2, "indirectDrawCount");
|
||||
|
@ -1346,10 +1346,6 @@ static int l_lovrGraphicsNewMaterial(lua_State* L) {
|
|||
info.data.occlusionStrength = luax_optfloat(L, -1, 1.f);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, 1, "glowStrength");
|
||||
info.data.glowStrength = luax_optfloat(L, -1, 1.f);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, 1, "normalScale");
|
||||
info.data.normalScale = luax_optfloat(L, -1, 1.f);
|
||||
lua_pop(L, 1);
|
||||
|
|
|
@ -50,7 +50,6 @@ static int l_lovrMaterialGetProperties(lua_State* L) {
|
|||
lua_pushnumber(L, info->data.clearcoat), lua_setfield(L, -2, "clearcoat");
|
||||
lua_pushnumber(L, info->data.clearcoatRoughness), lua_setfield(L, -2, "clearcoatRoughness");
|
||||
lua_pushnumber(L, info->data.occlusionStrength), lua_setfield(L, -2, "occlusionStrength");
|
||||
lua_pushnumber(L, info->data.glowStrength), lua_setfield(L, -2, "glowStrength");
|
||||
lua_pushnumber(L, info->data.normalScale), lua_setfield(L, -2, "normalScale");
|
||||
lua_pushnumber(L, info->data.alphaCutoff), lua_setfield(L, -2, "alphaCutoff");
|
||||
lua_pushnumber(L, info->data.pointSize), lua_setfield(L, -2, "pointSize");
|
||||
|
|
|
@ -64,7 +64,7 @@ static int l_lovrShaderHasAttribute(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrShaderGetLocalWorkgroupSize(lua_State* L) {
|
||||
static int l_lovrShaderGetWorkgroupSize(lua_State* L) {
|
||||
Shader* shader = luax_checktype(L, 1, Shader);
|
||||
|
||||
if (!lovrShaderHasStage(shader, STAGE_COMPUTE)) {
|
||||
|
@ -73,7 +73,7 @@ static int l_lovrShaderGetLocalWorkgroupSize(lua_State* L) {
|
|||
}
|
||||
|
||||
uint32_t size[3];
|
||||
lovrShaderGetLocalWorkgroupSize(shader, size);
|
||||
lovrShaderGetWorkgroupSize(shader, size);
|
||||
lua_pushinteger(L, size[0]);
|
||||
lua_pushinteger(L, size[1]);
|
||||
lua_pushinteger(L, size[2]);
|
||||
|
@ -85,6 +85,6 @@ const luaL_Reg lovrShader[] = {
|
|||
{ "getType", l_lovrShaderGetType },
|
||||
{ "hasStage", l_lovrShaderHasStage },
|
||||
{ "hasAttribute", l_lovrShaderHasAttribute },
|
||||
{ "getLocalWorkgroupSize", l_lovrShaderGetLocalWorkgroupSize },
|
||||
{ "getWorkgroupSize", l_lovrShaderGetWorkgroupSize },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -186,6 +186,11 @@ static int l_lovrSystemGetWindowDimensions(lua_State* L) {
|
|||
|
||||
static int l_lovrSystemGetWindowDensity(lua_State* L) {
|
||||
lua_pushnumber(L, lovrSystemGetWindowDensity());
|
||||
}
|
||||
|
||||
static int l_lovrSystemIsKeyDown(lua_State* L) {
|
||||
os_key key = luax_checkenum(L, 1, KeyboardKey, NULL);
|
||||
lua_pushboolean(L, lovrSystemIsKeyDown(key));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -199,6 +204,7 @@ static const luaL_Reg lovrSystem[] = {
|
|||
{ "getWindowHeight", l_lovrSystemGetWindowHeight },
|
||||
{ "getWindowDimensions", l_lovrSystemGetWindowDimensions },
|
||||
{ "getWindowDensity", l_lovrSystemGetWindowDensity },
|
||||
{ "isKeyDown", l_lovrSystemIsKeyDown },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -665,9 +665,9 @@ typedef struct {
|
|||
uint32_t clipDistances;
|
||||
uint32_t cullDistances;
|
||||
uint32_t clipAndCullDistances;
|
||||
uint32_t computeDispatchCount[3];
|
||||
uint32_t computeWorkgroupSize[3];
|
||||
uint32_t computeWorkgroupVolume;
|
||||
uint32_t workgroupCount[3];
|
||||
uint32_t workgroupSize[3];
|
||||
uint32_t totalWorkgroupSize;
|
||||
uint32_t computeSharedMemory;
|
||||
uint32_t pushConstantSize;
|
||||
uint32_t indirectDrawCount;
|
||||
|
|
|
@ -1928,13 +1928,13 @@ bool gpu_init(gpu_config* config) {
|
|||
config->limits->clipDistances = limits->maxClipDistances;
|
||||
config->limits->cullDistances = limits->maxCullDistances;
|
||||
config->limits->clipAndCullDistances = limits->maxCombinedClipAndCullDistances;
|
||||
config->limits->computeDispatchCount[0] = limits->maxComputeWorkGroupCount[0];
|
||||
config->limits->computeDispatchCount[1] = limits->maxComputeWorkGroupCount[1];
|
||||
config->limits->computeDispatchCount[2] = limits->maxComputeWorkGroupCount[2];
|
||||
config->limits->computeWorkgroupSize[0] = limits->maxComputeWorkGroupSize[0];
|
||||
config->limits->computeWorkgroupSize[1] = limits->maxComputeWorkGroupSize[1];
|
||||
config->limits->computeWorkgroupSize[2] = limits->maxComputeWorkGroupSize[2];
|
||||
config->limits->computeWorkgroupVolume = limits->maxComputeWorkGroupInvocations;
|
||||
config->limits->workgroupCount[0] = limits->maxComputeWorkGroupCount[0];
|
||||
config->limits->workgroupCount[1] = limits->maxComputeWorkGroupCount[1];
|
||||
config->limits->workgroupCount[2] = limits->maxComputeWorkGroupCount[2];
|
||||
config->limits->workgroupSize[0] = limits->maxComputeWorkGroupSize[0];
|
||||
config->limits->workgroupSize[1] = limits->maxComputeWorkGroupSize[1];
|
||||
config->limits->workgroupSize[2] = limits->maxComputeWorkGroupSize[2];
|
||||
config->limits->totalWorkgroupSize = limits->maxComputeWorkGroupInvocations;
|
||||
config->limits->computeSharedMemory = limits->maxComputeSharedMemorySize;
|
||||
config->limits->pushConstantSize = limits->maxPushConstantsSize;
|
||||
config->limits->indirectDrawCount = limits->maxDrawIndirectCount;
|
||||
|
|
|
@ -187,9 +187,9 @@ static spv_result spv_parse_execution_mode(spv_context* spv, const uint32_t* op,
|
|||
return SPV_OK;
|
||||
}
|
||||
|
||||
info->localWorkgroupSize[0] = op[3];
|
||||
info->localWorkgroupSize[1] = op[4];
|
||||
info->localWorkgroupSize[2] = op[5];
|
||||
info->workgroupSize[0] = op[3];
|
||||
info->workgroupSize[1] = op[4];
|
||||
info->workgroupSize[2] = op[5];
|
||||
return SPV_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
uint32_t localWorkgroupSize[3];
|
||||
uint32_t workgroupSize[3];
|
||||
uint32_t featureCount;
|
||||
uint32_t specConstantCount;
|
||||
uint32_t pushConstantCount;
|
||||
|
|
|
@ -84,7 +84,6 @@ typedef struct {
|
|||
float clearcoat;
|
||||
float clearcoatRoughness;
|
||||
float occlusionStrength;
|
||||
float glowStrength;
|
||||
float normalScale;
|
||||
float alphaCutoff;
|
||||
float pointSize;
|
||||
|
|
|
@ -695,7 +695,7 @@ ModelData* lovrModelDataInitGltf(ModelData* model, Blob* source, ModelDataIO* io
|
|||
ModelMaterial* material = model->materials;
|
||||
for (int i = (token++)->size; i > 0; i--, material++) {
|
||||
memcpy(material->color, (float[4]) { 1.f, 1.f, 1.f, 1.f }, 16);
|
||||
memcpy(material->glow, (float[4]) { 0.f, 0.f, 0.f, 0.f }, 16);
|
||||
memcpy(material->glow, (float[4]) { 0.f, 0.f, 0.f, 1.f }, 16);
|
||||
material->uvShift[0] = 0.f;
|
||||
material->uvShift[1] = 0.f;
|
||||
material->uvScale[0] = 1.f;
|
||||
|
@ -705,7 +705,6 @@ ModelData* lovrModelDataInitGltf(ModelData* model, Blob* source, ModelDataIO* io
|
|||
material->clearcoat = 0.f;
|
||||
material->clearcoatRoughness = 0.f;
|
||||
material->occlusionStrength = 1.f;
|
||||
material->glowStrength = 1.f;
|
||||
material->normalScale = 1.f;
|
||||
material->alphaCutoff = 0.f;
|
||||
material->pointSize = 1.f;
|
||||
|
|
|
@ -48,7 +48,7 @@ static void parseMtl(char* path, char* base, ModelDataIO* io, arr_image_t* image
|
|||
map_set(names, hash64(line + 7, length - 7), materials->length);
|
||||
arr_push(materials, ((ModelMaterial) {
|
||||
.color = { 1.f, 1.f, 1.f, 1.f },
|
||||
.glow = { 0.f, 0.f, 0.f, 0.f },
|
||||
.glow = { 0.f, 0.f, 0.f, 1.f },
|
||||
.uvShift = { 0.f, 0.f },
|
||||
.uvScale = { 1.f, 1.f },
|
||||
.metalness = 1.f,
|
||||
|
@ -56,7 +56,6 @@ static void parseMtl(char* path, char* base, ModelDataIO* io, arr_image_t* image
|
|||
.clearcoat = 0.f,
|
||||
.clearcoatRoughness = 0.f,
|
||||
.occlusionStrength = 1.f,
|
||||
.glowStrength = 1.f,
|
||||
.normalScale = 1.f,
|
||||
.alphaCutoff = 0.f,
|
||||
.pointSize = 1.f,
|
||||
|
|
|
@ -101,7 +101,7 @@ struct Shader {
|
|||
ShaderInfo info;
|
||||
uint32_t layout;
|
||||
uint32_t computePipeline;
|
||||
uint32_t localWorkgroupSize[3];
|
||||
uint32_t workgroupSize[3];
|
||||
uint32_t bufferMask;
|
||||
uint32_t textureMask;
|
||||
uint32_t samplerMask;
|
||||
|
@ -236,6 +236,11 @@ struct Tally {
|
|||
gpu_buffer* buffer;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
float resolution[4];
|
||||
float time;
|
||||
} Globals;
|
||||
|
||||
typedef struct {
|
||||
float view[16];
|
||||
float projection[16];
|
||||
|
@ -312,7 +317,7 @@ struct Pass {
|
|||
bool cameraDirty;
|
||||
DrawData* drawData;
|
||||
uint32_t drawCount;
|
||||
gpu_binding builtins[3];
|
||||
gpu_binding builtins[4];
|
||||
gpu_buffer* vertexBuffer;
|
||||
gpu_buffer* indexBuffer;
|
||||
Shape shapeCache[16];
|
||||
|
@ -461,9 +466,10 @@ bool lovrGraphicsInit(GraphicsConfig* config) {
|
|||
arr_init(&state.materialBlocks, realloc);
|
||||
|
||||
gpu_slot builtinSlots[] = {
|
||||
{ 0, GPU_SLOT_UNIFORM_BUFFER, GPU_STAGE_ALL }, // Cameras
|
||||
{ 1, GPU_SLOT_UNIFORM_BUFFER, GPU_STAGE_ALL }, // Draw data
|
||||
{ 2, GPU_SLOT_SAMPLER, GPU_STAGE_ALL } // Default sampler
|
||||
{ 0, GPU_SLOT_UNIFORM_BUFFER, GPU_STAGE_ALL }, // Globals
|
||||
{ 1, GPU_SLOT_UNIFORM_BUFFER, GPU_STAGE_ALL }, // Cameras
|
||||
{ 2, GPU_SLOT_UNIFORM_BUFFER, GPU_STAGE_ALL }, // Draw data
|
||||
{ 3, GPU_SLOT_SAMPLER, GPU_STAGE_ALL }, // Default sampler
|
||||
};
|
||||
|
||||
state.builtinLayout = getLayout(builtinSlots, COUNTOF(builtinSlots));
|
||||
|
@ -728,9 +734,9 @@ void lovrGraphicsGetLimits(GraphicsLimits* limits) {
|
|||
limits->clipDistances = state.limits.clipDistances;
|
||||
limits->cullDistances = state.limits.cullDistances;
|
||||
limits->clipAndCullDistances = state.limits.clipAndCullDistances;
|
||||
memcpy(limits->computeDispatchCount, state.limits.computeDispatchCount, 3 * sizeof(uint32_t));
|
||||
memcpy(limits->computeWorkgroupSize, state.limits.computeWorkgroupSize, 3 * sizeof(uint32_t));
|
||||
limits->computeWorkgroupVolume = state.limits.computeWorkgroupVolume;
|
||||
memcpy(limits->workgroupCount, state.limits.workgroupCount, 3 * sizeof(uint32_t));
|
||||
memcpy(limits->workgroupSize, state.limits.workgroupSize, 3 * sizeof(uint32_t));
|
||||
limits->totalWorkgroupSize = state.limits.totalWorkgroupSize;
|
||||
limits->computeSharedMemory = state.limits.computeSharedMemory;
|
||||
limits->shaderConstantSize = MIN(state.limits.pushConstantSize, 256);
|
||||
limits->indirectDrawCount = state.limits.indirectDrawCount;
|
||||
|
@ -1556,7 +1562,12 @@ Shader* lovrShaderCreate(const ShaderInfo* info) {
|
|||
}
|
||||
|
||||
if (info->type == SHADER_COMPUTE) {
|
||||
memcpy(shader->localWorkgroupSize, spv[0].localWorkgroupSize, 3 * sizeof(uint32_t));
|
||||
memcpy(shader->workgroupSize, spv[0].workgroupSize, 3 * sizeof(uint32_t));
|
||||
lovrCheck(shader->workgroupSize[0] <= state.limits.workgroupSize[0], "Shader workgroup size exceeds the 'workgroupSize' limit");
|
||||
lovrCheck(shader->workgroupSize[1] <= state.limits.workgroupSize[1], "Shader workgroup size exceeds the 'workgroupSize' limit");
|
||||
lovrCheck(shader->workgroupSize[2] <= state.limits.workgroupSize[2], "Shader workgroup size exceeds the 'workgroupSize' limit");
|
||||
uint32_t totalWorkgroupSize = shader->workgroupSize[0] * shader->workgroupSize[1] * shader->workgroupSize[2];
|
||||
lovrCheck(totalWorkgroupSize <= state.limits.totalWorkgroupSize, "Shader workgroup size exceeds the 'totalWorkgroupSize' limit");
|
||||
}
|
||||
|
||||
uint32_t constantStage = spv[0].pushConstantSize > spv[1].pushConstantSize ? 0 : 1;
|
||||
|
@ -1818,8 +1829,8 @@ bool lovrShaderHasAttribute(Shader* shader, const char* name, uint32_t location)
|
|||
return false;
|
||||
}
|
||||
|
||||
void lovrShaderGetLocalWorkgroupSize(Shader* shader, uint32_t size[3]) {
|
||||
memcpy(size, shader->localWorkgroupSize, 3 * sizeof(uint32_t));
|
||||
void lovrShaderGetWorkgroupSize(Shader* shader, uint32_t size[3]) {
|
||||
memcpy(size, shader->workgroupSize, 3 * sizeof(uint32_t));
|
||||
}
|
||||
|
||||
// Material
|
||||
|
@ -3404,13 +3415,28 @@ void lovrPassReset(Pass* pass) {
|
|||
}
|
||||
pass->cameraDirty = true;
|
||||
|
||||
gpu_buffer_binding globals = { tempAlloc(gpu_sizeof_buffer()), 0, sizeof(Globals) };
|
||||
gpu_buffer_binding cameras = { tempAlloc(gpu_sizeof_buffer()), 0, pass->cameraCount * sizeof(Camera) };
|
||||
gpu_buffer_binding draws = { tempAlloc(gpu_sizeof_buffer()), 0, 256 * sizeof(DrawData) };
|
||||
pass->drawCount = 0;
|
||||
|
||||
pass->builtins[0] = (gpu_binding) { 0, GPU_SLOT_UNIFORM_BUFFER, .buffer = cameras };
|
||||
pass->builtins[1] = (gpu_binding) { 1, GPU_SLOT_UNIFORM_BUFFER, .buffer = draws };
|
||||
pass->builtins[2] = (gpu_binding) { 2, GPU_SLOT_SAMPLER, .sampler = NULL };
|
||||
pass->builtins[0] = (gpu_binding) { 0, GPU_SLOT_UNIFORM_BUFFER, .buffer = globals };
|
||||
pass->builtins[1] = (gpu_binding) { 1, GPU_SLOT_UNIFORM_BUFFER, .buffer = cameras };
|
||||
pass->builtins[2] = (gpu_binding) { 2, GPU_SLOT_UNIFORM_BUFFER, .buffer = draws };
|
||||
pass->builtins[3] = (gpu_binding) { 3, GPU_SLOT_SAMPLER, .sampler = NULL };
|
||||
|
||||
Globals* global = gpu_map(pass->builtins[0].buffer.object, sizeof(Globals), state.limits.uniformBufferAlign, GPU_MAP_WRITE);
|
||||
|
||||
global->resolution[0] = pass->target.size[0];
|
||||
global->resolution[1] = pass->target.size[1];
|
||||
global->resolution[2] = 1.f / pass->target.size[0];
|
||||
global->resolution[3] = 1.f / pass->target.size[1];
|
||||
|
||||
#ifndef LOVR_DISABLE_HEADSET
|
||||
global->time = lovrHeadsetInterface ? lovrHeadsetInterface->getDisplayTime() : os_get_time();
|
||||
#else
|
||||
global->time = os_get_time();
|
||||
#endif
|
||||
|
||||
pass->vertexBuffer = NULL;
|
||||
pass->indexBuffer = NULL;
|
||||
|
@ -4089,7 +4115,7 @@ static void flushBuiltins(Pass* pass, Draw* draw, Shader* shader) {
|
|||
}
|
||||
|
||||
uint32_t size = pass->cameraCount * sizeof(Camera);
|
||||
void* data = gpu_map(pass->builtins[0].buffer.object, size, state.limits.uniformBufferAlign, GPU_MAP_WRITE);
|
||||
void* data = gpu_map(pass->builtins[1].buffer.object, size, state.limits.uniformBufferAlign, GPU_MAP_WRITE);
|
||||
memcpy(data, pass->cameras, size);
|
||||
pass->cameraDirty = false;
|
||||
rebind = true;
|
||||
|
@ -4097,13 +4123,13 @@ static void flushBuiltins(Pass* pass, Draw* draw, Shader* shader) {
|
|||
|
||||
if (pass->drawCount % 256 == 0) {
|
||||
uint32_t size = 256 * sizeof(DrawData);
|
||||
pass->drawData = gpu_map(pass->builtins[1].buffer.object, size, state.limits.uniformBufferAlign, GPU_MAP_WRITE);
|
||||
pass->drawData = gpu_map(pass->builtins[2].buffer.object, size, state.limits.uniformBufferAlign, GPU_MAP_WRITE);
|
||||
rebind = true;
|
||||
}
|
||||
|
||||
if (pass->samplerDirty) {
|
||||
Sampler* sampler = pass->pipeline->sampler ? pass->pipeline->sampler : state.defaultSamplers[FILTER_LINEAR];
|
||||
pass->builtins[2].sampler = sampler->gpu;
|
||||
pass->builtins[3].sampler = sampler->gpu;
|
||||
pass->samplerDirty = false;
|
||||
rebind = true;
|
||||
}
|
||||
|
@ -5087,9 +5113,9 @@ void lovrPassCompute(Pass* pass, uint32_t x, uint32_t y, uint32_t z, Buffer* ind
|
|||
|
||||
Shader* shader = pass->pipeline->shader;
|
||||
lovrCheck(shader && shader->info.type == SHADER_COMPUTE, "Tried to run a compute shader, but no compute shader is bound");
|
||||
lovrCheck(x <= state.limits.computeDispatchCount[0], "Compute %s count exceeds computeDispatchCount limit", "x");
|
||||
lovrCheck(y <= state.limits.computeDispatchCount[1], "Compute %s count exceeds computeDispatchCount limit", "y");
|
||||
lovrCheck(z <= state.limits.computeDispatchCount[2], "Compute %s count exceeds computeDispatchCount limit", "z");
|
||||
lovrCheck(x <= state.limits.workgroupCount[0], "Compute %s count exceeds workgroupCount limit", "x");
|
||||
lovrCheck(y <= state.limits.workgroupCount[1], "Compute %s count exceeds workgroupCount limit", "y");
|
||||
lovrCheck(z <= state.limits.workgroupCount[2], "Compute %s count exceeds workgroupCount limit", "z");
|
||||
|
||||
gpu_pipeline* pipeline = state.pipelines.data[shader->computePipeline];
|
||||
|
||||
|
|
|
@ -72,9 +72,9 @@ typedef struct {
|
|||
uint32_t clipDistances;
|
||||
uint32_t cullDistances;
|
||||
uint32_t clipAndCullDistances;
|
||||
uint32_t computeDispatchCount[3];
|
||||
uint32_t computeWorkgroupSize[3];
|
||||
uint32_t computeWorkgroupVolume;
|
||||
uint32_t workgroupCount[3];
|
||||
uint32_t workgroupSize[3];
|
||||
uint32_t totalWorkgroupSize;
|
||||
uint32_t computeSharedMemory;
|
||||
uint32_t shaderConstantSize;
|
||||
uint32_t indirectDrawCount;
|
||||
|
@ -315,7 +315,7 @@ void lovrShaderDestroy(void* ref);
|
|||
const ShaderInfo* lovrShaderGetInfo(Shader* shader);
|
||||
bool lovrShaderHasStage(Shader* shader, ShaderStage stage);
|
||||
bool lovrShaderHasAttribute(Shader* shader, const char* name, uint32_t location);
|
||||
void lovrShaderGetLocalWorkgroupSize(Shader* shader, uint32_t size[3]);
|
||||
void lovrShaderGetWorkgroupSize(Shader* shader, uint32_t size[3]);
|
||||
|
||||
// Material
|
||||
|
||||
|
@ -330,7 +330,6 @@ typedef struct {
|
|||
float clearcoat;
|
||||
float clearcoatRoughness;
|
||||
float occlusionStrength;
|
||||
float glowStrength;
|
||||
float normalScale;
|
||||
float alphaCutoff;
|
||||
float pointSize;
|
||||
|
|
|
@ -60,7 +60,7 @@ Vector lovrPoolAllocate(Pool* pool, VectorType type, float** data) {
|
|||
}
|
||||
|
||||
float* lovrPoolResolve(Pool* pool, Vector vector) {
|
||||
lovrAssert(vector.handle.generation == pool->generation, "Attempt to use a vector in a different generation than the one it was created in (vectors can not be saved into variables)");
|
||||
lovrAssert(vector.handle.generation == pool->generation, "Attempt to use a temporary vector from a previous frame");
|
||||
return pool->data + vector.handle.index;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,11 @@ static struct {
|
|||
bool initialized;
|
||||
int windowWidth;
|
||||
int windowHeight;
|
||||
bool pressedKeys[KEY_COUNT];
|
||||
} state;
|
||||
|
||||
static void onKey(os_button_action action, os_key key, uint32_t scancode, bool repeat) {
|
||||
state.pressedKeys[key] = (action == BUTTON_PRESSED);
|
||||
lovrEventPush((Event) {
|
||||
.type = action == BUTTON_PRESSED ? EVENT_KEYPRESSED : EVENT_KEYRELEASED,
|
||||
.data.key.code = key,
|
||||
|
@ -73,6 +75,10 @@ uint32_t lovrSystemGetCoreCount() {
|
|||
return os_get_core_count();
|
||||
}
|
||||
|
||||
bool lovrSystemIsKeyDown(int keycode) {
|
||||
return state.pressedKeys[keycode];
|
||||
}
|
||||
|
||||
void lovrSystemRequestPermission(Permission permission) {
|
||||
os_request_permission((os_permission) permission);
|
||||
}
|
||||
|
|
|
@ -19,3 +19,4 @@ bool lovrSystemIsWindowOpen(void);
|
|||
uint32_t lovrSystemGetWindowWidth(void);
|
||||
uint32_t lovrSystemGetWindowHeight(void);
|
||||
float lovrSystemGetWindowDensity(void);
|
||||
bool lovrSystemIsKeyDown(int keycode);
|
||||
|
|
Loading…
Reference in New Issue