GPU/ShaderGen: Use [unroll] for resolve loops

This commit is contained in:
Connor McLaughlin 2021-07-11 13:08:25 +10:00
parent 719710ef98
commit 98af6e7228
3 changed files with 11 additions and 3 deletions

View file

@ -1052,7 +1052,7 @@ float4 LoadVRAM(int2 coords)
{ {
#if MULTISAMPLING #if MULTISAMPLING
float4 value = LOAD_TEXTURE_MS(samp0, coords, 0u); float4 value = LOAD_TEXTURE_MS(samp0, coords, 0u);
for (uint sample_index = 1u; sample_index < MULTISAMPLES; sample_index++) FOR_UNROLL (uint sample_index = 1u; sample_index < MULTISAMPLES; sample_index++)
value += LOAD_TEXTURE_MS(samp0, coords, sample_index); value += LOAD_TEXTURE_MS(samp0, coords, sample_index);
value /= float(MULTISAMPLES); value /= float(MULTISAMPLES);
return value; return value;
@ -1156,7 +1156,7 @@ float4 LoadVRAM(int2 coords)
{ {
#if MULTISAMPLING #if MULTISAMPLING
float4 value = LOAD_TEXTURE_MS(samp0, coords, 0u); float4 value = LOAD_TEXTURE_MS(samp0, coords, 0u);
for (uint sample_index = 1u; sample_index < MULTISAMPLES; sample_index++) FOR_UNROLL (uint sample_index = 1u; sample_index < MULTISAMPLES; sample_index++)
value += LOAD_TEXTURE_MS(samp0, coords, sample_index); value += LOAD_TEXTURE_MS(samp0, coords, sample_index);
value /= float(MULTISAMPLES); value /= float(MULTISAMPLES);
return value; return value;

View file

@ -1,4 +1,4 @@
#pragma once #pragma once
#include "types.h" #include "types.h"
static constexpr u32 SHADER_CACHE_VERSION = 5; static constexpr u32 SHADER_CACHE_VERSION = 6;

View file

@ -173,6 +173,10 @@ void ShaderGen::WriteHeader(std::stringstream& ss)
ss << "#define CONSTANT const\n"; ss << "#define CONSTANT const\n";
ss << "#define GLOBAL\n"; ss << "#define GLOBAL\n";
ss << "#define FOR_UNROLL for\n";
ss << "#define FOR_LOOP for\n";
ss << "#define IF_BRANCH if\n";
ss << "#define IF_FLATTEN if\n";
ss << "#define VECTOR_EQ(a, b) ((a) == (b))\n"; ss << "#define VECTOR_EQ(a, b) ((a) == (b))\n";
ss << "#define VECTOR_NEQ(a, b) ((a) != (b))\n"; ss << "#define VECTOR_NEQ(a, b) ((a) != (b))\n";
ss << "#define VECTOR_COMP_EQ(a, b) equal((a), (b))\n"; ss << "#define VECTOR_COMP_EQ(a, b) equal((a), (b))\n";
@ -214,6 +218,10 @@ void ShaderGen::WriteHeader(std::stringstream& ss)
ss << "#define mat4 float4x4\n"; ss << "#define mat4 float4x4\n";
ss << "#define CONSTANT static const\n"; ss << "#define CONSTANT static const\n";
ss << "#define GLOBAL static\n"; ss << "#define GLOBAL static\n";
ss << "#define FOR_UNROLL [unroll] for\n";
ss << "#define FOR_LOOP [loop] for\n";
ss << "#define IF_BRANCH [branch] if\n";
ss << "#define IF_FLATTEN [flatten] if\n";
ss << "#define VECTOR_EQ(a, b) (all((a) == (b)))\n"; ss << "#define VECTOR_EQ(a, b) (all((a) == (b)))\n";
ss << "#define VECTOR_NEQ(a, b) (any((a) != (b)))\n"; ss << "#define VECTOR_NEQ(a, b) (any((a) != (b)))\n";
ss << "#define VECTOR_COMP_EQ(a, b) ((a) == (b))\n"; ss << "#define VECTOR_COMP_EQ(a, b) ((a) == (b))\n";