diff --git a/examples/makefile b/examples/makefile index ec6ea3c43..78c0a9526 100644 --- a/examples/makefile +++ b/examples/makefile @@ -31,6 +31,8 @@ rebuild: # @make -s --no-print-directory rebuild -C 26-occlusion @make -s --no-print-directory rebuild -C 27-terrain @make -s --no-print-directory rebuild -C 28-wireframe + @make -s --no-print-directory rebuild -C common/debugdraw @make -s --no-print-directory rebuild -C common/font @make -s --no-print-directory rebuild -C common/imgui @make -s --no-print-directory rebuild -C common/nanovg + @make -s --no-print-directory rebuild -C common/ps \ No newline at end of file diff --git a/src/bgfx_shader.sh b/src/bgfx_shader.sh index 2cab0ca0d..0d71b2a4d 100644 --- a/src/bgfx_shader.sh +++ b/src/bgfx_shader.sh @@ -53,12 +53,12 @@ # define dFdyFine(_y) ddy_fine(-_y) # endif // BGFX_SHADER_LANGUAGE_HLSL > 4 -# if BGFX_SHADER_LANGUAGE_HLSL +# if BGFX_SHADER_LANGUAGE_HLSL float intBitsToFloat(int _x) { return asfloat(_x); } vec2 intBitsToFloat(uint2 _x) { return asfloat(_x); } vec3 intBitsToFloat(uint3 _x) { return asfloat(_x); } vec4 intBitsToFloat(uint4 _x) { return asfloat(_x); } -# endif // BGFX_SHADER_LANGUAGE_HLSL +# endif // BGFX_SHADER_LANGUAGE_HLSL float uintBitsToFloat(uint _x) { return asfloat(_x); } vec2 uintBitsToFloat(uint2 _x) { return asfloat(_x); } @@ -80,7 +80,7 @@ uint2 bitfieldReverse(uint2 _x) { return reversebits(_x); } uint3 bitfieldReverse(uint3 _x) { return reversebits(_x); } uint4 bitfieldReverse(uint4 _x) { return reversebits(_x); } -#if !BGFX_SHADER_LANGUAGE_SPIRV +# if !BGFX_SHADER_LANGUAGE_SPIRV uint packHalf2x16(vec2 _x) { return (f32tof16(_x.x)<<16) | f32tof16(_x.y); @@ -90,7 +90,7 @@ vec2 unpackHalf2x16(uint _x) { return vec2(f16tof32(_x >> 16), f16tof32(_x) ); } -#endif // !BGFX_SHADER_LANGUAGE_SPIRV +# endif // !BGFX_SHADER_LANGUAGE_SPIRV struct BgfxSampler2D { diff --git a/src/makefile b/src/makefile index 2475a5104..8f017d2d9 100644 --- a/src/makefile +++ b/src/makefile @@ -27,7 +27,7 @@ define shader-embedded @echo [$(<)] $(SILENT) $(SHADERC) --type $(1) --platform linux -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_glsl @cat $(SHADER_TMP) > $(@) - -$(SILENT) $(SHADERC) --type $(1) --platform windows -p spirv -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_spv + -$(SILENT) $(SHADERC) --type $(1) --platform linux -p spirv -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_spv -@cat $(SHADER_TMP) >> $(@) -$(SILENT) $(SHADERC) --type $(1) --platform windows -p $(2) -O 3 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_dx9 -@cat $(SHADER_TMP) >> $(@) diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index 131ad7b32..0f2197bc0 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -928,7 +928,7 @@ VK_IMPORT_INSTANCE vkGetPhysicalDeviceMemoryProperties(physicalDevices[ii], &pdmp); BX_TRACE("\tMemory type count: %d", pdmp.memoryTypeCount); - for (uint32_t jj = 0; jj < pdmp.memoryHeapCount; ++jj) + for (uint32_t jj = 0; jj < pdmp.memoryTypeCount; ++jj) { BX_TRACE("\t%3d: flags 0x%08x, index %d" , jj @@ -937,7 +937,7 @@ VK_IMPORT_INSTANCE ); } - BX_TRACE("\tMemory type count: %d", pdmp.memoryHeapCount); + BX_TRACE("\tMemory heap count: %d", pdmp.memoryHeapCount); for (uint32_t jj = 0; jj < pdmp.memoryHeapCount; ++jj) { char size[16]; @@ -1029,20 +1029,6 @@ VK_IMPORT_INSTANCE } vkGetPhysicalDeviceMemoryProperties(m_physicalDevice, &m_memoryProperties); - - for (uint32_t ii = 0, num = m_memoryProperties.memoryTypeCount; ii < num; ++ii) - { - const VkMemoryType& memoryType = m_memoryProperties.memoryTypes[ii]; - if (0 != (memoryType.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) ) - { - m_memHostVisibleIdx = ii; - } - - if (0 != (memoryType.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) ) - { - m_memLocalVisibleIdx = ii; - } - } } { @@ -1462,7 +1448,7 @@ VK_IMPORT_DEVICE ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ma.pNext = NULL; ma.allocationSize = mr.size; - ma.memoryTypeIndex = m_memLocalVisibleIdx; + ma.memoryTypeIndex = selectMemoryType(mr.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); result = vkAllocateMemory(m_device , &ma , m_allocatorCb @@ -2968,6 +2954,19 @@ VK_IMPORT_DEVICE // VK_CHECK(vkWaitForFences(m_device, 1, &m_fence, true, INT64_MAX) ); } + uint32_t selectMemoryType(uint32_t memoryTypeBits, uint32_t propertyFlags) + { + for (uint32_t ii = 0; ii < m_memoryProperties.memoryTypeCount; ++ii) + { + if ((((1<m_memHostVisibleIdx; + ma.memoryTypeIndex = s_renderVK->selectMemoryType(mr.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); VK_CHECK(vkAllocateMemory(device , &ma , allocatorCb @@ -3230,7 +3227,7 @@ VK_DESTROY ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ma.pNext = NULL; ma.allocationSize = mr.size; - ma.memoryTypeIndex = s_renderVK->m_memLocalVisibleIdx; + ma.memoryTypeIndex = s_renderVK->selectMemoryType(mr.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); result = vkAllocateMemory(device , &ma , allocatorCb @@ -3333,7 +3330,7 @@ VK_DESTROY ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; ma.pNext = NULL; ma.allocationSize = mr.size; - ma.memoryTypeIndex = s_renderVK->m_memHostVisibleIdx; + ma.memoryTypeIndex = s_renderVK->selectMemoryType(mr.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); VK_CHECK(vkAllocateMemory(device , &ma , allocatorCb @@ -3488,7 +3485,7 @@ VK_DESTROY } } - uint32_t shaderSize; + uint16_t shaderSize; bx::read(&reader, shaderSize); #if 1 diff --git a/tools/shaderc/shaderc_spirv.cpp b/tools/shaderc/shaderc_spirv.cpp index 502edddab..4c11f1ca9 100644 --- a/tools/shaderc/shaderc_spirv.cpp +++ b/tools/shaderc/shaderc_spirv.cpp @@ -645,12 +645,57 @@ namespace bgfx { namespace spirv } else { -// program->buildReflection(); -// fprintf(stderr, "attributes %d, uniforms %d\n" -// , program->getNumLiveAttributes() -// , program->getNumLiveUniformVariables() -// ); -// program->dumpReflection(); + program->buildReflection(); + { + uint16_t count = (uint16_t)program->getNumLiveUniformVariables(); + bx::write(_writer, count); + + uint32_t fragmentBit = profile[0] == 'p' ? BGFX_UNIFORM_FRAGMENTBIT : 0; + for (uint16_t ii = 0; ii < count; ++ii) + { + Uniform un; + un.name = program->getUniformName(ii); + switch (program->getUniformType(ii)) + { + case 0x1404: // GL_INT: + un.type = UniformType::Int1; + break; + case 0x8B52: // GL_FLOAT_VEC4: + un.type = UniformType::Vec4; + break; + case 0x8B5B: // GL_FLOAT_MAT3: + un.type = UniformType::Mat3; + break; + case 0x8B5C: // GL_FLOAT_MAT4: + un.type = UniformType::Mat4; + break; + default: + un.type = UniformType::End; + break; + } + un.num = program->getUniformArraySize(ii); + un.regIndex = 0; + un.regCount = un.num; + + uint8_t nameSize = (uint8_t)un.name.size(); + bx::write(_writer, nameSize); + bx::write(_writer, un.name.c_str(), nameSize); + uint8_t type = un.type | fragmentBit; + bx::write(_writer, type); + bx::write(_writer, un.num); + bx::write(_writer, un.regIndex); + bx::write(_writer, un.regCount); + + BX_TRACE("%s, %s, %d, %d, %d" + , un.name.c_str() + , getUniformTypeName(un.type) + , un.num + , un.regIndex + , un.regCount + ); + } + } + program->dumpReflection(); BX_UNUSED(spv::MemorySemanticsAllMemory);