From c28f53cd4adf4280b72d015992649b452c1abfe3 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 21 Nov 2018 14:27:30 -0500 Subject: [PATCH] gpu: move common compute header to its own file --- .../net/runelite/client/plugins/gpu/comp.glsl | 40 +--------- .../client/plugins/gpu/comp_common.glsl | 75 +++++++++++++++++++ .../client/plugins/gpu/comp_small.glsl | 51 +------------ .../client/plugins/gpu/ShaderTest.java | 27 +++++++ 4 files changed, 104 insertions(+), 89 deletions(-) create mode 100644 runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp_common.glsl diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp.glsl b/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp.glsl index 1ecde8126d..6d1bcca57b 100644 --- a/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp.glsl +++ b/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp.glsl @@ -24,18 +24,6 @@ */ #version 430 core -#define PI 3.1415926535897932384626433832795f -#define UNIT PI / 1024.0f - -layout(std140) uniform uniforms { - int cameraYaw; - int cameraPitch; - int centerX; - int centerY; - int zoom; - ivec2 sinCosTable[2048]; -}; - shared int totalNum[12]; // number of faces with a given priority shared int totalDistance[12]; // sum of distances to faces of a given priority @@ -55,33 +43,7 @@ struct modelinfo { int z; // scene position z }; -layout(std430, binding = 0) readonly buffer modelbuffer_in { - modelinfo ol[]; -}; - -layout(std430, binding = 1) readonly buffer vertexbuffer_in { - ivec4 vb[]; -}; - -layout(std430, binding = 2) readonly buffer tempvertexbuffer_in { - ivec4 tempvb[]; -}; - -layout(std430, binding = 3) writeonly buffer vertex_out { - ivec4 vout[]; -}; - -layout(std430, binding = 4) writeonly buffer uv_out { - vec4 uvout[]; -}; - -layout(std430, binding = 5) readonly buffer uvbuffer_in { - vec4 uv[]; -}; - -layout(std430, binding = 6) readonly buffer tempuvbuffer_in { - vec4 tempuv[]; -}; +#include comp_common.glsl layout(local_size_x = 1024) in; diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp_common.glsl b/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp_common.glsl new file mode 100644 index 0000000000..19848ba10e --- /dev/null +++ b/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp_common.glsl @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + #define PI 3.1415926535897932384626433832795f + #define UNIT PI / 1024.0f + + layout(std140) uniform uniforms { + int cameraYaw; + int cameraPitch; + int centerX; + int centerY; + int zoom; + ivec2 sinCosTable[2048]; + }; + + struct modelinfo { + int offset; // offset into buffer + int uvOffset; // offset into uv buffer + int length; // length in faces + int idx; // write idx in target buffer + int flags; // radius, orientation + int x; // scene position x + int y; // scene position y + int z; // scene position z + }; + + layout(std430, binding = 0) readonly buffer modelbuffer_in { + modelinfo ol[]; + }; + + layout(std430, binding = 1) readonly buffer vertexbuffer_in { + ivec4 vb[]; + }; + + layout(std430, binding = 2) readonly buffer tempvertexbuffer_in { + ivec4 tempvb[]; + }; + + layout(std430, binding = 3) writeonly buffer vertex_out { + ivec4 vout[]; + }; + + layout(std430, binding = 4) writeonly buffer uv_out { + vec4 uvout[]; + }; + + layout(std430, binding = 5) readonly buffer uvbuffer_in { + vec4 uv[]; + }; + + layout(std430, binding = 6) readonly buffer tempuvbuffer_in { + vec4 tempuv[]; + }; \ No newline at end of file diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp_small.glsl b/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp_small.glsl index 9548de5435..c0cce21b21 100644 --- a/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp_small.glsl +++ b/runelite-client/src/main/resources/net/runelite/client/plugins/gpu/comp_small.glsl @@ -24,18 +24,6 @@ */ #version 430 core -#define PI 3.1415926535897932384626433832795f -#define UNIT PI / 1024.0f - -layout(std140) uniform uniforms { - int cameraYaw; - int cameraPitch; - int centerX; - int centerY; - int zoom; - ivec2 sinCosTable[2048]; -}; - shared int totalNum[12]; // number of faces with a given priority shared int totalDistance[12]; // sum of distances to faces of a given priority @@ -44,44 +32,7 @@ shared int totalMappedNum[18]; // number of faces with a given adjusted priority shared int min10; // minimum distance to a face of priority 10 shared int dfs[512]; // packed face id and distance -struct modelinfo { - int offset; // offset into buffer - int uvOffset; // offset into uv buffer - int length; // length in faces - int idx; // write idx in target buffer - int flags; // radius, orientation - int x; // scene position x - int y; // scene position y - int z; // scene position z -}; - -layout(std430, binding = 0) readonly buffer modelbuffer_in { - modelinfo ol[]; -}; - -layout(std430, binding = 1) readonly buffer vertexbuffer_in { - ivec4 vb[]; -}; - -layout(std430, binding = 2) readonly buffer tempvertexbuffer_in { - ivec4 tempvb[]; -}; - -layout(std430, binding = 3) writeonly buffer vertex_out { - ivec4 vout[]; -}; - -layout(std430, binding = 4) writeonly buffer uv_out { - vec4 uvout[]; -}; - -layout(std430, binding = 5) readonly buffer uvbuffer_in { - vec4 uv[]; -}; - -layout(std430, binding = 6) readonly buffer tempuvbuffer_in { - vec4 tempuv[]; -}; +#include comp_common.glsl layout(local_size_x = 512) in; diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/gpu/ShaderTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/gpu/ShaderTest.java index 0889b0d0f6..bc42b37239 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/gpu/ShaderTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/gpu/ShaderTest.java @@ -85,6 +85,33 @@ public class ShaderTest gl = glContext.getGL().getGL4(); } + @Test + @Ignore + public void testUnordered() throws ShaderException + { + int glComputeProgram = gl.glCreateProgram(); + int glComputeShader = gl.glCreateShader(gl.GL_COMPUTE_SHADER); + try + { + Function func = (s) -> inputStreamToString(getClass().getResourceAsStream(s)); + Template template = new Template(func); + String source = template.process(func.apply("comp_unordered.glsl")); + + int line = 0; + for (String str : source.split("\\n")) + { + System.out.println(++line + " " + str); + } + + GLUtil.loadComputeShader(gl, glComputeProgram, glComputeShader, source); + } + finally + { + gl.glDeleteShader(glComputeShader); + gl.glDeleteProgram(glComputeProgram); + } + } + @Test @Ignore public void testSmall() throws ShaderException