Skip to content

Commit

Permalink
Yay very basic 3D (only white) finally shows.
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Feb 11, 2020
1 parent 449df8f commit 8cee770
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 107 deletions.
6 changes: 6 additions & 0 deletions core/math/camera_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ void CameraMatrix::invert() {
}
}

void CameraMatrix::flip_y() {
for (int i = 0; i < 4; i++) {
matrix[1][i] = -matrix[1][i];
}
}

CameraMatrix::CameraMatrix() {

set_identity();
Expand Down
2 changes: 2 additions & 0 deletions core/math/camera_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ struct CameraMatrix {
int get_pixels_per_meter(int p_for_pixel_width) const;
operator Transform() const;

void flip_y();

CameraMatrix();
CameraMatrix(const Transform &p_transform);
~CameraMatrix();
Expand Down
55 changes: 38 additions & 17 deletions drivers/vulkan/rendering_device_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,18 @@ uint32_t RenderingDeviceVulkan::get_compressed_image_format_pixel_rshift(DataFor
return 0;
}

bool RenderingDeviceVulkan::format_has_stencil(DataFormat p_format) {
switch (p_format) {
case DATA_FORMAT_S8_UINT:
case DATA_FORMAT_D16_UNORM_S8_UINT:
case DATA_FORMAT_D24_UNORM_S8_UINT:
case DATA_FORMAT_D32_SFLOAT_S8_UINT: {
return true;
}
}
return false;
}

uint32_t RenderingDeviceVulkan::get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw, uint32_t *r_blockh, uint32_t *r_depth) {

ERR_FAIL_COND_V(p_mipmaps == 0, 0);
Expand Down Expand Up @@ -1699,7 +1711,12 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T

//set bound and unbound layouts
if (p_format.usage_bits & TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
texture.aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT;

texture.read_aspect_mask = VK_IMAGE_ASPECT_DEPTH_BIT;
texture.barrier_aspect_mask = texture.read_aspect_mask;
if (format_has_stencil(p_format.format)) {
texture.barrier_aspect_mask |= VK_IMAGE_ASPECT_STENCIL_BIT;
}

if (p_format.usage_bits & TEXTURE_USAGE_SAMPLING_BIT) {
texture.unbound_layout = VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL;
Expand All @@ -1710,15 +1727,19 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T

} else if (p_format.usage_bits & TEXTURE_USAGE_COLOR_ATTACHMENT_BIT) {

texture.aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT;
texture.read_aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT;
texture.barrier_aspect_mask = texture.read_aspect_mask;

if (p_format.usage_bits & TEXTURE_USAGE_SAMPLING_BIT) {
texture.unbound_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} else {
texture.unbound_layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
}
texture.bound_layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
} else {
texture.aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT;
texture.read_aspect_mask = VK_IMAGE_ASPECT_COLOR_BIT;
texture.barrier_aspect_mask = texture.read_aspect_mask;

texture.unbound_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
texture.bound_layout = VK_IMAGE_LAYOUT_UNDEFINED; //will never be bound
}
Expand Down Expand Up @@ -1794,7 +1815,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = texture.image;
image_memory_barrier.subresourceRange.aspectMask = texture.aspect_mask;
image_memory_barrier.subresourceRange.aspectMask = texture.barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = 0;
image_memory_barrier.subresourceRange.levelCount = image_create_info.mipLevels;
image_memory_barrier.subresourceRange.baseArrayLayer = 0;
Expand Down Expand Up @@ -2053,7 +2074,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = texture->image;
image_memory_barrier.subresourceRange.aspectMask = texture->aspect_mask;
image_memory_barrier.subresourceRange.aspectMask = texture->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = 0;
image_memory_barrier.subresourceRange.levelCount = texture->mipmaps;
image_memory_barrier.subresourceRange.baseArrayLayer = p_layer;
Expand Down Expand Up @@ -2156,7 +2177,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con
buffer_image_copy.bufferRowLength = 0; //tigthly packed
buffer_image_copy.bufferImageHeight = 0; //tigthly packed

buffer_image_copy.imageSubresource.aspectMask = texture->aspect_mask;
buffer_image_copy.imageSubresource.aspectMask = texture->read_aspect_mask;
buffer_image_copy.imageSubresource.mipLevel = mm_i;
buffer_image_copy.imageSubresource.baseArrayLayer = p_layer;
buffer_image_copy.imageSubresource.layerCount = 1;
Expand Down Expand Up @@ -2191,7 +2212,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = texture->image;
image_memory_barrier.subresourceRange.aspectMask = texture->aspect_mask;
image_memory_barrier.subresourceRange.aspectMask = texture->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = 0;
image_memory_barrier.subresourceRange.levelCount = texture->mipmaps;
image_memory_barrier.subresourceRange.baseArrayLayer = p_layer;
Expand Down Expand Up @@ -2340,7 +2361,7 @@ PoolVector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint3
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = tex->image;
image_memory_barrier.subresourceRange.aspectMask = tex->aspect_mask;
image_memory_barrier.subresourceRange.aspectMask = tex->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = 0;
image_memory_barrier.subresourceRange.levelCount = tex->mipmaps;
image_memory_barrier.subresourceRange.baseArrayLayer = p_layer;
Expand Down Expand Up @@ -2379,7 +2400,7 @@ PoolVector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint3
get_image_format_required_size(tex->format, tex->width, tex->height, tex->depth, i + 1, &mm_width, &mm_height, &mm_depth);

VkImageCopy image_copy_region;
image_copy_region.srcSubresource.aspectMask = tex->aspect_mask;
image_copy_region.srcSubresource.aspectMask = tex->read_aspect_mask;
image_copy_region.srcSubresource.baseArrayLayer = p_layer;
image_copy_region.srcSubresource.layerCount = 1;
image_copy_region.srcSubresource.mipLevel = i;
Expand Down Expand Up @@ -2416,7 +2437,7 @@ PoolVector<uint8_t> RenderingDeviceVulkan::texture_get_data(RID p_texture, uint3
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = tex->image;
image_memory_barrier.subresourceRange.aspectMask = tex->aspect_mask;
image_memory_barrier.subresourceRange.aspectMask = tex->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = 0;
image_memory_barrier.subresourceRange.levelCount = tex->mipmaps;
image_memory_barrier.subresourceRange.baseArrayLayer = p_layer;
Expand Down Expand Up @@ -2528,7 +2549,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture,
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = src_tex->image;
image_memory_barrier.subresourceRange.aspectMask = src_tex->aspect_mask;
image_memory_barrier.subresourceRange.aspectMask = src_tex->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = p_src_mipmap;
image_memory_barrier.subresourceRange.levelCount = 1;
image_memory_barrier.subresourceRange.baseArrayLayer = p_src_layer;
Expand All @@ -2548,7 +2569,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture,
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = dst_tex->image;
image_memory_barrier.subresourceRange.aspectMask = dst_tex->aspect_mask;
image_memory_barrier.subresourceRange.aspectMask = dst_tex->read_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = p_dst_mipmap;
image_memory_barrier.subresourceRange.levelCount = 1;
image_memory_barrier.subresourceRange.baseArrayLayer = p_dst_layer;
Expand All @@ -2562,15 +2583,15 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture,
{

VkImageCopy image_copy_region;
image_copy_region.srcSubresource.aspectMask = src_tex->aspect_mask;
image_copy_region.srcSubresource.aspectMask = src_tex->read_aspect_mask;
image_copy_region.srcSubresource.baseArrayLayer = p_src_layer;
image_copy_region.srcSubresource.layerCount = 1;
image_copy_region.srcSubresource.mipLevel = p_src_mipmap;
image_copy_region.srcOffset.x = p_from.x;
image_copy_region.srcOffset.y = p_from.y;
image_copy_region.srcOffset.z = p_from.z;

image_copy_region.dstSubresource.aspectMask = src_tex->aspect_mask;
image_copy_region.dstSubresource.aspectMask = src_tex->barrier_aspect_mask;
image_copy_region.dstSubresource.baseArrayLayer = p_dst_layer;
image_copy_region.dstSubresource.layerCount = 1;
image_copy_region.dstSubresource.mipLevel = p_dst_mipmap;
Expand Down Expand Up @@ -2598,7 +2619,7 @@ Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture,
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = src_tex->image;
image_memory_barrier.subresourceRange.aspectMask = src_tex->aspect_mask;
image_memory_barrier.subresourceRange.aspectMask = src_tex->barrier_aspect_mask;
image_memory_barrier.subresourceRange.baseMipLevel = p_src_mipmap;
image_memory_barrier.subresourceRange.levelCount = src_tex->mipmaps;
image_memory_barrier.subresourceRange.baseArrayLayer = p_src_layer;
Expand Down Expand Up @@ -3672,12 +3693,12 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages
Vector<SpvReflectInterfaceVariable *> input_vars;
input_vars.resize(iv_count);

result = spvReflectEnumerateOutputVariables(&module, &iv_count, input_vars.ptrw());
result = spvReflectEnumerateInputVariables(&module, &iv_count, input_vars.ptrw());
ERR_FAIL_COND_V_MSG(result != SPV_REFLECT_RESULT_SUCCESS, RID(),
"Reflection of SPIR-V shader stage '" + String(shader_stage_names[p_stages[i].shader_stage]) + "' failed obtaining input variables.");

for (uint32_t j = 0; j < iv_count; j++) {
if (input_vars[j]) {
if (input_vars[j] && input_vars[j]->decoration_flags == 0) { //regular input
vertex_input_mask |= (1 << uint32_t(input_vars[j]->location));
}
}
Expand Down
4 changes: 3 additions & 1 deletion drivers/vulkan/rendering_device_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
static uint32_t get_compressed_image_format_pixel_rshift(DataFormat p_format);
static uint32_t get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw = NULL, uint32_t *r_blockh = NULL, uint32_t *r_depth = NULL);
static uint32_t get_image_required_mipmaps(uint32_t p_width, uint32_t p_height, uint32_t p_depth);
static bool format_has_stencil(DataFormat p_format);

/***************************/
/**** ID INFRASTRUCTURE ****/
Expand Down Expand Up @@ -139,7 +140,8 @@ class RenderingDeviceVulkan : public RenderingDevice {

VkImageLayout bound_layout; //layout used when bound to framebuffer being drawn
VkImageLayout unbound_layout; //layout used otherwise
uint32_t aspect_mask;
uint32_t read_aspect_mask;
uint32_t barrier_aspect_mask;
bool bound; //bound to framebffer
RID owner;
};
Expand Down
1 change: 1 addition & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
Error Main::setup2(Thread::ID p_main_tid_override) {

preregister_module_types();
preregister_server_types();

// Print engine name and version
print_line(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE));
Expand Down
7 changes: 5 additions & 2 deletions servers/register_server_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ static bool has_server_feature_callback(const String &p_feature) {
return false;
}

void preregister_server_types() {
shader_types = memnew(ShaderTypes);
}

void register_server_types() {

OS::get_singleton()->set_has_server_feature_callback(has_server_feature_callback);
Expand All @@ -120,8 +124,6 @@ void register_server_types() {
ClassDB::register_class<ARVRServer>();
ClassDB::register_class<CameraServer>();

shader_types = memnew(ShaderTypes);

ClassDB::register_virtual_class<ARVRInterface>();
ClassDB::register_class<ARVRPositionalTracker>();

Expand Down Expand Up @@ -210,6 +212,7 @@ void unregister_server_types() {
}

void register_server_singletons() {

Engine::get_singleton()->add_singleton(Engine::Singleton("VisualServer", VisualServer::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer", PhysicsServer::get_singleton()));
Expand Down
1 change: 1 addition & 0 deletions servers/register_server_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef REGISTER_SERVER_TYPES_H
#define REGISTER_SERVER_TYPES_H

void preregister_server_types();
void register_server_types();
void unregister_server_types();

Expand Down
Loading

0 comments on commit 8cee770

Please sign in to comment.