Slang対応
テクニカル諏訪子 <suwako@076.moe>、2026-07-21 12:19
コミット f7ec533c45d5051d13c50caa0c84ee3a0e201cc7
・親 5f666f6
・ファイルを見る
6個のファイル、+177 -58
| @@ -29,26 +29,26 @@ | ||
| 29 | 29 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
| 30 | 30 | <ConfigurationType>Application</ConfigurationType> |
| 31 | 31 | <UseDebugLibraries>true</UseDebugLibraries> |
| 32 | - <PlatformToolset>v143</PlatformToolset> | |
| 32 | + <PlatformToolset>v145</PlatformToolset> | |
| 33 | 33 | <CharacterSet>Unicode</CharacterSet> |
| 34 | 34 | </PropertyGroup> |
| 35 | 35 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
| 36 | 36 | <ConfigurationType>Application</ConfigurationType> |
| 37 | 37 | <UseDebugLibraries>false</UseDebugLibraries> |
| 38 | - <PlatformToolset>v143</PlatformToolset> | |
| 38 | + <PlatformToolset>v145</PlatformToolset> | |
| 39 | 39 | <WholeProgramOptimization>true</WholeProgramOptimization> |
| 40 | 40 | <CharacterSet>Unicode</CharacterSet> |
| 41 | 41 | </PropertyGroup> |
| 42 | 42 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
| 43 | 43 | <ConfigurationType>Application</ConfigurationType> |
| 44 | 44 | <UseDebugLibraries>true</UseDebugLibraries> |
| 45 | - <PlatformToolset>v143</PlatformToolset> | |
| 45 | + <PlatformToolset>v145</PlatformToolset> | |
| 46 | 46 | <CharacterSet>Unicode</CharacterSet> |
| 47 | 47 | </PropertyGroup> |
| 48 | 48 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
| 49 | 49 | <ConfigurationType>Application</ConfigurationType> |
| 50 | 50 | <UseDebugLibraries>false</UseDebugLibraries> |
| 51 | - <PlatformToolset>v143</PlatformToolset> | |
| 51 | + <PlatformToolset>v145</PlatformToolset> | |
| 52 | 52 | <WholeProgramOptimization>true</WholeProgramOptimization> |
| 53 | 53 | <CharacterSet>Unicode</CharacterSet> |
| 54 | 54 | </PropertyGroup> |
| @@ -100,10 +100,11 @@ | ||
| 100 | 100 | <ClCompile> |
| 101 | 101 | <WarningLevel>Level3</WarningLevel> |
| 102 | 102 | <SDLCheck>true</SDLCheck> |
| 103 | - <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
| 103 | + <PreprocessorDefinitions>_DEBUG;_CONSOLE;USING_SLANG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
| 104 | 104 | <ConformanceMode>true</ConformanceMode> |
| 105 | - <AdditionalIncludeDirectories>$(SolutionDir)dep\include;$(VULKAN_SDK)\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
| 105 | + <AdditionalIncludeDirectories>$(SolutionDir)dep\include;$(VULKAN_SDK)\Include;$(ProjectDir)</AdditionalIncludeDirectories> | |
| 106 | 106 | <LanguageStandard>stdcpp20</LanguageStandard> |
| 107 | + <AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions> | |
| 107 | 108 | </ClCompile> |
| 108 | 109 | <Link> |
| 109 | 110 | <SubSystem>Console</SubSystem> |
| @@ -113,7 +114,8 @@ | ||
| 113 | 114 | </Link> |
| 114 | 115 | <PostBuildEvent> |
| 115 | 116 | <Command>$(VULKAN_SDK)\Bin\glslc.exe $(ProjectDir)shader.vert -o $(ProjectDir)vert.spv |
| 116 | -$(VULKAN_SDK)\Bin\glslc.exe $(ProjectDir)shader.frag -o $(ProjectDir)frag.spv</Command> | |
| 117 | +$(VULKAN_SDK)\Bin\glslc.exe $(ProjectDir)shader.frag -o $(ProjectDir)frag.spv | |
| 118 | +$(VULKAN_SDK)\Bin\slangc.exe $(ProjectDir)shader.slang -target spirv -profile spirv_1_4 -emit-spirv-directly -fvk-use-entrypoint-name -entry vertMain -entry fragMain -o slang.spv</Command> | |
| 117 | 119 | </PostBuildEvent> |
| 118 | 120 | </ItemDefinitionGroup> |
| 119 | 121 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
| @@ -122,10 +124,11 @@ | ||
| 122 | 124 | <FunctionLevelLinking>true</FunctionLevelLinking> |
| 123 | 125 | <IntrinsicFunctions>true</IntrinsicFunctions> |
| 124 | 126 | <SDLCheck>true</SDLCheck> |
| 125 | - <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
| 127 | + <PreprocessorDefinitions>NDEBUG;_CONSOLE;USING_SLANG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
| 126 | 128 | <ConformanceMode>true</ConformanceMode> |
| 127 | - <AdditionalIncludeDirectories>$(SolutionDir)dep\include;$(VULKAN_SDK)\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
| 129 | + <AdditionalIncludeDirectories>$(SolutionDir)dep\include;$(VULKAN_SDK)\Include;$(ProjectDir)</AdditionalIncludeDirectories> | |
| 128 | 130 | <LanguageStandard>stdcpp20</LanguageStandard> |
| 131 | + <AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions> | |
| 129 | 132 | </ClCompile> |
| 130 | 133 | <Link> |
| 131 | 134 | <SubSystem>Console</SubSystem> |
| @@ -135,11 +138,25 @@ | ||
| 135 | 138 | </Link> |
| 136 | 139 | <PostBuildEvent> |
| 137 | 140 | <Command>$(VULKAN_SDK)\Bin\glslc.exe $(ProjectDir)shader.vert -o $(ProjectDir)vert.spv |
| 138 | -$(VULKAN_SDK)\Bin\glslc.exe $(ProjectDir)shader.frag -o $(ProjectDir)frag.spv</Command> | |
| 141 | +$(VULKAN_SDK)\Bin\glslc.exe $(ProjectDir)shader.frag -o $(ProjectDir)frag.spv | |
| 142 | +$(VULKAN_SDK)\Bin\slangc.exe $(ProjectDir)shader.slang -target spirv -profile spirv_1_4 -emit-spirv-directly -fvk-use-entrypoint-name -entry vertMain -entry fragMain -o slang.spv</Command> | |
| 139 | 143 | </PostBuildEvent> |
| 140 | 144 | </ItemDefinitionGroup> |
| 141 | 145 | <ItemGroup> |
| 142 | 146 | <ClCompile Include="main.cc" /> |
| 147 | + <ClCompile Include="shader\glsl.cc" /> | |
| 148 | + <ClCompile Include="shader\slang.cc" /> | |
| 149 | + <ClCompile Include="util\file.cc" /> | |
| 150 | + </ItemGroup> | |
| 151 | + <ItemGroup> | |
| 152 | + <ClInclude Include="shader\glsl.hh" /> | |
| 153 | + <ClInclude Include="shader\slang.hh" /> | |
| 154 | + <ClInclude Include="util\file.hh" /> | |
| 155 | + </ItemGroup> | |
| 156 | + <ItemGroup> | |
| 157 | + <None Include="shader.frag" /> | |
| 158 | + <None Include="shader.slang" /> | |
| 159 | + <None Include="shader.vert" /> | |
| 143 | 160 | </ItemGroup> |
| 144 | 161 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
| 145 | 162 | <ImportGroup Label="ExtensionTargets"> |
| @@ -13,10 +13,53 @@ | ||
| 13 | 13 | <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> |
| 14 | 14 | <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> |
| 15 | 15 | </Filter> |
| 16 | + <Filter Include="Header Files\shader"> | |
| 17 | + <UniqueIdentifier>{6c2608ee-04db-4f8f-abd0-fd3a1d3f67b3}</UniqueIdentifier> | |
| 18 | + </Filter> | |
| 19 | + <Filter Include="Source Files\shader"> | |
| 20 | + <UniqueIdentifier>{06354e1d-5a76-473a-842e-b454c5e4b64f}</UniqueIdentifier> | |
| 21 | + </Filter> | |
| 22 | + <Filter Include="Header Files\util"> | |
| 23 | + <UniqueIdentifier>{025c7e9a-27a3-411d-993d-4964934e9584}</UniqueIdentifier> | |
| 24 | + </Filter> | |
| 25 | + <Filter Include="Source Files\util"> | |
| 26 | + <UniqueIdentifier>{04597cf8-3222-464c-b8ca-69b5e864bf20}</UniqueIdentifier> | |
| 27 | + </Filter> | |
| 16 | 28 | </ItemGroup> |
| 17 | 29 | <ItemGroup> |
| 18 | 30 | <ClCompile Include="main.cc"> |
| 19 | 31 | <Filter>Source Files</Filter> |
| 20 | 32 | </ClCompile> |
| 33 | + <ClCompile Include="shader\glsl.cc"> | |
| 34 | + <Filter>Source Files\shader</Filter> | |
| 35 | + </ClCompile> | |
| 36 | + <ClCompile Include="shader\slang.cc"> | |
| 37 | + <Filter>Source Files\shader</Filter> | |
| 38 | + </ClCompile> | |
| 39 | + <ClCompile Include="util\file.cc"> | |
| 40 | + <Filter>Source Files\util</Filter> | |
| 41 | + </ClCompile> | |
| 42 | + </ItemGroup> | |
| 43 | + <ItemGroup> | |
| 44 | + <ClInclude Include="shader\glsl.hh"> | |
| 45 | + <Filter>Header Files\shader</Filter> | |
| 46 | + </ClInclude> | |
| 47 | + <ClInclude Include="shader\slang.hh"> | |
| 48 | + <Filter>Header Files\shader</Filter> | |
| 49 | + </ClInclude> | |
| 50 | + <ClInclude Include="util\file.hh"> | |
| 51 | + <Filter>Header Files\util</Filter> | |
| 52 | + </ClInclude> | |
| 53 | + </ItemGroup> | |
| 54 | + <ItemGroup> | |
| 55 | + <None Include="shader.frag"> | |
| 56 | + <Filter>Resource Files</Filter> | |
| 57 | + </None> | |
| 58 | + <None Include="shader.slang"> | |
| 59 | + <Filter>Resource Files</Filter> | |
| 60 | + </None> | |
| 61 | + <None Include="shader.vert"> | |
| 62 | + <Filter>Resource Files</Filter> | |
| 63 | + </None> | |
| 21 | 64 | </ItemGroup> |
| 22 | 65 | </Project> |
| @@ -1,9 +1,9 @@ | ||
| 1 | -#define NOMINMAX | |
| 1 | +#define NOMINMAX | |
| 2 | 2 | |
| 3 | 3 | #pragma region headers |
| 4 | +#include <util/file.hh> | |
| 5 | + | |
| 4 | 6 | #include <iostream> |
| 5 | -#include <string> | |
| 6 | -#include <vector> | |
| 7 | 7 | #include <map> |
| 8 | 8 | #include <ranges> |
| 9 | 9 | #include <algorithm> |
| @@ -58,23 +58,6 @@ | ||
| 58 | 58 | } |
| 59 | 59 | #pragma endregion |
| 60 | 60 | |
| 61 | -#pragma region readShader | |
| 62 | -static std::vector<char> readFile(const std::string &filename) { | |
| 63 | - std::ifstream file(filename, std::ios::ate | std::ios::binary); | |
| 64 | - if (!file.is_open()) { | |
| 65 | - | |
| 66 | - return {}; | |
| 67 | - } | |
| 68 | - | |
| 69 | - size_t fileSize = (size_t)file.tellg(); | |
| 70 | - std::vector<char> buf(fileSize); | |
| 71 | - file.seekg(0); | |
| 72 | - file.read(buf.data(), fileSize); | |
| 73 | - file.close(); | |
| 74 | - return buf; | |
| 75 | -} | |
| 76 | -#pragma endregion | |
| 77 | - | |
| 78 | 61 | #pragma region transitionImgLayout |
| 79 | 62 | void transitionImgLayout(uint32_t imgIdx, |
| 80 | 63 | vk::ImageLayout oldLayout, |
| @@ -165,7 +148,7 @@ | ||
| 165 | 148 | #pragma region window |
| 166 | 149 | int winWidth = 800; |
| 167 | 150 | int winHeight = 600; |
| 168 | - | |
| 151 | + std::string winName = reinterpret_cast<const char *>(u8"Vulkanレンダー"); | |
| 169 | 152 | |
| 170 | 153 | glfwInit(); |
| 171 | 154 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); |
| @@ -208,7 +191,7 @@ | ||
| 208 | 191 | }); |
| 209 | 192 | |
| 210 | 193 | if (!layerFound) { |
| 211 | - | |
| 194 | + assert(false && "必要なレイヤーを見つけられませんでした。\n"); | |
| 212 | 195 | return -1; |
| 213 | 196 | } |
| 214 | 197 | |
| @@ -262,7 +245,7 @@ | ||
| 262 | 245 | #pragma region physdevice |
| 263 | 246 | auto physDevs = instance.enumeratePhysicalDevices(); |
| 264 | 247 | if (physDevs.empty()) { |
| 265 | - | |
| 248 | + assert(false && "Vulkanを対応しているGPUを見つけられませんでした。"); | |
| 266 | 249 | return -1; |
| 267 | 250 | } |
| 268 | 251 | |
| @@ -280,7 +263,7 @@ | ||
| 280 | 263 | } |
| 281 | 264 | |
| 282 | 265 | if (physDevices.empty()) { |
| 283 | - | |
| 266 | + assert(false && "利用可能なGPUを見つけられませんでした。"); | |
| 284 | 267 | return -1; |
| 285 | 268 | } |
| 286 | 269 | |
| @@ -300,13 +283,14 @@ | ||
| 300 | 283 | }); |
| 301 | 284 | |
| 302 | 285 | auto features = physicalDevice.template getFeatures2<vk::PhysicalDeviceFeatures2, |
| 286 | + vk::PhysicalDeviceVulkan11Features, | |
| 303 | 287 | vk::PhysicalDeviceVulkan13Features, |
| 304 | 288 | vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>(); |
| 305 | 289 | bool supportReqFeature = features.template get<vk::PhysicalDeviceVulkan13Features>().dynamicRendering |
| 306 | 290 | && features.template get<vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>().extendedDynamicState; |
| 307 | 291 | |
| 308 | 292 | if (!supportAllExt || !supportsGfx || !supportReqFeature) { |
| 309 | - | |
| 293 | + assert(false && "利用可能なGPUを見つけられませんでした。"); | |
| 310 | 294 | return -1; |
| 311 | 295 | } |
| 312 | 296 | #pragma endregion |
| @@ -327,7 +311,7 @@ | ||
| 327 | 311 | } |
| 328 | 312 | |
| 329 | 313 | if (queueIdx == ~0) { |
| 330 | - | |
| 314 | + assert(false && "グラフィックと表示塞翁しているキューを見つけられませんでした。"); | |
| 331 | 315 | return -1; |
| 332 | 316 | } |
| 333 | 317 | |
| @@ -335,7 +319,8 @@ | ||
| 335 | 319 | float queuePriority = .5f; |
| 336 | 320 | |
| 337 | 321 | vk::PhysicalDeviceFeatures2 baseFeatures{}; |
| 338 | - | |
| 322 | + vk::PhysicalDeviceVulkan11Features features11{}; | |
| 323 | + features11.shaderDrawParameters = true; | |
| 339 | 324 | vk::PhysicalDeviceVulkan13Features features13{}; |
| 340 | 325 | features13.dynamicRendering = true; |
| 341 | 326 | features13.synchronization2 = true; |
| @@ -344,9 +329,11 @@ | ||
| 344 | 329 | extDynState.extendedDynamicState = true; |
| 345 | 330 | |
| 346 | 331 | vk::StructureChain<vk::PhysicalDeviceFeatures2, |
| 332 | + vk::PhysicalDeviceVulkan11Features, | |
| 347 | 333 | vk::PhysicalDeviceVulkan13Features, |
| 348 | 334 | vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = { |
| 349 | 335 | baseFeatures, |
| 336 | + features11, | |
| 350 | 337 | features13, |
| 351 | 338 | extDynState, |
| 352 | 339 | }; |
| @@ -443,30 +430,47 @@ | ||
| 443 | 430 | #pragma endregion |
| 444 | 431 | |
| 445 | 432 | #pragma region gfxPipeline |
| 446 | - auto vertShader = readFile("vert.spv"); | |
| 447 | - if (vertShader.empty()) return -1; | |
| 448 | - auto fragShader = readFile("frag.spv"); | |
| 449 | - if (fragShader.empty()) return -1; | |
| 433 | + //auto vertShader = readFile("vert.spv"); | |
| 434 | + //if (vertShader.empty()) return -1; | |
| 435 | + //auto fragShader = readFile("frag.spv"); | |
| 436 | + //if (fragShader.empty()) return -1; | |
| 450 | 437 | |
| 451 | - vk::ShaderModuleCreateInfo vertCreateInfo = {}; | |
| 452 | - vertCreateInfo.codeSize = vertShader.size() * sizeof(char); | |
| 453 | - vertCreateInfo.pCode = reinterpret_cast<const uint32_t *>(vertShader.data()); | |
| 454 | - vk::ShaderModule vertShaderModule = device.createShaderModule(vertCreateInfo); | |
| 438 | + //vk::ShaderModuleCreateInfo vertCreateInfo = {}; | |
| 439 | + //vertCreateInfo.codeSize = vertShader.size() * sizeof(char); | |
| 440 | + //vertCreateInfo.pCode = reinterpret_cast<const uint32_t *>(vertShader.data()); | |
| 441 | + //vk::ShaderModule vertShaderModule = device.createShaderModule(vertCreateInfo); | |
| 455 | 442 | |
| 456 | - vk::ShaderModuleCreateInfo fragCreateInfo = {}; | |
| 457 | - fragCreateInfo.codeSize = fragShader.size() * sizeof(char); | |
| 458 | - fragCreateInfo.pCode = reinterpret_cast<const uint32_t *>(fragShader.data()); | |
| 459 | - vk::ShaderModule fragShaderModule = device.createShaderModule(fragCreateInfo); | |
| 443 | + //vk::ShaderModuleCreateInfo fragCreateInfo = {}; | |
| 444 | + //fragCreateInfo.codeSize = fragShader.size() * sizeof(char); | |
| 445 | + //fragCreateInfo.pCode = reinterpret_cast<const uint32_t *>(fragShader.data()); | |
| 446 | + //vk::ShaderModule fragShaderModule = device.createShaderModule(fragCreateInfo); | |
| 460 | 447 | |
| 448 | + //vk::PipelineShaderStageCreateInfo vertShaderStageInfo = {}; | |
| 449 | + //vertShaderStageInfo.stage = vk::ShaderStageFlagBits::eVertex; | |
| 450 | + //vertShaderStageInfo.module = vertShaderModule; | |
| 451 | + //vertShaderStageInfo.pName = "main"; | |
| 452 | + | |
| 453 | + //vk::PipelineShaderStageCreateInfo fragShaderStageInfo = {}; | |
| 454 | + //fragShaderStageInfo.stage = vk::ShaderStageFlagBits::eFragment; | |
| 455 | + //fragShaderStageInfo.module = fragShaderModule; | |
| 456 | + //fragShaderStageInfo.pName = "main"; | |
| 457 | + | |
| 458 | + auto shader = readFile("slang.spv"); | |
| 459 | + | |
| 460 | + vk::ShaderModuleCreateInfo info = {}; | |
| 461 | + info.codeSize = shader.size(); | |
| 462 | + info.pCode = reinterpret_cast<const uint32_t *>(shader.data()); | |
| 463 | + vk::ShaderModule shaderModule = device.createShaderModule(info); | |
| 464 | + | |
| 461 | 465 | vk::PipelineShaderStageCreateInfo vertShaderStageInfo = {}; |
| 462 | 466 | vertShaderStageInfo.stage = vk::ShaderStageFlagBits::eVertex; |
| 463 | - vertShaderStageInfo.module = vertShaderModule; | |
| 464 | - vertShaderStageInfo.pName = "main"; | |
| 467 | + vertShaderStageInfo.module = shaderModule; | |
| 468 | + vertShaderStageInfo.pName = "vertMain"; | |
| 465 | 469 | |
| 466 | 470 | vk::PipelineShaderStageCreateInfo fragShaderStageInfo = {}; |
| 467 | 471 | fragShaderStageInfo.stage = vk::ShaderStageFlagBits::eFragment; |
| 468 | - fragShaderStageInfo.module = fragShaderModule; | |
| 469 | - fragShaderStageInfo.pName = "main"; | |
| 472 | + fragShaderStageInfo.module = shaderModule; | |
| 473 | + fragShaderStageInfo.pName = "fragMain"; | |
| 470 | 474 | |
| 471 | 475 | vk::PipelineShaderStageCreateInfo shaderStages[] = { |
| 472 | 476 | vertShaderStageInfo, |
| @@ -567,7 +571,7 @@ | ||
| 567 | 571 | |
| 568 | 572 | auto [result, pipeline] = device.createGraphicsPipeline(nullptr, pipelineInfo); |
| 569 | 573 | if (result != vk::Result::eSuccess) { |
| 570 | - | |
| 574 | + assert(false && "グラフィックパイプラインの設置にしっぱい。"); | |
| 571 | 575 | return -1; |
| 572 | 576 | } |
| 573 | 577 | |
| @@ -623,7 +627,7 @@ | ||
| 623 | 627 | #pragma region drawFrame |
| 624 | 628 | auto fenceResult = device.waitForFences(drawFence, vk::True, UINT64_MAX); |
| 625 | 629 | if (fenceResult != vk::Result::eSuccess) { |
| 626 | - | |
| 630 | + assert(false && "フェンスまで待つに失敗。"); | |
| 627 | 631 | break; |
| 628 | 632 | } |
| 629 | 633 | |
| @@ -632,7 +636,7 @@ | ||
| 632 | 636 | |
| 633 | 637 | if (acquireRes == vk::Result::eErrorOutOfDateKHR || acquireRes == vk::Result::eSuboptimalKHR) continue; |
| 634 | 638 | if (acquireRes != vk::Result::eSuccess) { |
| 635 | - | |
| 639 | + assert(false && "次の画像の受け取りに失敗。"); | |
| 636 | 640 | break; |
| 637 | 641 | } |
| 638 | 642 | |
| @@ -677,8 +681,9 @@ | ||
| 677 | 681 | if (cmdPool) device.destroyCommandPool(cmdPool); |
| 678 | 682 | if (gfxPipeline) device.destroyPipeline(gfxPipeline); |
| 679 | 683 | if (pipelineLayout) device.destroyPipelineLayout(pipelineLayout); |
| 680 | - if (fragShaderModule) device.destroyShaderModule(fragShaderModule); | |
| 681 | - if (vertShaderModule) device.destroyShaderModule(vertShaderModule); | |
| 684 | + if (shaderModule) device.destroyShaderModule(shaderModule); | |
| 685 | + //if (fragShaderModule) device.destroyShaderModule(fragShaderModule); | |
| 686 | + //if (vertShaderModule) device.destroyShaderModule(vertShaderModule); | |
| 682 | 687 | |
| 683 | 688 | for (auto &view : swapChainImageViews) device.destroyImageView(view); |
| 684 | 689 | swapChainImageViews.clear(); |
| @@ -0,0 +1,30 @@ | ||
| 1 | +static float2 positions[3] = float2[]( | |
| 2 | + float2( 0.0, -0.5), | |
| 3 | + float2( 0.5, 0.5), | |
| 4 | + float2(-0.5, 0.5), | |
| 5 | +); | |
| 6 | + | |
| 7 | +static float3 colors[3] = float3[]( | |
| 8 | + float3(1.0, 0.0, 0.0), | |
| 9 | + float3(0.0, 1.0, 0.0), | |
| 10 | + float3(0.0, 0.0, 1.0), | |
| 11 | +); | |
| 12 | + | |
| 13 | +struct VertexOutput { | |
| 14 | + float3 color; | |
| 15 | + float4 sv_position: SV_Position; | |
| 16 | +}; | |
| 17 | + | |
| 18 | +[shader("vertex")] | |
| 19 | +VertexOutput vertMain(uint vid: SV_VertexID) { | |
| 20 | + VertexOutput out; | |
| 21 | + out.sv_position = float4(positions[vid], 0.0, 1.0); | |
| 22 | + out.color = colors[vid]; | |
| 23 | + return out; | |
| 24 | +} | |
| 25 | + | |
| 26 | +[shader("fragment")] | |
| 27 | +float4 fragMain(VertexOutput inVert) : SV_Target { | |
| 28 | + float3 color = inVert.color; | |
| 29 | + return float4(color, 1.0); | |
| 30 | +} |
| @@ -0,0 +1,18 @@ | ||
| 1 | +#include <util/file.hh> | |
| 2 | +#include <fstream> | |
| 3 | +#include <cassert> | |
| 4 | + | |
| 5 | +std::vector<char> readFile(const std::string &filename) { | |
| 6 | + std::ifstream file(filename, std::ios::ate | std::ios::binary); | |
| 7 | + if (!file.is_open()) { | |
| 8 | + assert(false && u8"ファイルを開くに失敗。"); | |
| 9 | + return {}; | |
| 10 | + } | |
| 11 | + | |
| 12 | + size_t fileSize = (size_t)file.tellg(); | |
| 13 | + std::vector<char> buf(fileSize); | |
| 14 | + file.seekg(0); | |
| 15 | + file.read(buf.data(), fileSize); | |
| 16 | + file.close(); | |
| 17 | + return buf; | |
| 18 | +} |
| @@ -0,0 +1,6 @@ | ||
| 1 | +#pragma once | |
| 2 | + | |
| 3 | +#include <string> | |
| 4 | +#include <vector> | |
| 5 | + | |
| 6 | +std::vector<char> readFile(const std::string &filename); |