Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: gpu/command_buffer/service/program_manager.cc

Issue 9309047: Swizzle Uniform Locations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add random offset to prevent more programmer errors Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/program_manager.cc
diff --git a/gpu/command_buffer/service/program_manager.cc b/gpu/command_buffer/service/program_manager.cc
index faf5b3f3771ede5f06c5a5fd535f976999852e4e..d01e9dfff9df242f29c27a96ec3a4cf2c93cf6a3 100644
--- a/gpu/command_buffer/service/program_manager.cc
+++ b/gpu/command_buffer/service/program_manager.cc
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/rand_util.h"
#include "base/string_number_conversions.h"
#include "gpu/command_buffer/common/gles2_cmd_format.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
@@ -450,7 +451,7 @@ static uint32 ComputeOffset(const void* start, const void* position) {
}
void ProgramManager::ProgramInfo::GetProgramInfo(
- CommonDecoder::Bucket* bucket) const {
+ ProgramManager* manager, CommonDecoder::Bucket* bucket) const {
// NOTE: It seems to me the math in here does not need check for overflow
// because the data being calucated from has various small limits. The max
// number of attribs + uniforms is somewhere well under 1024. The maximum size
@@ -516,7 +517,7 @@ void ProgramManager::ProgramInfo::GetProgramInfo(
inputs->name_length = info.name.size();
DCHECK(static_cast<size_t>(info.size) == info.element_locations.size());
for (size_t jj = 0; jj < info.element_locations.size(); ++jj) {
- *locations++ = info.element_locations[jj];
+ *locations++ = manager->SwizzleLocation(info.element_locations[jj]);
}
memcpy(strings, info.name.c_str(), info.name.size());
strings += info.name.size();
@@ -528,7 +529,9 @@ void ProgramManager::ProgramInfo::GetProgramInfo(
ProgramManager::ProgramInfo::~ProgramInfo() {}
-ProgramManager::ProgramManager() {}
+ProgramManager::ProgramManager()
+ : uniform_swizzle_(base::RandInt(0, 15)) {
+}
ProgramManager::~ProgramManager() {
DCHECK(program_infos_.empty());
@@ -628,6 +631,31 @@ void ProgramManager::UnuseProgram(
RemoveProgramInfoIfUnused(shader_manager, info);
}
+static GLint Swizzle(GLint location) {
+ union {
+ GLint as_int;
apatrick_chromium 2012/02/06 21:04:44 Is there any need to do this on an unsigned int? I
greggman 2012/02/06 21:30:01 Done.
+ GLuint as_uint;
+ } t;
+ t.as_int = location;
+ GLuint v = t.as_uint;
+ v = (v & 0xFFFF0000U) |
+ ((v & 0x0000AAAAU) >> 1) |
+ ((v & 0x00005555U) << 1);
+ t.as_uint = v;
+ return t.as_int;
+}
+
+GLint ProgramManager::SwizzleLocation(GLint unswizzled_location) const {
+ GLint v = unswizzled_location < 0 ? unswizzled_location :
+ (unswizzled_location + uniform_swizzle_);
apatrick_chromium 2012/02/06 21:04:44 Why add a random number?
greggman 2012/02/06 21:30:01 The random number is added because NaCl devs were
+ return Swizzle(v);
+}
+
+GLint ProgramManager::UnswizzleLocation(GLint swizzled_location) const {
+ GLint v = Swizzle(swizzled_location);
+ return v < 0 ? v : (v - uniform_swizzle_);
+}
+
} // namespace gles2
} // namespace gpu
« no previous file with comments | « gpu/command_buffer/service/program_manager.h ('k') | gpu/command_buffer/service/program_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698