Initial implementation of ShaderModule

Basic shell class for ShaderModule

Bug b/118386749

Change-Id: Ia41957ba1ef3be179d20c37cea0227a9a4509c7b
Reviewed-on: https://swiftshader-review.googlesource.com/c/22609
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Vulkan/VkDestroy.h b/src/Vulkan/VkDestroy.h
index 15e2192..1686bf0 100644
--- a/src/Vulkan/VkDestroy.h
+++ b/src/Vulkan/VkDestroy.h
@@ -25,6 +25,7 @@
 #include "VkPhysicalDevice.hpp"
 #include "VkQueue.hpp"
 #include "VkSemaphore.hpp"
+#include "VkShaderModule.hpp"
 
 namespace vk
 {
diff --git a/src/Vulkan/VkShaderModule.cpp b/src/Vulkan/VkShaderModule.cpp
new file mode 100644
index 0000000..5be04e8
--- /dev/null
+++ b/src/Vulkan/VkShaderModule.cpp
@@ -0,0 +1,36 @@
+// Copyright 2018 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "VkShaderModule.hpp"
+#include <memory.h>
+
+namespace vk
+{
+
+ShaderModule::ShaderModule(const VkShaderModuleCreateInfo* pCreateInfo, void* mem) : code(reinterpret_cast<uint32_t*>(mem))
+{
+	memcpy(code, pCreateInfo->pCode, pCreateInfo->codeSize);
+}
+
+void ShaderModule::destroy(const VkAllocationCallbacks* pAllocator)
+{
+	vk::deallocate(code, pAllocator);
+}
+
+size_t ShaderModule::ComputeRequiredAllocationSize(const VkShaderModuleCreateInfo* pCreateInfo)
+{
+	return pCreateInfo->codeSize;
+}
+
+} // namespace vk
diff --git a/src/Vulkan/VkShaderModule.hpp b/src/Vulkan/VkShaderModule.hpp
new file mode 100644
index 0000000..b179cbe
--- /dev/null
+++ b/src/Vulkan/VkShaderModule.hpp
@@ -0,0 +1,43 @@
+// Copyright 2018 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef VK_SHADER_MODULE_HPP_
+#define VK_SHADER_MODULE_HPP_
+
+#include "VkObject.hpp"
+
+namespace vk
+{
+
+class ShaderModule : public Object<ShaderModule, VkShaderModule>
+{
+public:
+	ShaderModule(const VkShaderModuleCreateInfo* pCreateInfo, void* mem);
+	~ShaderModule() = delete;
+	void destroy(const VkAllocationCallbacks* pAllocator);
+
+	static size_t ComputeRequiredAllocationSize(const VkShaderModuleCreateInfo* pCreateInfo);
+
+private:
+	uint32_t* code = nullptr;
+};
+
+static inline ShaderModule* Cast(VkShaderModule object)
+{
+	return reinterpret_cast<ShaderModule*>(object);
+}
+
+} // namespace vk
+
+#endif // VK_SHADER_MODULE_HPP_
diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp
index 84bceab..2d4df6f 100644
--- a/src/Vulkan/libVulkan.cpp
+++ b/src/Vulkan/libVulkan.cpp
@@ -29,6 +29,7 @@
 #include "VkPipelineLayout.hpp"
 #include "VkQueue.hpp"
 #include "VkSemaphore.hpp"
+#include "VkShaderModule.hpp"
 
 #include <algorithm>
 #include <cstring>
@@ -748,19 +749,22 @@
 VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule)
 {
 	TRACE("(VkDevice device = 0x%X, const VkShaderModuleCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkShaderModule* pShaderModule = 0x%X)",
-		    device, pCreateInfo, pAllocator, pShaderModule);
+	      device, pCreateInfo, pAllocator, pShaderModule);
 
-	UNIMPLEMENTED();
+	if(pCreateInfo->pNext || pCreateInfo->flags)
+	{
+		UNIMPLEMENTED();
+	}
 
-	return VK_SUCCESS;
+	return vk::ShaderModule::Create(pAllocator, pCreateInfo, pShaderModule);
 }
 
 VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
 {
 	TRACE("(VkDevice device = 0x%X, VkShaderModule shaderModule = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)",
-		    device, shaderModule, pAllocator);
+	      device, shaderModule, pAllocator);
 
-	UNIMPLEMENTED();
+	vk::destroy(shaderModule, pAllocator);
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(VkDevice device, const VkPipelineCacheCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineCache* pPipelineCache)
diff --git a/src/Vulkan/vulkan.vcxproj b/src/Vulkan/vulkan.vcxproj
index b57b6d8..1f44cc4 100644
--- a/src/Vulkan/vulkan.vcxproj
+++ b/src/Vulkan/vulkan.vcxproj
@@ -113,6 +113,7 @@
     <ClCompile Include="VkPipelineLayout.cpp" />

     <ClCompile Include="VkPromotedExtensions.cpp" />

     <ClCompile Include="VkQueue.cpp" />

+    <ClCompile Include="VkShaderModule.cpp" />

     <ClCompile Include="..\Device\Blitter.cpp" />

     <ClCompile Include="..\Device\Clipper.cpp" />

     <ClCompile Include="..\Device\Color.cpp" />

@@ -203,6 +204,7 @@
     <ClInclude Include="VkPipelineLayout.hpp" />

     <ClInclude Include="VkQueue.hpp" />

     <ClInclude Include="VkSemaphore.hpp" />

+    <ClInclude Include="VkShaderModule.hpp" />

     <ClInclude Include="..\Device\Blitter.hpp" />

     <ClInclude Include="..\Device\Clipper.hpp" />

     <ClInclude Include="..\Device\Color.hpp" />

diff --git a/src/Vulkan/vulkan.vcxproj.filters b/src/Vulkan/vulkan.vcxproj.filters
index 12784c0..de1d38f 100644
--- a/src/Vulkan/vulkan.vcxproj.filters
+++ b/src/Vulkan/vulkan.vcxproj.filters
@@ -237,6 +237,9 @@
     <ClCompile Include="VkQueue.cpp">

       <Filter>Source Files\Vulkan</Filter>

     </ClCompile>

+    <ClCompile Include="VkShaderModule.cpp">

+      <Filter>Source Files\Vulkan</Filter>

+    </ClCompile>

   </ItemGroup>

   <ItemGroup>

     <ClInclude Include="resource.h">

@@ -293,6 +296,9 @@
     <ClInclude Include="VkSemaphore.hpp">

       <Filter>Header Files\Vulkan</Filter>

     </ClInclude>

+    <ClInclude Include="VkShaderModule.hpp">

+      <Filter>Header Files\Vulkan</Filter>

+    </ClInclude>

     <ClInclude Include="..\Device\VertexProcessor.hpp">

       <Filter>Header Files\Device</Filter>

     </ClInclude>