Revert "Another big WebGPU compatibility patch"
This reverts commit 3229c4fa2c
.
This commit is contained in:
parent
dbc03078de
commit
239ecc8d56
17 changed files with 103 additions and 151 deletions
|
@ -7,7 +7,6 @@
|
||||||
#include "object.hpp"
|
#include "object.hpp"
|
||||||
#include "components.hpp"
|
#include "components.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
#include "render_constants.hpp"
|
|
||||||
|
|
||||||
template<class Component>
|
template<class Component>
|
||||||
using Pool = std::unordered_map<prism::Object, Component>;
|
using Pool = std::unordered_map<prism::Object, Component>;
|
||||||
|
@ -194,6 +193,10 @@ private:
|
||||||
std::vector<prism::Object> _objects;
|
std::vector<prism::Object> _objects;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const int max_spot_shadows = 4;
|
||||||
|
const int max_point_shadows = 4;
|
||||||
|
const int max_environment_probes = 4;
|
||||||
|
|
||||||
class GFXFramebuffer;
|
class GFXFramebuffer;
|
||||||
class GFXTexture;
|
class GFXTexture;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ public:
|
||||||
|
|
||||||
ShaderLanguage accepted_shader_language() override;
|
ShaderLanguage accepted_shader_language() override;
|
||||||
const char* get_name() override;
|
const char* get_name() override;
|
||||||
bool supports_feature(GFXFeature feature) override;
|
|
||||||
|
|
||||||
// buffer
|
// buffer
|
||||||
GFXBuffer* create_buffer(void* data, GFXSize size, bool is_dynamic, GFXBufferUsage usage) override;
|
GFXBuffer* create_buffer(void* data, GFXSize size, bool is_dynamic, GFXBufferUsage usage) override;
|
||||||
|
|
|
@ -196,23 +196,10 @@ GFXBuffer* GFXWebGPU::create_buffer(void* data, const GFXSize size, const bool i
|
||||||
buffer->size = size;
|
buffer->size = size;
|
||||||
|
|
||||||
WGPUBufferDescriptor desc = {};
|
WGPUBufferDescriptor desc = {};
|
||||||
|
desc.usage = WGPUBufferUsage_CopyDst;
|
||||||
desc.size = size;
|
desc.size = size;
|
||||||
desc.mappedAtCreation = true;
|
desc.mappedAtCreation = true;
|
||||||
|
|
||||||
switch(usage) {
|
|
||||||
case GFXBufferUsage::Vertex:
|
|
||||||
desc.usage = WGPUBufferUsage_Vertex;
|
|
||||||
break;
|
|
||||||
case GFXBufferUsage::Index:
|
|
||||||
desc.usage = WGPUBufferUsage_Index;
|
|
||||||
break;
|
|
||||||
case GFXBufferUsage::Storage:
|
|
||||||
desc.usage = WGPUBufferUsage_Storage;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
desc.usage |= WGPUBufferUsage_Uniform; // TODO: not currently exposed in gfx api
|
|
||||||
|
|
||||||
buffer->handle = wgpuDeviceCreateBuffer(device, &desc);
|
buffer->handle = wgpuDeviceCreateBuffer(device, &desc);
|
||||||
|
|
||||||
wgpuQueueWriteBuffer(queue, buffer->handle, 0, data, size);
|
wgpuQueueWriteBuffer(queue, buffer->handle, 0, data, size);
|
||||||
|
@ -255,7 +242,6 @@ GFXTexture* GFXWebGPU::create_texture(const GFXTextureCreateInfo& info) {
|
||||||
descriptor.mipLevelCount = info.mip_count;
|
descriptor.mipLevelCount = info.mip_count;
|
||||||
|
|
||||||
descriptor.usage = WGPUTextureUsage_None;
|
descriptor.usage = WGPUTextureUsage_None;
|
||||||
descriptor.sampleCount = 1;
|
|
||||||
|
|
||||||
if((info.usage & GFXTextureUsage::Sampled) == GFXTextureUsage::Sampled)
|
if((info.usage & GFXTextureUsage::Sampled) == GFXTextureUsage::Sampled)
|
||||||
descriptor.usage |= WGPUTextureUsage_TextureBinding;
|
descriptor.usage |= WGPUTextureUsage_TextureBinding;
|
||||||
|
@ -274,17 +260,6 @@ GFXTexture* GFXWebGPU::create_texture(const GFXTextureCreateInfo& info) {
|
||||||
|
|
||||||
texture->handle = wgpuDeviceCreateTexture(device, &descriptor);
|
texture->handle = wgpuDeviceCreateTexture(device, &descriptor);
|
||||||
|
|
||||||
WGPUTextureViewDescriptor view_descriptor = {};
|
|
||||||
view_descriptor.label = info.label.data();
|
|
||||||
view_descriptor.format = descriptor.format;
|
|
||||||
view_descriptor.mipLevelCount = descriptor.mipLevelCount;
|
|
||||||
view_descriptor.dimension = WGPUTextureViewDimension_2D;
|
|
||||||
view_descriptor.baseArrayLayer = 0;
|
|
||||||
view_descriptor.aspect = WGPUTextureAspect_All;
|
|
||||||
view_descriptor.arrayLayerCount = info.array_length;
|
|
||||||
|
|
||||||
texture->view = wgpuTextureCreateView(texture->handle, &view_descriptor);
|
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,10 +278,6 @@ void GFXWebGPU::copy_texture(GFXTexture* from, GFXBuffer* to) {
|
||||||
GFXSampler* GFXWebGPU::create_sampler(const GFXSamplerCreateInfo& info) {
|
GFXSampler* GFXWebGPU::create_sampler(const GFXSamplerCreateInfo& info) {
|
||||||
auto sampler = new GFXWebGPUSampler();
|
auto sampler = new GFXWebGPUSampler();
|
||||||
|
|
||||||
WGPUSamplerDescriptor sampler_descriptor = {};
|
|
||||||
|
|
||||||
sampler->handle = wgpuDeviceCreateSampler(device, &sampler_descriptor);
|
|
||||||
|
|
||||||
return sampler;
|
return sampler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,10 +296,8 @@ GFXRenderPass* GFXWebGPU::create_render_pass(const GFXRenderPassCreateInfo& info
|
||||||
GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreateInfo& info) {
|
GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreateInfo& info) {
|
||||||
auto pipeline = new GFXWebGPUPipeline();
|
auto pipeline = new GFXWebGPUPipeline();
|
||||||
|
|
||||||
pipeline->label = info.label;
|
|
||||||
|
|
||||||
WGPURenderPipelineDescriptor descriptor = {};
|
WGPURenderPipelineDescriptor descriptor = {};
|
||||||
descriptor.label = pipeline->label.c_str();
|
descriptor.label = info.label.c_str();
|
||||||
|
|
||||||
const bool has_vertex_stage = !info.shaders.vertex_src.empty();
|
const bool has_vertex_stage = !info.shaders.vertex_src.empty();
|
||||||
if (has_vertex_stage) {
|
if (has_vertex_stage) {
|
||||||
|
@ -340,7 +309,7 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate
|
||||||
descriptor.vertex.module = create_shader(vertex_shader_vector.data(), vertex_shader_vector.size() * sizeof(uint32_t), std::string(info.label + " vertex stage").c_str());
|
descriptor.vertex.module = create_shader(vertex_shader_vector.data(), vertex_shader_vector.size() * sizeof(uint32_t), std::string(info.label + " vertex stage").c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto vertex_shader = prism::open_file(prism::internal_domain / (info.shaders.vertex_src.as_path().string() + ".wgsl"), true);
|
auto vertex_shader = prism::open_file(prism::internal_domain / (info.shaders.vertex_src.as_path().string() + ".wgsl.spv"), true);
|
||||||
vertex_shader->read_all();
|
vertex_shader->read_all();
|
||||||
|
|
||||||
descriptor.vertex.module = create_shader(vertex_shader->cast_data<uint32_t>(), vertex_shader->size(), info.shaders.vertex_src.as_path().string().c_str());
|
descriptor.vertex.module = create_shader(vertex_shader->cast_data<uint32_t>(), vertex_shader->size(), info.shaders.vertex_src.as_path().string().c_str());
|
||||||
|
@ -348,7 +317,6 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate
|
||||||
}
|
}
|
||||||
|
|
||||||
WGPUFragmentState fragment = {};
|
WGPUFragmentState fragment = {};
|
||||||
fragment.entryPoint = "main";
|
|
||||||
|
|
||||||
const bool has_fragment_stage = !info.shaders.fragment_src.empty();
|
const bool has_fragment_stage = !info.shaders.fragment_src.empty();
|
||||||
if (has_fragment_stage) {
|
if (has_fragment_stage) {
|
||||||
|
@ -362,15 +330,13 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate
|
||||||
fragment.module = create_shader(fragment_shader_vector.data(), fragment_shader_vector.size() * sizeof(uint32_t), std::string(info.label + " fragment stage").c_str());
|
fragment.module = create_shader(fragment_shader_vector.data(), fragment_shader_vector.size() * sizeof(uint32_t), std::string(info.label + " fragment stage").c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto fragment_shader = prism::open_file(prism::internal_domain / (info.shaders.fragment_src.as_path().string() + ".wgsl"), true);
|
auto fragment_shader = prism::open_file(prism::internal_domain / (info.shaders.fragment_src.as_path().string() + ".wgsl.spv"), true);
|
||||||
fragment_shader->read_all();
|
fragment_shader->read_all();
|
||||||
|
|
||||||
fragment.module = create_shader(fragment_shader->cast_data<uint32_t>(), fragment_shader->size(), info.shaders.fragment_src.as_path().string().c_str());
|
fragment.module = create_shader(fragment_shader->cast_data<uint32_t>(), fragment_shader->size(), info.shaders.fragment_src.as_path().string().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptor.vertex.entryPoint = "main";
|
|
||||||
|
|
||||||
prism::log("building pipeline {}", info.label);
|
prism::log("building pipeline {}", info.label);
|
||||||
prism::log("--------");
|
prism::log("--------");
|
||||||
|
|
||||||
|
@ -434,6 +400,7 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
descriptor.primitive.stripIndexFormat = WGPUIndexFormat_Uint16;
|
||||||
descriptor.primitive.topology = WGPUPrimitiveTopology_TriangleList;
|
descriptor.primitive.topology = WGPUPrimitiveTopology_TriangleList;
|
||||||
|
|
||||||
// create bind group layout
|
// create bind group layout
|
||||||
|
@ -472,8 +439,6 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate
|
||||||
group_entries.push_back(entry);
|
group_entries.push_back(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptor.multisample.count = 1;
|
|
||||||
|
|
||||||
WGPUBindGroupLayoutDescriptor bind_group_layout_descriptor = {};
|
WGPUBindGroupLayoutDescriptor bind_group_layout_descriptor = {};
|
||||||
bind_group_layout_descriptor.entryCount = group_entries.size();
|
bind_group_layout_descriptor.entryCount = group_entries.size();
|
||||||
bind_group_layout_descriptor.entries = group_entries.data();
|
bind_group_layout_descriptor.entries = group_entries.data();
|
||||||
|
@ -500,20 +465,15 @@ GFXPipeline* GFXWebGPU::create_compute_pipeline(const GFXComputePipelineCreateIn
|
||||||
descriptor.compute.module = create_shader(compute_shader_vector.data(), compute_shader_vector.size() * sizeof(uint32_t), info.label.c_str());
|
descriptor.compute.module = create_shader(compute_shader_vector.data(), compute_shader_vector.size() * sizeof(uint32_t), info.label.c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto compute_shader = prism::open_file(prism::internal_domain / (info.compute_src.as_path().string() + ".wgsl"), true);
|
auto compute_shader = prism::open_file(prism::internal_domain / (info.compute_src.as_path().string() + ".wgsl.spv"), true);
|
||||||
compute_shader->read_all();
|
compute_shader->read_all();
|
||||||
|
|
||||||
descriptor.compute.module = create_shader(compute_shader->cast_data<uint32_t>(), compute_shader->size(), info.compute_src.as_path().string().c_str());
|
descriptor.compute.module = create_shader(compute_shader->cast_data<uint32_t>(), compute_shader->size(), info.compute_src.as_path().string().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pipeline->compute_handle = wgpuDeviceCreateComputePipeline(device, &descriptor);
|
pipeline->compute_handle = wgpuDeviceCreateComputePipeline(device, &descriptor);
|
||||||
|
|
||||||
WGPUBindGroupLayoutDescriptor bind_group_layout_descriptor = {};
|
|
||||||
|
|
||||||
pipeline->bind_group_layout = wgpuDeviceCreateBindGroupLayout(device, &bind_group_layout_descriptor);
|
|
||||||
|
|
||||||
return pipeline;
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,18 +579,17 @@ void GFXWebGPU::submit(GFXCommandBuffer* command_buffer, const platform::window_
|
||||||
if(current_pipeline == nullptr)
|
if(current_pipeline == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const uint64_t hash = get_bind_group_hash(current_pipeline);
|
if(last_bind_group_hash != get_bind_group_hash(current_pipeline)) {
|
||||||
if(last_bind_group_hash != hash) {
|
if(!current_pipeline->cached_bind_groups.count(get_bind_group_hash(current_pipeline)))
|
||||||
if(!current_pipeline->cached_bind_groups.count(hash))
|
|
||||||
cache_bind_group_state(current_pipeline, current_pipeline->bind_group_layout);
|
cache_bind_group_state(current_pipeline, current_pipeline->bind_group_layout);
|
||||||
|
|
||||||
auto bind_group = current_pipeline->cached_bind_groups[hash];
|
auto& bind_group = current_pipeline->cached_bind_groups[get_bind_group_hash(current_pipeline)];
|
||||||
if(bind_group == nullptr)
|
if(bind_group == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
wgpuRenderPassEncoderSetBindGroup(render_encoder, 0, bind_group, 0, nullptr);
|
wgpuRenderPassEncoderSetBindGroup(render_encoder, 0, bind_group, 0, nullptr);
|
||||||
|
|
||||||
last_bind_group_hash = hash;
|
last_bind_group_hash = get_bind_group_hash(current_pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -872,18 +831,14 @@ uint64_t GFXWebGPU::get_bind_group_hash(GFXWebGPUPipeline *pipeline) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXWebGPU::cache_bind_group_state(GFXWebGPUPipeline* pipeline, WGPUBindGroupLayout group_layout) {
|
void GFXWebGPU::cache_bind_group_state(GFXWebGPUPipeline* pipeline, WGPUBindGroupLayout group_layout) {
|
||||||
const uint64_t hash = get_bind_group_hash(pipeline);
|
uint64_t hash = get_bind_group_hash(pipeline);
|
||||||
|
|
||||||
std::vector<WGPUBindGroupEntry> group_entries;
|
std::vector<WGPUBindGroupEntry> group_entries;
|
||||||
|
|
||||||
prism::log("creating bind group for {}", pipeline->label);
|
|
||||||
|
|
||||||
for (auto [i, buffer] : utility::enumerate(boundShaderBuffers)) {
|
for (auto [i, buffer] : utility::enumerate(boundShaderBuffers)) {
|
||||||
if (buffer.buffer != nullptr) {
|
if (buffer.buffer != nullptr) {
|
||||||
auto wgpu_buffer = (GFXWebGPUBuffer*)buffer.buffer;
|
auto wgpu_buffer = (GFXWebGPUBuffer*)buffer.buffer;
|
||||||
|
|
||||||
prism::log("binding {} filled", i);
|
|
||||||
|
|
||||||
WGPUBindGroupEntry entry = {};
|
WGPUBindGroupEntry entry = {};
|
||||||
entry.buffer = wgpu_buffer->handle;
|
entry.buffer = wgpu_buffer->handle;
|
||||||
entry.size = buffer.size;
|
entry.size = buffer.size;
|
||||||
|
@ -898,10 +853,9 @@ void GFXWebGPU::cache_bind_group_state(GFXWebGPUPipeline* pipeline, WGPUBindGrou
|
||||||
if (texture != nullptr) {
|
if (texture != nullptr) {
|
||||||
auto wgpu_texture = (GFXWebGPUTexture*) texture;
|
auto wgpu_texture = (GFXWebGPUTexture*) texture;
|
||||||
|
|
||||||
prism::log("binding {} filled", i);
|
|
||||||
|
|
||||||
WGPUBindGroupEntry entry = {};
|
WGPUBindGroupEntry entry = {};
|
||||||
entry.textureView = wgpu_texture->view;
|
entry.textureView = wgpu_texture->view;
|
||||||
|
entry.sampler = wgpu_texture->sampler;
|
||||||
entry.binding = i;
|
entry.binding = i;
|
||||||
|
|
||||||
group_entries.push_back(entry);
|
group_entries.push_back(entry);
|
||||||
|
@ -912,8 +866,6 @@ void GFXWebGPU::cache_bind_group_state(GFXWebGPUPipeline* pipeline, WGPUBindGrou
|
||||||
if (sampler != nullptr) {
|
if (sampler != nullptr) {
|
||||||
auto wgpu_sampler = (GFXWebGPUSampler*) sampler;
|
auto wgpu_sampler = (GFXWebGPUSampler*) sampler;
|
||||||
|
|
||||||
prism::log("binding {} filled", i);
|
|
||||||
|
|
||||||
WGPUBindGroupEntry entry = {};
|
WGPUBindGroupEntry entry = {};
|
||||||
entry.sampler = wgpu_sampler->handle;
|
entry.sampler = wgpu_sampler->handle;
|
||||||
entry.binding = i;
|
entry.binding = i;
|
||||||
|
@ -922,15 +874,10 @@ void GFXWebGPU::cache_bind_group_state(GFXWebGPUPipeline* pipeline, WGPUBindGrou
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prism::log("num entries: {}", group_entries.size());
|
|
||||||
|
|
||||||
prism::log("-----");
|
|
||||||
|
|
||||||
WGPUBindGroupDescriptor group_descriptor = {};
|
WGPUBindGroupDescriptor group_descriptor = {};
|
||||||
group_descriptor.layout = group_layout;
|
group_descriptor.layout = group_layout;
|
||||||
group_descriptor.entryCount = group_entries.size();
|
group_descriptor.entryCount = group_entries.size();
|
||||||
group_descriptor.entries = group_entries.data();
|
group_descriptor.entries = group_entries.data();
|
||||||
group_descriptor.label = pipeline->label.c_str();
|
|
||||||
|
|
||||||
pipeline->cached_bind_groups[hash] = wgpuDeviceCreateBindGroup(device, &group_descriptor);
|
pipeline->cached_bind_groups[hash] = wgpuDeviceCreateBindGroup(device, &group_descriptor);
|
||||||
}
|
}
|
||||||
|
@ -945,7 +892,3 @@ void GFXWebGPU::reset_bind_state() {
|
||||||
for (auto& sampler : boundSamplers)
|
for (auto& sampler : boundSamplers)
|
||||||
sampler = nullptr;
|
sampler = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GFXWebGPU::supports_feature(GFXFeature feature) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
|
|
||||||
class GFXWebGPUPipeline : public GFXPipeline {
|
class GFXWebGPUPipeline : public GFXPipeline {
|
||||||
public:
|
public:
|
||||||
std::string label;
|
|
||||||
|
|
||||||
WGPURenderPipeline render_handle = nullptr;
|
WGPURenderPipeline render_handle = nullptr;
|
||||||
WGPUComputePipeline compute_handle = nullptr;
|
WGPUComputePipeline compute_handle = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -7,4 +7,5 @@ public:
|
||||||
WGPUTexture handle = nullptr;
|
WGPUTexture handle = nullptr;
|
||||||
WGPUTextureFormat format = WGPUTextureFormat_Undefined;
|
WGPUTextureFormat format = WGPUTextureFormat_Undefined;
|
||||||
WGPUTextureView view = nullptr;
|
WGPUTextureView view = nullptr;
|
||||||
|
WGPUSampler sampler = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
|
|
||||||
class Material;
|
class Material;
|
||||||
|
|
||||||
constexpr int position_buffer_index = 2;
|
constexpr int position_buffer_index = 5;
|
||||||
constexpr int normal_buffer_index = 3;
|
constexpr int normal_buffer_index = 6;
|
||||||
constexpr int texcoord_buffer_index = 4;
|
constexpr int texcoord_buffer_index = 7;
|
||||||
constexpr int tangent_buffer_index = 5;
|
constexpr int tangent_buffer_index = 8;
|
||||||
constexpr int bitangent_buffer_index = 6;
|
constexpr int bitangent_buffer_index = 9;
|
||||||
constexpr int bone_buffer_index = 7;
|
constexpr int bone_buffer_index = 10;
|
||||||
|
|
||||||
class MaterialCompiler {
|
class MaterialCompiler {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -30,6 +30,8 @@ class DoFPass;
|
||||||
class Scene;
|
class Scene;
|
||||||
struct Camera;
|
struct Camera;
|
||||||
|
|
||||||
|
constexpr int max_scene_materials = 25, max_scene_lights = 25;
|
||||||
|
|
||||||
struct render_screen_options {
|
struct render_screen_options {
|
||||||
bool render_world = false;
|
bool render_world = false;
|
||||||
Matrix4x4 mvp;
|
Matrix4x4 mvp;
|
||||||
|
|
|
@ -125,7 +125,11 @@ std::tuple<GFXPipeline*, GFXPipeline*> MaterialCompiler::create_pipeline_permuta
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr std::string_view struct_info =
|
constexpr std::string_view struct_info =
|
||||||
R"(struct Material {{
|
R"(layout (constant_id = 0) const int max_materials = 25;
|
||||||
|
layout (constant_id = 1) const int max_lights = 25;
|
||||||
|
layout (constant_id = 2) const int max_spot_lights = 4;
|
||||||
|
layout (constant_id = 3) const int max_probes = 4;
|
||||||
|
struct Material {{
|
||||||
vec4 color, info;
|
vec4 color, info;
|
||||||
}};
|
}};
|
||||||
struct Light {{
|
struct Light {{
|
||||||
|
@ -141,10 +145,10 @@ layout(std430, binding = 1) buffer readonly SceneInformation {{
|
||||||
vec4 options;
|
vec4 options;
|
||||||
vec4 camPos;
|
vec4 camPos;
|
||||||
mat4 vp, lightSpace;
|
mat4 vp, lightSpace;
|
||||||
mat4 spotLightSpaces[MAX_SPOT_LIGHTS];
|
mat4 spotLightSpaces[max_spot_lights];
|
||||||
Material materials[MAX_MATERIALS];
|
Material materials[max_materials];
|
||||||
Light lights[MAX_LIGHTS];
|
Light lights[max_lights];
|
||||||
Probe probes[MAX_PROBES];
|
Probe probes[max_probes];
|
||||||
int numLights;
|
int numLights;
|
||||||
}} scene;
|
}} scene;
|
||||||
layout (binding = 2) uniform sampler2D sun_shadow;
|
layout (binding = 2) uniform sampler2D sun_shadow;
|
||||||
|
@ -199,7 +203,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
|
||||||
format_to(std::back_inserter(src),
|
format_to(std::back_inserter(src),
|
||||||
R"(layout(location = 4) in vec4 fragPosLightSpace;
|
R"(layout(location = 4) in vec4 fragPosLightSpace;
|
||||||
layout(location = 5) in mat3 in_tbn;
|
layout(location = 5) in mat3 in_tbn;
|
||||||
layout(location = 14) in vec4 fragPostSpotLightSpace[MAX_SPOT_LIGHTS];
|
layout(location = 14) in vec4 fragPostSpotLightSpace[max_spot_lights];
|
||||||
layout(location = 13) in flat int inMaterialIndex;
|
layout(location = 13) in flat int inMaterialIndex;
|
||||||
#include "common.glsl"
|
#include "common.glsl"
|
||||||
#include "rendering.glsl"
|
#include "rendering.glsl"
|
||||||
|
@ -348,7 +352,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
|
||||||
format_to(std::back_inserter(src),
|
format_to(std::back_inserter(src),
|
||||||
R"(vec3 ambient = vec3(0.0);
|
R"(vec3 ambient = vec3(0.0);
|
||||||
float sum = 0.0;
|
float sum = 0.0;
|
||||||
for(int i = 0; i < MAX_PROBES; i++) {{
|
for(int i = 0; i < max_probes; i++) {{
|
||||||
if(scene.probes[i].position.w == 1) {{
|
if(scene.probes[i].position.w == 1) {{
|
||||||
const vec3 position = scene.probes[i].position.xyz;
|
const vec3 position = scene.probes[i].position.xyz;
|
||||||
const vec3 probe_min = position - (scene.probes[i].size.xyz / 2.0);
|
const vec3 probe_min = position - (scene.probes[i].size.xyz / 2.0);
|
||||||
|
|
|
@ -211,7 +211,7 @@ void renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge
|
||||||
commandbuffer->end_render_pass();
|
commandbuffer->end_render_pass();
|
||||||
|
|
||||||
// begin auto exposure
|
// begin auto exposure
|
||||||
if(render_options.tonemapping == TonemapOperator::AutoExposure) {
|
|
||||||
commandbuffer->set_compute_pipeline(histogram_pipeline);
|
commandbuffer->set_compute_pipeline(histogram_pipeline);
|
||||||
|
|
||||||
commandbuffer->bind_texture(target.offscreenColorTexture, 0);
|
commandbuffer->bind_texture(target.offscreenColorTexture, 0);
|
||||||
|
@ -243,7 +243,6 @@ void renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge
|
||||||
commandbuffer->bind_texture(average_luminance_texture, 0);
|
commandbuffer->bind_texture(average_luminance_texture, 0);
|
||||||
|
|
||||||
commandbuffer->dispatch(1, 1, 1);
|
commandbuffer->dispatch(1, 1, 1);
|
||||||
}
|
|
||||||
|
|
||||||
// continue post processing
|
// continue post processing
|
||||||
beginInfo.framebuffer = nullptr;
|
beginInfo.framebuffer = nullptr;
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include "includer.hpp"
|
#include "includer.hpp"
|
||||||
#include "defaultresources.hpp"
|
#include "defaultresources.hpp"
|
||||||
#include "spirv_hlsl.hpp"
|
#include "spirv_hlsl.hpp"
|
||||||
#include "render_constants.hpp"
|
|
||||||
|
|
||||||
static inline std::vector<std::string> include_path;
|
static inline std::vector<std::string> include_path;
|
||||||
|
|
||||||
|
@ -107,14 +106,6 @@ std::optional<ShaderSource> ShaderCompiler::compile(const ShaderLanguage from_la
|
||||||
|
|
||||||
options.enable_wgpu_compat = to_language == ShaderLanguage::WGSL;
|
options.enable_wgpu_compat = to_language == ShaderLanguage::WGSL;
|
||||||
|
|
||||||
options.definitions.emplace_back("FILTER_SIZE " + std::to_string(512));
|
|
||||||
options.definitions.emplace_back("DOF_WIDTH " + std::to_string(15));
|
|
||||||
options.definitions.emplace_back("DOF_HEIGHT " + std::to_string(15));
|
|
||||||
options.definitions.emplace_back("MAX_LIGHTS " + std::to_string(max_scene_lights));
|
|
||||||
options.definitions.emplace_back("MAX_MATERIALS " + std::to_string(max_scene_materials));
|
|
||||||
options.definitions.emplace_back("MAX_PROBES " + std::to_string(15));
|
|
||||||
options.definitions.emplace_back("MAX_SPOT_LIGHTS " + std::to_string(max_spot_shadows));
|
|
||||||
|
|
||||||
auto spirv = compile_glsl_to_spv(shader_source.as_string(), lang, options);
|
auto spirv = compile_glsl_to_spv(shader_source.as_string(), lang, options);
|
||||||
if(spirv.empty()) {
|
if(spirv.empty()) {
|
||||||
prism::log("SPIRV generation failed!");
|
prism::log("SPIRV generation failed!");
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
layout(constant_id = 0) const int width = 25;
|
||||||
|
layout(constant_id = 1) const int height = 25;
|
||||||
|
|
||||||
layout(location = 0) out vec2 outUV;
|
layout(location = 0) out vec2 outUV;
|
||||||
layout(location = 1) out flat ivec2 outPixel;
|
layout(location = 1) out flat ivec2 outPixel;
|
||||||
layout(location = 2) out float outDepth;
|
layout(location = 2) out float outDepth;
|
||||||
|
@ -11,10 +14,10 @@ layout(push_constant) uniform readonly PushConstant{
|
||||||
void main() {
|
void main() {
|
||||||
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||||
|
|
||||||
ivec2 pixel = ivec2(gl_InstanceIndex % DOF_WIDTH, gl_InstanceIndex / DOF_WIDTH);
|
ivec2 pixel = ivec2(gl_InstanceIndex % width, gl_InstanceIndex / width);
|
||||||
outPixel = pixel;
|
outPixel = pixel;
|
||||||
|
|
||||||
const float depth = texture(depth_sampler, vec2(pixel) / vec2(DOF_WIDTH, DOF_HEIGHT)).r;
|
const float depth = texture(depth_sampler, vec2(pixel) / vec2(width, height)).r;
|
||||||
outDepth = depth;
|
outDepth = depth;
|
||||||
|
|
||||||
vec2 pos = vec2(outUV * 2.0 + -1.0);
|
vec2 pos = vec2(outUV * 2.0 + -1.0);
|
||||||
|
@ -25,7 +28,7 @@ void main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pos += vec2(pixel.x, pixel.y);
|
pos += vec2(pixel.x, pixel.y);
|
||||||
pos *= 2.0 / vec2(DOF_WIDTH, DOF_HEIGHT);
|
pos *= 2.0 / vec2(width, height);
|
||||||
pos += vec2(-1, -1);
|
pos += vec2(-1, -1);
|
||||||
|
|
||||||
gl_Position = vec4(pos.x, pos.y, 0.0, 1.0);
|
gl_Position = vec4(pos.x, pos.y, 0.0, 1.0);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "common.nocompile.glsl"
|
#include "common.nocompile.glsl"
|
||||||
|
|
||||||
|
layout (constant_id = 0) const int texture_size = 512;
|
||||||
|
|
||||||
layout(location = 0) in vec3 inPos;
|
layout(location = 0) in vec3 inPos;
|
||||||
layout(location = 0) out vec4 outColor;
|
layout(location = 0) out vec4 outColor;
|
||||||
|
|
||||||
|
@ -35,7 +37,7 @@ void main() {
|
||||||
const float HdotV = max(dot(H, V), 0.0);
|
const float HdotV = max(dot(H, V), 0.0);
|
||||||
const float pdf = D * NdotH / (4.0 * HdotV) + 0.0001;
|
const float pdf = D * NdotH / (4.0 * HdotV) + 0.0001;
|
||||||
|
|
||||||
const float saTexel = 4.0 * PI / (6.0 * FILTER_SIZE * FILTER_SIZE);
|
const float saTexel = 4.0 * PI / (6.0 * texture_size * texture_size);
|
||||||
const float saSample = 1.0 / (float(SAMPLE_COUNT) * pdf + 0.0001);
|
const float saSample = 1.0 / (float(SAMPLE_COUNT) * pdf + 0.0001);
|
||||||
|
|
||||||
const float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel);
|
const float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel);
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
layout (constant_id = 0) const int max_materials = 25;
|
||||||
|
layout (constant_id = 1) const int max_lights = 25;
|
||||||
|
layout (constant_id = 2) const int max_spot_lights = 4;
|
||||||
|
layout (constant_id = 3) const int max_probes = 4;
|
||||||
|
|
||||||
layout (location = 0) in vec3 inPosition;
|
layout (location = 0) in vec3 inPosition;
|
||||||
layout (location = 1) in vec3 inNormal;
|
layout (location = 1) in vec3 inNormal;
|
||||||
layout (location = 2) in vec2 inUV;
|
layout (location = 2) in vec2 inUV;
|
||||||
|
@ -14,7 +19,7 @@ layout (location = 1) out vec3 outNormal;
|
||||||
layout (location = 2) out vec2 outUV;
|
layout (location = 2) out vec2 outUV;
|
||||||
layout (location = 4) out vec4 fragPosLightSpace;
|
layout (location = 4) out vec4 fragPosLightSpace;
|
||||||
layout (location = 5) out mat3 outTBN;
|
layout (location = 5) out mat3 outTBN;
|
||||||
layout (location = 14) out vec4 fragPostSpotLightSpace[MAX_SPOT_LIGHTS];
|
layout (location = 14) out vec4 fragPostSpotLightSpace[max_spot_lights];
|
||||||
layout (location = 13) out flat int outMaterialIndex;
|
layout (location = 13) out flat int outMaterialIndex;
|
||||||
|
|
||||||
struct Material {
|
struct Material {
|
||||||
|
@ -35,10 +40,10 @@ layout(std430, binding = 1) buffer readonly SceneInformation {
|
||||||
vec4 options;
|
vec4 options;
|
||||||
vec4 camPos;
|
vec4 camPos;
|
||||||
mat4 vp, lightSpace;
|
mat4 vp, lightSpace;
|
||||||
mat4 spotLightSpaces[MAX_SPOT_LIGHTS];
|
mat4 spotLightSpaces[max_spot_lights];
|
||||||
Material materials[MAX_MATERIALS];
|
Material materials[max_materials];
|
||||||
Light lights[MAX_LIGHTS];
|
Light lights[max_lights];
|
||||||
Probe probes[MAX_PROBES];
|
Probe probes[max_probes];
|
||||||
int numLights;
|
int numLights;
|
||||||
} scene;
|
} scene;
|
||||||
|
|
||||||
|
@ -88,7 +93,7 @@ void main() {
|
||||||
outUV = inUV;
|
outUV = inUV;
|
||||||
fragPosLightSpace = (biasMat * scene.lightSpace) * bPos;
|
fragPosLightSpace = (biasMat * scene.lightSpace) * bPos;
|
||||||
|
|
||||||
for(int i = 0; i < MAX_SPOT_LIGHTS; i++) {
|
for(int i = 0; i < max_spot_lights; i++) {
|
||||||
fragPostSpotLightSpace[i] = (biasMat * scene.spotLightSpaces[i]) * bPos;
|
fragPostSpotLightSpace[i] = (biasMat * scene.spotLightSpaces[i]) * bPos;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -99,7 +104,7 @@ void main() {
|
||||||
outUV = inUV;
|
outUV = inUV;
|
||||||
fragPosLightSpace = (biasMat * scene.lightSpace * model) * vec4(inPosition, 1.0);
|
fragPosLightSpace = (biasMat * scene.lightSpace * model) * vec4(inPosition, 1.0);
|
||||||
|
|
||||||
for(int i = 0; i < MAX_SPOT_LIGHTS; i++) {
|
for(int i = 0; i < max_spot_lights; i++) {
|
||||||
fragPostSpotLightSpace[i] = (biasMat * scene.spotLightSpaces[i] * model) * vec4(inPosition, 1.0);
|
fragPostSpotLightSpace[i] = (biasMat * scene.spotLightSpaces[i] * model) * vec4(inPosition, 1.0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -110,7 +115,7 @@ void main() {
|
||||||
outUV = inUV;
|
outUV = inUV;
|
||||||
fragPosLightSpace = (biasMat * scene.lightSpace * model) * vec4(inPosition, 1.0);
|
fragPosLightSpace = (biasMat * scene.lightSpace * model) * vec4(inPosition, 1.0);
|
||||||
|
|
||||||
for(int i = 0; i < MAX_SPOT_LIGHTS; i++) {
|
for(int i = 0; i < max_spot_lights; i++) {
|
||||||
fragPostSpotLightSpace[i] = (biasMat * scene.spotLightSpaces[i] * model) * vec4(inPosition, 1.0);
|
fragPostSpotLightSpace[i] = (biasMat * scene.spotLightSpaces[i] * model) * vec4(inPosition, 1.0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
layout (constant_id = 0) const int max_lights = 25;
|
||||||
|
|
||||||
layout (location = 0) in vec3 inPos;
|
layout (location = 0) in vec3 inPos;
|
||||||
layout (location = 1) flat in int index;
|
layout (location = 1) flat in int index;
|
||||||
|
|
||||||
layout (location = 0) out float outFragColor;
|
layout (location = 0) out float outFragColor;
|
||||||
|
|
||||||
layout(std430, binding = 2) buffer readonly LightInformation {
|
layout(std430, binding = 2) buffer readonly LightInformation {
|
||||||
vec4 light_locations[MAX_LIGHTS];
|
vec4 light_locations[max_lights];
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
layout (constant_id = 0) const int max_materials = 25;
|
||||||
|
layout (constant_id = 1) const int max_lights = 25;
|
||||||
|
layout (constant_id = 2) const int max_spot_lights = 4;
|
||||||
|
|
||||||
layout (location = 0) in vec3 inPosition;
|
layout (location = 0) in vec3 inPosition;
|
||||||
layout (location = 1) in vec3 inNormal;
|
layout (location = 1) in vec3 inNormal;
|
||||||
layout (location = 2) in vec2 inUV;
|
layout (location = 2) in vec2 inUV;
|
||||||
|
@ -23,9 +27,9 @@ layout(std430, binding = 5) buffer readonly SceneInformation {
|
||||||
vec4 camPos;
|
vec4 camPos;
|
||||||
mat4 projection, lightSpace;
|
mat4 projection, lightSpace;
|
||||||
vec4 skyColor;
|
vec4 skyColor;
|
||||||
mat4 spotLightSpaces[MAX_SPOT_LIGHTS];
|
mat4 spotLightSpaces[max_spot_lights];
|
||||||
Material materials[MAX_MATERIALS];
|
Material materials[max_materials];
|
||||||
Light lights[MAX_LIGHTS];
|
Light lights[max_lights];
|
||||||
int numLights;
|
int numLights;
|
||||||
} scene;
|
} scene;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
layout (constant_id = 0) const int max_lights = 25;
|
||||||
|
|
||||||
layout (location = 0) in vec3 inPosition;
|
layout (location = 0) in vec3 inPosition;
|
||||||
|
|
||||||
#ifdef BONE
|
#ifdef BONE
|
||||||
|
@ -19,7 +21,7 @@ layout(std430, binding = 14) buffer readonly BoneInformation {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
layout(std430, binding = 2) buffer readonly LightInformation {
|
layout(std430, binding = 2) buffer readonly LightInformation {
|
||||||
vec4 light_locations[MAX_LIGHTS];
|
vec4 light_locations[max_lights];
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
constexpr int max_scene_materials = 25, max_scene_lights = 25;
|
|
||||||
const int max_spot_shadows = 4;
|
|
||||||
const int max_point_shadows = 4;
|
|
||||||
const int max_environment_probes = 4;
|
|
Reference in a new issue